From: Stephen Berman Date: Mon, 17 Jul 2017 09:09:07 +0000 (+0200) Subject: Preserve point under 'dired-auto-revert-buffer' (second case) X-Git-Tag: emacs-26.0.90~518^2~80 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b2150e0b02fa4a7ad4c1461e0b4ff8fd632c0fb8;p=emacs.git Preserve point under 'dired-auto-revert-buffer' (second case) * lisp/dired.el (dired): Use pop-to-buffer-same-window instead of switch-to-buffer. This preserves Dired window point when dired-auto-revert-buffer is non-nil. (Bug#27243) * test/lisp/dired-tests.el (dired-test-bug27243): New test. --- diff --git a/lisp/dired.el b/lisp/dired.el index 0c1f3e4af64..4fb4fe78f89 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -785,7 +785,7 @@ Type \\[describe-mode] after entering Dired for more info. If DIRNAME is already in a Dired buffer, that buffer is used without refresh." ;; Cannot use (interactive "D") because of wildcards. (interactive (dired-read-dir-and-switches "")) - (switch-to-buffer (dired-noselect dirname switches))) + (pop-to-buffer-same-window (dired-noselect dirname switches))) ;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window) ;;;###autoload diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el index 208e1c25091..87a83c4f861 100644 --- a/test/lisp/dired-tests.el +++ b/test/lisp/dired-tests.el @@ -84,6 +84,36 @@ (advice-remove 'dired-query "advice-dired-query") (advice-remove 'completing-read "advice-completing-read")))) +(ert-deftest dired-test-bug27243 () + "Test for http://debbugs.gnu.org/27243 ." + (let ((test-dir (make-temp-file "test-dir-" t)) + (dired-auto-revert-buffer t)) + (with-current-buffer (find-file-noselect test-dir) + (make-directory "test-subdir")) + (dired test-dir) + (unwind-protect + (let ((buf (current-buffer)) + (pt1 (point)) + (test-file (concat (file-name-as-directory "test-subdir") + "test-file"))) + (write-region "Test" nil test-file nil 'silent nil 'excl) + ;; Sanity check: point should now be on the subdirectory. + (should (equal (dired-file-name-at-point) + (concat (file-name-as-directory test-dir) + (file-name-as-directory "test-subdir")))) + (dired-find-file) + (let ((pt2 (point))) ; Point is on test-file. + (switch-to-buffer buf) + ;; Sanity check: point should now be back on the subdirectory. + (should (eq (point) pt1)) + ;; Case 1: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#5 + (dired-find-file) + (should (eq (point) pt2)) + ;; Case 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#28 + (dired test-dir) + (should (eq (point) pt1)))) + (delete-directory test-dir t)))) + (ert-deftest dired-test-bug27693 () "Test for http://debbugs.gnu.org/27693 ." (require 'ls-lisp)