emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/relint 7690e3a 08/16: Scan font-lock-defaults correctly


From: Mattias Engdegård
Subject: [elpa] externals/relint 7690e3a 08/16: Scan font-lock-defaults correctly
Date: Mon, 30 Nov 2020 05:00:58 -0500 (EST)

branch: externals/relint
commit 7690e3af91ec8f9649cc5685404ffe61497b1643
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Scan font-lock-defaults correctly
    
    Previously, font-lock-defaults was treated as font-lock-keywords which
    is incorrect; the forms are different. Now assignments to variables
    whose name contain 'font-lock-keywords' are scanned as such.
---
 relint.el       | 30 ++++++++++++++++++++++++++----
 test/9.elisp    | 22 +++++++++++++++++-----
 test/9.expected | 18 ++++++++++++------
 3 files changed, 55 insertions(+), 15 deletions(-)

diff --git a/relint.el b/relint.el
index 08f61aa..7a45323 100644
--- a/relint.el
+++ b/relint.el
@@ -1154,6 +1154,22 @@ source."
                                 (if literal (cons 1 elem-path) elem-path))))
    form path))
 
+(defun relint--check-font-lock-defaults (form name pos path)
+  "Check a value for `font-lock-defaults'."
+  (let ((val (relint--eval-or-nil form)))
+    (when (consp val)
+     (cond
+      ((symbolp (car val))
+       (unless (memq (car val) relint--checked-variables)
+         (relint--check-font-lock-keywords (car val) name pos path)))
+      ((consp (car val))
+       (let ((keywords (car val)))
+         (while keywords
+           (when (and (symbolp (car keywords))
+                      (not (memq (car keywords) relint--checked-variables)))
+             (relint--check-font-lock-keywords (car keywords) name pos path))
+           (setq keywords (cdr keywords)))))))))
+
 (defun relint--check-font-lock-keywords (form name pos path)
   "Check a font-lock-keywords list.  A regexp can be found in an element,
 or in the car of an element."
@@ -1761,8 +1777,11 @@ directly."
            (cond
             ((memq name relint--known-regexp-variables)
              (relint--check-re expr name pos (cons i path)))
-            ((memq name '(font-lock-defaults font-lock-keywords))
+            ((and (symbolp name) (string-match-p (rx "font-lock-keywords")
+                                                 (symbol-name name)))
              (relint--check-font-lock-keywords expr name pos (cons i path)))
+            ((eq name 'font-lock-defaults)
+             (relint--check-font-lock-defaults expr name pos (cons i path)))
             ((eq name 'imenu-generic-expression)
              (relint--check-imenu-generic-expression
               expr name pos (cons i path)))
@@ -1969,8 +1988,8 @@ directly."
                                   (symbol-name name)))
               (relint--check-list re-arg name pos (cons 2 path) nil)
               (push name relint--checked-variables))
-             ((string-match-p (rx "font-lock-keywords")
-                              (symbol-name name))
+             ((and (symbolp name) (string-match-p (rx "font-lock-keywords")
+                                                  (symbol-name name)))
               (relint--check-font-lock-keywords re-arg name pos (cons 2 path))
               (push name relint--checked-variables))
              ((eq name 'compilation-error-regexp-alist-alist)
@@ -2040,7 +2059,10 @@ directly."
        (`(set (make-local-variable ',name) ,expr)
         (cond ((memq name relint--known-regexp-variables)
                (relint--check-re expr name pos (cons 2 path)))
-              ((memq name '(font-lock-defaults font-lock-keywords))
+              ((eq name 'font-lock-defaults)
+               (relint--check-font-lock-defaults expr name pos (cons 2 path)))
+              ((and (symbolp name) (string-match-p (rx "font-lock-keywords")
+                                                   (symbol-name name)))
                (relint--check-font-lock-keywords expr name pos (cons 2 path)))
               ((eq name 'imenu-generic-expression)
                (relint--check-imenu-generic-expression
diff --git a/test/9.elisp b/test/9.elisp
index 4a37174..ef6ae86 100644
--- a/test/9.elisp
+++ b/test/9.elisp
@@ -19,12 +19,24 @@
            (comment-end-skip "[ll]"))
       (asdf))))
 
-(defun test-9-fl ()
-  (setq-local font-lock-defaults '(("[mm]" . tag)))
-  (setq font-lock-defaults '(("[nn]" . tag)))
-  (set (make-local-variable 'font-lock-defaults) '(("[oo]" . tag))))
-
 (defun test-9-ge ()
   (setq-local imenu-generic-expression
               '((nil "oh" 0)
                 ("*more*" "+a+" 0))))
+
+(defun test-9-fl-kw ()
+  (setq-local font-lock-keywords '(("[mm]" . tag)))
+  (setq font-lock-keywords '(("[nn]" . tag)))
+  (set (make-local-variable 'font-lock-keywords) '(("[oo]" . tag))))
+
+(defconst my-fl-keyw-1
+  '(("[pp]" . alpha)))
+
+(defconst my-font-lock-keywords-2
+  '(("[qq]" . beta)))
+
+(defun test-9-fl-def ()
+  (setq font-lock-defaults
+        '((my-fl-keyw-1
+           my-font-lock-keywords-2)
+          moo mooo)))
diff --git a/test/9.expected b/test/9.expected
index 7bab898..b960f81 100644
--- a/test/9.expected
+++ b/test/9.expected
@@ -34,15 +34,21 @@
 9.elisp:19:33: In comment-end-skip: Duplicated `l' inside character 
alternative (pos 2)
   "[ll]"
    ..^
-9.elisp:23:40: In font-lock-defaults (tag): Duplicated `m' inside character 
alternative (pos 2)
+9.elisp:25:28: In imenu-generic-expression: Unescaped literal `+' (pos 0)
+  "+a+"
+   ^
+9.elisp:28:40: In font-lock-keywords (tag): Duplicated `m' inside character 
alternative (pos 2)
   "[mm]"
    ..^
-9.elisp:24:34: In font-lock-defaults (tag): Duplicated `n' inside character 
alternative (pos 2)
+9.elisp:29:34: In font-lock-keywords (tag): Duplicated `n' inside character 
alternative (pos 2)
   "[nn]"
    ..^
-9.elisp:25:56: In font-lock-defaults (tag): Duplicated `o' inside character 
alternative (pos 2)
+9.elisp:30:56: In font-lock-keywords (tag): Duplicated `o' inside character 
alternative (pos 2)
   "[oo]"
    ..^
-9.elisp:30:28: In imenu-generic-expression: Unescaped literal `+' (pos 0)
-  "+a+"
-   ^
+9.elisp:36:9: In my-font-lock-keywords-2 (beta): Duplicated `q' inside 
character alternative (pos 2)
+  "[qq]"
+   ..^
+9.elisp:40:9: In font-lock-defaults (alpha): Duplicated `p' inside character 
alternative (pos 2)
+  "[pp]"
+   ..^



reply via email to

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