Define an argument with default options and a completing-read-multiple reader, which retains selections between readings (using :always-read)? #194
-
Sorry for the long title. I don't understand how to do what I want, and transient is young and specific enough that I thought this (rather than reddit, or emacs-devel) would be the best place to ask. Hope that's right. I want to define a transient argument which:
I've got as far as something like this: (transient-define-argument magit-send-email:-b ()
:description "Bcc"
:class 'transient-option
:key "-b"
:argument "--bcc="
:reader #'completing-read-multiple
:multi-value t
:always-read t
:prompt "Bcc: ")
As far as I can tell there are two problems. First, transient's readers take First question: how I can I dynamically (in the above sense) set the choices for the crm reader? Secondly, I need to set the initial value for crm. I tried setting Second question: how can I dynamically (in a similar sense) set the initial value for every crm session? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Well, maybe make it a named function but other than that this is what you are expected to do. And why not? The place where the completion happens seems like the prefect place to specify the details of how the completion should be performed. Putting the information in the slots of an object/class just spreads the relevant information further. Of course An additional benefit of that is that you can use the specialized reader for multiple related suffixes. All you have to do for each suffix is to set only the reader slot, instead of having to set multiple slots to potentially non-trivial values. Here's how how magit reads the files that go after (transient-define-argument magit:-- ()
:description "Limit to files"
:class 'transient-files
:key "--"
:argument "--"
:prompt "Limit to file(s): "
:reader #'magit-read-files
:multi-value t)
(defun magit-read-files (prompt initial-input history &optional list-fn)
(magit-completing-read-multiple* prompt
(funcall (or list-fn #'magit-list-files))
nil nil
(or initial-input (magit-file-at-point))
history)) Grep magit for If you are wondering why |
Beta Was this translation helpful? Give feedback.
Well, maybe make it a named function but other than that this is what you are expected to do. And why not? The place where the completion happens seems like the prefect place to specify the details of how the completion should be performed. Putting the information in the slots of an object/class just spreads the relevant information further.
Of course
transient
already does the latter but that is done to reduce the amount of boilerplate. So the things that are very similar between all or most infix arguments are controlled by setting the values of certain slots, but …