commit fdabfe7d88853e052cd5a20614585ed3cc1faeac parent 3b2c09fd5fec99b49ee4859c7e8ffd70cb72f5f8 Author: Wilfred Hughes <me@wilfred.me.uk> Date: Mon, 12 Jun 2017 10:05:22 +0100 Run major mode hooks that are known to be for syntax highlighting Diffstat:
| M | helpful.el | | | 24 | ++++++++++++++++++++++++ |
1 file changed, 24 insertions(+), 0 deletions(-)
diff --git a/helpful.el b/helpful.el @@ -206,13 +206,37 @@ This allows us to distinguish strings from symbols." docstring t t)) +(defconst helpful--highlighting-funcs + '(ert--activate-font-lock-keywords + highlight-quoted-mode + rainbow-delimiters-mode) + "Highlighting functions that are safe to run in a temporary buffer. +This is used in `helpful--syntax-highlight' to support extra +highlighting that the user may have configured in their mode +hooks.") + (defun helpful--syntax-highlight (source &optional mode) "Return a propertized version of SOURCE in MODE." (unless mode (setq mode #'emacs-lisp-mode)) (with-temp-buffer (insert source) + + ;; Switch to major-mode MODE, but don't run any hooks. (delay-mode-hooks (funcall mode)) + + ;; `delayed-mode-hooks' contains mode hooks like + ;; `emacs-lisp-mode-hook'. Build a list of functions that are run + ;; when the mode hooks run. + (let (hook-funcs) + (dolist (hook delayed-mode-hooks) + (let ((funcs (symbol-value hook))) + (setq hook-funcs (append hook-funcs funcs)))) + + ;; Filter hooks to those that relate to highlighting, and run them. + (setq hook-funcs (-intersection hook-funcs helpful--highlighting-funcs)) + (-map #'funcall hook-funcs)) + (if (fboundp 'font-lock-ensure) (font-lock-ensure) (with-no-warnings