Annotation of gforth/tags.fs, revision 1.1

1.1     ! pazsan      1: \ VI tags support for GNU Forth.
        !             2: 
        !             3: \ Copyright (C) 1995,1998 Free Software Foundation, Inc.
        !             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
        !            19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
        !            20: 
        !            21: 
        !            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: 
        !            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: 
        !            45: require search.fs
        !            46: require extend.fs
        !            47: 
        !            48: : tags-file-name ( -- c-addr u )
        !            49:     \ for now I use just tags; this may become more flexible in the
        !            50:     \ future
        !            51:     s" tags" ;
        !            52: 
        !            53: variable tags-file 0 tags-file !
        !            54: 
        !            55: create tags-line 128 chars allot
        !            56:     
        !            57: : skip-tags ( file-id -- )
        !            58:     \ reads in file until it finds the end or the loadfilename
        !            59:     drop ;
        !            60: 
        !            61: : tags-file-id ( -- file-id )
        !            62:     tags-file @ 0= if
        !            63:        tags-file-name w/o create-file throw
        !            64: \      2dup file-status
        !            65: \      if \ the file does not exist
        !            66: \          drop w/o create-file throw
        !            67: \      else
        !            68: \          drop r/w open-file throw
        !            69: \          dup skip-tags
        !            70: \      endif
        !            71:        tags-file !
        !            72:     endif
        !            73:     tags-file @ ;
        !            74: 
        !            75: 2variable last-loadfilename 0 0 last-loadfilename 2!
        !            76: 
        !            77: : put-load-file-name ( file-id -- )
        !            78:     >r
        !            79:     sourcefilename r@ write-file throw
        !            80:     #tab r> emit-file throw ;
        !            81: 
        !            82: : put-tags-entry ( -- )
        !            83:     \ write the entry for the last name to the TAGS file
        !            84:     \ if the input is from a file and it is not a local name
        !            85:     source-id dup 0<> swap -1 <> and   \ input from a file
        !            86:     current @ locals-list <> and       \ not a local name
        !            87:     last @ 0<> and     \ not an anonymous (i.e. noname) header
        !            88:     if
        !            89:        tags-file-id >r 
        !            90:        r@ put-load-file-name
        !            91:        last @ name>string r@ write-file throw
        !            92:        #tab r@ emit-file throw
        !            93:        s" /^" r@ write-file throw
        !            94:        source drop >in @ r@ write-file throw
        !            95:        s" $/" r@ write-line throw
        !            96:        rdrop
        !            97:     endif ;
        !            98: 
        !            99: : (tags-header) ( -- )
        !           100:     defers header
        !           101:     put-tags-entry ;
        !           102: 
        !           103: ' (tags-header) IS header

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>