I've already asked the same question on Emacs. If it's not permitted, I'm sorry and I will delete the question.
- Start Emacs in my home directory (
- Find a file in the
~/Projects/ruby-play directory with
- Try to find another file with
The default directory in the file finder will be
What I'd like to see is the default directory being
Is there a package/hook/Elisp function I should use to make this happen?
Thank you very much!
Best How To :
One way would be to set
nil, but then you won't have a default directory at all, not even your home-directory:
(setq insert-default-directory nil)
If you want your home directory to show up as the default, this cannot be done so easily. When interactively calling
find-file, this results in a call to
read-file-name which has a rather complicated default behavior.
default-directory doesn't help, as it's value is set when the file of the buffer you're currently seeing is visited.
The only option I see is using your own version of
find-file like this:
(defun my-find-file-read-args (prompt mustmatch)
(list (read-file-name prompt "~/" nil mustmatch)
(defun my-find-file (filename &optional wildcards)
"Edit file FILENAME.
Like `find-file` but always uses ~ as the default directory"
(my-find-file-read-args "Find file: "
(let ((value (find-file-noselect filename nil nil wildcards)))
(if (listp value)
(mapcar 'switch-to-buffer (nreverse value))
(global-set-key (kbd "C-x C-f") 'my-find-file)