Skip to content

Commit

Permalink
Support suffix description functions that take object as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Oct 26, 2023
1 parent beaa3ca commit 09be367
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
13 changes: 7 additions & 6 deletions docs/transient.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions docs/transient.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lisp/transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down

0 comments on commit 09be367

Please sign in to comment.