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?
Asked
Active
Viewed 355 times
3
-
1Possible duplicate of Call a function and insert text in minibuffer prompt – Drew Dec 29 '17 at 18:01
-
If the question is specifically about find-file, please make it clear. Otherwise it should be closed as duplicate imo. – YoungFrog Jan 01 '18 at 07:41
1 Answers
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))

phils
- 50,977
- 3
- 79
- 122
-
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 (withread-string
, for example). See this answer for an example. – 0x5453 Dec 29 '17 at 16:03 -
2OP: 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 optioninsert-default-directory
be non-nil
(which it is by default). Otherwise, you can insert the directory into the minibuffer interactively, usingM-n
. – Drew Dec 29 '17 at 18:05