Fix #5187: syntax highlighting in ielm REPL

This commit is contained in:
Henrik Lissner 2021-07-10 16:32:11 -04:00
parent 3aeb0c060f
commit 243cb43fec

View file

@ -153,27 +153,31 @@ employed so that flycheck still does *some* helpful linting.")
:config :config
(set-lookup-handlers! 'inferior-emacs-lisp-mode (set-lookup-handlers! 'inferior-emacs-lisp-mode
:definition #'+emacs-lisp-lookup-definition :definition #'+emacs-lisp-lookup-definition
:documentation #'+emacs-lisp-lookup-documentation)) :documentation #'+emacs-lisp-lookup-documentation)
;; Adapted from http://www.modernemacs.com/post/comint-highlighting/ to add ;; Adapted from http://www.modernemacs.com/post/comint-highlighting/ to add
;; syntax highlighting to ielm REPLs. ;; syntax highlighting to ielm REPLs.
(add-hook! 'ielm-mode-hook (setq ielm-font-lock-keywords
(defun +emacs-lisp-init-syntax-highlighting-h () (append '(("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)"
(font-lock-add-keywords (1 font-lock-comment-face)
nil (cl-loop for (matcher . match-highlights) (2 font-lock-constant-face)))
in (append lisp-el-font-lock-keywords-2 lisp-cl-font-lock-keywords-2) (when (require 'highlight-numbers nil t)
collect (highlight-numbers--get-regexp-for-mode 'emacs-lisp-mode))
`((lambda (limit) (cl-loop for (matcher . match-highlights)
(and ,(if (symbolp matcher) in (append lisp-el-font-lock-keywords-2
`(,matcher limit) lisp-cl-font-lock-keywords-2)
`(re-search-forward ,matcher limit t)) collect
;; Only highlight matches after the prompt `((lambda (limit)
(> (match-beginning 0) (car comint-last-prompt)) (when ,(if (symbolp matcher)
;; Make sure we're not in a comment or string `(,matcher limit)
(let ((state (sp--syntax-ppss))) `(re-search-forward ,matcher limit t))
(not (or (nth 3 state) ;; Only highlight matches after the prompt
(nth 4 state)))))) (> (match-beginning 0) (car comint-last-prompt))
,@match-highlights))))) ;; Make sure we're not in a comment or string
(let ((state (syntax-ppss)))
(not (or (nth 3 state)
(nth 4 state))))))
,@match-highlights)))))
;; ;;