Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2441 lines
102 KiB

  1. This is transient.info, produced by makeinfo version 6.5 from
  2. transient.texi.
  3. Copyright (C) 2018-2020 Jonas Bernoulli <jonas@bernoul.li>
  4. You can redistribute this document and/or modify it under the terms
  5. of the GNU General Public License as published by the Free Software
  6. Foundation, either version 3 of the License, or (at your option)
  7. any later version.
  8. This document is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. INFO-DIR-SECTION Emacs
  13. START-INFO-DIR-ENTRY
  14. * Transient: (transient). Transient Commands.
  15. END-INFO-DIR-ENTRY
  16. 
  17. File: transient.info, Node: Top, Next: Introduction, Up: (dir)
  18. Transient User and Developer Manual
  19. ***********************************
  20. Taking inspiration from prefix keys and prefix arguments, Transient
  21. implements a similar abstraction involving a prefix command, infix
  22. arguments and suffix commands. We could call this abstraction a
  23. "transient command", but because it always involves at least two
  24. commands (a prefix and a suffix) we prefer to call it just a
  25. "transient".
  26. When the user calls a transient prefix command, then a transient
  27. (temporary) keymap is activated, which binds the transient’s infix and
  28. suffix commands, and functions that control the transient state are
  29. added to ‘pre-command-hook’ and ‘post-command-hook’. The available
  30. suffix and infix commands and their state are shown in a popup buffer
  31. until the transient is exited by invoking a suffix command.
  32. Calling an infix command causes its value to be changed, possibly by
  33. reading a new value in the minibuffer.
  34. Calling a suffix command usually causes the transient to be exited
  35. but suffix commands can also be configured to not exit the transient.
  36. This manual is for Transient version 0.2.0.
  37. Copyright (C) 2018-2020 Jonas Bernoulli <jonas@bernoul.li>
  38. You can redistribute this document and/or modify it under the terms
  39. of the GNU General Public License as published by the Free Software
  40. Foundation, either version 3 of the License, or (at your option)
  41. any later version.
  42. This document is distributed in the hope that it will be useful,
  43. but WITHOUT ANY WARRANTY; without even the implied warranty of
  44. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  45. General Public License for more details.
  46. * Menu:
  47. * Introduction::
  48. * Usage::
  49. * Other Options::
  50. * Modifying Existing Transients::
  51. * Defining New Commands::
  52. * Classes and Methods::
  53. * Related Abstractions and Packages::
  54. * FAQ::
  55. * Keystroke Index::
  56. * Command Index::
  57. * Function Index::
  58. * Variable Index::
  59. — The Detailed Node Listing —
  60. Usage
  61. * Invoking Transients::
  62. * Aborting and Resuming Transients::
  63. * Common Suffix Commands::
  64. * Saving Values::
  65. * Using History::
  66. * Getting Help for Suffix Commands::
  67. * Enabling and Disabling Suffixes::
  68. * Other Commands::
  69. Defining New Commands
  70. * Defining Transients::
  71. * Binding Suffix and Infix Commands::
  72. * Defining Suffix and Infix Commands::
  73. * Using Infix Arguments::
  74. * Transient State::
  75. Binding Suffix and Infix Commands
  76. * Group Specifications::
  77. * Suffix Specifications::
  78. Classes and Methods
  79. * Group Classes::
  80. * Group Methods::
  81. * Prefix Classes::
  82. * Suffix Classes::
  83. * Suffix Methods::
  84. * Prefix Slots::
  85. * Suffix Slots::
  86. * Predicate Slots::
  87. Suffix Methods
  88. * Suffix Value Methods::
  89. * Suffix Format Methods::
  90. Related Abstractions and Packages
  91. * Comparison With Prefix Keys and Prefix Arguments::
  92. * Comparison With Other Packages::
  93. 
  94. File: transient.info, Node: Introduction, Next: Usage, Prev: Top, Up: Top
  95. 1 Introduction
  96. **************
  97. Taking inspiration from prefix keys and prefix arguments, Transient
  98. implements a similar abstraction involving a prefix command, infix
  99. arguments and suffix commands. We could call this abstraction a
  100. "transient command", but because it always involves at least two
  101. commands (a prefix and a suffix) we prefer to call it just a
  102. "transient".
  103. Transient keymaps are a feature provided by Emacs. Transients as
  104. implemented by this package involve the use of transient keymaps.
  105. Emacs provides a feature that it calls "prefix commands". When we
  106. talk about "prefix commands" in this manual, then we mean our own
  107. kind of "prefix commands", unless specified otherwise. To avoid
  108. ambiguity we sometimes use the terms "transient prefix command" for
  109. our kind and "regular prefix command" for Emacs’ kind.
  110. When the user calls a transient prefix command, then a transient
  111. (temporary) keymap is activated, which binds the transient’s infix and
  112. suffix commands, and functions that control the transient state are
  113. added to ‘pre-command-hook’ and ‘post-command-hook’. The available
  114. suffix and infix commands and their state are shown in a popup buffer
  115. until the transient state is exited by invoking a suffix command.
  116. Calling an infix command causes its value to be changed. How that is
  117. done depends on the type of the infix command. The simplest case is an
  118. infix command that represents a command-line argument that does not take
  119. a value. Invoking such an infix command causes the switch to be toggled
  120. on or off. More complex infix commands may read a value from the user,
  121. using the minibuffer.
  122. Calling a suffix command usually causes the transient to be exited;
  123. the transient keymaps and hook functions are removed, the popup buffer
  124. no longer shows information about the (no longer bound) suffix commands,
  125. the values of some public global variables are set, while some internal
  126. global variables are unset, and finally the command is actually called.
  127. Suffix commands can also be configured to not exit the transient.
  128. A suffix command can, but does not have to, use the infix arguments
  129. in much the same way it can choose to use or ignore the prefix
  130. arguments. For a suffix command that was invoked from a transient the
  131. variable ‘current-transient-suffixes’ and the function ‘transient-args’
  132. serve about the same purpose as the variables ‘prefix-arg’ and
  133. ‘current-prefix-arg’ do for any command that was called after the prefix
  134. arguments have been set using a command such as ‘universal-argument’.
  135. The information shown in the popup buffer while a transient is active
  136. looks a bit like this:
  137. ,-----------------------------------------
  138. |Arguments
  139. | -f Force (--force)
  140. | -a Annotate (--annotate)
  141. |
  142. |Create
  143. | t tag
  144. | r release
  145. `-----------------------------------------
  146. This is a simplified version of ‘magit-tag’. Info manuals do not
  147. support images or colored text, so the above "screenshot" lacks
  148. some information; in practice you would be able to tell whether the
  149. arguments ‘--force’ and ‘--annotate’ are enabled or not based on
  150. their color.
  151. Transient can be used to implement simple "command dispatchers". The
  152. main benefit then is that the user can see all the available commands in
  153. a popup buffer. That is useful by itself because it frees the user from
  154. having to remember all the keys that are valid after a certain prefix
  155. key or command. Magit’s ‘magit-dispatch’ command is an example of using
  156. Transient to merely implement a command dispatcher.
  157. In addition to that, Transient also allows users to interactively
  158. pass arguments to commands. These arguments can be much more complex
  159. than what is reasonable when using prefix arguments. There is a limit
  160. to how many aspects of a command can be controlled using prefix
  161. arguments. Furthermore what a certain prefix argument means for
  162. different commands can be completely different, and users have to read
  163. documentation to learn and then commit to memory what a certain prefix
  164. argument means to a certain command.
  165. Transient suffix commands on the other hand can accept dozens of
  166. different arguments without the user having to remember anything. When
  167. using Transient, then one can call a command with arguments that are
  168. just as complex as when calling the same function non-interactively
  169. using code.
  170. Invoking a transient command with arguments is similar to invoking a
  171. command in a shell with command-line completion and history enabled.
  172. One benefit of the Transient interface is that it remembers history not
  173. only on a global level ("this command was invoked using these arguments
  174. and previously it was invoked using those other arguments"), but also
  175. remembers the values of individual arguments independently. See *note
  176. Using History::.
  177. After a transient prefix command is invoked ‘C-h <key>’ can be used
  178. to show the documentation for the infix or suffix command that ‘<key>’
  179. is bound to (see *note Getting Help for Suffix Commands::) and infixes
  180. and suffixes can be removed from the transient using ‘C-x l <key>’.
  181. Infixes and suffixes that are disabled by default can be enabled the
  182. same way. See *note Enabling and Disabling Suffixes::.
  183. Transient ships with support for a few different types of specialized
  184. infix commands. A command that sets a command line option for example
  185. has different needs than a command that merely toggles a boolean flag.
  186. Additionally Transient provides abstractions for defining new types,
  187. which the author of Transient did not anticipate (or didn’t get around
  188. to implementing yet).
  189. 
  190. File: transient.info, Node: Usage, Next: Other Options, Prev: Introduction, Up: Top
  191. 2 Usage
  192. *******
  193. * Menu:
  194. * Invoking Transients::
  195. * Aborting and Resuming Transients::
  196. * Common Suffix Commands::
  197. * Saving Values::
  198. * Using History::
  199. * Getting Help for Suffix Commands::
  200. * Enabling and Disabling Suffixes::
  201. * Other Commands::
  202. 
  203. File: transient.info, Node: Invoking Transients, Next: Aborting and Resuming Transients, Up: Usage
  204. 2.1 Invoking Transients
  205. =======================
  206. A transient prefix command is invoked like any other command by pressing
  207. the key that is bound to that command. The main difference to other
  208. commands is that a transient prefix command activates a transient
  209. keymap, which temporarily binds the transient’s infix and suffix
  210. commands. Bindings from other keymaps may, or may not, be disabled
  211. while the transient state is in effect.
  212. There are two kinds of commands that are available after invoking a
  213. transient prefix command; infix and suffix commands. Infix commands set
  214. some value (which is then shown in a popup buffer), without leaving the
  215. transient. Suffix commands on the other hand usually quit the transient
  216. and they may use the values set by the infix commands, i.e. the infix
  217. *arguments*.
  218. Instead of setting arguments to be used by a suffix command, infix
  219. commands may also set some value by side-effect.
  220. 
  221. File: transient.info, Node: Aborting and Resuming Transients, Next: Common Suffix Commands, Prev: Invoking Transients, Up: Usage
  222. 2.2 Aborting and Resuming Transients
  223. ====================================
  224. To quit the transient without invoking a suffix command press ‘C-g’.
  225. Key bindings in transient keymaps may be longer than a single event.
  226. After pressing a valid prefix key, all commands whose bindings do not
  227. begin with that prefix key are temporarily unavailable and grayed out.
  228. To abort the prefix key press ‘C-g’ (which in this case only quits the
  229. prefix key, but not the complete transient).
  230. A transient prefix command can be bound as a suffix of another
  231. transient. Invoking such a suffix replaces the current transient state
  232. with a new transient state, i.e. the available bindings change and the
  233. information displayed in the popup buffer is updated accordingly.
  234. Pressing ‘C-g’ while a nested transient is active only quits the
  235. innermost transient, causing a return to the previous transient.
  236. ‘C-q’ or ‘C-z’ on the other hand always exits all transients. If you
  237. use the latter, then you can later resume the stack of transients using
  238. ‘M-x transient-resume’.
  239. ‘C-g’ (‘transient-quit-seq’)
  240. ‘C-g’ (‘transient-quit-one’)
  241. This key quits the currently active incomplete key sequence, if
  242. any, or else the current transient. When quitting the current
  243. transient, then it returns to the previous transient, if any.
  244. Transient’s predecessor bound ‘q’ instead of ‘C-g’ to the quit
  245. command. To learn how to get that binding back see
  246. ‘transient-bind-q-to-quit’’s doc string.
  247. ‘C-q’ (‘transient-quit-all’)
  248. This command quits the currently active incomplete key sequence, if
  249. any, and all transients, including the active transient and all
  250. suspended transients, if any.
  251. ‘C-z’ (‘transient-suspend’)
  252. Like ‘transient-quit-all’, this command quits an incomplete key
  253. sequence, if any, and all transients. Additionally it saves the
  254. stack of transients so that it can easily be resumed (which is
  255. particularly useful if you quickly need to do "something else" and
  256. the stack is deeper than a single transient and/or you have already
  257. changed the values of some infix arguments).
  258. Note that only a single stack of transients can be saved at a time.
  259. If another stack is already saved, then saving a new stack discards
  260. the previous stack.
  261. ‘M-x transient-resume’ (‘transient-resume’)
  262. This command resumes the previously suspended stack of transients,
  263. if any.
  264. 
  265. File: transient.info, Node: Common Suffix Commands, Next: Saving Values, Prev: Aborting and Resuming Transients, Up: Usage
  266. 2.3 Common Suffix Commands
  267. ==========================
  268. A few shared suffix commands are available in all transients. These
  269. suffix commands are not shown in the popup buffer by default.
  270. Most of these commands are bound to ‘C-x <key>’ and after pressing
  271. ‘C-x’ a section featuring all common commands is temporarily shown in
  272. the popup buffer. After invoking one of these commands, that section
  273. disappears again. Note however that one of these commands is described
  274. as "Show common permanently"; invoke that if you want the common
  275. commands to always be shown for all transients.
  276. ‘C-x t’ (‘transient-toggle-common’)
  277. This command toggles whether the generic commands that are common
  278. to all transients are always displayed or only after typing the
  279. incomplete prefix key sequence ‘C-x’. This only affects the
  280. current Emacs session.
  281. -- User Option: transient-show-common-commands
  282. This option controls whether shared suffix commands are shown
  283. alongside the transient-specific infix and suffix commands. By
  284. default the shared commands are not shown to avoid overwhelming the
  285. user with to many options.
  286. While a transient is active, pressing ‘C-x’ always shows the common
  287. command. The value of this option can be changed for the current
  288. Emacs session by typing ‘C-x t’ while a transient is active.
  289. The other common commands are described in either the previous node
  290. or in one of the following nodes.
  291. Some of Transient’s key bindings differ from the respective bindings
  292. of Magit-Popup; see *note FAQ:: for more information.
  293. 
  294. File: transient.info, Node: Saving Values, Next: Using History, Prev: Common Suffix Commands, Up: Usage
  295. 2.4 Saving Values
  296. =================
  297. After setting the infix arguments in a transient, the user can save
  298. those arguments for future invocations.
  299. Most transients will start out with the saved arguments when they are
  300. invoked. There are a few exceptions though. Some transients are
  301. designed so that the value that they use is stored externally as the
  302. buffer-local value of some variable. Invoking such a transient again
  303. uses the buffer-local value. (1)
  304. If the user does not save the value and just exits using a regular
  305. suffix command, then the value is merely saved to the transient’s
  306. history. That value won’t be used when the transient is next invoked
  307. but it is easily accessible (see *note Using History::).
  308. ‘C-x s’ (‘transient-set’)
  309. This command saves the value of the active transient for this Emacs
  310. session.
  311. ‘C-x C-s’ (‘transient-save’)
  312. Save the value of the active transient persistently across Emacs
  313. sessions.
  314. -- User Option: transient-values-file
  315. This file is used to persist the values of transients between Emacs
  316. sessions.
  317. ---------- Footnotes ----------
  318. (1) ‘magit-diff’ and ‘magit-log’ are two prominent examples, and
  319. their handling of buffer-local values is actually a bit more complicated
  320. than outlined above and even customizable. This is something I am
  321. rethinking, but I don’t want to rush any changes.)
  322. 
  323. File: transient.info, Node: Using History, Next: Getting Help for Suffix Commands, Prev: Saving Values, Up: Usage
  324. 2.5 Using History
  325. =================
  326. Every time the user invokes a suffix command the transient’s current
  327. value is saved to its history. These values can be cycled through the
  328. same way one can cycle through the history of commands that read
  329. user-input in the minibuffer.
  330. ‘M-p’ (‘transient-history-prev’)
  331. This command switches to the previous value used for the active
  332. transient.
  333. ‘M-n’ (‘transient-history-next’)
  334. This command switches to the next value used for the active
  335. transient.
  336. In addition to the transient-wide history, Transient of course
  337. supports per-infix history. When an infix reads user-input using the
  338. minibuffer, then the user can use the regular minibuffer history
  339. commands to cycle through previously used values. Usually the same keys
  340. as those mentioned above are bound to those commands.
  341. Authors of transients should arrange for different infix commands
  342. that read the same kind of value to also use the same history key (see
  343. *note Suffix Slots::).
  344. Both kinds of history are saved to a file when Emacs is exited.
  345. -- User Option: transient-history-file
  346. This file is used to persist the history of transients and their
  347. infixes between Emacs sessions.
  348. -- User Option: transient-history-limit
  349. This option controls how many history elements are kept at the time
  350. the history is saved in ‘transient-history-file’.
  351. 
  352. File: transient.info, Node: Getting Help for Suffix Commands, Next: Enabling and Disabling Suffixes, Prev: Using History, Up: Usage
  353. 2.6 Getting Help for Suffix Commands
  354. ====================================
  355. Transients can have many suffixes and infixes that the user might not be
  356. familiar with. To make it trivial to get help for these, Transient
  357. provides access to the documentation directly from the active transient.
  358. ‘C-h’ (‘transient-help’)
  359. This command enters help mode. When help mode is active, then
  360. typing ‘<key>’ shows information about the suffix command that
  361. ‘<key>’ normally is bound to (instead of invoking it). Pressing
  362. ‘C-h’ a second time shows information about the _prefix_ command.
  363. After typing ‘<key>’ the stack of transient states is suspended and
  364. information about the suffix command is shown instead. Typing ‘q’
  365. in the help buffer buries that buffer and resumes the transient
  366. state.
  367. What sort of documentation is shown depends on how the transient was
  368. defined. For infix commands that represent command-line arguments this
  369. ideally shows the appropriate manpage. ‘transient-help’ then tries to
  370. jump to the correct location within that. Info manuals are also
  371. supported. The fallback is to show the command’s doc string, for
  372. non-infix suffixes this is usually appropriate.
  373. 
  374. File: transient.info, Node: Enabling and Disabling Suffixes, Next: Other Commands, Prev: Getting Help for Suffix Commands, Up: Usage
  375. 2.7 Enabling and Disabling Suffixes
  376. ===================================
  377. The user base of a package that uses transients can be very diverse.
  378. This is certainly the case for Magit; some users have been using it and
  379. Git for a decade, while others are just getting started now.
  380. For that reason a mechanism is needed that authors can use to
  381. classify a transient’s infixes and suffixes along the
  382. essentials...everything spectrum. We use the term "levels" to describe
  383. that mechanism.
  384. Each suffix command is placed on a level and each transient has a
  385. level (called transient-level), which controls which suffix commands are
  386. available. Integers between 1 and 7 (inclusive) are valid levels. For
  387. suffixes, 0 is also valid; it means that the suffix is not displayed at
  388. any level.
  389. The levels of individual transients and/or their individual suffixes
  390. can be changed interactively, by invoking the transient and then
  391. pressing ‘C-x l’ to enter the "edit" mode, see below.
  392. The default level for both transients and their suffixes is 4. The
  393. ‘transient-default-level’ option only controls the default for
  394. transients. The default suffix level is always 4. The authors of
  395. transients should place certain suffixes on a higher level, if they
  396. expect that it won’t be of use to most users, and they should place very
  397. important suffixes on a lower level, so that they remain available even
  398. if the user lowers the transient level.
  399. (Magit currently places nearly all suffixes on level 4 and lower
  400. levels are not used at all yet. So for the time being you should not
  401. set a lower default level and using a higher level might not give you as
  402. many additional suffixes as you hoped.)
  403. -- User Option: transient-default-level
  404. This option controls which suffix levels are made available by
  405. default. It sets the transient-level for transients for which the
  406. user has not set that individually.
  407. -- User Option: transient-levels-file
  408. This file is used to persist the levels of transients and their
  409. suffixes between Emacs sessions.
  410. ‘C-x l’ (‘transient-set-level’)
  411. This command enters edit mode. When edit mode is active, then all
  412. infixes and suffixes that are currently usable are displayed along
  413. with their levels. The colors of the levels indicate whether they
  414. are enabled or not. The level of the transient is also displayed
  415. along with some usage information.
  416. In edit mode, pressing the key that would usually invoke a certain
  417. suffix instead prompts the user for the level that suffix should be
  418. placed on.
  419. Help mode is available in edit mode.
  420. To change the transient level press ‘C-x l’ again.
  421. To exit edit mode press ‘C-g’.
  422. Note that edit mode does not display any suffixes that are not
  423. currently usable. ‘magit-rebase’ for example shows different
  424. suffixes depending on whether a rebase is already in progress or
  425. not. The predicates also apply in edit mode.
  426. Therefore, to control which suffixes are available given a certain
  427. state, you have to make sure that that state is currently active.
  428. 
  429. File: transient.info, Node: Other Commands, Prev: Enabling and Disabling Suffixes, Up: Usage
  430. 2.8 Other Commands
  431. ==================
  432. When invoking a transient in a small frame, the transient window may not
  433. show the complete buffer, making it necessary to scroll, using the
  434. following commands. These commands are never shown in the transient
  435. window, and the key bindings are the same as for ‘scroll-up-command’ and
  436. ‘scroll-down-command’ in other buffers.
  437. -- Command: transient-scroll-up arg
  438. This command scrolls text of transient popup window upward ARG
  439. lines. If ARG is ‘nil’, then it scrolls near full screen. This is
  440. a wrapper around ‘scroll-up-command’ (which see).
  441. -- Command: transient-scroll-down arg
  442. This command scrolls text of transient popup window down ARG lines.
  443. If ARG is ‘nil’, then it scrolls near full screen. This is a
  444. wrapper around ‘scroll-down-command’ (which see).
  445. 
  446. File: transient.info, Node: Other Options, Next: Modifying Existing Transients, Prev: Usage, Up: Top
  447. 3 Other Options
  448. ***************
  449. -- User Option: transient-show-popup
  450. This option controls whether the current transient’s infix and
  451. suffix commands are shown in the popup buffer.
  452. • If ‘t’ (the default) then the popup buffer is shown as soon as
  453. a transient prefix command is invoked.
  454. • If ‘nil’, then the popup buffer is not shown unless the user
  455. explicitly requests it, by pressing an incomplete prefix key
  456. sequence.
  457. • If a number, then the a brief one-line summary is shown
  458. instead of the popup buffer. If zero or negative, then not
  459. even that summary is shown; only the pressed key itself is
  460. shown.
  461. The popup is shown when the user explicitly requests it by
  462. pressing an incomplete prefix key sequence. Unless this is
  463. zero, then the popup is shown after that many seconds of
  464. inactivity (using the absolute value).
  465. -- User Option: transient-enable-popup-navigation
  466. This option controls whether navigation commands are enabled in the
  467. transient popup.
  468. While a transient is active the transient popup buffer is not the
  469. current buffer, making it necessary to use dedicated commands to
  470. act on that buffer itself. This is disabled by default. If this
  471. option is non-nil, then the following features are available:
  472. • ‘<up>’ moves the cursor to the previous suffix. ‘<down>’
  473. moves the cursor to the next suffix. ‘RET’ invokes the suffix
  474. the cursor is on.
  475. • ‘<mouse-1>’ invokes the clicked on suffix.
  476. • ‘C-s’ and ‘C-r’ start isearch in the popup buffer.
  477. -- User Option: transient-display-buffer-action
  478. This option specifies the action used to display the transient
  479. popup buffer. The transient popup buffer is displayed in a window
  480. using ‘(display-buffer buf transient-display-buffer-action)’.
  481. The value of this option has the form ‘(FUNCTION . ALIST)’, where
  482. FUNCTION is a function or a list of functions. Each such function
  483. should accept two arguments: a buffer to display and an alist of
  484. the same form as ALIST. See *note (elisp)Choosing Window::.
  485. The default is ‘(display-buffer-in-side-window (side . bottom))’.
  486. This displays the window at the bottom of the selected frame.
  487. Another useful value is ‘(display-buffer-below-selected)’. This is
  488. what ‘magit-popup’ used by default. For more alternatives see
  489. *note (elisp)Display Action Functions::.
  490. It may be possible to display the window in another frame, but
  491. whether that works in practice depends on the window-manager. If
  492. the window manager selects the new window (Emacs frame), then it
  493. doesn’t work.
  494. If you change the value of this option, then you might also want to
  495. change the value of ‘transient-mode-line-format’.
  496. -- User Option: transient-mode-line-format
  497. This option controls whether the transient popup buffer has a
  498. mode-line, separator line, or neither.
  499. If ‘nil’, then the buffer has no mode-line. If the buffer is not
  500. displayed right above the echo area, then this probably is not a
  501. good value.
  502. If ‘line’ (the default), then the buffer also has no mode-line, but
  503. a thin line is drawn instead, using the background color of the
  504. face ‘transient-separator’. Termcap frames cannot display thin
  505. lines and therefore fallback to treating ‘line’ like ‘nil’.
  506. Otherwise this can be any mode-line format. See *note (elisp)Mode
  507. Line Format:: for details.
  508. -- User Option: transient-read-with-initial-input
  509. This option controls whether the last history element is used as
  510. the initial minibuffer input when reading the value of an infix
  511. argument from the user. If ‘nil’, then there is no initial input
  512. and the first element has to be accessed the same way as the older
  513. elements.
  514. -- User Option: transient-highlight-mismatched-keys
  515. This option controls whether key bindings of infix commands that do
  516. not match the respective command-line argument should be
  517. highlighted. For other infix commands this option has no effect.
  518. When this option is non-nil, then the key binding for an infix
  519. argument is highlighted when only a long argument (e.g.
  520. ‘--verbose’) is specified but no shorthand (e.g ‘-v’). In the rare
  521. case that a shorthand is specified but the key binding does not
  522. match, then it is highlighted differently.
  523. Highlighting mismatched key bindings is useful when learning the
  524. arguments of the underlying command-line tool; you wouldn’t want to
  525. learn any short-hands that do not actually exist.
  526. The highlighting is done using one of the faces
  527. ‘transient-mismatched-key’ and ‘transient-nonstandard-key’.
  528. -- User Option: transient-substitute-key-function
  529. This function is used to modify key bindings. If the value of this
  530. option is nil (the default), then no substitution is performed.
  531. This function is called with one argument, the prefix object, and
  532. must return a key binding description, either the existing key
  533. description it finds in the ‘key’ slot, or the key description that
  534. replaces the prefix key. It could be used to make other
  535. substitutions, but that is discouraged.
  536. For example, ‘=’ is hard to reach using my custom keyboard layout,
  537. so I substitute ‘(’ for that, which is easy to reach using a layout
  538. optimized for lisp.
  539. (setq transient-substitute-key-function
  540. (lambda (obj)
  541. (let ((key (oref obj key)))
  542. (if (string-match "\\`\\(=\\)[a-zA-Z]" key)
  543. (replace-match "(" t t key 1)
  544. key))))
  545. -- User Option: transient-detect-key-conflicts
  546. This option controls whether key binding conflicts should be
  547. detected at the time the transient is invoked. If so, then this
  548. results in an error, which prevents the transient from being used.
  549. Because of that, conflicts are ignored by default.
  550. Conflicts cannot be determined earlier, i.e. when the transient is
  551. being defined and when new suffixes are being added, because at
  552. that time there can be false-positives. It is actually valid for
  553. multiple suffixes to share a common key binding, provided the
  554. predicates of those suffixes prevent that more than one of them is
  555. enabled at a time.
  556. -- User Option: transient-force-fixed-pitch
  557. This option controls whether to force the use of a monospaced font
  558. in popup buffer. Even if you use a proportional font for the
  559. ‘default’ face, you might still want to use a monospaced font in
  560. transient’s popup buffer. Setting this option to t causes
  561. ‘default’ to be remapped to ‘fixed-pitch’ in that buffer.
  562. 
  563. File: transient.info, Node: Modifying Existing Transients, Next: Defining New Commands, Prev: Other Options, Up: Top
  564. 4 Modifying Existing Transients
  565. *******************************
  566. To an extent transients can be customized interactively, see *note
  567. Enabling and Disabling Suffixes::. This section explains how existing
  568. transients can be further modified non-interactively.
  569. The following functions share a few arguments:
  570. • PREFIX is a transient prefix command, a symbol.
  571. • SUFFIX is a transient infix or suffix specification in the same
  572. form as expected by ‘define-transient-command’. Note that an infix
  573. is a special kind of suffix. Depending on context "suffixes" means
  574. "suffixes (including infixes)" or "non-infix suffixes". Here it
  575. means the former. See *note Suffix Specifications::.
  576. SUFFIX may also be a group in the same form as expected by
  577. ‘define-transient-command’. See *note Group Specifications::.
  578. • LOC is a command, a key vector, a key description (a string as
  579. returned by ‘key-description’), or a list specifying coordinates
  580. (the last element may also be a command or key). For example ‘(1 0
  581. -1)’ identifies the last suffix (‘-1’) of the first subgroup (‘0’)
  582. of the second group (‘1’).
  583. If LOC is a list of coordinates, then it can be used to identify a
  584. group, not just an individual suffix command.
  585. The function ‘transient-get-suffix’ can be useful to determine
  586. whether a certain coordination list identifies the suffix or group
  587. that you expect it to identify. In hairy cases it may be necessary
  588. to look at the definition of the transient prefix command.
  589. These functions operate on the information stored in the
  590. ‘transient--layout’ property of the PREFIX symbol. Suffix entries in
  591. that tree are not objects but have the form ‘(LEVEL CLASS PLIST)’, where
  592. plist should set at least ‘:key’, ‘:description’ and ‘:command’.
  593. -- Function: transient-insert-suffix prefix loc suffix
  594. This function inserts suffix or group SUFFIX into PREFIX before
  595. LOC.
  596. -- Function: transient-append-suffix prefix loc suffix
  597. This function inserts suffix or group SUFFIX into PREFIX after LOC.
  598. -- Function: transient-replace-suffix prefix loc suffix
  599. This function replaces the suffix or group at LOC in PREFIX with
  600. suffix or group SUFFIX.
  601. -- Function: transient-remove-suffix prefix loc
  602. This function removes the suffix or group at LOC in PREFIX.
  603. -- Function: transient-get-suffix prefix loc
  604. This function returns the suffix or group at LOC in PREFIX. The
  605. returned value has the form mentioned above.
  606. -- Function: transient-suffix-put prefix loc prop value
  607. This function edits the suffix or group at LOC in PREFIX, by
  608. setting the PROP of its plist to VALUE.
  609. Most of these functions do not signal an error if they cannot perform
  610. the requested modification. The functions that insert new suffixes show
  611. a warning if LOC cannot be found in PREFIX, without signaling an error.
  612. The reason for doing it like this is that establishing a key binding
  613. (and that is what we essentially are trying to do here) should not
  614. prevent the rest of the configuration from loading. Among these
  615. functions only ‘transient-get-suffix’ and ‘transient-suffix-put’ may
  616. signal an error.
  617. 
  618. File: transient.info, Node: Defining New Commands, Next: Classes and Methods, Prev: Modifying Existing Transients, Up: Top
  619. 5 Defining New Commands
  620. ***********************
  621. * Menu:
  622. * Defining Transients::
  623. * Binding Suffix and Infix Commands::
  624. * Defining Suffix and Infix Commands::
  625. * Using Infix Arguments::
  626. * Transient State::
  627. 
  628. File: transient.info, Node: Defining Transients, Next: Binding Suffix and Infix Commands, Up: Defining New Commands
  629. 5.1 Defining Transients
  630. =======================
  631. A transient consists of a prefix command and at least one suffix
  632. command, though usually a transient has several infix and suffix
  633. commands. The below macro defines the transient prefix command *and*
  634. binds the transient’s infix and suffix commands. In other words, it
  635. defines the complete transient, not just the transient prefix command
  636. that is used to invoke that transient.
  637. -- Macro: define-transient-command name arglist [docstring] [keyword
  638. value]... group... [body...]
  639. This macro defines NAME as a transient prefix command and binds the
  640. transient’s infix and suffix commands.
  641. ARGLIST are the arguments that the prefix command takes. DOCSTRING
  642. is the documentation string and is optional.
  643. These arguments can optionally be followed by keyword-value pairs.
  644. Each key has to be a keyword symbol, either ‘:class’ or a keyword
  645. argument supported by the constructor of that class. The
  646. ‘transient-prefix’ class is used if the class is not specified
  647. explicitly.
  648. GROUPs add key bindings for infix and suffix commands and specify
  649. how these bindings are presented in the popup buffer. At least one
  650. GROUP has to be specified. See *note Binding Suffix and Infix
  651. Commands::.
  652. The BODY is optional. If it is omitted, then ARGLIST is ignored
  653. and the function definition becomes:
  654. (lambda ()
  655. (interactive)
  656. (transient-setup 'NAME))
  657. If BODY is specified, then it must begin with an ‘interactive’ form
  658. that matches ARGLIST, and it must call ‘transient-setup’. It may
  659. however call that function only when some condition is satisfied.
  660. All transients have a (possibly ‘nil’) value, which is exported
  661. when suffix commands are called, so that they can consume that
  662. value. For some transients it might be necessary to have a sort of
  663. secondary value, called a "scope". Such a scope would usually be
  664. set in the command’s ‘interactive’ form and has to be passed to the
  665. setup function:
  666. (transient-setup 'NAME nil nil :scope SCOPE)
  667. For example, the scope of the ‘magit-branch-configure’ transient is
  668. the branch whose variables are being configured.
  669. 
  670. File: transient.info, Node: Binding Suffix and Infix Commands, Next: Defining Suffix and Infix Commands, Prev: Defining Transients, Up: Defining New Commands
  671. 5.2 Binding Suffix and Infix Commands
  672. =====================================
  673. The macro ‘define-transient-command’ is used to define a transient.
  674. This defines the actual transient prefix command (see *note Defining
  675. Transients::) and adds the transient’s infix and suffix bindings, as
  676. described below.
  677. Users and third-party packages can add additional bindings using
  678. functions such as ‘transient-insert-suffix’ (See *note Modifying
  679. Existing Transients::). These functions take a "suffix specification"
  680. as one of their arguments, which has the same form as the specifications
  681. used in ‘define-transient-command’.
  682. * Menu:
  683. * Group Specifications::
  684. * Suffix Specifications::
  685. 
  686. File: transient.info, Node: Group Specifications, Next: Suffix Specifications, Up: Binding Suffix and Infix Commands
  687. 5.2.1 Group Specifications
  688. --------------------------
  689. The suffix and infix commands of a transient are organized in groups.
  690. The grouping controls how the descriptions of the suffixes are outlined
  691. visually but also makes it possible to set certain properties for a set
  692. of suffixes.
  693. Several group classes exist, some of which organize suffixes in
  694. subgroups. In most cases the class does not have to be specified
  695. explicitly, but see *note Group Classes::.
  696. Groups are specified in the call to ‘define-transient-command’, using
  697. vectors. Because groups are represented using vectors, we cannot use
  698. square brackets to indicate an optional element and instead use curly
  699. brackets to do the latter.
  700. Group specifications then have this form:
  701. [{LEVEL} {DESCRIPTION} {KEYWORD VALUE}... ELEMENT...]
  702. The LEVEL is optional and defaults to 4. See *note Enabling and
  703. Disabling Suffixes::.
  704. The DESCRIPTION is optional. If present it is used as the heading of
  705. the group.
  706. The KEYWORD-VALUE pairs are optional. Each keyword has to be a
  707. keyword symbol, either ‘:class’ or a keyword argument supported by the
  708. constructor of that class.
  709. • One of these keywords, ‘:description’, is equivalent to specifying
  710. DESCRIPTION at the very beginning of the vector. The
  711. recommendation is to use ‘:description’ if some other keyword is
  712. also used, for consistency, or DESCRIPTION otherwise, because it
  713. looks better.
  714. • Likewise ‘:level’ is equivalent to LEVEL.
  715. • Other important keywords include the ‘:if...’ keywords. These
  716. keywords control whether the group is available in a certain
  717. situation.
  718. For example, one group of the ‘magit-rebase’ transient uses ‘:if
  719. magit-rebase-in-progress-p’, which contains the suffixes that are
  720. useful while rebase is already in progress; and another that uses
  721. ‘:if-not magit-rebase-in-progress-p’, which contains the suffixes
  722. that initiate a rebase.
  723. These predicates can also be used on individual suffixes and are
  724. only documented once, see *note Predicate Slots::.
  725. • Finally the value of ‘:hide’, if non-nil, is a predicate that
  726. controls whether the group is hidden by default. The key bindings
  727. for suffixes of a hidden group should all use the same prefix key.
  728. Pressing that prefix key should temporarily show the group and its
  729. suffixes, which assumes that a predicate like this is used:
  730. (lambda ()
  731. (eq (car transient--redisplay-key)
  732. ?\C-c)) ; the prefix key shared by all bindings
  733. The ELEMENTs are either all subgroups (vectors), or all suffixes
  734. (lists) and strings. (At least currently no group type exists that
  735. would allow mixing subgroups with commands at the same level, though in
  736. principle there is nothing that prevents that.)
  737. If the ELEMENTs are not subgroups, then they can be a mixture of
  738. lists that specify commands and strings. Strings are inserted verbatim.
  739. The empty string can be used to insert gaps between suffixes, which is
  740. particularly useful if the suffixes are outlined as a table.
  741. The form of suffix specifications is documented in the next node.
  742. 
  743. File: transient.info, Node: Suffix Specifications, Prev: Group Specifications, Up: Binding Suffix and Infix Commands
  744. 5.2.2 Suffix Specifications
  745. ---------------------------
  746. A transient’s suffix and infix commands are bound when the transient
  747. prefix command is defined using ‘define-transient-command’, see *note
  748. Defining Transients::. The commands are organized into groups, see
  749. *note Group Specifications::. Here we describe the form used to bind an
  750. individual suffix command.
  751. The same form is also used when later binding additional commands
  752. using functions such as ‘transient-insert-suffix’, see *note Modifying
  753. Existing Transients::.
  754. Note that an infix is a special kind of suffix. Depending on context
  755. "suffixes" means "suffixes (including infixes)" or "non-infix suffixes".
  756. Here it means the former.
  757. Suffix specifications have this form:
  758. ([LEVEL] [KEY] [DESCRIPTION] COMMAND|ARGUMENT [KEYWORD VALUE]...)
  759. LEVEL, KEY and DESCRIPTION can also be specified using the KEYWORDs
  760. ‘:level’, ‘:key’ and ‘:description’. If the object that is associated
  761. with COMMAND sets these properties, then they do not have to be
  762. specified here. You can however specify them here anyway, possibly
  763. overriding the object’s values just for the binding inside this
  764. transient.
  765. • LEVEL is the suffix level, an integer between 1 and 7. See *note
  766. Enabling and Disabling Suffixes::.
  767. • KEY is the key binding, either a vector or key description string.
  768. • DESCRIPTION is the description, either a string or a function that
  769. returns a string. The function should be a lambda expression to
  770. avoid ambiguity. In some cases a symbol that is bound as a
  771. function would also work but to be safe you should use
  772. ‘:description’ in that case.
  773. The next element is either a command or an argument. This is the
  774. only argument that is mandatory in all cases.
  775. • COMMAND is a symbol that is bound as a function, which has to be a
  776. command. Any command will do; it does not need to have an object
  777. associated with it (as would be the case if ‘define-suffix-command’
  778. or ‘define-infix-command’ were used to define it).
  779. As mentioned above, the object that is associated with a command
  780. can be used to set the default for certain values that otherwise
  781. have to be set in the suffix specification. Therefore if there is
  782. no object, then you have to make sure to specify the KEY and the
  783. DESCRIPTION.
  784. • The mandatory argument can also be a command-line argument, a
  785. string. In that case an anonymous command is defined and bound.
  786. Instead of a string, this can also be a list of two strings, in
  787. which case the first string is used as the short argument (which
  788. can also be specified using ‘:shortarg’) and the second as the long
  789. argument (which can also be specified using ‘:argument’).
  790. Only the long argument is displayed in the popup buffer. See
  791. ‘transient-detect-key-conflicts’ for how the short argument may be
  792. used.
  793. Unless the class is specified explicitly, the appropriate class is
  794. guessed based on the long argument. If the argument ends with "=​"
  795. (e.g. "–format=") then ‘transient-option’ is used, otherwise
  796. ‘transient-switch’.
  797. Finally, details can be specified using optional KEYWORD-VALUE pairs.
  798. Each keyword has to be a keyword symbol, either ‘:class’ or a keyword
  799. argument supported by the constructor of that class. See *note Suffix
  800. Slots::.
  801. 
  802. File: transient.info, Node: Defining Suffix and Infix Commands, Next: Using Infix Arguments, Prev: Binding Suffix and Infix Commands, Up: Defining New Commands
  803. 5.3 Defining Suffix and Infix Commands
  804. ======================================
  805. Note that an infix is a special kind of suffix. Depending on context
  806. "suffixes" means "suffixes (including infixes)" or "non-infix suffixes".
  807. -- Macro: define-suffix-command name arglist [docstring] [keyword
  808. value]... body...
  809. This macro defines NAME as a transient suffix command.
  810. ARGLIST are the arguments that the command takes. DOCSTRING is the
  811. documentation string and is optional.
  812. These arguments can optionally be followed by keyword-value pairs.
  813. Each keyword has to be a keyword symbol, either ‘:class’ or a
  814. keyword argument supported by the constructor of that class. The
  815. ‘transient-suffix’ class is used if the class is not specified
  816. explicitly.
  817. The BODY must begin with an ‘interactive’ form that matches
  818. ARGLIST. The infix arguments are usually accessed by using
  819. ‘transient-args’ inside ‘interactive’.
  820. -- Macro: define-infix-command name arglist [docstring] [keyword
  821. value]...
  822. This macro defines NAME as a transient infix command.
  823. ARGLIST is always ignored (but mandatory never-the-less) and
  824. reserved for future use. DOCSTRING is the documentation string and
  825. is optional.
  826. The keyword-value pairs are mandatory. All transient infix
  827. commands are ‘equal’ to each other (but not ‘eq’), so it is
  828. meaningless to define an infix command without also setting at
  829. least ‘:class’ and one other keyword (which it is depends on the
  830. used class, usually ‘:argument’ or ‘:variable’).
  831. Each keyword has to be a keyword symbol, either ‘:class’ or a
  832. keyword argument supported by the constructor of that class. The
  833. ‘transient-switch’ class is used if the class is not specified
  834. explicitly.
  835. The function definition is always:
  836. (lambda ()
  837. (interactive)
  838. (let ((obj (transient-suffix-object)))
  839. (transient-infix-set obj (transient-infix-read obj)))
  840. (transient--show))
  841. ‘transient-infix-read’ and ‘transient-infix-set’ are generic
  842. functions. Different infix commands behave differently because the
  843. concrete methods are different for different infix command classes.
  844. In rare cases the above command function might not be suitable,
  845. even if you define your own infix command class. In that case you
  846. have to use ‘transient-suffix-command’ to define the infix command
  847. and use ‘t’ as the value of the ‘:transient’ keyword.
  848. -- Macro: define-infix-argument name arglist [docstring] [keyword
  849. value]...
  850. This macro defines NAME as a transient infix command.
  851. It is an alias for ‘define-infix-command’. Only use this alias to
  852. define an infix command that actually sets an infix argument. To
  853. define an infix command that, for example, sets a variable, use
  854. ‘define-infix-command’ instead.
  855. 
  856. File: transient.info, Node: Using Infix Arguments, Next: Transient State, Prev: Defining Suffix and Infix Commands, Up: Defining New Commands
  857. 5.4 Using Infix Arguments
  858. =========================
  859. The function and the variables described below allow suffix commands to
  860. access the value of the transient from which they were invoked; which is
  861. the value of its infix arguments. These variables are set when the user
  862. invokes a suffix command that exits the transient, but before actually
  863. calling the command.
  864. When returning to the command-loop after calling the suffix command,
  865. the arguments are reset to ‘nil’ (which causes the function to return
  866. ‘nil’ too).
  867. Like for Emacs’ prefix arguments it is advisable, but not mandatory,
  868. to access the infix arguments inside the command’s ‘interactive’ form.
  869. The preferred way of doing that is to call the ‘transient-args’
  870. function, which for infix arguments serves about the same purpose as
  871. ‘prefix-arg’ serves for prefix arguments.
  872. -- Function: transient-args &optional prefix
  873. This function returns the value of the transient prefix command
  874. PREFIX.
  875. If the current command was invoked from the transient prefix
  876. command PREFIX, then it returns the active infix arguments. If the
  877. current command was not invoked from PREFIX, then it returns the
  878. set, saved or default value for PREFIX.
  879. -- Variable: current-transient-suffixes
  880. The suffixes of the transient from which this suffix command was
  881. invoked. This is a list of objects. Usually it is sufficient to
  882. instead use the function ‘transient-args’, which returns a list of
  883. values. In complex cases it might be necessary to use this
  884. variable instead, i.e. if you need access to information beside
  885. the value.
  886. -- Variable: current-transient-prefix
  887. The transient from which this suffix command was invoked. The
  888. returned value is a ‘transient-prefix’ object, which holds
  889. information associated with the transient prefix command.
  890. -- Variable: current-transient-command
  891. The transient from which this suffix command was invoked. The
  892. returned value is a symbol, the transient prefix command.
  893. 
  894. File: transient.info, Node: Transient State, Prev: Using Infix Arguments, Up: Defining New Commands
  895. 5.5 Transient State
  896. ===================
  897. Invoking a transient prefix command "activates" the respective
  898. transient, i.e. it puts a transient keymap into effect, which binds the
  899. transient’s infix and suffix commands.
  900. The default behavior while a transient is active is as follows:
  901. • Invoking an infix command does not affect the transient state; the
  902. transient remains active.
  903. • Invoking a (non-infix) suffix command "deactivates" the transient
  904. state by removing the transient keymap and performing some
  905. additional cleanup.
  906. • Invoking a command that is bound in a keymap other than the
  907. transient keymap is disallowed and trying to do so results in a
  908. warning. This does not "deactivate" the transient.
  909. But these are just the defaults. Whether a certain command
  910. deactivates or "exits" the transient is configurable. There is more
  911. than one way in which a command can be "transient" or "non-transient";
  912. the exact behavior is implemented by calling a so-called "pre-command"
  913. function. Whether non-suffix commands are allowed to be called is
  914. configurable per transient.
  915. • The transient-ness of suffix commands (including infix commands) is
  916. controlled by the value of their ‘transient’ slot, which can be set
  917. either when defining the command or when adding a binding to a
  918. transient while defining the respective transient prefix command.
  919. Valid values are booleans and the pre-commands described below.
  920. • ‘t’ is equivalent to ‘transient--do-stay’.
  921. • ‘nil’ is equivalent to ‘transient--do-exit’.
  922. • If ‘transient’ is unbound (and that is actually the default
  923. for non-infix suffixes) then the value of the prefix’s
  924. ‘transient-suffix’ slot is used instead. The default value of
  925. that slot is ‘nil’, so the suffix’s ‘transient’ slot being
  926. unbound is essentially equivalent to it being ‘nil’.
  927. • A suffix command can be a prefix command itself, i.e. a
  928. "sub-prefix". While a sub-prefix is active we nearly always want
  929. ‘C-g’ to take the user back to the "super-prefix". However in rare
  930. cases this may not be desirable, and that makes the following
  931. complication necessary:
  932. For ‘transient-suffix’ objects the ‘transient’ slot is unbound. We
  933. can ignore that for the most part because, as stated above, ‘nil’
  934. and the slot being unbound are equivalent, and mean "do exit".
  935. That isn’t actually true for suffixes that are sub-prefixes though.
  936. For such suffixes unbound means "do exit but allow going back",
  937. which is the default, while ‘nil’ means "do exit permanently",
  938. which requires that slot to be explicitly set to that value.
  939. • The transient-ness of certain built-in suffix commands is specified
  940. using ‘transient-predicate-map’. This is a special keymap, which
  941. binds commands to pre-commands (as opposed to keys to commands) and
  942. takes precedence over the ‘transient’ slot.
  943. The available pre-command functions are documented below. They are
  944. called by ‘transient--pre-command’, a function on ‘pre-command-hook’ and
  945. the value that they return determines whether the transient is exited.
  946. To do so the value of one of the constants ‘transient--exit’ or
  947. ‘transient--stay’ is used (that way we don’t have to remember if ‘t’
  948. means "exit" or "stay").
  949. Additionally these functions may change the value of ‘this-command’
  950. (which explains why they have to be called using ‘pre-command-hook’),
  951. call ‘transient-export’, ‘transient--stack-zap’ or
  952. ‘transient--stack-push’; and set the values of ‘transient--exitp’,
  953. ‘transient--helpp’ or ‘transient--editp’.
  954. 5.5.1 Pre-commands for Infixes
  955. ------------------------------
  956. The default for infixes is ‘transient--do-stay’. This is also the only
  957. function that makes sense for infixes.
  958. -- Function: transient--do-stay
  959. Call the command without exporting variables and stay transient.
  960. 5.5.2 Pre-commands for Suffixes
  961. -------------------------------
  962. The default for suffixes is ‘transient--do-exit’.
  963. -- Function: transient--do-exit
  964. Call the command after exporting variables and exit the transient.
  965. -- Function: transient--do-call
  966. Call the command after exporting variables and stay transient.
  967. -- Function: transient--do-replace
  968. Call the transient prefix command, replacing the active transient.
  969. This is used for suffixes that are prefixes themselves, i.e. for
  970. sub-prefixes.
  971. 5.5.3 Pre-commands for Non-Suffixes
  972. -----------------------------------
  973. The default for non-suffixes, i.e commands that are bound in other
  974. keymaps beside the transient keymap, is ‘transient--do-warn’. Silently
  975. ignoring the user-error is also an option, though probably not a good
  976. one.
  977. If you want to let the user invoke non-suffix commands, then use
  978. ‘transient--do-stay’ as the value of the prefix’s ‘transient-non-suffix’
  979. slot.
  980. -- Function: transient--do-warn
  981. Call ‘transient-undefined’ and stay transient.
  982. -- Function: transient--do-noop
  983. Call ‘transient-noop’ and stay transient.
  984. 5.5.4 Special Pre-Commands
  985. --------------------------
  986. -- Function: transient--do-quit-one
  987. If active, quit help or edit mode, else exit the active transient.
  988. This is used when the user pressed ‘C-g’.
  989. -- Function: transient--do-quit-all
  990. Exit all transients without saving the transient stack.
  991. This is used when the user pressed ‘C-q’.
  992. -- Function: transient--do-suspend
  993. Suspend the active transient, saving the transient stack.
  994. This is used when the user pressed ‘C-z’.
  995. 
  996. File: transient.info, Node: Classes and Methods, Next: Related Abstractions and Packages, Prev: Defining New Commands, Up: Top
  997. 6 Classes and Methods
  998. *********************
  999. Transient uses classes and generic functions to make it possible to
  1000. define new types of suffix commands that are similar to existing types,
  1001. but behave differently in some aspects. It does the same for groups and
  1002. prefix commands, though at least for prefix commands that *currently*
  1003. appears to be less important.
  1004. Every prefix, infix and suffix command is associated with an object,
  1005. which holds information that controls certain aspects of its behavior.
  1006. This happens in two ways.
  1007. • Associating a command with a certain class gives the command a
  1008. type. This makes it possible to use generic functions to do
  1009. certain things that have to be done differently depending on what
  1010. type of command it acts on.
  1011. That in turn makes it possible for third-parties to add new types
  1012. without having to convince the maintainer of Transient that that
  1013. new type is important enough to justify adding a special case to a
  1014. dozen or so functions.
  1015. • Associating a command with an object makes it possible to easily
  1016. store information that is specific to that particular command.
  1017. Two commands may have the same type, but obviously their key
  1018. bindings and descriptions still have to be different, for example.
  1019. The values of some slots are functions. The ‘reader’ slot for
  1020. example holds a function that is used to read a new value for an
  1021. infix command. The values of such slots are regular functions.
  1022. Generic functions are used when a function should do something
  1023. different based on the type of the command, i.e. when all commands
  1024. of a certain type should behave the same way but different from the
  1025. behavior for other types. Object slots that hold a regular
  1026. function as value are used when the task that they perform is
  1027. likely to differ even between different commands of the same type.
  1028. * Menu:
  1029. * Group Classes::
  1030. * Group Methods::
  1031. * Prefix Classes::
  1032. * Suffix Classes::
  1033. * Suffix Methods::
  1034. * Prefix Slots::
  1035. * Suffix Slots::
  1036. * Predicate Slots::
  1037. 
  1038. File: transient.info, Node: Group Classes, Next: Group Methods, Up: Classes and Methods
  1039. 6.1 Group Classes
  1040. =================
  1041. The type of a group can be specified using the ‘:class’ property at the
  1042. beginning of the class specification, e.g. ‘[:class transient-columns
  1043. ...]’ in a call to ‘define-transient-command’.
  1044. • The abstract ‘transient-child’ class is the base class of both
  1045. ‘transient-group’ (and therefore all groups) as well as of
  1046. ‘transient-suffix’ (and therefore all suffix and infix commands).
  1047. This class exists because the elements (aka "children") of certain
  1048. groups can be other groups instead of suffix and infix commands.
  1049. • The abstract ‘transient-group’ class is the superclass of all other
  1050. group classes.
  1051. • The ‘transient-column’ class is the simplest group.
  1052. This is the default "flat" group. If the class is not specified
  1053. explicitly and the first element is not a vector (i.e. not a
  1054. group), then this class is used.
  1055. This class displays each element on a separate line.
  1056. • The ‘transient-row’ class displays all elements on a single line.
  1057. • The ‘transient-columns’ class displays commands organized in
  1058. columns.
  1059. Direct elements have to be groups whose elements have to be
  1060. commands or strings. Each subgroup represents a column. This
  1061. class takes care of inserting the subgroups’ elements.
  1062. This is the default "nested" group. If the class is not specified
  1063. explicitly and the first element is a vector (i.e. a group), then
  1064. this class is used.
  1065. • The ‘transient-subgroups’ class wraps other groups.
  1066. Direct elements have to be groups whose elements have to be
  1067. commands or strings. This group inserts an empty line between
  1068. subgroups. The subgroups themselves are responsible for displaying
  1069. their elements.
  1070. 
  1071. File: transient.info, Node: Group Methods, Next: Prefix Classes, Prev: Group Classes, Up: Classes and Methods
  1072. 6.2 Group Methods
  1073. =================
  1074. -- Function: transient--insert-group group
  1075. This generic function formats the group and its elements and
  1076. inserts the result into the current buffer, which is a temporary
  1077. buffer. The contents of that buffer are later inserted into the
  1078. popup buffer.
  1079. Functions that are called by this function may need to operate in
  1080. the buffer from which the transient was called. To do so they can
  1081. temporally make the ‘transient--source-buffer’ the current buffer.
  1082. 
  1083. File: transient.info, Node: Prefix Classes, Next: Suffix Classes, Prev: Group Methods, Up: Classes and Methods
  1084. 6.3 Prefix Classes
  1085. ==================
  1086. Currently the ‘transient-prefix’ class is being used for all prefix
  1087. commands and there is only a single generic function that can be
  1088. specialized based on the class of a prefix command.
  1089. -- Function: transient--history-init obj
  1090. This generic function is called while setting up the transient and
  1091. is responsible for initializing the ‘history’ slot. This is the
  1092. transient-wide history; many individual infixes also have a history
  1093. of their own.
  1094. The default (and currently only) method extracts the value from the
  1095. global variable ‘transient-history’.
  1096. A transient prefix command’s object is stored in the
  1097. ‘transient--prefix’ property of the command symbol. While a transient
  1098. is active, a clone of that object is stored in the variable
  1099. ‘transient--prefix’. A clone is used because some changes that are made
  1100. to the active transient’s object should not affect later invocations.
  1101. 
  1102. File: transient.info, Node: Suffix Classes, Next: Suffix Methods, Prev: Prefix Classes, Up: Classes and Methods
  1103. 6.4 Suffix Classes
  1104. ==================
  1105. • All suffix and infix classes derive from ‘transient-suffix’, which
  1106. in turn derives from ‘transient-child’, from which
  1107. ‘transient-group’ also derives (see *note Group Classes::).
  1108. • All infix classes derive from the abstract ‘transient-infix’ class,
  1109. which in turn derives from the ‘transient-suffix’ class.
  1110. Infixes are a special type of suffixes. The primary difference is
  1111. that infixes always use the ‘transient--do-stay’ pre-command, while
  1112. non-infix suffixes use a variety of pre-commands (see *note
  1113. Transient State::). Doing that is most easily achieved by using
  1114. this class, though theoretically it would be possible to define an
  1115. infix class that does not do so. If you do that then you get to
  1116. implement many methods.
  1117. Also, infixes and non-infix suffixes are usually defined using
  1118. different macros (see *note Defining Suffix and Infix Commands::).
  1119. • Classes used for infix commands that represent arguments should be
  1120. derived from the abstract ‘transient-argument’ class.
  1121. • The ‘transient-switch’ class (or a derived class) is used for infix
  1122. arguments that represent command-line switches (arguments that do
  1123. not take a value).
  1124. • The ‘transient-option’ class (or a derived class) is used for infix
  1125. arguments that represent command-line options (arguments that do
  1126. take a value).
  1127. • The ‘transient-switches’ class can be used for a set of mutually
  1128. exclusive command-line switches.
  1129. • The ‘transient-files’ class can be used for a "–" argument that
  1130. indicates that all remaining arguments are files.
  1131. • Classes used for infix commands that represent variables should
  1132. derived from the abstract ‘transient-variables’ class.
  1133. Magit defines additional classes, which can serve as examples for the
  1134. fancy things you can do without modifying Transient. Some of these
  1135. classes will likely get generalized and added to Transient. For now
  1136. they are very much subject to change and not documented.
  1137. 
  1138. File: transient.info, Node: Suffix Methods, Next: Prefix Slots, Prev: Suffix Classes, Up: Classes and Methods
  1139. 6.5 Suffix Methods
  1140. ==================
  1141. To get information about the methods implementing these generic
  1142. functions use ‘describe-function’.
  1143. * Menu:
  1144. * Suffix Value Methods::
  1145. * Suffix Format Methods::
  1146. 
  1147. File: transient.info, Node: Suffix Value Methods, Next: Suffix Format Methods, Up: Suffix Methods
  1148. 6.5.1 Suffix Value Methods
  1149. --------------------------
  1150. -- Function: transient-init-value obj
  1151. This generic function sets the initial value of the object OBJ.
  1152. This function is called for all suffix commands, but unless a
  1153. concrete method is implemented this falls through to the default
  1154. implementation, which is a noop. In other words this usually only
  1155. does something for infix commands, but note that this is not
  1156. implemented for the abstract class ‘transient-infix’, so if your
  1157. class derives from that directly, then you must implement a method.
  1158. -- Function: transient-infix-read obj
  1159. This generic function determines the new value of the infix object
  1160. OBJ.
  1161. This function merely determines the value; ‘transient-infix-set’ is
  1162. used to actually store the new value in the object.
  1163. For most infix classes this is done by reading a value from the
  1164. user using the reader specified by the ‘reader’ slot (using the
  1165. ‘transient-infix-value’ method described below).
  1166. For some infix classes the value is changed without reading
  1167. anything in the minibuffer, i.e. the mere act of invoking the
  1168. infix command determines what the new value should be, based on the
  1169. previous value.
  1170. -- Function: transient-prompt obj
  1171. This generic function returns the prompt to be used to read infix
  1172. object OBJ’s value.
  1173. -- Function: transient-infix-set obj value
  1174. This generic function sets the value of infix object OBJ to VALUE.
  1175. -- Function: transient-infix-value obj
  1176. This generic function returns the value of the suffix object OBJ.
  1177. This function is called by ‘transient-args’ (which see), meaning
  1178. this function is how the value of a transient is determined so that
  1179. the invoked suffix command can use it.
  1180. Currently most values are strings, but that is not set in stone.
  1181. ‘nil’ is not a value, it means "no value".
  1182. Usually only infixes have a value, but see the method for
  1183. ‘transient-suffix’.
  1184. -- Function: transient-init-scope obj
  1185. This generic function sets the scope of the suffix object OBJ.
  1186. The scope is actually a property of the transient prefix, not of
  1187. individual suffixes. However it is possible to invoke a suffix
  1188. command directly instead of from a transient. In that case, if the
  1189. suffix expects a scope, then it has to determine that itself and
  1190. store it in its ‘scope’ slot.
  1191. This function is called for all suffix commands, but unless a
  1192. concrete method is implemented this falls through to the default
  1193. implementation, which is a noop.
  1194. 
  1195. File: transient.info, Node: Suffix Format Methods, Prev: Suffix Value Methods, Up: Suffix Methods
  1196. 6.5.2 Suffix Format Methods
  1197. ---------------------------
  1198. -- Function: transient-format obj
  1199. This generic function formats and returns OBJ for display.
  1200. When this function is called, then the current buffer is some
  1201. temporary buffer. If you need the buffer from which the prefix
  1202. command was invoked to be current, then do so by temporarily making
  1203. ‘transient--source-buffer’ current.
  1204. -- Function: transient-format-key obj
  1205. This generic function formats OBJ’s ‘key’ for display and returns
  1206. the result.
  1207. -- Function: transient-format-description obj
  1208. This generic function formats OBJ’s ‘description’ for display and
  1209. returns the result.
  1210. -- Function: transient-format-value obj
  1211. This generic function formats OBJ’s value for display and returns
  1212. the result.
  1213. -- Function: transient-show-help obj
  1214. Show help for the prefix, infix or suffix command represented by
  1215. OBJ.
  1216. For prefixes, show the info manual, if that is specified using the
  1217. ‘info-manual’ slot. Otherwise show the manpage if that is
  1218. specified using the ‘man-page’ slot. Otherwise show the command’s
  1219. doc string.
  1220. For suffixes, show the command’s doc string.
  1221. For infixes, show the manpage if that is specified. Otherwise show
  1222. the command’s doc string.
  1223. 
  1224. File: transient.info, Node: Prefix Slots, Next: Suffix Slots, Prev: Suffix Methods, Up: Classes and Methods
  1225. 6.6 Prefix Slots
  1226. ================
  1227. • ‘man-page’ or ‘info-manual’ can be used to specify the
  1228. documentation for the prefix and its suffixes. The command
  1229. ‘transient-help’ uses the method ‘transient-show-help’ (which see)
  1230. to lookup and use these values.
  1231. • ‘history-key’ If multiple prefix commands should share a single
  1232. value, then this slot has to be set to the same value for all of
  1233. them. You probably don’t want that.
  1234. • ‘transient-suffix’ and ‘transient-non-suffix’ play a part when
  1235. determining whether the currently active transient prefix command
  1236. remains active/transient when a suffix or abitrary non-suffix
  1237. command is invoked. See *note Transient State::.
  1238. • ‘incompatible’ A list of lists. Each sub-list specifies a set of
  1239. mutually exclusive arguments. Enabling one of these arguments
  1240. causes the others to be disabled.
  1241. • ‘scope’ For some transients it might be necessary to have a sort of
  1242. secondary value, called a "scope". See ‘define-transient-command’.
  1243. 6.6.1 Internal Prefix Slots
  1244. ---------------------------
  1245. These slots are mostly intended for internal use. They should not be
  1246. set in calls to ‘define-transient-command’.
  1247. • ‘prototype’ When a transient prefix command is invoked, then a
  1248. clone of that object is stored in the global variable
  1249. ‘transient--prefix’ and the prototype is stored in the clone’s
  1250. ‘prototype’ slot.
  1251. • ‘command’ The command, a symbol. Each transient prefix command
  1252. consists of a command, which is stored in a symbol’s function slot
  1253. and an object, which is stored in the ‘transient--prefix’ property
  1254. of the same symbol.
  1255. • ‘level’ The level of the prefix commands. The suffix commands
  1256. whose layer is equal or lower are displayed. See *note Enabling
  1257. and Disabling Suffixes::.
  1258. • ‘value’ The likely outdated value of the prefix. Instead of
  1259. accessing this slot directly you should use the function
  1260. ‘transient-get-value’, which is guaranteed to return the up-to-date
  1261. value.
  1262. • ‘history’ and ‘history-pos’ are used to keep track of historic
  1263. values. Unless you implement your own ‘transient-infix-read’
  1264. method you should not have to deal with these slots.
  1265. 
  1266. File: transient.info, Node: Suffix Slots, Next: Predicate Slots, Prev: Prefix Slots, Up: Classes and Methods
  1267. 6.7 Suffix Slots
  1268. ================
  1269. Here we document most of the slots that are only available for suffix
  1270. objects. Some slots are shared by suffix and group objects, they are
  1271. documented in *note Predicate Slots::.
  1272. Also see *note Suffix Classes::.
  1273. 6.7.1 Slots of ‘transient-suffix’
  1274. ---------------------------------
  1275. • ‘key’ The key, a key vector or a key description string.
  1276. • ‘command’ The command, a symbol.
  1277. • ‘transient’ Whether to stay transient. See *note Transient
  1278. State::.
  1279. • ‘format’ The format used to display the suffix in the popup buffer.
  1280. It must contain the following %-placeholders:
  1281. • ‘%k’ For the key.
  1282. • ‘%d’ For the description.
  1283. • ‘%v’ For the infix value. Non-infix suffixes don’t have a
  1284. value.
  1285. • ‘description’ The description, either a string or a function that
  1286. is called with no argument and returns a string.
  1287. 6.7.2 Slots of ‘transient-infix’
  1288. --------------------------------
  1289. Some of these slots are only meaningful for some of the subclasses.
  1290. They are defined here anyway to allow sharing certain methods.
  1291. • ‘argument’ The long argument, e.g. ‘--verbose’.
  1292. • ‘shortarg’ The short argument, e.g. ‘-v’.
  1293. • ‘multi-value’ For options, whether the option can have multiple
  1294. values. If non-nil, then default to use
  1295. ‘completing-read-multiple’.
  1296. • ‘allow-empty’ For options, whether the empty string is a valid
  1297. value.
  1298. • ‘history-key’ The key used to store the history. This defaults to
  1299. the command name. This is useful when multiple infixes should
  1300. share the same history because their values are of the same kind.
  1301. • ‘reader’ The function used to read the value of an infix. Not used
  1302. for switches. The function takes three arguments, PROMPT,
  1303. INITIAL-INPUT and HISTORY, and must return a string.
  1304. • ‘prompt’ The prompt used when reading the value, either a string or
  1305. a function that takes the object as the only argument and which
  1306. returns a prompt string.
  1307. • ‘choices’ A list of valid values. How exactly that is used depends
  1308. on the class of the object.
  1309. 6.7.3 Slots of ‘transient-variable’
  1310. -----------------------------------
  1311. • ‘variable’ The variable.
  1312. 6.7.4 Slots of ‘transient-switches’
  1313. -----------------------------------
  1314. • ‘argument-format’ The display format. Must contain ‘%s’, one of
  1315. the ‘choices’ is substituted for that. E.g. ‘--%s-order’.
  1316. • ‘argument-regexp’ The regexp used to match any one of the switches.
  1317. E.g. ‘\\(--\\(topo\\|author-date\\|date\\)-order\\)’.
  1318. 
  1319. File: transient.info, Node: Predicate Slots, Prev: Suffix Slots, Up: Classes and Methods
  1320. 6.8 Predicate Slots
  1321. ===================
  1322. Suffix and group objects share some predicate slots that control whether
  1323. a group or suffix should be available depending on some state. Only one
  1324. of these slots can be used at the same time. It is undefined what
  1325. happens if you use more than one.
  1326. • ‘if’ Enable if predicate returns non-nil.
  1327. • ‘if-not’ Enable if predicate returns nil.
  1328. • ‘if-non-nil’ Enable if variable’s value is non-nil.
  1329. • ‘if-nil’ Enable if variable’s value is nil.
  1330. • ‘if-mode’ Enable if major-mode matches value.
  1331. • ‘if-not-mode’ Enable if major-mode does not match value.
  1332. • ‘if-derived’ Enable if major-mode derives from value.
  1333. • ‘if-not-derived’ Enable if major-mode does not derive from value.
  1334. One more slot is shared between group and suffix classes, ‘level’.
  1335. Like the slots documented above, it is a predicate, but it is used for a
  1336. different purpose. The value has to be an integer between 1 and 7.
  1337. ‘level’ controls whether a suffix or a group should be available
  1338. depending on user preference. See *note Enabling and Disabling
  1339. Suffixes::.
  1340. 
  1341. File: transient.info, Node: Related Abstractions and Packages, Next: FAQ, Prev: Classes and Methods, Up: Top
  1342. 7 Related Abstractions and Packages
  1343. ***********************************
  1344. * Menu:
  1345. * Comparison With Prefix Keys and Prefix Arguments::
  1346. * Comparison With Other Packages::
  1347. 
  1348. File: transient.info, Node: Comparison With Prefix Keys and Prefix Arguments, Next: Comparison With Other Packages, Up: Related Abstractions and Packages
  1349. 7.1 Comparison With Prefix Keys and Prefix Arguments
  1350. ====================================================
  1351. While transient commands were inspired by regular prefix keys and prefix
  1352. arguments, they are also quite different and much more complex.
  1353. The following diagrams illustrate some of the differences.
  1354. • ‘(c)’ represents a return to the command loop.
  1355. • ‘(+)’ represents the user’s choice to press one key or another.
  1356. • ‘{WORD}’ are possible behaviors.
  1357. • ‘{NUMBER}’ is a footnote.
  1358. 7.1.1 Regular Prefix Commands
  1359. -----------------------------
  1360. See *note (elisp)Prefix Keys::.
  1361. ,--> command1 --> (c)
  1362. |
  1363. (c)-(+)-> prefix command or key --+--> command2 --> (c)
  1364. |
  1365. `--> command3 --> (c)
  1366. 7.1.2 Regular Prefix Arguments
  1367. ------------------------------
  1368. See *note (elisp)Prefix Command Arguments::.
  1369. ,----------------------------------,
  1370. | |
  1371. v |
  1372. (c)-(+)---> prefix argument command --(c)-(+)-> any command --> (c)
  1373. | ^ |
  1374. | | |
  1375. `-- sets or changes --, ,-- maybe used --' |
  1376. | | |
  1377. v | |
  1378. prefix argument state |
  1379. ^ |
  1380. | |
  1381. `-------- discards --------'
  1382. 7.1.3 Transients
  1383. ----------------
  1384. (∩`-´)⊃━☆゚.*・。゚
  1385. This diagram ignores the infix value and external state:
  1386. (c)
  1387. | ,- {stay} ------<-,-<------------<-,-<---,
  1388. (+) | | | |
  1389. | | | | |
  1390. | | ,--> infix1 --| | |
  1391. | | | | | |
  1392. | | |--> infix2 --| | |
  1393. v v | | | |
  1394. prefix -(c)-(+)-> infix3 --' ^ |
  1395. | | |
  1396. |---------------> suffix1 -->--| |
  1397. | | |
  1398. |---------------> suffix2 ----{1}------> {exit} --> (c)
  1399. | |
  1400. |---------------> suffix3 -------------> {exit} --> (c)
  1401. | |
  1402. `--> any command --{2}-> {warn} -->--|
  1403. | |
  1404. |--> {noop} -->--|
  1405. | |
  1406. |--> {call} -->--'
  1407. |
  1408. `------------------> {exit} --> (c)
  1409. This diagram takes the infix value into account to an extend, while
  1410. still ignoring external state:
  1411. (c)
  1412. | ,- {stay} ------<-,-<------------<-,-<---,
  1413. (+) | | | |
  1414. | | | | |
  1415. | | ,--> infix1 --| | |
  1416. | | | | | | |
  1417. | | ,--> infix2 --| | |
  1418. v v | | | | |
  1419. prefix -(c)-(+)-> infix3 --' | |
  1420. | | ^ |
  1421. | | | |
  1422. |---------------> suffix1 -->--| |
  1423. | | ^ | |
  1424. | | | | |
  1425. |---------------> suffix2 ----{1}------> {exit} --> (c)
  1426. | | ^ | |
  1427. | | | | v
  1428. | | | | |
  1429. |---------------> suffix3 -------------> {exit} --> (c)
  1430. | | ^ | |
  1431. | sets | | v
  1432. | | maybe | |
  1433. | | used | |
  1434. | | | | |
  1435. | | infix --' | |
  1436. | `---> value | |
  1437. | ^ | |
  1438. | | | |
  1439. | hides | |
  1440. | | | |
  1441. | `--------------------------<---|
  1442. | | |
  1443. `--> any command --{2}-> {warn} -->--| |
  1444. | | |
  1445. |--> {noop} -->--| |
  1446. | | |
  1447. |--> {call} -->--' ^
  1448. | |
  1449. `------------------> {exit} --> (c)
  1450. This diagram provides more information about the infix value and also
  1451. takes external state into account.
  1452. ,----sets--- "anything"
  1453. |
  1454. v
  1455. ,---------> external
  1456. | state
  1457. | | |
  1458. | initialized | ☉‿⚆
  1459. sets from |
  1460. | | maybe
  1461. | ,----------' used
  1462. | | |
  1463. (c) | | v
  1464. | ,- {stay} --|---<-,-<------|-----<-,-<---,
  1465. (+) | | | | | | |
  1466. | | | v | | | |
  1467. | | ,--> infix1 --| | | |
  1468. | | | | | | | | |
  1469. | | | | v | | | |
  1470. | | ,--> infix2 --| | | |
  1471. | | | | ^ | | | |
  1472. v v | | | | | | |
  1473. prefix -(c)-(+)-> infix3 --' | | |
  1474. | | ^ | ^ |
  1475. | | | v | |
  1476. |---------------> suffix1 -->--| |
  1477. | | | ^ | | |
  1478. | | | | v | |
  1479. |---------------> suffix2 ----{1}------> {exit} --> (c)
  1480. | | | ^ | | |
  1481. | | | | | | v
  1482. | | | | v | |
  1483. |---------------> suffix3 -------------> {exit} --> (c)
  1484. | | | ^ | |
  1485. | sets | | | v
  1486. | | initialized maybe | |
  1487. | | from used | |
  1488. | | | | | |
  1489. | | `-- infix ---' | |
  1490. | `---> value -----------------------------> persistent
  1491. | ^ ^ | | across
  1492. | | | | | invocations -,
  1493. | hides | | | |
  1494. | | `----------------------------------------------'
  1495. | | | |
  1496. | `--------------------------<---|
  1497. | | |
  1498. `--> any command --{2}-> {warn} -->--| |
  1499. | | |
  1500. |--> {noop} -->--| |
  1501. | | |
  1502. |--> {call} -->--' ^
  1503. | |
  1504. `------------------> {exit} --> (c)
  1505. • ‘{1}’ Transients can be configured to be exited when a suffix
  1506. command is invoked. The default is to do so for all suffixes
  1507. except for those that are common to all transients and which are
  1508. used to perform tasks such as providing help and saving the value
  1509. of the infix arguments for future invocations. The behavior can
  1510. also be specified for individual suffix commands and may even
  1511. depend on state.
  1512. • ‘{2}’ Transients can be configured to allow the user to invoke
  1513. non-suffix commands. The default is to not allow that and instead
  1514. warn the user.
  1515. Despite already being rather complex, even the last diagram leaves
  1516. out many details. Most importantly it implies that the decision whether
  1517. to remain transient is made later than it actually is made (for the most
  1518. part a function on ‘pre-command-hook’ is responsible). But such
  1519. implementation details are of little relevance to users and are covered
  1520. elsewhere.
  1521. 
  1522. File: transient.info, Node: Comparison With Other Packages, Prev: Comparison With Prefix Keys and Prefix Arguments, Up: Related Abstractions and Packages
  1523. 7.2 Comparison With Other Packages
  1524. ==================================
  1525. 7.2.1 Magit-Popup
  1526. -----------------
  1527. Transient is the successor to Magit-Popup (see *note
  1528. (magit-popup)Top::).
  1529. One major difference between these two implementations of the same
  1530. ideas is that while Transient uses transient keymaps and embraces the
  1531. command-loop, Magit-Popup implemented an inferior mechanism that does
  1532. not use transient keymaps and that instead of using the command-loop
  1533. implements a naive alternative based on ‘read-char’.
  1534. Magit-Popup does not use classes and generic functions and defining a
  1535. new command type is near impossible as it involves adding hard-coded
  1536. special-cases to many functions. Because of that only a single new type
  1537. was added, which was not already part of Magit-Popup’s initial release.
  1538. A lot of things are hard-coded in Magit-Popup. One random example is
  1539. that the key bindings for switches must begin with "-" and those for
  1540. options must begin with "=".
  1541. 7.2.2 Hydra
  1542. -----------
  1543. Hydra (see <https://github.com/abo-abo/hydra>) is another package that
  1544. provides features similar to those of Transient.
  1545. Both packages use transient keymaps to make a set of commands
  1546. temporarily available and show the available commands in a popup buffer.
  1547. A Hydra "body" is equivalent to a Transient "prefix" and a Hydra
  1548. "head" is equivalent to a Transient "suffix". Hydra has no equivalent
  1549. of a Transient "infix".
  1550. Both hydras and transients can be used as simple command dispatchers.
  1551. Used like this they are similar to regular prefix commands and prefix
  1552. keys, except that the available commands are shown in the popup buffer.
  1553. (Another package that does this is ‘which-key’. It does so
  1554. automatically for any incomplete key sequence. The advantage of that
  1555. approach is that no additional work is necessary; the disadvantage is
  1556. that the available commands are not organized semantically.)
  1557. Both Hydra and Transient provide features that go beyond simple
  1558. command dispatchers:
  1559. • Invoking a command from a hydra does not necessarily exit the
  1560. hydra. That makes it possible to invoke the same command again,
  1561. but using a shorter key sequence (i.e. the key that was used to
  1562. enter the hydra does not have to be pressed again).
  1563. Transient supports that too, but for now this feature is not a
  1564. focus and the interface is a bit more complicated. A very basic
  1565. example using the current interface:
  1566. (define-transient-command outline-navigate ()
  1567. :transient-suffix 'transient--do-stay
  1568. :transient-non-suffix 'transient--do-warn
  1569. [("p" "previous visible heading" outline-previous-visible-heading)
  1570. ("n" "next visible heading" outline-next-visible-heading)])
  1571. • Transient supports infix arguments; values that are set by infix
  1572. commands and then consumed by the invoked suffix command(s).
  1573. To my knowledge, Hydra does not support that.
  1574. Both packages make it possible to specify how exactly the available
  1575. commands are outlined:
  1576. • With Hydra this is often done using an explicit format string,
  1577. which gives authors a lot of flexibility and makes it possible to
  1578. do fancy things.
  1579. The downside of this is that it becomes harder for a user to add
  1580. additional commands to an existing hydra and to change key
  1581. bindings.
  1582. • Transient allows the author of a transient to organize the commands
  1583. into groups and the use of generic functions allows authors of
  1584. transients to control exactly how a certain command type is
  1585. displayed.
  1586. However while Transient supports giving sections a heading it does
  1587. not currently support giving the displayed information more
  1588. structure by, for example, using box-drawing characters.
  1589. That could be implemented by defining a new group class, which lets
  1590. the author specify a format string. It should be possible to
  1591. implement that without modifying any existing code, but it does not
  1592. currently exist.
  1593. 
  1594. File: transient.info, Node: FAQ, Next: Keystroke Index, Prev: Related Abstractions and Packages, Up: Top
  1595. Appendix A FAQ
  1596. **************
  1597. A.1 Can I control how the popup buffer is displayed?
  1598. ====================================================
  1599. Yes, see ‘transient-display-buffer-action’ in *note Other Options::.
  1600. A.2 Why did some of the key bindings change?
  1601. ============================================
  1602. You may have noticed that the bindings for some of the common commands
  1603. do *not* have the prefix ‘C-x’ and that furthermore some of these
  1604. commands are grayed out while others are not. That unfortunately is a
  1605. bit confusing if the section of common commands is not shown
  1606. permanently, making the following explanation necessary.
  1607. The purpose of usually hiding that section but showing it after the
  1608. user pressed the respective prefix key is to conserve space and not
  1609. overwhelm users with too much noise, while allowing the user to quickly
  1610. list common bindings on demand.
  1611. That however should not keep us from using the best possible key
  1612. bindings. The bindings that do use a prefix do so to avoid wasting too
  1613. many non-prefix bindings, keeping them available for use in individual
  1614. transients. The bindings that do not use a prefix and that are *not*
  1615. grayed out are very important bindings that are *always* available, even
  1616. when invoking the "common command key prefix" or *any other*
  1617. transient-specific prefix. The non-prefix keys that *are* grayed out
  1618. however, are not available when any incomplete prefix key sequence is
  1619. active. They do not use the "common command key prefix" because it is
  1620. likely that users want to invoke them several times in a row and e.g.
  1621. ‘M-p M-p M-p’ is much more convenient than ‘C-x M-p C-x M-p C-x M-p’.
  1622. You may also have noticed that the "Set" command is bound to ‘C-x s’,
  1623. while Magit-Popup used to bind ‘C-c C-c’ instead. I have seen several
  1624. users praise the latter binding (sic), so I did not change it
  1625. willy-nilly. The reason that I changed it is that using different
  1626. prefix keys for different common commands, would have made the temporary
  1627. display of the common commands even more confusing, i.e. after pressing
  1628. ‘C-c’ all the ‘C-x ...’ bindings would be grayed out.
  1629. Using a single prefix for common commands key means that all other
  1630. potential prefix keys can be used for transient-specific commands
  1631. *without* the section of common commands also popping up. ‘C-c’ in
  1632. particular is a prefix that I want to (and already do) use for Magit,
  1633. and also using that for a common command would prevent me from doing so.
  1634. (Also see the next question.)
  1635. A.3 Why does ‘q’ not quit popups anymore?
  1636. =========================================
  1637. I agree that ‘q’ is a good binding for commands that quit something.
  1638. This includes quitting whatever transient is currently active, but it
  1639. also includes quitting whatever it is that some specific transient is
  1640. controlling. The transient ‘magit-blame’ for example binds ‘q’ to the
  1641. command that turns ‘magit-blame-mode’ off.
  1642. So I had to decide if ‘q’ should quit the active transient (like
  1643. Magit-Popup used to) or whether ‘C-g’ should do that instead, so that
  1644. ‘q’ could be bound in individual transient to whatever commands make
  1645. sense for them. Because all other letters are already reserved for use
  1646. by individual transients, I have decided to no longer make an exception
  1647. for ‘q’.
  1648. If you want to get ‘q’’s old binding back then you can do so. Doing
  1649. that is a bit more complicated than changing a single key binding, so I
  1650. have implemented a function, ‘transient-bind-q-to-quit’ that makes the
  1651. necessary changes. See its doc string for more information.
  1652. 
  1653. File: transient.info, Node: Keystroke Index, Next: Command Index, Prev: FAQ, Up: Top
  1654. Appendix B Keystroke Index
  1655. **************************
  1656. [index]
  1657. * Menu:
  1658. * C-g: Aborting and Resuming Transients.
  1659. (line 25)
  1660. * C-g <1>: Aborting and Resuming Transients.
  1661. (line 26)
  1662. * C-h: Getting Help for Suffix Commands.
  1663. (line 10)
  1664. * C-q: Aborting and Resuming Transients.
  1665. (line 36)
  1666. * C-x C-s: Saving Values. (line 25)
  1667. * C-x l: Enabling and Disabling Suffixes.
  1668. (line 49)
  1669. * C-x s: Saving Values. (line 20)
  1670. * C-x t: Common Suffix Commands.
  1671. (line 16)
  1672. * C-z: Aborting and Resuming Transients.
  1673. (line 42)
  1674. * M-n: Using History. (line 16)
  1675. * M-p: Using History. (line 11)
  1676. * M-x transient-resume: Aborting and Resuming Transients.
  1677. (line 55)
  1678. 
  1679. File: transient.info, Node: Command Index, Next: Function Index, Prev: Keystroke Index, Up: Top
  1680. Appendix C Command Index
  1681. ************************
  1682. [index]
  1683. * Menu:
  1684. * transient-help: Getting Help for Suffix Commands.
  1685. (line 10)
  1686. * transient-history-next: Using History. (line 16)
  1687. * transient-history-prev: Using History. (line 11)
  1688. * transient-quit-all: Aborting and Resuming Transients.
  1689. (line 36)
  1690. * transient-quit-one: Aborting and Resuming Transients.
  1691. (line 26)
  1692. * transient-quit-seq: Aborting and Resuming Transients.
  1693. (line 25)
  1694. * transient-resume: Aborting and Resuming Transients.
  1695. (line 55)
  1696. * transient-save: Saving Values. (line 25)
  1697. * transient-scroll-down arg: Other Commands. (line 18)
  1698. * transient-scroll-up arg: Other Commands. (line 12)
  1699. * transient-set: Saving Values. (line 20)
  1700. * transient-set-level: Enabling and Disabling Suffixes.
  1701. (line 49)
  1702. * transient-suspend: Aborting and Resuming Transients.
  1703. (line 42)
  1704. * transient-toggle-common: Common Suffix Commands.
  1705. (line 16)
  1706. 
  1707. File: transient.info, Node: Function Index, Next: Variable Index, Prev: Command Index, Up: Top
  1708. Appendix D Function Index
  1709. *************************
  1710. [index]
  1711. * Menu:
  1712. * define-infix-argument: Defining Suffix and Infix Commands.
  1713. (line 63)
  1714. * define-infix-command: Defining Suffix and Infix Commands.
  1715. (line 27)
  1716. * define-suffix-command: Defining Suffix and Infix Commands.
  1717. (line 9)
  1718. * define-transient-command: Defining Transients. (line 13)
  1719. * transient--do-call: Transient State. (line 98)
  1720. * transient--do-exit: Transient State. (line 94)
  1721. * transient--do-noop: Transient State. (line 125)
  1722. * transient--do-quit-all: Transient State. (line 138)
  1723. * transient--do-quit-one: Transient State. (line 132)
  1724. * transient--do-replace: Transient State. (line 102)
  1725. * transient--do-stay: Transient State. (line 85)
  1726. * transient--do-suspend: Transient State. (line 144)
  1727. * transient--do-warn: Transient State. (line 121)
  1728. * transient--history-init: Prefix Classes. (line 10)
  1729. * transient--insert-group: Group Methods. (line 6)
  1730. * transient-append-suffix: Modifying Existing Transients.
  1731. (line 47)
  1732. * transient-args: Using Infix Arguments.
  1733. (line 22)
  1734. * transient-format: Suffix Format Methods.
  1735. (line 6)
  1736. * transient-format-description: Suffix Format Methods.
  1737. (line 20)
  1738. * transient-format-key: Suffix Format Methods.
  1739. (line 15)
  1740. * transient-format-value: Suffix Format Methods.
  1741. (line 25)
  1742. * transient-get-suffix: Modifying Existing Transients.
  1743. (line 60)
  1744. * transient-infix-read: Suffix Value Methods.
  1745. (line 17)
  1746. * transient-infix-set: Suffix Value Methods.
  1747. (line 39)
  1748. * transient-infix-value: Suffix Value Methods.
  1749. (line 43)
  1750. * transient-init-scope: Suffix Value Methods.
  1751. (line 57)
  1752. * transient-init-value: Suffix Value Methods.
  1753. (line 6)
  1754. * transient-insert-suffix: Modifying Existing Transients.
  1755. (line 42)
  1756. * transient-prompt: Suffix Value Methods.
  1757. (line 34)
  1758. * transient-remove-suffix: Modifying Existing Transients.
  1759. (line 56)
  1760. * transient-replace-suffix: Modifying Existing Transients.
  1761. (line 51)
  1762. * transient-scroll-down: Other Commands. (line 18)
  1763. * transient-scroll-up: Other Commands. (line 12)
  1764. * transient-show-help: Suffix Format Methods.
  1765. (line 30)
  1766. * transient-suffix-put: Modifying Existing Transients.
  1767. (line 65)
  1768. 
  1769. File: transient.info, Node: Variable Index, Prev: Function Index, Up: Top
  1770. Appendix E Variable Index
  1771. *************************
  1772. [index]
  1773. * Menu:
  1774. * current-transient-command: Using Infix Arguments.
  1775. (line 47)
  1776. * current-transient-prefix: Using Infix Arguments.
  1777. (line 41)
  1778. * current-transient-suffixes: Using Infix Arguments.
  1779. (line 32)
  1780. * transient-default-level: Enabling and Disabling Suffixes.
  1781. (line 38)
  1782. * transient-detect-key-conflicts: Other Options. (line 137)
  1783. * transient-display-buffer-action: Other Options. (line 46)
  1784. * transient-enable-popup-navigation: Other Options. (line 28)
  1785. * transient-force-fixed-pitch: Other Options. (line 151)
  1786. * transient-highlight-mismatched-keys: Other Options. (line 96)
  1787. * transient-history-file: Using History. (line 33)
  1788. * transient-history-limit: Using History. (line 38)
  1789. * transient-levels-file: Enabling and Disabling Suffixes.
  1790. (line 44)
  1791. * transient-mode-line-format: Other Options. (line 71)
  1792. * transient-read-with-initial-input: Other Options. (line 88)
  1793. * transient-show-common-commands: Common Suffix Commands.
  1794. (line 23)
  1795. * transient-show-popup: Other Options. (line 6)
  1796. * transient-substitute-key-function: Other Options. (line 115)
  1797. * transient-values-file: Saving Values. (line 30)
  1798. 
  1799. Tag Table:
  1800. Node: Top751
  1801. Node: Introduction3651
  1802. Node: Usage9438
  1803. Node: Invoking Transients9772
  1804. Node: Aborting and Resuming Transients10804
  1805. Node: Common Suffix Commands13463
  1806. Node: Saving Values15217
  1807. Ref: Saving Values-Footnote-116475
  1808. Node: Using History16745
  1809. Node: Getting Help for Suffix Commands18286
  1810. Node: Enabling and Disabling Suffixes19679
  1811. Node: Other Commands22969
  1812. Node: Other Options23925
  1813. Node: Modifying Existing Transients31049
  1814. Node: Defining New Commands34453
  1815. Node: Defining Transients34789
  1816. Node: Binding Suffix and Infix Commands37221
  1817. Node: Group Specifications38076
  1818. Node: Suffix Specifications41409
  1819. Node: Defining Suffix and Infix Commands44976
  1820. Node: Using Infix Arguments48161
  1821. Node: Transient State50381
  1822. Node: Classes and Methods56254
  1823. Node: Group Classes58468
  1824. Node: Group Methods60385
  1825. Node: Prefix Classes61030
  1826. Node: Suffix Classes62122
  1827. Node: Suffix Methods64366
  1828. Node: Suffix Value Methods64687
  1829. Node: Suffix Format Methods67447
  1830. Node: Prefix Slots68899
  1831. Node: Suffix Slots71376
  1832. Node: Predicate Slots74227
  1833. Node: Related Abstractions and Packages75475
  1834. Node: Comparison With Prefix Keys and Prefix Arguments75762
  1835. Node: Comparison With Other Packages86074
  1836. Node: FAQ90265
  1837. Node: Keystroke Index93999
  1838. Node: Command Index95633
  1839. Node: Function Index97420
  1840. Node: Variable Index101577
  1841. 
  1842. End Tag Table
  1843. 
  1844. Local Variables:
  1845. coding: utf-8
  1846. End: