0

I have an interactive function taking 2 arguments. I can read them with

(defun example-fct (arg1 arg2)
  "This function take two arguments"
  (interactive
   (let ((arg1 (read-string "Arg1: "))
         (arg2 (read-string "Arg2: ")))
     (list arg1 arg2)))
  (message (format "input arg1=%s arg2=%s" arg1 arg2)))

Most of the time arg2 does not need to be entered. The default value is appropriate, and the second read is boring.

So I would prefer ask for arg1 and arg2 at the same time, something like a form. TAB switch between fields, ENTER (or other key) close the form and run the function.

-UUU:----F1  *scratch*      All (4,0)      (Lisp Interaction Fly AC WK ElDo
Arg1:                                  Arg2:

or

-UUU:----F1  *scratch*      All (4,0)      (Lisp Interaction Fly AC WK ElDo
Arg1:
Arg2:

How can I do this ?

I have look at magit transient, cus-edit.el and wid-edit.el (Are there any libraries for input fields in Emacs?) but I don't find.

Edit:

When I run isearch-fordward in the completions buffer during a find-file command, I have a second field in minibuffer. Does any one know how to do this ? enter image description here

8
  • 1. completing-read-multiple may get you part-way there. 2. Icicles multi-completions provide what you request, but there are no doubt simple answers/workarounds also.
    – Drew
    Jun 19, 2021 at 13:45
  • Thanks. I have tried (completing-read-multiple "Arg1, Arg2: " nil). But it is more confusing, and I don't have same autocompletion for arg1 and arg2.
    – Balaïtous
    Jun 19, 2021 at 15:54
  • For multiple input fields, transient is the only option I am aware of. My brother has a already very useful stalled/unfinished tutorial on using transients, but using transient gets tricky for default values. Jun 19, 2021 at 16:07
  • 1
    However, I do not know why you want it, but is it really so bad to read the colors sequentially? You could optionally only prompt for a second color when the command is prefixed with a universal argument. Also, I am not sure what colors you want to provide as options, but you might like to use the read-color function (and possibly modify it to make it accept default values). Jun 19, 2021 at 16:15
  • Related: For Elgrep I had a similar problem at a larger scale. Elgrep has many options. To use all those options with sane default settings I provided a menu-driven input elgrep-menu with the help of the Widgets library. This is probably only relevant if your command gets more options with sensible default values.
    – Tobias
    Jun 20, 2021 at 5:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.