I have a function that creates a buffer, with a default file name, and would like the first user action for that buffer be a prompt to write the buffer to a file, allowing the user to change the default, but offering the default in the minibuffer prompt.
The best result of all the options I have tried so far does properly associate the desired filename and path with a buffer, and does prompt the user, but does not offer the default name as a default.
Here is one of the best versions of the test function:
(defun my-write-test ()
(interactive)
(let*
((name "foo.txt")
(path "/home/me/foo.txt")
(buf (create-file-buffer name)))
(pop-to-buffer buf)
(insert "random text\n")
(set-visited-file-name path)
(call-interactively 'write-file (vector path))))
My guess is that I am somehow not properly defining the vector argument to function call-interactively
, but I could be wrong; Maybe I'm just using the wrong elisp function?
read-file-name
, which can have default input, visible suggested initial input, etc. -- store the value to a let-bound variable and later pass that value towrite-file
. I'm not sure why you would needwrite-file
interactively, if you useread-file-name
. To see more about that function, typeM-x describe-function
orC-h f
. And, unless I am mistaken,write-file
does not take a vector -- it takes a STRING as its first argument. Again, describe the functionwrite-file
and see what the doc-string suggests for its arguments.read-file-name
.