Function: helpful--syntax-highlight
helpful--syntax-highlight is a byte-compiled function defined in
helpful.el.
Signature
(helpful--syntax-highlight SOURCE &optional MODE)
Documentation
Return a propertized version of SOURCE in MODE.
Source Code
;; Defined in ~/.emacs.d/elpa/helpful-20250408.334/helpful.el
;; TODO: crashes on `backtrace-frame' on a recent checkout.
(defun helpful--syntax-highlight (source &optional mode)
"Return a propertized version of SOURCE in MODE."
(unless mode
(setq mode #'emacs-lisp-mode))
(if (or
(< (length source) helpful-max-highlight)
(eq 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
(font-lock-fontify-buffer)))
(buffer-string))
;; SOURCE was too long to highlight in a reasonable amount of
;; time.
(concat
(propertize
"// Skipping highlighting due to "
'face 'font-lock-comment-face)
(helpful--button
"helpful-max-highlight"
'helpful-describe-exactly-button
'symbol 'helpful-max-highlight
'callable-p nil)
(propertize
".\n"
'face 'font-lock-comment-face)
source)))