branch: externals/transient commit 55b01dc46026e5632a701b2ef1d04c21be8eb40c Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
transient--insert-suffix: Do not signal error by default In [1: 8daf9890] 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 8daf9890ee65335a23eebc8919e9cfdd7c7249eb transient--insert-suffix: Signal error if location is invalid --- docs/transient.org | 10 ++++++++++ docs/transient.texi | 10 ++++++++++ lisp/transient.el | 22 +++++++++++++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/docs/transient.org b/docs/transient.org index a53fae49f6..a18571acc4 100644 --- a/docs/transient.org +++ b/docs/transient.org @@ -899,6 +899,16 @@ that tree are not objects but have the form {{{codevar((LEVEL CLASS PLIST))}}}, This function edits the suffix or group at {{{var(LOC)}}} in {{{var(PREFIX)}}}, by setting the {{{var(PROP)}}} of its plist to {{{var(VALUE)}}}. +Most of these functions do not signal an error if they cannot perform +the requested modification. The functions that insert new suffixes +show a warning if {{{var(LOC)}}} cannot be found in {{{var(PREFIX,)}}} without signaling an +error. The reason for doing it like this is that establishing a key +binding (and that is what we essentially are trying to do here) should +not prevent the rest of the configuration from loading. Among these +functions only ~transient-get-suffix~ and ~transient-suffix-put~ signal +an error by default. If you really want the insert functions to also +signal an error, set ~transient-error-on-insert-failure~ to ~t~. + * Defining New Commands ** Technical Introduction diff --git a/docs/transient.texi b/docs/transient.texi index 42f4c6766c..c88f454a2e 100644 --- a/docs/transient.texi +++ b/docs/transient.texi @@ -1055,6 +1055,16 @@ This function edits the suffix or group at @var{LOC} in @var{PREFIX}, by setting the @var{PROP} of its plist to @var{VALUE}. @end defun +Most of these functions do not signal an error if they cannot perform +the requested modification. The functions that insert new suffixes +show a warning if @var{LOC} cannot be found in @var{PREFIX} without signaling an +error. The reason for doing it like this is that establishing a key +binding (and that is what we essentially are trying to do here) should +not prevent the rest of the configuration from loading. Among these +functions only @code{transient-get-suffix} and @code{transient-suffix-put} signal +an error by default. If you really want the insert functions to also +signal an error, set @code{transient-error-on-insert-failure} to @code{t}. + @node Defining New Commands @chapter Defining New Commands diff --git a/lisp/transient.el b/lisp/transient.el index fec9c7349e..7473c50b8b 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -432,6 +432,16 @@ used." :group 'transient :type 'boolean) +(defcustom transient-error-on-insert-failure nil + "Whether to signal an error when failing to insert a suffix. + +When `transient-insert-suffix' and `transient-append-suffix' fail +to insert a suffix into an existing prefix, they usually just show +a warning. If this is non-nil, they signal an error instead." + :package-version '(transient . "0.8.8") + :group 'transient + :type 'boolean) + (defcustom transient-align-variable-pitch nil "Whether to align columns pixel-wise in the popup buffer. @@ -1455,14 +1465,16 @@ Intended for use in a group's `:setup-children' function." (setq suf (eval suf t)) (cond ((not mem) - (error "Cannot insert %S into %s; %s not found" - suffix prefix loc)) + (funcall (if transient-error-on-insert-failure #'error #'message) + "Cannot insert %S into %s; %s not found" + suffix prefix loc)) ((or (and (vectorp suffix) (not (vectorp elt))) (and (listp suffix) (vectorp elt)) (and (stringp suffix) (vectorp elt))) - (error "Cannot place %S into %s at %s; %s" - suffix prefix loc - "suffixes and groups cannot be siblings")) + (funcall (if transient-error-on-insert-failure #'error #'message) + "Cannot place %S into %s at %s; %s" + suffix prefix loc + "suffixes and groups cannot be siblings")) (t (when-let* (((not (eq keep-other 'always))) (bindingp (listp suf))