]> git.eshelyaron.com Git - emacs.git/commitdiff
Preserve point under 'dired-auto-revert-buffer' (second case)
authorStephen Berman <stephen.berman@gmx.net>
Mon, 17 Jul 2017 09:09:07 +0000 (11:09 +0200)
committerStephen Berman <stephen.berman@gmx.net>
Mon, 17 Jul 2017 09:09:07 +0000 (11:09 +0200)
* 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.

lisp/dired.el
test/lisp/dired-tests.el

index 0c1f3e4af648aeb147e7c57be44482ebeac67e95..4fb4fe78f8991a3364cdc612d700b64c71bc2490 100644 (file)
@@ -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
index 208e1c25091b8e91db697d42d8727b15a8d5d792..87a83c4f86116f3151e1302da7af3676566bbb20 100644 (file)
       (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)