Skip to content

Commit

Permalink
manual: Add an example using :setup-children
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Jun 28, 2024
1 parent 0e0ece3 commit cfd17a7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
31 changes: 30 additions & 1 deletion docs/transient.org
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,10 @@ constructor of that class.
to use the same form as understood by ~transient-define-prefix~,
described below. If you use the latter approach, you can use the
~transient-parse-suffixes~ and ~transient-parse-suffix~ functions to
transform them from the convenient to the expected form.
transform them from the convenient to the expected form. Depending
on the used group class, ~transient-parse-suffixes~'s SUFFIXES must be
a list of group vectors (for ~transient-columns~) or a list of suffix
lists (for all other group classes).

If you explicitly specify children and then transform them using
~:setup-children~, then the class of the group is determined as usual,
Expand All @@ -1024,6 +1027,32 @@ constructor of that class.
is used and a warning is displayed. This warning will eventually
be replaced with an error.

#+BEGIN_SRC emacs-lisp
(transient-define-prefix my-finder-by-keyword ()
"Select a keyword and list matching packages."
;; The real `finder-by-keyword' is more convenient
;; of course, but that is not the point here.
[:class transient-columns
:setup-children
(lambda (_)
(transient-parse-suffixes
'my-finder-by-keyword
(let ((char (1- ?A)))
(mapcar ; a list ...
(lambda (partition)
(vconcat ; of group vectors ...
(mapcar (lambda (elt)
(let ((keyword (symbol-name (car elt))))
; ... where each suffix is a list
(list (format "%c" (cl-incf char))
keyword
(lambda ()
(interactive)
(finder-list-matches keyword)))))
partition)))
(seq-partition finder-known-keywords 7)))))])
#+END_SRC

- The boolean ~:pad-keys~ argument controls whether keys of all suffixes
contained in a group are right padded, effectively aligning the
descriptions.
Expand Down
31 changes: 30 additions & 1 deletion docs/transient.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,10 @@ prefix's @code{transient--layout} property, but it is often more convenient
to use the same form as understood by @code{transient-define-prefix},
described below. If you use the latter approach, you can use the
@code{transient-parse-suffixes} and @code{transient-parse-suffix} functions to
transform them from the convenient to the expected form.
transform them from the convenient to the expected form. Depending
on the used group class, @code{transient-parse-suffixes}'s SUFFIXES must be
a list of group vectors (for @code{transient-columns}) or a list of suffix
lists (for all other group classes).

If you explicitly specify children and then transform them using
@code{:setup-children}, then the class of the group is determined as usual,
Expand All @@ -1213,6 +1216,32 @@ For backward compatibility, if you fail to do so, @code{transient-column}
is used and a warning is displayed. This warning will eventually
be replaced with an error.

@lisp
(transient-define-prefix my-finder-by-keyword ()
"Select a keyword and list matching packages."
;; The real `finder-by-keyword' is more convenient
;; of course, but that is not the point here.
[:class transient-columns
:setup-children
(lambda (_)
(transient-parse-suffixes
'my-finder-by-keyword
(let ((char (1- ?A)))
(mapcar ; a list ...
(lambda (partition)
(vconcat ; of group vectors ...
(mapcar (lambda (elt)
(let ((keyword (symbol-name (car elt))))
; ... where each suffix is a list
(list (format "%c" (cl-incf char))
keyword
(lambda ()
(interactive)
(finder-list-matches keyword)))))
partition)))
(seq-partition finder-known-keywords 7)))))])
@end lisp

@item
The boolean @code{:pad-keys} argument controls whether keys of all suffixes
contained in a group are right padded, effectively aligning the
Expand Down

0 comments on commit cfd17a7

Please sign in to comment.