[comp.emacs] ``troff -ms'' additions for etags

gudeman@arizona.edu (David Gudeman) (09/20/89)

I've been writting a rather large document in troff (using eqn and the
-ms macro package) and found a need for an easy way to find subject
headers and labeled equations.  I came up with the following simple
change to etags to make it understand these files.  If you apply these
diffs, etags will recognise all files of the form ``*.tr'' and
``*.[0-9]*'' as troff files, and make tags appropriately.  The tag for
a subject header is the first line of the subject, and the tag for an
equation is the label.

It would be really nice if etags could take regular-expression
arguments to define what sort of tags it looks for.  Anyone want a
project?

The tags search (in 18.52) has a bug.  It searches backwards before
looking on the current line for the tag.  This means that if you have
a section like
----------------
Alpha-0 is an algorithmic language on the same order of complexity as
the lambda calculus:
.SH
Alpha-0
----------------
the tags search will find the first ``Alpha-0'' rather than the real
subject header.  In fact, it will find the first instance of the tag
at the beginning of a line -- searching backwards from the correct
location.
================================================================
*** old/etags.c	Thu Jun 23 05:45:37 1988
--- etags.c	Tue Sep 19 17:08:04 1989
***************
*** 505,510 ****
--- 505,518 ----


        fclose(inf);
        return;
      }
+   /* .tr or .[0-9] implies eqn | ?roff -ms */
+   if (cp && (!strcmp(cp + 1, ".tr") ||
+ 	     ('0' <= cp[1] && cp[1] <= '9')))
+     {
+       MS_funcs(inf);
+       fclose(inf);
+       return;
+     }
    /* .l or .el or .lisp (or .cl or .clisp or ...) implies lisp source code */
    if (cp && (!strcmp (cp + 1, "l") ||
  	     !strcmp (cp + 1, "el") ||
***************
*** 1524,1529 ****
--- 1532,1575 ----
        return i;
    return -1;
  }
+ 
+ 
+ MS_funcs (fi)
+     FILE *fi;
+ {
+   lineno = 0;
+   charno = 0;
+   pfcnt = 0;
+ 
+   while (!feof (fi))
+     {
+       lineno++;
+       linecharno = charno;
+       charno += readline (&lb, fi) + 1;
+       dbp = lb.buffer;
+       if (*lb.buffer != '.') continue;
+       if (lb.buffer[2] == 'H' &&
+ 	  (lb.buffer[1] == 'S' || lb.buffer[1] == 'N'))
+ 	{
+ 	  lineno++;
+ 	  linecharno = charno;
+ 	  charno += readline (&lb, fi) + 1;
+ 	  dbp = lb.buffer;
+ 	  pfnote (lb.buffer, TRUE, lb.buffer, strlen (lb.buffer),
+ 		  lineno, linecharno);
+ 	}
+       else if (lb.buffer[1] == 'E' && lb.buffer[2] == 'Q')
+ 	{ char *s;
+ 	  s = lb.buffer + 3;
+ 	  while (*s == ' ' || *s == '\t') s++;
+ 	  if (*s == 'I' || *s == 'L') s++;
+ 	  while (*s == ' ' || *s == '\t') s++;
+ 	  if (*s) pfnote(s, TRUE, lb.buffer, strlen (lb.buffer),
+ 			 lineno, linecharno);
+ 	}
+     }
+ }
+ 
  
  /* Initialize a linebuffer for use */
  
-- 
					David Gudeman
Department of Computer Science
The University of Arizona        gudeman@arizona.edu
Tucson, AZ 85721                 {allegra,cmcl2,noao}!arizona!gudeman