*** empty log message ***
[gnus] / lisp / gnus-kill.el
1 ;;; gnus-kill.el --- kill commands for Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
3
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;;      Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'gnus)
29
30 (defvar gnus-kill-file-mode-hook nil
31   "*A hook for Gnus kill file mode.")
32
33 (defvar gnus-kill-expiry-days 7
34   "*Number of days before expiring unused kill file entries.")
35
36 (defvar gnus-kill-save-kill-file nil
37   "*If non-nil, will save kill files after processing them.")
38
39 (defvar gnus-winconf-kill-file nil)
40
41 \f
42
43 (defmacro gnus-raise (field expression level)
44   (` (gnus-kill (, field) (, expression)
45                 (function (gnus-summary-raise-score (, level))) t)))
46
47 (defmacro gnus-lower (field expression level)
48   (` (gnus-kill (, field) (, expression)
49                 (function (gnus-summary-raise-score (- (, level)))) t)))
50
51 ;;;
52 ;;; Gnus Kill File Mode
53 ;;;
54
55 (defvar gnus-kill-file-mode-map nil)
56
57 (if gnus-kill-file-mode-map
58     nil
59   (setq gnus-kill-file-mode-map (copy-keymap emacs-lisp-mode-map))
60   (define-key gnus-kill-file-mode-map 
61     "\C-c\C-k\C-s" 'gnus-kill-file-kill-by-subject)
62   (define-key gnus-kill-file-mode-map
63     "\C-c\C-k\C-a" 'gnus-kill-file-kill-by-author)
64   (define-key gnus-kill-file-mode-map
65     "\C-c\C-k\C-t" 'gnus-kill-file-kill-by-thread)
66   (define-key gnus-kill-file-mode-map 
67     "\C-c\C-k\C-x" 'gnus-kill-file-kill-by-xref)
68   (define-key gnus-kill-file-mode-map
69     "\C-c\C-a" 'gnus-kill-file-apply-buffer)
70   (define-key gnus-kill-file-mode-map
71     "\C-c\C-e" 'gnus-kill-file-apply-last-sexp)
72   (define-key gnus-kill-file-mode-map 
73     "\C-c\C-c" 'gnus-kill-file-exit))
74
75 (defun gnus-kill-file-mode ()
76   "Major mode for editing kill files.
77
78 If you are using this mode - you probably shouldn't.  Kill files
79 perform badly and paint with a pretty broad brush.  Score files, on
80 the other hand, are vastly faster (40x speedup) and give you more
81 control over what to do.
82
83 In addition to Emacs-Lisp Mode, the following commands are available:
84
85 \\{gnus-kill-file-mode-map}
86
87   A kill file contains Lisp expressions to be applied to a selected
88 newsgroup.  The purpose is to mark articles as read on the basis of
89 some set of regexps.  A global kill file is applied to every newsgroup,
90 and a local kill file is applied to a specified newsgroup.  Since a
91 global kill file is applied to every newsgroup, for better performance
92 use a local one.
93
94   A kill file can contain any kind of Emacs Lisp expressions expected
95 to be evaluated in the Summary buffer.  Writing Lisp programs for this
96 purpose is not so easy because the internal working of Gnus must be
97 well-known.  For this reason, Gnus provides a general function which
98 does this easily for non-Lisp programmers.
99
100   The `gnus-kill' function executes commands available in Summary Mode
101 by their key sequences. `gnus-kill' should be called with FIELD,
102 REGEXP and optional COMMAND and ALL.  FIELD is a string representing
103 the header field or an empty string.  If FIELD is an empty string, the
104 entire article body is searched for.  REGEXP is a string which is
105 compared with FIELD value. COMMAND is a string representing a valid
106 key sequence in Summary mode or Lisp expression. COMMAND defaults to
107 '(gnus-summary-mark-as-read nil \"X\").  Make sure that COMMAND is
108 executed in the Summary buffer.  If the second optional argument ALL
109 is non-nil, the COMMAND is applied to articles which are already
110 marked as read or unread.  Articles which are marked are skipped over
111 by default.
112
113   For example, if you want to mark articles of which subjects contain
114 the string `AI' as read, a possible kill file may look like:
115
116         (gnus-kill \"Subject\" \"AI\")
117
118   If you want to mark articles with `D' instead of `X', you can use
119 the following expression:
120
121         (gnus-kill \"Subject\" \"AI\" \"d\")
122
123 In this example it is assumed that the command
124 `gnus-summary-mark-as-read-forward' is assigned to `d' in Summary Mode.
125
126   It is possible to delete unnecessary headers which are marked with
127 `X' in a kill file as follows:
128
129         (gnus-expunge \"X\")
130
131   If the Summary buffer is empty after applying kill files, Gnus will
132 exit the selected newsgroup normally.  If headers which are marked
133 with `D' are deleted in a kill file, it is impossible to read articles
134 which are marked as read in the previous Gnus sessions.  Marks other
135 than `D' should be used for articles which should really be deleted.
136
137 Entry to this mode calls emacs-lisp-mode-hook and
138 gnus-kill-file-mode-hook with no arguments, if that value is non-nil."
139   (interactive)
140   (kill-all-local-variables)
141   (use-local-map gnus-kill-file-mode-map)
142   (set-syntax-table emacs-lisp-mode-syntax-table)
143   (setq major-mode 'gnus-kill-file-mode)
144   (setq mode-name "Kill")
145   (lisp-mode-variables nil)
146   (run-hooks 'emacs-lisp-mode-hook 'gnus-kill-file-mode-hook))
147
148 (defun gnus-kill-file-edit-file (newsgroup)
149   "Begin editing a kill file for NEWSGROUP.
150 If NEWSGROUP is nil, the global kill file is selected."
151   (interactive "sNewsgroup: ")
152   (let ((file (gnus-newsgroup-kill-file newsgroup)))
153     (gnus-make-directory (file-name-directory file))
154     ;; Save current window configuration if this is first invocation.
155     (or (and (get-file-buffer file)
156              (get-buffer-window (get-file-buffer file)))
157         (setq gnus-winconf-kill-file (current-window-configuration)))
158     ;; Hack windows.
159     (let ((buffer (find-file-noselect file)))
160       (cond ((get-buffer-window buffer)
161              (pop-to-buffer buffer))
162             ((eq major-mode 'gnus-group-mode)
163              (gnus-configure-windows 'group) ;Take all windows.
164              (pop-to-buffer buffer))
165             ((eq major-mode 'gnus-summary-mode)
166              (gnus-configure-windows 'article)
167              (pop-to-buffer gnus-article-buffer)
168              (bury-buffer gnus-article-buffer)
169              (switch-to-buffer buffer))
170             (t                          ;No good rules.
171              (find-file-other-window file))))
172     (gnus-kill-file-mode)))
173
174 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
175 (defun gnus-kill-set-kill-buffer ()
176   (let* ((file (gnus-newsgroup-kill-file gnus-newsgroup-name))
177          (buffer (find-file-noselect file)))
178     (set-buffer buffer)
179     (gnus-kill-file-mode)
180     (bury-buffer buffer)))
181
182 (defun gnus-kill-file-enter-kill (field regexp)
183   ;; Enter kill file entry.
184   ;; FIELD: String containing the name of the header field to kill.
185   ;; REGEXP: The string to kill.
186   (save-excursion
187     (let (string)
188       (gnus-kill-set-kill-buffer)
189       (goto-char (point-max))
190       (insert (setq string (format "(gnus-kill %S %S)\n" field regexp)))
191       (gnus-kill-file-apply-string string))))
192     
193 (defun gnus-kill-file-kill-by-subject ()
194   "Kill by subject."
195   (interactive)
196   (gnus-kill-file-enter-kill
197    "Subject" 
198    (regexp-quote 
199     (gnus-simplify-subject (header-subject gnus-current-headers)))))
200   
201 (defun gnus-kill-file-kill-by-author ()
202   "Kill by author."
203   (interactive)
204   (gnus-kill-file-enter-kill
205    "From" (regexp-quote (header-from gnus-current-headers))))
206  
207 (defun gnus-kill-file-kill-by-thread ()
208   "Kill by author."
209   (interactive "p")
210   (gnus-kill-file-enter-kill
211    "References" (regexp-quote (header-id gnus-current-headers))))
212  
213 (defun gnus-kill-file-kill-by-xref ()
214   "Kill by Xref."
215   (interactive)
216   (let ((xref (header-xref gnus-current-headers))
217         (start 0)
218         group)
219     (if xref
220         (while (string-match " \\([^ \t]+\\):" xref start)
221           (setq start (match-end 0))
222           (if (not (string= 
223                     (setq group 
224                           (substring xref (match-beginning 1) (match-end 1)))
225                     gnus-newsgroup-name))
226               (gnus-kill-file-enter-kill 
227                "Xref" (concat " " (regexp-quote group) ":"))))
228       (gnus-kill-file-enter-kill "Xref" ""))))
229
230 (defun gnus-kill-file-raise-followups-to-author (level)
231   "Raise score for all followups to the current author."
232   (interactive "p")
233   (let ((name (header-from gnus-current-headers))
234         string)
235     (save-excursion
236       (gnus-kill-set-kill-buffer)
237       (goto-char (point-min))
238       (setq name (read-string (concat "Add " level
239                                       " to followup articles to: ")
240                               (regexp-quote name)))
241       (setq 
242        string
243        (format
244         "(gnus-kill %S %S '(gnus-summary-temporarily-raise-by-thread %S))\n"
245         "From" name level))
246       (insert string)
247       (gnus-kill-file-apply-string string))
248     (message "Added temporary score file entry for followups to %s." name)))
249
250 (defun gnus-kill-file-apply-buffer ()
251   "Apply current buffer to current newsgroup."
252   (interactive)
253   (if (and gnus-current-kill-article
254            (get-buffer gnus-summary-buffer))
255       ;; Assume newsgroup is selected.
256       (gnus-kill-file-apply-string (buffer-string))
257     (ding) (message "No newsgroup is selected.")))
258
259 (defun gnus-kill-file-apply-string (string)
260   "Apply STRING to current newsgroup."
261   (interactive)
262   (let ((string (concat "(progn \n" string "\n)")))
263     (save-excursion
264       (save-window-excursion
265         (pop-to-buffer gnus-summary-buffer)
266         (eval (car (read-from-string string)))))))
267
268 (defun gnus-kill-file-apply-last-sexp ()
269   "Apply sexp before point in current buffer to current newsgroup."
270   (interactive)
271   (if (and gnus-current-kill-article
272            (get-buffer gnus-summary-buffer))
273       ;; Assume newsgroup is selected.
274       (let ((string
275              (buffer-substring
276               (save-excursion (forward-sexp -1) (point)) (point))))
277         (save-excursion
278           (save-window-excursion
279             (pop-to-buffer gnus-summary-buffer)
280             (eval (car (read-from-string string))))))
281     (ding) (message "No newsgroup is selected.")))
282
283 (defun gnus-kill-file-exit ()
284   "Save a kill file, then return to the previous buffer."
285   (interactive)
286   (save-buffer)
287   (let ((killbuf (current-buffer)))
288     ;; We don't want to return to article buffer.
289     (and (get-buffer gnus-article-buffer)
290          (bury-buffer gnus-article-buffer))
291     ;; Delete the KILL file windows.
292     (delete-windows-on killbuf)
293     ;; Restore last window configuration if available.
294     (and gnus-winconf-kill-file
295          (set-window-configuration gnus-winconf-kill-file))
296     (setq gnus-winconf-kill-file nil)
297     ;; Kill the KILL file buffer.  Suggested by tale@pawl.rpi.edu.
298     (kill-buffer killbuf)))
299
300 ;; For kill files
301
302 (defun gnus-Newsgroup-kill-file (newsgroup)
303   "Return the name of a kill file for NEWSGROUP.
304 If NEWSGROUP is nil, return the global kill file instead."
305   (cond ((or (null newsgroup)
306              (string-equal newsgroup ""))
307          ;; The global kill file is placed at top of the directory.
308          (expand-file-name gnus-kill-file-name
309                            (or gnus-kill-files-directory "~/News")))
310         (gnus-use-long-file-name
311          ;; Append ".KILL" to capitalized newsgroup name.
312          (expand-file-name (concat (gnus-capitalize-newsgroup newsgroup)
313                                    "." gnus-kill-file-name)
314                            (or gnus-kill-files-directory "~/News")))
315         (t
316          ;; Place "KILL" under the hierarchical directory.
317          (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
318                                    "/" gnus-kill-file-name)
319                            (or gnus-kill-files-directory "~/News")))))
320
321 (defun gnus-expunge (marks)
322   "Remove lines marked with MARKS."
323   (save-excursion
324     (set-buffer gnus-summary-buffer)
325     (gnus-summary-remove-lines-marked-with marks)))
326
327 (defun gnus-apply-kill-file-internal ()
328   "Apply a kill file to the current newsgroup.
329 Returns the number of articles marked as read."
330   (let* ((kill-files (list (gnus-newsgroup-kill-file nil)
331                            (gnus-newsgroup-kill-file gnus-newsgroup-name)))
332          (unreads (length gnus-newsgroup-unreads))
333          (gnus-summary-inhibit-highlight t)
334          beg)
335     (setq gnus-newsgroup-kill-headers nil)
336     (or gnus-newsgroup-headers-hashtb-by-number
337         (gnus-make-headers-hashtable-by-number))
338     ;; If there are any previously scored articles, we remove these
339     ;; from the `gnus-newsgroup-headers' list that the score functions
340     ;; will see. This is probably pretty wasteful when it comes to
341     ;; conses, but is, I think, faster than having to assq in every
342     ;; single score function.
343     (let ((files kill-files))
344       (while files
345         (if (file-exists-p (car files))
346             (let ((headers gnus-newsgroup-headers))
347               (if gnus-kill-killed
348                   (setq gnus-newsgroup-kill-headers
349                         (mapcar (lambda (header) (header-number header))
350                                 headers))
351                 (while headers
352                   (or (gnus-member-of-range 
353                        (header-number (car headers)) 
354                        gnus-newsgroup-killed)
355                       (setq gnus-newsgroup-kill-headers 
356                             (cons (header-number (car headers))
357                                   gnus-newsgroup-kill-headers)))
358                   (setq headers (cdr headers))))
359               (setq files nil))
360           (setq files (cdr files)))))
361     (if (not gnus-newsgroup-kill-headers)
362         ()
363       (save-excursion
364         (while kill-files
365           (if (not (file-exists-p (car kill-files)))
366               ()
367             (message "Processing kill file %s..." (car kill-files))
368             (find-file (car kill-files))
369             (gnus-add-current-to-buffer-list)
370             (goto-char (point-min))
371
372             (if (consp (condition-case nil (read (current-buffer)) 
373                          (error nil)))
374                 (gnus-kill-parse-gnus-kill-file)
375               (gnus-kill-parse-rn-kill-file))
376             
377             (message "Processing kill file %s...done" (car kill-files)))
378           (setq kill-files (cdr kill-files)))))
379
380     (if beg
381         (let ((nunreads (- unreads (length gnus-newsgroup-unreads))))
382           (or (eq nunreads 0)
383               (message "Marked %d articles as read" nunreads))
384           nunreads)
385       0)))
386
387 ;; Parse a Gnus killfile.
388 (defun gnus-score-insert-help (string alist idx)
389   (save-excursion
390     (pop-to-buffer "*Score Help*")
391     (buffer-disable-undo (current-buffer))
392     (erase-buffer)
393     (insert string ":\n\n")
394     (while alist
395       (insert (format " %c: %s\n" (car (car alist)) (nth idx (car alist))))
396       (setq alist (cdr alist)))))
397
398 (defun gnus-kill-parse-gnus-kill-file ()
399   (goto-char (point-min))
400   (gnus-kill-file-mode)
401   (let (beg form)
402     (while (progn 
403              (setq beg (point))
404              (setq form (condition-case () (read (current-buffer))
405                           (error nil))))
406       (or (listp form)
407           (error "Illegal kill entry (possibly rn kill file?): %s" form))
408       (if (or (eq (car form) 'gnus-kill)
409               (eq (car form) 'gnus-raise)
410               (eq (car form) 'gnus-lower))
411           (progn
412             (delete-region beg (point))
413             (insert (or (eval form) "")))
414         (save-excursion
415           (set-buffer gnus-summary-buffer)
416           (condition-case () (eval form) (error nil)))))
417     (and (buffer-modified-p) 
418          gnus-kill-save-kill-file
419          (save-buffer))
420     (set-buffer-modified-p nil)))
421
422 ;; Parse an rn killfile.
423 (defun gnus-kill-parse-rn-kill-file ()
424   (goto-char (point-min))
425   (gnus-kill-file-mode)
426   (let ((mod-to-header
427          '((?a . "")
428            (?h . "")
429            (?f . "from")
430            (?: . "subject")))
431         (com-to-com
432          '((?m . " ")
433            (?j . "X")))
434         pattern modifier commands)
435   (while (not (eobp))
436     (if (not (looking-at "[ \t]*/\\([^/]*\\)/\\([ahfcH]\\)?:\\([a-z=:]*\\)"))
437         ()
438       (setq pattern (buffer-substring (match-beginning 1) (match-end 1)))
439       (setq modifier (if (match-beginning 2) (char-after (match-beginning 2))
440                        ?s))
441       (setq commands (buffer-substring (match-beginning 3) (match-end 3)))
442
443       ;; The "f:+" command marks everything *but* the matches as read,
444       ;; so we simply first match everything as read, and then unmark
445       ;; PATTERN later. 
446       (and (string-match "\\+" commands)
447            (progn
448              (gnus-kill "from" ".")
449              (setq commands "m")))
450
451       (gnus-kill 
452        (or (cdr (assq modifier mod-to-header)) "subject")
453        pattern 
454        (if (string-match "m" commands) 
455            '(gnus-summary-mark-as-unread nil " ")
456          '(gnus-summary-mark-as-read nil "X")) 
457        nil t))
458     (forward-line 1))))
459
460 ;; Kill changes and new format by suggested by JWZ and Sudish Joseph
461 ;; <joseph@cis.ohio-state.edu>.  
462 (defun gnus-kill (field regexp &optional exe-command all silent)
463   "If FIELD of an article matches REGEXP, execute COMMAND.
464 Optional 1st argument COMMAND is default to
465         (gnus-summary-mark-as-read nil \"X\").
466 If optional 2nd argument ALL is non-nil, articles marked are also applied to.
467 If FIELD is an empty string (or nil), entire article body is searched for.
468 COMMAND must be a lisp expression or a string representing a key sequence."
469   ;; We don't want to change current point nor window configuration.
470   (save-excursion
471     (save-window-excursion
472       ;; Selected window must be summary buffer to execute keyboard
473       ;; macros correctly. See command_loop_1.
474       (switch-to-buffer gnus-summary-buffer 'norecord)
475       (goto-char (point-min))           ;From the beginning.
476       (let ((kill-list regexp)
477             (date (current-time-string))
478             (command (or exe-command '(gnus-summary-mark-as-read 
479                                        nil gnus-kill-file-mark)))
480             kill kdate prev)
481         (if (listp kill-list)
482             ;; It is a list.
483             (if (not (consp (cdr kill-list)))
484                 ;; It's on the form (regexp . date).
485                 (if (zerop (gnus-execute field (car kill-list) 
486                                          command nil (not all)))
487                     (if (> (gnus-days-between date (cdr kill-list))
488                            gnus-kill-expiry-days)
489                         (setq regexp nil))
490                   (setcdr kill-list date))
491               (while (setq kill (car kill-list))
492                 (if (consp kill)
493                     ;; It's a temporary kill.
494                     (progn
495                       (setq kdate (cdr kill))
496                       (if (zerop (gnus-execute 
497                                   field (car kill) command nil (not all)))
498                           (if (> (gnus-days-between date kdate)
499                                  gnus-kill-expiry-days)
500                               ;; Time limit has been exceeded, so we
501                               ;; remove the match.
502                               (if prev
503                                   (setcdr prev (cdr kill-list))
504                                 (setq regexp (cdr regexp))))
505                         ;; Successful kill. Set the date to today.
506                         (setcdr kill date)))
507                   ;; It's a permanent kill.
508                   (gnus-execute field kill command nil (not all)))
509                 (setq prev kill-list)
510                 (setq kill-list (cdr kill-list))))
511           (gnus-execute field kill-list command nil (not all))))))
512   (if (and (eq major-mode 'gnus-kill-file-mode) regexp (not silent))
513       (gnus-pp-gnus-kill
514        (nconc (list 'gnus-kill field 
515                     (if (consp regexp) (list 'quote regexp) regexp))
516               (if (or exe-command all) (list (list 'quote exe-command)))
517               (if all (list t) nil)))))
518
519 (defun gnus-pp-gnus-kill (object)
520   (if (or (not (consp (nth 2 object)))
521           (not (consp (cdr (nth 2 object))))
522           (and (eq 'quote (car (nth 2 object)))
523                (not (consp (cdr (car (cdr (nth 2 object))))))))
524       (concat "\n" (prin1-to-string object))
525     (save-excursion
526       (set-buffer (get-buffer-create "*Gnus PP*"))
527       (buffer-disable-undo (current-buffer))
528       (erase-buffer)
529       (insert (format "\n(%S %S\n  '(" (nth 0 object) (nth 1 object)))
530       (let ((klist (car (cdr (nth 2 object))))
531             (first t))
532         (while klist
533           (insert (if first (progn (setq first nil) "")  "\n    ")
534                   (prin1-to-string (car klist)))
535           (setq klist (cdr klist))))
536       (insert ")")
537       (and (nth 3 object)
538            (insert "\n  " 
539                    (if (and (consp (nth 3 object))
540                             (not (eq 'quote (car (nth 3 object))))) 
541                        "'" "")
542                    (prin1-to-string (nth 3 object))))
543       (and (nth 4 object)
544            (insert "\n  t"))
545       (insert ")")
546       (prog1
547           (buffer-substring (point-min) (point-max))
548         (kill-buffer (current-buffer))))))
549
550 (defun gnus-execute-1 (function regexp form header)
551   (save-excursion
552     (let (did-kill)
553       (if (null header)
554           nil                           ;Nothing to do.
555         (if function
556             ;; Compare with header field.
557             (let (value)
558               (and header
559                    (progn
560                      (setq value (funcall function header))
561                      ;; Number (Lines:) or symbol must be converted to string.
562                      (or (stringp value)
563                          (setq value (prin1-to-string value)))
564                      (setq did-kill (string-match regexp value)))
565                    (if (stringp form)   ;Keyboard macro.
566                        (execute-kbd-macro form)
567                      (funcall form))))
568           ;; Search article body.
569           (let ((gnus-current-article nil) ;Save article pointer.
570                 (gnus-last-article nil)
571                 (gnus-break-pages nil)  ;No need to break pages.
572                 (gnus-mark-article-hook nil)) ;Inhibit marking as read.
573             (message "Searching for article: %d..." (header-number header))
574             (gnus-article-setup-buffer)
575             (gnus-article-prepare (header-number header) t)
576             (if (save-excursion
577                   (set-buffer gnus-article-buffer)
578                   (goto-char (point-min))
579                   (setq did-kill (re-search-forward regexp nil t)))
580                 (if (stringp form)      ;Keyboard macro.
581                     (execute-kbd-macro form)
582                   (eval form))))))
583       did-kill)))
584
585 (defun gnus-execute (field regexp form &optional backward ignore-marked)
586   "If FIELD of article header matches REGEXP, execute lisp FORM (or a string).
587 If FIELD is an empty string (or nil), entire article body is searched for.
588 If optional 1st argument BACKWARD is non-nil, do backward instead.
589 If optional 2nd argument IGNORE-MARKED is non-nil, articles which are
590 marked as read or ticked are ignored."
591   (save-excursion
592     (let ((killed-no 0)
593           function article)
594       (if (or (null field) (string-equal field ""))
595           (setq function nil)
596         ;; Get access function of header filed.
597         (setq function (intern-soft (concat "gnus-header-" (downcase field))))
598         (if (and function (fboundp function))
599             (setq function (symbol-function function))
600           (error "Unknown header field: \"%s\"" field))
601         ;; Make FORM funcallable.
602         (if (and (listp form) (not (eq (car form) 'lambda)))
603             (setq form (list 'lambda nil form))))
604       ;; Starting from the current article.
605       (while (or (and (not article)
606                       (setq article (gnus-summary-article-number))
607                       t)
608                  (setq article 
609                        (gnus-summary-search-subject 
610                         backward (not ignore-marked))))
611         (and (or (null gnus-newsgroup-kill-headers)
612                  (memq article gnus-newsgroup-kill-headers))
613              (gnus-execute-1 function regexp form 
614                              (gnus-get-header-by-number article))
615              (setq killed-no (1+ killed-no))))
616       killed-no)))
617