[alt.sources] Kill-permanent command; Faster kill hooks

rgs@CS.CMU.EDU (Robert Stockton) (12/10/89)

Original-posting-by: rgs@CS.CMU.EDU (Robert Stockton)
Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
Posting-id: 891209.2026
Posting-number: Volume TEST, Number TEST
Archive-name: new-gnus-kill.el

[This is an experimental alt.sources re-posting from the
newsgroup(s) gnu.emacs.gnus.
No attempt has been made to edit, clean, modify, or otherwise
change the contents of the original posting, or to contact the
author.  Please consider cross-posting all sources postings to
alt.sources as a matter of course.]

[Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti)]

In article <ASHWIN.89Dec8104122@pravda.gatech.edu> ashwin@gatech.edu (Ashwin Ram) writes:

   Does anyone have a 'kill-permanent' command for gnus (like the 'K' command
   in rn)?

   Also, does anyone have faster code for applying kill hooks?  I find that
   using kill files is very slow if I have more than 4 or 5 gnus-kill commands
   in the kill file and there are 20-30 messages in the newsgroup.  With 10
   kill commands and 50 messages it's pretty much unusable.  I think it is the
   gnus-kill function that is the bottleneck, but I could be wrong.

I would tend to agree that the gnus-kill function is entirely too slow.  I've
seen it take upwards of half an hour on some of the larger newsgroups (which
are the ones that really need kill files.)  I have worked around this problem
by writing my own version of 'gnus-kill which is nearly compatible with the
old one, but which runs vastly faster (i.e. I have no problem running it on
1000 messages at a time).  It's not incredibly clean code at the moment, but I
think you will find it worthwhile anyway.  If anyone out there wants to clean
it up and include it in the distribution that is fine with me.

------------------------------ >8 Cut here 8< ------------------------------
(defun new-gnus-kill (field regexp &optional command)
  (save-excursion
    (save-window-excursion
      (switch-to-buffer gnus-Subject-buffer)
      (let ((fun (intern-soft (concat "gnus-header-" (downcase field))))
	    (headers gnus-newsgroup-headers)
	    (value nil))
      (while headers
	(setq value (funcall fun (car headers)))
	;; Number (Lines:) or symbol must be converted to string.
	(or (stringp value)
	    (setq value (prin1-to-string value)))
	(if (string-match regexp value)
	    (progn (goto-char (point-min))
		   (while (and (re-search-forward (int-to-string (gnus-header-number (car headers))) nil t)
		     (not (looking-at ":.\\["))))
		   (cond ((not (looking-at ": \\[")) nil)
			 ((null command) (gnus-Subject-mark-as-read nil "X"))
			 ((stringp command)	;Keyboard macro.
			  (execute-kbd-macro command))
			 (t (eval command)))))
	(setq headers (cdr headers)))))))
--
Robert Stockton
ARPA: rgs@k.cs.cmu.edu
UUCP: ...!seismo!cmu-cs-k!rgs
      ...!seismo!rgs@k.cs.cmu.edu