* lib-src/etags.c (Lisp_functions): Skip (defvar foo) declarations
[bpt/emacs.git] / lib-src / etags.c
index ec185c9..d393c4d 100644 (file)
@@ -353,6 +353,7 @@ static void put_entries (node *);
 static char *concat (const char *, const char *, const char *);
 static char *skip_spaces (char *);
 static char *skip_non_spaces (char *);
+static char *skip_name (char *);
 static char *savenstr (const char *, int);
 static char *savestr (const char *);
 static char *etags_strchr (const char *, int);
@@ -619,7 +620,8 @@ static const char Lisp_help [] =
 "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\
+The `--declarations' option tags \"(defvar foo)\" constructs too.";
 
 static const char *Lua_suffixes [] =
   { "lua", "LUA", NULL };
@@ -4747,6 +4749,19 @@ Lisp_functions (FILE *inf)
       if (dbp[0] != '(')
        continue;
 
+      /* "(defvar foo)" is a declaration rather than a definition.  */
+      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);
@@ -6307,6 +6322,16 @@ skip_non_spaces (char *cp)
   return cp;
 }
 
+/* Skip any chars in the "name" class.*/
+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
 fatal (const char *s1, const char *s2)