[gnu.emacs.gnus] sorting subjects

paisley@cme.nist.gov (Scott Paisley) (07/31/89)

I would like to see another sorting method for the gnus subject
buffer.  I really like sorting by subject but if I don't finish
reading the entire newsgroup, I FEEL like I'm really out of time sync.
New messages come in and then when I read the group again, I sometimes
see these messages before the older messages.  What I would like to
see is a grouping of the same subjects by arrival time.

Here is a sample from comp.protocols.appletalk.

Sort by message number:
D 2176:+[ 13:barnett@crdgw] Re: NCSA Telnet
  2177: [ 60:fxa@BOOMBOX.M] POP2/SMTP mail client for Mac now available
  2178: [ 16:dale@wucs1.wu] TelNet doesn't like CAP
  2179: [  5:asher@UHURA.C] Re: POP2/SMTP mail client for Mac now available
  2180: [  1:PWF@VX.ACSS.U] test message, please ignore
  2181: [ 23:Wolfgang_Naeg] Re: TelNet doesn't like CAP
  2182: [  4:louis@aerospa] CAP on the IRIS

Sorted by subject looks like this:
  2182: [  4:louis@aerospa] CAP on the IRIS
D 2176:+[ 13:barnett@crdgw] Re: NCSA Telnet
  2177: [ 60:fxa@BOOMBOX.M] POP2/SMTP mail client for Mac now available
  2179: [  5:asher@UHURA.C] Re: POP2/SMTP mail client for Mac now available
  2178: [ 16:dale@wucs1.wu] TelNet doesn't like CAP
  2181: [ 23:Wolfgang_Naeg] Re: TelNet doesn't like CAP
  2180: [  1:PWF@VX.ACSS.U] test message, please ignore

Grouped by arival time and subject:
D 2176:+[ 13:barnett@crdgw] Re: NCSA Telnet
  2177: [ 60:fxa@BOOMBOX.M] POP2/SMTP mail client for Mac now available
  2179: [  5:asher@UHURA.C] Re: POP2/SMTP mail client for Mac now available
  2178: [ 16:dale@wucs1.wu] TelNet doesn't like CAP
  2181: [ 23:Wolfgang_Naeg] Re: TelNet doesn't like CAP
  2180: [  1:PWF@VX.ACSS.U] test message, please ignore
  2182: [  4:louis@aerospa] CAP on the IRIS

How can I do this?  Thanks for any help in advance.
--
"We each pay a fabulous price, for our visions of paradise."

Scott Paisley        paisley@cme.nbs.gov        ..!uunet!cme-durer!paisley

ange@HPLB.HPL.HP.COM (Andy Norman) (07/31/89)

> How can I do this?  Thanks for any help in advance.

Well, this is something I knocked up in 10 mins. It may not be the most
efficient of code, but it may solve your problem...

Hope this helps.

					-- ange --

					ange@hplb.hpl.hp.com

--------------------------------------------------------------------------------
(setq gnus-Select-group-hook
      '(lambda ()
	 (mapcar (function
		  (lambda (header)
		    (nntp-set-header-subject
		     header
		     (gnus-simplify-subject
		      (gnus-header-subject header) 're-only))))
		 gnus-newsgroup-headers)
	 (ange-sort-headers)))

(defun ange-sort-headers ()
  (let ((alist nil)			;assoc list keyed on subject
	(entry nil)			;current assoc entry
	(elt nil))			;current elt of list
    (while gnus-newsgroup-headers
      (setq elt (car gnus-newsgroup-headers))
      (setq entry (assoc (nntp-header-subject elt) alist))
      (if entry
	  (rplacd entry (cons elt (cdr entry)))
	(setq alist (cons (list (nntp-header-subject elt) elt) alist)))
      (setq gnus-newsgroup-headers (cdr gnus-newsgroup-headers)))
    (setq alist (reverse alist))
    (while alist
      (setq elt (car alist))
      (setq gnus-newsgroup-headers (nconc gnus-newsgroup-headers (reverse (cdr elt))))
      (setq alist (cdr alist)))))

ange@HPLB.HPL.HP.COM (Andy Norman) (07/31/89)

Actually, on second thoughts, I think I prefer the following version.

					-- ange --

					ange@hplb.hpl.hp.com

--------------------------------------------------------------------------------

(setq gnus-Select-group-hook
      '(lambda ()
	 (mapcar (function
		  (lambda (header)
		    (nntp-set-header-subject
		     header
		     (gnus-simplify-subject
		      (gnus-header-subject header) 're-only))))
		 gnus-newsgroup-headers)
	 (ange-sort-headers)))

(defun ange-sort-headers ()
  (let (alist)				;assoc list keyed on subject
    (mapcar				;sort headers into subject buckets
     (function (lambda (header)
		 (let ((entry (assoc (nntp-header-subject header) alist)))
		   (if entry
		       (rplacd entry (cons header (cdr entry)))
		     (setq alist (cons (list (nntp-header-subject header) header) alist))))))
     gnus-newsgroup-headers)
    (setq gnus-newsgroup-headers nil)
    (mapcar				;extract headers from buckets
     (function (lambda (bucket)
		 (setq gnus-newsgroup-headers
		       (nconc gnus-newsgroup-headers (nreverse (cdr bucket))))))
     (nreverse alist))))