Subject: bug#66181: Subject: 29.1; Occur changes don't affect Dired buffer

From: Eli Zaretskii <[email-masked]>
Date: Mon, 25 Sep 2023 11:42:28 +0300

> Cc: [email-masked]
> Date: Mon, 25 Sep 2023 10:29:17 +0300
> From: Eli Zaretskii <[email-masked]>
> 
> > From: Maske <[email-masked]>
> > Date: Sun, 24 Sep 2023 13:32:04 +0200
> > 
> > I read a post, where Occur is used to edit a Dired buffer. Well, it
> > doesn't work:
> > 
> > - Tested in emacs -q
> > - Make Dired buffer writable
> > - Launch Occur
> > - Make Occur buffer editable
> > - Make changes in Occur buffer
> > - Changes are not saved in Dired buffer.
> 
> The last item is inaccurate.  The changes in the Occur buffer _are_
> reflected in the Dired buffer, but typing "C-c C-c" in the Dired
> buffer doesn't commit the changes to disk; instead it says "No changes
> to be performed" and reverts to the previous display of Dired.

This happens because WDired relies on before-change-functions to mark
the portions of the Dired buffer which were edited.  But Occur Edit
mode modifies the target buffer from an after-change function, so
buffer-modification hooks are disabled when the modifications are
performed, and the before-change function installed by WDired isn't
called.

Which also means that any mode that relies on buffer-modification
hooks will fail with the same symptoms when its buffer is edited
indirectly via Occur Edit.

Stefan, do we have any safe means of running the hooks in this case?
I thought about running the buffer-local values of before- and
after-change-functions by hand from occur-after-change-function,
skipping the t entry, but I'm not sure this is safe.  It is certainly
messy, so if there's a more elegant way, I'd like to know.