help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recognizing active/inactive mode-line in (:eval ...) form in mode-li


From: Michael Heerdegen
Subject: Re: Recognizing active/inactive mode-line in (:eval ...) form in mode-line-string
Date: Fri, 01 Mar 2013 20:21:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Alessandro Piras <laynor@gmail.com> writes:

> Is there a way to know if the mode-line is active in a (:eval ...)
> form inside the mode-line-string?
>
> A simple example:
> mode-line-string =>
>    ("%e" (:eval (if <condition> "foo" "bar")))
>
> I would like to see "foo" on the mode-line of the active window,
> "bar" on the others.

This is a very good question!

AFAICT, when the mode-line of any window is calculated, it is
temporarily selected.  This would mean that such a condition doesn't
exist.  So, you'll need some trick, e.g. something like

--8<---------------cut here---------------start------------->8---
(add-hook 'post-command-hook
          (lambda () (setq my-selected-window (selected-window))))

(push '(:eval (if (eq (selected-window) my-selected-window)
                  "foo" "bar")) default-mode-line-format)
--8<---------------cut here---------------end--------------->8---

i.e., try to remember and update the selected window in a global
variable.  Probably this can be achieved more elegantly than above.

Note that you still may have to force a mode-line update to always have
the right "foo" or "bar".


Regards,

Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]