🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #581

Re: fine-grained control of sorting in newsgroups

#581
From: Dan_Jacobson
Date: Tue, 10 Sep 1991 22:52
197 lines
9087 bytes
>>>>> On 10 Sep 91 20:36:53 GMT, emv@msen.com (Ed Vielmetti) said:

Ed> One way that I organize my news reading is to periodically re-sort the
Ed> .newsrc file, using the "fixnewsrc" script that ckd@eff.org (Chris
Ed> Davis) built.  

Ed> I'm thinking that it would be useful to take the same approach to some
Ed> newsgroups, percolating some of the consistently interesting stuff to
Ed> the top of the sort list, and then sorting the rest by some stable
Ed> thing (by thread or date or what have you).  This is another
Ed> refinement on a "kill file", but more than just a kill file it would
Ed> be a selective sort on the newsgroup.  e.g. for comp.archives is might
Ed> look like "put stuff with [comp.*] at the top, then the rest.".  Or
Ed> whatever.

Ed> GNUS might be able to do this with a proper sort hook, but I don't
Ed> hack elisp....

Here's what I use in GNUS.  [With the following code, I do
(setq newsgroup-type-priority-list nil)
(setq newsgroup-name-priority-list
  '(
        "important"
        "^news\\.announce\\.new"
        ....
myself, and run it every few weeks.]

;From: ashwin@gatech.edu (Ashwin Ram)
;Newsgroups: gnu.emacs.gnus
;Subject: Re: How to sort the groups alphabeticaly?
;Date: 22 Oct 90 14:50:16 GMT
;Reply-To: ashwin@pravda.gatech.edu (Ashwin Ram)
;Organization: Georgia Institute of Technology, College of Computing
;In-reply-to: hilken.bln@nixpbe.uucp's message of 17 Oct 90 10:37:52 GMT
;
;I have code that (a) sorts the .newsrc file in order of "priority", and then
;(b) maintains it in that order by inserting new newsgroups in the appropriate
;place.  (a) is slow but you only do it once.  I've been using the code for
;several weeks now without running into any bugs.
;
;"Priority" is defined using a list that allows you to specify newsgroup names
;or name substrings in order of priority.  You get two variables you can
;customize.  E.g., the following settings specify that you want to read "comp"
;groups first, then "sci" groups, then "soc" groups, and everything else
;doesn't matter (that's the type-priority list); furthermore, you want to read
;"general" groups first, then groups about "ai", then groups about "gnus", and
;everything else doesn't matter.
;
;    (setq newsgroup-type-priority-list '("comp" "sci" "soc"))
;    (setq newsgroup-name-priority-list '("\\.general" "\\.ai" "gnus")))
;
;Either list can include arbitrary regexps.  The newsgroups are sorted
;alphabetically, but weighted by the above priorities.  So for example given
;the above variables you'd get "comp.ai" before "comp.emacs.gnus" before
;"comp.arch" (say).
;
;If you don't care about priorities, you can leave these variables alone and
;stay with regular alphabetical order.
;
;Code follows:
;
;----- cut ----- cut ----- cut ----- cut ----- cut ----- cut ----- cut -----
;; GNUS-PRIORITY.EL
;; Copyleft (c) Ashwin Ram, 7/1/90.  Usual GNU rules apply.
;;
;; Code to allow GNUS to maintain .newsrc in order of priority of newsgroups.
;; Default order is alphabetical, but certain type hierarchies (e.g., "comp")
;; or certain newsgroup name substrings (e.g., "ai") can be boosted up if
;; desired.
;;
;; How to customize:
;;     (setq newsgroup-type-priority-list ...)
;;     (setq newsgroup-name-priority-list ...)
;;
;; How to use:
;;     (require 'gnus-priority)
;;     Manually, in .newsrc buffer:  M-x newsrc-sort
;;     To have new newsgroups inserted in the appropriate position automatically:
;;       (setq gnus-subscribe-newsgroup-method
;;             (function
;;                (lambda (newsgroup)
;;                   (gnus-subscribe-newsgroup newsgroup
;;                                             (car (find '(lambda (n) (newsgroup< newsgroup (car n)))
;;                                                         gnus-newsrc-assoc))))))

;; Variables for customization
;; ---------------------------
;; Example:
;; 
;;    To read "comp" groups first, then "soc" groups, then "sci" groups, and
;;    everything else alphabetically:
;;        (setq newsgroup-type-priority-list '("comp" "sci" "soc"))
;; 
;;    To read "general" groups first, then groups about "ai", then groups
;;    about "gnus", and everything else alphabetically:
;;        (setq newsgroup-name-priority-list '("\\.general" "\\.ai"))
;;
;; Either list can include arbitrary regexps.  The newsgroups are sorted
;; alphabetically, but weighted by the above priorities.  So for example
;; given the above variables you'd get "comp.ai" before "comp.emacs.gnus"
;; before "comp.arch" (say).
;; 
;; If you don't care about priorities, you can leave these variables alone
;; and stay with regular alphabetical order.

(defvar newsgroup-type-priority-list nil   
   "List of newsgroup type/hierarchy names in descending order of priority.
Types not mentioned are of zero priority.  See also newsgroup-name-priority-list.")

(defvar newsgroup-name-priority-list nil
   "List of newsgroup name components/substrings in descending order of priority.
Components not mentioned are of zero priority.  See also newsgroup-type-priority-list.")

;; Main prioritization functions
;; -----------------------------

(defun newsgroup< (a b)
   "Newsgroup A comes before newsgroup B if it is higher priority.
If priorities are equal, alphabetical order is used."
   (let ((pa (newsgroup-priority a))
         (pb (newsgroup-priority b)))
      (cond ((> pa pb) t)
            ((= pa pb) (string< a b))
            (t nil))))

(defun newsgroup-priority (newsgroup)
   (let* ((newsgroup-type
              (and (string-match "^[^.]*\\." newsgroup)
                   (substring newsgroup 0 (- (match-end 0) 1))))
          (newsgroup-type-index (mem 'equal newsgroup-type newsgroup-type-priority-list))
          (newsgroup-name-index (mem '(lambda (a b) (string-match b a)) newsgroup newsgroup-name-priority-list)))
      (+ (* (length newsgroup-type-priority-list)
            (if newsgroup-type-index (length newsgroup-type-index) 0))
         (if newsgroup-name-index (length newsgroup-name-index) 0))))

;; Main user functions.
;; --------------------

(defun newsrc-sort ()
   "Sort newsgroups in .newsrc using newsgroup< predicate."
   (interactive)
   (require 'sort)
;  (find-file "~/.newsrc")
   (save-excursion
      (goto-char (point-min))
      (message "Sorting newsrc (finding sort keys)...")
      (let* ((sort-lists (sort-build-lists 'forward-line 'end-of-line nil nil))
             (old (reverse sort-lists)))
         (cond ((null sort-lists) nil)
               (t (message "Sorting newsrc (sorting records)...")
                  (setq sort-lists
                        (sort sort-lists
                              (function
                               (lambda (a b) (newsgroup< (car a) (car b))))))))
         (message "Sorting newsrc (reordering buffer)...")
         (sort-reorder-buffer sort-lists old)
         (message "Sorting newsrc... done"))))

;; Uncomment this if you want new newsgroups to be placed at the
;; appropriate position automatically.
;;
;; (setq gnus-subscribe-newsgroup-method
;;       (function
;;        (lambda (newsgroup)
;;           (gnus-subscribe-newsgroup newsgroup
;;                                     (car (find '(lambda (n) (newsgroup< newsgroup (car n)))
;;                                                gnus-newsrc-assoc))))))

;; Simple Lisp utilities.
;; ----------------------

(defun find (pred l)
   (while (not (funcall pred (car l)))
      (setq l (cdr l)))
   (car l))

(defun mem (pred x l)
   (let ((done nil))
      (while (and l (not done))
         (if (funcall pred x (car l))
             (setq done t)
             (setq l (cdr l))))
      l))



(provide 'gnus-priority)

;; End of GNUS-PRIORITY.EL
;----- cut ----- cut ----- cut ----- cut ----- cut ----- cut ----- cut -----
;
;Hope this helps.  Improvements welcome.
;
;Ashwin Ram <ashwin@cc.gatech.edu>
;College of Computing
;Georgia Institute of Technology, Atlanta, Georgia 30332-0280
Technical Details
Message-ID: <1991Sep10Tu185346.Dan_Jacobson@ATT.COM>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!funic!fuug!mcsun!unido!unidui!math.fu-berlin.de!ox.com!spool.mu.edu!sdd.hp.com!mips!pacbell.com!att!cbnewse!danj1
References: <EMV.91Sep10163653@cato.aa.ox.com>

Show Full Headers
Complete Article Headers
Message-ID: <1991Sep10Tu185346.Dan_Jacobson@ATT.COM>
Subject: Re: fine-grained control of sorting in newsgroups
Date: Tue, 10 Sep 1991 22:52:40 +0000
From: Dan_Jacobson@ATT.COM
References: <EMV.91Sep10163653@cato.aa.ox.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!funic!fuug!mcsun!unido!unidui!math.fu-berlin.de!ox.com!spool.mu.edu!sdd.hp.com!mips!pacbell.com!att!cbnewse!danj1
Newsgroups: news.software.readers,comp.archives.admin,gnu.emacs.gnus,gnu.emacs.sources
Sender: danj1@cbnewse.cb.att.com (daniel.jacobson)
Reply-To: Dan_Jacobson@ihlpz.ATT.COM
Followup-To: news.software.readers,comp.archives.admin,gnu.emacs.gnus
Organization: AT&T-BL, Naperville IL, USA
Lines: 196
In-Reply-To: emv@msen.com's message of 10 Sep 91 20: 36:53 GMT