[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Custom mode-line format (bug)
From: |
Miguel Guedes |
Subject: |
Re: Custom mode-line format (bug) |
Date: |
21 Mar 2013 07:57:14 GMT |
User-agent: |
Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) |
Hi Michael,
On Wed, 20 Mar 2013 18:07:58 +0100, Michael Heerdegen wrote:
> No, that's not a bug. You set `mode-line-format' to a already formatted
> (calculated) mode-line, which is just a (constant) string. Note that
>
> (format-mode-line mode-line-format 'mode-line-custom-warning-face)
>
> is evaluated at load time.
>
> What you want is something like this:
>
> (defun root-file-warning ()
> (when (string-match "^/su\\(do\\)?:" default-directory)
> (setq mode-line-format
> `(:propertize ,mode-line-format face
> mode-line-custom-warning-face))
> (server-start-timed)
> ))
>
> But maybe it's better (cleaner) to use face-remapping for that purpose,
> instead of manipulating the mode-line:
>
> (defun root-file-warning ()
> (when (string-match "^/su\\(do\\)?:" default-directory)
> (face-remap-add-relative
> 'mode-line '(:background "dark red" :foreground "white"))
> (server-start-timed)))
>
> You could as well remap the `mode-line-inactive' face so that the
> mode-line looks different as well when the according window is not
> selected.
This solution of yours works absolutely beautiful; also thanks for the
explanation why it wasn't working.
Here's what I came up with in the end (added mode-line-inactive as per
your recommendation):
(defun root-file-warning ()
(when (string-match "^/su\\(do\\)?:" default-directory)
(face-remap-add-relative
'mode-line
'(:background "red3" :foreground "white"))
(face-remap-add-relative
'mode-line-inactive
'(:background "red4" :foreground "dark gray"))
)
Thanks for your help.