Subject: bug#10205: [PATCH] setting nntp-server-list-active-group to nil breaks agent

From: Wolfgang Jenkner <[email-masked]>
Date: Sat, 03 Dec 2011 02:26:21 +0100

Let ~/.gnus consist of

(setq gnus-select-method
      '(nntp "news.gmane.org"
	     (nntp-server-list-active-group nil)))

Now start gnus, agentize the news.gmane.org server, subscribe to
gmane.emacs.devel and get new articles

ESC x g n u s RET ^ n J a q S s g m a n e . e m a c s . d e v e l RET g

Observe that the *Group* buffer looks like

   *: gmane.emacs.devel

but it should have some integer instead of the `*'.

No Gnus v0.18
GNU Emacs 24.0.91.1 (amd64-portbld-freebsd9.0, GTK+ Version 2.24.6)
 of 2011-11-18 on iznogoud.viz

2011-12-02  Wolfgang Jenkner  <[email-masked]>

	* gnus-agent.el (gnus-agent-save-active): Deal with the "groups"
	format.  In particular, add an optional argument and a docstring.

	* gnus-start.el (gnus-groups-to-gnus-format): Use it.

	* nntp.el (nntp-finish-retrieve-group-infos): Make `nntp-server-buffer'
	current before calling `gnus-groups-to-gnus-format'.
	Note that this was already the case for `gnus-active-to-gnus-format'.

-- >8 --
Subject: [PATCH] Fix agentized servers which use the "groups" format.

---
 lisp/gnus-agent.el |   10 ++++++++--
 lisp/gnus-start.el |    2 +-
 lisp/nntp.el       |    3 ++-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lisp/gnus-agent.el b/lisp/gnus-agent.el
index bf7f31e..849f66b 100644
--- a/lisp/gnus-agent.el
+++ b/lisp/gnus-agent.el
@@ -1302,12 +1302,18 @@ This can be added to `gnus-select-article-hook' or
             (gnus-group-update-group group t)))
     nil))
 
-(defun gnus-agent-save-active (method)
+(defun gnus-agent-save-active (method &optional groups-p)
+  "Sync the agent's active file with the current buffer.
+Pass non-nil for GROUPS-P if the buffer starts out in groups format.
+Regardless, both the file and the buffer end up in active format
+if METHOD is agentized; otherwise the function is a no-op."
   (when (gnus-agent-method-p method)
     (let* ((gnus-command-method method)
 	   (new (gnus-make-hashtable (count-lines (point-min) (point-max))))
 	   (file (gnus-agent-lib-file "active")))
-      (gnus-active-to-gnus-format nil new)
+      (if groups-p
+	  (gnus-groups-to-gnus-format nil new)
+	(gnus-active-to-gnus-format nil new))
       (gnus-agent-write-active file new)
       (erase-buffer)
       (let ((nnheader-file-coding-system gnus-agent-file-coding-system))
diff --git a/lisp/gnus-start.el b/lisp/gnus-start.el
index b121960..6077faa 100644
--- a/lisp/gnus-start.el
+++ b/lisp/gnus-start.el
@@ -2211,7 +2211,7 @@ If SCAN, request a scan of that group as well."
 	     (gnus-online method)
 	     (gnus-agent-method-p method))
 	(progn
-	  (gnus-agent-save-active method)
+	  (gnus-agent-save-active method t)
 	  (gnus-active-to-gnus-format method hashtb nil real-active))
 
       (goto-char (point-min))
diff --git a/lisp/nntp.el b/lisp/nntp.el
index 9816c20..d0834cb 100644
--- a/lisp/nntp.el
+++ b/lisp/nntp.el
@@ -816,7 +816,8 @@ command whose response triggered the error."
 	      (progn
 		(nntp-copy-to-buffer nntp-server-buffer
 				     (point-min) (point-max))
-		(gnus-groups-to-gnus-format method gnus-active-hashtb t))
+		(with-current-buffer nntp-server-buffer
+		  (gnus-groups-to-gnus-format method gnus-active-hashtb t)))
 	    ;; We have read active entries, so we just delete the
 	    ;; superfluous gunk.
 	    (goto-char (point-min))
-- 
1.7.7.4