Skip to content

Commit 55b01dc

Browse files
committed
transient--insert-suffix: Do not signal error by default
In [1: 8daf989] we started to signal an error instead of merely showing a message on failure. That was a mistake, see #374. Add new option `transient-error-on-insert-failure', so users can opt-in to fatal errors for minor issues. 1: 2025-03-24 8daf989 transient--insert-suffix: Signal error if location is invalid
1 parent afc88b2 commit 55b01dc

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

docs/transient.org

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,16 @@ that tree are not objects but have the form {{{codevar((LEVEL CLASS PLIST))}}},
899899
This function edits the suffix or group at {{{var(LOC)}}} in {{{var(PREFIX)}}}, by setting
900900
the {{{var(PROP)}}} of its plist to {{{var(VALUE)}}}.
901901

902+
Most of these functions do not signal an error if they cannot perform
903+
the requested modification. The functions that insert new suffixes
904+
show a warning if {{{var(LOC)}}} cannot be found in {{{var(PREFIX,)}}} without signaling an
905+
error. The reason for doing it like this is that establishing a key
906+
binding (and that is what we essentially are trying to do here) should
907+
not prevent the rest of the configuration from loading. Among these
908+
functions only ~transient-get-suffix~ and ~transient-suffix-put~ signal
909+
an error by default. If you really want the insert functions to also
910+
signal an error, set ~transient-error-on-insert-failure~ to ~t~.
911+
902912
* Defining New Commands
903913
** Technical Introduction
904914

docs/transient.texi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,16 @@ This function edits the suffix or group at @var{LOC} in @var{PREFIX}, by setting
10551055
the @var{PROP} of its plist to @var{VALUE}.
10561056
@end defun
10571057

1058+
Most of these functions do not signal an error if they cannot perform
1059+
the requested modification. The functions that insert new suffixes
1060+
show a warning if @var{LOC} cannot be found in @var{PREFIX} without signaling an
1061+
error. The reason for doing it like this is that establishing a key
1062+
binding (and that is what we essentially are trying to do here) should
1063+
not prevent the rest of the configuration from loading. Among these
1064+
functions only @code{transient-get-suffix} and @code{transient-suffix-put} signal
1065+
an error by default. If you really want the insert functions to also
1066+
signal an error, set @code{transient-error-on-insert-failure} to @code{t}.
1067+
10581068
@node Defining New Commands
10591069
@chapter Defining New Commands
10601070

lisp/transient.el

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,16 @@ used."
432432
:group 'transient
433433
:type 'boolean)
434434

435+
(defcustom transient-error-on-insert-failure nil
436+
"Whether to signal an error when failing to insert a suffix.
437+
438+
When `transient-insert-suffix' and `transient-append-suffix' fail
439+
to insert a suffix into an existing prefix, they usually just show
440+
a warning. If this is non-nil, they signal an error instead."
441+
:package-version '(transient . "0.8.8")
442+
:group 'transient
443+
:type 'boolean)
444+
435445
(defcustom transient-align-variable-pitch nil
436446
"Whether to align columns pixel-wise in the popup buffer.
437447
@@ -1455,14 +1465,16 @@ Intended for use in a group's `:setup-children' function."
14551465
(setq suf (eval suf t))
14561466
(cond
14571467
((not mem)
1458-
(error "Cannot insert %S into %s; %s not found"
1459-
suffix prefix loc))
1468+
(funcall (if transient-error-on-insert-failure #'error #'message)
1469+
"Cannot insert %S into %s; %s not found"
1470+
suffix prefix loc))
14601471
((or (and (vectorp suffix) (not (vectorp elt)))
14611472
(and (listp suffix) (vectorp elt))
14621473
(and (stringp suffix) (vectorp elt)))
1463-
(error "Cannot place %S into %s at %s; %s"
1464-
suffix prefix loc
1465-
"suffixes and groups cannot be siblings"))
1474+
(funcall (if transient-error-on-insert-failure #'error #'message)
1475+
"Cannot place %S into %s at %s; %s"
1476+
suffix prefix loc
1477+
"suffixes and groups cannot be siblings"))
14661478
(t
14671479
(when-let* (((not (eq keep-other 'always)))
14681480
(bindingp (listp suf))

0 commit comments

Comments
 (0)