Function: nnselect-request-thread

nnselect-request-thread is a byte-compiled function defined in nnselect.el.gz.

Signature

(nnselect-request-thread HEADER &optional GROUP SERVER)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/nnselect.el.gz
(deffoo nnselect-request-thread (header &optional group server)
  (with-current-buffer gnus-summary-buffer
    (let ((group (nnselect-add-prefix group))
	  ;; find the best group for the originating article. if its a
	  ;; pseudo-article look for real articles in the same thread
	  ;; and see where they come from.
	  (artgroup (nnselect-article-group
		     (if (> (mail-header-number header) 0)
			 (mail-header-number header)
		       (if (> (gnus-summary-article-number) 0)
			   (gnus-summary-article-number)
			 (let ((thread
				(gnus-id-to-thread (mail-header-id header))))
			   (when thread
                             (cl-some (lambda (x)
                                        (when (and x (> x 0)) x))
				      (gnus-articles-in-thread thread)))))))))
      ;; Check if search-based thread referral is permitted, and
      ;; available.
      (if (and gnus-refer-thread-use-search
	       (gnus-search-server-to-engine
		(gnus-method-to-server
		 (gnus-find-method-for-group artgroup))))
	  ;; If so we perform the query, massage the result, and return
	  ;; the new headers back to the caller to incorporate into the
	  ;; current summary buffer.
	  (let* ((group-spec
		  (list (delq nil (list
				   (or server (gnus-group-server artgroup))
				   (unless gnus-refer-thread-use-search
				     artgroup)))))
		 (ids (cons (mail-header-id header)
			    (split-string
			     (or (mail-header-references header)
				 ""))))
		 (query-spec
		  (list (cons 'query (mapconcat (lambda (i)
						  (format "id:%s" i))
						ids " or "))
			(cons 'thread t)))
		 (last (nnselect-artlist-length gnus-newsgroup-selection))
		 (first (1+ last))
		 (new-nnselect-artlist
		  (gnus-search-run-query
		   (list (cons 'search-query-spec query-spec)
			 (cons 'search-group-spec group-spec))))
		 old-arts seq
		 headers)
	    (mapc
             (lambda (article)
               (if
                   (setq seq
                         (cl-position
                          article
                          gnus-newsgroup-selection
                          :test
                          (lambda (x y)
                            (and (equal (nnselect-artitem-group x)
                                        (nnselect-artitem-group y))
                                 (eql (nnselect-artitem-number x)
                                      (nnselect-artitem-number y))))))
                   (push (1+ seq) old-arts)
                 (setq gnus-newsgroup-selection
                       (vconcat gnus-newsgroup-selection (vector article)))
                 (cl-incf last)))
	     new-nnselect-artlist)
	    (setq headers
		  (gnus-fetch-headers
		   (append (sort old-arts #'<)
			   (number-sequence first last))
		   nil t))
	    (nnselect-store-artlist group gnus-newsgroup-selection)
	    (when (>= last first)
	      (let (new-marks)
		(pcase-dolist (`(,artgroup . ,artids)
			       (ids-by-group (number-sequence first last)))
		  (pcase-dolist (`(,type . ,marked)
				 (gnus-info-marks (gnus-get-info artgroup)))
		    (setq marked (gnus-uncompress-sequence marked))
		    (when (setq new-marks
				(delq nil
				      (mapcar
                                       (lambda (art)
                                         (when (memq (cdr art) marked)
                                           (car art)))
				       artids)))
		      (nconc
		       (symbol-value
			(intern
			 (format "gnus-newsgroup-%s"
				 (car (rassq type gnus-article-mark-lists)))))
		       new-marks)))))
	      (setq gnus-newsgroup-active
		    (cons 1 (nnselect-artlist-length gnus-newsgroup-selection)))
	      (gnus-set-active
	       group
	       (cons 1 (nnselect-artlist-length gnus-newsgroup-selection))))
	    headers)
	;; If we can't or won't use search, just warp to the original
	;; group and punt back to gnus-summary-refer-thread.
	(and (gnus-warp-to-article) (gnus-summary-refer-thread))))))