diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2022-01-28 14:23:47 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-01-29 16:58:47 -0700 |
commit | aeda967091739a4fc5c9f8f8aac51408014644c6 (patch) | |
tree | 5daaa9dfcc0ae1711d8115919312487db7799d5b /.emacs.d/site-lisp | |
parent | 76eb56c3a11d0e4336b2752685d5cd8021fbf3b7 (diff) | |
download | dotfiles-aeda967091739a4fc5c9f8f8aac51408014644c6.tar.gz |
introduce some abbreviated specifications for elements of COMMANDS
Diffstat (limited to '.emacs.d/site-lisp')
-rw-r--r-- | .emacs.d/site-lisp/transient-cycles.el | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/.emacs.d/site-lisp/transient-cycles.el b/.emacs.d/site-lisp/transient-cycles.el index 2ef3351b..08789259 100644 --- a/.emacs.d/site-lisp/transient-cycles.el +++ b/.emacs.d/site-lisp/transient-cycles.el @@ -95,14 +95,29 @@ storage is intended to last for the duration of transient cycling, and may be used for cycling state or to save values from before cycling began for restoration during ON-EXIT. -Each of COMMANDS defines a command variant, and should be of the -form (ORIGINAL ARGS [INTERACTIVE] &body BODY) where ORIGINAL -names the command for which a transient cycling variant should be -defined, and ARGS, INTERACTIVE and BODY are as in `lambda'. If -INTERACTIVE is absent then the newly defined command is given -ORIGINAL's interactive form. As a special case, if ORIGINAL is -of the form [remap COMMAND], then COMMAND is used as ORIGINAL and -[remap COMMAND] is bound to the command variant in KEYMAP. +Each of COMMANDS defines a command variant, and should be of one +of the following forms: + +1. (ORIGINAL ARGS [INTERACTIVE] &body BODY) + +2. ORIGINAL alone, which means + (ORIGINAL (&rest args) (apply ORIGINAL args)). + +ORIGINAL can have one of the following forms: + +a. a plain symbol + +b. a pair (KEY . ORIGINAL) where ORIGINAL is a symbol + +c. a vector [remap ORIGINAL] where ORIGINAL is a symbol, which + means ([remap ORIGINAL] . ORIGINAL). + +In each combination, ORIGINAL names the command for which a +transient cycling variant should be defined; ARGS, INTERACTIVE +and BODY are as in `lambda'; and KEY, if present, is a key +sequence to which the command should be bound in KEYMAP. If +INTERACTIVE is absent then the newly defined command receives +ORIGINAL's interactive form. CYCLER-GENERATOR defines a function which will be called with the return value of each command variant, and must return a function @@ -118,9 +133,21 @@ argument to `set-transient-map'." (macroexp-progn (cl-loop with on-exit = (and on-exit `(lambda () ,on-exit)) and arg = (gensym) and cycler = (gensym) and tmap = (gensym) - for (original args . body) in commands - for remap-p = (and (vectorp original) (eq 'remap (aref original 0))) - for original* = (if remap-p (aref original 1) original) + for command in commands + for (original args . body) + = (if (proper-list-p command) + command + (let ((f (cl-etypecase command + (symbol command) + (cons (cdr command)) + (vector (aref command 1))))) + `(,command (&rest args) (apply #',f args)))) + for (key . original*) = (cond ((symbolp original) + (cons nil original)) + ((and (vectorp original) + (eq 'remap (aref original 0))) + (cons original (aref original 1))) + (t original)) for name = (intern (format "transient-cycles--%s-with-transient-cycling" (symbol-name original*))) @@ -167,7 +194,7 @@ argument to `set-transient-map'." (interactive "p") (funcall ,cycler (* -1 ,arg)))) (set-transient-map ,tmap t ,on-exit)))) - when remap-p collect `(define-key ,keymap ,original #',name)))) + when key collect `(define-key ,keymap ,key #',name)))) (put 'transient-cycles-define-commands 'common-lisp-indent-function '(4 (&whole 2 &rest (&whole 1 4 &body)) &body)) |