Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Sure you can, (see this SO questionthis 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)

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)

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)
added 12 characters in body
Source Link
PythonNut
  • 10.5k
  • 3
  • 31
  • 79

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)

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

(defun nadvice/message (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)

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)

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)
Source Link
PythonNut
  • 10.5k
  • 3
  • 31
  • 79

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

(defun nadvice/message (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)

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)