lunes, 28 de enero de 2013

a simple pattern to shorten the feedback cycle

Lately I had to do some work on nginx configuration and lua-scripting (here is the detailed info on augmenting an API through nginx and lua). To do so, the development cycle is the following:
  1. edit nginx conf file or lua file called from the nginx conf file.
  2. restart or reload nginx.
  3. check in nginx log file for errors
  4. Try the feature via curl or browser
I 'nulled' the 2nd step via a very simple pattern that I've been using lately. It's dead simple, but involves a few elisp-ities you may or may not know. Anyway, check it out.
The 'trick' is to use buffer local variables to run the appropiate commands in each buffer. So you should set a variable called run-command, to the string that will be executed when saving.
Hint: here's the pattern for the prop-line in case you want emacs to set the variable automatically when you open the file.
# -*- run-command: "/opt/openresty/nginx/sbin/nginx -c /home/rgrau/workspace/nginx-translator/config_nginx.conf -p /tmp/nginx/  -s reload"; -*

For more fancyness, there's also add-file-local-variable-prop-line which can help you.
And the tiny code to hook the command to after-save hook.
(defun rgc/run-command ()
  (interactive)
  (when (boundp 'run-command)
    (shell-command run-command)))

(add-to-list 'after-save-hook 'rgc/run-command)
To speed up the 3rd step, you can play with tailing the log file in a shell-mode buffer, or use auto-reverse-tail-mode. But let's leave it for another post :) Btw, Next weekend I'll be the next FOSDEM. If anyone wants to meet and hack some elisp or discuss vim vs emacs with a beer, ping me (raimonster at gmail dot com)

1 comentario:

Jakub Hozak dijo...

+1 - good idea!