From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#27968: 26.0.50; dired-revert: Saved positions might change if a dired header changes Date: Sat, 05 Aug 2017 22:01:34 +0900 Message-ID: <87bmnu6udt.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1501938142 8044 195.159.176.226 (5 Aug 2017 13:02:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 5 Aug 2017 13:02:22 +0000 (UTC) Cc: stephen berman To: 27968@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 05 15:02:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddyiW-0001Bu-DN for geb-bug-gnu-emacs@m.gmane.org; Sat, 05 Aug 2017 15:02:08 +0200 Original-Received: from localhost ([::1]:56779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddyia-0000Rb-PN for geb-bug-gnu-emacs@m.gmane.org; Sat, 05 Aug 2017 09:02:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddyiU-0000RM-7A for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2017 09:02:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddyiR-0001Ha-2S for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2017 09:02:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39946) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddyiQ-0001HN-V0 for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2017 09:02:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ddyiQ-0004Fc-8f; Sat, 05 Aug 2017 09:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: stephen.berman@gmx.net, bug-gnu-emacs@gnu.org Resent-Date: Sat, 05 Aug 2017 13:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27968 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: stephen berman Original-Received: via spool by submit@debbugs.gnu.org id=B.150193811616326 (code B ref -1); Sat, 05 Aug 2017 13:02:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Aug 2017 13:01:56 +0000 Original-Received: from localhost ([127.0.0.1]:42622 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddyiK-0004FG-Bv for submit@debbugs.gnu.org; Sat, 05 Aug 2017 09:01:56 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:41691) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddyiI-0004F2-2I for submit@debbugs.gnu.org; Sat, 05 Aug 2017 09:01:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddyiB-000187-E0 for submit@debbugs.gnu.org; Sat, 05 Aug 2017 09:01:48 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:41782) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddyiB-000182-Ay for submit@debbugs.gnu.org; Sat, 05 Aug 2017 09:01:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddyi9-0000DY-6g for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2017 09:01:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddyi6-00014d-4g for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2017 09:01:45 -0400 Original-Received: from mail-pf0-x233.google.com ([2607:f8b0:400e:c00::233]:34781) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddyi5-00012R-RL for bug-gnu-emacs@gnu.org; Sat, 05 Aug 2017 09:01:42 -0400 Original-Received: by mail-pf0-x233.google.com with SMTP id o86so17762773pfj.1 for ; Sat, 05 Aug 2017 06:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=ey+IHJ4/9cKOGfHQb5wbSk8Skfq6EKI4JP7GHcuA1WM=; b=V7OndwqXqfXCIqvV0Hny6fQMeK7n+DFXUMfkH5Uj8DPpY+3DkDppyr+PUpNCEqXIyj MGONXjShrW5Cfq0K+zHD/csYAIOHLRWkJQKKaLpHruYEKWfNSmEuSQB2fIq7q9yru3+b geJ/VXdC0GQsWGQWqgrX/rl1GCu7OLOPQDg0lavrOaPZ0ezlA359subvO9h4KY6G8W04 SLsv12aZEkJ0D45PnobyNyKlUcwHBPbUS42VYD4rSQhGF+U684qCkrUe/iwJN6VSpNoa QAc16FcWJIdQ+eU7TZiARZGFSAgW+ZyIkzVCw4g33Ft6wOsrdykgvmLisN2U/jejVhed VMcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=ey+IHJ4/9cKOGfHQb5wbSk8Skfq6EKI4JP7GHcuA1WM=; b=ZMRZfBVgTzecpDKOVpZ+P5x/E9r5VE9O7euoBy1ao7Y3PfvNMzU+gDj65y/Cd1Lehb Mocr9uxFUAbpJWyG6QexuZ28MOnXiIUnbl4h2h/HLEmeVgh1P4wEuXpbffI/ZulE9hIx b0p/Xr6//D9EUpejKVPv0b0zO2qx4sxN70MtJAKkiTUoAeG8BS6oBz/7eZZ9zlv1x8m4 cfGFMXRpy/PlCnyd/8TOuoA1Sx91/UBnqTqLCodWY4X0jBY4ePDB7wN+IhdbcDPrquAc LGJ9a9ISnRyexxnmB6EdnShNzVmHGHrCUWGDgxA/welHltLqlsavvrTuTBCOhAOF0PiQ bDag== X-Gm-Message-State: AIVw113aQXBrR2usLp3Dobq5UkUPbTR5Dm97K1hkygiuTUkNC6t0tZRf tPXEq7taWVcc0Wbg X-Received: by 10.99.7.131 with SMTP id 125mr5451317pgh.136.1501938098816; Sat, 05 Aug 2017 06:01:38 -0700 (PDT) Original-Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id l2sm7314677pgc.27.2017.08.05.06.01.37 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2017 06:01:38 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:135426 Archived-At: X-Debbugs-CC: Stephen Berman Tag: patch Dired headers also changes; if you add/deleted some files, the used space shown changes: that will mess up the saved buffer positions if the length of the header is different. This problem causes dired-test-bug27243-01 to fail in hydra. One possible solution is the patch below. It saves line numbers instead of positions. Line numbers won't change if a dired header changes its length. --8<-----------------------------cut here---------------start------------->8--- commit a6799f27a9d18618f3046a1db7ffebc480310e8f Author: Tino Calancha Date: Sat Aug 5 21:59:06 2017 +0900 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. 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. diff --git a/lisp/dired.el b/lisp/dired.el index 24759c6c9b..d04bd6fe03 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1444,18 +1444,22 @@ dired-save-positions The positions have the form (BUFFER-POSITION WINDOW-POSITIONS). BUFFER-POSITION is the point position in the current Dired buffer. -It has the form (BUFFER DIRED-FILENAME BUFFER-POINT). +It has the form (BUFFER DIRED-FILENAME BUFFER-LINE-NUMBER). WINDOW-POSITIONS are current positions in all windows displaying this dired buffer. The window positions have the form (WINDOW -DIRED-FILENAME WINDOW-POINT)." +DIRED-FILENAME WINDOW-LINE-NUMBER). + +We store line numbers instead of point positions because the header +lines might change as well: when this happen the line number doesn't +change; the point does." (list - (list (current-buffer) (dired-get-filename nil t) (point)) + (list (current-buffer) (dired-get-filename nil t) (line-number-at-pos)) (mapcar (lambda (w) - (list w - (with-selected-window w - (dired-get-filename nil t)) - (window-point w))) + (with-selected-window w + (list w + (dired-get-filename nil t) + (line-number-at-pos (window-point w))))) (get-buffer-window-list nil 0 t)))) (defun dired-restore-positions (positions) @@ -1464,7 +1468,8 @@ dired-restore-positions (buffer (nth 0 buf-file-pos))) (unless (and (nth 1 buf-file-pos) (dired-goto-file (nth 1 buf-file-pos))) - (goto-char (nth 2 buf-file-pos)) + (goto-char (point-min)) + (forward-line (1- (nth 2 buf-file-pos))) (dired-move-to-filename)) (dolist (win-file-pos (nth 1 positions)) ;; Ensure that window still displays the original buffer. @@ -1472,7 +1477,8 @@ dired-restore-positions (with-selected-window (nth 0 win-file-pos) (unless (and (nth 1 win-file-pos) (dired-goto-file (nth 1 win-file-pos))) - (goto-char (nth 2 win-file-pos)) + (goto-char (point-min)) + (forward-line (1- (nth 2 win-file-pos))) (dired-move-to-filename))))))) (defun dired-remember-marks (beg end) diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el index b14bbc6360..4bbf72ab74 100644 --- a/test/lisp/dired-tests.el +++ b/test/lisp/dired-tests.el @@ -308,5 +308,44 @@ dired-dwim-target (should (eq 2 (current-column)))) (dired-hide-details-mode orig)))) +(ert-deftest dired-test-bug27968 () + (let* ((top-dir (make-temp-file "top-dir" t)) + (subdir (expand-file-name "subdir" top-dir)) + (header-len-fn (lambda () + (save-excursion + (goto-char 1) + (forward-line 1) + (- (point-at-eol) (point))))) + orig-len len diff pos) + (make-directory subdir 'parents) + (unwind-protect + (with-current-buffer (dired-noselect subdir) + (setq orig-len (funcall header-len-fn) + pos (point)) + ;; Bug arises when the header line changes its length; this may + ;; happen if the used space has changed: for instance, with the + ;; creation of additional files. + (make-directory "subdir" t) + (dired-revert) + ;; Change the header line. + (save-excursion + (goto-char 1) + (forward-line 1) + (let ((inhibit-read-only t)) + (delete-region (point) (point-at-eol)) + (insert " test-bug27968"))) + (setq len (funcall header-len-fn) + diff (- len orig-len)) + (should-not (zerop diff)) ; Header length has changed. + ;; If diff > 0, then the point moves back. + ;; If diff < 0, then the point moves forward. + ;; If diff = 0, then the point doesn't move. + ;; We correct `point' with diff to obtain the right line number. + (should (equal (line-number-at-pos (+ (point) diff)) + (line-number-at-pos pos))) + ;; After revert, the point must be in 'subdir' line. + (should (equal "subdir" (dired-get-filename nil t)))) + (delete-directory top-dir t)))) + (provide 'dired-tests) ;; dired-tests.el ends here --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-08-05 built on calancha-pc Repository revision: 1d51b265075ea9852dab678071b0e400a2c36ae7 Windowing system distributor 'The X.Org Foundation', version 11.0.11902000 System Description: Debian GNU/Linux 9.1 (stretch)