views:

113

answers:

1

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
Thank you, I tried it and it is working fine.
Nikwin
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