Mercurial > emacs
comparison lisp/gnus-kill.el @ 13401:178d730efae2
entered into RCS
author | Lars Magne Ingebrigtsen <larsi@gnus.org> |
---|---|
date | Sat, 04 Nov 1995 03:54:42 +0000 |
parents | |
children | 83f275dcd93a |
comparison
equal
deleted
inserted
replaced
13400:4a57cda2a39a | 13401:178d730efae2 |
---|---|
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 | |
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 (or (eq major-mode 'gnus-kill-file-mode) | |
189 (gnus-kill-set-kill-buffer)) | |
190 (current-buffer) | |
191 (goto-char (point-max)) | |
192 (insert (setq string (format "(gnus-kill %S %S)\n" field regexp))) | |
193 (gnus-kill-file-apply-string string)))) | |
194 | |
195 (defun gnus-kill-file-kill-by-subject () | |
196 "Kill by subject." | |
197 (interactive) | |
198 (gnus-kill-file-enter-kill | |
199 "Subject" | |
200 (if (vectorp gnus-current-headers) | |
201 (regexp-quote | |
202 (gnus-simplify-subject (mail-header-subject gnus-current-headers))) | |
203 ""))) | |
204 | |
205 (defun gnus-kill-file-kill-by-author () | |
206 "Kill by author." | |
207 (interactive) | |
208 (gnus-kill-file-enter-kill | |
209 "From" | |
210 (if (vectorp gnus-current-headers) | |
211 (regexp-quote (mail-header-from gnus-current-headers)) | |
212 ""))) | |
213 | |
214 (defun gnus-kill-file-kill-by-thread () | |
215 "Kill by author." | |
216 (interactive "p") | |
217 (gnus-kill-file-enter-kill | |
218 "References" | |
219 (if (vectorp gnus-current-headers) | |
220 (regexp-quote (mail-header-id gnus-current-headers)) | |
221 ""))) | |
222 | |
223 (defun gnus-kill-file-kill-by-xref () | |
224 "Kill by Xref." | |
225 (interactive) | |
226 (let ((xref (and (vectorp gnus-current-headers) | |
227 (mail-header-xref gnus-current-headers))) | |
228 (start 0) | |
229 group) | |
230 (if xref | |
231 (while (string-match " \\([^ \t]+\\):" xref start) | |
232 (setq start (match-end 0)) | |
233 (if (not (string= | |
234 (setq group | |
235 (substring xref (match-beginning 1) (match-end 1))) | |
236 gnus-newsgroup-name)) | |
237 (gnus-kill-file-enter-kill | |
238 "Xref" (concat " " (regexp-quote group) ":")))) | |
239 (gnus-kill-file-enter-kill "Xref" "")))) | |
240 | |
241 (defun gnus-kill-file-raise-followups-to-author (level) | |
242 "Raise score for all followups to the current author." | |
243 (interactive "p") | |
244 (let ((name (mail-header-from gnus-current-headers)) | |
245 string) | |
246 (save-excursion | |
247 (gnus-kill-set-kill-buffer) | |
248 (goto-char (point-min)) | |
249 (setq name (read-string (concat "Add " level | |
250 " to followup articles to: ") | |
251 (regexp-quote name))) | |
252 (setq | |
253 string | |
254 (format | |
255 "(gnus-kill %S %S '(gnus-summary-temporarily-raise-by-thread %S))\n" | |
256 "From" name level)) | |
257 (insert string) | |
258 (gnus-kill-file-apply-string string)) | |
259 (message "Added temporary score file entry for followups to %s." name))) | |
260 | |
261 (defun gnus-kill-file-apply-buffer () | |
262 "Apply current buffer to current newsgroup." | |
263 (interactive) | |
264 (if (and gnus-current-kill-article | |
265 (get-buffer gnus-summary-buffer)) | |
266 ;; Assume newsgroup is selected. | |
267 (gnus-kill-file-apply-string (buffer-string)) | |
268 (ding) (message "No newsgroup is selected."))) | |
269 | |
270 (defun gnus-kill-file-apply-string (string) | |
271 "Apply STRING to current newsgroup." | |
272 (interactive) | |
273 (let ((string (concat "(progn \n" string "\n)"))) | |
274 (save-excursion | |
275 (save-window-excursion | |
276 (pop-to-buffer gnus-summary-buffer) | |
277 (eval (car (read-from-string string))))))) | |
278 | |
279 (defun gnus-kill-file-apply-last-sexp () | |
280 "Apply sexp before point in current buffer to current newsgroup." | |
281 (interactive) | |
282 (if (and gnus-current-kill-article | |
283 (get-buffer gnus-summary-buffer)) | |
284 ;; Assume newsgroup is selected. | |
285 (let ((string | |
286 (buffer-substring | |
287 (save-excursion (forward-sexp -1) (point)) (point)))) | |
288 (save-excursion | |
289 (save-window-excursion | |
290 (pop-to-buffer gnus-summary-buffer) | |
291 (eval (car (read-from-string string)))))) | |
292 (ding) (message "No newsgroup is selected."))) | |
293 | |
294 (defun gnus-kill-file-exit () | |
295 "Save a kill file, then return to the previous buffer." | |
296 (interactive) | |
297 (save-buffer) | |
298 (let ((killbuf (current-buffer))) | |
299 ;; We don't want to return to article buffer. | |
300 (and (get-buffer gnus-article-buffer) | |
301 (bury-buffer gnus-article-buffer)) | |
302 ;; Delete the KILL file windows. | |
303 (delete-windows-on killbuf) | |
304 ;; Restore last window configuration if available. | |
305 (and gnus-winconf-kill-file | |
306 (set-window-configuration gnus-winconf-kill-file)) | |
307 (setq gnus-winconf-kill-file nil) | |
308 ;; Kill the KILL file buffer. Suggested by tale@pawl.rpi.edu. | |
309 (kill-buffer killbuf))) | |
310 | |
311 ;; For kill files | |
312 | |
313 (defun gnus-Newsgroup-kill-file (newsgroup) | |
314 "Return the name of a kill file for NEWSGROUP. | |
315 If NEWSGROUP is nil, return the global kill file instead." | |
316 (cond ((or (null newsgroup) | |
317 (string-equal newsgroup "")) | |
318 ;; The global kill file is placed at top of the directory. | |
319 (expand-file-name gnus-kill-file-name | |
320 (or gnus-kill-files-directory "~/News"))) | |
321 (gnus-use-long-file-name | |
322 ;; Append ".KILL" to capitalized newsgroup name. | |
323 (expand-file-name (concat (gnus-capitalize-newsgroup newsgroup) | |
324 "." gnus-kill-file-name) | |
325 (or gnus-kill-files-directory "~/News"))) | |
326 (t | |
327 ;; Place "KILL" under the hierarchical directory. | |
328 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) | |
329 "/" gnus-kill-file-name) | |
330 (or gnus-kill-files-directory "~/News"))))) | |
331 | |
332 (defun gnus-expunge (marks) | |
333 "Remove lines marked with MARKS." | |
334 (save-excursion | |
335 (set-buffer gnus-summary-buffer) | |
336 (gnus-summary-remove-lines-marked-with marks))) | |
337 | |
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 (or gnus-newsgroup-headers-hashtb-by-number | |
348 (gnus-make-headers-hashtable-by-number)) | |
349 ;; If there are any previously scored articles, we remove these | |
350 ;; from the `gnus-newsgroup-headers' list that the score functions | |
351 ;; will see. This is probably pretty wasteful when it comes to | |
352 ;; conses, but is, I think, faster than having to assq in every | |
353 ;; single score function. | |
354 (let ((files kill-files)) | |
355 (while files | |
356 (if (file-exists-p (car files)) | |
357 (let ((headers gnus-newsgroup-headers)) | |
358 (if gnus-kill-killed | |
359 (setq gnus-newsgroup-kill-headers | |
360 (mapcar (lambda (header) (mail-header-number header)) | |
361 headers)) | |
362 (while headers | |
363 (or (gnus-member-of-range | |
364 (mail-header-number (car headers)) | |
365 gnus-newsgroup-killed) | |
366 (setq gnus-newsgroup-kill-headers | |
367 (cons (mail-header-number (car headers)) | |
368 gnus-newsgroup-kill-headers))) | |
369 (setq headers (cdr headers)))) | |
370 (setq files nil)) | |
371 (setq files (cdr files))))) | |
372 (if (not gnus-newsgroup-kill-headers) | |
373 () | |
374 (save-window-excursion | |
375 (save-excursion | |
376 (while kill-files | |
377 (if (not (file-exists-p (car kill-files))) | |
378 () | |
379 (message "Processing kill file %s..." (car kill-files)) | |
380 (find-file (car kill-files)) | |
381 (gnus-add-current-to-buffer-list) | |
382 (goto-char (point-min)) | |
383 | |
384 (if (consp (condition-case nil (read (current-buffer)) | |
385 (error nil))) | |
386 (gnus-kill-parse-gnus-kill-file) | |
387 (gnus-kill-parse-rn-kill-file)) | |
388 | |
389 (message "Processing kill file %s...done" (car kill-files))) | |
390 (setq kill-files (cdr kill-files))))) | |
391 | |
392 (gnus-set-mode-line 'summary) | |
393 | |
394 (if beg | |
395 (let ((nunreads (- unreads (length gnus-newsgroup-unreads)))) | |
396 (or (eq nunreads 0) | |
397 (message "Marked %d articles as read" nunreads)) | |
398 nunreads) | |
399 0)))) | |
400 | |
401 ;; Parse a Gnus killfile. | |
402 (defun gnus-score-insert-help (string alist idx) | |
403 (save-excursion | |
404 (pop-to-buffer "*Score Help*") | |
405 (buffer-disable-undo (current-buffer)) | |
406 (erase-buffer) | |
407 (insert string ":\n\n") | |
408 (while alist | |
409 (insert (format " %c: %s\n" (car (car alist)) (nth idx (car alist)))) | |
410 (setq alist (cdr alist))))) | |
411 | |
412 (defun gnus-kill-parse-gnus-kill-file () | |
413 (goto-char (point-min)) | |
414 (gnus-kill-file-mode) | |
415 (let (beg form) | |
416 (while (progn | |
417 (setq beg (point)) | |
418 (setq form (condition-case () (read (current-buffer)) | |
419 (error nil)))) | |
420 (or (listp form) | |
421 (error "Illegal kill entry (possibly rn kill file?): %s" form)) | |
422 (if (or (eq (car form) 'gnus-kill) | |
423 (eq (car form) 'gnus-raise) | |
424 (eq (car form) 'gnus-lower)) | |
425 (progn | |
426 (delete-region beg (point)) | |
427 (insert (or (eval form) ""))) | |
428 (save-excursion | |
429 (set-buffer gnus-summary-buffer) | |
430 (condition-case () (eval form) (error nil))))) | |
431 (and (buffer-modified-p) | |
432 gnus-kill-save-kill-file | |
433 (save-buffer)) | |
434 (set-buffer-modified-p nil))) | |
435 | |
436 ;; Parse an rn killfile. | |
437 (defun gnus-kill-parse-rn-kill-file () | |
438 (goto-char (point-min)) | |
439 (gnus-kill-file-mode) | |
440 (let ((mod-to-header | |
441 '((?a . "") | |
442 (?h . "") | |
443 (?f . "from") | |
444 (?: . "subject"))) | |
445 (com-to-com | |
446 '((?m . " ") | |
447 (?j . "X"))) | |
448 pattern modifier commands) | |
449 (while (not (eobp)) | |
450 (if (not (looking-at "[ \t]*/\\([^/]*\\)/\\([ahfcH]\\)?:\\([a-z=:]*\\)")) | |
451 () | |
452 (setq pattern (buffer-substring (match-beginning 1) (match-end 1))) | |
453 (setq modifier (if (match-beginning 2) (char-after (match-beginning 2)) | |
454 ?s)) | |
455 (setq commands (buffer-substring (match-beginning 3) (match-end 3))) | |
456 | |
457 ;; The "f:+" command marks everything *but* the matches as read, | |
458 ;; so we simply first match everything as read, and then unmark | |
459 ;; PATTERN later. | |
460 (and (string-match "\\+" commands) | |
461 (progn | |
462 (gnus-kill "from" ".") | |
463 (setq commands "m"))) | |
464 | |
465 (gnus-kill | |
466 (or (cdr (assq modifier mod-to-header)) "subject") | |
467 pattern | |
468 (if (string-match "m" commands) | |
469 '(gnus-summary-mark-as-unread nil " ") | |
470 '(gnus-summary-mark-as-read nil "X")) | |
471 nil t)) | |
472 (forward-line 1)))) | |
473 | |
474 ;; Kill changes and new format by suggested by JWZ and Sudish Joseph | |
475 ;; <joseph@cis.ohio-state.edu>. | |
476 (defun gnus-kill (field regexp &optional exe-command all silent) | |
477 "If FIELD of an article matches REGEXP, execute COMMAND. | |
478 Optional 1st argument COMMAND is default to | |
479 (gnus-summary-mark-as-read nil \"X\"). | |
480 If optional 2nd argument ALL is non-nil, articles marked are also applied to. | |
481 If FIELD is an empty string (or nil), entire article body is searched for. | |
482 COMMAND must be a lisp expression or a string representing a key sequence." | |
483 ;; We don't want to change current point nor window configuration. | |
484 (let ((old-buffer (current-buffer))) | |
485 (save-excursion | |
486 (save-window-excursion | |
487 ;; Selected window must be summary buffer to execute keyboard | |
488 ;; macros correctly. See command_loop_1. | |
489 (switch-to-buffer gnus-summary-buffer 'norecord) | |
490 (goto-char (point-min)) ;From the beginning. | |
491 (let ((kill-list regexp) | |
492 (date (current-time-string)) | |
493 (command (or exe-command '(gnus-summary-mark-as-read | |
494 nil gnus-kill-file-mark))) | |
495 kill kdate prev) | |
496 (if (listp kill-list) | |
497 ;; It is a list. | |
498 (if (not (consp (cdr kill-list))) | |
499 ;; It's on the form (regexp . date). | |
500 (if (zerop (gnus-execute field (car kill-list) | |
501 command nil (not all))) | |
502 (if (> (gnus-days-between date (cdr kill-list)) | |
503 gnus-kill-expiry-days) | |
504 (setq regexp nil)) | |
505 (setcdr kill-list date)) | |
506 (while (setq kill (car kill-list)) | |
507 (if (consp kill) | |
508 ;; It's a temporary kill. | |
509 (progn | |
510 (setq kdate (cdr kill)) | |
511 (if (zerop (gnus-execute | |
512 field (car kill) command nil (not all))) | |
513 (if (> (gnus-days-between date kdate) | |
514 gnus-kill-expiry-days) | |
515 ;; Time limit has been exceeded, so we | |
516 ;; remove the match. | |
517 (if prev | |
518 (setcdr prev (cdr kill-list)) | |
519 (setq regexp (cdr regexp)))) | |
520 ;; Successful kill. Set the date to today. | |
521 (setcdr kill date))) | |
522 ;; It's a permanent kill. | |
523 (gnus-execute field kill command nil (not all))) | |
524 (setq prev kill-list) | |
525 (setq kill-list (cdr kill-list)))) | |
526 (gnus-execute field kill-list command nil (not all)))))) | |
527 (switch-to-buffer old-buffer) | |
528 (if (and (eq major-mode 'gnus-kill-file-mode) regexp (not silent)) | |
529 (gnus-pp-gnus-kill | |
530 (nconc (list 'gnus-kill field | |
531 (if (consp regexp) (list 'quote regexp) regexp)) | |
532 (if (or exe-command all) (list (list 'quote exe-command))) | |
533 (if all (list t) nil)))))) | |
534 | |
535 (defun gnus-pp-gnus-kill (object) | |
536 (if (or (not (consp (nth 2 object))) | |
537 (not (consp (cdr (nth 2 object)))) | |
538 (and (eq 'quote (car (nth 2 object))) | |
539 (not (consp (cdr (car (cdr (nth 2 object)))))))) | |
540 (concat "\n" (prin1-to-string object)) | |
541 (save-excursion | |
542 (set-buffer (get-buffer-create "*Gnus PP*")) | |
543 (buffer-disable-undo (current-buffer)) | |
544 (erase-buffer) | |
545 (insert (format "\n(%S %S\n '(" (nth 0 object) (nth 1 object))) | |
546 (let ((klist (car (cdr (nth 2 object)))) | |
547 (first t)) | |
548 (while klist | |
549 (insert (if first (progn (setq first nil) "") "\n ") | |
550 (prin1-to-string (car klist))) | |
551 (setq klist (cdr klist)))) | |
552 (insert ")") | |
553 (and (nth 3 object) | |
554 (insert "\n " | |
555 (if (and (consp (nth 3 object)) | |
556 (not (eq 'quote (car (nth 3 object))))) | |
557 "'" "") | |
558 (prin1-to-string (nth 3 object)))) | |
559 (and (nth 4 object) | |
560 (insert "\n t")) | |
561 (insert ")") | |
562 (prog1 | |
563 (buffer-substring (point-min) (point-max)) | |
564 (kill-buffer (current-buffer)))))) | |
565 | |
566 (defun gnus-execute-1 (function regexp form header) | |
567 (save-excursion | |
568 (let (did-kill) | |
569 (if (null header) | |
570 nil ;Nothing to do. | |
571 (if function | |
572 ;; Compare with header field. | |
573 (let (value) | |
574 (and header | |
575 (progn | |
576 (setq value (funcall function header)) | |
577 ;; Number (Lines:) or symbol must be converted to string. | |
578 (or (stringp value) | |
579 (setq value (prin1-to-string value))) | |
580 (setq did-kill (string-match regexp value))) | |
581 (if (stringp form) ;Keyboard macro. | |
582 (execute-kbd-macro form) | |
583 (funcall form)))) | |
584 ;; Search article body. | |
585 (let ((gnus-current-article nil) ;Save article pointer. | |
586 (gnus-last-article nil) | |
587 (gnus-break-pages nil) ;No need to break pages. | |
588 (gnus-mark-article-hook nil)) ;Inhibit marking as read. | |
589 (message "Searching for article: %d..." (mail-header-number header)) | |
590 (gnus-article-setup-buffer) | |
591 (gnus-article-prepare (mail-header-number header) t) | |
592 (if (save-excursion | |
593 (set-buffer gnus-article-buffer) | |
594 (goto-char (point-min)) | |
595 (setq did-kill (re-search-forward regexp nil t))) | |
596 (if (stringp form) ;Keyboard macro. | |
597 (execute-kbd-macro form) | |
598 (eval form)))))) | |
599 did-kill))) | |
600 | |
601 (defun gnus-execute (field regexp form &optional backward ignore-marked) | |
602 "If FIELD of article header matches REGEXP, execute lisp FORM (or a string). | |
603 If FIELD is an empty string (or nil), entire article body is searched for. | |
604 If optional 1st argument BACKWARD is non-nil, do backward instead. | |
605 If optional 2nd argument IGNORE-MARKED is non-nil, articles which are | |
606 marked as read or ticked are ignored." | |
607 (save-excursion | |
608 (let ((killed-no 0) | |
609 function article header) | |
610 (if (or (null field) (string-equal field "")) | |
611 (setq function nil) | |
612 ;; Get access function of header filed. | |
613 (setq function (intern-soft (concat "gnus-header-" (downcase field)))) | |
614 (if (and function (fboundp function)) | |
615 (setq function (symbol-function function)) | |
616 (error "Unknown header field: \"%s\"" field)) | |
617 ;; Make FORM funcallable. | |
618 (if (and (listp form) (not (eq (car form) 'lambda))) | |
619 (setq form (list 'lambda nil form)))) | |
620 ;; Starting from the current article. | |
621 (while (or (and (not article) | |
622 (setq article (gnus-summary-article-number)) | |
623 t) | |
624 (setq article | |
625 (gnus-summary-search-subject | |
626 backward (not ignore-marked)))) | |
627 (and (or (null gnus-newsgroup-kill-headers) | |
628 (memq article gnus-newsgroup-kill-headers)) | |
629 (vectorp (setq header (gnus-get-header-by-number article))) | |
630 (gnus-execute-1 function regexp form header) | |
631 (setq killed-no (1+ killed-no)))) | |
632 killed-no))) | |
633 |