mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 14:30:50 -08:00
Replace lisp-mode-symbol-regexp with (rx lisp-mode-symbol)
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.
This commit is contained in:
parent
65df97f361
commit
544361d37f
3 changed files with 34 additions and 30 deletions
|
|
@ -89,8 +89,12 @@
|
|||
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
|
||||
|
|
@ -117,7 +121,7 @@
|
|||
;; 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
|
||||
|
|
@ -126,7 +130,7 @@
|
|||
(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-*("
|
||||
|
|
@ -138,12 +142,12 @@
|
|||
"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")
|
||||
|
|
@ -160,7 +164,7 @@
|
|||
;; 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue