Subject: Re: bug#5600: 23.1; etags don't tag (defvar foo) declaration

From: Kevin Ryde <[email-masked]>
Date: Sat, 20 Feb 2010 11:06:17 +1100

Francesco Potortì <[email-masked]> writes:
>
> Lisp_functions should distinguish between defvar and other (def*
> constructs, and tag the former only if --declarations.

Sounds likely.  I didn't know about that option, new diff below.
I suppose it could tag `declare-function' and the like too, but start
with untagging the defvar ones.

(The bloat of bizaar has made the tree inaccessible for me, so excuse
three separate diff files.)

2010-02-19  Kevin Ryde  <[email-masked]>

	* etags.c (skip_name): New helper.
	(Lisp_functions): Tag "(defvar foo)" only under --declarations.
	(Lisp_help): Describe this --declarations.

2010-02-19  Kevin Ryde  <[email-masked]>

	* maintaining.texi (Tag Syntax): Add Lisp --declarations for
	(defvar foo).

2010-02-19  Kevin Ryde  <[email-masked]>

	* doc/man/etags.1 (--declarations): Add Lisp (defvar foo).

--- etags.c.~3.93.~	2009-11-29 08:42:32.000000000 +1100
+++ etags.c	2010-02-20 10:14:45.000000000 +1100
@@ -433,6 +433,7 @@
 static char *concat __P((char *, char *, char *));
 static char *skip_spaces __P((char *));
 static char *skip_non_spaces __P((char *));
+static char *skip_name __P((char *));
 static char *savenstr __P((char *, int));
 static char *savestr __P((char *));
 static char *etags_strchr __P((const char *, int));
@@ -699,7 +700,9 @@
 "In Lisp code, any function defined with `defun', any variable\n\
 defined with `defvar' or `defconst', and in general the first\n\
 argument of any expression that starts with `(def' in column zero\n\
-is a tag.";
+is a tag.\n\
+`--declarations' tags declarations \"(defvar foo)\" as well as\n\
+definitions.";
 
 static char *Lua_suffixes [] =
   { "lua", "LUA", NULL };
@@ -4858,6 +4861,19 @@
       if (dbp[0] != '(')
 	continue;
 
+      /* "(defvar foo)" is a declaration rather than a definition.
+	 ENHANCE-ME: Maybe also Elisp (declare-function funcname ...),
+	 and/or CL and Elisp (declare (special varname)), or (proclaim). */
+      if (! declarations) {
+	char *p = dbp+1;
+	if (LOOKING_AT (p, "defvar")) {
+	  p = skip_name (p); /* past var name */
+	  p = skip_spaces (p);
+	  if (*p == ')')
+	    continue;
+	}
+      }
+
       if (strneq (dbp+1, "def", 3) || strneq (dbp+1, "DEF", 3))
 	{
 	  dbp = skip_non_spaces (dbp);
@@ -6510,6 +6526,16 @@
     cp++;
   return cp;
 }
+
+/* Skip past any chars at cp which are "name" class, meaning not notinname().*/
+static char *
+skip_name (char *cp)
+{
+  /* '\0' is a notinname() so loop stops there too */
+  while (! notinname (*cp))
+    cp++;
+  return cp;
+}
 
 /* Print error message and exit.  */
 void
--- maintaining.texi.~1.22.~	2009-11-29 08:42:21.000000000 +1100
+++ maintaining.texi	2010-02-20 10:32:11.000000000 +1100
@@ -1593,7 +1593,8 @@
 In Lisp code, any function defined with @code{defun}, any variable
 defined with @code{defvar} or @code{defconst}, and in general the first
 argument of any expression that starts with @samp{(def} in column zero is
-a tag.
+a tag.  The @option{--declarations} option tags declarations
+@code{(defvar foo)} as well as definitions.
 
 @item
 In Scheme code, tags include anything defined with @code{def} or with a
--- etags.1.~1.8.~	2009-01-12 11:01:43.000000000 +1100
+++ etags.1	2010-02-20 10:28:25.000000000 +1100
@@ -88,6 +88,8 @@
 .B \-\-declarations
 In C and derived languages, create tags for function declarations,
 and create tags for extern variables unless \-\-no\-globals is used.
+
+In Lisp, create tags for declarations (defvar foo).
 .TP
 .B \-D, \-\-no\-defines
 Do not create tag entries for C preprocessor constant definitions