1

I use Emacs under Ubuntu.

I would like to bind the make command to a shortcut, so that makefile could be launched. If the compilation fails, I would the error message to be shown in a sub-window or the message bar; otherwise, I would all the sub-windows to be closed except the one containing the main text.

Does anyone know how to realize that? Also which shortcut should be chosen?

  • Why not just bind compile to whatever key you'd like? compile-command is 'make -k' by default. – Kyle Meyer Apr 27 '15 at 2:51
  • 1
    Or, even better, use recompile instead of compile. That way you skip the confirmation step. – deprecated Apr 27 '15 at 3:35
  • Like deprecated said, just bind the recompile command, and set compile-command somewhere in your init file. F5 or F7 are pretty common shortcuts for most IDEs. – user2699 Apr 27 '15 at 3:36
  • I know this is an old thread, but, when I run M-x compile it uses my dir vars, and run make accordingly. If I use (global-set-key (kbd "C-c C-c") #'compile), the compile command run is not the same (asks complete different questions, probably related to the major mode). How to specify the exact 'built-in' compile method? – Alberto Mar 28 at 10:09
3

One possibility (based on an original suggestion by Kyle Meyer) is

(global-set-key (kbd "C-c m") 'recompile)

Then you can type C-c m, which will first offer to save the current buffer if necessary, and then will run the command make -k in the directory containing the associated file. The -k switch causes make to try to keep going even if some commands fail. In case you want to modify this, you can type C-u C-c m and you will get the chance to edit the compilation command in the minibuffer first. The edited command will then be remembered on a per-buffer basis.

Any compilation errors will be shown in a dedicated buffer (called *compilation*) and you can either click on these with the mouse (to jump to the relevant point in the source file) or use C-x backtick to cycle through them (sorry, I can't work out how to type a literal backtick inside backticks!). The compilation buffer is not shown if no errors occur but you get a notification in the echo area when compilation is complete.

Of course, you can use any other key of your choice instead of C-c m - I chose that for the mnemonic m = "make" and because the C-c letter keys are reserved for the end-user, so there is little risk of collision.

0

So the global set key to recompile is the first way to go. Now we can try another option, more interactive and visual, which is helm-make by abo-abo, a prolific emacs lisp developer: https://github.com/abo-abo/helm-make

With the command helm-make-projectile you will have a nice helm buffer which suggests the targets of the makefile, that it will find at your project root directory (handy). Choose one and it calls compile.

Install it with

package-install RET helm-make RET

(you need MELPA)

Note: and this package is similar, but it's mine, it displays a menu with the Makefile targets, and it isn't in melpa. To try it copy it in a buffer and call M-x eval-buffer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.