(interactive "sPROMPT: ")

one can set a prompt for, e.g., a string function.

Question: Is it possible to also supplement a default argument to the function? Say

(interactive "sPROMPT: default")

so that the users can supply "default" as the default argument to the function, unless they change it manually?

(defun hello (st)
  (interactive (list (read-string "Your name: " "toto")))
  (message "Hello Mr %s" st))

where "toto" is the initial-input.

  • Read the documentation of read-string, and note that the initial input ("toto" in the example above) is not necessarily the same thing as the default value (the optional fourth argument), meaning the value that is returned if the user deletes the initial input and returns the empty string. – Phil Hudson Mar 16 at 21:00
  • @ Phil Hudson: I know this, but I imagine that the careful user of read-string will have the curiosity to read the documentation, which is neither long nor very complex to have a code as close to his desire. – gigiair Mar 16 at 21:24
  • 1
    Fair enough, and on reflection I think yours is the better (because simpler) take. Your answer is exactly what was wanted, my comment is (probably) surplus and perhaps a bit pedantic. Still, it might come in useful to someone searching someday. – Phil Hudson Mar 18 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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