Skip to content

Commit 6b14639

Browse files
committed
transient-scope: Add CLASSES argument
Closes ^334.
1 parent f9a9054 commit 6b14639

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

CHANGELOG

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ Bug fixes:
1919

2020
- Added documentation for ~inapt-if*~ slots to manual. 179545a6
2121

22-
- ~transient-args~ and ~transient-scope~ now both take a prefix command or
23-
a list of prefix commands as argument. ~transient-scope~ can still be
24-
called without an argument, but that should only be done in functions
25-
that take part in setting up a menu, not in a suffix command.
22+
- ~transient-args~ now takes a prefix command or a list of prefix
23+
commands as argument.
24+
25+
- ~transient-scope~ now takes a prefix command or a list of prefix
26+
commands and/or a prefix class or list of prefix classes as
27+
arguments. It can still be called without any argument, but that
28+
should only be done in functions that take part in setting up a
29+
menu, not in a suffix command.
2630

2731
- Added new generic function ~transient-prefix-value~, giving finer
2832
control over how the value returned by ~transient-args~ is determined.

lisp/transient.el

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,47 +3869,45 @@ a default implementation, which is a noop.")
38693869

38703870
;;;; Get
38713871

3872-
(defun transient-scope (&optional prefixes)
3872+
(defun transient-scope (&optional prefixes classes)
38733873
"Return the scope of the active or current transient prefix command.
38743874
3875-
If optional PREFIXES is nil, return the scope of the prefix currently
3876-
being setup, making this variant useful, e.g., in `:if*' predicates.
3877-
If no prefix is being setup, but the current command was invoked from
3878-
some prefix, return the scope of that.
3875+
If optional PREFIXES and CLASSES are both nil, return the scope of
3876+
the prefix currently being setup, making this variation useful, e.g.,
3877+
in `:if*' predicates. If no prefix is being setup, but the current
3878+
command was invoked from some prefix, then return the scope of that.
38793879
3880-
When this function is called from the body or `interactive' form of a
3881-
suffix command, PREFIXES should be non-nil.
3882-
3883-
If PREFIXES is non-nil, it must be a prefix command or class, or a list
3884-
of such commands and/or classes. In this case try the following in
3885-
order:
3880+
If PREFIXES is non-nil, it must be a prefix command or a list of such
3881+
commands. If CLASSES is non-nil, it must be a prefix class or a list
3882+
of such classes. When this function is called from the body or the
3883+
`interactive' form of a suffix command, PREFIXES and/or CLASSES should
3884+
be non-nil. If either is non-nil, try the following in order:
38863885
38873886
- If the current suffix command was invoked from a prefix, which
38883887
appears in PREFIXES, return the scope of that prefix.
38893888
38903889
- If the current suffix command was invoked from a prefix, and its
3891-
class derives from one of the classes in PREFIXES, return the scope
3892-
of that prefix.
3890+
class derives from one of the CLASSES, return the scope of that
3891+
prefix.
38933892
38943893
- If a prefix is being setup and it appears in PREFIXES, return its
38953894
scope.
38963895
38973896
- If a prefix is being setup and its class derives from one of the
3898-
classes in PREFIXES, return its scope.
3897+
CLASSES, return its scope.
38993898
3900-
- Finally try to return the default scope of the first element of
3901-
PREFIXES, which must be a command (not a class). This only works
3902-
if that slot is set in the respective class definition or using
3903-
its `transient-init-scope' method.
3899+
- Finally try to return the default scope of the first command in
3900+
PREFIXES. This only works if that slot is set in the respective
3901+
class definition or using its `transient-init-scope' method.
39043902
39053903
If no prefix matches, return nil."
3906-
(if prefixes
3904+
(if (or prefixes classes)
39073905
(let* ((prefixes (ensure-list prefixes))
3908-
(classes (seq-filter #'class-p prefixes)))
3906+
(type (if (symbolp classes) classes (cons 'or classes))))
39093907
(if-let* ((obj (cl-flet ((match (obj)
39103908
(and obj
39113909
(or (memq (oref obj command) prefixes)
3912-
(cl-typep obj (cons 'or classes)))
3910+
(cl-typep obj type))
39133911
obj)))
39143912
(or (match transient-current-prefix)
39153913
(match transient--prefix)))))

0 commit comments

Comments
 (0)