在Emacs中运行py.test

9

我希望在编辑名称以test_开头的文件时,按下C-c C-c可以运行py.test并在另一个缓冲区中显示输出,否则正常运行py-execute-buffer。我该如何做到这一点?我使用的是带有python-mode的emacs 23.1.1,并可以从命令行访问py.test。

1个回答

8

这并没有经过严格测试,只是一个粗略的想法。

(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)))

1
在更多的使用中,我决定只让py.test在当前缓冲区中运行,因此我用(shell-command (concat "py.test " (buffer-file-name)))替换了(compile "py.test")。 - Nikwin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接