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

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

Re: Propertize mode-line contents only for mode-line of selected window?


From: Michael Heerdegen
Subject: Re: Propertize mode-line contents only for mode-line of selected window?
Date: Sun, 01 Mar 2015 03:40:36 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Alexis <flexibeast@gmail.com> writes:

> i'd like to modify the value of `mode-line-format` such that one
> specific part of it is propertized in a specific way only for the
> mode-line of the currently selected window. Is there some way of
> achieving this via ELisp?  i've not been able to make any progress on
> this with various permutations of `frame-selected-window`,
> `window-buffer`, `current-buffer` etc. ....

Yes, this will all not work.  The reason is that when any mode-line in
any window is refreshed, its window is internally temporarily selected.

So you will need to remember the selected window in a variable, or
something like that - here is an example:

--8<---------------cut here---------------start------------->8---
(defvar my-selected-win nil)

(defun my-set-selected-win ()
  (setq my-selected-win (selected-window)))

(add-hook 'post-command-hook
          #'my-set-selected-win)

(defun my-ml-emphasize-selected-window ()
  (and (eq (selected-window) my-selected-win) "!!!"))

;;; example
(push '(:eval (my-ml-emphasize-selected-window))
      (default-value 'mode-line-format))
--8<---------------cut here---------------end--------------->8---

Using `post-command-hook' seems a bit exaggerated, but
`window-configuration-change-hook' is not triggered for `other-window'
and the like, and advising `select-window' is also not an option because
of its internal use to calculate mode-lines of all windows.  Maybe it
can be done better, dunno.


Michael.




reply via email to

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