compile命令能不能设置Makefile的路径

在按compile命令后,如果我的项目结构是这样的

  • src/
    • hello.c
  • Makefile

我在编辑hello.c的缓冲区下执行compile命令,默认的值是make -k,这个时候肯定不通过,因为在src/目录下找不到Makefile

我要如何设置才能让emacs知道Makefile的路径

修改 default-directory,使其指向上层目录:

(let ((default-directory (locate-dominating-file (buffer-file-name) "Makefile)))
  (compile))

可以把它扩充成一个更通用的函数。

或者试试 project-compile

project-compile就行了吗

https://github.com/zerolee/.emacs.d/blob/master/Configurations/my-tools.el

自用的,require 后,执行 zerolee-compile 就可以了,依赖 projectile

可以试试 counsel-compile 能够自动识别 Makefile

啥都不用修改!

M-x compile `make -k -C <makefile-directory>`

M-x man make

留意-f-C 选项