unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Propertize mode-line contents only for mode-line of selected window?
@ 2015-02-28 10:49 Alexis
  2015-03-01  2:40 ` Michael Heerdegen
  0 siblings, 1 reply; 3+ messages in thread
From: Alexis @ 2015-02-28 10:49 UTC (permalink / raw)
  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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Propertize mode-line contents only for mode-line of selected window?
  2015-02-28 10:49 Propertize mode-line contents only for mode-line of selected window? Alexis
@ 2015-03-01  2:40 ` Michael Heerdegen
  2015-03-01  3:23   ` Alexis
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Heerdegen @ 2015-03-01  2:40 UTC (permalink / raw)
  To: help-gnu-emacs

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.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Propertize mode-line contents only for mode-line of selected window?
  2015-03-01  2:40 ` Michael Heerdegen
@ 2015-03-01  3:23   ` Alexis
  0 siblings, 0 replies; 3+ messages in thread
From: Alexis @ 2015-03-01  3:23 UTC (permalink / raw)
  To: help-gnu-emacs


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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-01  3:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-28 10:49 Propertize mode-line contents only for mode-line of selected window? Alexis
2015-03-01  2:40 ` Michael Heerdegen
2015-03-01  3:23   ` Alexis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).