Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

0 views
Skip to first unread message

Alexis

unread,
Feb 28, 2015, 5:49:35 AM2/28/15
to help-gnu-emacs

Hi all,

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. ....


Alexis.

Michael Heerdegen

unread,
Feb 28, 2015, 9:40:55 PM2/28/15
to help-gn...@gnu.org
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.


Alexis

unread,
Feb 28, 2015, 10:23:54 PM2/28/15
to help-gn...@gnu.org

On 2015-03-01T13:40:36+1100, Michael Heerdegen said:

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

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

Yes, your suggested approach did the trick. :-) Thank you, much
appreciated!


Alexis.

0 new messages