防止自动更改默认目录 [英] Preventing automatic change of default-directory
问题描述
根据 Emacs文档,每次打开文件时,Emacs会将 default-directory
更改为包含该文件的目录。
As per the Emacs docs, every time you open a file, Emacs changes default-directory
to the directory containing that file.
然后,如果游标在该缓冲区中,并且(例如)启动SLIME,则使用 default-directory
作为SLIME的当前工作目录。如果您尝试打开一个新文件,它会以 default-directory
作为起点打开文件。
Then, if the cursor is in that buffer and you (for example) start SLIME, it uses default-directory
as the current working directory for SLIME. If you try to open a new file, it opens the file with default-directory
as your starting point.
我想要能够将 Mx cd
或以其他方式 cd
添加到目录中,然后再不要让Emacs更改我当前的工作目录到除了该目录之外的任何东西,否则我告诉它。我希望这是所有缓冲区中的全局,所以任何时候我在做一些涉及当前工作目录的事情,我知道它的设置是什么,不管我的光标在哪里。有没有办法这样做?
I want to be able to M-x cd
or otherwise cd
to a directory, and then never have Emacs change my current working directory to anything but that directory until I tell it otherwise. I want this to be global across all buffers, so that any time I'm doing something involving the current working directory, I know what it's set to regardless of where my cursor is at the moment. Is there a way to do this?
推荐答案
你可以尝试使用这样的东西:
You could try using something like this:
(add-hook 'find-file-hook
(lambda ()
(setq default-directory command-line-default-directory)))
这篇关于防止自动更改默认目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!