Annotation of gforth/tags.fs, revision 1.8
1.1 pazsan 1: \ VI tags support for GNU Forth.
2:
1.7 anton 3: \ Copyright (C) 1995,1998,2002,2003,2007 Free Software Foundation, Inc.
1.1 pazsan 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
1.6 anton 9: \ as published by the Free Software Foundation, either version 3
1.1 pazsan 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
1.6 anton 18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.1 pazsan 19:
1.2 anton 20: \ usage: gforth tags.fs your_files.fs ...
21: \ then: vi -t word_name
1.1 pazsan 22:
23: \ This does not work like etags; instead, the TAGS file is updated
24: \ during the normal Forth interpretation/compilation process.
25:
26: \ The present version has several shortcomings: It always overwrites
27: \ the TAGS file instead of just the parts corresponding to the loaded
28: \ files, but you can have several tag tables in emacs. Every load
29: \ creates a new etags file and the user has to confirm that she wants
30: \ to use it.
31:
32: \ Communication of interactive programs like emacs and Forth over
33: \ files is clumsy. There should be better cooperation between them
34: \ (e.g. via shared memory)
35:
36: \ This is ANS Forth with the following serious environmental
1.8 ! anton 37: \ dependences: the word LATEST must return a pointer to the last
1.1 pazsan 38: \ header, NAME>STRING must convert that pointer to a string, and
39: \ HEADER must be a deferred word that is called to create the name.
40:
41: \ Changes by David: Removed the blanks before and after the explicit
42: \ tag name, since that conflicts with Emacs' auto-completition. In
43: \ fact those blanks are not necessary, since search is performed on
44: \ the tag-text, rather than the tag name.
45:
1.2 anton 46: \ Changes by Erik Rossen: Reversed the order of the tagname and tagfile
47: \ and got rid of the trailing "$" in the address regexp. I also needed
48: \ to comment out search.fs since it sets the search order destructively
49: \ on my system. Added a bit more explanation on how to use tags.fs.
50:
51: \ require search.fs
1.1 pazsan 52: require extend.fs
53:
54: : tags-file-name ( -- c-addr u )
55: \ for now I use just tags; this may become more flexible in the
56: \ future
57: s" tags" ;
58:
59: variable tags-file 0 tags-file !
60:
61: create tags-line 128 chars allot
62:
63: : skip-tags ( file-id -- )
64: \ reads in file until it finds the end or the loadfilename
65: drop ;
66:
67: : tags-file-id ( -- file-id )
68: tags-file @ 0= if
69: tags-file-name w/o create-file throw
70: \ 2dup file-status
71: \ if \ the file does not exist
72: \ drop w/o create-file throw
73: \ else
74: \ drop r/w open-file throw
75: \ dup skip-tags
76: \ endif
77: tags-file !
78: endif
79: tags-file @ ;
80:
81: 2variable last-loadfilename 0 0 last-loadfilename 2!
82:
83: : put-load-file-name ( file-id -- )
84: >r
85: sourcefilename r@ write-file throw
86: #tab r> emit-file throw ;
87:
88: : put-tags-entry ( -- )
89: \ write the entry for the last name to the TAGS file
90: \ if the input is from a file and it is not a local name
91: source-id dup 0<> swap -1 <> and \ input from a file
92: current @ locals-list <> and \ not a local name
1.4 anton 93: latest 0<> and \ not an anonymous (i.e. noname) header
1.1 pazsan 94: if
95: tags-file-id >r
1.4 anton 96: latest name>string r@ write-file throw
1.1 pazsan 97: #tab r@ emit-file throw
1.2 anton 98: r@ put-load-file-name
1.1 pazsan 99: s" /^" r@ write-file throw
100: source drop >in @ r@ write-file throw
1.2 anton 101: s" /" r@ write-line throw
1.1 pazsan 102: rdrop
103: endif ;
104:
105: : (tags-header) ( -- )
106: defers header
107: put-tags-entry ;
108:
109: ' (tags-header) IS header
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>