From 69de85035ef1c769e389a650ba9c18aed33cadef Mon Sep 17 00:00:00 2001 From: Michelle Baert Date: Tue, 29 Nov 2016 19:24:38 +0100 Subject: [PATCH 1/2] Keeping compilation buffer alive and implementing (mocha-run-last) --- mocha.el | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/mocha.el b/mocha.el index df07c5e..d2a00db 100644 --- a/mocha.el +++ b/mocha.el @@ -147,17 +147,47 @@ IF TEST is specified run mocha with a grep for just that test." If MOCHA-FILE is specified run just that file otherwise run MOCHA-PROJECT-TEST-DIRECTORY. -IF TEST is specified run mocha with a grep for just that test." +IF TEST is specified run mocha with a grep for just that test. + +Root directory (hence project), file and test are preserved +as local variables in *mocha tests* buffer, so don't kill it +if you want to use `mocha-run-last'. +" (save-some-buffers (not compilation-ask-about-save) (when (boundp 'compilation-save-buffers-predicate) compilation-save-buffers-predicate)) - (when (get-buffer "*mocha tests*") - (kill-buffer "*mocha tests*")) - (let ((test-command-to-run (mocha-generate-command nil mocha-file test)) (root-dir (mocha-find-project-root))) - (with-current-buffer (get-buffer-create "*mocha tests*") + (let ( + (test-command-to-run (mocha-generate-command nil mocha-file test)) + (root-dir (mocha-find-project-root)) + ;; reuse existing buffer to preserve layout and local variables + (buf (get-buffer-create "*mocha tests*")) + ) + (with-current-buffer buf + ;; unneeded: (toggle-read-only nil) (erase-buffer) + ;; : compilation will clean buffer anyway (setq default-directory root-dir) - (compilation-start test-command-to-run 'mocha-compilation-mode (lambda (m) (buffer-name)))))) + (compilation-start test-command-to-run 'mocha-compilation-mode (lambda (m) (buffer-name))) + + ;; memorize last test, used in mocha-run-last + (set (make-local-variable 'mocha-file) mocha-file) + (set (make-local-variable 'mocha-test) test) + ))) + +(defun mocha-run-last () + "Runs again mocha with same parameters as for last run. + +Relies on the presence of *mocha tests* buffer to retrieve settings. +" + (interactive) + (let ((buf (get-buffer "*mocha tests*"))) + (if buf + (with-current-buffer buf + (mocha-run mocha-file mocha-test) + ) + (message "Mocha buffer not found. You first need to use other mocha test commands.") + ) + )) (defun mocha-walk-up-to-it (node) "Recursively walk up the ast from the js2-node NODE. From 3f2b30fcbcb8fbc21a7f30bf647ce951c74c448b Mon Sep 17 00:00:00 2001 From: Michelle Baert Date: Tue, 29 Nov 2016 20:53:59 +0100 Subject: [PATCH 2/2] renamed buffer variables to avoid conflicts --- mocha.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mocha.el b/mocha.el index d2a00db..ac0dc77 100644 --- a/mocha.el +++ b/mocha.el @@ -170,8 +170,8 @@ if you want to use `mocha-run-last'. (compilation-start test-command-to-run 'mocha-compilation-mode (lambda (m) (buffer-name))) ;; memorize last test, used in mocha-run-last - (set (make-local-variable 'mocha-file) mocha-file) - (set (make-local-variable 'mocha-test) test) + (set (make-local-variable 'mocha-last-file) mocha-file) + (set (make-local-variable 'mocha-last-test) test) ))) (defun mocha-run-last () @@ -183,7 +183,7 @@ Relies on the presence of *mocha tests* buffer to retrieve settings. (let ((buf (get-buffer "*mocha tests*"))) (if buf (with-current-buffer buf - (mocha-run mocha-file mocha-test) + (mocha-run mocha-last-file mocha-last-test) ) (message "Mocha buffer not found. You first need to use other mocha test commands.") )