我希望在编辑名称以test_开头的文件时,按下C-c C-c可以运行py.test并在另一个缓冲区中显示输出,否则正常运行py-execute-buffer。我该如何做到这一点?我使用的是带有python-mode的emacs 23.1.1,并可以从命令行访问py.test。
这并没有经过严格测试,只是一个粗略的想法。
(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)))