Mercurial > emacs
annotate lisp/gnus/gnus-logic.el @ 94921:c2449f1de3ac
(Vcharset_non_preferred_head): New variable.
(Vcurrent_iso639_language): New variable.
(syms_of_charset): Declare it as a Lisp variable.
(char_charset): Don't check non preferred charsets. As a last
resort, return charset_unicode.
(Fset_charset_priority): Update Vcharset_non_preferred_head.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 14 May 2008 01:22:48 +0000 |
parents | f42ef85caf91 |
children | 645fb33380d6 |
rev | line source |
---|---|
17493 | 1 ;;; gnus-logic.el --- advanced scoring code for Gnus |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
2 |
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
79708 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
17493 | 5 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
17493 | 7 ;; Keywords: news |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
17493 | 12 ;; it under the terms of the GNU General Public License as published by |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
17493 | 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 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
17493 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;;; Code: | |
27 | |
19521
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
28 (eval-when-compile (require 'cl)) |
6f6cf9184e93
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
29 |
17493 | 30 (require 'gnus) |
31 (require 'gnus-score) | |
32 (require 'gnus-util) | |
33 | |
34 ;;; Internal variables. | |
35 | |
36 (defvar gnus-advanced-headers nil) | |
37 | |
38 ;; To avoid having 8-bit characters in the source file. | |
39 (defvar gnus-advanced-not (intern (format "%c" 172))) | |
40 | |
41 (defconst gnus-advanced-index | |
42 ;; Name to index alist. | |
43 '(("number" 0 gnus-advanced-integer) | |
44 ("subject" 1 gnus-advanced-string) | |
45 ("from" 2 gnus-advanced-string) | |
46 ("date" 3 gnus-advanced-date) | |
47 ("message-id" 4 gnus-advanced-string) | |
48 ("references" 5 gnus-advanced-string) | |
49 ("chars" 6 gnus-advanced-integer) | |
50 ("lines" 7 gnus-advanced-integer) | |
51 ("xref" 8 gnus-advanced-string) | |
52 ("head" nil gnus-advanced-body) | |
53 ("body" nil gnus-advanced-body) | |
54 ("all" nil gnus-advanced-body))) | |
55 | |
56 (eval-and-compile | |
57 (autoload 'parse-time-string "parse-time")) | |
58 | |
59 (defun gnus-score-advanced (rule &optional trace) | |
60 "Apply advanced scoring RULE to all the articles in the current group." | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
61 (let (new-score score multiple) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
62 (dolist (gnus-advanced-headers gnus-newsgroup-headers) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
63 (when (setq multiple (gnus-advanced-score-rule (car rule))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
64 (setq new-score (or (nth 1 rule) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
65 gnus-score-interactive-default-score)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
66 (when (numberp multiple) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
67 (setq new-score (* multiple new-score))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
68 ;; This rule was successful, so we add the score to this |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
69 ;; article. |
17493 | 70 (if (setq score (assq (mail-header-number gnus-advanced-headers) |
71 gnus-newsgroup-scored)) | |
72 (setcdr score | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
73 (+ (cdr score) new-score)) |
17493 | 74 (push (cons (mail-header-number gnus-advanced-headers) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
75 new-score) |
17493 | 76 gnus-newsgroup-scored) |
77 (when trace | |
78 (push (cons "A file" rule) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
79 ;; Must be synced with `gnus-score-edit-file-at-point'. |
17493 | 80 gnus-score-trace))))))) |
81 | |
82 (defun gnus-advanced-score-rule (rule) | |
83 "Apply RULE to `gnus-advanced-headers'." | |
84 (let ((type (car rule))) | |
85 (cond | |
86 ;; "And" rule. | |
87 ((or (eq type '&) (eq type 'and)) | |
88 (pop rule) | |
89 (if (not rule) | |
90 t ; Empty rule is true. | |
91 (while (and rule | |
92 (gnus-advanced-score-rule (car rule))) | |
93 (pop rule)) | |
94 ;; If all the rules were true, then `rule' should be nil. | |
95 (not rule))) | |
96 ;; "Or" rule. | |
97 ((or (eq type '|) (eq type 'or)) | |
98 (pop rule) | |
99 (if (not rule) | |
100 nil | |
101 (while (and rule | |
102 (not (gnus-advanced-score-rule (car rule)))) | |
103 (pop rule)) | |
104 ;; If one of the rules returned true, then `rule' should be non-nil. | |
105 rule)) | |
106 ;; "Not" rule. | |
107 ((or (eq type '!) (eq type 'not) (eq type gnus-advanced-not)) | |
108 (not (gnus-advanced-score-rule (nth 1 rule)))) | |
109 ;; This is a `1-'-type redirection rule. | |
110 ((and (symbolp type) | |
111 (string-match "^[0-9]+-$\\|^\\^+$" (symbol-name type))) | |
112 (let ((gnus-advanced-headers | |
113 (gnus-parent-headers | |
114 gnus-advanced-headers | |
115 (if (string-match "^\\([0-9]+\\)-$" (symbol-name type)) | |
116 ;; 1- type redirection. | |
117 (string-to-number | |
118 (substring (symbol-name type) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
119 (match-beginning 1) (match-end 1))) |
17493 | 120 ;; ^^^ type redirection. |
121 (length (symbol-name type)))))) | |
122 (when gnus-advanced-headers | |
123 (gnus-advanced-score-rule (nth 1 rule))))) | |
124 ;; Plain scoring rule. | |
125 ((stringp type) | |
126 (gnus-advanced-score-article rule)) | |
127 ;; Bug-out time! | |
128 (t | |
129 (error "Unknown advanced score type: %s" rule))))) | |
130 | |
131 (defun gnus-advanced-score-article (rule) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
132 ;; `rule' is a semi-normal score rule, so we find out what function |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
133 ;; that's supposed to do the actual processing. |
17493 | 134 (let* ((header (car rule)) |
135 (func (assoc (downcase header) gnus-advanced-index))) | |
136 (if (not func) | |
137 (error "No such header: %s" rule) | |
138 ;; Call the score function. | |
139 (funcall (caddr func) (or (cadr func) header) | |
140 (cadr rule) (caddr rule))))) | |
141 | |
142 (defun gnus-advanced-string (index match type) | |
143 "See whether string MATCH of TYPE matches `gnus-advanced-headers' in INDEX." | |
144 (let* ((type (or type 's)) | |
145 (case-fold-search (not (eq (downcase (symbol-name type)) | |
146 (symbol-name type)))) | |
33268
88bece18cf0d
2000-10-07 15:42:59 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31716
diff
changeset
|
147 (header (or (aref gnus-advanced-headers index) ""))) |
17493 | 148 (cond |
149 ((memq type '(r R regexp Regexp)) | |
150 (string-match match header)) | |
151 ((memq type '(s S string String)) | |
152 (string-match (regexp-quote match) header)) | |
153 ((memq type '(e E exact Exact)) | |
154 (string= match header)) | |
155 ((memq type '(f F fuzzy Fuzzy)) | |
156 (string-match (regexp-quote (gnus-simplify-subject-fuzzy match)) | |
157 header)) | |
158 (t | |
159 (error "No such string match type: %s" type))))) | |
160 | |
161 (defun gnus-advanced-integer (index match type) | |
162 (if (not (memq type '(< > <= >= =))) | |
163 (error "No such integer score type: %s" type) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
164 (funcall type (or (aref gnus-advanced-headers index) 0) match))) |
17493 | 165 |
166 (defun gnus-advanced-date (index match type) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
167 (let ((date (apply 'encode-time (parse-time-string |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
168 (aref gnus-advanced-headers index)))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
169 (match (apply 'encode-time (parse-time-string match)))) |
17493 | 170 (cond |
171 ((eq type 'at) | |
172 (equal date match)) | |
173 ((eq type 'before) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
174 (time-less-p match date)) |
17493 | 175 ((eq type 'after) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
176 (time-less-p date match)) |
17493 | 177 (t |
178 (error "No such date score type: %s" type))))) | |
179 | |
180 (defun gnus-advanced-body (header match type) | |
181 (when (string= header "all") | |
182 (setq header "article")) | |
183 (save-excursion | |
184 (set-buffer nntp-server-buffer) | |
185 (let* ((request-func (cond ((string= "head" header) | |
186 'gnus-request-head) | |
187 ((string= "body" header) | |
188 'gnus-request-body) | |
189 (t 'gnus-request-article))) | |
190 ofunc article) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
191 ;; Not all backends support partial fetching. In that case, we |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
192 ;; just fetch the entire article. |
17493 | 193 (unless (gnus-check-backend-function |
194 (intern (concat "request-" header)) | |
195 gnus-newsgroup-name) | |
196 (setq ofunc request-func) | |
197 (setq request-func 'gnus-request-article)) | |
198 (setq article (mail-header-number gnus-advanced-headers)) | |
199 (gnus-message 7 "Scoring article %s..." article) | |
200 (when (funcall request-func article gnus-newsgroup-name) | |
201 (goto-char (point-min)) | |
202 ;; If just parts of the article is to be searched and the | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
203 ;; backend didn't support partial fetching, we just narrow to |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
204 ;; the relevant parts. |
17493 | 205 (when ofunc |
206 (if (eq ofunc 'gnus-request-head) | |
207 (narrow-to-region | |
208 (point) | |
209 (or (search-forward "\n\n" nil t) (point-max))) | |
210 (narrow-to-region | |
211 (or (search-forward "\n\n" nil t) (point)) | |
212 (point-max)))) | |
213 (let* ((case-fold-search (not (eq (downcase (symbol-name type)) | |
214 (symbol-name type)))) | |
215 (search-func | |
216 (cond ((memq type '(r R regexp Regexp)) | |
217 're-search-forward) | |
218 ((memq type '(s S string String)) | |
219 'search-forward) | |
220 (t | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
221 (error "Invalid match type: %s" type))))) |
17493 | 222 (goto-char (point-min)) |
223 (prog1 | |
224 (funcall search-func match nil t) | |
225 (widen))))))) | |
226 | |
227 (provide 'gnus-logic) | |
228 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79708
diff
changeset
|
229 ;; arch-tag: 9651a100-4a59-4b69-a55b-e511e67c0f8d |
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
33342
diff
changeset
|
230 ;;; gnus-logic.el ends here |