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