emacs-devel
[Top][All Lists]
Advanced

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

Let mode-line packages distinguish the selected-window


From: Jonas Bernoulli
Subject: Let mode-line packages distinguish the selected-window
Date: Sat, 26 Oct 2019 15:38:19 +0200
User-agent: mu4e 1.1.0; emacs 27.0.50

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: mode-line-image-color.png
Description: PNG image

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

reply via email to

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