TransWikia.com

Coloured active mode line only when many windows

Emacs Asked by Toothrot on December 14, 2020

I am reluctantly using a coloured active mode line to
distinguish it from inactive mode lines, but it occurred to me
that it might be possible to reserve its colouring for times
when there are more than one window in the frame (when there
could be some doubt as to which is the active window). Any tips
on how to do this would be appreciated.

One Answer

Here is a slight varation of a previous answer of mine:

https://emacs.stackexchange.com/a/26345/2287

CAVEAT:  In addition to the buffer-list-update-hook, it may be helpful to add the function ml-update-all to additional hooks; e.g., it is possible to change the mode-line(s) and the color of the mini-buffer text when entering/exiting the mini-buffer ....

(defvar ml-selected-window nil "Doc-string.")

(defun ml-record-selected-window ()
  (setq ml-selected-window (selected-window)))

(defun ml-update-all ()
  (force-mode-line-update t))

(add-hook 'post-command-hook 'ml-record-selected-window)

(add-hook 'buffer-list-update-hook 'ml-update-all)

(setq-default mode-line-format
  '(:eval
      (cond
        ((and (eq ml-selected-window (selected-window))
              (one-window-p))
          (propertize "ACTIVE -- ONE (1) WINDOW" 'face '(:foreground "red")))
        ((and (eq ml-selected-window (selected-window))
              (not (one-window-p)))
          (propertize "ACTIVE -- MANY WINDOWS" 'face '(:foreground "blue")))
        (t
          "INACTIVE"))))

Here is a link to the opening thread on the Emacs Devel mailing list from 10/26/2019 entitled "Let mode-line packages distinguish the selected-window", wherein some of the thread participants provide Lisp variations (examples) to programmatically distinguish the selected window when the mode-line is updated:

https://lists.gnu.org/archive/html/emacs-devel/2019-10/msg01041.html

Answered by lawlist on December 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP