emacs-diffs
[Top][All Lists]
Advanced

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

master 8682756420: Add new function mode-line-window-selected-p


From: Lars Ingebrigtsen
Subject: master 8682756420: Add new function mode-line-window-selected-p
Date: Sat, 5 Feb 2022 16:46:39 -0500 (EST)

branch: master
commit 86827564208d93e243ee3cba7042f2d0ebd842b9
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new function mode-line-window-selected-p
    
    * doc/lispref/modes.texi (Mode Line Basics): Mention it (bug#53629).
    * lisp/bindings.el (mode-line-window-selected-p): New function
    from martin rudalics <rudalics@gmx.at>.
---
 doc/lispref/modes.texi | 22 ++++++++++++++++++++--
 etc/NEWS               |  6 ++++++
 lisp/bindings.el       | 12 ++++++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index e2b39836e6..2ef7de066f 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1964,8 +1964,26 @@ This function also forces an update of the menu bar and 
frame title.
 @end defun
 
   The selected window's mode line is usually displayed in a different
-color using the face @code{mode-line}.  Other windows' mode lines appear
-in the face @code{mode-line-inactive} instead.  @xref{Faces}.
+color using the face @code{mode-line-active}.  Other windows' mode
+lines appear in the face @code{mode-line-inactive} instead.
+@xref{Faces}.
+
+@defun mode-line-window-selected-p
+If you want to have more extensive differences between the mode lines
+in selected and non-selected windows, you can use this predicate in an
+@code{:eval} construct.  For instance, if you want to display the
+buffer name in bold in selected windows, but in italics in the other
+windows, you can say something like:
+
+@lisp
+(setq-default
+ mode-line-buffer-identification
+ '(:eval (propertize "%12b"
+                    'face (if (mode-line-window-selected-p)
+                              'bold
+                            'italic))))
+@end lisp
+@end defun
 
 @vindex mode-line-compact
   Some modes put a lot of data in the mode line, pushing elements at
diff --git a/etc/NEWS b/etc/NEWS
index ff9f22b6b0..e90cf19c16 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1035,6 +1035,12 @@ functions.
 
 * Lisp Changes in Emacs 29.1
 
++++
+** New utility predicate 'mode-line-window-selected-p'.
+This is meant to be used from ':eval' mode line constructs to create
+different mode line looks for selected and unselected windows.
+
++++
 ** New variable 'messages-buffer-name'.
 This variable (defaulting to "*Messages*") allows packages to override
 where messages are logged.
diff --git a/lisp/bindings.el b/lisp/bindings.el
index 86c0ea1a90..26b17035ef 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -654,6 +654,18 @@ By default, this shows the information specified by 
`global-mode-string'.")
   (with-selected-window (posn-window (event-start event))
     (previous-buffer)))
 
+(defun mode-line-window-selected-p ()
+  "Return non-nil if we're updating the mode line for the selected window.
+This function is meant to be called in `:eval' mode line
+constructs to allow altering the look of the mode line depending
+on whether the mode line belongs to the currently selected window
+or not."
+  (let ((window (selected-window)))
+    (or (eq window (old-selected-window))
+       (and (minibuffer-window-active-p (minibuffer-window))
+            (with-selected-window (minibuffer-window)
+              (eq window (minibuffer-selected-window)))))))
+
 (defmacro bound-and-true-p (var)
   "Return the value of symbol VAR if it is bound, else nil.
 Note that if `lexical-binding' is in effect, this function isn't



reply via email to

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