7

Is there any way to set a custom face for the echo area (and, by extension, the Isearch input text)?

So far my searching hasn't turned up anything, except that it seems like there isn't a way to modify this. Is that correct?

1 Answer 1

6

Sure you can, (see this SO question) although it seems a bit heavy-handed.

(defun nadvice/message-color (old-fun &optional str &rest args)
  (if (not str)
      (funcall old-fun)
    (funcall old-fun "%s" (propertize (apply #'format str args)
                                      'face '(:foreground "red")))))

(advice-add 'message :around #'nadvice/message-color)

A cleaner solution would be to only override the face for messages produced by specific pieces of code.

;; for example
(cl-letf* ((old-message (symbol-function #'message))
           ((symbol-function #'message)
            (lambda (&optional str &rest args)
              (if (not str)
                  (funcall old-message)
                (funcall old-message "%s"
                         (propertize (apply #'format str args)
                                     'face '(:foreground "red")))))))
  (message "hi!"))

So naturally, you can combine these two techniques:

(defun nadvice/isearch-color (old-fun &rest args)
  (cl-letf* ((old-message (symbol-function #'message))
             ((symbol-function #'message)
              (lambda (&optional str &rest iargs)
                (if (not str)
                    (funcall old-message)
                  (funcall old-message "%s"
                           (propertize (apply #'format str iargs)
                                       'face '(:foreground "red")))))))
    (apply old-fun args)))

(advice-add 'isearch-forward :around #'nadvice/isearch-color)
(advice-add 'isearch-backward :around #'nadvice/isearch-color)
5
  • Thanks for the response. I wasn't clear in my original question - I know that there are ways to display a message in the echo area with a different font color (I had come across the SO question you linked in my searching). I'm building a theme, though, and it seems that there is no straightforward way to just change the font face for the echo area (I assume it just uses the default face). I'll probably use what you have here in my own init, but I'm hesitant to put this in the theme file. Commented Feb 5, 2016 at 18:29
  • @user3014097 yeah, that would have been nice to know. :/ I agree, you probably shouldn't be doing anything too fancy in your theme init. I've never seen a special face for isearch, though. Why is it important?
    – PythonNut
    Commented Feb 5, 2016 at 18:31
  • Ha, I suppose that depends on how one defines "important." In the grand scheme of things it is not, just trying to satisfy my OCD. Commented Feb 5, 2016 at 18:35
  • @user3014097 I know what you mean. You're not going to find a face that's already configured for the echo area. You can prove this to yourself with M-x list-faces-display RET. That list includes all of the faces defined in Emacs. If the face you're looking for isn't there, it doesn't exist.
    – PythonNut
    Commented Feb 5, 2016 at 18:38
  • Yeah I had looked there (or well, had searched with M-x customize-face) and hadn't found anything. Thought maybe it might fall into another category I wasn't thinking of, but alas that does not seem to be the case. Thanks again :) Commented Feb 5, 2016 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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