Compiling Programs from Within Emacs?

回眸只為那壹抹淺笑 提交于 2019-12-06 02:33:32

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!