aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTino Calancha2020-01-19 11:13:02 +0100
committerTino Calancha2020-01-19 11:13:02 +0100
commit2eb0b7835d1a9cd4b804436e33c71058cb38f178 (patch)
tree9edfabae5617c7d9113eec228e9b09f0319321ec /test
parentc134978a769a27c10de4a1c3d28c073f3de87a3c (diff)
downloademacs-2eb0b7835d1a9cd4b804436e33c71058cb38f178.tar.gz
emacs-2eb0b7835d1a9cd4b804436e33c71058cb38f178.zip
Fix shell-command-dont-erase-buffer feature
* lisp/simple.el (shell-command-dont-erase-buffer): The default, nil, is backward compatible, i.e. it erases the buffer only if the output buffer is not the current one; the new value 'erase always erases the output buffer. Update docstring. (shell-command-save-pos-or-erase): Add optional arg output-to-current-buffer. Rename it so that it's not internal. All callers updated. (shell-command-set-point-after-cmd): Rename it so that it's not internal. All callers updated. Adjust it to cover a side case. (shell-command): Adjust logic to match the specification (Bug#39067). Enable the feature when the output buffer is the current one. (shell-command-on-region): Little tweak to follow `shell-command-dont-erase-buffer' specification. * test/lisp/simple-tests.el (with-shell-command-dont-erase-buffer): Add helper macro. (simple-tests-shell-command-39067) (simple-tests-shell-command-dont-erase-buffer): Add tests. * doc/emacs/misc.texi (Single Shell): Update manual. * etc/NEWS (Single shell commands): Announce the change.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/simple-tests.el54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 2611519d074..0b12cee5855 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -711,5 +711,59 @@ See Bug#21722."
711 (when process (delete-process process)) 711 (when process (delete-process process))
712 (when buffer (kill-buffer buffer))))))) 712 (when buffer (kill-buffer buffer)))))))
713 713
714
715;;; Tests for shell-command-dont-erase-buffer
716
717(defmacro with-shell-command-dont-erase-buffer (str output-buffer-is-current &rest body)
718 (declare (debug (form &body)) (indent 2))
719 (let ((expected (make-symbol "expected"))
720 (command (make-symbol "command"))
721 (caller-buf (make-symbol "caller-buf"))
722 (output-buf (make-symbol "output-buf")))
723 `(let* ((,caller-buf (generate-new-buffer "caller-buf"))
724 (,output-buf (if ,output-buffer-is-current ,caller-buf
725 (generate-new-buffer "output-buf")))
726 (,command (format "%s --batch --eval '(princ \"%s\")'" invocation-name ,str))
727 (inhibit-message t))
728 (unwind-protect
729 ;; Feature must work the same regardless how we specify the 2nd arg of `shell-command', ie,
730 ;; as a buffer, buffer name (or t, if the output must go to the current buffer).
731 (dolist (output (append (list ,output-buf (buffer-name ,output-buf))
732 (if ,output-buffer-is-current '(t) nil)))
733 (dolist (save-pos '(erase nil beg-last-out end-last-out save-point))
734 (let ((shell-command-dont-erase-buffer save-pos))
735 (with-current-buffer ,output-buf (erase-buffer))
736 (with-current-buffer ,caller-buf
737 (dotimes (_ 2) (shell-command ,command output)))
738 (with-current-buffer ,output-buf
739 ,@body))))
740 (kill-buffer ,caller-buf)
741 (when (buffer-live-p ,output-buf)
742 (kill-buffer ,output-buf))))))
743
744(ert-deftest simple-tests-shell-command-39067 ()
745 "The output buffer is erased or not according to `shell-command-dont-erase-buffer'."
746 (let ((str "foo\n"))
747 (dolist (output-current '(t nil))
748 (with-shell-command-dont-erase-buffer str output-current
749 (let ((expected (cond ((eq shell-command-dont-erase-buffer 'erase) str)
750 ((null shell-command-dont-erase-buffer)
751 (if output-current (concat str str)
752 str))
753 (t (concat str str)))))
754 (should (string= expected (buffer-string))))))))
755
756(ert-deftest simple-tests-shell-command-dont-erase-buffer ()
757 "The point is set at the expected position after execution of the command."
758 (let* ((str "foo\n")
759 (expected-point `((beg-last-out . ,(1+ (length str)))
760 (end-last-out . ,(1+ (* 2 (length str))))
761 (save-point . 1))))
762 (dolist (output-buffer-is-current '(t ni))
763 (with-shell-command-dont-erase-buffer str output-buffer-is-current
764 (when (memq shell-command-dont-erase-buffer '(beg-last-out end-last-out save-point))
765 (should (= (point) (alist-get shell-command-dont-erase-buffer expected-point))))))))
766
767
714(provide 'simple-test) 768(provide 'simple-test)
715;;; simple-test.el ends here 769;;; simple-test.el ends here