emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master b2150e0: Preserve point under 'dired-auto-revert-bu


From: Stephen Berman
Subject: [Emacs-diffs] master b2150e0: Preserve point under 'dired-auto-revert-buffer' (second case)
Date: Mon, 17 Jul 2017 05:17:01 -0400 (EDT)

branch: master
commit b2150e0b02fa4a7ad4c1461e0b4ff8fd632c0fb8
Author: Stephen Berman <address@hidden>
Commit: Stephen Berman <address@hidden>

    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.
---
 lisp/dired.el            |  2 +-
 test/lisp/dired-tests.el | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index 0c1f3e4..4fb4fe7 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 208e1c2..87a83c4 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]