Output alists with dotted pair notation in .dir-locals.el
[emacs.git] / lisp / gnus / gnus-kill.el
blob60732c11d54eadcd6e5a6a7c2adf0761678e2a02
1 ;;; gnus-kill.el --- kill commands for Gnus
3 ;; Copyright (C) 1995-2018 Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;;; Code:
28 (require 'gnus)
29 (require 'gnus-art)
30 (require 'gnus-range)
32 (defcustom gnus-kill-file-mode-hook nil
33 "Hook for Gnus kill file mode."
34 :group 'gnus-score-kill
35 :type 'hook)
37 (defcustom gnus-kill-expiry-days 7
38 "Number of days before expiring unused kill file entries."
39 :group 'gnus-score-kill
40 :group 'gnus-score-expire
41 :type 'integer)
43 (defcustom gnus-kill-save-kill-file nil
44 "If non-nil, will save kill files after processing them."
45 :group 'gnus-score-kill
46 :type 'boolean)
48 (defvar gnus-winconf-kill-file nil
49 "What does this do, Lars?
50 I don't know, Per.")
52 (defcustom gnus-kill-killed t
53 "If non-nil, Gnus will apply kill files to already killed articles.
54 If it is nil, Gnus will never apply kill files to articles that have
55 already been through the scoring process, which might very well save lots
56 of time."
57 :group 'gnus-score-kill
58 :type 'boolean)
62 (defmacro gnus-raise (field expression level)
63 `(gnus-kill ,field ,expression
64 (function (gnus-summary-raise-score ,level)) t))
66 (defmacro gnus-lower (field expression level)
67 `(gnus-kill ,field ,expression
68 (function (gnus-summary-raise-score (- ,level))) t))
70 ;;;
71 ;;; Gnus Kill File Mode
72 ;;;
74 (defvar gnus-kill-file-mode-map
75 (let ((map (make-sparse-keymap)))
76 (set-keymap-parent map emacs-lisp-mode-map)
77 (gnus-define-keymap map
78 "\C-c\C-k\C-s" gnus-kill-file-kill-by-subject
79 "\C-c\C-k\C-a" gnus-kill-file-kill-by-author
80 "\C-c\C-k\C-t" gnus-kill-file-kill-by-thread
81 "\C-c\C-k\C-x" gnus-kill-file-kill-by-xref
82 "\C-c\C-a" gnus-kill-file-apply-buffer
83 "\C-c\C-e" gnus-kill-file-apply-last-sexp
84 "\C-c\C-c" gnus-kill-file-exit)
85 map))
87 (define-derived-mode gnus-kill-file-mode emacs-lisp-mode "Kill"
88 "Major mode for editing kill files.
90 If you are using this mode - you probably shouldn't. Kill files
91 perform badly and paint with a pretty broad brush. Score files, on
92 the other hand, are vastly faster (40x speedup) and give you more
93 control over what to do.
95 In addition to Emacs-Lisp Mode, the following commands are available:
97 \\{gnus-kill-file-mode-map}
99 A kill file contains Lisp expressions to be applied to a selected
100 newsgroup. The purpose is to mark articles as read on the basis of
101 some set of regexps. A global kill file is applied to every newsgroup,
102 and a local kill file is applied to a specified newsgroup. Since a
103 global kill file is applied to every newsgroup, for better performance
104 use a local one.
106 A kill file can contain any kind of Emacs Lisp expressions expected
107 to be evaluated in the Summary buffer. Writing Lisp programs for this
108 purpose is not so easy because the internal working of Gnus must be
109 well-known. For this reason, Gnus provides a general function which
110 does this easily for non-Lisp programmers.
112 The `gnus-kill' function executes commands available in Summary Mode
113 by their key sequences. `gnus-kill' should be called with FIELD,
114 REGEXP and optional COMMAND and ALL. FIELD is a string representing
115 the header field or an empty string. If FIELD is an empty string, the
116 entire article body is searched for. REGEXP is a string which is
117 compared with FIELD value. COMMAND is a string representing a valid
118 key sequence in Summary mode or Lisp expression. COMMAND defaults to
119 \(gnus-summary-mark-as-read nil \"X\"). Make sure that COMMAND is
120 executed in the Summary buffer. If the second optional argument ALL
121 is non-nil, the COMMAND is applied to articles which are already
122 marked as read or unread. Articles which are marked are skipped over
123 by default.
125 For example, if you want to mark articles of which subjects contain
126 the string `AI' as read, a possible kill file may look like:
128 (gnus-kill \"Subject\" \"AI\")
130 If you want to mark articles with `D' instead of `X', you can use
131 the following expression:
133 (gnus-kill \"Subject\" \"AI\" \"d\")
135 In this example it is assumed that the command
136 `gnus-summary-mark-as-read-forward' is assigned to `d' in Summary Mode.
138 It is possible to delete unnecessary headers which are marked with
139 `X' in a kill file as follows:
141 (gnus-expunge \"X\")
143 If the Summary buffer is empty after applying kill files, Gnus will
144 exit the selected newsgroup normally. If headers which are marked
145 with `D' are deleted in a kill file, it is impossible to read articles
146 which are marked as read in the previous Gnus sessions. Marks other
147 than `D' should be used for articles which should really be deleted.
149 Entry to this mode calls emacs-lisp-mode-hook and
150 gnus-kill-file-mode-hook with no arguments, if that value is non-nil.")
152 (defun gnus-kill-file-edit-file (newsgroup)
153 "Begin editing a kill file for NEWSGROUP.
154 If NEWSGROUP is nil, the global kill file is selected."
155 (interactive "sNewsgroup: ")
156 (let ((file (gnus-newsgroup-kill-file newsgroup)))
157 (gnus-make-directory (file-name-directory file))
158 ;; Save current window configuration if this is first invocation.
159 (or (and (get-file-buffer file)
160 (get-buffer-window (get-file-buffer file)))
161 (setq gnus-winconf-kill-file (current-window-configuration)))
162 ;; Hack windows.
163 (let ((buffer (find-file-noselect file)))
164 (cond ((get-buffer-window buffer)
165 (pop-to-buffer buffer))
166 ((derived-mode-p 'gnus-group-mode)
167 (gnus-configure-windows 'group) ;Take all windows.
168 (pop-to-buffer buffer))
169 ((derived-mode-p 'gnus-summary-mode)
170 (gnus-configure-windows 'article)
171 (pop-to-buffer gnus-article-buffer)
172 (bury-buffer gnus-article-buffer)
173 (switch-to-buffer buffer))
174 (t ;No good rules.
175 (find-file-other-window file))))
176 (gnus-kill-file-mode)))
178 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
179 (defun gnus-kill-set-kill-buffer ()
180 (let* ((file (gnus-newsgroup-kill-file gnus-newsgroup-name))
181 (buffer (find-file-noselect file)))
182 (set-buffer buffer)
183 (gnus-kill-file-mode)
184 (bury-buffer buffer)))
186 (defun gnus-kill-file-enter-kill (field regexp &optional dont-move)
187 ;; Enter kill file entry.
188 ;; FIELD: String containing the name of the header field to kill.
189 ;; REGEXP: The string to kill.
190 (save-excursion
191 (let (string)
192 (unless (derived-mode-p 'gnus-kill-file-mode)
193 (gnus-kill-set-kill-buffer))
194 (unless dont-move
195 (goto-char (point-max)))
196 (insert (setq string (format "(gnus-kill %S %S)\n" field regexp)))
197 (gnus-kill-file-apply-string string))))
199 (defun gnus-kill-file-kill-by-subject ()
200 "Kill by subject."
201 (interactive)
202 (gnus-kill-file-enter-kill
203 "Subject"
204 (if (vectorp gnus-current-headers)
205 (regexp-quote
206 (gnus-simplify-subject (mail-header-subject gnus-current-headers)))
210 (defun gnus-kill-file-kill-by-author ()
211 "Kill by author."
212 (interactive)
213 (gnus-kill-file-enter-kill
214 "From"
215 (if (vectorp gnus-current-headers)
216 (regexp-quote (mail-header-from gnus-current-headers))
217 "") t))
219 (defun gnus-kill-file-kill-by-thread ()
220 "Kill by author."
221 (interactive)
222 (gnus-kill-file-enter-kill
223 "References"
224 (if (vectorp gnus-current-headers)
225 (regexp-quote (mail-header-id gnus-current-headers))
226 "")))
228 (defun gnus-kill-file-kill-by-xref ()
229 "Kill by Xref."
230 (interactive)
231 (let ((xref (and (vectorp gnus-current-headers)
232 (mail-header-xref gnus-current-headers)))
233 (start 0)
234 group)
235 (if xref
236 (while (string-match " \\([^ \t]+\\):" xref start)
237 (setq start (match-end 0))
238 (when (not (string=
239 (setq group
240 (substring xref (match-beginning 1) (match-end 1)))
241 gnus-newsgroup-name))
242 (gnus-kill-file-enter-kill
243 "Xref" (concat " " (regexp-quote group) ":") t)))
244 (gnus-kill-file-enter-kill "Xref" "" t))))
246 (defun gnus-kill-file-raise-followups-to-author (level)
247 "Raise score for all followups to the current author."
248 (interactive "p")
249 (let ((name (mail-header-from gnus-current-headers))
250 string)
251 (save-excursion
252 (gnus-kill-set-kill-buffer)
253 (goto-char (point-min))
254 (setq name (read-string (concat "Add " level
255 " to followup articles to: ")
256 (regexp-quote name)))
257 (setq
258 string
259 (format
260 "(gnus-kill %S %S '(gnus-summary-temporarily-raise-by-thread %S))\n"
261 "From" name level))
262 (insert string)
263 (gnus-kill-file-apply-string string))
264 (gnus-message
265 6 "Added temporary score file entry for followups to %s." name)))
267 (defun gnus-kill-file-apply-buffer ()
268 "Apply current buffer to current newsgroup."
269 (interactive)
270 (if (and gnus-current-kill-article
271 (get-buffer gnus-summary-buffer))
272 ;; Assume newsgroup is selected.
273 (gnus-kill-file-apply-string (buffer-string))
274 (ding) (gnus-message 2 "No newsgroup is selected.")))
276 (defun gnus-kill-file-apply-string (string)
277 "Apply STRING to current newsgroup."
278 (interactive)
279 (let ((string (concat "(progn \n" string "\n)")))
280 (save-excursion
281 (save-window-excursion
282 (pop-to-buffer gnus-summary-buffer)
283 (eval (car (read-from-string string)))))))
285 (defun gnus-kill-file-apply-last-sexp ()
286 "Apply sexp before point in current buffer to current newsgroup."
287 (interactive)
288 (if (and gnus-current-kill-article
289 (get-buffer gnus-summary-buffer))
290 ;; Assume newsgroup is selected.
291 (let ((string
292 (buffer-substring
293 (save-excursion (forward-sexp -1) (point)) (point))))
294 (save-excursion
295 (save-window-excursion
296 (pop-to-buffer gnus-summary-buffer)
297 (eval (car (read-from-string string))))))
298 (ding) (gnus-message 2 "No newsgroup is selected.")))
300 (defun gnus-kill-file-exit ()
301 "Save a kill file, then return to the previous buffer."
302 (interactive)
303 (save-buffer)
304 (let ((killbuf (current-buffer)))
305 ;; We don't want to return to article buffer.
306 (when (get-buffer gnus-article-buffer)
307 (bury-buffer gnus-article-buffer))
308 ;; Delete the KILL file windows.
309 (delete-windows-on killbuf)
310 ;; Restore last window configuration if available.
311 (when gnus-winconf-kill-file
312 (set-window-configuration gnus-winconf-kill-file))
313 (setq gnus-winconf-kill-file nil)
314 ;; Kill the KILL file buffer. Suggested by tale@pawl.rpi.edu.
315 (kill-buffer killbuf)))
317 ;; For kill files
319 (defun gnus-expunge (marks)
320 "Remove lines marked with MARKS."
321 (with-current-buffer gnus-summary-buffer
322 (gnus-summary-limit-to-marks marks 'reverse)))
324 (defun gnus-apply-kill-file-unless-scored ()
325 "Apply .KILL file, unless a .SCORE file for the same newsgroup exists."
326 (cond ((file-exists-p (gnus-score-file-name gnus-newsgroup-name))
327 ;; Ignores global KILL.
328 (when (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name))
329 (gnus-message 3 "Note: Ignoring %s.KILL; preferring .SCORE"
330 gnus-newsgroup-name))
332 ((or (file-exists-p (gnus-newsgroup-kill-file nil))
333 (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
334 (gnus-apply-kill-file-internal))
336 0)))
338 (defun gnus-apply-kill-file-internal ()
339 "Apply a kill file to the current newsgroup.
340 Returns the number of articles marked as read."
341 (let* ((kill-files (list (gnus-newsgroup-kill-file nil)
342 (gnus-newsgroup-kill-file gnus-newsgroup-name)))
343 (unreads (length gnus-newsgroup-unreads))
344 (gnus-summary-inhibit-highlight t)
345 beg)
346 (setq gnus-newsgroup-kill-headers nil)
347 ;; If there are any previously scored articles, we remove these
348 ;; from the `gnus-newsgroup-headers' list that the score functions
349 ;; will see. This is probably pretty wasteful when it comes to
350 ;; conses, but is, I think, faster than having to assq in every
351 ;; single score function.
352 (let ((files kill-files))
353 (while files
354 (if (file-exists-p (car files))
355 (let ((headers gnus-newsgroup-headers))
356 (if gnus-kill-killed
357 (setq gnus-newsgroup-kill-headers
358 (mapcar (lambda (header) (mail-header-number header))
359 headers))
360 (while headers
361 (unless (gnus-member-of-range
362 (mail-header-number (car headers))
363 gnus-newsgroup-killed)
364 (push (mail-header-number (car headers))
365 gnus-newsgroup-kill-headers))
366 (setq headers (cdr headers))))
367 (setq files nil))
368 (setq files (cdr files)))))
369 (if (not gnus-newsgroup-kill-headers)
371 (save-window-excursion
372 (save-excursion
373 (while kill-files
374 (if (not (file-exists-p (car kill-files)))
376 (gnus-message 6 "Processing kill file %s..." (car kill-files))
377 (find-file (car kill-files))
378 (goto-char (point-min))
380 (if (consp (ignore-errors (read (current-buffer))))
381 (gnus-kill-parse-gnus-kill-file)
382 (gnus-kill-parse-rn-kill-file))
384 (gnus-message
385 6 "Processing kill file %s...done" (car kill-files)))
386 (setq kill-files (cdr kill-files)))))
388 (gnus-set-mode-line 'summary)
390 (if beg
391 (let ((nunreads (- unreads (length gnus-newsgroup-unreads))))
392 (or (eq nunreads 0)
393 (gnus-message 6 "Marked %d articles as read" nunreads))
394 nunreads)
395 0))))
397 ;; Parse a Gnus killfile.
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 (ignore-errors (read (current-buffer)))))
405 (unless (listp form)
406 (error "Invalid kill entry (possibly rn kill file?): %s" form))
407 (if (or (eq (car form) 'gnus-kill)
408 (eq (car form) 'gnus-raise)
409 (eq (car form) 'gnus-lower))
410 (progn
411 (delete-region beg (point))
412 (insert (or (eval form) "")))
413 (with-current-buffer gnus-summary-buffer
414 (ignore-errors (eval form)))))
415 (and (buffer-modified-p)
416 gnus-kill-save-kill-file
417 (save-buffer))
418 (set-buffer-modified-p nil)))
420 ;; Parse an rn killfile.
421 (defun gnus-kill-parse-rn-kill-file ()
422 (goto-char (point-min))
423 (gnus-kill-file-mode)
424 (let ((mod-to-header
425 '((?a . "")
426 (?h . "")
427 (?f . "from")
428 (?: . "subject")))
429 ;;(com-to-com
430 ;; '((?m . " ")
431 ;; (?j . "X")))
432 pattern modifier commands)
433 (while (not (eobp))
434 (if (not (looking-at "[ \t]*/\\([^/]*\\)/\\([ahfcH]\\)?:\\([a-z=:]*\\)"))
436 (setq pattern (buffer-substring (match-beginning 1) (match-end 1)))
437 (setq modifier (if (match-beginning 2) (char-after (match-beginning 2))
438 ?s))
439 (setq commands (buffer-substring (match-beginning 3) (match-end 3)))
441 ;; The "f:+" command marks everything *but* the matches as read,
442 ;; so we simply first match everything as read, and then unmark
443 ;; PATTERN later.
444 (when (string-match "\\+" commands)
445 (gnus-kill "from" ".")
446 (setq commands "m"))
448 (gnus-kill
449 (or (cdr (assq modifier mod-to-header)) "subject")
450 pattern
451 (if (string-match "m" commands)
452 '(gnus-summary-tick-article nil " ")
453 '(gnus-summary-mark-as-read nil "X"))
454 nil t))
455 (forward-line 1))))
457 ;; Kill changes and new format by suggested by JWZ and Sudish Joseph
458 ;; <joseph@cis.ohio-state.edu>.
459 (defun gnus-kill (field regexp &optional exe-command all silent)
460 "If FIELD of an article matches REGEXP, execute COMMAND.
461 Optional 1st argument COMMAND is default to
462 (gnus-summary-mark-as-read nil \"X\").
463 If optional 2nd argument ALL is non-nil, articles marked are also applied to.
464 If FIELD is an empty string (or nil), entire article body is searched for.
465 COMMAND must be a Lisp expression or a string representing a key sequence."
466 ;; We don't want to change current point nor window configuration.
467 (let ((old-buffer (current-buffer)))
468 (save-excursion
469 (save-window-excursion
470 ;; Selected window must be summary buffer to execute keyboard
471 ;; macros correctly. See command_loop_1.
472 (switch-to-buffer gnus-summary-buffer 'norecord)
473 (goto-char (point-min)) ;From the beginning.
474 (let ((kill-list regexp)
475 (date (current-time-string))
476 (command (or exe-command '(gnus-summary-mark-as-read
477 nil gnus-kill-file-mark)))
478 kill kdate prev)
479 (if (listp kill-list)
480 ;; It is a list.
481 (if (not (consp (cdr kill-list)))
482 ;; It's of the form (regexp . date).
483 (if (zerop (gnus-execute field (car kill-list)
484 command nil (not all)))
485 (when (> (days-between date (cdr kill-list))
486 gnus-kill-expiry-days)
487 (setq regexp nil))
488 (setcdr kill-list date))
489 (while (setq kill (car kill-list))
490 (if (consp kill)
491 ;; It's a temporary kill.
492 (progn
493 (setq kdate (cdr kill))
494 (if (zerop (gnus-execute
495 field (car kill) command nil (not all)))
496 (when (> (days-between date kdate)
497 gnus-kill-expiry-days)
498 ;; Time limit has been exceeded, so we
499 ;; remove the match.
500 (if prev
501 (setcdr prev (cdr kill-list))
502 (setq regexp (cdr regexp))))
503 ;; Successful kill. Set the date to today.
504 (setcdr kill date)))
505 ;; It's a permanent kill.
506 (gnus-execute field kill command nil (not all)))
507 (setq prev kill-list)
508 (setq kill-list (cdr kill-list))))
509 (gnus-execute field kill-list command nil (not all))))))
510 (switch-to-buffer old-buffer)
511 (when (and (derived-mode-p 'gnus-kill-file-mode) regexp (not silent))
512 (gnus-pp-gnus-kill
513 (nconc (list 'gnus-kill field
514 (if (consp regexp) (list 'quote regexp) regexp))
515 (when (or exe-command all)
516 (list (list 'quote exe-command)))
517 (if all (list t) nil))))))
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 (cdadr (nth 2 object))))))
524 (concat "\n" (gnus-prin1-to-string object))
525 (with-current-buffer (gnus-get-buffer-create "*Gnus PP*")
526 (buffer-disable-undo)
527 (erase-buffer)
528 (insert (format "\n(%S %S\n '(" (nth 0 object) (nth 1 object)))
529 (let ((klist (cadr (nth 2 object)))
530 (first t))
531 (while klist
532 (insert (if first (progn (setq first nil) "") "\n ")
533 (gnus-prin1-to-string (car klist)))
534 (setq klist (cdr klist))))
535 (insert ")")
536 (and (nth 3 object)
537 (insert "\n "
538 (if (and (consp (nth 3 object))
539 (not (eq 'quote (car (nth 3 object)))))
540 "'" "")
541 (gnus-prin1-to-string (nth 3 object))))
542 (when (nth 4 object)
543 (insert "\n t"))
544 (insert ")")
545 (prog1
546 (buffer-string)
547 (kill-buffer (current-buffer))))))
549 (defun gnus-execute-1 (function regexp form header)
550 (save-excursion
551 (let (did-kill)
552 (if (null header)
553 nil ;Nothing to do.
554 (if function
555 ;; Compare with header field.
556 (let (value)
557 (and header
558 (progn
559 (setq value (funcall function header))
560 ;; Number (Lines:) or symbol must be converted to string.
561 (unless (stringp value)
562 (setq value (gnus-prin1-to-string value)))
563 (setq did-kill (string-match regexp value)))
564 (cond ((stringp form) ;Keyboard macro.
565 (execute-kbd-macro form))
566 ((functionp form)
567 (funcall form))
569 (eval form)))))
570 ;; Search article body.
571 (let ((gnus-current-article nil) ;Save article pointer.
572 (gnus-last-article nil)
573 (gnus-break-pages nil) ;No need to break pages.
574 (gnus-mark-article-hook nil)) ;Inhibit marking as read.
575 (gnus-message
576 6 "Searching for article: %d..." (mail-header-number header))
577 (gnus-article-setup-buffer)
578 (gnus-article-prepare (mail-header-number header) t)
579 (when (with-current-buffer gnus-article-buffer
580 (goto-char (point-min))
581 (setq did-kill (re-search-forward regexp nil t)))
582 (cond ((stringp form) ;Keyboard macro.
583 (execute-kbd-macro form))
584 ((functionp form)
585 (funcall form))
587 (eval form)))))))
588 did-kill)))
590 (defun gnus-execute (field regexp form &optional backward unread)
591 "If FIELD of article header matches REGEXP, execute Lisp FORM (or a string).
592 If FIELD is an empty string (or nil), entire article body is searched for.
593 If optional 1st argument BACKWARD is non-nil, do backward instead.
594 If optional 2nd argument UNREAD is non-nil, articles which are
595 marked as read or ticked are ignored."
596 (save-excursion
597 (let ((killed-no 0)
598 function article header extras)
599 (cond
600 ;; Search body.
601 ((or (null field)
602 (string-equal field ""))
603 (setq function nil))
604 ;; Get access function of header field.
605 ((cond ((fboundp
606 (setq function
607 (intern-soft
608 (concat "mail-header-" (downcase field)))))
609 (setq function `(lambda (h) (,function h))))
610 ((when (setq extras
611 (member (downcase field)
612 (mapcar (lambda (header)
613 (downcase (symbol-name header)))
614 gnus-extra-headers)))
615 (setq function
616 `(lambda (h)
617 (gnus-extra-header
618 (quote ,(nth (- (length gnus-extra-headers)
619 (length extras))
620 gnus-extra-headers))
621 h)))))))
622 ;; Signal error.
624 (error "Unknown header field: \"%s\"" field)))
625 ;; Starting from the current article.
626 (while (or
627 ;; First article.
628 (and (not article)
629 (setq article (gnus-summary-article-number)))
630 ;; Find later articles.
631 (setq article
632 (gnus-summary-search-forward unread nil backward)))
633 (and (or (null gnus-newsgroup-kill-headers)
634 (memq article gnus-newsgroup-kill-headers))
635 (vectorp (setq header (gnus-summary-article-header article)))
636 (gnus-execute-1 function regexp form header)
637 (setq killed-no (1+ killed-no))))
638 ;; Return the number of killed articles.
639 killed-no)))
641 ;;;###autoload
642 (defalias 'gnus-batch-kill 'gnus-batch-score)
643 ;;;###autoload
644 (defun gnus-batch-score ()
645 "Run batched scoring.
646 Usage: emacs -batch -l ~/.emacs -l gnus -f gnus-batch-score"
647 (interactive)
648 (let* ((gnus-newsrc-options-n
649 (gnus-newsrc-parse-options
650 (concat "options -n "
651 (mapconcat 'identity command-line-args-left " "))))
652 (gnus-expert-user t)
653 (mail-sources nil)
654 (gnus-use-dribble-file nil)
655 (gnus-batch-mode t)
656 info group newsrc unread
657 ;; Disable verbose message.
658 gnus-novice-user gnus-large-newsgroup
659 gnus-options-subscribe gnus-auto-subscribed-groups
660 gnus-options-not-subscribe)
661 ;; Eat all arguments.
662 (setq command-line-args-left nil)
663 (gnus-slave)
664 ;; Apply kills to specified newsgroups in command line arguments.
665 (setq newsrc (cdr gnus-newsrc-alist))
666 (while (setq info (pop newsrc))
667 (setq group (gnus-info-group info)
668 unread (gnus-group-unread group))
669 (when (and (<= (gnus-info-level info) gnus-level-subscribed)
670 (and unread
671 (or (eq unread t)
672 (not (zerop unread)))))
673 (ignore-errors
674 (gnus-summary-read-group group nil t nil t))
675 (when (eq (current-buffer) (get-buffer gnus-summary-buffer))
676 (gnus-summary-exit))))
677 ;; Exit Emacs.
678 (switch-to-buffer gnus-group-buffer)
679 (gnus-group-save-newsrc)))
681 (provide 'gnus-kill)
683 ;;; gnus-kill.el ends here