Subject: bug#75626: 31.0.50; Dired misses or double-processes files when auto-revert-mode is enabled

From: Tassilo Horn <[email-masked]>
Date: Thu, 06 Feb 2025 17:58:51 +0100

Michael Albinus <[email-masked]> writes:

>> Have you ever read (info "(elisp) Surprising Local Vars") - and the
>> whole (info "(elisp) Problems with Macros") chapter?  (If not, you
>> should do...)
>
> I did. But I've never thought about consequences for macro
> expansion. Finally, I've decided for "a more obscure name".

Why not go the full way and do it correctly like with this patch:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 315100885be..b3079658ece 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -781,22 +781,24 @@ auto-revert--end-lockout
     "Deactivate auto-reverting of current buffer temporarily.
 Run BODY."
     (declare (indent 0) (debug (body)))
-    `(progn
-       ;; Cleanup.
-       (dolist (buf inhibit-auto-revert-buffers)
-         (unless (buffer-live-p buf)
-           (setq inhibit-auto-revert-buffers
-                 (delq buf inhibit-auto-revert-buffers))))
-       (let ((iar-buf
-              (and (not (memq (current-buffer) inhibit-auto-revert-buffers))
-                   (current-buffer))))
-         (unwind-protect
-             (progn
-               (when iar-buf (add-to-list 'inhibit-auto-revert-buffers iar-buf))
-               ,@body)
-           (when iar-buf
+    (let ((buf (make-symbol "buf"))
+          (buf2 (make-symbol "buf2")))
+      `(progn
+         ;; Cleanup.
+         (dolist (,buf inhibit-auto-revert-buffers)
+           (unless (buffer-live-p buf)
              (setq inhibit-auto-revert-buffers
-                   (delq iar-buf inhibit-auto-revert-buffers))))))))
+                   (delq ,buf inhibit-auto-revert-buffers))))
+         (let ((,buf2
+                (and (not (memq (current-buffer) inhibit-auto-revert-buffers))
+                     (current-buffer))))
+           (unwind-protect
+               (progn
+                 (when ,buf2 (add-to-list 'inhibit-auto-revert-buffers ,buf2))
+                 ,@body)
+             (when ,buf2
+               (setq inhibit-auto-revert-buffers
+                     (delq ,buf2 inhibit-auto-revert-buffers)))))))))
 
 (defun auto-revert-active-p ()
   "Check if auto-revert is active in current buffer."
--8<---------------cut here---------------end--------------->8---

BTW, Clojure has a very nice feature.  When you write a macro like

(defmacro quux []
  `(let [x# (foo)
         y# (baz x#)]
      (+ x# y#)))

every occurrence of x# (and y#) expands into the same
gensymed/uninterned symbol.  So you don't need to manually create and
let-bind uninterned symbols in order to splice them in the expansion.
That would be nice to have in Elisp.

Bye,
Tassilo