diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-02-08 23:06:34 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-02-09 15:30:30 -0700 |
commit | 7a04e5dc1b13565177d9bde9599b224f8f03a1f8 (patch) | |
tree | b446153b697999b022ee153d82b3d82f53b9354d /.emacs.d/site-lisp | |
parent | 326c0398fdf073fa273dce20119eb06ca242ff01 (diff) | |
download | dotfiles-7a04e5dc1b13565177d9bde9599b224f8f03a1f8.tar.gz |
transient-cycles: simplify cycling key defaults
Diffstat (limited to '.emacs.d/site-lisp')
-rw-r--r-- | .emacs.d/site-lisp/transient-cycles.el | 102 |
1 files changed, 59 insertions, 43 deletions
diff --git a/.emacs.d/site-lisp/transient-cycles.el b/.emacs.d/site-lisp/transient-cycles.el index 304ef33f..fb6c8a37 100644 --- a/.emacs.d/site-lisp/transient-cycles.el +++ b/.emacs.d/site-lisp/transient-cycles.el @@ -72,13 +72,13 @@ "Defaults when defining variants of commands with transient cycling." :group 'convenience) -(defcustom transient-cycles-default-cycle-backwards-key [up] +(defcustom transient-cycles-default-cycle-backwards-key [left] "Default key for cycling backwards in the transient maps set by commands augmented with transient cycling." :type 'key-sequence :group 'transient-cycles) -(defcustom transient-cycles-default-cycle-forwards-key [down] +(defcustom transient-cycles-default-cycle-forwards-key [right] "Default key for cycling forwards in the transient maps set by commands augmented with transient cycling." :type 'key-sequence @@ -86,7 +86,9 @@ commands augmented with transient cycling." (cl-defmacro transient-cycles-define-commands (bindings commands cycler-generator - &key on-exit cycle-forwards-key cycle-backwards-key + &key on-exit + (cycle-forwards-key transient-cycles-default-cycle-forwards-key) + (cycle-backwards-key transient-cycles-default-cycle-backwards-key) (keymap '(current-global-map))) "Define command variants closing over BINDINGS as specified by COMMANDS with transient cycling as supplied by CYCLER-GENERATOR. @@ -130,6 +132,15 @@ CYCLE-FORWARDS-KEY invokes the cycler with the numeric value of the prefix argument and CYCLE-BACKWARDS-KEY invokes the cycler with the numeric value of the prefix argument multiplied by -1. +CYCLE-FORWARDS-KEY and CYCLE-BACKWARDS-KEY are evaluated at the +time the transient map is established, so it is possible to +compute cycling keys from the binding used to invoke the command. +For example, for CYCLE-FORWARDS-KEY, you might have + + (cond ((memq last-command-event '(up down)) [down]) + ((memq last-command-event '(left right)) [right]) + (t transient-cycles-default-cycle-forwards-key)) + ON-EXIT, if present, is wrapped in a lambda expression with no arguments, i.e. (lambda () ON-EXIT), and passed as the third argument to `set-transient-map'." @@ -174,25 +185,11 @@ argument to `set-transient-map'." ;; For the forward direction we could elide this lambda and ;; just bind the key to the cycler. But this way means we are ;; consistent in always supplying an integer. - (define-key ,tmap - ,(or cycle-forwards-key - '(cond ((memq last-command-event '(up down)) - [down]) - ((memq last-command-event '(left right)) - [right]) - (t - transient-cycles-default-cycle-forwards-key))) + (define-key ,tmap ,cycle-forwards-key (lambda (,arg) (interactive "p") (funcall ,cycler ,arg))) - (define-key ,tmap - ,(or cycle-backwards-key - '(cond ((memq last-command-event '(up down)) - [up]) - ((memq last-command-event '(left right)) - [left]) - (t - transient-cycles-default-cycle-backwards-key))) + (define-key ,tmap ,cycle-backwards-key (lambda (,arg) (interactive "p") (funcall ,cycler (* -1 ,arg)))) @@ -313,14 +310,26 @@ major mode is one of the primary uses of indirect clones." (defvar transient-cycles-buffer-siblings-mode-map (make-sparse-keymap) "Keymap for `transient-cycles-buffer-siblings-mode'.") +(defcustom transient-cycles-buffer-siblings-cycle-backwards-key [left] + "Key to cycle backwards in the transient maps set by commands +augmented by `transient-cycles-buffer-siblings-mode'." + :type 'key-sequence + :group 'transient-cycles) + +(defcustom transient-cycles-buffer-siblings-cycle-forwards-key [right] + "Key to cycle forwards in the transient maps set by commands +augmented by `transient-cycles-buffer-siblings-mode'." + :type 'key-sequence + :group 'transient-cycles) + ;;;###autoload (define-minor-mode transient-cycles-buffer-siblings-mode "Augment a number of standard buffer switching commands with transient cycling through buffer siblings. After typing \\[switch-to-buffer], \\[display-buffer], \\[info] and some others, you can use the keys -`transient-cycles-default-cycle-backwards-key' and -`transient-cycles-default-cycle-forwards-key' to select a +`transient-cycles-buffer-siblings-cycle-backwards-key' and +`transient-cycles-buffer-siblings-cycle-forwards-key' to select a different, relevantly similar buffer to select or display instead. See `transient-cycles-buffer-siblings-ring' for details of the notion of similarity employed. @@ -335,13 +344,7 @@ always take you to `*info*', and if you use \\[switch-to-buffer] it might take you several tries to select the buffer you wanted. Thanks to this minor mode, after using either of those commands to switch to any `Info-mode' buffer you can quickly cycle through -to the intended target. - -If any of the commands augmented by this minor mode have been -rebound to key sequences ending in arrow keys, then the cycling -keys will be the corresponding pair of arrow keys. For example, -if you have rebound `switch-to-buffer' to a key sequence ending -in \\`<left>', then the cycling keys will be \\`<left>' and \\`<right>'." +to the intended target." :lighter nil :keymap transient-cycles-buffer-siblings-mode-map :global t :group 'transient-cycles) @@ -362,7 +365,9 @@ in \\`<left>', then the cycling keys will be \\`<left>' and \\`<right>'." :on-exit (progn (switch-to-buffer (current-buffer) nil t) (set-window-next-buffers nil nil) (set-window-prev-buffers nil prev-buffers)) - :keymap transient-cycles-buffer-siblings-mode-map) + :keymap transient-cycles-buffer-siblings-mode-map + :cycle-forwards-key transient-cycles-buffer-siblings-cycle-forwards-key + :cycle-backwards-key transient-cycles-buffer-siblings-cycle-backwards-key) ;; Here we don't try to restore the fundamental or frame buffer lists, but it ;; would be possible to do so. See (info "(elisp) Buffer List"). @@ -385,27 +390,36 @@ in \\`<left>', then the cycling keys will be \\`<left>' and \\`<right>'." (display-buffer buffer)))) :on-exit (progn (set-window-next-buffers window nil) (set-window-prev-buffers window prev-buffers)) - :keymap transient-cycles-buffer-siblings-mode-map) + :keymap transient-cycles-buffer-siblings-mode-map + :cycle-forwards-key transient-cycles-buffer-siblings-cycle-forwards-key + :cycle-backwards-key transient-cycles-buffer-siblings-cycle-backwards-key) (defvar transient-cycles-window-buffers-mode-map (make-sparse-keymap) "Keymap for `transient-cycles-window-buffers-mode'.") +(defcustom transient-cycles-window-buffers-cycle-backwards-key [left] + "Key to cycle backwards in the transient maps set by commands +augmented by `transient-cycles-window-buffers-mode'." + :type 'key-sequence + :group 'transient-cycles) + +(defcustom transient-cycles-window-buffers-cycle-forwards-key [right] + "Key to cycle forwards in the transient maps set by commands +augmented by `transient-cycles-window-buffers-mode'." + :type 'key-sequence + :group 'transient-cycles) + ;;;###autoload (define-minor-mode transient-cycles-window-buffers-mode "Augment \\[previous-buffer] and \\[next-buffer] with transient -cycling. After typing those commands, you can use the cycling -keys to move forwards and backwards in a virtual list of the -window's previous, current and next buffers. When transient -cycling completes, your starting point will be stored, such that +cycling. After typing those commands, you can use +`transient-cycles-window-buffers-cycle-backwards-key' and +`transient-cycles-window-buffers-cycle-forwards-key' to move +forwards and backwards in a virtual list of the window's +previous, current and next buffers. When transient cycling +completes, your starting point will be stored, such that \\[transient-cycles-window-buffers-back-and-forth] can quickly -take you back there. - -If either `previous-buffer' or `next-buffer' are bound to key -sequences ending in arrow keys, then the cycling keys will be the -corresponding pair of arrow keys. Thus, by default, the cycling -keys are \\`<left>' and \\`<right>'. Otherwise the fallbacks -`transient-cycles-default-cycle-backwards-key' and -`transient-cycles-default-cycle-forwards-key' are used." +take you back there." :lighter nil :keymap transient-cycles-window-buffers-mode-map :global t :group 'transient-cycles (if transient-cycles-window-buffers-mode @@ -455,7 +469,9 @@ keys are \\`<left>' and \\`<right>'. Otherwise the fallbacks :on-exit (setq param (if (and recent-buffer (zerop recent-buffer)) last-recent-buffer recent-buffer)) - :keymap transient-cycles-window-buffers-mode-map) + :keymap transient-cycles-window-buffers-mode-map + :cycle-forwards-key transient-cycles-window-buffers-cycle-forwards-key + :cycle-backwards-key transient-cycles-window-buffers-cycle-backwards-key) (defun transient-cycles--reset-window-recent-buffer (&rest _ignore) (setq param nil)) |