From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#48805: 27.2; dired-mode moves point to wrong positions while deleting non-empty directories Date: Thu, 03 Jun 2021 23:52:40 +0200 Message-ID: <875yyuipjr.fsf@gmx.net> References: <868s3rv2h3.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15411"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 48805@debbugs.gnu.org To: ynyaaa@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 03 23:59:16 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lovMy-0003sT-Gf for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Jun 2021 23:59:16 +0200 Original-Received: from localhost ([::1]:60712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovMx-00088V-ID for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Jun 2021 17:59:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lovGw-0001AC-OT for bug-gnu-emacs@gnu.org; Thu, 03 Jun 2021 17:53:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33409) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lovGw-0008EO-Ef for bug-gnu-emacs@gnu.org; Thu, 03 Jun 2021 17:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lovGw-0006sT-Do for bug-gnu-emacs@gnu.org; Thu, 03 Jun 2021 17:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 03 Jun 2021 21:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48805 X-GNU-PR-Package: emacs Original-Received: via spool by 48805-submit@debbugs.gnu.org id=B48805.162275717026420 (code B ref 48805); Thu, 03 Jun 2021 21:53:02 +0000 Original-Received: (at 48805) by debbugs.gnu.org; 3 Jun 2021 21:52:50 +0000 Original-Received: from localhost ([127.0.0.1]:44955 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lovGk-0006s4-De for submit@debbugs.gnu.org; Thu, 03 Jun 2021 17:52:50 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:42525) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lovGi-0006rr-LQ for 48805@debbugs.gnu.org; Thu, 03 Jun 2021 17:52:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1622757161; bh=+lwNHYkCF5vrXGDZ7me/C2aFJCFRHF6Vbo0B0Kmwq6A=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=EtySgup+ynn6rbI1cTnPtkwP/kWl52b0znSzrMiSuqSw1Dhtm9AsQtgL5it6mONSF eQP2/knR4Cbx6xcxwhI9XUnCQz59Nz9r40R8YltmmIIRR4cCGnId/DYk6I7pbSY0Cx T4+DmOzO6f8Bt5U6g+wy94BhhY0PFdc7oxx79/rA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from strobe-jhalfs ([94.220.124.191]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MyKDe-1lRtjx223g-00yeM5; Thu, 03 Jun 2021 23:52:41 +0200 In-Reply-To: <868s3rv2h3.fsf@gmail.com> (ynyaaa@gmail.com's message of "Thu, 03 Jun 2021 16:20:24 +0900") X-Provags-ID: V03:K1:LsjdxAaHrkiz7u6x2BBGHyoUoJKRVQ/Aujoo/GTs9z/z3vS3dsQ VBRQ1X7veSuNMo8N6Z7gxxPBV6Bcqf4pJNhPlo/3fncfaRaljWdMreioSeytzKuIQJdY5VU qUw6ZH9URGk8FRV/MJH0GPCXI9livLBeoNc63TSttzHcur0O6IGMrzKbIzd74vIDLRTJMX/ lQtJRTjLPmgVlznV/vrdw== X-UI-Out-Filterresults: notjunk:1;V03:K0:CawLzskPW3k=:CeTEAXWryNngsYoqGLj0l9 IlYgEssNvplluqyYoJ/VP9cS/QCp0zCWPHVoMKtKh2DMd5ZCZ9hhyRvVZsqFFqi0LAX1k/gCf BCO/0wxNcLp3v1c6PpvUD/DkCTkvQaRTUE71jQA2Q7lhId+W7d5cnuEhiReHm7sCyiQsUNp89 GXUHqjqt2GomngPegpeGPe2haJ139zyLlzipFRiWGT1m+Ww+R97FDd7HEjcIXh4wi0hA7UONj 8Zo0IhtaD9fVrOpv/jRU3xr48DvmMHPd9u6JgrvCZL8DpGf01UZ+1EMvMR7fZMSSEX4Xxd3TD wtqeMl2ygzn6G1nVMUoWNW0PPWHsWKIqubA4M8EMcqSK+k87q21ONUK5yDlT2dAaH5KrR8fpf FHdS6JvWaDdEVrCMh1jbaG0/tdc3FwtUT7MtKTVYhO1DXC27HqIlFGCFGsHCrt2i8zEKl3ymO HfS6/F0H7L9a/9Npqyy7Ke00aMMzH+lIIrtJE1Yl5uXpNgqAhtWZnkil3nqs1z/KzeSyVB+wO Anbzjx/kS1QdIyBpztLNALYFZwRZMmCyALO7JVye3/O0XCDsUp3Xdc1rwi8o2MJTVhD0//9nI gf1gi/Kh/Wvc9dMaJLNR3PRbneq6rlUnd5GqXkuP557Lx917M5QlmkFReFBnoT6hU7X5OT7+8 LB5xXspY90QdmWJX08XX9+xvxo6M42m5Co+xxLu8YbsOYAwsGn84ZiJGp5wfah1k/BG9ovCLG 0m5z4JwN7EJuMrpuGn7rG+gR4xPJNuEJP6RtLr3gvHDtInnc5WGg60c4wt/IsN7RFH2niLF0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:207973 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, 03 Jun 2021 16:20:24 +0900 ynyaaa@gmail.com wrote: > The form below creates a working directory and generate many non-empty > directories under the working directory, then displaye the working > directory in a dired-mode buffer. > (let ((dir (make-temp-file "dir" t))) > (dotimes (i 100) > (let ((d (expand-file-name (format "d%03d" i) dir))) > (make-directory d) > (write-region "" nil (expand-file-name "file" d)) > )) > (dired dir)) > Mark all subdirectories to be deleted with typing 'C-u 100 d'. > Tell emacs to delete all marked directories with typing 'x'. > Emacs asks 'Delete D [100 files] (yes or no) ', and answer yes. > Then emacs asks like 'Recursively delete d000? (yes, no, all, quit, help= ) ' > for each directory, and answer yes for each confirmation. > While these confirmations, emacs tries to move point to the 'D' marker o= f > the line of the asked directory. > But the real position of the point is different from the line. > Perhaps because the goal point value is changed with the deletion of the > lines of the directories which has been deleted. This bug was introduced by this commit: commit 9ecbdeeaa845a75c63210057a8a554eedc9387bf Author: Tino Calancha Commit: Tino Calancha CommitDate: Wed Aug 9 14:37:21 2017 +0900 Ask files for deletion in buffer order: top first, botton later * lisp/dired.el (dired-do-flagged-delete, dired-do-delete): Call `nreverse' t invert the output of `dired-map-over-marks'. In effect, this countermanded the requirement stated by this comment in dired-internal-do-deletions: ;; L is an alist of files to delete, with their buffer positions. [...] ;; (car L) *must* be the *last* (bottommost) file in the dired buffer. ;; That way as changes are made in the buffer they do not shift the ;; lines still to be changed, so the (point) values in L stay valid. ;; Also, for subdirs in natural order, a subdir's files are deleted ;; before the subdir itself - the other way around would not work. However, the last sentence of this comment was made obsolete by commit f06280268, which allows deleting non-empty directories. And since the motivation for commit 9ecbdeeaa seems reasonable, it seems best not to rely on buffer positions but instead to use markers. The attached patch does this, and that fixes the bug reported above AFAICT. (If an accumulation of markers is not a concern here, the patch could be simplified.) (Commit a84c3810b, which fixed another regression due to commit 9ecbdeeaa but did not address the problem reported in this bug, is left intact by the patch.) > Also, I think the point should be moved to the directory name, not marke= r. > Directory names are much more important than marker types and there is a > long distance between the marker and the name. That seems like a reasonable request, and the attached patch implements it too. (A further development of this could be to highlight the file name when prompting for whether to delete it, making it even more obvious which file is meant. But maybe that's overengineering.) 2021-06-03 Stephen Berman Fix placement of point in Dired deletion operations (bug#48805) * lisp/dired.el (dired-do-flagged-delete, dired-do-delete): Use point-marker instead of point to record each file name position. Clean up the markers before returning. (dired-internal-do-deletions): Move to the file name marker, and then move point to the file name to visually emphasize which file is being operated on. --=-=-= Content-Type: text/x-patch Content-Disposition: inline Content-Description: bug#48805 patch Content-Transfer-Encoding: quoted-printable diff --git a/lisp/dired.el b/lisp/dired.el index 8527634760..165484302a 100644 =2D-- a/lisp/dired.el +++ b/lisp/dired.el @@ -3280,15 +3280,19 @@ dired-do-flagged-delete (interactive) (let* ((dired-marker-char dired-del-marker) (regexp (dired-marker-regexp)) - case-fold-search) + case-fold-search markers) (if (save-excursion (goto-char (point-min)) (re-search-forward regexp nil t)) (dired-internal-do-deletions (nreverse ;; this can't move point since ARG is nil - (dired-map-over-marks (cons (dired-get-filename) (point)) + (dired-map-over-marks (cons (dired-get-filename) + (let ((m (point-marker))) + (push m markers) + m)) nil)) nil t) + (dolist (m markers) (set-marker m nil)) (or nomessage (message "(No deletions requested)"))))) @@ -3299,12 +3303,17 @@ dired-do-delete ;; This is more consistent with the file marking feature than ;; dired-do-flagged-delete. (interactive "P") - (dired-internal-do-deletions - (nreverse - ;; this may move point if ARG is an integer - (dired-map-over-marks (cons (dired-get-filename) (point)) - arg)) - arg t)) + (let (markers) + (dired-internal-do-deletions + (nreverse + ;; this may move point if ARG is an integer + (dired-map-over-marks (cons (dired-get-filename) + (let ((m (point-marker))) + (push m markers) + m)) + arg)) + arg t) + (dolist (m markers) (set-marker m nil)))) (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p? @@ -3312,11 +3321,6 @@ dired-internal-do-deletions ;; L is an alist of files to delete, with their buffer positions. ;; ARG is the prefix arg. ;; Filenames are absolute. - ;; (car L) *must* be the *last* (bottommost) file in the dired buffer. - ;; That way as changes are made in the buffer they do not shift the - ;; lines still to be changed, so the (point) values in L stay valid. - ;; Also, for subdirs in natural order, a subdir's files are deleted - ;; before the subdir itself - the other way around would not work. (let* ((files (mapcar #'car l)) (count (length l)) (succ 0) @@ -3337,9 +3341,10 @@ dired-internal-do-deletions (make-progress-reporter (if trashing "Trashing..." "Deleting...") succ count)) - failures) ;; files better be in reverse order for this loop! + failures) (while l - (goto-char (cdr (car l))) + (goto-char (marker-position (cdr (car l)))) + (dired-move-to-filename) (let ((inhibit-read-only t)) (condition-case err (let ((fn (car (car l)))) --=-=-=--