Annotation of gforth/etags.fs, revision 1.16
1.1 anton 1: \ Etags support for GNU Forth.
2:
1.16 ! anton 3: \ Copyright (C) 1995,1998,2001,2003,2007 Free Software Foundation, Inc.
1.3 anton 4:
5: \ This file is part of Gforth.
6:
7: \ Gforth is free software; you can redistribute it and/or
8: \ modify it under the terms of the GNU General Public License
9: \ as published by the Free Software Foundation; either version 2
10: \ of the License, or (at your option) any later version.
11:
12: \ This program is distributed in the hope that it will be useful,
13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: \ GNU General Public License for more details.
16:
17: \ You should have received a copy of the GNU General Public License
18: \ along with this program; if not, write to the Free Software
1.10 anton 19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.3 anton 20:
21:
1.1 anton 22: \ This does not work like etags; instead, the TAGS file is updated
23: \ during the normal Forth interpretation/compilation process.
24:
25: \ The present version has several shortcomings: It always overwrites
26: \ the TAGS file instead of just the parts corresponding to the loaded
27: \ files, but you can have several tag tables in emacs. Every load
28: \ creates a new etags file and the user has to confirm that she wants
29: \ to use it.
30:
31: \ Communication of interactive programs like emacs and Forth over
32: \ files is clumsy. There should be better cooperation between them
33: \ (e.g. via shared memory)
34:
35: \ This is ANS Forth with the following serious environmental
36: \ dependences: the variable LAST must contain a pointer to the last
37: \ header, NAME>STRING must convert that pointer to a string, and
38: \ HEADER must be a deferred word that is called to create the name.
39:
1.11 dvdkhlng 40: \ Changes by David: Removed the blanks before and after the explicit
41: \ tag name, since that conflicts with Emacs' auto-completition. In
42: \ fact those blanks are not necessary, since search is performed on
43: \ the tag-text, rather than the tag name.
44:
1.8 pazsan 45: require search.fs
1.15 pazsan 46: require environ.fs
1.8 pazsan 47: require extend.fs
1.7 pazsan 48:
1.1 anton 49: : tags-file-name ( -- c-addr u )
50: \ for now I use just TAGS; this may become more flexible in the
51: \ future
52: s" TAGS" ;
53:
54: variable tags-file 0 tags-file !
55:
56: create tags-line 128 chars allot
57:
58: : skip-tags ( file-id -- )
59: \ reads in file until it finds the end or the loadfilename
60: drop ;
61:
62: : tags-file-id ( -- file-id )
63: tags-file @ 0= if
64: tags-file-name w/o create-file throw
65: \ 2dup file-status
66: \ if \ the file does not exist
67: \ drop w/o create-file throw
68: \ else
69: \ drop r/w open-file throw
70: \ dup skip-tags
71: \ endif
72: tags-file !
73: endif
74: tags-file @ ;
75:
76: 2variable last-loadfilename 0 0 last-loadfilename 2!
77:
78: : put-load-file-name ( file-id -- )
79: >r
1.4 anton 80: sourcefilename last-loadfilename 2@ d<>
1.1 anton 81: if
82: #ff r@ emit-file throw
83: #lf r@ emit-file throw
1.4 anton 84: sourcefilename 2dup
1.1 anton 85: r@ write-file throw
86: last-loadfilename 2!
87: s" ,0" r@ write-line throw
88: endif
89: rdrop ;
90:
91: : put-tags-entry ( -- )
92: \ write the entry for the last name to the TAGS file
93: \ if the input is from a file and it is not a local name
94: source-id dup 0<> swap -1 <> and \ input from a file
1.5 anton 95: current @ locals-list <> and \ not a local name
1.13 anton 96: latest 0<> and \ not an anonymous (i.e. noname) header
1.1 anton 97: if
98: tags-file-id >r
99: r@ put-load-file-name
100: source drop >in @ r@ write-file throw
101: 127 r@ emit-file throw
1.11 dvdkhlng 102: \ bl r@ emit-file throw
1.13 anton 103: latest name>string r@ write-file throw
1.11 dvdkhlng 104: \ bl r@ emit-file throw
1.1 anton 105: 1 r@ emit-file throw
1.4 anton 106: base @ decimal sourceline# 0 <# #s #> r@ write-file throw base !
1.1 anton 107: s" ,0" r@ write-line throw
108: \ the character position in the file; not strictly necessary AFAIK
109: \ instead of using 0, we could use file-position and subtract
110: \ the line length
111: rdrop
1.5 anton 112: endif ;
1.1 anton 113:
114: : (tags-header) ( -- )
115: defers header
116: put-tags-entry ;
117:
118: ' (tags-header) IS header
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>