emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/etags-regen 46c1f2f 10/11: Solve (hopefully?) the local-variable


From: Dmitry Gutov
Subject: scratch/etags-regen 46c1f2f 10/11: Solve (hopefully?) the local-variable-satefy issue
Date: Sun, 3 Jan 2021 19:06:32 -0500 (EST)

branch: scratch/etags-regen
commit 46c1f2f44738d7e56e1d8141747b7fbbd611f75d
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    Solve (hopefully?) the local-variable-satefy issue
---
 .dir-locals.el                | 10 ++++-----
 lisp/progmodes/etags-regen.el | 49 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el
index 785f6c3..4ce1f44 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -5,13 +5,11 @@
          (sentence-end-double-space . t)
          (fill-column . 70)
          (bug-reference-url-format . "https://debbugs.gnu.org/%s";)
-         (etags-regen-program-options
+         (etags-regen-lang-regexp-alist
           .
-          ("--regex='{c}/[     ]*DEFVAR_[A-Z_  (]+\"\\([^\"]+\\)\"/\\1/'"
-           "--regex='{c}/[     ]*DEFVAR_[A-Z_  (]+\"[^\"]+\",[         
]\\([A-Za-z0-9_]+\\)/\\1/'"
-           "--regex='{objc}/[  ]*DEFVAR_[A-Z_  (]+\"\\([^\"]+\\)\"/\\1/'"
-           "--regex='{objc}/[  ]*DEFVAR_[A-Z_  (]+\"[^\"]+\",[         
]\\([A-Za-z0-9_]+\\)/\\1/'")
-          )))
+          ((("c" "objc") .
+            ("/[ \t]*DEFVAR_[A-Z_ \t(]+\"\\([^\"]+\\)\"/\\1/"
+             "/[ \t]*DEFVAR_[A-Z_ \t(]+\"[^\"]+\",[ 
\t]\\([A-Za-z0-9_]+\\)/\\1/"))))))
  (c-mode . ((c-file-style . "GNU")
             (c-noise-macro-names . ("INLINE" "ATTRIBUTE_NO_SANITIZE_UNDEFINED" 
"UNINIT" "CALLBACK" "ALIGN_STACK"))
             (electric-quote-comment . nil)
diff --git a/lisp/progmodes/etags-regen.el b/lisp/progmodes/etags-regen.el
index 9c0cb3c..fe183bf 100644
--- a/lisp/progmodes/etags-regen.el
+++ b/lisp/progmodes/etags-regen.el
@@ -45,9 +45,37 @@
 
 (defcustom etags-regen-program-options nil
   "List of additional options to pass to the etags program."
-  ;; FIXME: How to implement the safety predicate?
   :type '(repeat string))
 
+(defcustom etags-regen-lang-regexp-alist nil
+  "Mapping of languages to additional regexps for tags.
+
+Each language should be one of the recognized by etags, see
+'etags --help'.  Each tag regexp should be a string in the format
+as documented for the '--regex' arguments, except for
+the (optional) language prefix."
+  :type '(repeat
+          (cons
+           :tag "Languages group"
+           (repeat (string :tag "Language name"))
+           (repeat (string :tag "Tag Regexp"))))
+  :safe 'etags-regen--safe-regexp-alist-p)
+
+(defun etags-regen--safe-regexp-alist-p (value)
+  (and (listp value)
+       (seq-every-p
+        (lambda (group)
+          (and (consp group)
+               (listp (car group))
+               (listp (cdr group))
+               (seq-every-p
+                (lambda (lang)
+                  (and (stringp lang)
+                       (string-match-p "\\`[a-z*+]+\\'" lang)))
+                (car group))
+               (seq-every-p #'stringp (cdr group))))
+        value)))
+
 (defvar etags-regen--errors-buffer-name "*etags-regen-tags-errors*")
 
 (defun etags-regen--maybe-generate ()
@@ -84,7 +112,7 @@
          ;; but better-maintained versions of it exist (like universal-ctags).
          (command (format "%s %s -L - -o %s"
                           etags-regen-program
-                          (mapconcat #'identity etags-regen-program-options " 
")
+                          (mapconcat #'identity 
(etags-regen--build-program-options) " ")
                           tags-file)))
     (setq etags-regen--tags-file tags-file
           etags-regen--tags-root root)
@@ -96,10 +124,25 @@
       (shell-command-on-region (point-min) (point-max) command
                                nil nil etags-regen--errors-buffer-name t))))
 
+(defun etags-regen--build-program-options ()
+  (nconc
+   (mapcan
+    (lambda (group)
+      (mapcan
+       (lambda (lang)
+         (mapcar (lambda (regexp)
+                   (concat "--regex="
+                           (shell-quote-argument
+                            (format "{%s}%s" lang regexp))))
+                 (cdr group)))
+       (car group)))
+    etags-regen-lang-regexp-alist)
+   etags-regen-program-options))
+
 (defun etags-regen--update-file ()
   ;; TODO: Maybe only do this when Emacs is idle for a bit.
   (let ((file-name buffer-file-name)
-        (options etags-regen-program-options)
+        (options (etags-regen--build-program-options))
         (tags-file-buf (get-file-buffer etags-regen--tags-file))
         pr should-scan)
     (save-excursion



reply via email to

[Prev in Thread] Current Thread [Next in Thread]