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