Skip to content

Commit

Permalink
transient-toggle-level-limit: New command
Browse files Browse the repository at this point in the history
Closes #243.
  • Loading branch information
tarsius committed Oct 30, 2023
1 parent 59d602a commit 9257245
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/transient.org
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,12 @@ available even if the user lowers the transient level.
Therefore, to control which suffixes are available given a certain
state, you have to make sure that that state is currently active.

- Key: C-x a (transient-toggle-level-limit) ::

This command toggle whether suffixes that are on levels lower than
the level specified by ~transient-default-level~ are temporarily
available anyway.

** Other Commands

When invoking a transient in a small frame, the transient window may
Expand Down
7 changes: 7 additions & 0 deletions docs/transient.texi
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ not. The predicates also apply in edit mode.

Therefore, to control which suffixes are available given a certain
state, you have to make sure that that state is currently active.

@item @kbd{C-x a} (@code{transient-toggle-level-limit})
@kindex C-x a
@findex transient-toggle-level-limit
This command toggle whether suffixes that are on levels lower than
the level specified by @code{transient-default-level} are temporarily
available anyway.
@end table

@node Other Commands
Expand Down
39 changes: 33 additions & 6 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ text and might otherwise have to scroll in two dimensions."
:group 'transient
:type 'boolean)

(defconst transient--max-level 7)
(defconst transient--default-child-level 1)

(defconst transient--default-prefix-level 4)

(defcustom transient-default-level transient--default-prefix-level
Expand Down Expand Up @@ -1412,6 +1412,9 @@ variable instead.")
(defvar transient--refreshp nil
"Whether to refresh the transient completely.")

(defvar transient--all-levels-p nil
"Whether temporary display of suffixes on all levels is active.")

(defvar transient--active-infix nil "The active infix awaiting user input.")

(defvar transient--timer nil)
Expand Down Expand Up @@ -1616,7 +1619,8 @@ to `transient-predicate-map'. Also see `transient-base-map'."
(if transient-show-common-commands
"Hide common commands"
"Show common permanently")))
(list "C-x l" "Show/hide suffixes" #'transient-set-level))))))))
(list "C-x l" "Show/hide suffixes" #'transient-set-level)
(list "C-x a" #'transient-toggle-level-limit))))))))

(defvar-keymap transient-popup-navigation-map
:doc "One of the keymaps used when popup navigation is enabled.
Expand Down Expand Up @@ -1979,7 +1983,8 @@ value. Otherwise return CHILDREN as is."
(error "No key for %s" (oref obj command))))))

(defun transient--use-level-p (level &optional edit)
(or (and transient--editp (not edit))
(or transient--all-levels-p
(and transient--editp (not edit))
(and (>= level 1)
(<= level (oref transient--prefix level)))))

Expand Down Expand Up @@ -2374,6 +2379,7 @@ value. Otherwise return CHILDREN as is."
(setq transient--exitp nil)
(setq transient--helpp nil)
(setq transient--editp nil)
(setq transient--all-levels-p nil)
(setq transient--minibuffer-depth 0)
(run-hooks 'transient-exit-hook)
(when resume
Expand Down Expand Up @@ -2735,6 +2741,25 @@ transient is active."
(t
(transient-undefined))))

(transient-define-suffix transient-toggle-level-limit ()
"Toggle whether to temporarily displayed suffixes on all levels."
:description
(lambda ()
(cond
((= transient-default-level transient--max-level)
"Always displaying all levels")
(transient--all-levels-p
(format "Hide suffix %s"
(propertize
(format "levels > %s" (oref transient--prefix level))
'face 'transient-higher-level)))
("Show all suffix levels")))
:inapt-if (lambda () (= transient-default-level transient--max-level))
:transient t
(interactive)
(setq transient--all-levels-p (not transient--all-levels-p))
(setq transient--refreshp t))

(defun transient-set ()
"Set active transient's value for this Emacs session."
(interactive)
Expand Down Expand Up @@ -3696,9 +3721,11 @@ If the OBJ's `key' is currently unreachable, then apply the face
(cond ((and (slot-boundp obj 'key)
(transient--key-unreachable-p obj))
(propertize desc 'face 'transient-unreachable))
((and transient-highlight-higher-levels
(> (max (oref obj level) transient--max-group-level)
transient--default-prefix-level))
((if transient--all-levels-p
(> (oref obj level) transient--default-prefix-level)
(and transient-highlight-higher-levels
(> (max (oref obj level) transient--max-group-level)
transient--default-prefix-level)))
(add-face-text-property
0 (length desc) 'transient-higher-level nil desc)
desc)
Expand Down

0 comments on commit 9257245

Please sign in to comment.