Subject: bug#24472: - a workaround/fix for the menubar crashes on macOS

From: Michael Albinus <[email-masked]>
Date: Sat, 02 May 2020 14:15:19 +0200

Marc Herbert <[email-masked]> writes:

Hi Marc,

> I leveraged the milder symptoms in 26.1 to debug the issue and found a
> workaround/fix. I then upgraded to 26.3 and ta-da: the crashes are
> gone!
>
> The root cause is in menu-bar.el which defines the revert-buffer item like this:
>
>       '(menu-item "Revert Buffer" revert-buffer
>                   :enable (or (blah) (blah)
>                               (and buffer-file-number
>                                    (or (buffer-modified-p)
>                                        (not (verify-visited-file-modtime
>                                              (current-buffer))))))
>
> This greys out the "Revert Buffer" menu item when (among others) no
> one modified the file outside Emacs.
>
> verify-visited-file-modtime calls
> tramp-sh-handle-verify-visited-file-modtime that temporarily hardcodes
> remote-file-name-inhibit-cache to 't that causes the network accesses
> that cause the delays and/or crashes.

Excellent analysis!

> After a few other attempts, my final workaround is dead simple: remove
> the "Revert Buffer" item from the menu by adding this one line to your
> .emacs file:
>
>      (define-key global-map [menu-bar file revert-buffer] nil)
>
> Enjoy. I think it's better than a "workaround" actually, it's almost a
> "feature" that I'm going to keep that in my .emacs file permanently
> because trying to use the network every time you click the menubar is
> just... silly?

Isn't this too heavy? Wouldn't it be sufficient to avoid the
`verify-visited-file-modtime' call in case the buffer is visiting a
remote file? Something like

                              (and buffer-file-number
                                   (or (buffer-modified-p)
                                       (file-remote-p default-directory)
                                       (not (verify-visited-file-modtime
                                             (current-buffer))))))

> I also tried to hack menu-bar.el directly but any change I made to it
> was completely ignored. Anyone knows why?

Hmm. Have you recompiled the whole Emacs after your change? Maybe menu-bar.elc
is dumped into Emacs?

Best regards, Michael.