diff options
| author | David Shepherd <davidshepherd7@gmail.com> | 2017-03-30 08:43:16 +0100 |
|---|---|---|
| committer | David Shepherd <davidshepherd7@gmail.com> | 2017-03-30 16:23:55 +0100 |
| commit | c843a574f441be003c56c7ebda088950461c8f2e (patch) | |
| tree | 4e70a9fc29fe091acc5ea3080a1dc3fe93fe930a | |
| parent | Show error message if terminal command fails (diff) | |
| download | emacs-terminal-here-c843a574f441be003c56c7ebda088950461c8f2e.tar.gz | |
Don't query about closing terminals when exiting emacs on Windows
| -rw-r--r-- | terminal-here.el | 6 | ||||
| -rw-r--r-- | test/terminal-here-test.el | 74 |
2 files changed, 43 insertions, 37 deletions
diff --git a/terminal-here.el b/terminal-here.el index 0820ef9..6d412bf 100644 --- a/terminal-here.el +++ b/terminal-here.el @@ -31,7 +31,7 @@ ((eq system-type 'darwin) (list "open" "-a" "Terminal.app" dir)) - ;; From http://stackoverflow.com/a/13509208/874671 + ;; From http://stackoverflow.com/a/13509208/874671 ((memq system-type '(windows-nt ms-dos cygwin)) (list "cmd.exe" "/C" "start" "cmd.exe")) @@ -78,7 +78,9 @@ buffer is not in a project." (when (and (eq (process-status proc) 'exit) (/= (process-exit-status proc) 0)) (message "Error: in terminal here, command `%s` exited with error code %d" (mapconcat #'identity term-command " ") - (process-exit-status proc))))))) + (process-exit-status proc))))) + ;; Don't close when emacs closes, seems to only be necessary on Windows. + (set-process-query-on-exit-flag proc nil))) ;;;###autoload (defun terminal-here-launch () diff --git a/test/terminal-here-test.el b/test/terminal-here-test.el index 8e8cab7..6323c8a 100644 --- a/test/terminal-here-test.el +++ b/test/terminal-here-test.el @@ -1,50 +1,54 @@ ;;; -*- lexical-binding: t; -*- +(defmacro with-terminal-here-mocks (&rest body) + "Stub out some process interaction functions" + `(with-mock + (stub set-process-sentinel) + (stub set-process-query-on-exit-flag) + ,@body)) + + + (ert-deftest linux-default-command () - (with-mock - (mock (set-process-sentinel)) - (mock (start-process "x-terminal-emulator" * "x-terminal-emulator")) - (let ((system-type 'gnu/linux)) - (custom-reevaluate-setting 'terminal-here-terminal-command) - (terminal-here-launch-in-directory "adir")))) + (with-terminal-here-mocks + (mock (start-process "x-terminal-emulator" * "x-terminal-emulator")) + (let ((system-type 'gnu/linux)) + (custom-reevaluate-setting 'terminal-here-terminal-command) + (terminal-here-launch-in-directory "adir")))) (ert-deftest osx-default-command () - (with-mock - (mock (set-process-sentinel)) - (mock (start-process "open" * "open" "-a" "Terminal.app" "adir")) - (let ((system-type 'darwin)) - (custom-reevaluate-setting 'terminal-here-terminal-command) - (terminal-here-launch-in-directory "adir")))) + (with-terminal-here-mocks + (mock (start-process "open" * "open" "-a" "Terminal.app" "adir")) + (let ((system-type 'darwin)) + (custom-reevaluate-setting 'terminal-here-terminal-command) + (terminal-here-launch-in-directory "adir")))) (ert-deftest windows-default-command () - (with-mock - (mock (set-process-sentinel)) - (mock (start-process "cmd.exe" * "cmd.exe" "/C" "start" "cmd.exe")) - (let ((system-type 'windows-nt)) - (custom-reevaluate-setting 'terminal-here-terminal-command) - (terminal-here-launch-in-directory "adir")))) + (with-terminal-here-mocks + (mock (start-process "cmd.exe" * "cmd.exe" "/C" "start" "cmd.exe")) + (let ((system-type 'windows-nt)) + (custom-reevaluate-setting 'terminal-here-terminal-command) + (terminal-here-launch-in-directory "adir")))) (ert-deftest custom-terminal-command-as-list () - (with-mock - (mock (set-process-sentinel)) - (mock (start-process "1" * "1" "2" "3")) - (validate-setq terminal-here-terminal-command '("1" "2" "3")) - (terminal-here-launch-in-directory "adir"))) + (with-terminal-here-mocks + (mock (start-process "1" * "1" "2" "3")) + (validate-setq terminal-here-terminal-command '("1" "2" "3")) + (terminal-here-launch-in-directory "adir"))) (ert-deftest custom-terminal-command-as-function () - (with-mock - (mock (set-process-sentinel)) - (mock (start-process "1" * "1" "2" "3" "adir")) - (validate-setq terminal-here-terminal-command (lambda (dir) (list "1" "2" "3" dir))) - (terminal-here-launch-in-directory "adir"))) + (with-terminal-here-mocks + (mock (start-process "1" * "1" "2" "3" "adir")) + (validate-setq terminal-here-terminal-command (lambda (dir) (list "1" "2" "3" dir))) + (terminal-here-launch-in-directory "adir"))) (ert-deftest custom-terminal-command-as-junk-rejected () - (with-mock - (should-error - (validate-setq terminal-here-terminal-command "astring") - :type 'user-error))) + (with-terminal-here-mocks + (should-error + (validate-setq terminal-here-terminal-command "astring") + :type 'user-error))) @@ -57,9 +61,9 @@ (ert-deftest with-project-root-function () (let ((project-root-finder (lambda () "" "vc-root"))) (validate-setq terminal-here-project-root-function project-root-finder) - (with-mock - (mock (terminal-here-launch-in-directory "vc-root")) - (terminal-here-project-launch)))) + (with-terminal-here-mocks + (mock (terminal-here-launch-in-directory "vc-root")) + (terminal-here-project-launch)))) (ert-deftest project-root-finds-nothing () (validate-setq terminal-here-project-root-function (lambda () nil)) |
