Subject: Re: bug#33665: 27.0.50; Variables not set up in Gnus when hooks are run

From: Eric Abrahamsen <[email-masked]>
Date: Fri, 07 Dec 2018 10:36:18 -0800

Lars Ingebrigtsen <[email-masked]> writes:

> Eric Abrahamsen <[email-masked]> writes:
>
>> Lars Ingebrigtsen <[email-masked]> writes:
>>
>>> It looks like gnus-newsgroup-name (and friends?) are no longer set when
>>> the summary mode hooks are run, so hooks that rely on that are now
>>> broken.
>>
>> Yes, since `gnus-summary-mode' is now a real mode, it clears local
>> variables before running the hook. The right place for that sort of hook
>> is now `gnus-summary-prepared-hook'. I tried to change all the relevant
>> hooks I could within the codebase, but I guess gnus-mdrtn.el isn't
>> publicly available? I can change the Moderation section of the manual to
>> update the installation instructions.
>
> No, you can't break third-party software that way.  You have to set the
> variables the hooks expect to exist before calling the hook.

Okay. This patch should restore that behavior. I don't see any other
buffer-local variables that were being set to a specific value, other
than `gnus-newsgroup-name'.

diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 4baf4bc826..58605826f6 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -3064,6 +3064,7 @@ gnus-summary-mode
   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
     (gnus-summary-make-local-variables))
   (gnus-summary-make-local-variables)
+  (setq gnus-newsgroup-name gnus-summary-mode-group)
   (when (gnus-visual-p 'summary-menu 'menu)
     (gnus-summary-make-menu-bar)
     (gnus-summary-make-tool-bar))
@@ -3457,6 +3458,11 @@ gnus-summary-set-article-display-arrow
 					       (point)
 					       (current-buffer))))))
 
+(defvar gnus-summary-mode-group nil
+  "Variable for communication with `gnus-summary-mode'.
+Allows the `gnus-newsgroup-name' local variable to be set before
+the summary mode hooks are run.")
+
 (defun gnus-summary-setup-buffer (group)
   "Initialize summary buffer for GROUP.
 This function does all setup work that relies on the specific
@@ -3476,10 +3482,11 @@ gnus-summary-setup-buffer
 	  (not gnus-newsgroup-prepared))
       (set-buffer (gnus-get-buffer-create buffer))
       (setq gnus-summary-buffer (current-buffer))
-      (gnus-summary-mode)
+      (let ((gnus-summary-mode-group group))
+       (gnus-summary-mode))
       (when (gnus-group-quit-config group)
 	(set (make-local-variable 'gnus-single-article-buffer) nil))
-      (setq gnus-newsgroup-name group)
+;      (setq gnus-newsgroup-name group)
       (turn-on-gnus-mailing-list-mode)
       ;; These functions don't currently depend on GROUP, but might in
       ;; the future.