diff options
| author | Stefan Monnier | 2015-09-15 12:44:35 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2015-09-15 12:44:35 -0400 |
| commit | 6d98299e761f18f171e042391138f4f5f5762de7 (patch) | |
| tree | 3578140ecd711c14c4cd70597cd0d69f73647883 | |
| parent | ef7dbdf5873bf0a1f3f0e64e5d019e74d5b15b9e (diff) | |
| download | emacs-6d98299e761f18f171e042391138f4f5f5762de7.tar.gz emacs-6d98299e761f18f171e042391138f4f5f5762de7.zip | |
* lisp/emacs-lisp/lisp-mode.el (lisp-mode-symbol-regexp): New const
Use it everywhere "\\(\\sw\\|\\s_\\|\\\\.\\)+" was used.
(cl-lib-fdefs): Add defgeneric.
(cl-kw): Add all elements of eieio-kw and cl-lib-kw.
(eieio-kw, cl-lib-kw, el-kw): Remove.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 108 |
1 files changed, 49 insertions, 59 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 7be7cb341ca..56c2966656c 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -87,6 +87,9 @@ | |||
| 87 | table) | 87 | table) |
| 88 | "Syntax table used in `lisp-mode'.") | 88 | "Syntax table used in `lisp-mode'.") |
| 89 | 89 | ||
| 90 | (eval-and-compile | ||
| 91 | (defconst lisp-mode-symbol-regexp "\\(?:\\sw\\|\\s_\\|\\\\.\\)+")) | ||
| 92 | |||
| 90 | (defvar lisp-imenu-generic-expression | 93 | (defvar lisp-imenu-generic-expression |
| 91 | (list | 94 | (list |
| 92 | (list nil | 95 | (list nil |
| @@ -110,7 +113,7 @@ | |||
| 110 | ;; CLOS and EIEIO | 113 | ;; CLOS and EIEIO |
| 111 | "defgeneric" "defmethod") | 114 | "defgeneric" "defmethod") |
| 112 | t)) | 115 | t)) |
| 113 | "\\s-+\\(\\(\\sw\\|\\s_\\|\\\\.\\)+\\)")) | 116 | "\\s-+\\(" lisp-mode-symbol-regexp "\\)")) |
| 114 | 2) | 117 | 2) |
| 115 | (list (purecopy "Variables") | 118 | (list (purecopy "Variables") |
| 116 | (purecopy (concat "^\\s-*(" | 119 | (purecopy (concat "^\\s-*(" |
| @@ -122,11 +125,11 @@ | |||
| 122 | "defconstant" | 125 | "defconstant" |
| 123 | "defparameter" "define-symbol-macro") | 126 | "defparameter" "define-symbol-macro") |
| 124 | t)) | 127 | t)) |
| 125 | "\\s-+\\(\\(\\sw\\|\\s_\\|\\\\.\\)+\\)")) | 128 | "\\s-+\\(" lisp-mode-symbol-regexp "\\)")) |
| 126 | 2) | 129 | 2) |
| 127 | ;; For `defvar', we ignore (defvar FOO) constructs. | 130 | ;; For `defvar', we ignore (defvar FOO) constructs. |
| 128 | (list (purecopy "Variables") | 131 | (list (purecopy "Variables") |
| 129 | (purecopy (concat "^\\s-*(defvar\\s-+\\(\\(\\sw\\|\\s_\\|\\\\.\\)+\\)" | 132 | (purecopy (concat "^\\s-*(defvar\\s-+\\(" lisp-mode-symbol-regexp "\\)" |
| 130 | "[[:space:]\n]+[^)]")) | 133 | "[[:space:]\n]+[^)]")) |
| 131 | 1) | 134 | 1) |
| 132 | (list (purecopy "Types") | 135 | (list (purecopy "Types") |
| @@ -143,7 +146,7 @@ | |||
| 143 | ;; CLOS and EIEIO | 146 | ;; CLOS and EIEIO |
| 144 | "defclass") | 147 | "defclass") |
| 145 | t)) | 148 | t)) |
| 146 | "\\s-+'?\\(\\(\\sw\\|\\s_\\|\\\\.\\)+\\)")) | 149 | "\\s-+'?\\(" lisp-mode-symbol-regexp "\\)")) |
| 147 | 2)) | 150 | 2)) |
| 148 | 151 | ||
| 149 | "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") | 152 | "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.") |
| @@ -220,7 +223,9 @@ | |||
| 220 | (defun lisp--el-match-keyword (limit) | 223 | (defun lisp--el-match-keyword (limit) |
| 221 | ;; FIXME: Move to elisp-mode.el. | 224 | ;; FIXME: Move to elisp-mode.el. |
| 222 | (catch 'found | 225 | (catch 'found |
| 223 | (while (re-search-forward "(\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)\\_>" limit t) | 226 | (while (re-search-forward |
| 227 | (eval-when-compile "(\\(" lisp-mode-symbol-regexp "\\)\\_>") | ||
| 228 | limit t) | ||
| 224 | (let ((sym (intern-soft (match-string 1)))) | 229 | (let ((sym (intern-soft (match-string 1)))) |
| 225 | (when (or (special-form-p sym) | 230 | (when (or (special-form-p sym) |
| 226 | (and (macrop sym) | 231 | (and (macrop sym) |
| @@ -249,39 +254,13 @@ | |||
| 249 | (el-vdefs '("defconst" "defcustom" "defvaralias" "defvar-local" | 254 | (el-vdefs '("defconst" "defcustom" "defvaralias" "defvar-local" |
| 250 | "defface")) | 255 | "defface")) |
| 251 | (el-tdefs '("defgroup" "deftheme")) | 256 | (el-tdefs '("defgroup" "deftheme")) |
| 252 | (el-kw '("while-no-input" "letrec" "pcase" "pcase-exhaustive" | ||
| 253 | "pcase-lambda" "pcase-let" "pcase-let*" "save-restriction" | ||
| 254 | "save-excursion" "save-selected-window" | ||
| 255 | ;; "eval-after-load" "eval-next-after-load" | ||
| 256 | "save-window-excursion" "save-current-buffer" | ||
| 257 | "save-match-data" "combine-after-change-calls" | ||
| 258 | "condition-case-unless-debug" "track-mouse" | ||
| 259 | "eval-and-compile" "eval-when-compile" "with-case-table" | ||
| 260 | "with-category-table" "with-coding-priority" | ||
| 261 | "with-current-buffer" "with-demoted-errors" | ||
| 262 | "with-electric-help" "with-eval-after-load" | ||
| 263 | "with-file-modes" | ||
| 264 | "with-local-quit" "with-no-warnings" | ||
| 265 | "with-output-to-temp-buffer" "with-selected-window" | ||
| 266 | "with-selected-frame" "with-silent-modifications" | ||
| 267 | "with-syntax-table" "with-temp-buffer" "with-temp-file" | ||
| 268 | "with-temp-message" "with-timeout" | ||
| 269 | "with-timeout-handler")) | ||
| 270 | (el-errs '("user-error")) | 257 | (el-errs '("user-error")) |
| 271 | ;; Common-Lisp constructs supported by EIEIO. FIXME: namespace. | 258 | ;; Common-Lisp constructs supported by EIEIO. FIXME: namespace. |
| 272 | (eieio-fdefs '("defgeneric" "defmethod")) | 259 | (eieio-fdefs '("defgeneric" "defmethod")) |
| 273 | (eieio-tdefs '("defclass")) | 260 | (eieio-tdefs '("defclass")) |
| 274 | (eieio-kw '("with-slots")) | ||
| 275 | ;; Common-Lisp constructs supported by cl-lib. | 261 | ;; Common-Lisp constructs supported by cl-lib. |
| 276 | (cl-lib-fdefs '("defmacro" "defsubst" "defun" "defmethod")) | 262 | (cl-lib-fdefs '("defmacro" "defsubst" "defun" "defmethod" "defgeneric")) |
| 277 | (cl-lib-tdefs '("defstruct" "deftype")) | 263 | (cl-lib-tdefs '("defstruct" "deftype")) |
| 278 | (cl-lib-kw '("progv" "eval-when" "case" "ecase" "typecase" | ||
| 279 | "etypecase" "ccase" "ctypecase" "loop" "do" "do*" | ||
| 280 | "the" "locally" "proclaim" "declaim" "letf" "go" | ||
| 281 | ;; "lexical-let" "lexical-let*" | ||
| 282 | "symbol-macrolet" "flet" "flet*" "destructuring-bind" | ||
| 283 | "labels" "macrolet" "tagbody" "multiple-value-bind" | ||
| 284 | "block" "return" "return-from")) | ||
| 285 | (cl-lib-errs '("assert" "check-type")) | 264 | (cl-lib-errs '("assert" "check-type")) |
| 286 | ;; Common-Lisp constructs not supported by cl-lib. | 265 | ;; Common-Lisp constructs not supported by cl-lib. |
| 287 | (cl-fdefs '("defsetf" "define-method-combination" | 266 | (cl-fdefs '("defsetf" "define-method-combination" |
| @@ -290,14 +269,20 @@ | |||
| 290 | "define-compiler-macro" "define-modify-macro")) | 269 | "define-compiler-macro" "define-modify-macro")) |
| 291 | (cl-vdefs '("define-symbol-macro" "defconstant" "defparameter")) | 270 | (cl-vdefs '("define-symbol-macro" "defconstant" "defparameter")) |
| 292 | (cl-tdefs '("defpackage" "defstruct" "deftype")) | 271 | (cl-tdefs '("defpackage" "defstruct" "deftype")) |
| 293 | (cl-kw '("prog" "prog*" "handler-case" "handler-bind" | 272 | (cl-kw '("block" "break" "case" "ccase" "compiler-let" "ctypecase" |
| 294 | "in-package" "restart-case" ;; "inline" | 273 | "declaim" "destructuring-bind" "do" "do*" |
| 295 | "restart-bind" "break" "multiple-value-prog1" | 274 | "ecase" "etypecase" "eval-when" "flet" "flet*" |
| 296 | "compiler-let" "with-accessors" "with-compilation-unit" | 275 | "go" "handler-case" "handler-bind" "in-package" ;; "inline" |
| 276 | "labels" "letf" "locally" "loop" | ||
| 277 | "macrolet" "multiple-value-bind" "multiple-value-prog1" | ||
| 278 | "proclaim" "prog" "prog*" "progv" | ||
| 279 | "restart-case" "restart-bind" "return" "return-from" | ||
| 280 | "symbol-macrolet" "tagbody" "the" "typecase" | ||
| 281 | "with-accessors" "with-compilation-unit" | ||
| 297 | "with-condition-restarts" "with-hash-table-iterator" | 282 | "with-condition-restarts" "with-hash-table-iterator" |
| 298 | "with-input-from-string" "with-open-file" | 283 | "with-input-from-string" "with-open-file" |
| 299 | "with-open-stream" "with-package-iterator" | 284 | "with-open-stream" "with-package-iterator" |
| 300 | "with-simple-restart" "with-standard-io-syntax")) | 285 | "with-simple-restart" "with-slots" "with-standard-io-syntax")) |
| 301 | (cl-errs '("abort" "cerror"))) | 286 | (cl-errs '("abort" "cerror"))) |
| 302 | (let ((vdefs (eval-when-compile | 287 | (let ((vdefs (eval-when-compile |
| 303 | (append lisp-vdefs el-vdefs cl-vdefs))) | 288 | (append lisp-vdefs el-vdefs cl-vdefs))) |
| @@ -318,16 +303,9 @@ | |||
| 318 | eieio-fdefs eieio-tdefs | 303 | eieio-fdefs eieio-tdefs |
| 319 | cl-fdefs cl-vdefs cl-tdefs) | 304 | cl-fdefs cl-vdefs cl-tdefs) |
| 320 | t))) | 305 | t))) |
| 321 | ;; Elisp and Common Lisp keywords. | 306 | ;; Common Lisp keywords (Elisp keywords are handled dynamically). |
| 322 | ;; (el-kws-re (eval-when-compile | ||
| 323 | ;; (regexp-opt (append | ||
| 324 | ;; lisp-kw el-kw eieio-kw | ||
| 325 | ;; (cons "go" (mapcar (lambda (s) (concat "cl-" s)) | ||
| 326 | ;; (remove "go" cl-lib-kw)))) | ||
| 327 | ;; t))) | ||
| 328 | (cl-kws-re (eval-when-compile | 307 | (cl-kws-re (eval-when-compile |
| 329 | (regexp-opt (append lisp-kw cl-kw eieio-kw cl-lib-kw) | 308 | (regexp-opt (append lisp-kw cl-kw) t))) |
| 330 | t))) | ||
| 331 | ;; Elisp and Common Lisp "errors". | 309 | ;; Elisp and Common Lisp "errors". |
| 332 | (el-errs-re (eval-when-compile | 310 | (el-errs-re (eval-when-compile |
| 333 | (regexp-opt (append (mapcar (lambda (s) (concat "cl-" s)) | 311 | (regexp-opt (append (mapcar (lambda (s) (concat "cl-" s)) |
| @@ -349,7 +327,8 @@ | |||
| 349 | ;; Any whitespace and defined object. | 327 | ;; Any whitespace and defined object. |
| 350 | "[ \t']*" | 328 | "[ \t']*" |
| 351 | "\\(([ \t']*\\)?" ;; An opening paren. | 329 | "\\(([ \t']*\\)?" ;; An opening paren. |
| 352 | "\\(\\(setf\\)[ \t]+\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\|\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)?") | 330 | "\\(\\(setf\\)[ \t]+" lisp-mode-symbol-regexp |
| 331 | "\\|" lisp-mode-symbol-regexp "\\)?") | ||
| 353 | (1 font-lock-keyword-face) | 332 | (1 font-lock-keyword-face) |
| 354 | (3 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type))) | 333 | (3 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type))) |
| 355 | (cond ((eq type 'var) font-lock-variable-name-face) | 334 | (cond ((eq type 'var) font-lock-variable-name-face) |
| @@ -360,7 +339,8 @@ | |||
| 360 | ;; defmethod with (setf foo) as name. | 339 | ;; defmethod with (setf foo) as name. |
| 361 | ((or (not (match-string 2)) ;; Normal defun. | 340 | ((or (not (match-string 2)) ;; Normal defun. |
| 362 | (and (match-string 2) ;; Setf method. | 341 | (and (match-string 2) ;; Setf method. |
| 363 | (match-string 4))) font-lock-function-name-face))) | 342 | (match-string 4))) |
| 343 | font-lock-function-name-face))) | ||
| 364 | nil t)) | 344 | nil t)) |
| 365 | ;; Emacs Lisp autoload cookies. Supports the slightly different | 345 | ;; Emacs Lisp autoload cookies. Supports the slightly different |
| 366 | ;; forms used by mh-e, calendar, etc. | 346 | ;; forms used by mh-e, calendar, etc. |
| @@ -373,7 +353,8 @@ | |||
| 373 | ;; Any whitespace and defined object. | 353 | ;; Any whitespace and defined object. |
| 374 | "[ \t']*" | 354 | "[ \t']*" |
| 375 | "\\(([ \t']*\\)?" ;; An opening paren. | 355 | "\\(([ \t']*\\)?" ;; An opening paren. |
| 376 | "\\(\\(setf\\)[ \t]+\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\|\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)?") | 356 | "\\(\\(setf\\)[ \t]+" lisp-mode-symbol-regexp |
| 357 | "\\|" lisp-mode-symbol-regexp "\\)?") | ||
| 377 | (1 font-lock-keyword-face) | 358 | (1 font-lock-keyword-face) |
| 378 | (3 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type))) | 359 | (3 (let ((type (get (intern-soft (match-string 1)) 'lisp-define-type))) |
| 379 | (cond ((eq type 'var) font-lock-variable-name-face) | 360 | (cond ((eq type 'var) font-lock-variable-name-face) |
| @@ -395,22 +376,25 @@ | |||
| 395 | (lisp--el-match-keyword . 1) | 376 | (lisp--el-match-keyword . 1) |
| 396 | ;; Exit/Feature symbols as constants. | 377 | ;; Exit/Feature symbols as constants. |
| 397 | (,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>" | 378 | (,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>" |
| 398 | "[ \t']*\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)?") | 379 | "[ \t']*\\(" lisp-mode-symbol-regexp "\\)?") |
| 399 | (1 font-lock-keyword-face) | 380 | (1 font-lock-keyword-face) |
| 400 | (2 font-lock-constant-face nil t)) | 381 | (2 font-lock-constant-face nil t)) |
| 401 | ;; Erroneous structures. | 382 | ;; Erroneous structures. |
| 402 | (,(concat "(" el-errs-re "\\_>") | 383 | (,(concat "(" el-errs-re "\\_>") |
| 403 | (1 font-lock-warning-face)) | 384 | (1 font-lock-warning-face)) |
| 404 | ;; Words inside \\[] tend to be for `substitute-command-keys'. | 385 | ;; Words inside \\[] tend to be for `substitute-command-keys'. |
| 405 | ("\\\\\\\\\\[\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)\\]" | 386 | (,(concat "\\\\\\\\\\[\\(" lisp-mode-symbol-regexp "\\)\\]") |
| 406 | (1 font-lock-constant-face prepend)) | 387 | (1 font-lock-constant-face prepend)) |
| 407 | ;; Words inside ‘’ and '' and `' tend to be symbol names. | 388 | ;; Words inside ‘’ and '' and `' tend to be symbol names. |
| 408 | ("['`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)['’]" | 389 | (,(concat "['`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)" |
| 390 | lisp-mode-symbol-regexp "\\)['’]") | ||
| 409 | (1 font-lock-constant-face prepend)) | 391 | (1 font-lock-constant-face prepend)) |
| 410 | ;; Constant values. | 392 | ;; Constant values. |
| 411 | ("\\_<:\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\_>" 0 font-lock-builtin-face) | 393 | (,(concat "\\_<:" lisp-mode-symbol-regexp "\\_>") |
| 394 | (0 font-lock-builtin-face)) | ||
| 412 | ;; ELisp and CLisp `&' keywords as types. | 395 | ;; ELisp and CLisp `&' keywords as types. |
| 413 | ("\\_<\\&\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\_>" . font-lock-type-face) | 396 | (,(concat "\\_<\\&" lisp-mode-symbol-regexp "\\_>") |
| 397 | . font-lock-type-face) | ||
| 414 | ;; ELisp regexp grouping constructs | 398 | ;; ELisp regexp grouping constructs |
| 415 | (,(lambda (bound) | 399 | (,(lambda (bound) |
| 416 | (catch 'found | 400 | (catch 'found |
| @@ -447,19 +431,22 @@ | |||
| 447 | (,(concat "(" cl-kws-re "\\_>") . 1) | 431 | (,(concat "(" cl-kws-re "\\_>") . 1) |
| 448 | ;; Exit/Feature symbols as constants. | 432 | ;; Exit/Feature symbols as constants. |
| 449 | (,(concat "(\\(catch\\|throw\\|provide\\|require\\)\\_>" | 433 | (,(concat "(\\(catch\\|throw\\|provide\\|require\\)\\_>" |
| 450 | "[ \t']*\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)?") | 434 | "[ \t']*\\(" lisp-mode-symbol-regexp "\\)?") |
| 451 | (1 font-lock-keyword-face) | 435 | (1 font-lock-keyword-face) |
| 452 | (2 font-lock-constant-face nil t)) | 436 | (2 font-lock-constant-face nil t)) |
| 453 | ;; Erroneous structures. | 437 | ;; Erroneous structures. |
| 454 | (,(concat "(" cl-errs-re "\\_>") | 438 | (,(concat "(" cl-errs-re "\\_>") |
| 455 | (1 font-lock-warning-face)) | 439 | (1 font-lock-warning-face)) |
| 456 | ;; Words inside ‘’ and '' and `' tend to be symbol names. | 440 | ;; Words inside ‘’ and '' and `' tend to be symbol names. |
| 457 | ("['`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\)['’]" | 441 | (,(concat "['`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)" |
| 442 | lisp-mode-symbol-regexp "\\)['’]") | ||
| 458 | (1 font-lock-constant-face prepend)) | 443 | (1 font-lock-constant-face prepend)) |
| 459 | ;; Constant values. | 444 | ;; Constant values. |
| 460 | ("\\_<:\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\_>" 0 font-lock-builtin-face) | 445 | (,(concat "\\_<:" lisp-mode-symbol-regexp "\\_>") |
| 446 | (0 font-lock-builtin-face)) | ||
| 461 | ;; ELisp and CLisp `&' keywords as types. | 447 | ;; ELisp and CLisp `&' keywords as types. |
| 462 | ("\\_<\\&\\(?:\\sw\\|\\s_\\|\\\\.\\)+\\_>" . font-lock-type-face) | 448 | (,(concat "\\_<\\&" lisp-mode-symbol-regexp "\\_>") |
| 449 | . font-lock-type-face) | ||
| 463 | ;; This is too general -- rms. | 450 | ;; This is too general -- rms. |
| 464 | ;; A user complained that he has functions whose names start with `do' | 451 | ;; A user complained that he has functions whose names start with `do' |
| 465 | ;; and that they get the wrong color. | 452 | ;; and that they get the wrong color. |
| @@ -482,7 +469,10 @@ | |||
| 482 | (let* ((firstsym (and listbeg | 469 | (let* ((firstsym (and listbeg |
| 483 | (save-excursion | 470 | (save-excursion |
| 484 | (goto-char listbeg) | 471 | (goto-char listbeg) |
| 485 | (and (looking-at "([ \t\n]*\\(\\(\\sw\\|\\s_\\|\\\\.\\)+\\)") | 472 | (and (looking-at |
| 473 | (eval-when-compile | ||
| 474 | (concat "([ \t\n]*\\(" | ||
| 475 | lisp-mode-symbol-regexp "\\)"))) | ||
| 486 | (match-string 1))))) | 476 | (match-string 1))))) |
| 487 | (docelt (and firstsym | 477 | (docelt (and firstsym |
| 488 | (function-get (intern-soft firstsym) | 478 | (function-get (intern-soft firstsym) |