5

I'm trying to insert text into the mini buffer after running an external command. E.G

(call-interactively 'eval-expression)
(insert "blah")

The problem of course is that eval-expression doesn't return before the user has entered input. My end goal is to add some default editable text into the mini buffer prompt of an arbitrary command (i.e a 'default string' or template). How can I go about accomplishing this?

Drew
  • 29,895
  • 7
  • 74
  • 104
curious
  • 133
  • 7

1 Answers1

5

Use minibuffer-setup-hook:

(defun foo () (insert "ABCDE"))

(add-hook 'minibuffer-setup-hook 'foo)
Drew
  • 29,895
  • 7
  • 74
  • 104
  • 1
    Is there a way to accomplish this temporarily without having to add/remove the hook each time the function call is made? I only want this behavior when a custom function of mine is used. – curious Mar 21 '16 at 04:09
  • 1
    Just add/remove each time you need to do it "temporarily". It is not costly. Put the add/remove code in whatever function you use that needs it. – Drew Mar 21 '16 at 16:15
  • Thanks, I just wanted to make sure there isn't a more idiomatic way to do it (adding/removing a hook seems wasteful somehow) – curious Mar 21 '16 at 18:24
  • Nope, that's the idiomatic way: add/remove for the hook. – Drew Mar 21 '16 at 19:40