How do I not move directories in Emacs?

Asked 2 years ago, Updated 2 years ago, 103 views

I'm looking for a way not to move directories when I open files in Emacs.
For example, if you open a subdirectory /path/to/myproject/src/foo.py while working in the directory /path/to/myproject, the current directory moves to /path/to/myproject/src, but you want to stay in /path/to/myproject.

I've been using vim for a long time, and I've been trying Emacs (Spacemacs) recently, but I'm having trouble with this behavior that vim doesn't see.If you want to search for files under a project such as helm-grep-do-git-grep, you have to go back to the original project directory.

Thank you for your cooperation.

emacs spacemacs

2022-09-29 22:44

2 Answers

How about using the .dir-locals.el file?

/path/to/myproject/.dir-locals.el

((nil.((default-directory."/path/to/myproject"))))

I tried this environment (Emacs 25.1) and found that /path/to/myproject all the following files work recursively.


2022-09-29 22:44

Since command-line-default-directory contains the startup default-directory, how about reconfiguring default-directory with that value in each hook?

 (default my/restore-default-directory()
  (setq default-directory command-line-default-directory))
(dolist(hook'(find-file-hook redirect-mode-hook redirect-after-readin-hook))
  (add-hook hook#'my/restore-default-directory))

I don't know in any case, but when I just opened the file and opened the dead, the above alone worked. If there is a shortage, I think I can add a hook each time.


2022-09-29 22:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.