aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTino Calancha2017-08-06 13:05:16 +0900
committerTino Calancha2017-08-06 13:09:31 +0900
commit7c3593f81724d0c7a2ee2f90797db0e705adc859 (patch)
tree1c87dc10cc0ca3fd1cd7774bbf181eef782d1f8c /test
parent9b463fa8648b7baed95a44f4317cb7402fd8bf1c (diff)
downloademacs-7c3593f81724d0c7a2ee2f90797db0e705adc859.tar.gz
emacs-7c3593f81724d0c7a2ee2f90797db0e705adc859.zip
dired-revert: save line numbers instead of positions
Positions might change if the length of one dired header line changes; this happen, for instance, if we add new files. Instead, line numbers are invariant under shrinks/enlargements of the file header. https://lists.gnu.org/archive/html/emacs-devel/2017-07/msg01092.html * lisp/dired.el (dired-save-positions): Save the line numbers at point. (dired-restore-positions): Use forward-line to restore the original position (Bug#27968). * test/lisp/dired-tests.el (dired-test-bug27968): Add test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/dired-tests.el46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index b14bbc63609..105a79f0014 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -308,5 +308,51 @@
308 (should (eq 2 (current-column)))) 308 (should (eq 2 (current-column))))
309 (dired-hide-details-mode orig)))) 309 (dired-hide-details-mode orig))))
310 310
311(ert-deftest dired-test-bug27968 ()
312 "Test for http://debbugs.gnu.org/27968 ."
313 (let* ((top-dir (make-temp-file "top-dir" t))
314 (subdir (expand-file-name "subdir" top-dir))
315 (header-len-fn (lambda ()
316 (save-excursion
317 (goto-char 1)
318 (forward-line 1)
319 (- (point-at-eol) (point)))))
320 orig-len len diff pos line-nb)
321 (make-directory subdir 'parents)
322 (unwind-protect
323 (with-current-buffer (dired-noselect subdir)
324 (setq orig-len (funcall header-len-fn)
325 pos (point)
326 line-nb (line-number-at-pos))
327 ;; Bug arises when the header line changes its length; this may
328 ;; happen if the used space has changed: for instance, with the
329 ;; creation of additional files.
330 (make-directory "subdir" t)
331 (dired-revert)
332 ;; Change the header line.
333 (save-excursion
334 (goto-char 1)
335 (forward-line 1)
336 (let ((inhibit-read-only t))
337 (delete-region (point) (point-at-eol))
338 (insert " test-bug27968")))
339 (setq len (funcall header-len-fn)
340 diff (- len orig-len))
341 (should-not (zerop diff)) ; Header length has changed.
342 ;; If diff > 0, then the point moves back.
343 ;; If diff < 0, then the point moves forward.
344 ;; If diff = 0, then the point doesn't move.
345 ;; Sometimes this point movement causes
346 ;; line-nb != (line-number-at-pos pos), so that we get
347 ;; an unexpected file at point if we store buffer points.
348 ;; Note that the line number before/after revert
349 ;; doesn't change.
350 (should (= line-nb
351 (line-number-at-pos)
352 (line-number-at-pos (+ pos diff))))
353 ;; After revert, the point must be in 'subdir' line.
354 (should (equal "subdir" (dired-get-filename 'local t))))
355 (delete-directory top-dir t))))
356
311(provide 'dired-tests) 357(provide 'dired-tests)
312;; dired-tests.el ends here 358;; dired-tests.el ends here