Skip to content

Commit

Permalink
transient-infix-set(argument): Also disable based on concrete value
Browse files Browse the repository at this point in the history
"--one" may be incompatible with "--two=foo" but not "--two=bar".
  • Loading branch information
tarsius committed Oct 31, 2023
1 parent ed5bd6f commit 2eb214a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
7 changes: 6 additions & 1 deletion docs/transient.org
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,12 @@ functions use ~describe-function~.
- ~incompatible~ A list of lists. Each sub-list specifies a set of
mutually exclusive arguments. Enabling one of these arguments
causes the others to be disabled. An argument may appear in
multiple sub-lists.
multiple sub-lists. Arguments must me given in the same form as
used in the ~argument~ or ~argument-format~ slot of the respective
suffix objects, usually something like ~--switch~ or ~--option=%s~. For
options and ~transient-switches~ suffixes it is also possible to match
against a specific value, as returned by ~transient-infix-value~,
for example, ~--option=one~.

- ~scope~ For some transients it might be necessary to have a sort of
secondary value, called a “scope”. See ~transient-define-prefix~.
Expand Down
9 changes: 7 additions & 2 deletions docs/transient.texi
Original file line number Diff line number Diff line change
Expand Up @@ -2033,11 +2033,16 @@ disabled by default and still considered experimental.
@code{incompatible} A list of lists. Each sub-list specifies a set of
mutually exclusive arguments. Enabling one of these arguments
causes the others to be disabled. An argument may appear in
multiple sub-lists.
multiple sub-lists. Arguments must me given in the same form as
used in the @code{argument} or @code{argument-format} slot of the respective
suffix objects, usually something like @code{--switch} or @code{--option=%s}. For
options and @code{transient-switches} suffixes it is also possible to match
against a specific value, as returned by @code{transient-infix-value},
for example, @code{--option=one}.

@item
@code{scope} For some transients it might be necessary to have a sort of
secondary value, called a ``scope''. See @code{transient-define-prefix}.
secondary value, called a scope. See @code{transient-define-prefix}.
@end itemize

@anchor{Internal Prefix Slots}
Expand Down
18 changes: 13 additions & 5 deletions lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -3188,20 +3188,28 @@ prompt."
(cl-defmethod transient-infix-set :after ((obj transient-argument) value)
"Unset incompatible infix arguments."
(when-let* ((--- value)
(val (transient-infix-value obj))
(arg (if (slot-boundp obj 'argument)
(oref obj argument)
(oref obj argument-format)))
(spec (oref transient--prefix incompatible))
(incomp (cl-mapcan (lambda (rule)
(and (member arg rule)
(remove arg rule)))
spec)))
(filter (lambda (x rule)
(and (member x rule)
(remove x rule))))
(incomp (nconc
(cl-mapcan (apply-partially filter arg) spec)
(and (not (equal val arg))
(cl-mapcan (apply-partially filter val) spec)))))
(dolist (obj transient--suffixes)
(when-let* ((--- (cl-typep obj 'transient-argument))
(val (transient-infix-value obj))
(arg (if (slot-boundp obj 'argument)
(oref obj argument)
(oref obj argument-format)))
(--- (member arg incomp)))
(--- (if (equal val arg)
(member arg incomp)
(or (member val incomp)
(member arg incomp)))))
(transient-infix-set obj nil)))))

(cl-defgeneric transient-set-value (obj)
Expand Down

0 comments on commit 2eb214a

Please sign in to comment.