diff options
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/emacs-lisp/byte-run.el | 28 | ||||
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 49 |
3 files changed, 58 insertions, 34 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 25571bab9c5..e365346c972 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2015-03-17 Tassilo Horn <tsdh@gnu.org> | ||
| 2 | |||
| 3 | * emacs-lisp/byte-run.el (macro-declarations-alist): New | ||
| 4 | declaration no-font-lock-keyword. | ||
| 5 | (defmacro): Flush font-lock in existing elisp buffers. | ||
| 6 | |||
| 7 | * emacs-lisp/lisp-mode.el (lisp--el-update-after-load) | ||
| 8 | (lisp--el-update-macro-regexp, lisp--el-macro-regexp): Delete | ||
| 9 | functions and defconst. | ||
| 10 | (lisp--el-match-keyword): Rename from lisp--el-match-macro. | ||
| 11 | (lisp--el-font-lock-flush-elisp-buffers): New function. | ||
| 12 | (lisp-mode-variables): Remove code for updating | ||
| 13 | lisp--el-macro-regexp, and add | ||
| 14 | lisp--el-font-lock-flush-elisp-buffers to after-load-functions. | ||
| 15 | |||
| 1 | 2015-03-17 Simen Heggestøyl <simenheg@gmail.com> | 16 | 2015-03-17 Simen Heggestøyl <simenheg@gmail.com> |
| 2 | 17 | ||
| 3 | * textmodes/css-mode.el (css--font-lock-keywords): Discriminate | 18 | * textmodes/css-mode.el (css--font-lock-keywords): Discriminate |
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el index caa7e3dad33..e0d6c3e7829 100644 --- a/lisp/emacs-lisp/byte-run.el +++ b/lisp/emacs-lisp/byte-run.el | |||
| @@ -147,11 +147,16 @@ This is used by `declare'.") | |||
| 147 | (defvar macro-declarations-alist | 147 | (defvar macro-declarations-alist |
| 148 | (cons | 148 | (cons |
| 149 | (list 'debug | 149 | (list 'debug |
| 150 | #'(lambda (name _args spec) | 150 | #'(lambda (name _args spec) |
| 151 | (list 'progn :autoload-end | 151 | (list 'progn :autoload-end |
| 152 | (list 'put (list 'quote name) | 152 | (list 'put (list 'quote name) |
| 153 | ''edebug-form-spec (list 'quote spec))))) | 153 | ''edebug-form-spec (list 'quote spec))))) |
| 154 | defun-declarations-alist) | 154 | (cons |
| 155 | (list 'no-font-lock-keyword | ||
| 156 | #'(lambda (name _args val) | ||
| 157 | (list 'function-put (list 'quote name) | ||
| 158 | ''no-font-lock-keyword (list 'quote val)))) | ||
| 159 | defun-declarations-alist)) | ||
| 155 | "List associating properties of macros to their macro expansion. | 160 | "List associating properties of macros to their macro expansion. |
| 156 | Each element of the list takes the form (PROP FUN) where FUN is a function. | 161 | Each element of the list takes the form (PROP FUN) where FUN is a function. |
| 157 | For each (PROP . VALUES) in a macro's declaration, the FUN corresponding | 162 | For each (PROP . VALUES) in a macro's declaration, the FUN corresponding |
| @@ -201,6 +206,19 @@ The return value is undefined. | |||
| 201 | (message "Warning: Unknown macro property %S in %S" | 206 | (message "Warning: Unknown macro property %S in %S" |
| 202 | (car x) name)))) | 207 | (car x) name)))) |
| 203 | decls))) | 208 | decls))) |
| 209 | ;; Refresh font-lock if this is a new macro, or it is an | ||
| 210 | ;; existing macro whose 'no-font-lock-keyword declaration | ||
| 211 | ;; has changed. | ||
| 212 | (if (and | ||
| 213 | ;; If lisp-mode hasn't been loaded, there's no reason | ||
| 214 | ;; to flush. | ||
| 215 | (fboundp 'lisp--el-font-lock-flush-elisp-buffers) | ||
| 216 | (or (not (fboundp name)) ;; new macro | ||
| 217 | (and (fboundp name) ;; existing macro | ||
| 218 | (member `(function-put ',name 'no-font-lock-keyword | ||
| 219 | ',(get name 'no-font-lock-keyword)) | ||
| 220 | declarations)))) | ||
| 221 | (lisp--el-font-lock-flush-elisp-buffers)) | ||
| 204 | (if declarations | 222 | (if declarations |
| 205 | (cons 'prog1 (cons def declarations)) | 223 | (cons 'prog1 (cons def declarations)) |
| 206 | def)))))) | 224 | def)))))) |
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index b4f87fdac66..6b3077302ed 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -181,32 +181,25 @@ | |||
| 181 | nil))) | 181 | nil))) |
| 182 | res)) | 182 | res)) |
| 183 | 183 | ||
| 184 | (defconst lisp--el-macro-regexp nil | 184 | (defun lisp--el-match-keyword (limit) |
| 185 | "A regular expression matching all loaded elisp macros. | 185 | (catch 'found |
| 186 | Can be updated using `lisp--el-update-macro-regexp' after new | 186 | (while (re-search-forward "(\\(\\(?:\\sw\\|\\s_\\)+\\)\\_>" limit t) |
| 187 | macros were defined.") | 187 | (let ((sym (intern-soft (match-string 1)))) |
| 188 | 188 | (when (or (special-form-p sym) | |
| 189 | (defun lisp--el-update-macro-regexp () | 189 | (and (macrop sym) |
| 190 | "Update `lisp--el-update-macro-regexp' from `obarray'. | 190 | (not (get sym 'no-font-lock-keyword)))) |
| 191 | Return non-nil only if the old and new value are different." | 191 | (throw 'found t)))))) |
| 192 | (let ((old-regex lisp--el-macro-regexp) | 192 | |
| 193 | (elisp-macros nil)) | 193 | (defun lisp--el-font-lock-flush-elisp-buffers (&optional file) |
| 194 | (mapatoms (lambda (a) | 194 | ;; Don't flush during load unless called from after-load-functions. |
| 195 | (when (or (macrop a) (special-form-p a)) | 195 | ;; In that case, FILE is non-nil. It's somehow strange that |
| 196 | (push (symbol-name a) elisp-macros)))) | 196 | ;; load-in-progress is t when an after-load-function is called since |
| 197 | (setq lisp--el-macro-regexp | 197 | ;; that should run *after* the load... |
| 198 | (concat "(" (regexp-opt elisp-macros t) "\\_>")) | 198 | (when (or (not load-in-progress) file) |
| 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)) | 199 | (dolist (buf (buffer-list)) |
| 205 | (when (derived-mode-p 'emacs-lisp-mode) | 200 | (with-current-buffer buf |
| 206 | (font-lock-flush))))) | 201 | (when (derived-mode-p 'emacs-lisp-mode) |
| 207 | 202 | (font-lock-flush)))))) | |
| 208 | (defun lisp--el-match-macro (limit) | ||
| 209 | (re-search-forward lisp--el-macro-regexp limit t)) | ||
| 210 | 203 | ||
| 211 | (pcase-let | 204 | (pcase-let |
| 212 | ((`(,vdefs ,tdefs | 205 | ((`(,vdefs ,tdefs |
| @@ -362,7 +355,7 @@ Return non-nil only if the old and new value are different." | |||
| 362 | `( ;; Regexp negated char group. | 355 | `( ;; Regexp negated char group. |
| 363 | ("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend) | 356 | ("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend) |
| 364 | ;; Control structures. Common Lisp forms. | 357 | ;; Control structures. Common Lisp forms. |
| 365 | (lisp--el-match-macro . 1) | 358 | (lisp--el-match-keyword . 1) |
| 366 | ;; Exit/Feature symbols as constants. | 359 | ;; Exit/Feature symbols as constants. |
| 367 | (,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>" | 360 | (,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>" |
| 368 | "[ \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?") | 361 | "[ \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?") |
| @@ -543,9 +536,7 @@ font-lock keywords will not be case sensitive." | |||
| 543 | . lisp-font-lock-syntactic-face-function))) | 536 | . lisp-font-lock-syntactic-face-function))) |
| 544 | (setq-local prettify-symbols-alist lisp--prettify-symbols-alist) | 537 | (setq-local prettify-symbols-alist lisp--prettify-symbols-alist) |
| 545 | (when elisp | 538 | (when elisp |
| 546 | (unless lisp--el-macro-regexp | 539 | (add-hook 'after-load-functions #'lisp--el-font-lock-flush-elisp-buffers) |
| 547 | (lisp--el-update-macro-regexp)) | ||
| 548 | (add-hook 'after-load-functions #'lisp--el-update-after-load) | ||
| 549 | (setq-local electric-pair-text-pairs | 540 | (setq-local electric-pair-text-pairs |
| 550 | (cons '(?\` . ?\') electric-pair-text-pairs))) | 541 | (cons '(?\` . ?\') electric-pair-text-pairs))) |
| 551 | (setq-local electric-pair-skip-whitespace 'chomp) | 542 | (setq-local electric-pair-skip-whitespace 'chomp) |