File:  [gforth] / gforth / tags.fs
Revision 1.14: download - view: text, annotated - select for diffs
Fri Mar 9 21:19:19 2012 UTC (12 years ago) by anton
Branches: MAIN
CVS tags: HEAD
tags.fs now also records IS (untested)

    1: \ VI tags support for GNU Forth.
    2: 
    3: \ Copyright (C) 1995,1998,2002,2003,2007,2008,2009,2010 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 3
   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, see http://www.gnu.org/licenses/.
   19: 
   20: \ usage: gforth tags.fs your_files.fs ...
   21: \  then: vi -t word_name
   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
   37: \ dependences: the word LATEST must return a pointer to the last
   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: 
   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
   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:         s" sort >tags" w/o open-pipe throw
   70: \	tags-file-name w/o create-file throw
   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: 
   89: : put-tags-string ( c-addr u -- )
   90:     2>r source-id dup 0<> swap -1 <> and	\ input from a file
   91:     current @ locals-list <> and	\ not a local name
   92:     if
   93: 	tags-file-id >r 
   94: 	r> 2r> rot dup >r write-file throw
   95: 	#tab r@ emit-file throw
   96: 	r@ put-load-file-name
   97: 	s" /^" r@ write-file throw
   98: 	source drop >in @ r@ write-file throw
   99: 	s" /" r@ write-line throw
  100: 	rdrop
  101:     else
  102: 	2r> 2drop
  103:     endif ;
  104: 
  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: 
  117: : (tags-header) ( -- )
  118:     defers header
  119:     put-tags-entry ;
  120: 
  121: ' (tags-header) IS header

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