aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2017-07-29 13:34:47 +0200
committerStephen Berman2017-07-29 13:34:47 +0200
commit8e394b082bd6ecd9ba212cb3ca07cbace66767a6 (patch)
tree4782f5d9fb8b3143acd57ccf9de78f633c6c94f6
parentdfee60fe66f3d9fe4249c9662d802753f3e50929 (diff)
downloademacs-8e394b082bd6ecd9ba212cb3ca07cbace66767a6.tar.gz
emacs-8e394b082bd6ecd9ba212cb3ca07cbace66767a6.zip
Preserve point under 'dired-auto-revert-buffer' (third case)
* lisp/files.el (find-file): 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-01) (dired-test-bug27243-02, dired-test-bug27243-03): New tests. The first two replace a previous test that combined them; that test intermittently fails in the Hydra build system, so maybe separating the two cases will help locate the point of failure. The third test involves find-file but is here because it, like the others, is testing the effect of dired-auto-revert-buffer.
-rw-r--r--lisp/files.el4
-rw-r--r--test/lisp/dired-tests.el99
2 files changed, 96 insertions, 7 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 6d9957d494a..6ce2fe98b05 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1599,8 +1599,8 @@ automatically choosing a major mode, use \\[find-file-literally]."
1599 (confirm-nonexistent-file-or-buffer))) 1599 (confirm-nonexistent-file-or-buffer)))
1600 (let ((value (find-file-noselect filename nil nil wildcards))) 1600 (let ((value (find-file-noselect filename nil nil wildcards)))
1601 (if (listp value) 1601 (if (listp value)
1602 (mapcar 'switch-to-buffer (nreverse value)) 1602 (mapcar 'pop-to-buffer-same-window (nreverse value))
1603 (switch-to-buffer value)))) 1603 (pop-to-buffer-same-window value))))
1604 1604
1605(defun find-file-other-window (filename &optional wildcards) 1605(defun find-file-other-window (filename &optional wildcards)
1606 "Edit file FILENAME, in another window. 1606 "Edit file FILENAME, in another window.
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index 601d65768bd..43a21e1accb 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -89,8 +89,40 @@
89 (advice-remove 'dired-query "advice-dired-query") 89 (advice-remove 'dired-query "advice-dired-query")
90 (advice-remove 'completing-read "advice-completing-read")))) 90 (advice-remove 'completing-read "advice-completing-read"))))
91 91
92(ert-deftest dired-test-bug27243 () 92;; (ert-deftest dired-test-bug27243 ()
93 "Test for http://debbugs.gnu.org/27243 ." 93;; "Test for http://debbugs.gnu.org/27243 ."
94;; (let ((test-dir (make-temp-file "test-dir-" t))
95;; (dired-auto-revert-buffer t) buffers)
96;; (with-current-buffer (find-file-noselect test-dir)
97;; (make-directory "test-subdir"))
98;; (push (dired test-dir) buffers)
99;; (unwind-protect
100;; (let ((buf (current-buffer))
101;; (pt1 (point))
102;; (test-file (concat (file-name-as-directory "test-subdir")
103;; "test-file")))
104;; (write-region "Test" nil test-file nil 'silent nil 'excl)
105;; ;; Sanity check: point should now be on the subdirectory.
106;; (should (equal (dired-file-name-at-point)
107;; (concat (file-name-as-directory test-dir)
108;; (file-name-as-directory "test-subdir"))))
109;; (push (dired-find-file) buffers)
110;; (let ((pt2 (point))) ; Point is on test-file.
111;; (switch-to-buffer buf)
112;; ;; Sanity check: point should now be back on the subdirectory.
113;; (should (eq (point) pt1))
114;; ;; Case 1: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#5
115;; (push (dired-find-file) buffers)
116;; (should (eq (point) pt2))
117;; ;; Case 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#28
118;; (push (dired test-dir) buffers)
119;; (should (eq (point) pt1))))
120;; (dolist (buf buffers)
121;; (when (buffer-live-p buf) (kill-buffer buf)))
122;; (delete-directory test-dir t))))
123
124(ert-deftest dired-test-bug27243-01 ()
125 "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#5 ."
94 (let ((test-dir (make-temp-file "test-dir-" t)) 126 (let ((test-dir (make-temp-file "test-dir-" t))
95 (dired-auto-revert-buffer t) buffers) 127 (dired-auto-revert-buffer t) buffers)
96 (with-current-buffer (find-file-noselect test-dir) 128 (with-current-buffer (find-file-noselect test-dir)
@@ -111,16 +143,73 @@
111 (switch-to-buffer buf) 143 (switch-to-buffer buf)
112 ;; Sanity check: point should now be back on the subdirectory. 144 ;; Sanity check: point should now be back on the subdirectory.
113 (should (eq (point) pt1)) 145 (should (eq (point) pt1))
114 ;; Case 1: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#5
115 (push (dired-find-file) buffers) 146 (push (dired-find-file) buffers)
116 (should (eq (point) pt2)) 147 (should (eq (point) pt2))))
117 ;; Case 2: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#28 148 (dolist (buf buffers)
149 (when (buffer-live-p buf) (kill-buffer buf)))
150 (delete-directory test-dir t))))
151
152(ert-deftest dired-test-bug27243-02 ()
153 "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#28 ."
154 (let ((test-dir (make-temp-file "test-dir-" t))
155 (dired-auto-revert-buffer t) buffers)
156 (with-current-buffer (find-file-noselect test-dir)
157 (make-directory "test-subdir"))
158 (push (dired test-dir) buffers)
159 (unwind-protect
160 (let ((buf (current-buffer))
161 (pt1 (point))
162 (test-file (concat (file-name-as-directory "test-subdir")
163 "test-file")))
164 (write-region "Test" nil test-file nil 'silent nil 'excl)
165 ;; Sanity check: point should now be on the subdirectory.
166 (should (equal (dired-file-name-at-point)
167 (concat (file-name-as-directory test-dir)
168 (file-name-as-directory "test-subdir"))))
169 (push (dired-find-file) buffers)
170 (let ((pt2 (point))) ; Point is on test-file.
171 (switch-to-buffer buf)
172 ;; Sanity check: point should now be back on the subdirectory.
173 (should (eq (point) pt1))
118 (push (dired test-dir) buffers) 174 (push (dired test-dir) buffers)
119 (should (eq (point) pt1)))) 175 (should (eq (point) pt1))))
120 (dolist (buf buffers) 176 (dolist (buf buffers)
121 (when (buffer-live-p buf) (kill-buffer buf))) 177 (when (buffer-live-p buf) (kill-buffer buf)))
122 (delete-directory test-dir t)))) 178 (delete-directory test-dir t))))
123 179
180(ert-deftest dired-test-bug27243-03 ()
181 "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#61 ."
182 (let ((test-dir (make-temp-file "test-dir-" t))
183 (dired-auto-revert-buffer t)
184 test-subdir1 test-subdir2 allbufs)
185 (unwind-protect
186 (progn
187 (with-current-buffer (find-file-noselect test-dir)
188 (push (current-buffer) allbufs)
189 (make-directory "test-subdir1")
190 (make-directory "test-subdir2")
191 (let ((test-file1 "test-file1")
192 (test-file2 "test-file2"))
193 (with-current-buffer (find-file-noselect "test-subdir1")
194 (push (current-buffer) allbufs)
195 (write-region "Test1" nil test-file1 nil 'silent nil 'excl))
196 (with-current-buffer (find-file-noselect "test-subdir2")
197 (push (current-buffer) allbufs)
198 (write-region "Test2" nil test-file2 nil 'silent nil 'excl))))
199 ;; Call find-file with a wild card and test point in each file.
200 (let ((buffers (find-file (concat (file-name-as-directory test-dir)
201 "*")
202 t)))
203 (dolist (buf buffers)
204 (let ((pt (with-current-buffer buf (point))))
205 (switch-to-buffer (find-file-noselect test-dir))
206 (find-file (buffer-name buf))
207 (should (equal (point) pt))))
208 (append buffers allbufs)))
209 (dolist (buf allbufs)
210 (when (buffer-live-p buf) (kill-buffer buf)))
211 (delete-directory test-dir t))))
212
124(ert-deftest dired-test-bug27693 () 213(ert-deftest dired-test-bug27693 ()
125 "Test for http://debbugs.gnu.org/27693 ." 214 "Test for http://debbugs.gnu.org/27693 ."
126 (let ((dir (expand-file-name "lisp" source-directory)) 215 (let ((dir (expand-file-name "lisp" source-directory))