Mercurial > emacs
annotate lisp/gnus/gnus-logic.el @ 102735:07f2395ce3db
* callint.c (Fcall_interactively): For '^' just delegate the work to
handle-shift-selection.
(syms_of_callint): Move declaration of shift-select-mode to simple.el.
* simple.el (shift-select-mode): Move declaration from callint.c.
(handle-shift-selection): Remove `deactivate' arg and check
shift-select-mode instead.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 26 Mar 2009 17:07:54 +0000 |
parents | a9dc0e7c3f2b |
children | 1d1d5d9bd884 |
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, |
100908 | 4 ;; 2005, 2006, 2007, 2008, 2009 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 | |
95820
645fb33380d6
Remove unnecessary eval-and-compile of autoloads.
Glenn Morris <rgm@gnu.org>
parents:
94662
diff
changeset
|
56 (autoload 'parse-time-string "parse-time") |
17493 | 57 |
58 (defun gnus-score-advanced (rule &optional trace) | |
59 "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
|
60 (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
|
61 (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
|
62 (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
|
63 (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
|
64 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
|
65 (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
|
66 (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
|
67 ;; 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
|
68 ;; article. |
17493 | 69 (if (setq score (assq (mail-header-number gnus-advanced-headers) |
70 gnus-newsgroup-scored)) | |
71 (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
|
72 (+ (cdr score) new-score)) |
17493 | 73 (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
|
74 new-score) |
17493 | 75 gnus-newsgroup-scored) |
76 (when trace | |
77 (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
|
78 ;; Must be synced with `gnus-score-edit-file-at-point'. |
17493 | 79 gnus-score-trace))))))) |
80 | |
81 (defun gnus-advanced-score-rule (rule) | |
82 "Apply RULE to `gnus-advanced-headers'." | |
83 (let ((type (car rule))) | |
84 (cond | |
85 ;; "And" rule. | |
86 ((or (eq type '&) (eq type 'and)) | |
87 (pop rule) | |
88 (if (not rule) | |
89 t ; Empty rule is true. | |
90 (while (and rule | |
91 (gnus-advanced-score-rule (car rule))) | |
92 (pop rule)) | |
93 ;; If all the rules were true, then `rule' should be nil. | |
94 (not rule))) | |
95 ;; "Or" rule. | |
96 ((or (eq type '|) (eq type 'or)) | |
97 (pop rule) | |
98 (if (not rule) | |
99 nil | |
100 (while (and rule | |
101 (not (gnus-advanced-score-rule (car rule)))) | |
102 (pop rule)) | |
103 ;; If one of the rules returned true, then `rule' should be non-nil. | |
104 rule)) | |
105 ;; "Not" rule. | |
106 ((or (eq type '!) (eq type 'not) (eq type gnus-advanced-not)) | |
107 (not (gnus-advanced-score-rule (nth 1 rule)))) | |
108 ;; This is a `1-'-type redirection rule. | |
109 ((and (symbolp type) | |
110 (string-match "^[0-9]+-$\\|^\\^+$" (symbol-name type))) | |
111 (let ((gnus-advanced-headers | |
112 (gnus-parent-headers | |
113 gnus-advanced-headers | |
114 (if (string-match "^\\([0-9]+\\)-$" (symbol-name type)) | |
115 ;; 1- type redirection. | |
116 (string-to-number | |
117 (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
|
118 (match-beginning 1) (match-end 1))) |
17493 | 119 ;; ^^^ type redirection. |
120 (length (symbol-name type)))))) | |
121 (when gnus-advanced-headers | |
122 (gnus-advanced-score-rule (nth 1 rule))))) | |
123 ;; Plain scoring rule. | |
124 ((stringp type) | |
125 (gnus-advanced-score-article rule)) | |
126 ;; Bug-out time! | |
127 (t | |
128 (error "Unknown advanced score type: %s" rule))))) | |
129 | |
130 (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
|
131 ;; `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
|
132 ;; that's supposed to do the actual processing. |
17493 | 133 (let* ((header (car rule)) |
134 (func (assoc (downcase header) gnus-advanced-index))) | |
135 (if (not func) | |
136 (error "No such header: %s" rule) | |
137 ;; Call the score function. | |
138 (funcall (caddr func) (or (cadr func) header) | |
139 (cadr rule) (caddr rule))))) | |
140 | |
141 (defun gnus-advanced-string (index match type) | |
142 "See whether string MATCH of TYPE matches `gnus-advanced-headers' in INDEX." | |
143 (let* ((type (or type 's)) | |
144 (case-fold-search (not (eq (downcase (symbol-name type)) | |
145 (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
|
146 (header (or (aref gnus-advanced-headers index) ""))) |
17493 | 147 (cond |
148 ((memq type '(r R regexp Regexp)) | |
149 (string-match match header)) | |
150 ((memq type '(s S string String)) | |
151 (string-match (regexp-quote match) header)) | |
152 ((memq type '(e E exact Exact)) | |
153 (string= match header)) | |
154 ((memq type '(f F fuzzy Fuzzy)) | |
155 (string-match (regexp-quote (gnus-simplify-subject-fuzzy match)) | |
156 header)) | |
157 (t | |
158 (error "No such string match type: %s" type))))) | |
159 | |
160 (defun gnus-advanced-integer (index match type) | |
161 (if (not (memq type '(< > <= >= =))) | |
162 (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
|
163 (funcall type (or (aref gnus-advanced-headers index) 0) match))) |
17493 | 164 |
165 (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
|
166 (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
|
167 (aref gnus-advanced-headers index)))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19521
diff
changeset
|
168 (match (apply 'encode-time (parse-time-string match)))) |
17493 | 169 (cond |
170 ((eq type 'at) | |
171 (equal date match)) | |
172 ((eq type 'before) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
173 (time-less-p match date)) |
17493 | 174 ((eq type 'after) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
175 (time-less-p date match)) |
17493 | 176 (t |
177 (error "No such date score type: %s" type))))) | |
178 | |
179 (defun gnus-advanced-body (header match type) | |
180 (when (string= header "all") | |
181 (setq header "article")) | |
182 (save-excursion | |
183 (set-buffer nntp-server-buffer) | |
184 (let* ((request-func (cond ((string= "head" header) | |
185 'gnus-request-head) | |
186 ((string= "body" header) | |
187 'gnus-request-body) | |
188 (t 'gnus-request-article))) | |
189 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
|
190 ;; 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
|
191 ;; just fetch the entire article. |
17493 | 192 (unless (gnus-check-backend-function |
193 (intern (concat "request-" header)) | |
194 gnus-newsgroup-name) | |
195 (setq ofunc request-func) | |
196 (setq request-func 'gnus-request-article)) | |
197 (setq article (mail-header-number gnus-advanced-headers)) | |
198 (gnus-message 7 "Scoring article %s..." article) | |
199 (when (funcall request-func article gnus-newsgroup-name) | |
200 (goto-char (point-min)) | |
201 ;; 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
|
202 ;; 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
|
203 ;; the relevant parts. |
17493 | 204 (when ofunc |
205 (if (eq ofunc 'gnus-request-head) | |
206 (narrow-to-region | |
207 (point) | |
208 (or (search-forward "\n\n" nil t) (point-max))) | |
209 (narrow-to-region | |
210 (or (search-forward "\n\n" nil t) (point)) | |
211 (point-max)))) | |
212 (let* ((case-fold-search (not (eq (downcase (symbol-name type)) | |
213 (symbol-name type)))) | |
214 (search-func | |
215 (cond ((memq type '(r R regexp Regexp)) | |
216 're-search-forward) | |
217 ((memq type '(s S string String)) | |
218 'search-forward) | |
219 (t | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
220 (error "Invalid match type: %s" type))))) |
17493 | 221 (goto-char (point-min)) |
222 (prog1 | |
223 (funcall search-func match nil t) | |
224 (widen))))))) | |
225 | |
226 (provide 'gnus-logic) | |
227 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79708
diff
changeset
|
228 ;; 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
|
229 ;;; gnus-logic.el ends here |