[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 544361d37f 1/2: Replace lisp-mode-symbol-regexp with (rx lisp-mod
From: |
Mattias Engdegård |
Subject: |
master 544361d37f 1/2: Replace lisp-mode-symbol-regexp with (rx lisp-mode-symbol) |
Date: |
Mon, 4 Jul 2022 09:01:59 -0400 (EDT) |
branch: master
commit 544361d37f3877b2f10c362936a283f4a0b2fa71
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
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.
---
lisp/emacs-lisp/checkdoc.el | 6 ++---
lisp/emacs-lisp/lisp-mode.el | 56 +++++++++++++++++++++++--------------------
lisp/emacs-lisp/shorthands.el | 2 +-
3 files changed, 34 insertions(+), 30 deletions(-)
diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el
index 2cb5fa120e..2c9adfe2d2 100644
--- a/lisp/emacs-lisp/checkdoc.el
+++ b/lisp/emacs-lisp/checkdoc.el
@@ -165,7 +165,7 @@
(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)
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index d61432b7dd..ab572d5795 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -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)
diff --git a/lisp/emacs-lisp/shorthands.el b/lisp/emacs-lisp/shorthands.el
index a9e4343715..75cbe5f192 100644
--- a/lisp/emacs-lisp/shorthands.el
+++ b/lisp/emacs-lisp/shorthands.el
@@ -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