Gnus development mailing list
 help / color / mirror / Atom feed
* virtual nnvirtual
@ 2022-03-23  0:45 Andrew Cohen
  2022-03-23  8:14 ` Eric S Fraga
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Andrew Cohen @ 2022-03-23  0:45 UTC (permalink / raw)
  To: ding

I finally got around to fixing up an nnvirtual replacement using
nnselect, and here is something for testing (mostly by Eric F., I think:))

You will need the latest version of nnselect just pushed to master
(there isn't anything really specific about nnvirtual, just that the
latest changes will allow NOT storing the nnvirtual group info in the
newsrc which saves a lot of space). Then you should evaluate the two
functions below. (All of this would be much more trivial except for the
nnvirtual algorithm of interleaving the articles from the component
groups---I'm not sure how great this algorithm is, but I've reproduced
it. If this is all working it would be very easy to pop in an improved
replacement.)


This first is a convenience function for creating a group. Invoke it
interactively in the group buffer and it will prompt for the new group
name, and then either a list of component groups, or a (string) regexp
to match for the list of component groups:

#+begin_src emacs-lisp
  (defun gnus-group-make-nnvirtual-group (name groups)
    "Make an nnvirtual group using the nnselect backend.
    Prompts for a list or (string) regular expression of component GROUPS."
    (interactive (list (gnus-read-group "New Group Name: ")
                       (read-minibuffer "Component Groups (list or regexp): ")
    ))
      (with-current-buffer gnus-group-buffer
        (gnus-group-make-group
         name
         (list 'nnselect "nnselect")
         nil
         (list
          (cons 'nnselect-specs
                (list
                 (cons 'nnselect-function 'nnselect-generate-nnvirtual)
                 (cons 'nnselect-args groups)))
          (cons 'nnselect-artlist nil)
          (cons 'nnselect-always-regenerate t)))))
#+end_src

This is the function that creates the artlist for the new group. 
#+begin_src emacs-lisp
(defun nnselect-generate-nnvirtual (components)
  "This function generates an nnvirtual article list for GROUPS.
  An nnselect artlist is constructed by interleaving the articles
  from these component groups: the component group lists are cycled
  over with the most recent article popped off and pushed pushed
  onto the artlist; once a component group is exhausted it is
  skipped in subsequent cycles."
  (let ((groups nil))
    ;; Get the list of component groups.
    (if (listp components)
        (setq groups components)
      (dolist (group (cdr gnus-group-list))
        (when (string-match components group)
          (setq groups (cons group groups))))
      (setq groups (delete-dups groups)))
    ;; Prepare the group data.
    (let ((gdata nil) (count 0))
      (dolist (group groups)
        (pcase-let ((`(,min . ,max) (gnus-active group)))
          (cl-incf max)
          (cl-incf count (- max min))
          (push (list  max group min) gdata)))
      (setq gdata (sort gdata 'car-less-than-car))
      ;; Make and fill the vector.  Think of the component article
      ;; lists as columns in a matrix.  We map over the rows and
      ;; remove a column once it is empty.
      (let ((artlist (make-vector count  nil)))
        (while gdata
          (pcase-let ((`(,max ,group ,min) (pop gdata)))
            (while (< min max)
	      (aset artlist (cl-decf count) (vector group (cl-decf max) 1))
	      (mapc
	       (lambda (data)
		 (aset artlist
		       (cl-decf count)
		       (vector (cadr data) (cl-decf (car data)) 1)))
	       gdata))))
	artlist))))
#+end_src

-- 
Andrew Cohen



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-03-25  9:39 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23  0:45 virtual nnvirtual Andrew Cohen
2022-03-23  8:14 ` Eric S Fraga
2022-03-23 11:53 ` Eric S Fraga
2022-03-23 12:02 ` Eric S Fraga
2022-03-23 12:53   ` Andrew Cohen
2022-03-23 13:19     ` Eric S Fraga
2022-03-23 14:51       ` Andrew Cohen
2022-03-23 15:28         ` Eric S Fraga
2022-03-23 15:00       ` Eric Abrahamsen
2022-03-23 15:31         ` Eric S Fraga
2022-03-24  5:30       ` Andrew Cohen
2022-03-24  7:27         ` Eric S Fraga
2022-03-23 15:33 ` Eric S Fraga
2022-03-25  0:39   ` Andrew Cohen
2022-03-25  4:53     ` Andrew Cohen
2022-03-25  9:15       ` Eric S Fraga
2022-03-25  9:27         ` Andrew Cohen
2022-03-25  9:35           ` Eric S Fraga
2022-03-25  9:39             ` Andrew Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).