From: Tassilo Horn <tsdh@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 20096@debbugs.gnu.org
Subject: bug#20096: 25.0.50; Add Font-Lock support for subr-x macros
Date: Sat, 14 Mar 2015 09:26:21 +0100 [thread overview]
Message-ID: <87sid8vvbm.fsf@gnu.org> (raw)
In-Reply-To: <jwvpp8e2rvc.fsf-monnier+emacsbugs@gnu.org> (Stefan Monnier's message of "Thu, 12 Mar 2015 10:52:51 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Is committing the following change the right thing to do?
>
> On that philosophical question, I think the answer would be:
> not quite.
>
> Instead, The Right Thing to do, might be to change elisp-mode's
> font-lock rules so they check obarray for macros (i.e. use mapatoms +
> regexp-opt to generate a macro matching all macros, and probably
> update it from after-load-functions)?
I don't understant what you mean with generating a macro matching all
macros, but the attached patch uses a regexp defconst with a matcher
function for font-lock-keywords. The regex is updated by an
after-load-function which also refreshes fontification in existing elisp
buffers.
--8<---------------cut here---------------start------------->8---
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 5d91209..96fa403 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -181,6 +181,30 @@
nil)))
res))
+(defconst lisp--el-macro-regexp nil
+ "A regular expression matching all loaded elisp macros.
+Can be updated using `lisp--el-update-macro-regexp' after new
+macros were defined.")
+
+(defun lisp--el-update-macro-regexp ()
+ "Update `lisp--el-update-macro-regexp' from `obarray'."
+ (let (elisp-macros)
+ (mapatoms (lambda (a)
+ (when (macrop a)
+ (push (symbol-name a) elisp-macros))))
+ (setq lisp--el-macro-regexp
+ (concat "(" (regexp-opt elisp-macros t) "\\_>"))))
+
+(defun lisp--el-update-after-load (_file)
+ "Update `lisp--el-macro-regexp' and adjust font-lock in existing buffers."
+ (lisp--el-update-macro-regexp)
+ (dolist (buf (buffer-list))
+ (when (derived-mode-p 'emacs-lisp-mode)
+ (font-lock-flush))))
+
+(defun lisp--el-match-macro (limit)
+ (re-search-forward lisp--el-macro-regexp limit t))
+
(pcase-let
((`(,vdefs ,tdefs
,el-defs-re ,cl-defs-re
@@ -194,7 +218,9 @@
"when" "unless" "with-output-to-string"
"ignore-errors" "dotimes" "dolist" "declare"))
(lisp-errs '("warn" "error" "signal"))
- ;; Elisp constructs. FIXME: update dynamically from obarray.
+ ;; Elisp constructs. Now they are update dynamically
+ ;; from obarray but they are also used for setting up
+ ;; the keywords for Common Lisp.
(el-fdefs '("define-advice" "defadvice" "defalias"
"define-derived-mode" "define-minor-mode"
"define-generic-mode" "define-global-minor-mode"
@@ -333,7 +359,7 @@
`( ;; Regexp negated char group.
("\\[\\(\\^\\)" 1 font-lock-negation-char-face prepend)
;; Control structures. Common Lisp forms.
- (,(concat "(" el-kws-re "\\_>") . 1)
+ (lisp--el-match-macro . 1)
;; Exit/Feature symbols as constants.
(,(concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\_>"
"[ \t']*\\(\\(?:\\sw\\|\\s_\\)+\\)?")
@@ -514,6 +540,9 @@ font-lock keywords will not be case sensitive."
. lisp-font-lock-syntactic-face-function)))
(setq-local prettify-symbols-alist lisp--prettify-symbols-alist)
(when elisp
+ (unless lisp--el-macro-regexp
+ (lisp--el-update-macro-regexp))
+ (add-hook 'after-load-functions #'lisp--el-update-after-load)
(setq-local electric-pair-text-pairs
(cons '(?\` . ?\') electric-pair-text-pairs)))
(setq-local electric-pair-skip-whitespace 'chomp)
--8<---------------cut here---------------end--------------->8---
Bye,
Tassilo
next prev parent reply other threads:[~2015-03-14 8:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-12 8:42 bug#20096: 25.0.50; Add Font-Lock support for subr-x macros Tassilo Horn
2015-03-12 14:52 ` Stefan Monnier
2015-03-14 8:26 ` Tassilo Horn [this message]
2015-03-14 13:56 ` Stefan Monnier
2015-03-15 8:25 ` Tassilo Horn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sid8vvbm.fsf@gnu.org \
--to=tsdh@gnu.org \
--cc=20096@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.