Skip to content

Commit

Permalink
transient-scope: Add CLASSES argument
Browse files Browse the repository at this point in the history
Closes ^334.
  • Loading branch information
tarsius committed Dec 9, 2024
1 parent ec6d711 commit 4926418
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ Bug fixes:

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

- ~transient-args~ and ~transient-scope~ now both take a prefix command or
a list of prefix commands as argument. ~transient-scope~ can still be
called without an argument, but that should only be done in functions
that take part in setting up a menu, not in a suffix command.
- ~transient-args~ now takes a prefix command or a list of prefix
commands as argument.

- ~transient-scope~ now takes a prefix command or a list of prefix
commands and/or a prefix class or list of prefix classes as
arguments. It can still be called without any argument, but that
should only be done in functions that take part in setting up a
menu, not in a suffix command.

- Added new generic function ~transient-prefix-value~, giving finer
control over how the value returned by ~transient-args~ is determined.
Expand Down
40 changes: 19 additions & 21 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -3785,47 +3785,45 @@ a default implementation, which is a noop.")

;;;; Get

(defun transient-scope (&optional prefixes)
(defun transient-scope (&optional prefixes classes)
"Return the scope of the active or current transient prefix command.
If optional PREFIXES is nil, return the scope of the prefix currently
being setup, making this variant useful, e.g., in `:if*' predicates.
If no prefix is being setup, but the current command was invoked from
some prefix, return the scope of that.
If optional PREFIXES and CLASSES are both nil, return the scope of
the prefix currently being setup, making this variation useful, e.g.,
in `:if*' predicates. If no prefix is being setup, but the current
command was invoked from some prefix, then return the scope of that.
When this function is called from the body or `interactive' form of a
suffix command, PREFIXES should be non-nil.
If PREFIXES is non-nil, it must be a prefix command or class, or a list
of such commands and/or classes. In this case try the following in
order:
If PREFIXES is non-nil, it must be a prefix command or a list of such
commands. If CLASSES is non-nil, it must be a prefix class or a list
of such classes. When this function is called from the body or the
`interactive' form of a suffix command, PREFIXES and/or CLASSES should
be non-nil. If either is non-nil, try the following in order:
- If the current suffix command was invoked from a prefix, which
appears in PREFIXES, return the scope of that prefix.
- If the current suffix command was invoked from a prefix, and its
class derives from one of the classes in PREFIXES, return the scope
of that prefix.
class derives from one of the CLASSES, return the scope of that
prefix.
- If a prefix is being setup and it appears in PREFIXES, return its
scope.
- If a prefix is being setup and its class derives from one of the
classes in PREFIXES, return its scope.
CLASSES, return its scope.
- Finally try to return the default scope of the first element of
PREFIXES, which must be a command (not a class). This only works
if that slot is set in the respective class definition or using
its `transient-init-scope' method.
- Finally try to return the default scope of the first command in
PREFIXES. This only works if that slot is set in the respective
class definition or using its `transient-init-scope' method.
If no prefix matches, return nil."
(if prefixes
(if (or prefixes classes)
(let* ((prefixes (ensure-list prefixes))
(classes (seq-filter #'class-p prefixes)))
(type (if (symbolp classes) classes (cons 'or classes))))
(if-let* ((obj (cl-flet ((match (obj)
(and obj
(or (memq (oref obj command) prefixes)
(cl-typep obj (cons 'or classes)))
(cl-typep obj type))
obj)))
(or (match transient-current-prefix)
(match transient--prefix)))))
Expand Down

0 comments on commit 4926418

Please sign in to comment.