emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/swsw 48db8fe39b 021/146: Add a reference implementation fo


From: ELPA Syncer
Subject: [nongnu] elpa/swsw 48db8fe39b 021/146: Add a reference implementation for a conditional display function
Date: Wed, 25 May 2022 02:59:39 -0400 (EDT)

branch: elpa/swsw
commit 48db8fe39bd506eb6280158daec5599f96ca398c
Author: Daniel Semyonov <cmstr@dsemy.com>
Commit: Daniel Semyonov <cmstr@dsemy.com>

    Add a reference implementation for a conditional display function
    
    * swsw.el (swsw--mode-line-display, swsw--mode-line-hide): New
    functions performing operations common to both reference display
    functions.
    (swsw-mode-line-conditional-display-function): New reference
    conditional display function.
---
 swsw.el | 50 ++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/swsw.el b/swsw.el
index ca3d10d348..67afecf7d5 100644
--- a/swsw.el
+++ b/swsw.el
@@ -172,27 +172,49 @@ If set to `lighter', use the mode line lighter of 
`swsw-mode'"
 
 ;;;; Display functions:
 
+(defun swsw--mode-line-display ()
+  "Display window IDs at the beginning of the mode line."
+  (setq-default mode-line-format
+                `((swsw-mode
+                   (:eval (swsw-format-id (selected-window))))
+                  ,@(assq-delete-all
+                     `swsw-mode
+                     (default-value `mode-line-format))))
+  (force-mode-line-update t))
+
+(defun swsw--mode-line-hide ()
+  "Remove window IDs from the beginning of the mode line."
+  (setq-default mode-line-format
+                (assq-delete-all
+                 'swsw-mode
+                 (default-value 'mode-line-format)))
+  (force-mode-line-update t))
+
 (defun swsw-mode-line-display-function (switch)
-  "Display window IDs on the mode line if SWITCH is non-nil, and disable 
displaying
-window IDs on the mode line if SWITCH is nil.
+  "Display window IDs on the mode line if SWITCH is non-nil, and disable
+displaying window IDs on the mode line if SWITCH is nil.
+
+This display function shows the window IDs at the beginning of the mode line,
+similarly to `ace-window-display-mode'.
+This display function respects `swsw-id-format'."
+  (if switch
+      (swsw--mode-line-display)
+    (swsw--mode-line-hide)))
+
+(defun swsw-mode-line-conditional-display-function (switch)
+  "Display window IDs on the mode line if SWITCH is non-nil and a window
+selection is in progress, and disable
+displaying window IDs on the mode line if SWITCH is nil.
 
 This display function shows the window IDs at the beginning of the mode line,
 similarly to `ace-window-display-mode'.
 This display function respects `swsw-id-format'."
   (if switch
       (progn
-        (force-mode-line-update t)
-        (setq-default mode-line-format
-                      `((swsw-mode
-                         (:eval (swsw-format-id (selected-window))))
-                        ,@(assq-delete-all
-                           `swsw-mode
-                           (default-value `mode-line-format)))))
-    (force-mode-line-update t)
-    (setq-default mode-line-format
-                  (assq-delete-all
-                   'swsw-mode
-                   (default-value 'mode-line-format)))))
+        (add-hook 'swsw-before-select-hook #'swsw--mode-line-display)
+        (add-hook 'swsw-after-select-hook #'swsw--mode-line-hide))
+    (remove-hook 'swsw-before-select-hook #'swsw--mode-line-display)
+    (remove-hook 'swsw-after-select-hook #'swsw--mode-line-hide)))
 
 (provide 'swsw)
 



reply via email to

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