aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2022-02-18 10:38:47 +0200
committerEli Zaretskii2022-02-18 10:38:49 +0200
commit2ed240296c181cc677caeef1ec33befd8428aa98 (patch)
tree8a7c5af3b20d468dadb6655b8a9827c6c9fc7813
parentb16aed76cb2e94dc5a8cb27ba574346a3931ca92 (diff)
parentc8442df581feb45d50530b372152beff9d23211d (diff)
downloademacs-2ed240296c181cc677caeef1ec33befd8428aa98.tar.gz
emacs-2ed240296c181cc677caeef1ec33befd8428aa98.zip
Merge from origin/emacs-28
c8442df ; Separate command and concept index in Transient manual 8aa052c ; Fix Transient manual 5b7752a Fix problem with popd for in remote shell buffers 38f6ea1 Import texi source file for transient manual df34929 Update to Org 9.5.2-15-gc5ceb6
-rw-r--r--doc/misc/Makefile.in4
-rw-r--r--doc/misc/transient.texi2560
-rw-r--r--lisp/org/ol-bibtex.el6
-rw-r--r--lisp/org/org-list.el2
-rw-r--r--lisp/org/org-version.el2
-rw-r--r--lisp/shell.el2
6 files changed, 2569 insertions, 7 deletions
diff --git a/doc/misc/Makefile.in b/doc/misc/Makefile.in
index d348dbc194b..5bd8f6a1518 100644
--- a/doc/misc/Makefile.in
+++ b/doc/misc/Makefile.in
@@ -73,8 +73,8 @@ INFO_COMMON = auth autotype bovine calc ccmode cl \
73 flymake forms gnus emacs-gnutls htmlfontify idlwave ido info.info \ 73 flymake forms gnus emacs-gnutls htmlfontify idlwave ido info.info \
74 mairix-el message mh-e modus-themes newsticker nxml-mode octave-mode \ 74 mairix-el message mh-e modus-themes newsticker nxml-mode octave-mode \
75 org pcl-cvs pgg rcirc remember reftex sasl \ 75 org pcl-cvs pgg rcirc remember reftex sasl \
76 sc semantic ses sieve smtpmail speedbar srecode todo-mode tramp \ 76 sc semantic ses sieve smtpmail speedbar srecode todo-mode transient \
77 url vhdl-mode vip viper widget wisent woman 77 tramp url vhdl-mode vip viper widget wisent woman
78 78
79## Info files to install on current platform. 79## Info files to install on current platform.
80INFO_INSTALL = $(INFO_COMMON) $(DOCMISC_W32) 80INFO_INSTALL = $(INFO_COMMON) $(DOCMISC_W32)
diff --git a/doc/misc/transient.texi b/doc/misc/transient.texi
new file mode 100644
index 00000000000..bf048841a65
--- /dev/null
+++ b/doc/misc/transient.texi
@@ -0,0 +1,2560 @@
1\input texinfo @c -*- texinfo -*-
2@c %**start of header
3@setfilename transient.info
4@settitle Transient User and Developer Manual
5@documentencoding UTF-8
6@documentlanguage en
7@c %**end of header
8
9@copying
10@quotation
11Copyright (C) 2018-2022 Free Software Foundation, Inc.
12
13You can redistribute this document and/or modify it under the terms
14of the GNU General Public License as published by the Free Software
15Foundation, either version 3 of the License, or (at your option) any
16later version.
17
18This document is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE@. See the GNU
21General Public License for more details.
22
23@end quotation
24@end copying
25
26@dircategory Emacs
27@direntry
28* Transient: (transient). Transient Commands.
29@end direntry
30
31@finalout
32@titlepage
33@title Transient User and Developer Manual
34@subtitle for version 0.3.7
35@author Jonas Bernoulli
36@page
37@vskip 0pt plus 1filll
38@insertcopying
39@end titlepage
40
41@contents
42
43@ifnottex
44@node Top
45@top Transient User and Developer Manual
46
47Taking inspiration from prefix keys and prefix arguments, Transient
48implements a similar abstraction involving a prefix command, infix
49arguments and suffix commands. We could call this abstraction a
50``transient command'', but because it always involves at least two
51commands (a prefix and a suffix) we prefer to call it just a
52``transient''.
53
54When the user calls a transient prefix command, a transient
55(temporary) keymap is activated, which binds the transient's infix
56and suffix commands, and functions that control the transient state
57are added to @code{pre-command-hook} and @code{post-command-hook}. The available
58suffix and infix commands and their state are shown in a popup buffer
59until the transient is exited by invoking a suffix command.
60
61Calling an infix command causes its value to be changed, possibly by
62reading a new value in the minibuffer.
63
64Calling a suffix command usually causes the transient to be exited
65but suffix commands can also be configured to not exit the transient.
66
67@noindent
68This manual is for Transient version 0.3.7.
69
70@insertcopying
71@end ifnottex
72
73@menu
74* Introduction::
75* Usage::
76* Modifying Existing Transients::
77* Defining New Commands::
78* Classes and Methods::
79* Related Abstractions and Packages::
80* FAQ::
81* Keystroke Index::
82* Command and Function Index::
83* Variable Index::
84* Concept Index::
85* GNU General Public License::
86
87@detailmenu
88--- The Detailed Node Listing ---
89
90Usage
91
92* Invoking Transients::
93* Aborting and Resuming Transients::
94* Common Suffix Commands::
95* Saving Values::
96* Using History::
97* Getting Help for Suffix Commands::
98* Enabling and Disabling Suffixes::
99* Other Commands::
100* Other Options::
101
102Defining New Commands
103
104* Defining Transients::
105* Binding Suffix and Infix Commands::
106* Defining Suffix and Infix Commands::
107* Using Infix Arguments::
108* Transient State::
109
110Binding Suffix and Infix Commands
111
112* Group Specifications::
113* Suffix Specifications::
114
115
116Classes and Methods
117
118* Group Classes::
119* Group Methods::
120* Prefix Classes::
121* Suffix Classes::
122* Suffix Methods::
123* Prefix Slots::
124* Suffix Slots::
125* Predicate Slots::
126
127Suffix Methods
128
129* Suffix Value Methods::
130* Suffix Format Methods::
131
132
133Related Abstractions and Packages
134
135* Comparison With Prefix Keys and Prefix Arguments::
136* Comparison With Other Packages::
137
138@end detailmenu
139@end menu
140
141@node Introduction
142@chapter Introduction
143
144Taking inspiration from prefix keys and prefix arguments, Transient
145implements a similar abstraction involving a prefix command, infix
146arguments and suffix commands. We could call this abstraction a
147``transient command'', but because it always involves at least two
148commands (a prefix and a suffix) we prefer to call it just a
149``transient''.
150
151@quotation
152Transient keymaps are a feature provided by Emacs. Transients as
153implemented by this package involve the use of transient keymaps.
154
155@cindex transient prefix command
156Emacs provides a feature that it calls @dfn{prefix commands}. When we
157talk about ``prefix commands'' in this manual, then we mean our own kind
158of ``prefix commands'', unless specified otherwise. To avoid ambiguity
159we sometimes use the terms @dfn{transient prefix command} for our kind and
160``regular prefix command'' for the Emacs' kind.
161
162@end quotation
163
164When the user calls a transient prefix command, a transient
165(temporary) keymap is activated, which binds the transient's infix and
166suffix commands, and functions that control the transient state are
167added to @code{pre-command-hook} and @code{post-command-hook}. The available suffix
168and infix commands and their state are shown in a popup buffer until
169the transient state is exited by invoking a suffix command.
170
171Calling an infix command causes its value to be changed. How that is
172done depends on the type of the infix command. The simplest case is
173an infix command that represents a command-line argument that does not
174take a value. Invoking such an infix command causes the switch to be
175toggled on or off. More complex infix commands may read a value from
176the user, using the minibuffer.
177
178Calling a suffix command usually causes the transient to be exited;
179the transient keymaps and hook functions are removed, the popup buffer
180no longer shows information about the (no longer bound) suffix
181commands, the values of some public global variables are set, while
182some internal global variables are unset, and finally the command is
183actually called. Suffix commands can also be configured to not exit
184the transient.
185
186A suffix command can, but does not have to, use the infix arguments in
187much the same way any command can choose to use or ignore the prefix
188arguments. For a suffix command that was invoked from a transient, the
189variable @code{transient-current-suffixes} and the function @code{transient-args}
190serve about the same purpose as the variables @code{prefix-arg} and
191@code{current-prefix-arg} do for any command that was called after the prefix
192arguments have been set using a command such as @code{universal-argument}.
193
194The information shown in the popup buffer while a transient is active
195looks a bit like this:
196
197@example
198,-----------------------------------------
199|Arguments
200| -f Force (--force)
201| -a Annotate (--annotate)
202|
203|Create
204| t tag
205| r release
206`-----------------------------------------
207@end example
208
209@quotation
210This is a simplified version of @code{magit-tag}. Info manuals do not
211support images or colored text, so the above ``screenshot'' lacks some
212information; in practice you would be able to tell whether the
213arguments @code{--force} and @code{--annotate} are enabled or not based on their
214color.
215
216@end quotation
217
218@cindex command dispatchers
219Transient can be used to implement simple ``command dispatchers''. The
220main benefit then is that the user can see all the available commands
221in a popup buffer. That is useful by itself because it frees the user
222from having to remember all the keys that are valid after a certain
223prefix key or command. Magit's @code{magit-dispatch} (on @code{C-x M-g}) command is
224an example of using Transient to merely implement a command
225dispatcher.
226
227In addition to that, Transient also allows users to interactively pass
228arguments to commands. These arguments can be much more complex than
229what is reasonable when using prefix arguments. There is a limit to
230how many aspects of a command can be controlled using prefix
231arguments. Furthermore, what a certain prefix argument means for
232different commands can be completely different, and users have to read
233documentation to learn and then commit to memory what a certain prefix
234argument means to a certain command.
235
236Transient suffix commands, on the other hand, can accept dozens of
237different arguments without the user having to remember anything.
238When using Transient, one can call a command with arguments that
239are just as complex as when calling the same function non-interactively
240from Lisp.
241
242Invoking a transient command with arguments is similar to invoking a
243command in a shell with command-line completion and history enabled.
244One benefit of the Transient interface is that it remembers history
245not only on a global level (``this command was invoked using these
246arguments, and previously it was invoked using those other arguments''),
247but also remembers the values of individual arguments independently.
248@xref{Using History}.
249
250After a transient prefix command is invoked, @kbd{C-h @var{key}} can be used to
251show the documentation for the infix or suffix command that @kbd{@var{key}} is
252bound to (@pxref{Getting Help for Suffix Commands}), and infixes and
253suffixes can be removed from the transient using @kbd{C-x l @var{key}}. Infixes
254and suffixes that are disabled by default can be enabled the same way.
255@xref{Enabling and Disabling Suffixes}.
256
257Transient ships with support for a few different types of specialized
258infix commands. A command that sets a command line option, for example,
259has different needs than a command that merely toggles a boolean flag.
260Additionally, Transient provides abstractions for defining new types,
261which the author of Transient did not anticipate (or didn't get around
262to implementing yet).
263
264@node Usage
265@chapter Usage
266
267@menu
268* Invoking Transients::
269* Aborting and Resuming Transients::
270* Common Suffix Commands::
271* Saving Values::
272* Using History::
273* Getting Help for Suffix Commands::
274* Enabling and Disabling Suffixes::
275* Other Commands::
276* Other Options::
277@end menu
278
279@node Invoking Transients
280@section Invoking Transients
281@cindex invoking transients
282
283A transient prefix command is invoked like any other command by
284pressing the key that is bound to that command. The main difference
285to other commands is that a transient prefix command activates a
286transient keymap, which temporarily binds the transient's infix and
287suffix commands. Bindings from other keymaps may, or may not, be
288disabled while the transient state is in effect.
289
290There are two kinds of commands that are available after invoking a
291transient prefix command; infix and suffix commands. Infix commands
292set some value (which is then shown in a popup buffer), without
293leaving the transient. Suffix commands, on the other hand, usually quit
294the transient and they may use the values set by the infix commands,
295i.e.@: the infix @strong{arguments}.
296
297Instead of setting arguments to be used by a suffix command, infix
298commands may also set some value by side-effect, e.g., by setting the
299value of some variable.
300
301@node Aborting and Resuming Transients
302@section Aborting and Resuming Transients
303@cindex aborting transients
304@cindex resuming transients
305
306@cindex quit transient
307To quit the transient without invoking a suffix command press @code{C-g}.
308
309Key bindings in transient keymaps may be longer than a single event.
310After pressing a valid prefix key, all commands whose bindings do not
311begin with that prefix key are temporarily unavailable and grayed out.
312To abort the prefix key press @kbd{C-g} (which in this case only quits the
313prefix key, but not the complete transient).
314
315A transient prefix command can be bound as a suffix of another
316transient. Invoking such a suffix replaces the current transient
317state with a new transient state, i.e.@: the available bindings change
318and the information displayed in the popup buffer is updated
319accordingly. Pressing @kbd{C-g} while a nested transient is active only
320quits the innermost transient, causing a return to the previous
321transient.
322
323@kbd{C-q} or @kbd{C-z} on the other hand always exits all transients. If you use
324the latter, then you can later resume the stack of transients using
325@kbd{M-x transient-resume}.
326
327@table @asis
328@kindex C-g
329@findex transient-quit-seq
330@item @kbd{C-g} @tie{}@tie{}@tie{}@tie{}(@code{transient-quit-seq})
331@kindex C-g
332@findex transient-quit-one
333@item @kbd{C-g} @tie{}@tie{}@tie{}@tie{}(@code{transient-quit-one})
334
335This key quits the currently active incomplete key sequence, if any,
336or else the current transient. When quitting the current transient,
337it returns to the previous transient, if any.
338@end table
339
340Transient's predecessor bound @kbd{q} instead of @kbd{C-g} to the quit command.
341To learn how to get that binding back see @code{transient-bind-q-to-quit}'s
342doc string.
343
344@table @asis
345@kindex C-q
346@findex transient-quit-all
347@item @kbd{C-q} @tie{}@tie{}@tie{}@tie{}(@code{transient-quit-all})
348
349This command quits the currently active incomplete key sequence, if
350any, and all transients, including the active transient and all
351suspended transients, if any.
352
353@kindex C-z
354@findex transient-suspend
355@item @kbd{C-z} @tie{}@tie{}@tie{}@tie{}(@code{transient-suspend})
356
357Like @code{transient-quit-all}, this command quits an incomplete key
358sequence, if any, and all transients. Additionally, it saves the
359stack of transients so that it can easily be resumed (which is
360particularly useful if you quickly need to do ``something else'', and
361the stack is deeper than a single transient, and/or you have already
362changed the values of some infix arguments).
363
364Note that only a single stack of transients can be saved at a time.
365If another stack is already saved, then saving a new stack discards
366the previous stack.
367
368@kindex M-x transient-resume
369@findex transient-resume
370@item @kbd{M-x transient-resume} @tie{}@tie{}@tie{}@tie{}(@code{transient-resume})
371
372This command resumes the previously suspended stack of transients,
373if any.
374@end table
375
376@node Common Suffix Commands
377@section Common Suffix Commands
378@cindex common suffix commands
379
380A few shared suffix commands are available in all transients. These
381suffix commands are not shown in the popup buffer by default.
382
383This includes the aborting commands mentioned in the previous section, as
384well as some other commands that are all bound to @kbd{C-x @var{key}}. After
385@kbd{C-x} is pressed, a section featuring all these common commands is
386temporarily shown in the popup buffer. After invoking one of them,
387the section disappears again. Note, however, that one of these commands
388is described as ``Show common permanently''; invoke that if you want the
389common commands to always be shown for all transients.
390
391@table @asis
392@kindex C-x t
393@findex transient-toggle-common
394@item @kbd{C-x t} @tie{}@tie{}@tie{}@tie{}(@code{transient-toggle-common})
395
396This command toggles whether the generic commands that are common to
397all transients are always displayed or only after typing the
398incomplete prefix key sequence @kbd{C-x}. This only affects the current
399Emacs session.
400
401@end table
402
403@defopt transient-show-common-commands
404
405This option controls whether shared suffix commands are shown
406alongside the transient-specific infix and suffix commands. By
407default, the shared commands are not shown to avoid overwhelming
408the user with too many options.
409
410While a transient is active, pressing @kbd{C-x} always shows the common
411commands. The value of this option can be changed for the current
412Emacs session by typing @kbd{C-x t} while a transient is active.
413@end defopt
414
415The other common commands are described in either the previous or
416in one of the following sections.
417
418Some of Transient's key bindings differ from the respective bindings
419of Magit-Popup; see @ref{FAQ} for more information.
420
421@node Saving Values
422@section Saving Values
423@cindex saving values of arguments
424
425After setting the infix arguments in a transient, the user can save
426those arguments for future invocations.
427
428Most transients will start out with the saved arguments when they are
429invoked. There are a few exceptions, though. Some transients are
430designed so that the value that they use is stored externally as the
431buffer-local value of some variable. Invoking such a transient again
432uses the buffer-local value.@footnote{
433@code{magit-diff} and @code{magit-log} are two prominent examples, and their
434handling of buffer-local values is actually a bit more complicated
435than outlined above and even customizable.}
436
437If the user does not save the value and just exits using a regular
438suffix command, then the value is merely saved to the transient's
439history. That value won't be used when the transient is next invoked,
440but it is easily accessible (@pxref{Using History}).
441
442@table @asis
443@kindex C-x s
444@findex transient-set
445@item @kbd{C-x s} @tie{}@tie{}@tie{}@tie{}(@code{transient-set})
446
447This command saves the value of the active transient for this Emacs
448session.
449
450@kindex C-x C-s
451@findex transient-save
452@item @kbd{C-x C-s} @tie{}@tie{}@tie{}@tie{}(@code{transient-save})
453
454Save the value of the active transient persistently across Emacs
455sessions.
456
457@end table
458
459@defopt transient-values-file
460
461This option names the file that is used to persist the values of
462transients between Emacs sessions.
463@end defopt
464
465@node Using History
466@section Using History
467@cindex value history
468
469Every time the user invokes a suffix command the transient's current
470value is saved to its history. These values can be cycled through the
471same way one can cycle through the history of commands that read
472user-input in the minibuffer.
473
474@table @asis
475@kindex C-M-p
476@findex transient-history-prev
477@item @kbd{C-M-p} @tie{}@tie{}@tie{}@tie{}(@code{transient-history-prev})
478@kindex C-x p
479@findex transient-history-prev
480@item @kbd{C-x p} @tie{}@tie{}@tie{}@tie{}(@code{transient-history-prev})
481
482This command switches to the previous value used for the active
483transient.
484
485@kindex C-M-n
486@findex transient-history-next
487@item @kbd{C-M-n} @tie{}@tie{}@tie{}@tie{}(@code{transient-history-next})
488@kindex C-x n
489@findex transient-history-next
490@item @kbd{C-x n} @tie{}@tie{}@tie{}@tie{}(@code{transient-history-next})
491
492This command switches to the next value used for the active
493transient.
494@end table
495
496In addition to the transient-wide history, Transient of course
497supports per-infix history. When an infix reads user-input using the
498minibuffer, the user can use the regular minibuffer history
499commands to cycle through previously used values. Usually the same
500keys as those mentioned above are bound to those commands.
501
502Authors of transients should arrange for different infix commands that
503read the same kind of value to also use the same history key
504(@pxref{Suffix Slots}).
505
506Both kinds of history are saved to a file when Emacs is exited.
507
508@defopt transient-history-file
509
510This option names the file that is used to persist the history of
511transients and their infixes between Emacs sessions.
512@end defopt
513
514@defopt transient-history-limit
515
516This option controls how many history elements are kept at the time
517the history is saved in @code{transient-history-file}.
518@end defopt
519
520@node Getting Help for Suffix Commands
521@section Getting Help for Suffix Commands
522@cindex getting help
523
524Transients can have many suffixes and infixes that the user might not
525be familiar with. To make it trivial to get help for these, Transient
526provides access to the documentation directly from the active
527transient.
528
529@table @asis
530@kindex C-h
531@findex transient-help
532@item @kbd{C-h} @tie{}@tie{}@tie{}@tie{}(@code{transient-help})
533
534This command enters help mode. When help mode is active,
535typing a key shows information about the suffix command that the key
536is normally bound to (instead of invoking it). Pressing @kbd{C-h} a
537second time shows information about the @emph{prefix} command.
538
539After typing a key, the stack of transient states is suspended and
540information about the suffix command is shown instead. Typing @kbd{q} in
541the help buffer buries that buffer and resumes the transient state.
542@end table
543
544What sort of documentation is shown depends on how the transient was
545defined. For infix commands that represent command-line arguments
546this ideally shows the appropriate manpage. @code{transient-help} then tries
547to jump to the correct location within that. Info manuals are also
548supported. The fallback is to show the command's doc string, for
549non-infix suffixes this is usually appropriate.
550
551@node Enabling and Disabling Suffixes
552@section Enabling and Disabling Suffixes
553@cindex enabling suffixes
554@cindex disabling suffixes
555
556The user base of a package that uses transients can be very diverse.
557This is certainly the case for Magit; some users have been using it and
558Git for a decade, while others are just getting started now.
559
560@cindex levels
561For that reason a mechanism is needed that authors can use to classify a
562transient's infixes and suffixes along the essentials@dots{}everything
563spectrum. We use the term @dfn{levels} to describe that mechanism.
564
565@cindex transient-level
566Each suffix command is placed on a level and each transient has a
567level (called @dfn{transient-level}), which controls which suffix commands
568are available. Integers between 1 and 7 (inclusive) are valid levels.
569For suffixes, 0 is also valid; it means that the suffix is not
570displayed at any level.
571
572The levels of individual transients and/or their individual suffixes
573can be changed interactively, by invoking the transient and then
574pressing @kbd{C-x l} to enter the ``edit'' mode, see below.
575
576The default level for both transients and their suffixes is 4. The
577@code{transient-default-level} option only controls the default for
578transients. The default suffix level is always 4. The authors of
579transients should place certain suffixes on a higher level, if they
580expect that it won't be of use to most users, and they should place
581very important suffixes on a lower level, so that they remain
582available even if the user lowers the transient level.
583
584@defopt transient-default-level
585
586This option controls which suffix levels are made available by
587default. It sets the transient-level for transients for which the
588user has not set that individually.
589@end defopt
590
591@defopt transient-levels-file
592
593This option names the file that is used to persist the levels of
594transients and their suffixes between Emacs sessions.
595@end defopt
596
597@table @asis
598@kindex C-x l
599@findex transient-set-level
600@item @kbd{C-x l} @tie{}@tie{}@tie{}@tie{}(@code{transient-set-level})
601
602This command enters edit mode. When edit mode is active, then all
603infixes and suffixes that are currently usable are displayed along
604with their levels. The colors of the levels indicate whether they
605are enabled or not. The level of the transient is also displayed
606along with some usage information.
607
608In edit mode, pressing the key that would usually invoke a certain
609suffix instead prompts the user for the level that suffix should be
610placed on.
611
612Help mode is available in edit mode.
613
614To change the transient level press @kbd{C-x l} again.
615
616To exit edit mode press @kbd{C-g}.
617
618Note that edit mode does not display any suffixes that are not
619currently usable. @code{magit-rebase}, for example, shows different suffixes
620depending on whether a rebase is already in progress or not. The
621predicates also apply in edit mode.
622
623Therefore, to control which suffixes are available given a certain
624state, you have to make sure that that state is currently active.
625@end table
626
627@node Other Commands
628@section Other Commands
629
630When invoking a transient in a small frame, the transient window may
631not show the complete buffer, making it necessary to scroll, using the
632following commands. These commands are never shown in the transient
633window, and the key bindings are the same as for @code{scroll-up-command} and
634@code{scroll-down-command} in other buffers.
635
636@findex transient-scroll-up arg
637@deffn Command transient-scroll-up arg
638
639This command scrolls text of transient popup window upward @var{arg}
640lines. If @var{arg} is @code{nil}, then it scrolls near full screen. This
641is a wrapper around @code{scroll-up-command} (which see).
642@end deffn
643
644@findex transient-scroll-down arg
645@deffn Command transient-scroll-down arg
646
647This command scrolls text of transient popup window down @var{arg}
648lines. If @var{arg} is @code{nil}, then it scrolls near full screen. This
649is a wrapper around @code{scroll-down-command} (which see).
650@end deffn
651
652@node Other Options
653@section Other Options
654
655@defopt transient-show-popup
656
657This option controls whether the current transient's infix and
658suffix commands are shown in the popup buffer.
659
660@itemize
661@item
662If @code{t} (the default) then the popup buffer is shown as soon as a
663transient prefix command is invoked.
664
665
666@item
667If @code{nil}, then the popup buffer is not shown unless the user
668explicitly requests it, by pressing an incomplete prefix key
669sequence.
670
671
672@item
673If a number, then the a brief one-line summary is shown instead of
674the popup buffer. If zero or negative, then not even that summary
675is shown; only the pressed key itself is shown.
676
677The popup is shown when the user explicitly requests it by
678pressing an incomplete prefix key sequence. Unless this is zero,
679the popup is shown after that many seconds of inactivity
680(using the absolute value).
681@end itemize
682@end defopt
683
684@defopt transient-enable-popup-navigation
685
686This option controls whether navigation commands are enabled in the
687transient popup buffer.
688
689While a transient is active the transient popup buffer is not the
690current buffer, making it necessary to use dedicated commands to act
691on that buffer itself. This is disabled by default. If this option
692is non-nil, then the following features are available:
693
694@itemize
695@item
696@key{UP} moves the cursor to the previous suffix.
697@key{DOWN} moves the cursor to the next suffix.
698@key{RET} invokes the suffix the cursor is on.
699
700@item
701@key{mouse-1} invokes the clicked on suffix.
702
703@item
704@kbd{C-s} and @kbd{C-r} start isearch in the popup buffer.
705@end itemize
706@end defopt
707
708@defopt transient-display-buffer-action
709
710This option specifies the action used to display the transient popup
711buffer. The transient popup buffer is displayed in a window using
712@code{(display-buffer @var{buffer} transient-display-buffer-action)}.
713
714The value of this option has the form @code{(@var{function} . @var{alist})},
715where @var{function} is a function or a list of functions. Each such
716function should accept two arguments: a buffer to display and an
717alist of the same form as @var{alist}. @xref{Choosing Window,,,elisp,},
718for details.
719
720The default is:
721
722@lisp
723(display-buffer-in-side-window
724 (side . bottom)
725 (inhibit-same-window . t)
726 (window-parameters (no-other-window . t)))
727@end lisp
728
729This displays the window at the bottom of the selected frame.
730Another useful @var{function} is @code{display-buffer-below-selected}, which
731is what @code{magit-popup} used by default. For more alternatives see
732@ref{Display Action Functions,,,elisp,}, and see @ref{Buffer Display
733Action Alists,,,elisp,}.
734
735Note that the buffer that was current before the transient buffer
736is shown should remain the current buffer. Many suffix commands
737act on the thing at point, if appropriate, and if the transient
738buffer became the current buffer, then that would change what is
739at point. To that effect @code{inhibit-same-window} ensures that the
740selected window is not used to show the transient buffer.
741
742It may be possible to display the window in another frame, but
743whether that works in practice depends on the window-manager.
744If the window manager selects the new window (Emacs frame),
745then that unfortunately changes which buffer is current.
746
747If you change the value of this option, then you might also
748want to change the value of @code{transient-mode-line-format}.
749@end defopt
750
751@defopt transient-mode-line-format
752
753This option controls whether the transient popup buffer has a
754mode-line, separator line, or neither.
755
756If @code{nil}, then the buffer has no mode-line. If the buffer is not
757displayed right above the echo area, then this probably is not a
758good value.
759
760If @code{line} (the default), then the buffer also has no mode-line, but a
761thin line is drawn instead, using the background color of the face
762@code{transient-separator}. Text-mode frames cannot display thin lines, and
763therefore fall back to treating @code{line} like @code{nil}.
764
765Otherwise this can be any mode-line format. @xref{Mode Line
766Format,,,elisp,}, for details.
767@end defopt
768
769@defopt transient-read-with-initial-input
770
771This option controls whether the last history element is used as the
772initial minibuffer input when reading the value of an infix argument
773from the user. If @code{nil}, there is no initial input and the first
774element has to be accessed the same way as the older elements.
775@end defopt
776
777@defopt transient-highlight-mismatched-keys
778
779This option controls whether key bindings of infix commands that do
780not match the respective command-line argument should be highlighted.
781For other infix commands this option has no effect.
782
783When this option is non-@code{nil}, the key binding for an infix argument
784is highlighted when only a long argument (e.g., @code{--verbose}) is
785specified but no shorthand (e.g., @code{-v}). In the rare case that a
786shorthand is specified but the key binding does not match, then it
787is highlighted differently.
788
789Highlighting mismatched key bindings is useful when learning the
790arguments of the underlying command-line tool; you wouldn't want to
791learn any short-hands that do not actually exist.
792
793The highlighting is done using one of the faces
794@code{transient-mismatched-key} and @code{transient-nonstandard-key}.
795@end defopt
796
797@defopt transient-substitute-key-function
798
799This function is used to modify key bindings. If the value of this
800option is @code{nil} (the default), then no substitution is performed.
801
802This function is called with one argument, the prefix object, and
803must return a key binding description, either the existing key
804description it finds in the @code{key} slot, or the key description that
805replaces the prefix key. It could be used to make other
806substitutions, but that is discouraged.
807
808For example, @kbd{=} is hard to reach using my custom keyboard layout,
809so I substitute @kbd{(} for that, which is easy to reach using a layout
810optimized for lisp.
811
812@lisp
813(setq transient-substitute-key-function
814 (lambda (obj)
815 (let ((key (oref obj key)))
816 (if (string-match "\\`\\(=\\)[a-zA-Z]" key)
817 (replace-match "(" t t key 1)
818 key))))
819@end lisp
820@end defopt
821
822@defopt transient-detect-key-conflicts
823
824This option controls whether key binding conflicts should be
825detected at the time the transient is invoked. If so, this
826results in an error, which prevents the transient from being used.
827Because of that, conflicts are ignored by default.
828
829Conflicts cannot be determined earlier, i.e.@: when the transient is
830being defined and when new suffixes are being added, because at that
831time there can be false-positives. It is actually valid for
832multiple suffixes to share a common key binding, provided the
833predicates of those suffixes prevent that more than one of them is
834enabled at a time.
835@end defopt
836
837@defopt transient-force-fixed-pitch
838
839This option controls whether to force the use of a monospaced font
840in popup buffer. Even if you use a proportional font for the
841@code{default} face, you might still want to use a monospaced font in
842transient's popup buffer. Setting this option to @code{t} causes @code{default}
843to be remapped to @code{fixed-pitch} in that buffer.
844@end defopt
845
846@node Modifying Existing Transients
847@chapter Modifying Existing Transients
848@cindex modifying existing transients
849
850To an extent, transients can be customized interactively, see @ref{Enabling and Disabling Suffixes}. This section explains how existing transients
851can be further modified non-interactively.
852
853The following functions share a few arguments:
854
855@itemize
856@item
857@var{prefix} is a transient prefix command, a symbol.
858
859
860@item
861@var{suffix} is a transient infix or suffix specification in the same form
862as expected by @code{transient-define-prefix}. Note that an infix is a
863special kind of suffix. Depending on context ``suffixes'' means
864``suffixes (including infixes)'' or ``non-infix suffixes''. Here it
865means the former. @xref{Suffix Specifications}.
866
867@var{suffix} may also be a group in the same form as expected by
868@code{transient-define-prefix}. @xref{Group Specifications}.
869
870
871@item
872@var{loc} is a command, a key vector, a key description (a string as
873returned by @code{key-description}), or a list specifying coordinates (the
874last element may also be a command or key). For example @code{(1 0 -1)}
875identifies the last suffix (@code{-1}) of the first subgroup (@code{0}) of the
876second group (@code{1}).
877
878If @var{loc} is a list of coordinates, then it can be used to identify a
879group, not just an individual suffix command.
880
881The function @code{transient-get-suffix} can be useful to determine whether
882a certain coordination list identifies the suffix or group that you
883expect it to identify. In hairy cases it may be necessary to look
884at the definition of the transient prefix command.
885@end itemize
886
887These functions operate on the information stored in the
888@code{transient--layout} property of the @var{prefix} symbol. Suffix entries in
889that tree are not objects but have the form @code{(@var{level}
890@var{class} @var{plist})}, where
891@var{plist} should set at least @code{:key}, @code{:description} and
892@code{:command}.
893
894@defun transient-insert-suffix prefix loc suffix
895
896This function inserts suffix or group @var{suffix} into @var{prefix}
897before @var{loc}.
898@end defun
899
900@defun transient-append-suffix prefix loc suffix
901
902This function inserts suffix or group @var{suffix} into @var{prefix}
903after @var{loc}.
904@end defun
905
906@defun transient-replace-suffix prefix loc suffix
907
908This function replaces the suffix or group at @var{loc} in @var{prefix} with
909suffix or group @var{suffix}.
910@end defun
911
912@defun transient-remove-suffix prefix loc
913
914This function removes the suffix or group at @var{loc} in @var{prefix}.
915@end defun
916
917@defun transient-get-suffix prefix loc
918
919This function returns the suffix or group at @var{loc} in @var{prefix}. The
920returned value has the form mentioned above.
921@end defun
922
923@defun transient-suffix-put prefix loc prop value
924
925This function edits the suffix or group at @var{loc} in @var{prefix},
926by setting the @var{prop} of its plist to @var{value}.
927@end defun
928
929Most of these functions do not signal an error if they cannot perform
930the requested modification. The functions that insert new suffixes
931show a warning if @var{loc} cannot be found in @var{prefix}, without
932signaling an error. The reason for doing it like this is that
933establishing a key binding (and that is what we essentially are trying
934to do here) should not prevent the rest of the configuration from
935loading. Among these functions only @code{transient-get-suffix} and
936@code{transient-suffix-put} may signal an error.
937
938@node Defining New Commands
939@chapter Defining New Commands
940
941@menu
942* Defining Transients::
943* Binding Suffix and Infix Commands::
944* Defining Suffix and Infix Commands::
945* Using Infix Arguments::
946* Transient State::
947@end menu
948
949@node Defining Transients
950@section Defining Transients
951
952A transient consists of a prefix command and at least one suffix
953command, though usually a transient has several infix and suffix
954commands. The below macro defines the transient prefix command @strong{and}
955binds the transient's infix and suffix commands. In other words, it
956defines the complete transient, not just the transient prefix command
957that is used to invoke that transient.
958
959@defmac transient-define-prefix name arglist [docstring] [keyword value]@dots{} group@dots{} [body@dots{}]
960
961This macro defines @var{name} as a transient prefix command and binds the
962transient's infix and suffix commands.
963
964@var{arglist} are the arguments that the prefix command takes.
965@var{docstring} is the documentation string and is optional.
966
967These arguments can optionally be followed by keyword-value pairs.
968Each key has to be a keyword symbol, either @code{:class} or a keyword
969argument supported by the constructor of that class. The
970@code{transient-prefix} class is used if the class is not specified
971explicitly.
972
973@var{group}s add key bindings for infix and suffix commands and specify
974how these bindings are presented in the popup buffer. At least one
975@var{group} has to be specified. @xref{Binding Suffix and Infix Commands}.
976
977The @var{body} is optional. If it is omitted, then @var{arglist} is ignored and
978the function definition becomes:
979
980@lisp
981(lambda ()
982 (interactive)
983 (transient-setup 'NAME))
984@end lisp
985
986If @var{body} is specified, then it must begin with an @code{interactive} form
987that matches @var{arglist}, and it must call @code{transient-setup}. It may,
988however, call that function only when some condition is satisfied.
989
990@cindex scope of a transient
991All transients have a (possibly @code{nil}) value, which is exported when
992suffix commands are called, so that they can consume that value.
993For some transients it might be necessary to have a sort of
994secondary value, called a ``scope''. Such a scope would usually be
995set in the command's @code{interactive} form and has to be passed to the
996setup function:
997
998@lisp
999(transient-setup 'NAME nil nil :scope SCOPE)
1000@end lisp
1001
1002For example, the scope of the @code{magit-branch-configure} transient is
1003the branch whose variables are being configured.
1004@end defmac
1005
1006@node Binding Suffix and Infix Commands
1007@section Binding Suffix and Infix Commands
1008
1009The macro @code{transient-define-prefix} is used to define a transient.
1010This defines the actual transient prefix command (@pxref{Defining
1011Transients}) and adds the transient's infix and suffix bindings, as
1012described below.
1013
1014Users and third-party packages can add additional bindings using
1015functions such as @code{transient-insert-suffix} (@pxref{Modifying
1016Existing Transients}). These functions take a ``suffix
1017specification'' as one of their arguments, which has the same form as
1018the specifications used in @code{transient-define-prefix}.
1019
1020@menu
1021* Group Specifications::
1022* Suffix Specifications::
1023@end menu
1024
1025@node Group Specifications
1026@subsection Group Specifications
1027@cindex group specifications
1028
1029The suffix and infix commands of a transient are organized in groups.
1030The grouping controls how the descriptions of the suffixes are
1031outlined visually but also makes it possible to set certain properties
1032for a set of suffixes.
1033
1034Several group classes exist, some of which organize suffixes in
1035subgroups. In most cases the class does not have to be specified
1036explicitly, but see @ref{Group Classes}.
1037
1038Groups are specified in the call to @code{transient-define-prefix}, using
1039vectors. Because groups are represented using vectors, we cannot use
1040square brackets to indicate an optional element and instead use curly
1041brackets to do the latter.
1042
1043Group specifications then have this form:
1044
1045@lisp
1046[@{@var{level}@} @{@var{description}@}
1047 @{@var{keyword} @var{value}@}...
1048 @var{element}...]
1049@end lisp
1050
1051The @var{level} is optional and defaults to 4. @xref{Enabling and
1052Disabling Suffixes}.
1053
1054The @var{description} is optional. If present, it is used as the heading of
1055the group.
1056
1057The @var{keyword}-@var{value} pairs are optional. Each keyword has to be a
1058keyword symbol, either @code{:class} or a keyword argument supported by the
1059constructor of that class.
1060
1061@itemize
1062@item
1063One of these keywords, @code{:description}, is equivalent to specifying
1064@var{description} at the very beginning of the vector. The recommendation
1065is to use @code{:description} if some other keyword is also used, for
1066consistency, or @var{description} otherwise, because it looks better.
1067
1068@item
1069Likewise @code{:level} is equivalent to @var{level}.
1070
1071@item
1072Other important keywords include the @code{:if...} keywords. These
1073keywords control whether the group is available in a certain
1074situation.
1075
1076For example, one group of the @code{magit-rebase} transient uses
1077@code{:if magit-rebase-in-progress-p}, which contains the suffixes
1078that are useful while rebase is already in progress; and another that uses
1079@code{:if-not magit-rebase-in-progress-p}, which contains the suffixes that
1080initiate a rebase.
1081
1082These predicates can also be used on individual suffixes and are
1083only documented once, see @ref{Predicate Slots}.
1084
1085@item
1086The value of @code{:hide}, if non-@code{nil}, is a predicate that controls
1087whether the group is hidden by default. The key bindings for
1088suffixes of a hidden group should all use the same prefix key.
1089Pressing that prefix key should temporarily show the group and its
1090suffixes, which assumes that a predicate like this is used:
1091
1092@lisp
1093(lambda ()
1094 (eq (car transient--redisplay-key)
1095 ?\C-c)) ; the prefix key shared by all bindings
1096@end lisp
1097
1098@item
1099The value of @code{:setup-children}, if non-@code{nil}, is a function
1100that takes two arguments the group object itself and a list of children.
1101The children are given as a, potentially empty, list consisting
1102of either group or suffix specifications. It can make arbitrary
1103changes to the children including constructing new children from
1104scratch. Also see @code{transient-setup-children}.
1105
1106@item
1107The boolean @code{:pad-keys} argument controls whether keys of all suffixes
1108contained in a group are right padded, effectively aligning the
1109descriptions.
1110@end itemize
1111
1112The @var{element}s are either all subgroups (vectors), or all suffixes
1113(lists) and strings. (At least currently no group type exists that
1114would allow mixing subgroups with commands at the same level, though
1115in principle there is nothing that prevents that.)
1116
1117If the @var{element}s are not subgroups, then they can be a mixture of lists
1118that specify commands and strings. Strings are inserted verbatim.
1119The empty string can be used to insert gaps between suffixes, which is
1120particularly useful if the suffixes are outlined as a table.
1121
1122Variables are supported inside group specifications. For example in
1123place of a direct subgroup specification, a variable can be used whose
1124value is a vector that qualifies as a group specification. Likewise, a
1125variable can be used where a suffix specification is expected. Lists
1126of group or suffix specifications are also supported. Indirect
1127specifications are resolved when the transient prefix is being
1128defined.
1129
1130The form of suffix specifications is documented in the next node.
1131
1132@node Suffix Specifications
1133@subsection Suffix Specifications
1134@cindex suffix specifications
1135
1136A transient's suffix and infix commands are bound when the transient
1137prefix command is defined using @code{transient-define-prefix}, see
1138@ref{Defining Transients}. The commands are organized into groups, see
1139@ref{Group Specifications}. Here we describe the form used to bind an
1140individual suffix command.
1141
1142The same form is also used when later binding additional commands
1143using functions such as @code{transient-insert-suffix},
1144see @ref{Modifying Existing Transients}.
1145
1146Note that an infix is a special kind of suffix. Depending on context
1147``suffixes'' means ``suffixes (including infixes)'' or ``non-infix
1148suffixes''. Here it means the former.
1149
1150Suffix specifications have this form:
1151
1152@lisp
1153([@var{level}]
1154 [@var{key}] [@var{description}]
1155 @var{command}|@var{argument} [@var{keyword} @var{value}]...)
1156@end lisp
1157
1158@var{level}, @var{key} and @var{description} can also be specified using the @var{keyword}s
1159@code{:level}, @code{:key} and @code{:description}. If the object that is associated with
1160@var{command} sets these properties, then they do not have to be specified
1161here. You can however specify them here anyway, possibly overriding
1162the object's values just for the binding inside this transient.
1163
1164@itemize
1165@item
1166@var{level} is the suffix level, an integer between 1 and 7.
1167@xref{Enabling and Disabling Suffixes}.
1168
1169@item
1170@var{key} is the key binding, either a vector or key description string.
1171
1172@item
1173@var{description} is the description, either a string or a function that
1174returns a string. The function should be a lambda expression to
1175avoid ambiguity. In some cases a symbol that is bound as a function
1176would also work but to be safe you should use @code{:description} in that
1177case.
1178@end itemize
1179
1180The next element is either a command or an argument. This is the only
1181argument that is mandatory in all cases.
1182
1183@itemize
1184@item
1185Usually @var{command} is a symbol that is bound as a function, which has
1186to be defined or at least autoloaded as a command by the time the
1187containing prefix command is invoked.
1188
1189Any command will do; it does not need to have an object associated
1190with it (as would be the case if @code{transient-define-suffix} or
1191@code{transient-define-infix} were used to define it).
1192
1193The command can also be a closure or lambda expression, but that
1194should only be used for dynamic transients whose suffixes are
1195defined when the prefix command is invoked. See information about
1196the @code{:setup-children} function in @ref{Group Specifications}.
1197
1198As mentioned above, the object that is associated with a command can
1199be used to set the default for certain values that otherwise have to
1200be set in the suffix specification. Therefore if there is no object,
1201then you have to make sure to specify the @var{key} and the @var{description}.
1202
1203As a special case, if you want to add a command that might be neither
1204defined nor autoloaded, you can use a workaround like:
1205
1206@lisp
1207(transient-insert-suffix 'some-prefix "k"
1208 '("!" "Ceci n'est pas une commande" no-command
1209 :if (lambda () (featurep 'no-library))))
1210@end lisp
1211
1212Instead of @code{featurep} you could also use @code{require} with a
1213non-nil value for @var{noerror}.
1214
1215@item
1216The mandatory argument can also be a command-line argument, a
1217string. In that case an anonymous command is defined and bound.
1218
1219Instead of a string, this can also be a list of two strings, in
1220which case the first string is used as the short argument (which can
1221also be specified using @code{:shortarg}) and the second as the long argument
1222(which can also be specified using @code{:argument}).
1223
1224Only the long argument is displayed in the popup buffer. See
1225@code{transient-detect-key-conflicts} for how the short argument may be
1226used.
1227
1228Unless the class is specified explicitly, the appropriate class is
1229guessed based on the long argument. If the argument ends with @samp{=}
1230(e.g. @samp{--format=}) then @code{transient-option} is used, otherwise
1231@code{transient-switch}.
1232@end itemize
1233
1234Finally, details can be specified using optional
1235@var{keyword}-@var{value} pairs.
1236Each keyword has to be a keyword symbol, either @code{:class} or a keyword
1237argument supported by the constructor of that class. See @ref{Suffix Slots}.
1238
1239@node Defining Suffix and Infix Commands
1240@section Defining Suffix and Infix Commands
1241@cindex defining suffix commands
1242@cindex defining infix commands
1243
1244Note that an infix is a special kind of suffix. Depending on context
1245``suffixes'' means ``suffixes (including infixes)'' or ``non-infix
1246suffixes''.
1247
1248@defmac transient-define-suffix name arglist [docstring] [keyword value]@dots{} body@dots{}
1249
1250This macro defines @var{name} as a transient suffix command.
1251
1252@var{arglist} are the arguments that the command takes.
1253@var{docstring} is the documentation string and is optional.
1254
1255These arguments can optionally be followed by keyword-value pairs.
1256Each keyword has to be a keyword symbol, either @code{:class} or a keyword
1257argument supported by the constructor of that class. The
1258@code{transient-suffix} class is used if the class is not specified
1259explicitly.
1260
1261The @var{body} must begin with an @code{interactive} form that matches @var{arglist}.
1262The infix arguments are usually accessed by using @code{transient-args}
1263inside @code{interactive}.
1264@end defmac
1265
1266@defmac transient-define-infix name arglist [docstring] [keyword value]@dots{}
1267
1268This macro defines @var{name} as a transient infix command.
1269
1270@var{arglist} is always ignored (but mandatory never-the-less) and
1271reserved for future use. @var{docstring} is the documentation string and
1272is optional.
1273
1274The keyword-value pairs are mandatory. All transient infix commands
1275are @code{equal} to each other (but not @code{eq}), so it is meaningless to define
1276an infix command without also setting at least @code{:class} and one other
1277keyword (which it is depends on the used class, usually @code{:argument} or
1278@code{:variable}).
1279
1280Each keyword has to be a keyword symbol, either @code{:class} or a keyword
1281argument supported by the constructor of that class. The
1282@code{transient-switch} class is used if the class is not specified
1283explicitly.
1284
1285The function definition is always:
1286
1287@lisp
1288(lambda ()
1289 (interactive)
1290 (let ((obj (transient-suffix-object)))
1291 (transient-infix-set obj (transient-infix-read obj)))
1292 (transient--show))
1293@end lisp
1294
1295@code{transient-infix-read} and @code{transient-infix-set} are generic functions.
1296Different infix commands behave differently because the concrete
1297methods are different for different infix command classes. In rare
1298cases the above command function might not be suitable, even if you
1299define your own infix command class. In that case you have to use
1300@code{transient-suffix-command} to define the infix command and use @code{t} as
1301the value of the @code{:transient} keyword.
1302@end defmac
1303
1304@defmac transient-define-argument name arglist [docstring] [keyword value]@dots{}
1305
1306This macro defines @var{name} as a transient infix command.
1307
1308This is an alias for @code{transient-define-infix}. Only use this alias
1309to define an infix command that actually sets an infix argument.
1310To define an infix command that, for example, sets a variable, use
1311@code{transient-define-infix} instead.
1312@end defmac
1313
1314@node Using Infix Arguments
1315@section Using Infix Arguments
1316@cindex using infix arguments
1317
1318The functions and the variables described below allow suffix commands
1319to access the value of the transient from which they were invoked;
1320which is the value of its infix arguments. These variables are set
1321when the user invokes a suffix command that exits the transient, but
1322before actually calling the command.
1323
1324When returning to the command-loop after calling the suffix command,
1325the arguments are reset to @code{nil} (which causes the function to return
1326@code{nil} too).
1327
1328Like for Emacs' prefix arguments, it is advisable, but not mandatory,
1329to access the infix arguments inside the command's @code{interactive} form.
1330The preferred way of doing that is to call the @code{transient-args}
1331function, which for infix arguments serves about the same purpose as
1332@code{prefix-arg} serves for prefix arguments.
1333
1334@defun transient-args prefix
1335
1336This function returns the value of the transient prefix command
1337@var{prefix}.
1338
1339If the current command was invoked from the transient prefix command
1340@var{prefix}, then it returns the active infix arguments. If the current
1341command was not invoked from @var{prefix}, then it returns the set, saved
1342or default value for @var{prefix}.
1343@end defun
1344
1345@defun transient-arg-value arg args
1346
1347This function return the value of @var{arg} as it appears in @var{args}.
1348
1349For a switch a boolean is returned. For an option the value is
1350returned as a string, using the empty string for the empty value,
1351or @code{nil} if the option does not appear in @var{args}.
1352@end defun
1353
1354@defun transient-suffixes prefix
1355
1356This function returns the suffixes of the transient prefix command
1357@var{prefix}. This is a list of objects. This function should only be
1358used if you need the objects (as opposed to just their values) and
1359if the current command is not being invoked from @var{prefix}.
1360@end defun
1361
1362@defvar transient-current-suffixes
1363
1364The suffixes of the transient from which this suffix command was
1365invoked. This is a list of objects. Usually it is sufficient to
1366instead use the function @code{transient-args}, which returns a list of
1367values. In complex cases it might be necessary to use this variable
1368instead, i.e.@: if you need access to information beside the value.
1369@end defvar
1370
1371@defvar transient-current-prefix
1372
1373The transient from which this suffix command was invoked. The
1374returned value is a @code{transient-prefix} object, which holds information
1375associated with the transient prefix command.
1376@end defvar
1377
1378@defvar transient-current-command
1379
1380The transient from which this suffix command was invoked. The
1381returned value is a symbol, the transient prefix command.
1382@end defvar
1383
1384@node Transient State
1385@section Transient State
1386@cindex transient state
1387
1388Invoking a transient prefix command ``activates'' the respective
1389transient, i.e.@: it puts a transient keymap into effect, which binds
1390the transient's infix and suffix commands.
1391
1392The default behavior while a transient is active is as follows:
1393
1394@itemize
1395@item
1396Invoking an infix command does not affect the transient state; the
1397transient remains active.
1398
1399@item
1400Invoking a (non-infix) suffix command ``deactivates'' the transient
1401state by removing the transient keymap and performing some
1402additional cleanup.
1403
1404@item
1405Invoking a command that is bound in a keymap other than the
1406transient keymap is disallowed and trying to do so results in a
1407warning. This does not ``deactivate'' the transient.
1408@end itemize
1409
1410But these are just the defaults. Whether a certain command
1411deactivates or ``exits'' the transient is configurable. There is more
1412than one way in which a command can be ``transient'' or ``non-transient'';
1413the exact behavior is implemented by calling a so-called ``pre-command''
1414function. Whether non-suffix commands are allowed to be called is
1415configurable per transient.
1416
1417@itemize
1418@item
1419The transient-ness of suffix commands (including infix commands) is
1420controlled by the value of their @code{transient} slot, which can be set
1421either when defining the command or when adding a binding to a
1422transient while defining the respective transient prefix command.
1423
1424Valid values are booleans and the pre-commands described below.
1425
1426@itemize
1427@item
1428@code{t} is equivalent to @code{transient--do-stay}.
1429
1430@item
1431@code{nil} is equivalent to @code{transient--do-exit}.
1432
1433@item
1434If @code{transient} is unbound (and that is actually the default for
1435non-infix suffixes) then the value of the prefix's
1436@code{transient-suffix} slot is used instead. The default value of that
1437slot is @code{nil}, so the suffix's @code{transient} slot being unbound is
1438essentially equivalent to it being @code{nil}.
1439@end itemize
1440
1441@item
1442A suffix command can be a prefix command itself, i.e. a
1443``sub-prefix''. While a sub-prefix is active we nearly always want
1444@kbd{C-g} to take the user back to the ``super-prefix''. However in rare
1445cases this may not be desirable, and that makes the following
1446complication necessary:
1447
1448For @code{transient-suffix} objects the @code{transient} slot is unbound. We can
1449ignore that for the most part because, as stated above, @code{nil} and the
1450slot being unbound are equivalent, and mean ``do exit''. That isn't
1451actually true for suffixes that are sub-prefixes though. For such
1452suffixes unbound means ``do exit but allow going back'', which is the
1453default, while @code{nil} means ``do exit permanently'', which requires that
1454slot to be explicitly set to that value.
1455
1456@item
1457The transient-ness of certain built-in suffix commands is specified
1458using @code{transient-predicate-map}. This is a special keymap, which
1459binds commands to pre-commands (as opposed to keys to commands) and
1460takes precedence over the @code{transient} slot.
1461@end itemize
1462
1463The available pre-command functions are documented below. They are
1464called by @code{transient--pre-command}, a function on @code{pre-command-hook} and
1465the value that they return determines whether the transient is exited.
1466To do so the value of one of the constants @code{transient--exit} or
1467@code{transient--stay} is used (that way we don't have to remember if @code{t} means
1468``exit'' or ``stay'').
1469
1470Additionally, these functions may change the value of @code{this-command}
1471(which explains why they have to be called using @code{pre-command-hook}),
1472call @code{transient-export}, @code{transient--stack-zap} or @code{transient--stack-push};
1473and set the values of @code{transient--exitp}, @code{transient--helpp} or
1474@code{transient--editp}.
1475
1476@anchor{Pre-commands for Infixes}
1477@subheading Pre-commands for Infixes
1478
1479The default for infixes is @code{transient--do-stay}. This is also the only
1480function that makes sense for infixes.
1481
1482@defun transient--do-stay
1483
1484Call the command without exporting variables and stay transient.
1485@end defun
1486
1487@anchor{Pre-commands for Suffixes}
1488@subheading Pre-commands for Suffixes
1489
1490The default for suffixes is @code{transient--do-exit}.
1491
1492@defun transient--do-exit
1493
1494Call the command after exporting variables and exit the transient.
1495@end defun
1496
1497@defun transient--do-call
1498
1499Call the command after exporting variables and stay transient.
1500@end defun
1501
1502@defun transient--do-replace
1503
1504Call the transient prefix command, replacing the active transient.
1505
1506This is used for suffixes that are prefixes themselves, i.e.@: for
1507sub-prefixes.
1508@end defun
1509
1510@anchor{Pre-commands for Non-Suffixes}
1511@subheading Pre-commands for Non-Suffixes
1512
1513The default for non-suffixes, i.e@: commands that are bound in other
1514keymaps beside the transient keymap, is @code{transient--do-warn}. Silently
1515ignoring the user-error is also an option, though probably not a good
1516one.
1517
1518If you want to let the user invoke non-suffix commands, then use
1519@code{transient--do-stay} as the value of the prefix's @code{transient-non-suffix}
1520slot.
1521
1522@defun transient--do-warn
1523
1524Call @code{transient-undefined} and stay transient.
1525@end defun
1526
1527@defun transient--do-noop
1528
1529Call @code{transient-noop} and stay transient.
1530@end defun
1531
1532@anchor{Special Pre-Commands}
1533@subheading Special Pre-Commands
1534
1535@defun transient--do-quit-one
1536
1537If active, quit help or edit mode, else exit the active transient.
1538
1539This is used when the user pressed @kbd{C-g}.
1540@end defun
1541
1542@defun transient--do-quit-all
1543
1544Exit all transients without saving the transient stack.
1545
1546This is used when the user pressed @kbd{C-q}.
1547@end defun
1548
1549@defun transient--do-suspend
1550
1551Suspend the active transient, saving the transient stack.
1552
1553This is used when the user pressed @kbd{C-z}.
1554@end defun
1555
1556@node Classes and Methods
1557@chapter Classes and Methods
1558@cindex classes and methods
1559
1560Transient uses classes and generic functions to make it possible to
1561define new types of suffix commands that are similar to existing
1562types, but behave differently in some aspects. It does the same for
1563groups and prefix commands, though at least for prefix commands that
1564@strong{currently} appears to be less important.
1565
1566Every prefix, infix and suffix command is associated with an object,
1567which holds information that controls certain aspects of its behavior.
1568This happens in two ways.
1569
1570@itemize
1571@item
1572Associating a command with a certain class gives the command a type.
1573This makes it possible to use generic functions to do certain things
1574that have to be done differently depending on what type of command
1575it acts on.
1576
1577That in turn makes it possible for third-parties to add new types
1578without having to convince the maintainer of Transient that that new
1579type is important enough to justify adding a special case to a dozen
1580or so functions.
1581
1582@item
1583Associating a command with an object makes it possible to easily
1584store information that is specific to that particular command.
1585
1586Two commands may have the same type, but obviously their key
1587bindings and descriptions still have to be different, for example.
1588
1589The values of some slots are functions. The @code{reader} slot for example
1590holds a function that is used to read a new value for an infix
1591command. The values of such slots are regular functions.
1592
1593Generic functions are used when a function should do something
1594different based on the type of the command, i.e. when all commands
1595of a certain type should behave the same way but different from the
1596behavior for other types. Object slots that hold a regular function
1597as value are used when the task that they perform is likely to
1598differ even between different commands of the same type.
1599@end itemize
1600
1601@menu
1602* Group Classes::
1603* Group Methods::
1604* Prefix Classes::
1605* Suffix Classes::
1606* Suffix Methods::
1607* Prefix Slots::
1608* Suffix Slots::
1609* Predicate Slots::
1610@end menu
1611
1612@node Group Classes
1613@section Group Classes
1614
1615The type of a group can be specified using the @code{:class} property at the
1616beginning of the class specification, e.g. @code{[:class transient-columns
1617...]} in a call to @code{transient-define-prefix}.
1618
1619@itemize
1620@item
1621The abstract @code{transient-child} class is the base class of both
1622@code{transient-group} (and therefore all groups) as well as of
1623@code{transient-suffix} (and therefore all suffix and infix commands).
1624
1625This class exists because the elements (a.k.a.@: ``children'') of certain
1626groups can be other groups instead of suffix and infix commands.
1627
1628@item
1629The abstract @code{transient-group} class is the superclass of all other
1630group classes.
1631
1632@item
1633The @code{transient-column} class is the simplest group.
1634
1635This is the default ``flat'' group. If the class is not specified
1636explicitly and the first element is not a vector (i.e. not a group),
1637then this class is used.
1638
1639This class displays each element on a separate line.
1640
1641@item
1642The @code{transient-row} class displays all elements on a single line.
1643
1644@item
1645The @code{transient-columns} class displays commands organized in columns.
1646
1647Direct elements have to be groups whose elements have to be commands
1648or strings. Each subgroup represents a column. This class takes
1649care of inserting the subgroups' elements.
1650
1651This is the default ``nested'' group. If the class is not specified
1652explicitly and the first element is a vector (i.e.@: a group), then
1653this class is used.
1654
1655@item
1656The @code{transient-subgroups} class wraps other groups.
1657
1658Direct elements have to be groups whose elements have to be commands
1659or strings. This group inserts an empty line between subgroups.
1660The subgroups themselves are responsible for displaying their
1661elements.
1662@end itemize
1663
1664@node Group Methods
1665@section Group Methods
1666
1667@defun transient-setup-children group children
1668
1669This generic function can be used to setup the children or a group.
1670
1671The default implementation usually just returns the children
1672unchanged, but if the @code{setup-children} slot of @var{group} is non-nil, then
1673it calls that function with @var{children} as the only argument and
1674returns the value.
1675
1676The children are given as a (potentially empty) list consisting of
1677either group or suffix specifications. These functions can make
1678arbitrary changes to the children including constructing new
1679children from scratch.
1680@end defun
1681
1682@defun transient--insert-group group
1683
1684This generic function formats the group and its elements and inserts
1685the result into the current buffer, which is a temporary buffer.
1686The contents of that buffer are later inserted into the popup buffer.
1687
1688Functions that are called by this function may need to operate in
1689the buffer from which the transient was called. To do so they can
1690temporarily make the @code{transient--source-buffer} the current buffer.
1691@end defun
1692
1693@node Prefix Classes
1694@section Prefix Classes
1695
1696Currently the @code{transient-prefix} class is being used for all prefix
1697commands and there is only a single generic function that can be
1698specialized based on the class of a prefix command.
1699
1700@defun transient--history-init obj
1701
1702This generic function is called while setting up the transient and
1703is responsible for initializing the @code{history} slot. This is the
1704transient-wide history; many individual infixes also have a history
1705of their own.
1706
1707The default (and currently only) method extracts the value from the
1708global variable @code{transient-history}.
1709@end defun
1710
1711A transient prefix command's object is stored in the @code{transient--prefix}
1712property of the command symbol. While a transient is active, a clone
1713of that object is stored in the variable @code{transient--prefix}. A clone
1714is used because some changes that are made to the active transient's
1715object should not affect later invocations.
1716
1717@node Suffix Classes
1718@section Suffix Classes
1719
1720@itemize
1721@item
1722All suffix and infix classes derive from @code{transient-suffix}, which in
1723turn derives from @code{transient-child}, from which @code{transient-group} also
1724derives (@pxref{Group Classes}).
1725
1726@item
1727All infix classes derive from the abstract @code{transient-infix} class,
1728which in turn derives from the @code{transient-suffix} class.
1729
1730Infixes are a special type of suffixes. The primary difference is
1731that infixes always use the @code{transient--do-stay} pre-command, while
1732non-infix suffixes use a variety of pre-commands (see @ref{Transient State}). Doing that is most easily achieved by using this class,
1733though theoretically it would be possible to define an infix class
1734that does not do so. If you do that then you get to implement many
1735methods.
1736
1737Also, infixes and non-infix suffixes are usually defined using
1738different macros (@pxref{Defining Suffix and Infix Commands}).
1739
1740@item
1741Classes used for infix commands that represent arguments should
1742be derived from the abstract @code{transient-argument} class.
1743
1744@item
1745The @code{transient-switch} class (or a derived class) is used for infix
1746arguments that represent command-line switches (arguments that do
1747not take a value).
1748
1749@item
1750The @code{transient-option} class (or a derived class) is used for infix
1751arguments that represent command-line options (arguments that do
1752take a value).
1753
1754@item
1755The @code{transient-switches} class can be used for a set of mutually
1756exclusive command-line switches.
1757
1758@item
1759The @code{transient-files} class can be used for a @samp{--} argument that
1760indicates that all remaining arguments are files.
1761
1762@item
1763Classes used for infix commands that represent variables should
1764derived from the abstract @code{transient-variables} class.
1765@end itemize
1766
1767Magit defines additional classes, which can serve as examples for the
1768fancy things you can do without modifying Transient. Some of these
1769classes will likely get generalized and added to Transient. For now
1770they are very much subject to change and not documented.
1771
1772@node Suffix Methods
1773@section Suffix Methods
1774
1775To get information about the methods implementing these generic
1776functions use @code{describe-function}.
1777
1778@menu
1779* Suffix Value Methods::
1780* Suffix Format Methods::
1781@end menu
1782
1783@node Suffix Value Methods
1784@subsection Suffix Value Methods
1785
1786@defun transient-init-value obj
1787
1788This generic function sets the initial value of the object @var{obj}.
1789
1790This function is called for all suffix commands, but unless a
1791concrete method is implemented this falls through to the default
1792implementation, which is a noop. In other words this usually
1793only does something for infix commands, but note that this is
1794not implemented for the abstract class @code{transient-infix}, so if
1795your class derives from that directly, then you must implement
1796a method.
1797@end defun
1798
1799@defun transient-infix-read obj
1800
1801This generic function determines the new value of the infix object
1802@var{obj}.
1803
1804This function merely determines the value; @code{transient-infix-set} is
1805used to actually store the new value in the object.
1806
1807For most infix classes this is done by reading a value from the
1808user using the reader specified by the @code{reader} slot (using the
1809@code{transient-infix-value} method described below).
1810
1811For some infix classes the value is changed without reading
1812anything in the minibuffer, i.e.@: the mere act of invoking the
1813infix command determines what the new value should be, based
1814on the previous value.
1815@end defun
1816
1817@defun transient-prompt obj
1818
1819This generic function returns the prompt to be used to read infix
1820object @var{obj}'s value.
1821@end defun
1822
1823@defun transient-infix-set obj value
1824
1825This generic function sets the value of infix object @var{obj} to @var{value}.
1826@end defun
1827
1828@defun transient-infix-value obj
1829
1830This generic function returns the value of the suffix object @var{obj}.
1831
1832This function is called by @code{transient-args} (which see), meaning this
1833function is how the value of a transient is determined so that the
1834invoked suffix command can use it.
1835
1836Currently most values are strings, but that is not set in stone.
1837@code{nil} is not a value, it means ``no value''.
1838
1839Usually only infixes have a value, but see the method for
1840@code{transient-suffix}.
1841@end defun
1842
1843@defun transient-init-scope obj
1844
1845This generic function sets the scope of the suffix object @var{obj}.
1846
1847The scope is actually a property of the transient prefix, not of
1848individual suffixes. However it is possible to invoke a suffix
1849command directly instead of from a transient. In that case, if
1850the suffix expects a scope, then it has to determine that itself
1851and store it in its @code{scope} slot.
1852
1853This function is called for all suffix commands, but unless a
1854concrete method is implemented this falls through to the default
1855implementation, which is a noop.
1856@end defun
1857
1858@node Suffix Format Methods
1859@subsection Suffix Format Methods
1860
1861@defun transient-format obj
1862
1863This generic function formats and returns @var{obj} for display.
1864
1865When this function is called, then the current buffer is some
1866temporary buffer. If you need the buffer from which the prefix
1867command was invoked to be current, then do so by temporarily
1868making @code{transient--source-buffer} current.
1869@end defun
1870
1871@defun transient-format-key obj
1872
1873This generic function formats @var{obj}'s @code{key} for display and returns the
1874result.
1875@end defun
1876
1877@defun transient-format-description obj
1878
1879This generic function formats @var{obj}'s @code{description} for display and
1880returns the result.
1881@end defun
1882
1883@defun transient-format-value obj
1884
1885This generic function formats @var{obj}'s value for display and returns
1886the result.
1887@end defun
1888
1889@defun transient-show-help obj
1890
1891Show help for the prefix, infix or suffix command represented by
1892@var{obj}.
1893
1894For prefixes, show the info manual, if that is specified using the
1895@code{info-manual} slot. Otherwise, show the manpage if that is specified
1896using the @code{man-page} slot. Otherwise, show the command's doc string.
1897
1898For suffixes, show the command's doc string.
1899
1900For infixes, show the manpage if that is specified. Otherwise show
1901the command's doc string.
1902@end defun
1903
1904@node Prefix Slots
1905@section Prefix Slots
1906
1907@itemize
1908@item
1909@code{man-page} or @code{info-manual} can be used to specify the documentation for
1910the prefix and its suffixes. The command @code{transient-help} uses the
1911method @code{transient-show-help} (which see) to lookup and use these
1912values.
1913
1914@item
1915@code{history-key} If multiple prefix commands should share a single value,
1916then this slot has to be set to the same value for all of them. You
1917probably don't want that.
1918
1919@item
1920@code{transient-suffix} and @code{transient-non-suffix} play a part when
1921determining whether the currently active transient prefix command
1922remains active/transient when a suffix or abitrary non-suffix
1923command is invoked. @xref{Transient State}.
1924
1925@item
1926@code{incompatible} A list of lists. Each sub-list specifies a set of
1927mutually exclusive arguments. Enabling one of these arguments
1928causes the others to be disabled. An argument may appear in
1929multiple sub-lists.
1930
1931@item
1932@code{scope} For some transients it might be necessary to have a sort of
1933secondary value, called a ``scope''. See @code{transient-define-prefix}.
1934@end itemize
1935
1936@anchor{Internal Prefix Slots}
1937@subheading Internal Prefix Slots
1938
1939These slots are mostly intended for internal use. They should not be
1940set in calls to @code{transient-define-prefix}.
1941
1942@itemize
1943@item
1944@code{prototype} When a transient prefix command is invoked, then a clone
1945of that object is stored in the global variable @code{transient--prefix}
1946and the prototype is stored in the clone's @code{prototype} slot.
1947
1948@item
1949@code{command} The command, a symbol. Each transient prefix command
1950consists of a command, which is stored in a symbol's function slot
1951and an object, which is stored in the @code{transient--prefix} property
1952of the same symbol.
1953
1954@item
1955@code{level} The level of the prefix commands. The suffix commands whose
1956layer is equal or lower are displayed. @pxref{Enabling and Disabling Suffixes}.
1957
1958@item
1959@code{value} The likely outdated value of the prefix. Instead of accessing
1960this slot directly you should use the function @code{transient-get-value},
1961which is guaranteed to return the up-to-date value.
1962
1963@item
1964@code{history} and @code{history-pos} are used to keep track of historic values.
1965Unless you implement your own @code{transient-infix-read} method you should
1966not have to deal with these slots.
1967@end itemize
1968
1969@node Suffix Slots
1970@section Suffix Slots
1971
1972Here we document most of the slots that are only available for suffix
1973objects. Some slots are shared by suffix and group objects, they are
1974documented in @ref{Predicate Slots}.
1975
1976Also see @ref{Suffix Classes}.
1977
1978@anchor{Slots of @code{transient-suffix}}
1979@subheading Slots of @code{transient-suffix}
1980
1981@itemize
1982@item
1983@code{key} The key, a key vector or a key description string.
1984
1985@item
1986@code{command} The command, a symbol.
1987
1988@item
1989@code{transient} Whether to stay transient. @xref{Transient State}.
1990
1991@item
1992@code{format} The format used to display the suffix in the popup buffer.
1993It must contain the following %-placeholders:
1994
1995@itemize
1996@item
1997@code{%k} For the key.
1998
1999@item
2000@code{%d} For the description.
2001
2002@item
2003@code{%v} For the infix value. Non-infix suffixes don't have a value.
2004@end itemize
2005
2006@item
2007@code{description} The description, either a string or a function that is
2008called with no argument and returns a string.
2009@end itemize
2010
2011@anchor{Slots of @code{transient-infix}}
2012@subheading Slots of @code{transient-infix}
2013
2014Some of these slots are only meaningful for some of the subclasses.
2015They are defined here anyway to allow sharing certain methods.
2016
2017@itemize
2018@item
2019@code{argument} The long argument, e.g. @code{--verbose}.
2020
2021@item
2022@code{shortarg} The short argument, e.g. @code{-v}.
2023
2024@item
2025@code{value} The value. Should not be accessed directly.
2026
2027@item
2028@code{init-value} Function that is responsable for setting the object's
2029value. If bound, then this is called with the object as the only
2030argument. Usually this is not bound, in which case the object's
2031primary @code{transient-init-value} method is called instead.
2032
2033@item
2034@code{unsavable} Whether the value of the suffix is not saved as part of
2035the prefixes.
2036
2037@item
2038@code{multi-value} For options, whether the option can have multiple
2039values. If non-nil, then default to use @code{completing-read-multiple}.
2040
2041@item
2042@code{always-read} For options, whether to read a value on every invocation.
2043If this is nil, then options that have a value are simply unset and
2044have to be invoked a second time to set a new value.
2045
2046@item
2047@code{allow-empty} For options, whether the empty string is a valid value.
2048
2049@item
2050@code{history-key} The key used to store the history. This defaults to the
2051command name. This is useful when multiple infixes should share the
2052same history because their values are of the same kind.
2053
2054@item
2055@code{reader} The function used to read the value of an infix. Not used
2056for switches. The function takes three arguments, @var{prompt},
2057@var{initial-input} and @var{history}, and must return a string.
2058
2059@item
2060@code{prompt} The prompt used when reading the value, either a string or a
2061function that takes the object as the only argument and which
2062returns a prompt string.
2063
2064@item
2065@code{choices} A list of valid values. How exactly that is used depends on
2066the class of the object.
2067@end itemize
2068
2069@anchor{Slots of @code{transient-variable}}
2070@subheading Slots of @code{transient-variable}
2071
2072@itemize
2073@item
2074@code{variable} The variable.
2075@end itemize
2076
2077@anchor{Slots of @code{transient-switches}}
2078@subheading Slots of @code{transient-switches}
2079
2080@itemize
2081@item
2082@code{argument-format} The display format. Must contain @code{%s}, one of the
2083@code{choices} is substituted for that. E.g., @code{--%s-order}.
2084
2085@item
2086@code{argument-regexp} The regexp used to match any one of the switches.
2087E.g., @code{\\(--\\(topo\\|author-date\\|date\\)-order\\)}.
2088@end itemize
2089
2090@node Predicate Slots
2091@section Predicate Slots
2092
2093Suffix and group objects share some predicate slots that control
2094whether a group or suffix should be available depending on some state.
2095Only one of these slots can be used at the same time. It is undefined
2096what happens if you use more than one.
2097
2098@itemize
2099@item
2100@code{if} Enable if predicate returns non-@code{nil}.
2101
2102@item
2103@code{if-not} Enable if predicate returns @code{nil}.
2104
2105@item
2106@code{if-non-nil} Enable if variable's value is non-@code{nil}.
2107
2108@item
2109@code{if-nil} Enable if variable's value is @code{nil}.
2110
2111@item
2112@code{if-mode} Enable if major-mode matches value.
2113
2114@item
2115@code{if-not-mode} Enable if major-mode does not match value.
2116
2117@item
2118@code{if-derived} Enable if major-mode derives from value.
2119
2120@item
2121@code{if-not-derived} Enable if major-mode does not derive from value.
2122@end itemize
2123
2124One more slot is shared between group and suffix classes, @code{level}. Like
2125the slots documented above, it is a predicate, but it is used for a
2126different purpose. The value has to be an integer between 1
2127and 7. @code{level} controls whether a suffix or a group should be
2128available depending on user preference.
2129@xref{Enabling and Disabling Suffixes}.
2130
2131@node Related Abstractions and Packages
2132@chapter Related Abstractions and Packages
2133
2134@menu
2135* Comparison With Prefix Keys and Prefix Arguments::
2136* Comparison With Other Packages::
2137@end menu
2138
2139@node Comparison With Prefix Keys and Prefix Arguments
2140@section Comparison With Prefix Keys and Prefix Arguments
2141
2142While transient commands were inspired by regular prefix keys and
2143prefix arguments, they are also quite different and much more complex.
2144
2145The following diagrams illustrate some of the differences.
2146
2147@itemize
2148@item
2149@code{(c)} represents a return to the command loop.
2150
2151@item
2152@code{(+)} represents the user's choice to press one key or another.
2153
2154@item
2155@code{@{@var{word}@}} are possible behaviors.
2156
2157@item
2158@code{@{@var{number}@}} is a footnote.
2159@end itemize
2160
2161@anchor{Regular Prefix Commands}
2162@subheading Regular Prefix Commands
2163
2164@xref{Prefix Keys,,,elisp,}.
2165
2166@example
2167 ,--> command1 --> (c)
2168 |
2169(c)-(+)-> prefix command or key --+--> command2 --> (c)
2170 |
2171 `--> command3 --> (c)
2172@end example
2173
2174@anchor{Regular Prefix Arguments}
2175@subheading Regular Prefix Arguments
2176
2177@xref{Prefix Command Arguments,,,elisp,}.
2178
2179@example
2180 ,----------------------------------,
2181 | |
2182 v |
2183(c)-(+)---> prefix argument command --(c)-(+)-> any command --> (c)
2184 | ^ |
2185 | | |
2186 `-- sets or changes --, ,-- maybe used --' |
2187 | | |
2188 v | |
2189 prefix argument state |
2190 ^ |
2191 | |
2192 `-------- discards --------'
2193@end example
2194
2195@anchor{Transients}
2196@subheading Transients
2197
2198(∩`-´)⊃━☆゚.*・。゚
2199
2200This diagram ignores the infix value and external state:
2201
2202@example
2203(c)
2204 | ,- @{stay@} ------<-,-<------------<-,-<---,
2205(+) | | | |
2206 | | | | |
2207 | | ,--> infix1 --| | |
2208 | | | | | |
2209 | | |--> infix2 --| | |
2210 v v | | | |
2211 prefix -(c)-(+)-> infix3 --' ^ |
2212 | | |
2213 |---------------> suffix1 -->--| |
2214 | | |
2215 |---------------> suffix2 ----@{1@}------> @{exit@} --> (c)
2216 | |
2217 |---------------> suffix3 -------------> @{exit@} --> (c)
2218 | |
2219 `--> any command --@{2@}-> @{warn@} -->--|
2220 | |
2221 |--> @{noop@} -->--|
2222 | |
2223 |--> @{call@} -->--'
2224 |
2225 `------------------> @{exit@} --> (c)
2226@end example
2227
2228This diagram takes the infix value into account to an extend, while
2229still ignoring external state:
2230
2231@example
2232(c)
2233 | ,- @{stay@} ------<-,-<------------<-,-<---,
2234(+) | | | |
2235 | | | | |
2236 | | ,--> infix1 --| | |
2237 | | | | | | |
2238 | | ,--> infix2 --| | |
2239 v v | | | | |
2240 prefix -(c)-(+)-> infix3 --' | |
2241 | | ^ |
2242 | | | |
2243 |---------------> suffix1 -->--| |
2244 | | ^ | |
2245 | | | | |
2246 |---------------> suffix2 ----@{1@}------> @{exit@} --> (c)
2247 | | ^ | |
2248 | | | | v
2249 | | | | |
2250 |---------------> suffix3 -------------> @{exit@} --> (c)
2251 | | ^ | |
2252 | sets | | v
2253 | | maybe | |
2254 | | used | |
2255 | | | | |
2256 | | infix --' | |
2257 | `---> value | |
2258 | ^ | |
2259 | | | |
2260 | hides | |
2261 | | | |
2262 | `--------------------------<---|
2263 | | |
2264 `--> any command --@{2@}-> @{warn@} -->--| |
2265 | | |
2266 |--> @{noop@} -->--| |
2267 | | |
2268 |--> @{call@} -->--' ^
2269 | |
2270 `------------------> @{exit@} --> (c)
2271@end example
2272
2273This diagram provides more information about the infix value
2274and also takes external state into account.
2275
2276@example
2277 ,----sets--- "anything"
2278 |
2279 v
2280 ,---------> external
2281 | state
2282 | | |
2283 | initialized | ☉‿⚆
2284 sets from |
2285 | | maybe
2286 | ,----------' used
2287 | | |
2288(c) | | v
2289 | ,- @{stay@} --|---<-,-<------|-----<-,-<---,
2290(+) | | | | | | |
2291 | | | v | | | |
2292 | | ,--> infix1 --| | | |
2293 | | | | | | | | |
2294 | | | | v | | | |
2295 | | ,--> infix2 --| | | |
2296 | | | | ^ | | | |
2297 v v | | | | | | |
2298 prefix -(c)-(+)-> infix3 --' | | |
2299 | | ^ | ^ |
2300 | | | v | |
2301 |---------------> suffix1 -->--| |
2302 | | | ^ | | |
2303 | | | | v | |
2304 |---------------> suffix2 ----@{1@}------> @{exit@} --> (c)
2305 | | | ^ | | |
2306 | | | | | | v
2307 | | | | v | |
2308 |---------------> suffix3 -------------> @{exit@} --> (c)
2309 | | | ^ | |
2310 | sets | | | v
2311 | | initialized maybe | |
2312 | | from used | |
2313 | | | | | |
2314 | | `-- infix ---' | |
2315 | `---> value -----------------------------> persistent
2316 | ^ ^ | | across
2317 | | | | | invocations -,
2318 | hides | | | |
2319 | | `----------------------------------------------'
2320 | | | |
2321 | `--------------------------<---|
2322 | | |
2323 `--> any command --@{2@}-> @{warn@} -->--| |
2324 | | |
2325 |--> @{noop@} -->--| |
2326 | | |
2327 |--> @{call@} -->--' ^
2328 | |
2329 `------------------> @{exit@} --> (c)
2330@end example
2331
2332@itemize
2333@item
2334@code{@{1@}} Transients can be configured to be exited when a suffix command
2335is invoked. The default is to do so for all suffixes except for
2336those that are common to all transients and which are used to
2337perform tasks such as providing help and saving the value of the
2338infix arguments for future invocations. The behavior can also be
2339specified for individual suffix commands and may even depend on
2340state.
2341
2342@item
2343@code{@{2@}} Transients can be configured to allow the user to invoke
2344non-suffix commands. The default is to not allow that and instead
2345warn the user.
2346@end itemize
2347
2348Despite already being rather complex, even the last diagram leaves out
2349many details. Most importantly it implies that the decision whether
2350to remain transient is made later than it actually is made (for the
2351most part a function on @code{pre-command-hook} is responsible). But such
2352implementation details are of little relevance to users and are
2353covered elsewhere.
2354
2355@node Comparison With Other Packages
2356@section Comparison With Other Packages
2357
2358@anchor{Magit-Popup}
2359@subheading Magit-Popup
2360
2361Transient is the successor to Magit-Popup (@pxref{Top,,,magit-popup,}).
2362
2363One major difference between these two implementations of the same
2364ideas is that while Transient uses transient keymaps and embraces the
2365command-loop, Magit-Popup implemented an inferior mechanism that does
2366not use transient keymaps and that instead of using the command-loop
2367implements a naive alternative based on @code{read-char}.
2368
2369Magit-Popup does not use classes and generic functions and defining a
2370new command type is near impossible as it involves adding hard-coded
2371special-cases to many functions. Because of that only a single new
2372type was added, which was not already part of Magit-Popup's initial
2373release.
2374
2375A lot of things are hard-coded in Magit-Popup. One random example is
2376that the key bindings for switches must begin with @code{-} and those for
2377options must begin with @code{=}.
2378
2379@anchor{Hydra}
2380@subheading Hydra
2381
2382Hydra (see @uref{https://github.com/abo-abo/hydra}) is another package that
2383provides features similar to those of Transient.
2384
2385Both packages use transient keymaps to make a set of commands
2386temporarily available and show the available commands in a popup
2387buffer.
2388
2389A Hydra ``body'' is equivalent to a Transient ``prefix'' and a Hydra
2390``head'' is equivalent to a Transient ``suffix''. Hydra has no equivalent
2391of a Transient ``infix''.
2392
2393Both hydras and transients can be used as simple command dispatchers.
2394Used like this they are similar to regular prefix commands and prefix
2395keys, except that the available commands are shown in the popup buffer.
2396
2397(Another package that does this is @code{which-key}. It does so automatically
2398for any incomplete key sequence. The advantage of that approach is
2399that no additional work is necessary; the disadvantage is that the
2400available commands are not organized semantically.)
2401
2402Both Hydra and Transient provide features that go beyond simple
2403command dispatchers:
2404
2405@itemize
2406@item
2407Invoking a command from a hydra does not necessarily exit the hydra.
2408That makes it possible to invoke the same command again, but using a
2409shorter key sequence (i.e. the key that was used to enter the hydra
2410does not have to be pressed again).
2411
2412Transient supports that too, but for now this feature is not a focus
2413and the interface is a bit more complicated. A very basic example
2414using the current interface:
2415
2416@lisp
2417(transient-define-prefix outline-navigate ()
2418 :transient-suffix 'transient--do-stay
2419 :transient-non-suffix 'transient--do-warn
2420 [("p" "previous visible heading" outline-previous-visible-heading)
2421 ("n" "next visible heading" outline-next-visible-heading)])
2422@end lisp
2423
2424
2425@item
2426Transient supports infix arguments; values that are set by infix
2427commands and then consumed by the invoked suffix command(s).
2428
2429To my knowledge, Hydra does not support that.
2430@end itemize
2431
2432Both packages make it possible to specify how exactly the available
2433commands are outlined:
2434
2435@itemize
2436@item
2437With Hydra this is often done using an explicit format string, which
2438gives authors a lot of flexibility and makes it possible to do fancy
2439things.
2440
2441The downside of this is that it becomes harder for a user to add
2442additional commands to an existing hydra and to change key bindings.
2443
2444@item
2445Transient allows the author of a transient to organize the commands
2446into groups and the use of generic functions allows authors of
2447transients to control exactly how a certain command type is
2448displayed.
2449
2450However while Transient supports giving sections a heading it does
2451not currently support giving the displayed information more
2452structure by, for example, using box-drawing characters.
2453
2454That could be implemented by defining a new group class, which lets
2455the author specify a format string. It should be possible to
2456implement that without modifying any existing code, but it does not
2457currently exist.
2458@end itemize
2459
2460@node FAQ
2461@appendix FAQ
2462
2463
2464
2465@anchor{Can I control how the popup buffer is displayed?}
2466@appendixsec Can I control how the popup buffer is displayed?
2467
2468Yes, see @code{transient-display-buffer-action} in @ref{Other Options}.
2469
2470@anchor{Why did some of the key bindings change?}
2471@appendixsec Why did some of the key bindings change?
2472
2473You may have noticed that the bindings for some of the common commands
2474do @strong{not} have the prefix @code{C-x} and that furthermore some of these commands
2475are grayed out while others are not. That unfortunately is a bit
2476confusing if the section of common commands is not shown permanently,
2477making the following explanation necessary.
2478
2479The purpose of usually hiding that section but showing it after the
2480user pressed the respective prefix key is to conserve space and not
2481overwhelm users with too much noise, while allowing the user to
2482quickly list common bindings on demand.
2483
2484That however should not keep us from using the best possible key
2485bindings. The bindings that do use a prefix do so to avoid wasting
2486too many non-prefix bindings, keeping them available for use in
2487individual transients. The bindings that do not use a prefix and that
2488are @strong{not} grayed out are very important bindings that are @strong{always}
2489available, even when invoking the ``common command key prefix'' or @strong{any
2490other} transient-specific prefix. The non-prefix keys that @strong{are} grayed
2491out however, are not available when any incomplete prefix key sequence
2492is active. They do not use the ``common command key prefix'' because it
2493is likely that users want to invoke them several times in a row and
2494e.g. @kbd{M-p M-p M-p} is much more convenient than
2495@kbd{C-x M-p C-x M-p C-x M-p}.
2496
2497You may also have noticed that the "Set" command is bound to @kbd{C-x s},
2498while Magit-Popup used to bind @kbd{C-c C-c} instead. I have seen several
2499users praise the latter binding (sic), so I did not change it
2500willy-nilly. The reason that I changed it is that using different
2501prefix keys for different common commands, would have made the
2502temporary display of the common commands even more confusing,
2503i.e. after pressing @kbd{C-c} all the @kbd{C-x ...} bindings would be grayed out.
2504
2505Using a single prefix for common commands key means that all other
2506potential prefix keys can be used for transient-specific commands
2507@strong{without} the section of common commands also popping up. @code{C-c} in
2508particular is a prefix that I want to (and already do) use for Magit, and
2509also using that for a common command would prevent me from doing so.
2510
2511(Also see the next question.)
2512
2513@anchor{Why does @code{q} not quit popups anymore?}
2514@appendixsec Why does @code{q} not quit popups anymore?
2515
2516I agree that @kbd{q} is a good binding for commands that quit something.
2517This includes quitting whatever transient is currently active, but it
2518also includes quitting whatever it is that some specific transient is
2519controlling. The transient @code{magit-blame} for example binds @code{q} to the
2520command that turns @code{magit-blame-mode} off.
2521
2522So I had to decide if @kbd{q} should quit the active transient (like
2523Magit-Popup used to) or whether @kbd{C-g} should do that instead, so
2524that @kbd{q}
2525could be bound in individual transient to whatever commands make sense
2526for them. Because all other letters are already reserved for use by
2527individual transients, I have decided to no longer make an exception
2528for @kbd{q}.
2529
2530If you want to get @kbd{q}'s old binding back then you can do so. Doing
2531that is a bit more complicated than changing a single key binding, so
2532I have implemented a function, @code{transient-bind-q-to-quit} that makes the
2533necessary changes. See its doc string for more information.
2534
2535@node Keystroke Index
2536@appendix Keystroke Index
2537
2538@printindex ky
2539
2540@node Command and Function Index
2541@appendix Command and Function Index
2542
2543@printindex fn
2544
2545@node Variable Index
2546@appendix Variable Index
2547
2548@printindex vr
2549
2550@node Concept Index
2551@appendix Concept and Feature Index
2552
2553@printindex cp
2554
2555@node GNU General Public License
2556@appendix GNU General Public License
2557
2558@include gpl.texi
2559
2560@bye
diff --git a/lisp/org/ol-bibtex.el b/lisp/org/ol-bibtex.el
index 218f8f17ed5..81b99167b8e 100644
--- a/lisp/org/ol-bibtex.el
+++ b/lisp/org/ol-bibtex.el
@@ -655,7 +655,8 @@ With a prefix arg, query for optional fields."
655 655
656(defun org-bibtex-read () 656(defun org-bibtex-read ()
657 "Read a bibtex entry and save to `org-bibtex-entries'. 657 "Read a bibtex entry and save to `org-bibtex-entries'.
658This uses `bibtex-parse-entry'." 658This uses `bibtex-parse-entry'.
659Return the new value of `org-bibtex-entries'."
659 (interactive) 660 (interactive)
660 (let ((keyword (lambda (str) (intern (concat ":" (downcase str))))) 661 (let ((keyword (lambda (str) (intern (concat ":" (downcase str)))))
661 (clean-space (lambda (str) (replace-regexp-in-string 662 (clean-space (lambda (str) (replace-regexp-in-string
@@ -678,7 +679,8 @@ This uses `bibtex-parse-entry'."
678 (funcall clean-space (funcall strip-delim (cdr pair))))) 679 (funcall clean-space (funcall strip-delim (cdr pair)))))
679 (save-excursion (bibtex-beginning-of-entry) (bibtex-parse-entry))) 680 (save-excursion (bibtex-beginning-of-entry) (bibtex-parse-entry)))
680 org-bibtex-entries) 681 org-bibtex-entries)
681 (unless (car org-bibtex-entries) (pop org-bibtex-entries)))) 682 (unless (car org-bibtex-entries) (pop org-bibtex-entries))
683 org-bibtex-entries))
682 684
683(defun org-bibtex-read-buffer (buffer) 685(defun org-bibtex-read-buffer (buffer)
684 "Read all bibtex entries in BUFFER and save to `org-bibtex-entries'. 686 "Read all bibtex entries in BUFFER and save to `org-bibtex-entries'.
diff --git a/lisp/org/org-list.el b/lisp/org/org-list.el
index 0dd8139a977..da309f8c6da 100644
--- a/lisp/org/org-list.el
+++ b/lisp/org/org-list.el
@@ -1442,7 +1442,7 @@ This function returns, destructively, the new list structure."
1442 (save-excursion 1442 (save-excursion
1443 (goto-char (org-list-get-last-item item struct prevs)) 1443 (goto-char (org-list-get-last-item item struct prevs))
1444 (point-at-eol))) 1444 (point-at-eol)))
1445 ((string-match-p "\\`[0-9]+\\'" dest) 1445 ((and (stringp dest) (string-match-p "\\`[0-9]+\\'" dest))
1446 (let* ((all (org-list-get-all-items item struct prevs)) 1446 (let* ((all (org-list-get-all-items item struct prevs))
1447 (len (length all)) 1447 (len (length all))
1448 (index (mod (string-to-number dest) len))) 1448 (index (mod (string-to-number dest) len)))
diff --git a/lisp/org/org-version.el b/lisp/org/org-version.el
index 572203711c0..336347b29c2 100644
--- a/lisp/org/org-version.el
+++ b/lisp/org/org-version.el
@@ -11,7 +11,7 @@ Inserted by installing Org mode or when a release is made."
11(defun org-git-version () 11(defun org-git-version ()
12 "The Git version of Org mode. 12 "The Git version of Org mode.
13Inserted by installing Org or when a release is made." 13Inserted by installing Org or when a release is made."
14 (let ((org-git-version "release_9.5.2-13-gdd6486")) 14 (let ((org-git-version "release_9.5.2-15-gc5ceb6"))
15 org-git-version)) 15 org-git-version))
16 16
17(provide 'org-version) 17(provide 'org-version)
diff --git a/lisp/shell.el b/lisp/shell.el
index c0a82bca183..6198214abee 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -942,7 +942,7 @@ Environment variables are expanded, see function `substitute-in-file-name'."
942 dir 942 dir
943 (if (file-name-absolute-p dir) 943 (if (file-name-absolute-p dir)
944 ;; The name is absolute, so prepend the prefix. 944 ;; The name is absolute, so prepend the prefix.
945 (concat comint-file-name-prefix dir) 945 (concat comint-file-name-prefix (file-local-name dir))
946 ;; For relative name we assume default-directory already has the prefix. 946 ;; For relative name we assume default-directory already has the prefix.
947 (expand-file-name dir)))) 947 (expand-file-name dir))))
948 948