all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Let mode-line packages distinguish the selected-window
@ 2019-10-26 13:38 Jonas Bernoulli
  2019-10-26 14:01 ` Eli Zaretskii
  2019-10-26 16:36 ` Stefan Monnier
  0 siblings, 2 replies; 22+ messages in thread
From: Jonas Bernoulli @ 2019-10-26 13:38 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 840 bytes --]

By now there are quite a few packages that give the mode-line a more
"modern" look, including powerline, spaceline, doom-modeline, mood-line
and my moody.

  https://github.com/milkypostman/powerline
  https://github.com/TheBB/spaceline
  https://github.com/seagle0128/doom-modeline
  https://gitlab.com/jessieh/mood-line
  https://github.com/tarsius/moody

Something that many, if not all, of these packages have in common is
that they use images to give the mode-line a more "graphical" look.

The purely textual parts of the mode-line change their color based on
whether the respective window is the selected window by using one of
the faces mode-line or mode-line-inactive.

The colors of certain images also have to change based on whether the
window is selected or not.  Please look at the attached screenshot to
see why that is so.


[-- Attachment #2: mode-line-image-color.png --]
[-- Type: image/png, Size: 32235 bytes --]

[-- Attachment #3: Type: text/plain, Size: 2089 bytes --]


The problem is that the functions that are being called while the
mode-line-format is being processed cannot tell whether their window is
"the" selected window because *every* window is temporarily selected
before its mode-line-format is being processed.

To deal with this the packages mentioned above resort to using several
hook functions and advice to keep track of "the" selected window and
then they do something like:

  (eq (selected-window) remembered-selected-window)

Because keeping remembered-selected-window up-to-date involves several
hooks and advises this is rather ugly and fragile.  The value of
remembered-selected-window often isn't actually correct because getting
these hooks and advises right is hard and maybe even impossible.

For an example see for example:
https://github.com/milkypostman/powerline/blob/6ef4a06c3c583045accbc957b6f449b7c0c57cd8/powerline.el#L530-L584

It would be nice if Emacs could instead bind a variable that is
accessible from lisp to the window that will be the selected window
again once we are done updating the mode-line of this and other windows.

This should probably happen in display_mode_lines().  Actually this
function does already save the selected-window in another variable
before it changes the value of this variable, but it only does so for
its own use.

  Lisp_Object old_selected_window = selected_window;
  ...
  struct window *sel_w = XWINDOW (old_selected_window);

Later this function decides what face to use like so:

      /* Select mode line face based on the real selected window.  */
      display_mode_line (w, CURRENT_MODE_LINE_FACE_ID_3 (sel_w, sel_w, w),
			 NILP (window_mode_line_format)
			 ? BVAR (current_buffer, mode_line_format)
			 : window_mode_line_format);

The result of this decision unfortunately also isn't accessible from
lisp.

In summary, please add a way for functions that format elements of the
mode-line to determine whether these elements are going to be used in
the selected or some other window.  Maybe there is a better way to do
that than what I suggested above.

Thanks!
Jonas

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

end of thread, other threads:[~2019-10-30 16:10 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-26 13:38 Let mode-line packages distinguish the selected-window Jonas Bernoulli
2019-10-26 14:01 ` Eli Zaretskii
2019-10-26 21:10   ` martin rudalics
2019-10-27  5:01     ` Eli Zaretskii
2019-10-27  7:48       ` martin rudalics
2019-10-27 21:13     ` Jonas Bernoulli
2019-10-28  9:40       ` martin rudalics
2019-10-28 10:32         ` Jonas Bernoulli
2019-10-29  9:27           ` martin rudalics
2019-10-29 12:24             ` Eli Zaretskii
2019-10-29 18:05               ` martin rudalics
2019-10-29 18:46                 ` Eli Zaretskii
2019-10-30  8:14                   ` martin rudalics
2019-10-30 16:10                     ` Eli Zaretskii
2019-10-28 15:55       ` Eli Zaretskii
2019-10-29 11:50         ` Jonas Bernoulli
2019-10-26 16:36 ` Stefan Monnier
2019-10-26 19:27   ` Jonas Bernoulli
2019-10-26 19:41     ` Eli Zaretskii
2019-10-26 20:36     ` Stefan Monnier
2019-10-27 18:08       ` Jonas Bernoulli
2019-10-27 21:55         ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.