🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99493

Re: document TAGS file format

#99493
From: Roland McGrath
Date: Sun, 02 Sep 1990 18:49
57 lines
3143 bytes
In article <9008312002.AA06512@noname> eric%yamada-sun@CSE.OGI.EDU writes:

   How about documenting the format of the TAGS file?  That way it would
   be easy for us Elisp hackers to use the information contained in it.

If you're an ELisp hacker you ought to be able to read tags.el!

Anyway, tags files have a section for each file, beginning with a formfeed
(C-l), a newline (\n), then the name of the file followed by a comma and a
number which is the length (in characters) of the section for that file,
measured from the beginning of the following line (where the first tag is) to
the where the next section begins (with a formfeed) or the end of file.
Each tag line is the string to match, followed by a DEL, a number giving the
character position in the file to begin searching at, a comma, and a number
giving the line in the file to begin searching at.

This bit of code (from my etags2ctags.el, so it's copyright by me under the
terms of the GPL) starts a loop parsing a TAGS file in the current buffer.
Tack on code at the end of the loop to extract the info from each tag line
(with (buffer-substring (match-beginning N) (match-end N))) and do what you
like with it, then close up the loop.

The regexp I use is more complex than needed to just match a tag line, because
it extracts not only the string to match in the file, but the symbol that the
tag is really for (when looking for "foo", you might want to match
"^#define foo(").

      (while (not (eobp))
	(or (looking-at "\f\n")
	    (error "Invalid tags file format"))
	(forward-line 1)
	(let ((file (buffer-substring (point)
				      (progn (search-forward ",")
					     (1- (point)))))
	      (end (let ((len (string-to-int
			       (buffer-substring (point)
						 (progn (forward-line 1)
							(point))))))
		     (+ (point) len))))
	  (while
	      ;; This monster regexp matches an etags tag line.
	      ;;   \1 is the string to match;
	      ;;   \2 is not interesting;
	      ;;   \3 is the symbol;
	      ;;   \4 is the char to start searching at;
	      ;;   \5 is the line to start searching at.
	      (re-search-forward
	       "^\\(\\(.+[ \t]+\\)?\\([-a-zA-Z0-9_$]+\\)[^-a-zA-Z0-9_$]*\\)\^?\\([0-9]+\\),\\([0-9]+\\)\n"
		  end t)


Enjoy,
Roland
--
	Roland McGrath
	Free Software Foundation, Inc.
roland@ai.mit.edu, uunet!ai.mit.edu!roland
Technical Details
Message-ID: <ROLAND.90Sep2144946@geech.ai.mit.edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!wuarchive!zaphod.mps.ohio-state.edu!usc!snorkelwacker!ai-lab!geech!roland
References: <9008312002.AA06512@noname>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,d1aa6a1136244d30
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-09-02 15:42:04 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!wuarchive!zaphod.mps.ohio-state.edu!usc!snorkelwacker!ai-lab!geech!roland
From: roland@ai.mit.edu (Roland McGrath)
Newsgroups: gnu.emacs.bug
Subject: Re: document TAGS file format
Message-ID: <ROLAND.90Sep2144946@geech.ai.mit.edu>
Date: 2 Sep 90 18:49:46 GMT
References: <9008312002.AA06512@noname>
Sender: news@ai.mit.edu
Distribution: gnu
Organization: Hackers Anonymous International, Ltd., Inc. (Applications
 welcome)
Lines: 57
Posted: Sun Sep  2 19:49:46 1990
In-reply-to: eric%yamada-sun@CSE.OGI.EDU's message of 31 Aug 90 20:02:15 GMT