Subject: Re: bug#56423: 29.0.50; Hi-lock in dired broken by toggling wdired-mode

From: Michael Heerdegen <[email-masked]>
Date: Thu, 07 Jul 2022 12:26:03 +0200

Eli Zaretskii <[email-masked]> writes:

> > diff --git a/lisp/wdired.el b/lisp/wdired.el
> > index a5858ed190..7c8969431f 100644
> > --- a/lisp/wdired.el
> > +++ b/lisp/wdired.el
> > @@ -261,6 +261,7 @@ wdired-change-to-wdired-mode
> >    (add-hook 'before-change-functions #'wdired--before-change-fn nil t)
> >    (add-hook 'after-change-functions #'wdired--restore-properties nil t)
> >    (setq major-mode 'wdired-mode)
> > +  (setq font-lock-major-mode 'wdired-mode)
> >    (setq mode-name "Editable Dired")
> >    (add-function :override (local 'revert-buffer-function)
> > #'wdired-revert)
> >    (set-buffer-modified-p nil)
> > @@ -457,6 +458,7 @@ wdired-change-to-dired-mode
> >    (force-mode-line-update)
> >    (setq buffer-read-only t)
> >    (setq major-mode 'dired-mode)
> > +  (setq font-lock-major-mode 'dired-mode)
> >    (setq mode-name "Dired")
> >    (dired-advertise)
> >    (remove-hook 'kill-buffer-hook #'wdired-check-kill-buffer t)

> Don't we need to make sure font-lock-major-mode is restored no matter
> how wdired is exited, whether normally or abnormally?

There are two official ways to return - `wdired-abort-changes' and
`wdired-finish-edit' - both call `wdired-change-to-dired-mode' (which I
modified).

If a way of exiting doesn't call `wdired-change-to-dired-mode' your
dired buffer would be broken afterwards AFAIU - you must call it to get
rid of the modifications made by wdired.

Michael.