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 339 times
3
-
1Possible duplicate of [Call a function and insert text in minibuffer prompt](https://emacs.stackexchange.com/questions/36208/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
- 48,657
- 3
- 76
- 115
-
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](https://stackoverflow.com/a/9646268/3282436) answer for an example. – 0x5453 Dec 29 '17 at 16:03
-
2OP: The question you pose in your comment is the one posed [here](https://emacs.stackexchange.com/q/36208/105). 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