Subject: bug#79198: closed (Re: bug#79198: 31.0.50; Problem with multiple global auto-revert modes)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 09 Aug 2025 09:45:02 +0000

Your bug report

#79198: 31.0.50; Problem with multiple global auto-revert modes

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
79198: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79198
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#79198: 31.0.50; Problem with multiple global auto-revert modes
From: Sean Whitton <[email-masked]>
To: Stefan Monnier <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked]
Date: Sat, 09 Aug 2025 10:43:48 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

On Sat 09 Aug 2025 at 03:47am -04, Stefan Monnier wrote:

>> I think that the following would fix the problem; how does it look:
>>
>> --8<---------------cut here---------------start------------->8---
>> diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
>> index 46c99052090..f2d21d7ef45 100644
>> --- a/lisp/emacs-lisp/easy-mmode.el
>> +++ b/lisp/emacs-lisp/easy-mmode.el
>> @@ -500,7 +500,8 @@ define-globalized-minor-mode
>>  	  (intern (concat global-mode-name "-enable-in-buffer")))
>>  	 (minor-MODE-hook (intern (concat mode-name "-hook")))
>>  	 (MODE-set-explicitly (intern (concat mode-name "-set-explicitly")))
>> -	 (MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
>> +	 (MODE-major-mode (intern (concat (symbol-name global-mode)
>> +                                          "-major-mode")))
>>           (MODE-predicate (intern (concat (replace-regexp-in-string
>>                                            "-mode\\'" "" global-mode-name)
>>                                           "-modes")))
>> --8<---------------cut here---------------end--------------->8---
>
> I tend to agree and would suggest to put a "--" in there as well, since
> it's used internally by the global major mode and is not meant to be
> used by other code.
> [ Same for the "-set-explicitly" which should be "--set-explicitly". ]

Thanks for reviewing, now done.

-- 
Sean Whitton

Subject: 31.0.50; Problem with multiple global auto-revert modes
From: Sean Whitton <[email-masked]>
To: [email-masked]
Date: Fri, 08 Aug 2025 13:47:02 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

X-debbugs-cc: [email-masked], [email-masked], [email-masked]

Hello,

Currently, between Emacs core and Magit, there are three globalized
versions of auto-revert-mode: global-auto-revert-mode,
magit-auto-revert-mode and the new vc-auto-revert-mode.

global-auto-revert-mode has a custom definition, but
magit-auto-revert-mode and vc-auto-revert-mode both use
define-globalized-minor-mode.  That means they both make use of the
variable auto-revert-mode-major-mode.  Macroexpanding,

--8<---------------cut here---------------start------------->8---
(defun vc-auto-revert-mode-enable-in-buffer ()
    (unless auto-revert-mode-set-explicitly
      (unless (eq auto-revert-mode-major-mode major-mode) ; <-- HERE
        (if auto-revert-mode
            (progn
              (auto-revert-mode -1)
              (funcall
               (function vc-turn-on-auto-revert-mode-for-tracked-files)))
          (funcall
           (function vc-turn-on-auto-revert-mode-for-tracked-files)))))
    (setq auto-revert-mode-major-mode major-mode))
--8<---------------cut here---------------end--------------->8---

and

--8<---------------cut here---------------start------------->8---
(defun magit-auto-revert-mode-enable-in-buffer ()
    (unless auto-revert-mode-set-explicitly
      (unless (eq auto-revert-mode-major-mode major-mode) ; <-- HERE
	(if auto-revert-mode
	    (progn
	      (auto-revert-mode -1)
	      (funcall (function magit-turn-on-auto-revert-mode-if-desired)))
	  (funcall (function magit-turn-on-auto-revert-mode-if-desired)))))
    (setq auto-revert-mode-major-mode major-mode))
--8<---------------cut here---------------end--------------->8---

But now the following problem can occur:
1. Enable magit-auto-revert-mode.
2. *Subsequently*, enable vc-auto-revert-mode.
3. Visit a tracked file in a non-Git VC repository.

Expected behaviour: vc-auto-revert-mode turns on auto-revert-mode
because it's a buffer visiting a VCS-tracked file.

Actual behaviour: magit-auto-revert-mode-enable-in-buffer declines to
enable auto-revert-mode because it's not a Git repository.  It sets
auto-revert-mode-major-mode to non-nil.  But then
vc-auto-revert-mode-enable-in-buffer thinks it has already been called,
and also does nothing.

I think that the following would fix the problem; how does it look:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 46c99052090..f2d21d7ef45 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -500,7 +500,8 @@ define-globalized-minor-mode
 	  (intern (concat global-mode-name "-enable-in-buffer")))
 	 (minor-MODE-hook (intern (concat mode-name "-hook")))
 	 (MODE-set-explicitly (intern (concat mode-name "-set-explicitly")))
-	 (MODE-major-mode (intern (concat (symbol-name mode) "-major-mode")))
+	 (MODE-major-mode (intern (concat (symbol-name global-mode)
+                                          "-major-mode")))
          (MODE-predicate (intern (concat (replace-regexp-in-string
                                           "-mode\\'" "" global-mode-name)
                                          "-modes")))
--8<---------------cut here---------------end--------------->8---

-- 
Sean Whitton