0

I wanted to change the colours of Anzu's counter, taking the foreground from the Isearch match background and the background from the fringes, like this

enter image description here

So I evaluated

(face-spec-set 'anzu-mode-line `((t :foreground ,(face-attribute 'isearch :background)
                                    :background ,(face-attribute 'fringe :background)))
               'face-defface-spec)

and it worked. I added it to my init.el, restarted the emacs server... and then it looked like this:

enter image description here

How do I fix that?


PS If I launch Emacs from the command line instead of opening a client frame, then the faces get the right colours. It also works if I put strings in place of the face-attribute forms:

(face-spec-set 'anzu-mode-line '((t :foreground "magenta3"
                                    :background "grey95"))
               'face-defface-spec)

2 Answers 2

0

Use custom-set-faces instead (not tested).

(custom-set-faces
  '(anzu-mode-line ((t (:foreground ,(face-attribute 'isearch :background)
                        :background ,(face-attribute 'fringe :background))))))
3
  • Niet, it looks the same as in the second picture in the question. I've noticed that the customize menu reports ((t (:background "gray" :foreground unspecified))) as the value of the face and I have no idea why. Oct 8, 2020 at 20:31
  • Maybe because isearch and fringe need to be set first?
    – choroba
    Oct 8, 2020 at 21:26
  • I thought that too, so I tried with with-eval-after-load 'isearch and the after-make-frame-functions hook but it didn't change anything. Oct 8, 2020 at 21:32
0

Update: Emacs 27 provides server-after-make-frame-hook, which makes it easier to copy face properties for client sessions.

(defun my-anzu-faces ()
  (face-spec-set 'anzu-mode-line `((t
                                    :foreground ,(face-attribute 'isearch :background)
                                    :background ,(face-attribute 'mode-line-inactive :background)))
                 'face-defface-spec))
(if (daemonp)
    (add-hook 'server-after-make-frame-hook #'my-anzu-faces)
  (my-anzu-faces))

This works for client sessions as well as stand-alone ones.


Well, it seemed that the problem was that the face properties which I wanted anzu-mode-line to take were still unspecified at the time of setting it, so I kept on messing around with hooks and with-eval-after-load until I came up with this

(add-hook 'after-make-frame-functions
          (lambda (frame)
            (with-selected-frame frame
              (face-spec-set 'anzu-mode-line `((t
                                                :foreground ,(face-attribute 'isearch :background)
                                                :background ,(face-attribute 'fringe :background)))
                             'face-defface-spec))))

As you can probably guess, I'm not sure it is the optimal solution, but it is a solution.

Your Answer

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

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