3

I would like to call a function (find-file) interactively and then set the initial content of the mini buffer to my server's home folder. I got as far as using call-interactively, but after that I'm lost. Any suggestions?

8

find-file uses the buffer-local default-directory value as the default filename (see also find-file-read-args), so all you need to do is bind that value for the scope of the call to find-file:

(let ((default-directory "/home/"))
  (call-interactively 'find-file))
  • Great! For reference is there any generic way to insert text into the mini-buffer programmatically when calling a function interactively? – Eric Egan Dec 29 '17 at 15:30
  • Not sure if this is the best method, but you could wrap the function that you are calling in your own interactive function, creating the prompt yourself (with read-string, for example). See this answer for an example. – 0x5453 Dec 29 '17 at 16:03
  • 2
    OP: The question you pose in your comment is the one posed here. The question about find-file inserting a directory name is a special case, which can be taken care of as @phils said. For that solution, however, be sure to have option insert-default-directory be non-nil (which it is by default). Otherwise, you can insert the directory into the minibuffer interactively, using M-n. – Drew Dec 29 '17 at 18:05

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.