Annotation of gforth/tags.fs, revision 1.14
1.1 pazsan 1: \ VI tags support for GNU Forth.
2:
1.13 anton 3: \ Copyright (C) 1995,1998,2002,2003,2007,2008,2009,2010 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:
1.10 anton 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
1.12 anton 69: s" sort >tags" w/o open-pipe throw
70: \ tags-file-name w/o create-file throw
1.1 pazsan 71: \ 2dup file-status
72: \ if \ the file does not exist
73: \ drop w/o create-file throw
74: \ else
75: \ drop r/w open-file throw
76: \ dup skip-tags
77: \ endif
78: tags-file !
79: endif
80: tags-file @ ;
81:
82: 2variable last-loadfilename 0 0 last-loadfilename 2!
83:
84: : put-load-file-name ( file-id -- )
85: >r
86: sourcefilename r@ write-file throw
87: #tab r> emit-file throw ;
88:
1.14 ! anton 89: : put-tags-string ( c-addr u -- )
! 90: 2>r source-id dup 0<> swap -1 <> and \ input from a file
1.1 pazsan 91: current @ locals-list <> and \ not a local name
92: if
93: tags-file-id >r
1.14 ! anton 94: r> 2r> rot dup >r write-file throw
1.1 pazsan 95: #tab r@ emit-file throw
1.2 anton 96: r@ put-load-file-name
1.1 pazsan 97: s" /^" r@ write-file throw
98: source drop >in @ r@ write-file throw
1.2 anton 99: s" /" r@ write-line throw
1.1 pazsan 100: rdrop
1.14 ! anton 101: else
! 102: 2r> 2drop
1.1 pazsan 103: endif ;
104:
1.14 ! anton 105: : put-tags-name ( -- )
! 106: >in @ parse-name put-tags-string >in ! ;
! 107:
! 108: ' put-tags-name is record-name
! 109:
! 110: : put-tags-entry ( -- )
! 111: \ write the entry for the last name to the TAGS file
! 112: \ if the input is from a file and it is not a local name
! 113: latest 0<> if
! 114: latest name>string put-tags-string
! 115: then ;
! 116:
1.1 pazsan 117: : (tags-header) ( -- )
118: defers header
119: put-tags-entry ;
120:
121: ' (tags-header) IS header
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>