Emacs:'查找文件'而不改变工作目录 [英] Emacs: 'Find file' without changing working directory
问题描述
我的c / c ++项目倾向于具有相当简单的目录结构,分离出src,include,bin等。我也倾向于在最上面的目录中有一个master makefile。当在Emacs中这样工作时,我总是必须发出 Mx cd uppermost-dir ,以便我的编译快捷方式按预期工作。
My c/c++ projects tend to have fairly straightforward directory structures which separate out src, include, bin, etc. I also tend to have a master makefile in the uppermost directory. When working like this in Emacs, I always have to issue M-x cd uppermost-dir in order for my compilation shortcuts to work as expected.
有没有办法保持当前目录与启动Emacs的目录相同?也就是说,当我打开一个文件时,我可以停止Emacs更改它的工作目录吗?
Is there a way to keep the current directory the same as the one from which I launch Emacs? That is, can I stop Emacs from changing it's working directory when I open a file?
或者,有没有什么关键的,我缺少一个目录的典型工作流程
Alternatively, is there something crucial I'm missing about the typical workflow with a directory hierarchiy like this exclusively in Emacs?
推荐答案
一种方法可以做到这一点:
One way you can do this:
在项目调用的根目录中创建一个文件 .dir-locals.el
Make a file in the root directory of your project call .dir-locals.el
当您在目录中打开文件或它的子目录时,将会被读取。
This will be read whenever you open a file in the directory or it's sub-directories.
为了备份到根文件夹并运行make作为编译命令,只需将它放在 .dir-locals.el
文件中。
In order to back up to the root folder and run make as your compile command, just put this in the .dir-locals.el
file.
((nil . ((compile-command . "cd ~/mycode/c/; make"))))
nil
是为(nil表示任何)设置局部变量的模式,所以为了仅仅使用C ++模式,您可以这样做...
nil
is the mode to set local variables for (nil means any), so to do this for only C++ mode you could do this instead ...
((c++-mode . ((compile-command . "cd ~/mycode/c/; make"))))
显然,您可以设置更多选项的列表,说运行ant的java文件等等。
Obviously you can set up a list with more options, say running ant for java files and so on.
这篇关于Emacs:'查找文件'而不改变工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!