Subject: Re: bug#75305: 31.0.50; gnus-refer-thread-use-search isn't exact enough about how the current group is searched

From: Andrew Cohen <[email-masked]>
Date: Sun, 23 Feb 2025 11:48:03 +0800

>>>>> "EZ" == Eli Zaretskii <[email-masked]> writes:

    EZ> Ping! Can we please make some progress here?

All set to commit, I think. I have been running with the following in my
personal tree for the past few weeks without issue. If no objections we
can commit.

>From ec55d60f7b7d7e30ef4dce059f8b2f720c480e39 Mon Sep 17 00:00:00 2001
From: Andrew G Cohen <[email-masked]>
Date: Sun, 23 Feb 2025 11:18:37 +0800
Subject: [PATCH] Allow 'current in gnus-refer-thread-use-search

The variable `gnus-refer-thread-use-search' controls which groups are
searched when finding articles in a thread.  The symbol `current' can be
used to include the current group in those searched.

* doc/misc/gnus.texi: Document the use of `current' in
`gnus-refer-thread-use-search'.
* lisp/gnus/gnus-sum.el (gnus-summary-refer-thread): Resolve the symbol
`current' to the group from which `gnus-summary-refer-thread' was
invoked.
---
 doc/misc/gnus.texi    | 24 +++++++++++++-------
 lisp/gnus/gnus-sum.el | 51 +++++++++++++++++++++++++------------------
 2 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index bdfab7a8718..c901672738c 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -10546,8 +10546,7 @@ Finding the Parent
 @findex gnus-summary-refer-thread
 @kindex A T @r{(Summary)}
 Display the full thread where the current article appears
-(@code{gnus-summary-refer-thread}).  By default this command looks for
-articles only in the current group.  If the group belongs to a backend
+(@code{gnus-summary-refer-thread}).  If the group belongs to a backend
 that has an associated search engine, articles are found by searching.
 In other cases each header in the current group must be fetched and
 examined, so it usually takes a while.  If you do it often, you may
@@ -10557,12 +10556,21 @@ Finding the Parent
 course, it'll make group entry somewhat slow.
 
 @vindex gnus-refer-thread-use-search
-If @code{gnus-refer-thread-use-search} is @code{nil} (the default)
-then thread-referral only looks for articles in the current group.  If
-this variable is @code{t} the server to which the current group
-belongs is searched (provided that searching is available for the
-server's backend).  If this variable is a list of servers, each server
-in the list is searched.
+If @code{gnus-refer-thread-use-search} is @code{nil} (the default), then
+thread-referral only looks for articles in the current group.
+
+If this variable is @code{t}, and the server to which the current group
+belongs has an associated search engine, then this server is searched.
+
+This variable may also be a list of servers and groups to search. Each
+element of the list is of the form @code{(@var{server} @var{group1}
+@var{group2}@dots{})}, where @var{server} is the server and
+@var{group1}, @var{group2}@dots{} are the groups belonging to this
+server that are to be searched.  If the @var{group}s are absent the
+entire server is searched.
+
+This list may also contain the special symbol @code{current}, which will
+add the current group to the list of groups to be searched.
 
 @vindex gnus-refer-thread-limit
 The @code{gnus-refer-thread-limit} variable says how many old (i.e.,
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 6294825b400..21c6db381a8 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -145,15 +145,21 @@ 'gnus-refer-thread-use-nnir
 (defcustom gnus-refer-thread-use-search nil
   "Specify where to find articles when referring threads.
 A nil value restricts searches for thread-related articles to the
-current group; a value of t searches all groups on the server; a
-list of servers and groups (where each element is a list whose
-car is the server and whose cdr is a list of groups on this
-server or nil to search the entire server) searches these
-server/groups.  This may usefully be set as a group parameter."
-  :version "28.1"
+current group; a value of t searches all groups on the server to which
+the group belongs; a list of servers and groups (where each element is a
+list whose car is the server and whose cdr is a list of groups on this
+server, or nil to search the entire server) searches just these
+server/groups.
+
+The list of server/groups may contain the symbol `current' which
+includes the current group in the list of those searched."
+  :version "31.1"
   :group 'gnus-thread
-  :type '(restricted-sexp :match-alternatives
-                          (listp 't 'nil)))
+  :type '(choice (const :tag "Current group" nil)
+                 (const :tag "All groups" t)
+                 (repeat :tag "Server and groups"
+                         (choice (const :tag "Current Group" current)
+                                 (repeat :tag "Server and groups" string)))))
 
 (defcustom gnus-refer-thread-limit-to-thread nil
   "If non-nil referring a thread will limit the summary buffer to
@@ -9014,25 +9020,28 @@ gnus-delete-duplicate-headers
 
 (defun gnus-summary-refer-thread (&optional limit)
   "Fetch all articles in the current thread.
-A non-numeric prefix arg will search the entire server; without a
-prefix arg only the current group is searched.  If the variable
-`gnus-refer-thread-use-search' is t the prefix arg has the
-reverse meaning.  If searching is not enabled for the current
-group, fetch LIMIT (the numerical prefix) old headers.  If LIMIT
-is non-numeric or nil fetch the number specified by the
-`gnus-refer-thread-limit' variable."
+Only the current group is searched by default.  A non-numeric prefix arg
+will search the entire server.  If the variable
+`gnus-refer-thread-use-search' is t the meaning of the prefix arg is
+inverted; if it is a list, only those groups in the list will be
+searched.  If searching is not enabled for the current group, fetch
+LIMIT (the numerical prefix) old headers.  If LIMIT is non-numeric or
+nil fetch the number specified by the `gnus-refer-thread-limit'
+variable."
   (interactive "P" gnus-summary-mode)
   (let* ((group gnus-newsgroup-name)
+         (server (gnus-method-to-server (gnus-find-method-for-group group)))
          (header (gnus-summary-article-header))
          (id (mail-header-id header))
          (gnus-inhibit-demon t)
          (gnus-summary-ignore-duplicates t)
          (gnus-refer-thread-use-search
-          (if (or (null limit) (numberp limit))
-              gnus-refer-thread-use-search
-            (if (booleanp gnus-refer-thread-use-search)
-                (not gnus-refer-thread-use-search)
-              gnus-refer-thread-use-search))))
+          (if (listp gnus-refer-thread-use-search)
+              (cl-subst (list server group) 'current
+                        gnus-refer-thread-use-search)
+            (if (or (null limit) (numberp limit))
+                gnus-refer-thread-use-search
+              (not gnus-refer-thread-use-search)))))
     (gnus-summary-insert-articles
      (cond
       ;; If there is a backend-specific method, use it.
@@ -9041,7 +9050,7 @@ gnus-summary-refer-thread
        (gnus-request-thread header group))
       ;; If a search engine is configured, use it.
       ((ignore-errors
-         (gnus-search-server-to-engine (gnus-group-server group)))
+         (gnus-search-server-to-engine server))
        (gnus-search-thread header))
       ;; Otherwise just retrieve some headers.
       (t
-- 
2.47.2

-- 
Andrew Cohen