1

I'm using read-string to read a string from the minibuffer, with an initial input. How can I highlight the initial input, so that I can start replacing it with one key stroke? IOW, given (read-string "Test: " "Input") how can I put Input in an active region?

1 Answer 1

3

Use macro minibuffer-with-setup-hook to set the mark at the end of the minibuffer prompt. read-string then inserts the initial text with the mark active, which means that initial text is selected as the active region.

(defun foo (strg)
  "..."
  (interactive
   (list (minibuffer-with-setup-hook
             (lambda () (set-mark (minibuffer-prompt-end)))
           (read-string "Test: " "Input"))))
  (message "STRING: %s" strg))
1

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.