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