Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

One thing I find myself doing a lot is every time I restart emacs, I have to retype the compilation command:

make XXX -f path-to-makefile/makefile

Sometimes I may also be working on different things at once, for example editing a .tex document and writing code, and I end up having to retype the compilation command as I switch from one to the other.

Is there a better way to do this? Can I somehow associate files with file-specific compilation commands that are known to emacs by default? Or is there some other approach that would improve my compilation workflow?

share|improve this question

1 Answer 1

Sometimes I may also be working on different things at once, for example editing a .tex document and writing code, and I end up having to retype the compilation command as I switch from one to the other.

I have written a bit of elisp to help dealing with this by defining multiple compilation commands (in the sense of M-x), each associated with its own buffer and shell command.

Here is the relevant code: https://gist.github.com/ffevotte/6130884

With this configuration, I define 4 compilation commands, which I bind to the <F5>-<F8> keys, and I often use a workflow similar to the following:

  • <f5> (or M-x compile5): associated to make -k
  • <f6> (or M-x compile6): associated to make -k test
  • <f7> (or M-x compile7): associated to doxygen

every time I restart emacs, I have to retype the compilation command

This is something I don't do much (restarting Emacs). However, take a look at the compile-command variable. From the documentation (C-h v compile-command):

Last shell command used to do a compilation; default for next compilation.

Sometimes it is useful for files to supply local values for this variable.

(but please also read the warning about using this as a file-local variable.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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