From 194d54a929a83fede75d618b104acd1b544feb10 Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Fri, 4 Jun 2021 12:01:41 +0200 Subject: [PATCH] Fix placement of point in Dired deletion operations * 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 (bug#48805). --- lisp/dired.el | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/lisp/dired.el b/lisp/dired.el index 8527634760a..165484302a3 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -3280,15 +3280,19 @@ non-empty directories is allowed." (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 @@ non-empty directories is allowed." ;; 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 @@ non-empty directories is allowed." ;; 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 @@ non-empty directories is allowed." (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)))) -- 2.39.2