2

If you invoke M-x eval-expression then you can evaluate elisp expressions there, but there is no syntax highlight.

If I turn on emacs-lisp-mode in the eval-expression prompt then the major mode is switched to emacs-lisp, but the typed expression is still not highlighted.

Why is that? Why doesn't font lock work in the minibuffer?

1

A guess is that the basic functions that read minibuffer input are defined in C, and they just don't allow/account for that. (They're also old - predating even font-lock. But that's not necessarily a/the reason they don't support font-lock.)

FWIW, there's a FIXME comment in the code defining read--expression, which asks whether it should turn on emacs-lisp-mode.

(defun read--expression (prompt &optional initial-contents)
  (let ((minibuffer-completing-symbol t))
    (minibuffer-with-setup-hook
        (lambda ()
          ;; FIXME: call emacs-lisp-mode?
          (add-function :before-until (local 'eldoc-documentation-function)
                        #'elisp-eldoc-documentation-function)
          (eldoc-mode 1)
          (add-hook 'completion-at-point-functions
                    #'elisp-completion-at-point nil t)
          (run-hooks 'eval-expression-minibuffer-setup-hook))
      (read-from-minibuffer prompt initial-contents
                            read-expression-map t
                            'read-expression-history))))

But as you've discovered, turning on emacs-lisp-mode there won't support font-lock. And neither will explicitly turning on font-lock-mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.