emacs - 如何在Emacs中设置编译的默认目录?

标签 emacs compilation ocaml

我正在Emacs下对OCaml进行编码,在工作文件夹中有一个makefile,还有几个包含.ml文件的子文件夹。如果我启动M-x compile,并且makemakefile的缓冲区上可以正常工作,但在.ml文件的缓冲区上不起作用,则会给我一个错误:

-*- mode: compilation; default-directory: "..." -*-
Compilation started at Fri Jan 27 18:51:35

make -k
make: *** No targets specified and no makefile found.  Stop.

Compilation exited abnormally with code 2 at Fri Jan 27 18:51:35

这是可以理解的,因为默认目录是不包含makefile的子文件夹。有谁知道如何将makefile文件夹始终设置为编译的默认目录?

最佳答案

Matthias Puech在项目根目录中有一个solution文件,其中包含一个.dir-local文件:

((nil . ((eval . (setq default-directory 
                  (locate-dominating-file buffer-file-name
                   ".dir-locals.el")
)))))

大概也可以使用类似的内容:(shell-command-to-string "git rev-parse --show-toplevel")作为最里面的位。

关于emacs - 如何在Emacs中设置编译的默认目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9037833/

相关文章:

emacs - 在 emacs 组织模式中为粗体、斜体、...设置标记

emacs - 用flyspell标记所有拼写错误的单词,即使在当前 session 期间未写的单词也是如此

java - Java如何知道跳出循环时跳转到哪里?

ocaml - 为什么OCaml Map中的AVL树使用平衡因子(高度差异)2而不是1?

emacs - Emacs 启动时菜单栏闪烁片刻

emacs - 完全隐藏 :PROPERTIES: drawer in org-mode

java - 在一个项目中只编译一个类

c - 字符串文字的编译输出中的 .rodata 和 .rodata.str1.4 部分有什么区别?

ocaml - 为 opam 安装气泡包装的正确方法是什么(最好没有管理员权限)?

ocaml - 扩展 ocamllex 以获取更大的词典