[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swsw 96809a6cae 019/146: Add the ability to change the way
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swsw 96809a6cae 019/146: Add the ability to change the way window IDs are displayed |
Date: |
Wed, 25 May 2022 02:59:39 -0400 (EDT) |
branch: elpa/swsw
commit 96809a6cae49cd156cbb699113356cbd63d7542a
Author: Daniel Semyonov <cmstr@dsemy.com>
Commit: Daniel Semyonov <cmstr@dsemy.com>
Add the ability to change the way window IDs are displayed
* swsw.el (swsw--set-display-function, swsw-display-function): Add
user option to change the function used to display window IDs.
(swsw-id-format): Rename from 'swsw-mode-line-format'.
(swsw-format-id): Rename from 'swsw-mode--lighter-format'.
(swsw-mode): Only display a mode line lighter when
'swsw-display-function' is set to 'lighter'. Enable/disable
'swsw-display-function' (when set to a function) when
enabling/disabling the mode, respectively.
(swsw-mode-line-display-function): New reference display function.
---
swsw.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 57 insertions(+), 7 deletions(-)
diff --git a/swsw.el b/swsw.el
index 137d06f5e3..1140c8a864 100644
--- a/swsw.el
+++ b/swsw.el
@@ -24,7 +24,8 @@
;;; Commentary:
;; swsw (simple window switching) provides a minor mode for switching
-;; windows using IDs shown on the mode line.
+;; windows using IDs assigned to them.
+;; Customize `swsw-display-function' to change how window IDs are displayed.
;;; Code:
@@ -45,8 +46,28 @@
:group 'swsw
:type '(character))
-(defcustom swsw-mode-lighter-format " <%s>"
- "Format string for the lighter of `swsw-mode'.
+(defun swsw--set-display-function (sym fun)
+ "Call the previous display function with nil as the sole argument (turning
+it off), set SYM's value to FUN, and call FUN with t as the sole argument."
+ (unless (or (not (boundp 'swsw-display-function))
+ (eq swsw-display-function 'lighter))
+ (funcall swsw-display-function nil))
+ (set-default sym fun)
+ (unless (eq fun 'lighter)
+ (funcall fun t)))
+
+(defcustom swsw-display-function 'lighter
+ "Function used to display the ID of each window.
+This function is called with t as the sole argument when enabling `swsw-mode',
+and with nil as the sole argument when disabling it.
+If set to `lighter', use the mode line lighter of `swsw-mode'"
+ :group 'swsw
+ :type '(radio (const :tag "Mode line lighter" lighter)
+ (function :tag "Display function"))
+ :set #'swsw--set-display-function)
+
+(defcustom swsw-id-format " <%s>"
+ "Format string for the window ID.
%s is replaced with a representation of the window's ID."
:group 'swsw
:type '(string))
@@ -99,23 +120,28 @@
(push (cons id window) swsw-window-list)
(set-window-parameter window 'swsw-id id))))
-(defun swsw-mode--lighter-format (window)
- "Format a `swsw-mode' mode line lighter for WINDOW."
- (format swsw-mode-lighter-format
+(defun swsw-format-id (window)
+ "Format an ID string for WINDOW."
+ (format swsw-id-format
(reverse (apply #'string (window-parameter window 'swsw-id)))))
;;;###autoload
(define-minor-mode swsw-mode
"Minor mode for selecting windows by their ID."
:global t
- :lighter (:eval (swsw-mode--lighter-format (selected-window)))
+ :lighter (:eval (when (eq swsw-display-function 'lighter)
+ (swsw-format-id (selected-window))))
:keymap (make-sparse-keymap)
(if swsw-mode
(progn
(swsw-update)
+ (unless (eq swsw-display-function 'lighter)
+ (funcall swsw-display-function t))
(add-hook 'window-configuration-change-hook #'swsw-update)
(add-hook 'minibuffer-setup-hook #'swsw-update)
(add-hook 'minibuffer-exit-hook #'swsw-update))
+ (unless (eq swsw-display-function 'lighter)
+ (funcall swsw-display-function nil))
(remove-hook 'window-configuration-change-hook #'swsw-update)
(remove-hook 'minibuffer-setup-hook #'swsw-update)
(remove-hook 'minibuffer-exit-hook #'swsw-update)))
@@ -142,6 +168,30 @@
(select-window window)))
(other-window 1)))
+;;;; Display functions:
+
+(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.
+
+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)))))
+
(provide 'swsw)
;; swsw.el ends here
- [nongnu] elpa/swsw 15e188aa17 009/146: Fix some edge cases related to the minibuffer, (continued)
- [nongnu] elpa/swsw 15e188aa17 009/146: Fix some edge cases related to the minibuffer, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 0aef3311c6 014/146: ; Bump to version 0.3, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 9873ff1bd2 020/146: * swsw.el (swsw-select): Add before and after hooks., ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 4a7ea31b37 036/146: * swsw.el (swsw-mode): Bind 'C-x o' to 'swsw-select', ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 63e295f599 025/146: Add a user option to customize the scope of window tracking, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 721d0208f7 026/146: Update the window list after deleting a frame, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 48db8fe39b 021/146: Add a reference implementation for a conditional display function, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 4c84ca310f 016/146: ; Update README to reflect recent changes, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw a816f208e9 005/146: Simplify the format of 'swsw-window-list', ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw f9a901c809 004/146: * swsw.el (swsw-id-chars-base): Remove erroneous quote, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 96809a6cae 019/146: Add the ability to change the way window IDs are displayed,
ELPA Syncer <=
- [nongnu] elpa/swsw c08a9b1e58 024/146: ; Fix a docstring, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw b6277eb31f 037/146: ; Indicate that version 1.1 is still in development in the NEWS file, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw a5b25e075f 032/146: Allow setting the scope to the selected frame, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 082e03382e 033/146: * swsw.el (swsw-select): Ensure 'swsw-after-select-hook' runs., ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 40f7a25f82 047/146: ; Add license information to the title page of the Info node, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 3a9848deac 042/146: Add an Info node for the package, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw c2c579a3c9 061/146: Construct multi-character IDs without pre-computing all possible IDs, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 7d82ffeef4 076/146: ; Small modifications to the NEWS file, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw 4ceacd0330 132/146: Indicate that some functions are for interactive use only, ELPA Syncer, 2022/05/25
- [nongnu] elpa/swsw eba70478e0 065/146: Update window information after 'swsw-scope' is customized, ELPA Syncer, 2022/05/25