Spreadable Elisp

smarter-compile 2012.4.9

a smarter wrapper for `compile'

M-x package-install smarter-compile
Dino Chiesa

This package provides `smarter-compile' function.

It acts as a wrapper for `compile', providing a way to intelligently set the `compile-command' and then invoke `compile' as normal.

It chooses a compile command, and suggests it by invoking `compile' interactively. It makes the choice according to the name of the current buffer, and the items - think of them as rules - in the `smart-compile-alist'. By default, it performs the selection logic just once per buffer. When you run `smarter-compile', it sets a buffer-local flag and does not walk the rules again. If you'd like to force to walk through the rules, use C-u M-x smarter-compile.

The built-in rules are like this:

- If there is a makefile in the current directory, ask if the user wants to run make, and if so, suggest make.

- If there is a Msbuild project file in the current directory, suggest msbuild.exe .

- if there is a comment in the header like compile: <...>, and the file has an extension that is a member of `smart-compile-compile-command-in-comments-extension-list', then use that string that as the compile command.

- if editing a makefile, suggest make.

- if the file extension is .cs, .vb, .c, .java, and so on... use a module-specific build command.

To use this package, add this line to your .emacs file: (require 'smart-compile)

To tweak it, set `smart-compile-alist'. This variable holds the rules for guessing the compile command. It is a list of cons cells, each one like (TEST . COMMAND). In the simplest case, the TEST is a regex that gets applied to the filename, and COMMAND is a string used for the `compile-command' when the TEST succeeds. You can either setq the list, which would replacing the built-in rules completely, or you can append items to the default list, thereby extending the built-in behavior of `smarter-compile.el'. Keep in mind that the order of evaluation of the rules is significant.

The simplest kind of extension of the rules looks like this:

(require 'smarter-compile) (add-to-list 'smart-compile-alist '("\\.css\\'" . "/bin/csslint.js --format=compiler %f"))