aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/dired.el
diff options
context:
space:
mode:
authorMichael Albinus2025-02-04 14:09:52 +0100
committerMichael Albinus2025-02-04 14:09:52 +0100
commit9597881592049509d62f91139316ac0eba2fb19d (patch)
tree9eefe5fb39c5a42ee4bc54945b983882b34aaa00 /lisp/dired.el
parent40e38a681dafb02f71d741338e9c3c5ff99c734e (diff)
downloademacs-9597881592049509d62f91139316ac0eba2fb19d.tar.gz
emacs-9597881592049509d62f91139316ac0eba2fb19d.zip
Add inhibit-auto-revert macro
* doc/lispref/backups.texi (Reverting): Add inhibit-auto-revert-buffers and inhibit-auto-revert. * etc/NEWS: Add inhibit-auto-revert-buffers and inhibit-auto-revert. Fix typos. * lisp/autorevert.el (inhibit-auto-revert-buffers): New variable. (inhibit-auto-revert): New macro. (auto-revert-active-p, auto-revert-handler): Check `inhibit-auto-revert-buffers'. * lisp/dired.el (dired--inhibit-auto-revert): Remove. (dired-buffer-stale-p): Don't set it. (dired-map-over-marks, dired-internal-do-deletions): Use `inhibit-auto-revert. * test/lisp/autorevert-tests.el (auto-revert-test08-auto-revert-inhibit-auto-revert) (auto-revert-test08-auto-revert-inhibit-auto-revert-remote): New tests.
Diffstat (limited to 'lisp/dired.el')
-rw-r--r--lisp/dired.el133
1 files changed, 62 insertions, 71 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index 2eb6546107a..91163186443 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -944,9 +944,6 @@ Return value is the number of files marked, or nil if none were marked."
944 "")))) 944 ""))))
945 (and (> count 0) count))) 945 (and (> count 0) count)))
946 946
947(defvar-local dired--inhibit-auto-revert nil
948 "A non-nil value prevents `auto-revert-mode' from reverting the buffer.")
949
950(defmacro dired-map-over-marks (body arg &optional show-progress 947(defmacro dired-map-over-marks (body arg &optional show-progress
951 distinguish-one-marked) 948 distinguish-one-marked)
952 "Eval BODY with point on each marked line. Return a list of BODY's results. 949 "Eval BODY with point on each marked line. Return a list of BODY's results.
@@ -983,48 +980,48 @@ marked file, return (t FILENAME) instead of (FILENAME)."
983 ;;endless loop. 980 ;;endless loop.
984 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10. 981 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
985 `(prog1 982 `(prog1
986 (let ((dired--inhibit-auto-revert t) 983 (inhibit-auto-revert
987 (inhibit-read-only t) 984 (let ((inhibit-read-only t)
988 case-fold-search found results) 985 case-fold-search found results)
989 (if (and ,arg (not (eq ,arg 'marked))) 986 (if (and ,arg (not (eq ,arg 'marked)))
990 (if (integerp ,arg) 987 (if (integerp ,arg)
991 (progn ;; no save-excursion, want to move point. 988 (progn ;; no save-excursion, want to move point.
992 (dired-repeat-over-lines 989 (dired-repeat-over-lines
993 ,arg 990 ,arg
994 (lambda () 991 (lambda ()
995 (if ,show-progress (sit-for 0)) 992 (if ,show-progress (sit-for 0))
996 (setq results (cons ,body results)))) 993 (setq results (cons ,body results))))
997 (when (< ,arg 0) 994 (when (< ,arg 0)
998 (setq results (nreverse results))) 995 (setq results (nreverse results)))
999 results) 996 results)
1000 ;; non-nil, non-integer, non-marked ARG means use current file: 997 ;; non-nil, non-integer, non-marked ARG means use current file:
1001 (list ,body)) 998 (list ,body))
1002 (let ((regexp (dired-marker-regexp)) next-position) 999 (let ((regexp (dired-marker-regexp)) next-position)
1003 (save-excursion 1000 (save-excursion
1004 (goto-char (point-min)) 1001 (goto-char (point-min))
1005 ;; remember position of next marked file before BODY 1002 ;; remember position of next marked file before BODY
1006 ;; can insert lines before the just found file, 1003 ;; can insert lines before the just found file,
1007 ;; confusing us by finding the same marked file again 1004 ;; confusing us by finding the same marked file again
1008 ;; and again and... 1005 ;; and again and...
1009 (setq next-position (and (re-search-forward regexp nil t) 1006 (setq next-position (and (re-search-forward regexp nil t)
1010 (point-marker)) 1007 (point-marker))
1011 found (not (null next-position))) 1008 found (not (null next-position)))
1012 (while next-position 1009 (while next-position
1013 (goto-char next-position) 1010 (goto-char next-position)
1014 (if ,show-progress (sit-for 0)) 1011 (if ,show-progress (sit-for 0))
1015 (setq results (cons ,body results)) 1012 (setq results (cons ,body results))
1016 ;; move after last match 1013 ;; move after last match
1017 (goto-char next-position) 1014 (goto-char next-position)
1018 (forward-line 1) 1015 (forward-line 1)
1019 (set-marker next-position nil) 1016 (set-marker next-position nil)
1020 (setq next-position (and (re-search-forward regexp nil t) 1017 (setq next-position (and (re-search-forward regexp nil t)
1021 (point-marker))))) 1018 (point-marker)))))
1022 (if (and ,distinguish-one-marked (= (length results) 1)) 1019 (if (and ,distinguish-one-marked (= (length results) 1))
1023 (setq results (cons t results))) 1020 (setq results (cons t results)))
1024 (if found 1021 (if found
1025 results 1022 results
1026 (unless (eq ,arg 'marked) 1023 (unless (eq ,arg 'marked)
1027 (list ,body)))))) 1024 (list ,body)))))))
1028 ;; save-excursion loses, again 1025 ;; save-excursion loses, again
1029 (dired-move-to-filename))) 1026 (dired-move-to-filename)))
1030 1027
@@ -1294,12 +1291,6 @@ This feature is used by Auto Revert mode."
1294 ;; Do not auto-revert when the dired buffer can be currently 1291 ;; Do not auto-revert when the dired buffer can be currently
1295 ;; written by the user as in `wdired-mode'. 1292 ;; written by the user as in `wdired-mode'.
1296 buffer-read-only 1293 buffer-read-only
1297 ;; When a dired operation using dired-map-over-marks is in
1298 ;; progress, dired--inhibit-auto-revert is bound to some
1299 ;; non-nil value and we must not auto-revert because that could
1300 ;; change the order of files leading to skipping or
1301 ;; double-processing (see bug#75626).
1302 (not dired--inhibit-auto-revert)
1303 (dired-directory-changed-p dirname)))) 1294 (dired-directory-changed-p dirname))))
1304 1295
1305(defcustom dired-auto-revert-buffer nil 1296(defcustom dired-auto-revert-buffer nil
@@ -4089,26 +4080,26 @@ non-empty directories is allowed."
4089 (while l 4080 (while l
4090 (goto-char (marker-position (cdr (car l)))) 4081 (goto-char (marker-position (cdr (car l))))
4091 (dired-move-to-filename) 4082 (dired-move-to-filename)
4092 (let ((inhibit-read-only t) 4083 ;; Temporarily prevent auto-revert while deleting entry in
4093 ;; Temporarily prevent auto-revert while deleting 4084 ;; the dired buffer (bug#71264).
4094 ;; entry in the dired buffer (bug#71264). 4085 (inhibit-auto-revert
4095 (dired--inhibit-auto-revert t)) 4086 (let ((inhibit-read-only t))
4096 (condition-case err 4087 (condition-case err
4097 (let ((fn (car (car l)))) 4088 (let ((fn (car (car l))))
4098 (dired-delete-file fn dired-recursive-deletes trash) 4089 (dired-delete-file fn dired-recursive-deletes trash)
4099 ;; if we get here, removing worked 4090 ;; if we get here, removing worked
4100 (setq succ (1+ succ)) 4091 (setq succ (1+ succ))
4101 (progress-reporter-update progress-reporter succ) 4092 (progress-reporter-update progress-reporter succ)
4102 (dired-fun-in-all-buffers 4093 (dired-fun-in-all-buffers
4103 (file-name-directory fn) (file-name-nondirectory fn) 4094 (file-name-directory fn) (file-name-nondirectory fn)
4104 #'dired-delete-entry fn) 4095 #'dired-delete-entry fn)
4105 ;; For when FN's directory name is different 4096 ;; For when FN's directory name is different
4106 ;; from the current buffer's dired-directory. 4097 ;; from the current buffer's dired-directory.
4107 (dired-delete-entry fn)) 4098 (dired-delete-entry fn))
4108 (quit (throw '--delete-cancel (message "OK, canceled"))) 4099 (quit (throw '--delete-cancel (message "OK, canceled")))
4109 (error ;; catch errors from failed deletions 4100 (error ;; catch errors from failed deletions
4110 (dired-log "%s: %s\n" (car err) (error-message-string err)) 4101 (dired-log "%s: %s\n" (car err) (error-message-string err))
4111 (setq failures (cons (car (car l)) failures))))) 4102 (setq failures (cons (car (car l)) failures))))))
4112 (setq l (cdr l))) 4103 (setq l (cdr l)))
4113 (if (not failures) 4104 (if (not failures)
4114 (progress-reporter-done progress-reporter) 4105 (progress-reporter-done progress-reporter)