Update to Transient v0.4.3
This commit is contained in:
parent
31d3808fb9
commit
45cf3a0ced
2 changed files with 128 additions and 143 deletions
|
@ -31,7 +31,7 @@ General Public License for more details.
|
||||||
@finalout
|
@finalout
|
||||||
@titlepage
|
@titlepage
|
||||||
@title Transient User and Developer Manual
|
@title Transient User and Developer Manual
|
||||||
@subtitle for version 0.4.1
|
@subtitle for version 0.4.3
|
||||||
@author Jonas Bernoulli
|
@author Jonas Bernoulli
|
||||||
@page
|
@page
|
||||||
@vskip 0pt plus 1filll
|
@vskip 0pt plus 1filll
|
||||||
|
@ -74,7 +74,7 @@ that hurdle is Psionic K's interactive tutorial, available at
|
||||||
@end quotation
|
@end quotation
|
||||||
|
|
||||||
@noindent
|
@noindent
|
||||||
This manual is for Transient version 0.4.1.
|
This manual is for Transient version 0.4.3.
|
||||||
|
|
||||||
@insertcopying
|
@insertcopying
|
||||||
@end ifnottex
|
@end ifnottex
|
||||||
|
@ -248,17 +248,17 @@ When using Transient, one can call a command with arguments that are
|
||||||
just as complex as when calling the same function non-interactively
|
just as complex as when calling the same function non-interactively
|
||||||
from Lisp.
|
from Lisp.
|
||||||
|
|
||||||
Invoking a transient command with arguments is similar to invoking a
|
Invoking a transient suffix command with arguments is similar to
|
||||||
command in a shell with command-line completion and history enabled.
|
invoking a command in a shell with command-line completion and history
|
||||||
One benefit of the Transient interface is that it remembers history
|
enabled. One benefit of the Transient interface is that it remembers
|
||||||
not only on a global level (“this command was invoked using these
|
history not only on a global level (“this command was invoked using
|
||||||
arguments, and previously it was invoked using those other arguments”),
|
these arguments, and previously it was invoked using those other
|
||||||
but also remembers the values of individual arguments independently.
|
arguments”), but also remembers the values of individual arguments
|
||||||
@xref{Using History}.
|
independently. See @xref{Using History}.
|
||||||
|
|
||||||
After a transient prefix command is invoked, @kbd{C-h @var{KEY}} can be used to
|
After a transient prefix command is invoked, @kbd{C-h @var{KEY}} can be used to
|
||||||
show the documentation for the infix or suffix command that @kbd{@var{KEY}} is
|
show the documentation for the infix or suffix command that @kbd{@var{KEY}} is
|
||||||
bound to (@pxref{Getting Help for Suffix Commands}), and infixes and
|
bound to (see @ref{Getting Help for Suffix Commands}), and infixes and
|
||||||
suffixes can be removed from the transient using @kbd{C-x l @var{KEY}}. Infixes
|
suffixes can be removed from the transient using @kbd{C-x l @var{KEY}}. Infixes
|
||||||
and suffixes that are disabled by default can be enabled the same way.
|
and suffixes that are disabled by default can be enabled the same way.
|
||||||
@xref{Enabling and Disabling Suffixes}.
|
@xref{Enabling and Disabling Suffixes}.
|
||||||
|
@ -270,21 +270,26 @@ Additionally, Transient provides abstractions for defining new types,
|
||||||
which the author of Transient did not anticipate (or didn't get around
|
which the author of Transient did not anticipate (or didn't get around
|
||||||
to implementing yet).
|
to implementing yet).
|
||||||
|
|
||||||
|
Note that suffix commands also support regular prefix arguments. A
|
||||||
|
suffix command may even be called with both infix and prefix arguments
|
||||||
|
at the same time. If you invoke a command as a suffix of a transient
|
||||||
|
prefix command, but also want to pass prefix arguments to it, then
|
||||||
|
first invoke the prefix command, and only after doing that invoke the
|
||||||
|
prefix arguments, before finally invoking the suffix command. If you
|
||||||
|
instead began by providing the prefix arguments, then those would
|
||||||
|
apply to the prefix command, not the suffix command. Likewise, if you
|
||||||
|
want to change infix arguments before invoking a suffix command with
|
||||||
|
prefix arguments, then change the infix arguments before invoking the
|
||||||
|
prefix arguments. In other words, regular prefix arguments always
|
||||||
|
apply to the next command, and since transient prefix, infix and
|
||||||
|
suffix commands are just regular commands, the same applies to them.
|
||||||
|
(Regular prefix keys behave differently because they are not commands
|
||||||
|
at all, instead they are just incomplete key sequences, and those
|
||||||
|
cannot be interrupted with prefix commands.)
|
||||||
|
|
||||||
@node Usage
|
@node Usage
|
||||||
@chapter Usage
|
@chapter Usage
|
||||||
|
|
||||||
@menu
|
|
||||||
* Invoking Transients::
|
|
||||||
* Aborting and Resuming Transients::
|
|
||||||
* Common Suffix Commands::
|
|
||||||
* Saving Values::
|
|
||||||
* Using History::
|
|
||||||
* Getting Help for Suffix Commands::
|
|
||||||
* Enabling and Disabling Suffixes::
|
|
||||||
* Other Commands::
|
|
||||||
* Configuration::
|
|
||||||
@end menu
|
|
||||||
|
|
||||||
@node Invoking Transients
|
@node Invoking Transients
|
||||||
@section Invoking Transients
|
@section Invoking Transients
|
||||||
|
|
||||||
|
@ -997,14 +1002,6 @@ signal an error.
|
||||||
@node Defining New Commands
|
@node Defining New Commands
|
||||||
@chapter Defining New Commands
|
@chapter Defining New Commands
|
||||||
|
|
||||||
@menu
|
|
||||||
* Defining Transients::
|
|
||||||
* Binding Suffix and Infix Commands::
|
|
||||||
* Defining Suffix and Infix Commands::
|
|
||||||
* Using Infix Arguments::
|
|
||||||
* Transient State::
|
|
||||||
@end menu
|
|
||||||
|
|
||||||
@node Defining Transients
|
@node Defining Transients
|
||||||
@section Defining Transients
|
@section Defining Transients
|
||||||
|
|
||||||
|
@ -2234,11 +2231,6 @@ available depending on user preference.
|
||||||
@node Related Abstractions and Packages
|
@node Related Abstractions and Packages
|
||||||
@chapter Related Abstractions and Packages
|
@chapter Related Abstractions and Packages
|
||||||
|
|
||||||
@menu
|
|
||||||
* Comparison With Prefix Keys and Prefix Arguments::
|
|
||||||
* Comparison With Other Packages::
|
|
||||||
@end menu
|
|
||||||
|
|
||||||
@node Comparison With Prefix Keys and Prefix Arguments
|
@node Comparison With Prefix Keys and Prefix Arguments
|
||||||
@section Comparison With Prefix Keys and Prefix Arguments
|
@section Comparison With Prefix Keys and Prefix Arguments
|
||||||
|
|
||||||
|
@ -2559,8 +2551,6 @@ currently exist.
|
||||||
@node FAQ
|
@node FAQ
|
||||||
@appendix FAQ
|
@appendix FAQ
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@anchor{Can I control how the popup buffer is displayed?}
|
@anchor{Can I control how the popup buffer is displayed?}
|
||||||
@appendixsec Can I control how the popup buffer is displayed?
|
@appendixsec Can I control how the popup buffer is displayed?
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
;; URL: https://github.com/magit/transient
|
;; URL: https://github.com/magit/transient
|
||||||
;; Keywords: extensions
|
;; Keywords: extensions
|
||||||
|
|
||||||
;; Package-Version: 0.4.1
|
;; Package-Version: 0.4.3
|
||||||
;; Package-Requires: ((emacs "26.1"))
|
;; Package-Requires: ((emacs "26.1"))
|
||||||
|
|
||||||
;; SPDX-License-Identifier: GPL-3.0-or-later
|
;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
@ -67,6 +67,7 @@
|
||||||
|
|
||||||
(defvar display-line-numbers) ; since Emacs 26.1
|
(defvar display-line-numbers) ; since Emacs 26.1
|
||||||
(defvar Man-notify-method)
|
(defvar Man-notify-method)
|
||||||
|
(defvar pp-default-function) ; since Emacs 29.1
|
||||||
|
|
||||||
(defmacro transient--with-emergency-exit (&rest body)
|
(defmacro transient--with-emergency-exit (&rest body)
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
|
@ -565,7 +566,9 @@ the previous prefix."
|
||||||
(setq list (cl-sort (copy-sequence list) #'string< :key #'car))
|
(setq list (cl-sort (copy-sequence list) #'string< :key #'car))
|
||||||
(with-temp-file file
|
(with-temp-file file
|
||||||
(let ((print-level nil)
|
(let ((print-level nil)
|
||||||
(print-length nil))
|
(print-length nil)
|
||||||
|
(pp-default-function 'pp-28)
|
||||||
|
(fill-column 999))
|
||||||
(pp list (current-buffer)))))
|
(pp list (current-buffer)))))
|
||||||
|
|
||||||
(defvar transient-values
|
(defvar transient-values
|
||||||
|
@ -953,7 +956,7 @@ keyword.
|
||||||
(pcase-let ((`(,class ,slots ,_ ,docstr ,_)
|
(pcase-let ((`(,class ,slots ,_ ,docstr ,_)
|
||||||
(transient--expand-define-args args arglist)))
|
(transient--expand-define-args args arglist)))
|
||||||
`(progn
|
`(progn
|
||||||
(defalias ',name ,(transient--default-infix-command))
|
(defalias ',name #'transient--default-infix-command)
|
||||||
(put ',name 'interactive-only t)
|
(put ',name 'interactive-only t)
|
||||||
(put ',name 'command-modes (list 'not-a-mode))
|
(put ',name 'command-modes (list 'not-a-mode))
|
||||||
(put ',name 'function-documentation ,docstr)
|
(put ',name 'function-documentation ,docstr)
|
||||||
|
@ -969,6 +972,15 @@ example, sets a variable, use `transient-define-infix' instead.
|
||||||
|
|
||||||
\(fn NAME ARGLIST [DOCSTRING] [KEYWORD VALUE]...)")
|
\(fn NAME ARGLIST [DOCSTRING] [KEYWORD VALUE]...)")
|
||||||
|
|
||||||
|
(defun transient--default-infix-command ()
|
||||||
|
"Most transient infix commands are but an alias for this command."
|
||||||
|
(interactive)
|
||||||
|
(let ((obj (transient-suffix-object)))
|
||||||
|
(transient-infix-set obj (transient-infix-read obj)))
|
||||||
|
(transient--show))
|
||||||
|
(put 'transient--default-infix-command 'interactive-only t)
|
||||||
|
(put 'transient--default-infix-command 'command-modes (list 'not-a-mode))
|
||||||
|
|
||||||
(defun transient--expand-define-args (args &optional arglist)
|
(defun transient--expand-define-args (args &optional arglist)
|
||||||
(unless (listp arglist)
|
(unless (listp arglist)
|
||||||
(error "Mandatory ARGLIST is missing"))
|
(error "Mandatory ARGLIST is missing"))
|
||||||
|
@ -1071,11 +1083,16 @@ example, sets a variable, use `transient-define-infix' instead.
|
||||||
(if (and desc (or (stringp desc) (symbolp desc)))
|
(if (and desc (or (stringp desc) (symbolp desc)))
|
||||||
desc
|
desc
|
||||||
(plist-get args :key)))))))
|
(plist-get args :key)))))))
|
||||||
(setq args (plist-put args :command
|
(setq args (plist-put
|
||||||
`(defalias ',sym ,(macroexp-quote cmd))))))
|
args :command
|
||||||
|
`(prog1 ',sym
|
||||||
|
(put ',sym 'interactive-only t)
|
||||||
|
(put ',sym 'command-modes (list 'not-a-mode))
|
||||||
|
(defalias ',sym ,(macroexp-quote cmd)))))))
|
||||||
((or (stringp car)
|
((or (stringp car)
|
||||||
(and car (listp car)))
|
(and car (listp car)))
|
||||||
(let ((arg pop))
|
(let ((arg pop)
|
||||||
|
(sym nil))
|
||||||
(cl-typecase arg
|
(cl-typecase arg
|
||||||
(list
|
(list
|
||||||
(setq args (plist-put args :shortarg (car arg)))
|
(setq args (plist-put args :shortarg (car arg)))
|
||||||
|
@ -1085,9 +1102,13 @@ example, sets a variable, use `transient-define-infix' instead.
|
||||||
(when-let ((shortarg (transient--derive-shortarg arg)))
|
(when-let ((shortarg (transient--derive-shortarg arg)))
|
||||||
(setq args (plist-put args :shortarg shortarg)))
|
(setq args (plist-put args :shortarg shortarg)))
|
||||||
(setq args (plist-put args :argument arg))))
|
(setq args (plist-put args :argument arg))))
|
||||||
(setq args (plist-put args :command
|
(setq sym (intern (format "transient:%s:%s" prefix arg)))
|
||||||
(list 'quote (intern (format "transient:%s:%s"
|
(setq args (plist-put
|
||||||
prefix arg)))))
|
args :command
|
||||||
|
`(prog1 ',sym
|
||||||
|
(put ',sym 'interactive-only t)
|
||||||
|
(put ',sym 'command-modes (list 'not-a-mode))
|
||||||
|
(defalias ',sym #'transient--default-infix-command))))
|
||||||
(cond ((and car (not (keywordp car)))
|
(cond ((and car (not (keywordp car)))
|
||||||
(setq class 'transient-option)
|
(setq class 'transient-option)
|
||||||
(setq args (plist-put args :reader (macroexp-quote pop))))
|
(setq args (plist-put args :reader (macroexp-quote pop))))
|
||||||
|
@ -1116,26 +1137,6 @@ example, sets a variable, use `transient-define-infix' instead.
|
||||||
(macroexp-quote (or class 'transient-suffix))
|
(macroexp-quote (or class 'transient-suffix))
|
||||||
(cons 'list args))))
|
(cons 'list args))))
|
||||||
|
|
||||||
(defun transient--default-infix-command ()
|
|
||||||
(cons 'lambda
|
|
||||||
'(()
|
|
||||||
(interactive)
|
|
||||||
(let ((obj (transient-suffix-object)))
|
|
||||||
(transient-infix-set obj (transient-infix-read obj)))
|
|
||||||
(transient--show))))
|
|
||||||
|
|
||||||
(defun transient--ensure-infix-command (obj)
|
|
||||||
(let ((cmd (oref obj command)))
|
|
||||||
(unless (or (commandp cmd)
|
|
||||||
(get cmd 'transient--infix-command))
|
|
||||||
(if (or (cl-typep obj 'transient-switch)
|
|
||||||
(cl-typep obj 'transient-option))
|
|
||||||
(put cmd 'transient--infix-command
|
|
||||||
(transient--default-infix-command))
|
|
||||||
;; This is not an anonymous infix argument.
|
|
||||||
(when (transient--use-suffix-p obj)
|
|
||||||
(error "Suffix %s is not defined or autoloaded as a command" cmd))))))
|
|
||||||
|
|
||||||
(defun transient--derive-shortarg (arg)
|
(defun transient--derive-shortarg (arg)
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(and (string-match "\\`\\(-[a-zA-Z]\\)\\(\\'\\|=\\)" arg)
|
(and (string-match "\\`\\(-[a-zA-Z]\\)\\(\\'\\|=\\)" arg)
|
||||||
|
@ -1420,11 +1421,11 @@ Each suffix commands is associated with an object, which holds
|
||||||
additional information about the suffix, such as its value (in
|
additional information about the suffix, such as its value (in
|
||||||
the case of an infix command, which is a kind of suffix command).
|
the case of an infix command, which is a kind of suffix command).
|
||||||
|
|
||||||
This function is intended to be called by infix commands, whose
|
This function is intended to be called by infix commands, which
|
||||||
command definition usually (at least when defined using
|
are usually aliases of `transient--default-infix-command', which
|
||||||
`transient-define-infix') is this:
|
is defined like this:
|
||||||
|
|
||||||
(lambda ()
|
(defun transient--default-infix-command ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((obj (transient-suffix-object)))
|
(let ((obj (transient-suffix-object)))
|
||||||
(transient-infix-set obj (transient-infix-read obj)))
|
(transient-infix-set obj (transient-infix-read obj)))
|
||||||
|
@ -1441,7 +1442,7 @@ commands) may also need the object to guide their behavior.
|
||||||
This function attempts to return the object associated with the
|
This function attempts to return the object associated with the
|
||||||
current suffix command even if the suffix command was not invoked
|
current suffix command even if the suffix command was not invoked
|
||||||
from a transient. (For some suffix command that is a valid thing
|
from a transient. (For some suffix command that is a valid thing
|
||||||
to do, for others it is not.) In that case nil may be returned
|
to do, for others it is not.) In that case nil may be returned,
|
||||||
if the command was not defined using one of the macros intended
|
if the command was not defined using one of the macros intended
|
||||||
to define such commands.
|
to define such commands.
|
||||||
|
|
||||||
|
@ -1457,7 +1458,7 @@ probably use this instead:
|
||||||
(let ((suffixes
|
(let ((suffixes
|
||||||
(cl-remove-if-not
|
(cl-remove-if-not
|
||||||
(lambda (obj)
|
(lambda (obj)
|
||||||
(eq (transient--suffix-command obj)
|
(eq (oref obj command)
|
||||||
(or command
|
(or command
|
||||||
(if (eq this-command 'transient-set-level)
|
(if (eq this-command 'transient-set-level)
|
||||||
;; This is how it can look up for which
|
;; This is how it can look up for which
|
||||||
|
@ -1480,38 +1481,6 @@ probably use this instead:
|
||||||
(transient-init-value obj)
|
(transient-init-value obj)
|
||||||
obj)))
|
obj)))
|
||||||
|
|
||||||
(defun transient--suffix-command (object)
|
|
||||||
"Return the command represented by OBJECT.
|
|
||||||
|
|
||||||
If the value of OBJECT's `command' slot is a command, then return
|
|
||||||
that. Otherwise it is a symbol whose `transient--infix-command'
|
|
||||||
property holds an anonymous command, which is returned instead."
|
|
||||||
(cl-check-type object transient-suffix)
|
|
||||||
(let ((sym (oref object command)))
|
|
||||||
(if (commandp sym)
|
|
||||||
sym
|
|
||||||
(get sym 'transient--infix-command))))
|
|
||||||
|
|
||||||
(defun transient--suffix-symbol (arg)
|
|
||||||
"Return a symbol representing ARG.
|
|
||||||
|
|
||||||
ARG must be a command and/or a symbol. If it is a symbol,
|
|
||||||
then just return it. Otherwise return the symbol whose
|
|
||||||
`transient--infix-command' property's value is ARG."
|
|
||||||
(or (cl-typep arg 'command)
|
|
||||||
(cl-typep arg 'symbol)
|
|
||||||
(signal 'wrong-type-argument `((command symbol) ,arg)))
|
|
||||||
(if (symbolp arg)
|
|
||||||
arg
|
|
||||||
(let* ((obj (transient-suffix-object))
|
|
||||||
(sym (oref obj command)))
|
|
||||||
(if (eq (get sym 'transient--infix-command) arg)
|
|
||||||
sym
|
|
||||||
(catch 'found
|
|
||||||
(mapatoms (lambda (sym)
|
|
||||||
(when (eq (get sym 'transient--infix-command) arg)
|
|
||||||
(throw 'found sym)))))))))
|
|
||||||
|
|
||||||
;;; Keymaps
|
;;; Keymaps
|
||||||
|
|
||||||
(defvar-keymap transient-base-map
|
(defvar-keymap transient-base-map
|
||||||
|
@ -1709,7 +1678,7 @@ of the corresponding object."
|
||||||
(funcall transient-substitute-key-function obj)))
|
(funcall transient-substitute-key-function obj)))
|
||||||
(oset obj key key))
|
(oset obj key key))
|
||||||
(let ((kbd (kbd key))
|
(let ((kbd (kbd key))
|
||||||
(cmd (transient--suffix-command obj)))
|
(cmd (oref obj command)))
|
||||||
(when-let ((conflict (and transient-detect-key-conflicts
|
(when-let ((conflict (and transient-detect-key-conflicts
|
||||||
(transient--lookup-key map kbd))))
|
(transient--lookup-key map kbd))))
|
||||||
(unless (eq cmd conflict)
|
(unless (eq cmd conflict)
|
||||||
|
@ -1737,13 +1706,12 @@ of the corresponding object."
|
||||||
(keymap-set map "<handle-switch-frame>" #'transient--do-suspend))
|
(keymap-set map "<handle-switch-frame>" #'transient--do-suspend))
|
||||||
(dolist (obj transient--suffixes)
|
(dolist (obj transient--suffixes)
|
||||||
(let* ((cmd (oref obj command))
|
(let* ((cmd (oref obj command))
|
||||||
(sub-prefix (and (symbolp cmd) (get cmd 'transient--prefix) t))
|
(sub-prefix (and (symbolp cmd) (get cmd 'transient--prefix) t)))
|
||||||
(sym (transient--suffix-symbol cmd)))
|
|
||||||
(cond
|
(cond
|
||||||
((oref obj inapt)
|
((oref obj inapt)
|
||||||
(define-key map (vector sym) #'transient--do-warn-inapt))
|
(define-key map (vector cmd) #'transient--do-warn-inapt))
|
||||||
((slot-boundp obj 'transient)
|
((slot-boundp obj 'transient)
|
||||||
(define-key map (vector sym)
|
(define-key map (vector cmd)
|
||||||
(let ((do (oref obj transient)))
|
(let ((do (oref obj transient)))
|
||||||
(pcase (list do sub-prefix)
|
(pcase (list do sub-prefix)
|
||||||
('(t t) #'transient--do-recurse)
|
('(t t) #'transient--do-recurse)
|
||||||
|
@ -1753,8 +1721,8 @@ of the corresponding object."
|
||||||
('(nil t) #'transient--do-replace)
|
('(nil t) #'transient--do-replace)
|
||||||
('(nil nil) #'transient--do-exit)
|
('(nil nil) #'transient--do-exit)
|
||||||
(_ do)))))
|
(_ do)))))
|
||||||
((not (lookup-key transient-predicate-map (vector sym)))
|
((not (lookup-key transient-predicate-map (vector cmd)))
|
||||||
(define-key map (vector sym)
|
(define-key map (vector cmd)
|
||||||
(if sub-prefix
|
(if sub-prefix
|
||||||
#'transient--do-replace
|
#'transient--do-replace
|
||||||
(or (oref transient--prefix transient-suffix)
|
(or (oref transient--prefix transient-suffix)
|
||||||
|
@ -1904,21 +1872,28 @@ value. Otherwise return CHILDREN as is."
|
||||||
(defun transient--init-suffix (levels spec)
|
(defun transient--init-suffix (levels spec)
|
||||||
(pcase-let* ((`(,level ,class ,args) spec)
|
(pcase-let* ((`(,level ,class ,args) spec)
|
||||||
(cmd (plist-get args :command))
|
(cmd (plist-get args :command))
|
||||||
(level (or (alist-get (transient--suffix-symbol cmd) levels)
|
(level (or (alist-get cmd levels) level)))
|
||||||
level)))
|
|
||||||
(let ((fn (and (symbolp cmd)
|
(let ((fn (and (symbolp cmd)
|
||||||
(symbol-function cmd))))
|
(symbol-function cmd))))
|
||||||
(when (autoloadp fn)
|
(when (autoloadp fn)
|
||||||
(transient--debug " autoload %s" cmd)
|
(transient--debug " autoload %s" cmd)
|
||||||
(autoload-do-load fn)))
|
(autoload-do-load fn)))
|
||||||
(when (transient--use-level-p level)
|
(when (transient--use-level-p level)
|
||||||
(let ((obj (if-let ((proto (and cmd
|
(unless (and cmd (symbolp cmd))
|
||||||
(symbolp cmd)
|
(error "BUG: Non-symbolic suffix command: %s" cmd))
|
||||||
(get cmd 'transient--suffix))))
|
(let ((obj (if-let ((proto (get cmd 'transient--suffix)))
|
||||||
(apply #'clone proto :level level args)
|
(apply #'clone proto :level level args)
|
||||||
(apply class :level level args))))
|
(apply class :command cmd :level level args))))
|
||||||
|
(cond ((commandp cmd))
|
||||||
|
((or (cl-typep obj 'transient-switch)
|
||||||
|
(cl-typep obj 'transient-option))
|
||||||
|
;; As a temporary special case, if the package was compiled
|
||||||
|
;; with an older version of Transient, then we must define
|
||||||
|
;; "anonymous" switch and option commands here.
|
||||||
|
(defalias cmd #'transient--default-infix-command))
|
||||||
|
((transient--use-suffix-p obj)
|
||||||
|
(error "Suffix command %s is not defined or autoloaded" cmd)))
|
||||||
(transient--init-suffix-key obj)
|
(transient--init-suffix-key obj)
|
||||||
(transient--ensure-infix-command obj)
|
|
||||||
(when (transient--use-suffix-p obj)
|
(when (transient--use-suffix-p obj)
|
||||||
(if (transient--inapt-suffix-p obj)
|
(if (transient--inapt-suffix-p obj)
|
||||||
(oset obj inapt t)
|
(oset obj inapt t)
|
||||||
|
@ -2074,8 +2049,7 @@ value. Otherwise return CHILDREN as is."
|
||||||
|
|
||||||
(defun transient--get-predicate-for (cmd &optional suffix-only)
|
(defun transient--get-predicate-for (cmd &optional suffix-only)
|
||||||
(or (ignore-errors
|
(or (ignore-errors
|
||||||
(lookup-key transient--predicate-map
|
(lookup-key transient--predicate-map (vector cmd)))
|
||||||
(vector (transient--suffix-symbol cmd))))
|
|
||||||
(and (not suffix-only)
|
(and (not suffix-only)
|
||||||
(let ((pred (oref transient--prefix transient-non-suffix)))
|
(let ((pred (oref transient--prefix transient-non-suffix)))
|
||||||
(pcase pred
|
(pcase pred
|
||||||
|
@ -2189,6 +2163,37 @@ value. Otherwise return CHILDREN as is."
|
||||||
,@body)))
|
,@body)))
|
||||||
|
|
||||||
(defun transient--wrap-command ()
|
(defun transient--wrap-command ()
|
||||||
|
(if (>= emacs-major-version 30)
|
||||||
|
(transient--wrap-command-30)
|
||||||
|
(transient--wrap-command-29)))
|
||||||
|
|
||||||
|
(defun transient--wrap-command-30 ()
|
||||||
|
(letrec
|
||||||
|
((prefix transient--prefix)
|
||||||
|
(suffix this-command)
|
||||||
|
(advice (lambda (fn &rest args)
|
||||||
|
(interactive
|
||||||
|
(lambda (spec)
|
||||||
|
(let ((abort t))
|
||||||
|
(unwind-protect
|
||||||
|
(prog1 (advice-eval-interactive-spec spec)
|
||||||
|
(setq abort nil))
|
||||||
|
(when abort
|
||||||
|
(when-let ((unwind (oref prefix unwind-suffix)))
|
||||||
|
(transient--debug 'unwind-interactive)
|
||||||
|
(funcall unwind suffix))
|
||||||
|
(advice-remove suffix advice)
|
||||||
|
(oset prefix unwind-suffix nil))))))
|
||||||
|
(unwind-protect
|
||||||
|
(apply fn args)
|
||||||
|
(when-let ((unwind (oref prefix unwind-suffix)))
|
||||||
|
(transient--debug 'unwind-command)
|
||||||
|
(funcall unwind suffix))
|
||||||
|
(advice-remove suffix advice)
|
||||||
|
(oset prefix unwind-suffix nil)))))
|
||||||
|
(advice-add suffix :around advice '((depth . -99)))))
|
||||||
|
|
||||||
|
(defun transient--wrap-command-29 ()
|
||||||
(let* ((prefix transient--prefix)
|
(let* ((prefix transient--prefix)
|
||||||
(suffix this-command)
|
(suffix this-command)
|
||||||
(advice nil)
|
(advice nil)
|
||||||
|
@ -2202,9 +2207,7 @@ value. Otherwise return CHILDREN as is."
|
||||||
(when-let ((unwind (oref prefix unwind-suffix)))
|
(when-let ((unwind (oref prefix unwind-suffix)))
|
||||||
(transient--debug 'unwind-interactive)
|
(transient--debug 'unwind-interactive)
|
||||||
(funcall unwind suffix))
|
(funcall unwind suffix))
|
||||||
(if (symbolp suffix)
|
|
||||||
(advice-remove suffix advice)
|
(advice-remove suffix advice)
|
||||||
(remove-function suffix advice))
|
|
||||||
(oset prefix unwind-suffix nil))))))
|
(oset prefix unwind-suffix nil))))))
|
||||||
(advice-body
|
(advice-body
|
||||||
(lambda (fn &rest args)
|
(lambda (fn &rest args)
|
||||||
|
@ -2213,16 +2216,12 @@ value. Otherwise return CHILDREN as is."
|
||||||
(when-let ((unwind (oref prefix unwind-suffix)))
|
(when-let ((unwind (oref prefix unwind-suffix)))
|
||||||
(transient--debug 'unwind-command)
|
(transient--debug 'unwind-command)
|
||||||
(funcall unwind suffix))
|
(funcall unwind suffix))
|
||||||
(if (symbolp suffix)
|
|
||||||
(advice-remove suffix advice)
|
(advice-remove suffix advice)
|
||||||
(remove-function suffix advice))
|
|
||||||
(oset prefix unwind-suffix nil)))))
|
(oset prefix unwind-suffix nil)))))
|
||||||
(setq advice `(lambda (fn &rest args)
|
(setq advice `(lambda (fn &rest args)
|
||||||
(interactive ,advice-interactive)
|
(interactive ,advice-interactive)
|
||||||
(apply ',advice-body fn args)))
|
(apply ',advice-body fn args)))
|
||||||
(if (symbolp suffix)
|
(advice-add suffix :around advice '((depth . -99)))))
|
||||||
(advice-add suffix :around advice '((depth . -99)))
|
|
||||||
(add-function :around (var suffix) advice '((depth . -99))))))
|
|
||||||
|
|
||||||
(defun transient--premature-post-command ()
|
(defun transient--premature-post-command ()
|
||||||
(and (equal (this-command-keys-vector) [])
|
(and (equal (this-command-keys-vector) [])
|
||||||
|
@ -2343,7 +2342,7 @@ value. Otherwise return CHILDREN as is."
|
||||||
(if (symbolp arg)
|
(if (symbolp arg)
|
||||||
(message "-- %-22s (cmd: %s, event: %S, exit: %s%s)"
|
(message "-- %-22s (cmd: %s, event: %S, exit: %s%s)"
|
||||||
arg
|
arg
|
||||||
(or (ignore-errors (transient--suffix-symbol this-command))
|
(or (and (symbolp this-command) this-command)
|
||||||
(if (byte-code-function-p this-command)
|
(if (byte-code-function-p this-command)
|
||||||
"#[...]"
|
"#[...]"
|
||||||
this-command))
|
this-command))
|
||||||
|
@ -2526,12 +2525,9 @@ prefix argument and pivot to `transient-update'."
|
||||||
(propertize "?" 'face 'transient-key)
|
(propertize "?" 'face 'transient-key)
|
||||||
;; `this-command' is `transient-undefined' or `transient-inapt'.
|
;; `this-command' is `transient-undefined' or `transient-inapt'.
|
||||||
;; Show the command (`this-original-command') the user actually
|
;; Show the command (`this-original-command') the user actually
|
||||||
;; tried to invoke. For an anonymous inapt command that is a
|
;; tried to invoke.
|
||||||
;; lambda expression, which cannot be mapped to a symbol, so
|
(if-let ((cmd (or (ignore-errors (symbol-name this-original-command))
|
||||||
;; forgo displaying the command.
|
(ignore-errors (symbol-name this-command)))))
|
||||||
(if-let ((cmd (ignore-errors
|
|
||||||
(symbol-name (transient--suffix-symbol
|
|
||||||
this-original-command)))))
|
|
||||||
(format " [%s]" (propertize cmd 'face 'font-lock-warning-face))
|
(format " [%s]" (propertize cmd 'face 'font-lock-warning-face))
|
||||||
""))
|
""))
|
||||||
(unless (and transient--transient-map
|
(unless (and transient--transient-map
|
||||||
|
@ -2621,8 +2617,7 @@ transient is active."
|
||||||
(transient-suffix-object command)))
|
(transient-suffix-object command)))
|
||||||
(transient--show)
|
(transient--show)
|
||||||
(transient--read-number-N
|
(transient--read-number-N
|
||||||
(format "Set level for `%s': "
|
(format "Set level for `%s': " command)
|
||||||
(transient--suffix-symbol command))
|
|
||||||
nil nil (not (eq command prefix)))))))))))
|
nil nil (not (eq command prefix)))))))))))
|
||||||
(cond
|
(cond
|
||||||
((not command)
|
((not command)
|
||||||
|
@ -2631,7 +2626,7 @@ transient is active."
|
||||||
(level
|
(level
|
||||||
(let* ((prefix (oref transient--prefix command))
|
(let* ((prefix (oref transient--prefix command))
|
||||||
(alist (alist-get prefix transient-levels))
|
(alist (alist-get prefix transient-levels))
|
||||||
(sym (transient--suffix-symbol command)))
|
(sym command))
|
||||||
(if (eq command prefix)
|
(if (eq command prefix)
|
||||||
(progn (oset transient--prefix level level)
|
(progn (oset transient--prefix level level)
|
||||||
(setq sym t))
|
(setq sym t))
|
||||||
|
@ -3463,7 +3458,7 @@ Optional support for popup buttons is also implemented here."
|
||||||
(if transient-enable-popup-navigation
|
(if transient-enable-popup-navigation
|
||||||
(make-text-button str nil
|
(make-text-button str nil
|
||||||
'type 'transient
|
'type 'transient
|
||||||
'command (transient--suffix-command obj))
|
'command (oref obj command))
|
||||||
str)))
|
str)))
|
||||||
|
|
||||||
(cl-defmethod transient-format ((obj transient-infix))
|
(cl-defmethod transient-format ((obj transient-infix))
|
||||||
|
@ -3663,7 +3658,7 @@ that, else its name.
|
||||||
|
|
||||||
Intended to be temporarily used as the `:suffix-description' of
|
Intended to be temporarily used as the `:suffix-description' of
|
||||||
a prefix command, while porting a regular keymap to a transient."
|
a prefix command, while porting a regular keymap to a transient."
|
||||||
(let ((command (transient--suffix-symbol (oref obj command))))
|
(let ((command (oref obj command)))
|
||||||
(if-let ((doc (documentation command)))
|
(if-let ((doc (documentation command)))
|
||||||
(propertize (car (split-string doc "\n")) 'face 'font-lock-doc-face)
|
(propertize (car (split-string doc "\n")) 'face 'font-lock-doc-face)
|
||||||
(propertize (symbol-name command) 'face 'font-lock-function-name-face))))
|
(propertize (symbol-name command) 'face 'font-lock-function-name-face))))
|
||||||
|
@ -3691,7 +3686,7 @@ prefix method."
|
||||||
(cond
|
(cond
|
||||||
((eq this-command 'transient-help)
|
((eq this-command 'transient-help)
|
||||||
(transient-show-help transient--prefix))
|
(transient-show-help transient--prefix))
|
||||||
((let ((prefix (get (transient--suffix-command obj)
|
((let ((prefix (get (oref obj command)
|
||||||
'transient--prefix)))
|
'transient--prefix)))
|
||||||
(and prefix (not (eq (oref transient--prefix command) this-command))
|
(and prefix (not (eq (oref transient--prefix command) this-command))
|
||||||
(prog1 t (transient-show-help prefix)))))
|
(prog1 t (transient-show-help prefix)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue