Question

What is the best way to compile programs inside emacs? I am currently opening a separate buffer with C-x 3 and running eshell inside it using M-x eshell then invoking either make or clang directly; most of the time I do have a Makefile set up.

Is there any advantage with running the compilation process using M-x compile vs running make inside eshell? Any other ways to do it and what are the advantages/disadvantages of those?

Était-ce utile?

La solution

The easiest way to do this is to use the Emacs built-in compile command. M-x compile should do you fine. You can then edit the command that will be run (by default make -k) and then hit return to run the compilation. Emacs will then parse the output and if it finds any errors they will link to the source files so you can open them in a buffer.

Positives about it are:

  • Parsing of the output buffer
  • Memorisation of the compile command between invocations
  • Compilation output is shown in a non-selected buffer, you can quickly edit the file you were working on and fix any silly errors.
  • M-n and M-p scroll by error messages

Most of these features are provided by the compilation-minor-mode minor mode though not the actual compilation command and buffer. Once you have run a compilation command in eshell you could probably get similar results by setting the minor mode to compilation-minor-mode.

Autres conseils

I personally prefer to run make or whatever command you're using to compile within a multi-term for the following reasons:

  • it works like M-xcompileRET if you activate compilation-shell-minor-mode (M-p, C-`, …).

  • but you can, obviously, use other commands like

    mkdir build
    cd build
    ./configure --with-another-option
    

    Of course you can do this from Emacs but I prefer the shell interaction for this kind of stuff.

And imo, the main drawback of M-xcompile is that if you're editing a file located in another directory than your Makefile then you have to use M-xcompile in the correct directory and then M-xrecompile. But if you want, say to make clean && make, then you'll have to switch to the correct directory, do it, switch back.

However term.el has its own drawback, it uses a non-portable hacky way to track the current directory.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top