What I would like if for C-c C-c to run py.test and display the output in the other buffer if the name of the file being edited begins with test_ and to normally run py-execute-buffer otherwise. How would I do this? I am using emacs 23.1.1 with python-mode and can access py.test from the command line.
+3
A:
This isn't particularly well-tested; it's just a rough idea.
(defun py-do-it ()
(interactive)
(if (string-match
(rx bos "test_")
(file-name-nondirectory (buffer-file-name)))
(compile "py.test")
(py-execute-buffer)))
(add-hook 'python-mode-hook
(lambda ()
(local-set-key
(kbd "F5") ;or whatever
'py-do-it)))
offby1
2010-04-14 13:56:41
Thank you, I tried it and it is working fine.
Nikwin
2010-04-16 07:42:42
After working with it a while more, I decided that I wanted py.test to run only on the current buffer, so I replaced (compile "py.test") with (shell-command (concat "py.test " (buffer-file-name)))
Nikwin
2010-04-17 05:50:53