Emacs defaults to the command make -k
when I run compile
. However, I pretty much never think it's useful to have make
continue after errors, so I always remove the -k
flag. Is there a way to change the default in my .emacs
so that it's just make
?
Asked
Active
Viewed 6,242 times
15

Steve
- 8,153
- 9
- 44
- 91
-
11The answer to "can I change X in Emacs" is YES for all values of X. – AShelly Jan 05 '11 at 20:22
-
2AShelley, exactly right. The only real questions are, "HOW can I change X in Emacs?" – Cheeso Jan 06 '11 at 16:28
2 Answers
14
(setq compile-command "make")
or similar in your .emacs should suffice.
For more info, type
C-h f compile
which describes what variables are used when M-x compile is called.
In there, you should see it calls compile-command and a
C-h v compile-command
tells you this defaults to "make -k". All above is a simplification, but all the info should be in those commands should you need to dig further.

Andre Holzner
- 18,333
- 6
- 54
- 63

cristobalito
- 4,192
- 1
- 29
- 41
-
For this purpose, is there an effective difference between `(setq compile-command ...)` and `(setq-default compile-command ...)`? – Steve Jan 12 '11 at 22:01
-
No idea Steve - C-h f setq and C-h f setq-default give a little more info, but can't really decipher. – cristobalito Jan 13 '11 at 16:00
-
2@Steve, from the [Elisp Reference manual on `setq-default`](http://www.gnu.org/software/emacs/manual/html_node/elisp/Default-Value.html): "If a SYMBOL is not buffer-local for the current buffer, and is not marked automatically buffer-local, `setq-default` has the same effect as `setq`." `compile-command` is not automatically buffer-local, and it normally won't be buffer-local during execution of `.emacs`, so it normally won't make a difference. – cjm May 26 '11 at 08:36
8
Since I need different compilers for different modes, I make use of the following snippet (here shown for javascript):
(require 'compile)
(add-hook 'js-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(format "jshint %s" (file-name-nondirectory buffer-file-name)))))
This runs "jshint " as my compile command. I can then add hooks to other languages as well, and customize each according to my needs.

Stefan van der Walt
- 7,165
- 1
- 32
- 41
-
Note that you can also use `(file-name-sans-extension buffer-file-name)` for the file name without the extension. For example, `(format "rustc %s && %s" (file-name-nondirectory buffer-file-name) (file-name-sans-extension buffer-file-name))`. – Jake Ireland Dec 25 '21 at 04:58