diff options
| author | Tassilo Horn | 2015-03-14 09:27:31 +0100 |
|---|---|---|
| committer | Tassilo Horn | 2015-03-15 09:20:13 +0100 |
| commit | 51e7e463e93708a0e40688f91200e9e9869ec662 (patch) | |
| tree | d14ff26ac0b9432c7dd17d444e223545bea80f24 | |
| parent | 994168240aa3d81cb42cef2f049fec5739f9d850 (diff) | |
| download | emacs-51e7e463e93708a0e40688f91200e9e9869ec662.tar.gz emacs-51e7e463e93708a0e40688f91200e9e9869ec662.zip | |
Font-lock elisp macros/special forms dynamically
* emacs-lisp/lisp-mode.el (lisp--el-macro-regexp): New defconst.
(lisp--el-update-macro-regexp, lisp--el-update-after-load)
(lisp--el-match-macro): New functions.
(lisp-mode-variables): Update lisp--el-macro-regexp and add
lisp--el-update-after-load to after-load-functions.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 36 |
2 files changed, 42 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fb2291c534c..73ba0353d9d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2015-03-15 Tassilo Horn <tsdh@gnu.org> | ||
| 2 | |||
| 3 | * emacs-lisp/lisp-mode.el (lisp--el-macro-regexp): New defconst. | ||
| 4 | (lisp--el-update-macro-regexp, lisp--el-update-after-load) | ||
| 5 | (lisp--el-match-macro): New functions. | ||
| 6 | (lisp-mode-variables): Update lisp--el-macro-regexp and add | ||
| 7 | lisp--el-update-after-load to after-load-functions. | ||
| 8 | |||
| 1 | 2015-03-15 Daniel Colascione <dancol@dancol.org> | 9 | 2015-03-15 Daniel Colascione <dancol@dancol.org> |
| 2 | 10 | ||
| 3 | * emacs-lisp/cl-indent.el | 11 | * emacs-lisp/cl-indent.el |
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 5d912097838..b4f87fdac66 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -181,6 +181,33 @@ | |||
| 181 | nil))) | 181 | nil))) |
| 182 | res)) | 182 | res)) |
| 183 | 183 | ||
| 184 | (defconst lisp--el-macro-regexp nil | ||
| 185 | "A regular expression matching all loaded elisp macros. | ||
| 186 | Can be updated using `lisp--el-update-macro-regexp' after new | ||
| 187 | macros were defined.") | ||
| 188 | |||
| 189 | (defun lisp--el-update-macro-regexp () | ||
| 190 | "Update `lisp--el-update-macro-regexp' from `obarray'. | ||
| 191 | Return non-nil only if the old and new value are different." | ||
| 192 | (let ((old-regex lisp--el-macro-regexp) | ||
| 193 | (elisp-macros nil)) | ||
| 194 | (mapatoms (lambda (a) | ||
| 195 | (when (or (macrop a) (special-form-p a)) | ||
| 196 | (push (symbol-name a) elisp-macros)))) | ||
| 197 | (setq lisp--el-macro-regexp | ||
| 198 | (concat "(" (regexp-opt elisp-macros t) "\\_>")) | ||
| 199 | (not (string= old-regex lisp--el-macro-regexp)))) | ||
| 200 | |||
| 201 | (defun lisp--el-update-after-load (_file) | ||
| 202 | "Update `lisp--el-macro-regexp' and adjust font-lock in existing buffers." | ||
| 203 | (when (lisp--el-update-macro-regexp) | ||
| 204 | (dolist (buf (buffer-list)) | ||
| 205 | (when (derived-mode-p 'emacs-lisp-mode) | ||
| 206 | (font-lock-flush))))) | ||
| 207 | |||
| 208 | (defun lisp--el-match-macro (limit) | ||
| 209 | (re-search-forward lisp--el-macro-regexp limit t)) | ||
| 210 | |||
| 184 | (pcase-let | 211 | (pcase-let |
| 185 | ((`(,vdefs ,tdefs | 212 | ((`(,vdefs ,tdefs |
| 186 | ,el-defs-re ,cl-defs-re | 213 | ,el-defs-re ,cl-defs-re |
| @@ -194,7 +221,9 @@ | |||
| 194 | "when" "unless" "with-output-to-string" | 221 | "when" "unless" "with-output-to-string" |
| 195 | "ignore-errors" "dotimes" "dolist" "declare")) | 222 | "ignore-errors" "dotimes" "dolist" "declare")) |
| 196 | (lisp-errs '("warn" "error" "signal")) | 223 | (lisp-errs '("warn" "error" "signal")) |
| 197 | ;; Elisp constructs. FIXME: update dynamically from obarray. | 224 | ;; Elisp constructs. Now they are update dynamically |
| 225 | ;; from obarray but they are also used for setting up | ||
| 226 | ;; the keywords for Common Lisp. | ||
| 198 | (el-fdefs '("define-advice" "defadvice" "defalias" | 227 | (el-fdefs '("define-advice" "defadvice" "defalias" |
| 199 | "define-derived-mode" "define-minor-mode" | 228 | "define-derived-mode" "define-minor-mode" |
| 200 | "define-generic-mode" "define-global-minor-mode" | 229 | "define-generic-mode" "define-global-minor-mode" |
| @@ -333,7 +362,7 @@ | |||
| 333 | `( ;; Regexp negated char group. | 362 | `( ;; Regexp negated char group. |
| 334 | ("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend) | 363 | ("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend) |
| 335 | ;; Control structures. Common Lisp forms. | 364 | ;; Control structures. Common Lisp forms. |
| 336 | (,(concat "(" el-kws-re "\\_>") . 1) | 365 | (lisp--el-match-macro . 1) |
| 337 | ;; Exit/Feature symbols as constants. | 366 | ;; Exit/Feature symbols as constants. |
| 338 | (,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>" | 367 | (,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>" |
| 339 | "[ \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?") | 368 | "[ \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?") |
| @@ -514,6 +543,9 @@ font-lock keywords will not be case sensitive." | |||
| 514 | . lisp-font-lock-syntactic-face-function))) | 543 | . lisp-font-lock-syntactic-face-function))) |
| 515 | (setq-local prettify-symbols-alist lisp--prettify-symbols-alist) | 544 | (setq-local prettify-symbols-alist lisp--prettify-symbols-alist) |
| 516 | (when elisp | 545 | (when elisp |
| 546 | (unless lisp--el-macro-regexp | ||
| 547 | (lisp--el-update-macro-regexp)) | ||
| 548 | (add-hook 'after-load-functions #'lisp--el-update-after-load) | ||
| 517 | (setq-local electric-pair-text-pairs | 549 | (setq-local electric-pair-text-pairs |
| 518 | (cons '(?\` . ?\') electric-pair-text-pairs))) | 550 | (cons '(?\` . ?\') electric-pair-text-pairs))) |
| 519 | (setq-local electric-pair-skip-whitespace 'chomp) | 551 | (setq-local electric-pair-skip-whitespace 'chomp) |