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.

1 Answer 1


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


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
        ((and (eq ml-selected-window (selected-window))
          (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")))

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:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.