]> git.eshelyaron.com Git - emacs.git/commitdiff
Replace lisp-mode-symbol-regexp with (rx lisp-mode-symbol)
authorMattias Engdegård <mattiase@acm.org>
Mon, 4 Jul 2022 12:12:24 +0000 (14:12 +0200)
committerMattias Engdegård <mattiase@acm.org>
Mon, 4 Jul 2022 12:56:11 +0000 (14:56 +0200)
This is shorter, simplifies use inside rx expressions, and removes
need for eval-when-compile elsewhere (for later exploitation).

* lisp/emacs-lisp/lisp-mode.el (lisp-mode-symbol): New rx-define.
(lisp-mode-symbol-regexp): Redefine using lisp-mode-symbol.
(lisp-imenu-generic-expression, lisp--el-match-keyword)
(lisp-fdefs, lisp-string-in-doc-position-p):
* lisp/emacs-lisp/checkdoc.el (checkdoc--error-bad-format-p):
* lisp/emacs-lisp/shorthands.el (shorthands-font-lock-shorthands):
Use lisp-mode-symbol instead of lisp-mode-symbol-regexp.

lisp/emacs-lisp/checkdoc.el
lisp/emacs-lisp/lisp-mode.el
lisp/emacs-lisp/shorthands.el

index 2cb5fa120e0e9b0ebdf8c2c9e0fb2d84a87dcd27..2c9adfe2d27f259221097a24c1793fd575187af5 100644 (file)
 (require 'cl-lib)
 (require 'help-mode) ;; for help-xref-info-regexp
 (require 'thingatpt) ;; for handy thing-at-point-looking-at
-(require 'lisp-mode) ;; for lisp-mode-symbol-regexp
+(require 'lisp-mode) ;; for lisp-mode-symbol regexp
 (eval-when-compile (require 'dired))     ;; for dired-map-over-marks
 (require 'lisp-mnt)
 
@@ -2604,13 +2604,13 @@ The correct format is \"Foo\" or \"some-symbol: Foo\".  See also
     (unless (let ((case-fold-search nil))
               (looking-at (rx (or upper-case "%s"))))
       ;; A defined Lisp symbol is always okay.
-      (unless (and (looking-at (rx (group (regexp lisp-mode-symbol-regexp))))
+      (unless (and (looking-at (rx (group lisp-mode-symbol)))
                    (or (fboundp (intern (match-string 1)))
                        (boundp (intern (match-string 1)))))
         ;; Other Lisp symbols are sometimes okay.
         (rx-let ((c (? "\\\n")))        ; `c' is for a continued line
           (let ((case-fold-search nil)
-                (some-symbol (rx (regexp lisp-mode-symbol-regexp)
+                (some-symbol (rx lisp-mode-symbol
                                  c ":" c (+ (any " \t\n"))))
                 (lowercase-str (rx c (group (any "a-z") (+ wordchar)))))
             (if (looking-at some-symbol)
index d61432b7ddf7cb200e7e8e55f800e30f1989f35b..ab572d579525656a2867d462e587738ab63a3ae3 100644 (file)
     table)
   "Syntax table used in `lisp-mode'.")
 
+(rx-define lisp-mode-symbol (+ (| (syntax word)
+                                  (syntax symbol)
+                                  (: "\\" nonl))))
+
 (eval-and-compile
-  (defconst lisp-mode-symbol-regexp "\\(?:\\sw\\|\\s_\\|\\\\.\\)+"))
+  (defconst lisp-mode-symbol-regexp (rx lisp-mode-symbol)))
 
 (defvar lisp-imenu-generic-expression
   (list
                                 ;; CLOS and EIEIO
                                "defgeneric" "defmethod")
                               t))
-                          "\\s-+\\(" lisp-mode-symbol-regexp "\\)"))
+                          "\\s-+\\(" (rx lisp-mode-symbol) "\\)"))
         2)
    ;; Like the previous, but uses a quoted symbol as the name.
    (list nil
                             (regexp-opt
                              '("defalias" "define-obsolete-function-alias")
                               t))
-                          "\\s-+'\\(" lisp-mode-symbol-regexp "\\)"))
+                          "\\s-+'\\(" (rx lisp-mode-symbol) "\\)"))
         2)
    (list (purecopy "Variables")
         (purecopy (concat "^\\s-*("
                                 "defconstant"
                                "defparameter" "define-symbol-macro")
                               t))
-                          "\\s-+\\(" lisp-mode-symbol-regexp "\\)"))
+                          "\\s-+\\(" (rx lisp-mode-symbol) "\\)"))
         2)
    ;; For `defvar'/`defvar-local', we ignore (defvar FOO) constructs.
    (list (purecopy "Variables")
         (purecopy (concat "^\\s-*(defvar\\(?:-local\\)?\\s-+\\("
-                           lisp-mode-symbol-regexp "\\)"
+                           (rx lisp-mode-symbol) "\\)"
                           "[[:space:]\n]+[^)]"))
         1)
    (list (purecopy "Types")
                                 ;; CLOS and EIEIO
                                 "defclass")
                               t))
-                          "\\s-+'?\\(" lisp-mode-symbol-regexp "\\)"))
+                          "\\s-+'?\\(" (rx lisp-mode-symbol) "\\)"))
         2))
 
   "Imenu generic expression for Lisp mode.  See `imenu-generic-expression'.")
@@ -270,7 +274,7 @@ to a package-local <package>-loaddefs.el file.")
   (catch 'found
     (while (re-search-forward
             (eval-when-compile
-              (concat "(\\(" lisp-mode-symbol-regexp "\\)\\_>"))
+              (concat "(\\(" (rx lisp-mode-symbol) "\\)\\_>"))
             limit t)
       (let ((sym (intern-soft (match-string 1))))
        (when (and (or (special-form-p sym) (macrop sym))
@@ -419,8 +423,8 @@ This will generate compile-time constants from BINDINGS."
                   ;; Any whitespace and defined object.
                   "[ \t']*"
                   "\\(([ \t']*\\)?" ;; An opening paren.
-                  "\\(\\(setf\\)[ \t]+" lisp-mode-symbol-regexp
-                  "\\|" lisp-mode-symbol-regexp "\\)?")
+                  "\\(\\(setf\\)[ \t]+" (rx lisp-mode-symbol)
+                  "\\|" (rx lisp-mode-symbol) "\\)?")
           (1 font-lock-keyword-face)
           (3 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type)))
                (cond ((eq type 'var) font-lock-variable-name-face)
@@ -446,8 +450,8 @@ This will generate compile-time constants from BINDINGS."
                   ;; Any whitespace and defined object.
                   "[ \t']*"
                   "\\(([ \t']*\\)?" ;; An opening paren.
-                  "\\(\\(setf\\)[ \t]+" lisp-mode-symbol-regexp
-                  "\\|" lisp-mode-symbol-regexp "\\)?")
+                  "\\(\\(setf\\)[ \t]+" (rx lisp-mode-symbol)
+                  "\\|" (rx lisp-mode-symbol) "\\)?")
           (1 font-lock-keyword-face)
           (3 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type)))
                (cond ((eq type 'var) font-lock-variable-name-face)
@@ -473,34 +477,34 @@ This will generate compile-time constants from BINDINGS."
          (lisp--el-match-keyword . 1)
          ;; Exit/Feature symbols as constants.
          (,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>"
-                   "[ \t']*\\(" lisp-mode-symbol-regexp "\\)?")
+                   "[ \t']*\\(" (rx lisp-mode-symbol) "\\)?")
            (1 font-lock-keyword-face)
            (2 font-lock-constant-face nil t))
          ;; Words inside \\[], \\<>, \\{} or \\`' tend to be for
          ;; `substitute-command-keys'.
-         (,(rx "\\\\" (or (seq "[" (group-n 1 (regexp lisp-mode-symbol-regexp)) "]")
-                          (seq "`" (group-n 1 (+ (regexp lisp-mode-symbol-regexp)
+         (,(rx "\\\\" (or (seq "[" (group-n 1 lisp-mode-symbol) "]")
+                          (seq "`" (group-n 1 (+ lisp-mode-symbol
                                                  ;; allow multiple words, e.g. "C-x a"
                                                  (? " ")))
                            "'")))
           (1 font-lock-constant-face prepend))
-         (,(rx "\\\\" (or (seq "<" (group-n 1 (regexp lisp-mode-symbol-regexp)) ">")
-                          (seq "{" (group-n 1 (regexp lisp-mode-symbol-regexp)) "}")))
+         (,(rx "\\\\" (or (seq "<" (group-n 1 lisp-mode-symbol) ">")
+                          (seq "{" (group-n 1 lisp-mode-symbol) "}")))
           (1 font-lock-variable-name-face prepend))
          ;; Ineffective backslashes (typically in need of doubling).
          ("\\(\\\\\\)\\([^\"\\]\\)"
           (1 (elisp--font-lock-backslash) prepend))
          ;; Words inside ‘’, '' and `' tend to be symbol names.
-         (,(concat "[`‘']\\(" lisp-mode-symbol-regexp "\\)['’]")
+         (,(concat "[`‘']\\(" (rx lisp-mode-symbol) "\\)['’]")
           (1 font-lock-constant-face prepend))
          ;; \\= tends to be an escape in doc strings.
          (,(rx "\\\\=")
           (0 font-lock-builtin-face prepend))
          ;; Constant values.
-         (,(concat "\\_<:" lisp-mode-symbol-regexp "\\_>")
+         (,(concat "\\_<:" (rx lisp-mode-symbol) "\\_>")
           (0 font-lock-builtin-face))
          ;; ELisp and CLisp `&' keywords as types.
-         (,(concat "\\_<&" lisp-mode-symbol-regexp "\\_>")
+         (,(concat "\\_<&" (rx lisp-mode-symbol) "\\_>")
           . font-lock-type-face)
          ;; ELisp regexp grouping constructs
          (,(lambda (bound)
@@ -537,30 +541,30 @@ This will generate compile-time constants from BINDINGS."
          (,(concat "(" cl-kws-re "\\_>") . 1)
          ;; Exit/Feature symbols as constants.
          (,(concat "(\\(catch\\|throw\\|provide\\|require\\)\\_>"
-                   "[ \t']*\\(" lisp-mode-symbol-regexp "\\)?")
+                   "[ \t']*\\(" (rx lisp-mode-symbol) "\\)?")
            (1 font-lock-keyword-face)
            (2 font-lock-constant-face nil t))
          ;; Erroneous structures.
          (,(concat "(" cl-errs-re "\\_>")
            (1 font-lock-warning-face))
          ;; Words inside ‘’ and `' tend to be symbol names.
-         (,(concat "[`‘]\\(" lisp-mode-symbol-regexp "\\)['’]")
+         (,(concat "[`‘]\\(" (rx lisp-mode-symbol) "\\)['’]")
           (1 font-lock-constant-face prepend))
          ;; Uninterned symbols, e.g., (defpackage #:my-package ...)
          ;; must come before keywords below to have effect
-         (,(concat "#:" lisp-mode-symbol-regexp "") 0 font-lock-builtin-face)
+         (,(concat "#:" (rx lisp-mode-symbol) "") 0 font-lock-builtin-face)
          ;; Constant values.
-         (,(concat "\\_<:" lisp-mode-symbol-regexp "\\_>")
+         (,(concat "\\_<:" (rx lisp-mode-symbol) "\\_>")
           (0 font-lock-builtin-face))
          ;; ELisp and CLisp `&' keywords as types.
-         (,(concat "\\_<&" lisp-mode-symbol-regexp "\\_>")
+         (,(concat "\\_<&" (rx lisp-mode-symbol) "\\_>")
           . font-lock-type-face)
          ;; This is too general -- rms.
          ;; A user complained that he has functions whose names start with `do'
          ;; and that they get the wrong color.
          ;; That user has violated the https://www.cliki.net/Naming+conventions:
          ;; CL (but not EL!) `with-' (context) and `do-' (iteration)
-         (,(concat "(\\(\\(do-\\|with-\\)" lisp-mode-symbol-regexp "\\)")
+         (,(concat "(\\(\\(do-\\|with-\\)" (rx lisp-mode-symbol) "\\)")
            (1 font-lock-keyword-face))
          (lisp--match-hidden-arg
           (0 '(face font-lock-warning-face
@@ -596,7 +600,7 @@ containing STARTPOS."
                           (and (looking-at
                                 (eval-when-compile
                                   (concat "([ \t\n]*\\("
-                                          lisp-mode-symbol-regexp "\\)")))
+                                          (rx lisp-mode-symbol) "\\)")))
                                (match-string 1)))))
          (docelt (and firstsym
                       (function-get (intern-soft firstsym)
index a9e4343715c4fd3aed052a3fc044fef26617408f..75cbe5f1923b4fa185bdaceceb57d494af0b0cce 100644 (file)
@@ -62,7 +62,7 @@
   (when read-symbol-shorthands
     (while (re-search-forward
             (eval-when-compile
-              (concat "\\_<\\(" lisp-mode-symbol-regexp "\\)\\_>"))
+              (concat "\\_<\\(" (rx lisp-mode-symbol) "\\)\\_>"))
             limit t)
       (let* ((existing (get-text-property (match-beginning 1) 'face))
              (probe (and (not (memq existing '(font-lock-comment-face