With the following function using "completing-read", how can one add a default initial input to be Convert. What can I do?

(defun subset ()
  "Convert or extract subsets of data."

  (let* ( (opts '("Convert" "Split"))
          (sel  (completing-read "Subset: " opts nil t  )) )
  • The initial-input can be given as the 5th argument to the completing-read function. You can find that using C-h f. And, while typing the completing-read form, the expected arguments are displayed in the echo area. Or do you mean something else? I am not sure what is your goal, but if you have only two options, you could also consider to use the universal argument. Jun 13, 2022 at 22:31
  • I would just enter "Convert" as the 5th argument or something else?
    – Dilna
    Jun 13, 2022 at 22:39
  • Yes just enter that Jun 13, 2022 at 22:40
  • 1
    Thank you friend.
    – Dilna
    Jun 13, 2022 at 22:44
  • I am actually encountering a slight problem. I add "Convert" and run the function. What happens is that "Convert" appears as expected. But when I go through the option, the first one that appears is also "Convert". Making it seem like the option is stuck to "Convert".
    – Dilna
    Jun 13, 2022 at 22:49

1 Answer 1


If you really mean use Convert as the initial input then this is how:

(let* ((opts  '("Convert" "Split"))
       (sel   (completing-read "Subset: " opts nil t "Convert")))
  (message "SEL: %s" sel))

If you really mean use Convert as the default value then this is how:

(let* ((opts  '("Convert" "Split"))
       (sel   (completing-read "Subset: " opts nil t nil nil "Convert")))
  (message "SEL: %s" sel))

If you really mean use Convert as both the initial input and the default value then this is how:

(let* ((opts  '("Convert" "Split"))
       (sel   (completing-read "Subset: " opts nil t "Convert" nil "Convert")))
  (message "SEL: %s" sel))

In the initial-input (only) case Convert is preinserted into the minibuffer, and the default, if you remove that preinserted input, is the empty string, "".

In the default (only) case Convert is not inserted -- you use M-n to insert it. And if you just RET without inserting any text then you get Convert.

In all three cases, just hitting RET chooses Convert. Convert is an allowed completion because you decided that it belongs to opts, which you pass as the allowed completions.

If you remove Convert from opts and change the t value of arg REQUIRE-MATCH to nil, then Convert isn't a completion but it is accepted as an input. Anything at all is accepted as an input, in this case.

It all depends on what you want. If you have a more specific question, please pose that separately.

  • Reading the docstring of completing-read for INITIAL-INPUT - which says that the argument is deprecated - telling users to pass nil and supply the default value DEF instead.
    – Dilna
    Jun 21, 2022 at 7:59
  • Your comment isn't a sentence. What about such reading?
    – Drew
    Jun 21, 2022 at 14:55
  • That the suggestion on using initial-input could became a problem in future.
    – Dilna
    Jun 21, 2022 at 15:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.