branch: externals/transient commit 08b4778890e0b13c24a64a6737e6d6f8a14da9af Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
Make it trivial to use "q" to quit again Closes #18. --- docs/transient.org | 8 ++++++-- docs/transient.texi | 10 ++++++++-- lisp/transient.el | 31 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/docs/transient.org b/docs/transient.org index f18c9ad0da..1d468ca645 100644 --- a/docs/transient.org +++ b/docs/transient.org @@ -8,7 +8,7 @@ #+TEXINFO_DIR_CATEGORY: Emacs #+TEXINFO_DIR_TITLE: Transient: (transient). #+TEXINFO_DIR_DESC: Transient Commands -#+SUBTITLE: for version 0.1.0 (v0.1.0-30-g2033ac1+1) +#+SUBTITLE: for version 0.1.0 (v0.1.0-31-gf0213e0+1) #+TEXINFO_DEFFN: t #+OPTIONS: H:4 num:4 toc:2 @@ -37,7 +37,7 @@ Calling a suffix command usually causes the transient to be exited but suffix commands can also be configured to not exit the transient. #+TEXINFO: @noindent -This manual is for Transient version 0.1.0 (v0.1.0-30-g2033ac1+1). +This manual is for Transient version 0.1.0 (v0.1.0-31-gf0213e0+1). #+BEGIN_QUOTE Copyright (C) 2018-2019 Jonas Bernoulli <jo...@bernoul.li> @@ -219,6 +219,10 @@ the latter, then you can later resume the stack of transients using or else the current transient. When quitting the current transient, then it returns to the previous transient, if any. +Transient's predecessor bound ~q~ instead of ~C-g~ to the quit command. +To learn how to get that binding back see ~transient-bind-q-to-quit~'s +doc-string. + - Key: C-q, transient-quit-all This command quits the currently active incomplete key sequence, if diff --git a/docs/transient.texi b/docs/transient.texi index 92d52414ea..7e68fcf043 100644 --- a/docs/transient.texi +++ b/docs/transient.texi @@ -31,7 +31,7 @@ General Public License for more details. @finalout @titlepage @title Transient User and Developer Manual -@subtitle for version 0.1.0 (v0.1.0-30-g2033ac1+1) +@subtitle for version 0.1.0 (v0.1.0-31-gf0213e0+1) @author Jonas Bernoulli @page @vskip 0pt plus 1filll @@ -65,7 +65,7 @@ Calling a suffix command usually causes the transient to be exited but suffix commands can also be configured to not exit the transient. @noindent -This manual is for Transient version 0.1.0 (v0.1.0-30-g2033ac1+1). +This manual is for Transient version 0.1.0 (v0.1.0-31-gf0213e0+1). @quotation Copyright (C) 2018-2019 Jonas Bernoulli <jonas@@bernoul.li> @@ -337,7 +337,13 @@ the latter, then you can later resume the stack of transients using This key quits the currently active incomplete key sequence, if any, or else the current transient. When quitting the current transient, then it returns to the previous transient, if any. +@end table + +Transient's predecessor bound @code{q} instead of @code{C-g} to the quit command. +To learn how to get that binding back see @code{transient-bind-q-to-quit}'s +doc-string. +@table @asis @kindex C-q @cindex transient-quit-all @item @kbd{C-q} @tie{}@tie{}@tie{}@tie{}(@code{transient-quit-all}) diff --git a/lisp/transient.el b/lisp/transient.el index 74958d2986..2304f56ac2 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -2709,6 +2709,37 @@ resumes the suspended transient.") (which-key-mode 1) (remove-hook 'post-transient-hook 'transient--resume-which-key-mode))) +(defun transient-bind-q-to-quit () + "Modify some keymaps to bind \"q\" to the appropriate quit command. + +\"C-g\" is the default binding for such commands now, but Transient's +predecessor Magit-Popup used \"q\" instead. If you would like to get +that binding back, then call this function in your init file like so: + + (with-eval-after-load \\='transient + (transient-bind-q-to-quit)) + +Individual transients may already bind \"q\" to something else +and such a binding would shadow the quit binding. If that is the +case then \"Q\" is bound to whatever \"q\" would have been bound +to by setting `transient-substitute-key-function' to a function +that does that. Of course \"Q\" may already be bound to something +else, so that function binds \"M-q\" to that command instead. +Of course \"M-q\" may already be bound to something else, but +we stop there." + (define-key transient-map "q" 'transient-quit-one) + (define-key transient-edit-map "q" 'transient-quit-one) + (define-key transient-sticky-map "q" 'transient-quit-seq) + (setq transient-substitute-key-function + 'transient-rebind-quit-commands)) + +(defun transient-rebind-quit-commands (obj) + "See `transient-bind-q-to-quit'." + (let ((key (oref obj key))) + (cond ((string-equal key "q") "Q") + ((string-equal key "Q") "M-q") + (t key)))) + ;;; Font-Lock (defconst transient-font-lock-keywords