From 09be367bc07a6b113a024bc28c62b1ad04c47bc0 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Thu, 26 Oct 2023 12:17:13 +0200 Subject: [PATCH] Support suffix description functions that take object as argument --- docs/transient.org | 13 +++++++------ docs/transient.texi | 13 +++++++------ lisp/transient.el | 4 +++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/transient.org b/docs/transient.org index 2cb6989a..07cfa7c6 100644 --- a/docs/transient.org +++ b/docs/transient.org @@ -1043,10 +1043,10 @@ the object's values just for the binding inside this transient. - {{{var(KEY)}}} is the key binding, either a vector or key description string. - {{{var(DESCRIPTION)}}} is the description, either a string or a function that - returns a string. The function should be a lambda expression to - avoid ambiguity. In some cases a symbol that is bound as a function - would also work but to be safe you should use ~:description~ in that - case. + takes zero or one arguments (the suffix object) and returns a string. + The function should be a lambda expression to avoid ambiguity. In + some cases a symbol that is bound as a function would also work but + to be safe you should use ~:description~ in that case. The next element is either a command or an argument. This is the only argument that is mandatory in all cases. @@ -1833,8 +1833,9 @@ Also see [[*Suffix Classes]]. - ~%d~ For the description. - ~%v~ For the infix value. Non-infix suffixes don't have a value. -- ~description~ The description, either a string or a function that is - called with no argument and returns a string. +- ~description~ The description, either a string or a function, which is + called with zero or one argument (the suffix object), and returns a + string. - ~face~ Face used for the description. In simple cases it is easier to use this instead of using a function as ~description~ and adding diff --git a/docs/transient.texi b/docs/transient.texi index 14a9de6e..8c11a8b6 100644 --- a/docs/transient.texi +++ b/docs/transient.texi @@ -1222,10 +1222,10 @@ the object's values just for the binding inside this transient. @item @var{DESCRIPTION} is the description, either a string or a function that -returns a string. The function should be a lambda expression to -avoid ambiguity. In some cases a symbol that is bound as a function -would also work but to be safe you should use @code{:description} in that -case. +takes zero or one arguments (the suffix object) and returns a string. +The function should be a lambda expression to avoid ambiguity. In +some cases a symbol that is bound as a function would also work but +to be safe you should use @code{:description} in that case. @end itemize The next element is either a command or an argument. This is the only @@ -2096,8 +2096,9 @@ It must contain the following %-placeholders: @end itemize @item -@code{description} The description, either a string or a function that is -called with no argument and returns a string. +@code{description} The description, either a string or a function, which is +called with zero or one argument (the suffix object), and returns a +string. @item @code{face} Face used for the description. In simple cases it is easier diff --git a/lisp/transient.el b/lisp/transient.el index 706a8943..32558997 100644 --- a/lisp/transient.el +++ b/lisp/transient.el @@ -3636,7 +3636,9 @@ and its value is returned to the caller." (and-let* ((desc (oref obj description)) (desc (if (functionp desc) (with-current-buffer transient--original-buffer - (funcall desc)) + (if (= (car (func-arity desc)) 1) + (funcall desc obj) + (funcall desc))) desc))) (progn ; work around debbugs#31840 (when-let ((face (and (slot-exists-p obj 'face) (oref obj face))))