Nicolas Petton

Nicolas Petton

Web developer, Lisper, Smalltalker & Emacs maniac.

Watching buffers

Watching Buffers with buffer-watcher.el

October 24, 2014

buffer-watcher.el makes it easy to evaluate shell commands each time a buffer is saved in Emacs.

You can specify a mode and base path for which a specific script should be evaluated, and each time you save a buffer that matches the criteria, the hook will be run.

Here's an example that runs lessc each time a less file is saved in the project proj:

(require 'buffer-watcher)
(add-to-list 'buffer-watcher-commands '("Lessc hook" less-css-mode "~/projects/proj/" "lessc % > style.css"))

The command will be run from within the same folder as the save file, and % is expanded to the buffer's file name.

If you're into customize, you can M-x customize-group RET buffer-watcher to add your commands.

buffer-watcher.png

You can grab buffer-watcher from my emacs settings on GitHub.

comments powered by Disqus