Mercurial > hg > xemacs-beta
comparison lisp/gnus/gnus-art.el @ 98:0d2f883870bc r20-1b1
Import from CVS: tag r20-1b1
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:13:56 +0200 |
parents | |
children | 4be1180a9e89 |
comparison
equal
deleted
inserted
replaced
97:498bf5da1c90 | 98:0d2f883870bc |
---|---|
1 ;;; gnus-art.el --- article mode commands for Gnus | |
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 ;; Keywords: news | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 ;;; Code: | |
27 | |
28 (require 'custom) | |
29 (require 'gnus) | |
30 (require 'gnus-sum) | |
31 (require 'gnus-spec) | |
32 (require 'gnus-int) | |
33 (require 'browse-url) | |
34 | |
35 (defgroup gnus-article nil | |
36 "Article display." | |
37 :link '(custom-manual "(gnus)The Article Buffer") | |
38 :group 'gnus) | |
39 | |
40 (defgroup gnus-article-hiding nil | |
41 "Hiding article parts." | |
42 :link '(custom-manual "(gnus)Article Hiding") | |
43 :group 'gnus-article) | |
44 | |
45 (defgroup gnus-article-highlight nil | |
46 "Article highlighting." | |
47 :link '(custom-manual "(gnus)Article Highlighting") | |
48 :group 'gnus-article | |
49 :group 'gnus-visual) | |
50 | |
51 (defgroup gnus-article-signature nil | |
52 "Article signatures." | |
53 :link '(custom-manual "(gnus)Article Signature") | |
54 :group 'gnus-article) | |
55 | |
56 (defgroup gnus-article-headers nil | |
57 "Article headers." | |
58 :link '(custom-manual "(gnus)Hiding Headers") | |
59 :group 'gnus-article) | |
60 | |
61 (defgroup gnus-article-washing nil | |
62 "Special commands on articles." | |
63 :link '(custom-manual "(gnus)Article Washing") | |
64 :group 'gnus-article) | |
65 | |
66 (defgroup gnus-article-emphasis nil | |
67 "Fontisizing articles." | |
68 :link '(custom-manual "(gnus)Article Fontisizing") | |
69 :group 'gnus-article) | |
70 | |
71 (defgroup gnus-article-saving nil | |
72 "Saving articles." | |
73 :link '(custom-manual "(gnus)Saving Articles") | |
74 :group 'gnus-article) | |
75 | |
76 (defgroup gnus-article-mime nil | |
77 "Worshiping the MIME wonder." | |
78 :link '(custom-manual "(gnus)Using MIME") | |
79 :group 'gnus-article) | |
80 | |
81 (defgroup gnus-article-buttons nil | |
82 "Pushable buttons in the article buffer." | |
83 :link '(custom-manual "(gnus)Article Buttons") | |
84 :group 'gnus-article) | |
85 | |
86 (defgroup gnus-article-various nil | |
87 "Other article options." | |
88 :link '(custom-manual "(gnus)Misc Article") | |
89 :group 'gnus-article) | |
90 | |
91 (defcustom gnus-ignored-headers | |
92 '("^Path:" "^Posting-Version:" "^Article-I.D.:" "^Expires:" | |
93 "^Date-Received:" "^References:" "^Control:" "^Xref:" "^Lines:" | |
94 "^Posted:" "^Relay-Version:" "^Message-ID:" "^Nf-ID:" "^Nf-From:" | |
95 "^Approved:" "^Sender:" "^Received:" "^Mail-from:") | |
96 "All headers that match this regexp will be hidden. | |
97 This variable can also be a list of regexps of headers to be ignored. | |
98 If `gnus-visible-headers' is non-nil, this variable will be ignored." | |
99 :type '(choice :custom-show nil | |
100 regexp | |
101 (repeat regexp)) | |
102 :group 'gnus-article-hiding) | |
103 | |
104 (defcustom gnus-visible-headers | |
105 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From" | |
106 "All headers that do not match this regexp will be hidden. | |
107 This variable can also be a list of regexp of headers to remain visible. | |
108 If this variable is non-nil, `gnus-ignored-headers' will be ignored." | |
109 :type '(repeat :value-to-internal (lambda (widget value) | |
110 (custom-split-regexp-maybe value)) | |
111 :match (lambda (widget value) | |
112 (or (stringp value) | |
113 (widget-editable-list-match widget value))) | |
114 regexp) | |
115 :group 'gnus-article-hiding) | |
116 | |
117 (defcustom gnus-sorted-header-list | |
118 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:" | |
119 "^Cc:" "^Date:" "^Organization:") | |
120 "This variable is a list of regular expressions. | |
121 If it is non-nil, headers that match the regular expressions will | |
122 be placed first in the article buffer in the sequence specified by | |
123 this list." | |
124 :type '(repeat regexp) | |
125 :group 'gnus-article-hiding) | |
126 | |
127 (defcustom gnus-boring-article-headers '(empty followup-to reply-to) | |
128 "Headers that are only to be displayed if they have interesting data. | |
129 Possible values in this list are `empty', `newsgroups', `followup-to', | |
130 `reply-to', and `date'." | |
131 :type '(set (const :tag "Headers with no content." empty) | |
132 (const :tag "Newsgroups with only one group." newsgroups) | |
133 (const :tag "Followup-to identical to newsgroups." followup-to) | |
134 (const :tag "Reply-to identical to from." reply-to) | |
135 (const :tag "Date less than four days old." date)) | |
136 :group 'gnus-article-hiding) | |
137 | |
138 (defcustom gnus-signature-separator '("^-- $" "^-- *$") | |
139 "Regexp matching signature separator. | |
140 This can also be a list of regexps. In that case, it will be checked | |
141 from head to tail looking for a separator. Searches will be done from | |
142 the end of the buffer." | |
143 :type '(repeat string) | |
144 :group 'gnus-article-signature) | |
145 | |
146 (defcustom gnus-signature-limit nil | |
147 "Provide a limit to what is considered a signature. | |
148 If it is a number, no signature may not be longer (in characters) than | |
149 that number. If it is a floating point number, no signature may be | |
150 longer (in lines) than that number. If it is a function, the function | |
151 will be called without any parameters, and if it returns nil, there is | |
152 no signature in the buffer. If it is a string, it will be used as a | |
153 regexp. If it matches, the text in question is not a signature." | |
154 :type '(choice integer number function regexp) | |
155 :group 'gnus-article-signature) | |
156 | |
157 (defcustom gnus-hidden-properties '(invisible t intangible t) | |
158 "Property list to use for hiding text." | |
159 :type 'sexp | |
160 :group 'gnus-article-hiding) | |
161 | |
162 (defcustom gnus-article-x-face-command | |
163 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -" | |
164 "String or function to be executed to display an X-Face header. | |
165 If it is a string, the command will be executed in a sub-shell | |
166 asynchronously. The compressed face will be piped to this command." | |
167 :type 'string ;Leave function case to Lisp. | |
168 :group 'gnus-article-washing) | |
169 | |
170 (defcustom gnus-article-x-face-too-ugly nil | |
171 "Regexp matching posters whose face shouldn't be shown automatically." | |
172 :type 'regexp | |
173 :group 'gnus-article-washing) | |
174 | |
175 (defcustom gnus-emphasis-alist | |
176 (let ((format | |
177 "\\(\\s-\\|^\\|[-\"\(]\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\\(\\s-\\|[-?!.,;:\"\)]\\)") | |
178 (types | |
179 '(("_" "_" underline) | |
180 ("/" "/" italic) | |
181 ("\\*" "\\*" bold) | |
182 ;;("_/" "/_" underline-italic) | |
183 ;;("_\\*" "\\*_" underline-bold) | |
184 ("\\*/" "/\\*" bold-italic) | |
185 ;;("_\\*/" "/\\*_" underline-bold-italic) | |
186 ))) | |
187 `(("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)" | |
188 2 3 gnus-emphasis-underline) | |
189 ,@(mapcar | |
190 (lambda (spec) | |
191 (list | |
192 (format format (car spec) (cadr spec)) | |
193 2 3 (intern (format "gnus-emphasis-%s" (caddr spec))))) | |
194 types))) | |
195 "Alist that says how to fontify certain phrases. | |
196 Each item looks like this: | |
197 | |
198 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline) | |
199 | |
200 The first element is a regular expression to be matched. The second | |
201 is a number that says what regular expression grouping used to find | |
202 the entire emphasized word. The third is a number that says what | |
203 regexp grouping should be displayed and highlighted. The fourth | |
204 is the face used for highlighting." | |
205 :type '(repeat (list :value ("" 0 0 default) | |
206 regexp | |
207 (integer :tag "Match group") | |
208 (integer :tag "Emphasize group") | |
209 face)) | |
210 :group 'gnus-article-emphasis) | |
211 | |
212 (defface gnus-emphasis-bold '((t (:bold t))) | |
213 "Face used for displaying strong emphasized text (*word*)." | |
214 :group 'gnus-article-emphasis) | |
215 | |
216 (defface gnus-emphasis-italic '((t (:italic t))) | |
217 "Face used for displaying italic emphasized text (/word/)." | |
218 :group 'gnus-article-emphasis) | |
219 | |
220 (defface gnus-emphasis-underline '((t (:underline t))) | |
221 "Face used for displaying underlined emphasized text (_word_)." | |
222 :group 'gnus-article-emphasis) | |
223 | |
224 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t))) | |
225 "Face used for displaying underlined bold emphasized text (_*word*_)." | |
226 :group 'gnus-article-emphasis) | |
227 | |
228 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t))) | |
229 "Face used for displaying underlined italic emphasized text (_*word*_)." | |
230 :group 'gnus-article-emphasis) | |
231 | |
232 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t))) | |
233 "Face used for displaying bold italic emphasized text (/*word*/)." | |
234 :group 'gnus-article-emphasis) | |
235 | |
236 (defface gnus-emphasis-underline-bold-italic | |
237 '((t (:bold t :italic t :underline t))) | |
238 "Face used for displaying underlined bold italic emphasized text. | |
239 Esample: (_/*word*/_)." | |
240 :group 'gnus-article-emphasis) | |
241 | |
242 (defcustom gnus-article-time-format "%a, %b %d %Y %T %Z" | |
243 "Format for display of Date headers in article bodies. | |
244 See `format-time-zone' for the possible values." | |
245 :type 'string | |
246 :link '(custom-manual "(gnus)Article Date") | |
247 :group 'gnus-article-washing) | |
248 | |
249 (eval-and-compile | |
250 (autoload 'hexl-hex-string-to-integer "hexl") | |
251 (autoload 'timezone-make-date-arpa-standard "timezone") | |
252 (autoload 'mail-extract-address-components "mail-extr")) | |
253 | |
254 (defcustom gnus-article-save-directory gnus-directory | |
255 "*Name of the directory articles will be saved in (default \"~/News\")." | |
256 :group 'gnus-article-saving | |
257 :type 'directory) | |
258 | |
259 (defcustom gnus-save-all-headers t | |
260 "*If non-nil, don't remove any headers before saving." | |
261 :group 'gnus-article-saving | |
262 :type 'boolean) | |
263 | |
264 (defcustom gnus-prompt-before-saving 'always | |
265 "*This variable says how much prompting is to be done when saving articles. | |
266 If it is nil, no prompting will be done, and the articles will be | |
267 saved to the default files. If this variable is `always', each and | |
268 every article that is saved will be preceded by a prompt, even when | |
269 saving large batches of articles. If this variable is neither nil not | |
270 `always', there the user will be prompted once for a file name for | |
271 each invocation of the saving commands." | |
272 :group 'gnus-article-saving | |
273 :type '(choice (item always) | |
274 (item :tag "never" nil) | |
275 (sexp :tag "once" :format "%t"))) | |
276 | |
277 (defcustom gnus-saved-headers gnus-visible-headers | |
278 "Headers to keep if `gnus-save-all-headers' is nil. | |
279 If `gnus-save-all-headers' is non-nil, this variable will be ignored. | |
280 If that variable is nil, however, all headers that match this regexp | |
281 will be kept while the rest will be deleted before saving." | |
282 :group 'gnus-article-saving | |
283 :type '(repeat string)) | |
284 | |
285 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail | |
286 "A function to save articles in your favourite format. | |
287 The function must be interactively callable (in other words, it must | |
288 be an Emacs command). | |
289 | |
290 Gnus provides the following functions: | |
291 | |
292 * gnus-summary-save-in-rmail (Rmail format) | |
293 * gnus-summary-save-in-mail (Unix mail format) | |
294 * gnus-summary-save-in-folder (MH folder) | |
295 * gnus-summary-save-in-file (article format) | |
296 * gnus-summary-save-in-vm (use VM's folder format) | |
297 * gnus-summary-write-to-file (article format -- overwrite)." | |
298 :group 'gnus-article-saving | |
299 :type '(radio (function-item gnus-summary-save-in-rmail) | |
300 (function-item gnus-summary-save-in-mail) | |
301 (function-item gnus-summary-save-in-folder) | |
302 (function-item gnus-summary-save-in-file) | |
303 (function-item gnus-summary-save-in-vm) | |
304 (function-item gnus-summary-write-to-file))) | |
305 | |
306 (defcustom gnus-rmail-save-name 'gnus-plain-save-name | |
307 "A function generating a file name to save articles in Rmail format. | |
308 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE." | |
309 :group 'gnus-article-saving | |
310 :type 'function) | |
311 | |
312 (defcustom gnus-mail-save-name 'gnus-plain-save-name | |
313 "A function generating a file name to save articles in Unix mail format. | |
314 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE." | |
315 :group 'gnus-article-saving | |
316 :type 'function) | |
317 | |
318 (defcustom gnus-folder-save-name 'gnus-folder-save-name | |
319 "A function generating a file name to save articles in MH folder. | |
320 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER." | |
321 :group 'gnus-article-saving | |
322 :type 'function) | |
323 | |
324 (defcustom gnus-file-save-name 'gnus-numeric-save-name | |
325 "A function generating a file name to save articles in article format. | |
326 The function is called with NEWSGROUP, HEADERS, and optional | |
327 LAST-FILE." | |
328 :group 'gnus-article-saving | |
329 :type 'function) | |
330 | |
331 (defcustom gnus-split-methods | |
332 '((gnus-article-archive-name)) | |
333 "Variable used to suggest where articles are to be saved. | |
334 For instance, if you would like to save articles related to Gnus in | |
335 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\", | |
336 you could set this variable to something like: | |
337 | |
338 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\") | |
339 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\")) | |
340 | |
341 This variable is an alist where the where the key is the match and the | |
342 value is a list of possible files to save in if the match is non-nil. | |
343 | |
344 If the match is a string, it is used as a regexp match on the | |
345 article. If the match is a symbol, that symbol will be funcalled | |
346 from the buffer of the article to be saved with the newsgroup as the | |
347 parameter. If it is a list, it will be evaled in the same buffer. | |
348 | |
349 If this form or function returns a string, this string will be used as | |
350 a possible file name; and if it returns a non-nil list, that list will | |
351 be used as possible file names." | |
352 :group 'gnus-article-saving | |
353 :type '(repeat (choice (list function) | |
354 (cons regexp (repeat string)) | |
355 sexp))) | |
356 | |
357 (defcustom gnus-strict-mime t | |
358 "*If nil, MIME-decode even if there is no Mime-Version header." | |
359 :group 'gnus-article-mime | |
360 :type 'boolean) | |
361 | |
362 (defcustom gnus-show-mime-method 'metamail-buffer | |
363 "Function to process a MIME message. | |
364 The function is called from the article buffer." | |
365 :group 'gnus-article-mime | |
366 :type 'function) | |
367 | |
368 (defcustom gnus-decode-encoded-word-method 'gnus-article-de-quoted-unreadable | |
369 "*Function to decode MIME encoded words. | |
370 The function is called from the article buffer." | |
371 :group 'gnus-article-mime | |
372 :type 'function) | |
373 | |
374 (defcustom gnus-page-delimiter "^\^L" | |
375 "*Regexp describing what to use as article page delimiters. | |
376 The default value is \"^\^L\", which is a form linefeed at the | |
377 beginning of a line." | |
378 :type 'regexp | |
379 :group 'gnus-article-various) | |
380 | |
381 (defcustom gnus-article-mode-line-format "Gnus: %%b %S" | |
382 "*The format specification for the article mode line. | |
383 See `gnus-summary-mode-line-format' for a closer description." | |
384 :type 'string | |
385 :group 'gnus-article-various) | |
386 | |
387 (defcustom gnus-article-mode-hook nil | |
388 "*A hook for Gnus article mode." | |
389 :type 'hook | |
390 :group 'gnus-article-various) | |
391 | |
392 (defcustom gnus-article-menu-hook nil | |
393 "*Hook run after the creation of the article mode menu." | |
394 :type 'hook | |
395 :group 'gnus-article-various) | |
396 | |
397 (defcustom gnus-article-prepare-hook nil | |
398 "*A hook called after an article has been prepared in the article buffer. | |
399 If you want to run a special decoding program like nkf, use this hook." | |
400 :type 'hook | |
401 :group 'gnus-article-various) | |
402 | |
403 (defcustom gnus-article-button-face 'bold | |
404 "Face used for highlighting buttons in the article buffer. | |
405 | |
406 An article button is a piece of text that you can activate by pressing | |
407 `RET' or `mouse-2' above it." | |
408 :type 'face | |
409 :group 'gnus-article-buttons) | |
410 | |
411 (defcustom gnus-article-mouse-face 'highlight | |
412 "Face used for mouse highlighting in the article buffer. | |
413 | |
414 Article buttons will be displayed in this face when the cursor is | |
415 above them." | |
416 :type 'face | |
417 :group 'gnus-article-buttons) | |
418 | |
419 (defcustom gnus-signature-face 'italic | |
420 "Face used for highlighting a signature in the article buffer." | |
421 :type 'face | |
422 :group 'gnus-article-highlight | |
423 :group 'gnus-article-signature) | |
424 | |
425 (defface gnus-header-from-face | |
426 '((((class color) | |
427 (background dark)) | |
428 (:foreground "light blue" :bold t :italic t)) | |
429 (((class color) | |
430 (background light)) | |
431 (:foreground "MidnightBlue" :bold t :italic t)) | |
432 (t | |
433 (:bold t :italic t))) | |
434 "Face used for displaying from headers." | |
435 :group 'gnus-article-headers | |
436 :group 'gnus-article-highlight) | |
437 | |
438 (defface gnus-header-subject-face | |
439 '((((class color) | |
440 (background dark)) | |
441 (:foreground "pink" :bold t :italic t)) | |
442 (((class color) | |
443 (background light)) | |
444 (:foreground "firebrick" :bold t :italic t)) | |
445 (t | |
446 (:bold t :italic t))) | |
447 "Face used for displaying subject headers." | |
448 :group 'gnus-article-headers | |
449 :group 'gnus-article-highlight) | |
450 | |
451 (defface gnus-header-newsgroups-face | |
452 '((((class color) | |
453 (background dark)) | |
454 (:foreground "yellow" :bold t :italic t)) | |
455 (((class color) | |
456 (background light)) | |
457 (:foreground "indianred" :bold t :italic t)) | |
458 (t | |
459 (:bold t :italic t))) | |
460 "Face used for displaying newsgroups headers." | |
461 :group 'gnus-article-headers | |
462 :group 'gnus-article-highlight) | |
463 | |
464 (defface gnus-header-name-face | |
465 '((((class color) | |
466 (background dark)) | |
467 (:foreground "cyan" :bold t)) | |
468 (((class color) | |
469 (background light)) | |
470 (:foreground "DarkGreen" :bold t)) | |
471 (t | |
472 (:bold t))) | |
473 "Face used for displaying header names." | |
474 :group 'gnus-article-headers | |
475 :group 'gnus-article-highlight) | |
476 | |
477 (defface gnus-header-content-face | |
478 '((((class color) | |
479 (background dark)) | |
480 (:foreground "forest green" :italic t)) | |
481 (((class color) | |
482 (background light)) | |
483 (:foreground "DarkGreen" :italic t)) | |
484 (t | |
485 (:italic t))) "Face used for displaying header content." | |
486 :group 'gnus-article-headers | |
487 :group 'gnus-article-highlight) | |
488 | |
489 (defcustom gnus-header-face-alist | |
490 '(("From" nil gnus-header-from-face) | |
491 ("Subject" nil gnus-header-subject-face) | |
492 ("Newsgroups:.*," nil gnus-header-newsgroups-face) | |
493 ("" gnus-header-name-face gnus-header-content-face)) | |
494 "Controls highlighting of article header. | |
495 | |
496 An alist of the form (HEADER NAME CONTENT). | |
497 | |
498 HEADER is a regular expression which should match the name of an | |
499 header header and NAME and CONTENT are either face names or nil. | |
500 | |
501 The name of each header field will be displayed using the face | |
502 specified by the first element in the list where HEADER match the | |
503 header name and NAME is non-nil. Similarly, the content will be | |
504 displayed by the first non-nil matching CONTENT face." | |
505 :group 'gnus-article-headers | |
506 :group 'gnus-article-highlight | |
507 :type '(repeat (list (regexp :tag "Header") | |
508 (choice :tag "Name" | |
509 (item :tag "skip" nil) | |
510 (face :value default)) | |
511 (choice :tag "Content" | |
512 (item :tag "skip" nil) | |
513 (face :value default))))) | |
514 | |
515 ;;; Internal variables | |
516 | |
517 (defvar gnus-article-mode-syntax-table | |
518 (let ((table (copy-syntax-table text-mode-syntax-table))) | |
519 ;;(modify-syntax-entry ?_ "w" table) | |
520 table) | |
521 "Syntax table used in article mode buffers. | |
522 Initialized from `text-mode-syntax-table.") | |
523 | |
524 (defvar gnus-save-article-buffer nil) | |
525 | |
526 (defvar gnus-article-mode-line-format-alist | |
527 (nconc '((?w (gnus-article-wash-status) ?s)) | |
528 gnus-summary-mode-line-format-alist)) | |
529 | |
530 (defvar gnus-number-of-articles-to-be-saved nil) | |
531 | |
532 (defvar gnus-inhibit-hiding nil) | |
533 (defvar gnus-newsgroup-name) | |
534 | |
535 (defsubst gnus-article-hide-text (b e props) | |
536 "Set text PROPS on the B to E region, extending `intangible' 1 past B." | |
537 (add-text-properties b e props) | |
538 (when (memq 'intangible props) | |
539 (put-text-property | |
540 (max (1- b) (point-min)) | |
541 b 'intangible (cddr (memq 'intangible props))))) | |
542 | |
543 (defsubst gnus-article-unhide-text (b e) | |
544 "Remove hidden text properties from region between B and E." | |
545 (remove-text-properties b e gnus-hidden-properties) | |
546 (when (memq 'intangible gnus-hidden-properties) | |
547 (put-text-property (max (1- b) (point-min)) | |
548 b 'intangible nil))) | |
549 | |
550 (defun gnus-article-hide-text-type (b e type) | |
551 "Hide text of TYPE between B and E." | |
552 (gnus-article-hide-text | |
553 b e (cons 'article-type (cons type gnus-hidden-properties)))) | |
554 | |
555 (defun gnus-article-unhide-text-type (b e type) | |
556 "Hide text of TYPE between B and E." | |
557 (remove-text-properties | |
558 b e (cons 'article-type (cons type gnus-hidden-properties))) | |
559 (when (memq 'intangible gnus-hidden-properties) | |
560 (put-text-property (max (1- b) (point-min)) | |
561 b 'intangible nil))) | |
562 | |
563 (defun gnus-article-hide-text-of-type (type) | |
564 "Hide text of TYPE in the current buffer." | |
565 (save-excursion | |
566 (let ((b (point-min)) | |
567 (e (point-max))) | |
568 (while (setq b (text-property-any b e 'article-type type)) | |
569 (add-text-properties b (incf b) gnus-hidden-properties))))) | |
570 | |
571 (defun gnus-article-delete-text-of-type (type) | |
572 "Delete text of TYPE in the current buffer." | |
573 (save-excursion | |
574 (let ((b (point-min))) | |
575 (while (setq b (text-property-any b (point-max) 'article-type type)) | |
576 (delete-region b (incf b)))))) | |
577 | |
578 (defun gnus-article-delete-invisible-text () | |
579 "Delete all invisible text in the current buffer." | |
580 (save-excursion | |
581 (let ((b (point-min))) | |
582 (while (setq b (text-property-any b (point-max) 'invisible t)) | |
583 (delete-region b (incf b)))))) | |
584 | |
585 (defun gnus-article-text-type-exists-p (type) | |
586 "Say whether any text of type TYPE exists in the buffer." | |
587 (text-property-any (point-min) (point-max) 'article-type type)) | |
588 | |
589 (defsubst gnus-article-header-rank () | |
590 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'." | |
591 (let ((list gnus-sorted-header-list) | |
592 (i 0)) | |
593 (while list | |
594 (when (looking-at (car list)) | |
595 (setq list nil)) | |
596 (setq list (cdr list)) | |
597 (incf i)) | |
598 i)) | |
599 | |
600 (defun article-hide-headers (&optional arg delete) | |
601 "Toggle whether to hide unwanted headers and possibly sort them as well. | |
602 If given a negative prefix, always show; if given a positive prefix, | |
603 always hide." | |
604 (interactive (gnus-article-hidden-arg)) | |
605 (if (gnus-article-check-hidden-text 'headers arg) | |
606 ;; Show boring headers as well. | |
607 (gnus-article-show-hidden-text 'boring-headers) | |
608 ;; This function might be inhibited. | |
609 (unless gnus-inhibit-hiding | |
610 (save-excursion | |
611 (save-restriction | |
612 (let ((buffer-read-only nil) | |
613 (props (nconc (list 'article-type 'headers) | |
614 gnus-hidden-properties)) | |
615 (max (1+ (length gnus-sorted-header-list))) | |
616 (ignored (when (not gnus-visible-headers) | |
617 (cond ((stringp gnus-ignored-headers) | |
618 gnus-ignored-headers) | |
619 ((listp gnus-ignored-headers) | |
620 (mapconcat 'identity gnus-ignored-headers | |
621 "\\|"))))) | |
622 (visible | |
623 (cond ((stringp gnus-visible-headers) | |
624 gnus-visible-headers) | |
625 ((and gnus-visible-headers | |
626 (listp gnus-visible-headers)) | |
627 (mapconcat 'identity gnus-visible-headers "\\|")))) | |
628 (inhibit-point-motion-hooks t) | |
629 want-list beg) | |
630 ;; First we narrow to just the headers. | |
631 (widen) | |
632 (goto-char (point-min)) | |
633 ;; Hide any "From " lines at the beginning of (mail) articles. | |
634 (while (looking-at "From ") | |
635 (forward-line 1)) | |
636 (unless (bobp) | |
637 (if delete | |
638 (delete-region (point-min) (point)) | |
639 (gnus-article-hide-text (point-min) (point) props))) | |
640 ;; Then treat the rest of the header lines. | |
641 (narrow-to-region | |
642 (point) | |
643 (if (search-forward "\n\n" nil t) ; if there's a body | |
644 (progn (forward-line -1) (point)) | |
645 (point-max))) | |
646 ;; Then we use the two regular expressions | |
647 ;; `gnus-ignored-headers' and `gnus-visible-headers' to | |
648 ;; select which header lines is to remain visible in the | |
649 ;; article buffer. | |
650 (goto-char (point-min)) | |
651 (while (re-search-forward "^[^ \t]*:" nil t) | |
652 (beginning-of-line) | |
653 ;; Mark the rank of the header. | |
654 (put-text-property | |
655 (point) (1+ (point)) 'message-rank | |
656 (if (or (and visible (looking-at visible)) | |
657 (and ignored | |
658 (not (looking-at ignored)))) | |
659 (gnus-article-header-rank) | |
660 (+ 2 max))) | |
661 (forward-line 1)) | |
662 (message-sort-headers-1) | |
663 (when (setq beg (text-property-any | |
664 (point-min) (point-max) 'message-rank (+ 2 max))) | |
665 ;; We make the unwanted headers invisible. | |
666 (if delete | |
667 (delete-region beg (point-max)) | |
668 ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>. | |
669 (gnus-article-hide-text-type beg (point-max) 'headers)) | |
670 ;; Work around XEmacs lossage. | |
671 (put-text-property (point-min) beg 'invisible nil)))))))) | |
672 | |
673 (defun article-hide-boring-headers (&optional arg) | |
674 "Toggle hiding of headers that aren't very interesting. | |
675 If given a negative prefix, always show; if given a positive prefix, | |
676 always hide." | |
677 (interactive (gnus-article-hidden-arg)) | |
678 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg)) | |
679 (not gnus-show-all-headers)) | |
680 (save-excursion | |
681 (save-restriction | |
682 (let ((buffer-read-only nil) | |
683 (list gnus-boring-article-headers) | |
684 (inhibit-point-motion-hooks t) | |
685 elem) | |
686 (nnheader-narrow-to-headers) | |
687 (while list | |
688 (setq elem (pop list)) | |
689 (goto-char (point-min)) | |
690 (cond | |
691 ;; Hide empty headers. | |
692 ((eq elem 'empty) | |
693 (while (re-search-forward "^[^:]+:[ \t]*\n[^ \t]" nil t) | |
694 (forward-line -1) | |
695 (gnus-article-hide-text-type | |
696 (progn (beginning-of-line) (point)) | |
697 (progn | |
698 (end-of-line) | |
699 (if (re-search-forward "^[^ \t]" nil t) | |
700 (match-beginning 0) | |
701 (point-max))) | |
702 'boring-headers))) | |
703 ;; Hide boring Newsgroups header. | |
704 ((eq elem 'newsgroups) | |
705 (when (equal (gnus-fetch-field "newsgroups") | |
706 (gnus-group-real-name | |
707 (if (boundp 'gnus-newsgroup-name) | |
708 gnus-newsgroup-name | |
709 ""))) | |
710 (gnus-article-hide-header "newsgroups"))) | |
711 ((eq elem 'followup-to) | |
712 (when (equal (message-fetch-field "followup-to") | |
713 (message-fetch-field "newsgroups")) | |
714 (gnus-article-hide-header "followup-to"))) | |
715 ((eq elem 'reply-to) | |
716 (let ((from (message-fetch-field "from")) | |
717 (reply-to (message-fetch-field "reply-to"))) | |
718 (when (and | |
719 from reply-to | |
720 (ignore-errors | |
721 (equal | |
722 (nth 1 (mail-extract-address-components from)) | |
723 (nth 1 (mail-extract-address-components reply-to))))) | |
724 (gnus-article-hide-header "reply-to")))) | |
725 ((eq elem 'date) | |
726 (let ((date (message-fetch-field "date"))) | |
727 (when (and date | |
728 (< (gnus-days-between (current-time-string) date) | |
729 4)) | |
730 (gnus-article-hide-header "date"))))))))))) | |
731 | |
732 (defun gnus-article-hide-header (header) | |
733 (save-excursion | |
734 (goto-char (point-min)) | |
735 (when (re-search-forward (concat "^" header ":") nil t) | |
736 (gnus-article-hide-text-type | |
737 (progn (beginning-of-line) (point)) | |
738 (progn | |
739 (end-of-line) | |
740 (if (re-search-forward "^[^ \t]" nil t) | |
741 (match-beginning 0) | |
742 (point-max))) | |
743 'boring-headers)))) | |
744 | |
745 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>. | |
746 (defun article-treat-overstrike () | |
747 "Translate overstrikes into bold text." | |
748 (interactive) | |
749 (save-excursion | |
750 (let ((buffer-read-only nil)) | |
751 (while (search-forward "\b" nil t) | |
752 (let ((next (following-char)) | |
753 (previous (char-after (- (point) 2)))) | |
754 ;; We do the boldification/underlining by hiding the | |
755 ;; overstrikes and putting the proper text property | |
756 ;; on the letters. | |
757 (cond | |
758 ((eq next previous) | |
759 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike) | |
760 (put-text-property (point) (1+ (point)) 'face 'bold)) | |
761 ((eq next ?_) | |
762 (gnus-article-hide-text-type (1- (point)) (1+ (point)) 'overstrike) | |
763 (put-text-property | |
764 (- (point) 2) (1- (point)) 'face 'underline)) | |
765 ((eq previous ?_) | |
766 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike) | |
767 (put-text-property | |
768 (point) (1+ (point)) 'face 'underline)))))))) | |
769 | |
770 (defun article-fill () | |
771 "Format too long lines." | |
772 (interactive) | |
773 (save-excursion | |
774 (let ((buffer-read-only nil)) | |
775 (widen) | |
776 (goto-char (point-min)) | |
777 (search-forward "\n\n" nil t) | |
778 (end-of-line 1) | |
779 (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$") | |
780 (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?") | |
781 (adaptive-fill-mode t)) | |
782 (while (not (eobp)) | |
783 (and (>= (current-column) (min fill-column (window-width))) | |
784 (/= (preceding-char) ?:) | |
785 (fill-paragraph nil)) | |
786 (end-of-line 2)))))) | |
787 | |
788 (defun article-remove-cr () | |
789 "Remove carriage returns from an article." | |
790 (interactive) | |
791 (save-excursion | |
792 (let ((buffer-read-only nil)) | |
793 (goto-char (point-min)) | |
794 (while (search-forward "\r" nil t) | |
795 (replace-match "" t t))))) | |
796 | |
797 (defun article-remove-trailing-blank-lines () | |
798 "Remove all trailing blank lines from the article." | |
799 (interactive) | |
800 (save-excursion | |
801 (let ((buffer-read-only nil)) | |
802 (goto-char (point-max)) | |
803 (delete-region | |
804 (point) | |
805 (progn | |
806 (while (and (not (bobp)) | |
807 (looking-at "^[ \t]*$")) | |
808 (forward-line -1)) | |
809 (forward-line 1) | |
810 (point)))))) | |
811 | |
812 (defun article-display-x-face (&optional force) | |
813 "Look for an X-Face header and display it if present." | |
814 (interactive (list 'force)) | |
815 (save-excursion | |
816 ;; Delete the old process, if any. | |
817 (when (process-status "article-x-face") | |
818 (delete-process "article-x-face")) | |
819 (let ((inhibit-point-motion-hooks t) | |
820 (case-fold-search nil) | |
821 from) | |
822 (save-restriction | |
823 (nnheader-narrow-to-headers) | |
824 (setq from (message-fetch-field "from")) | |
825 (goto-char (point-min)) | |
826 (when (and gnus-article-x-face-command | |
827 (or force | |
828 ;; Check whether this face is censored. | |
829 (not gnus-article-x-face-too-ugly) | |
830 (and gnus-article-x-face-too-ugly from | |
831 (not (string-match gnus-article-x-face-too-ugly | |
832 from)))) | |
833 ;; Has to be present. | |
834 (re-search-forward "^X-Face: " nil t)) | |
835 ;; We now have the area of the buffer where the X-Face is stored. | |
836 (let ((beg (point)) | |
837 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t)))) | |
838 ;; We display the face. | |
839 (if (symbolp gnus-article-x-face-command) | |
840 ;; The command is a lisp function, so we call it. | |
841 (if (gnus-functionp gnus-article-x-face-command) | |
842 (funcall gnus-article-x-face-command beg end) | |
843 (error "%s is not a function" gnus-article-x-face-command)) | |
844 ;; The command is a string, so we interpret the command | |
845 ;; as a, well, command, and fork it off. | |
846 (let ((process-connection-type nil)) | |
847 (process-kill-without-query | |
848 (start-process | |
849 "article-x-face" nil shell-file-name shell-command-switch | |
850 gnus-article-x-face-command)) | |
851 (process-send-region "article-x-face" beg end) | |
852 (process-send-eof "article-x-face"))))))))) | |
853 | |
854 (defalias 'gnus-decode-rfc1522 'article-decode-rfc1522) | |
855 (defalias 'gnus-article-decode-rfc1522 'article-decode-rfc1522) | |
856 (defun article-decode-rfc1522 () | |
857 "Hack to remove QP encoding from headers." | |
858 (let ((case-fold-search t) | |
859 (inhibit-point-motion-hooks t) | |
860 (buffer-read-only nil) | |
861 string) | |
862 (save-restriction | |
863 (narrow-to-region | |
864 (goto-char (point-min)) | |
865 (or (search-forward "\n\n" nil t) (point-max))) | |
866 (goto-char (point-min)) | |
867 (while (re-search-forward | |
868 "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t) | |
869 (setq string (match-string 1)) | |
870 (save-restriction | |
871 (narrow-to-region (match-beginning 0) (match-end 0)) | |
872 (delete-region (point-min) (point-max)) | |
873 (insert string) | |
874 (article-mime-decode-quoted-printable | |
875 (goto-char (point-min)) (point-max)) | |
876 (subst-char-in-region (point-min) (point-max) ?_ ? ) | |
877 (goto-char (point-max))) | |
878 (goto-char (point-min)))))) | |
879 | |
880 (defun article-de-quoted-unreadable (&optional force) | |
881 "Do a naive translation of a quoted-printable-encoded article. | |
882 This is in no way, shape or form meant as a replacement for real MIME | |
883 processing, but is simply a stop-gap measure until MIME support is | |
884 written. | |
885 If FORCE, decode the article whether it is marked as quoted-printable | |
886 or not." | |
887 (interactive (list 'force)) | |
888 (save-excursion | |
889 (let ((case-fold-search t) | |
890 (buffer-read-only nil) | |
891 (type (gnus-fetch-field "content-transfer-encoding"))) | |
892 (gnus-article-decode-rfc1522) | |
893 (when (or force | |
894 (and type (string-match "quoted-printable" (downcase type)))) | |
895 (goto-char (point-min)) | |
896 (search-forward "\n\n" nil 'move) | |
897 (article-mime-decode-quoted-printable (point) (point-max)))))) | |
898 | |
899 (defun article-mime-decode-quoted-printable-buffer () | |
900 "Decode Quoted-Printable in the current buffer." | |
901 (article-mime-decode-quoted-printable (point-min) (point-max))) | |
902 | |
903 (defun article-mime-decode-quoted-printable (from to) | |
904 "Decode Quoted-Printable in the region between FROM and TO." | |
905 (interactive "r") | |
906 (goto-char from) | |
907 (while (search-forward "=" to t) | |
908 (cond ((eq (following-char) ?\n) | |
909 (delete-char -1) | |
910 (delete-char 1)) | |
911 ((looking-at "[0-9A-F][0-9A-F]") | |
912 (subst-char-in-region | |
913 (1- (point)) (point) ?= | |
914 (hexl-hex-string-to-integer | |
915 (buffer-substring (point) (+ 2 (point))))) | |
916 (delete-char 2)) | |
917 ((looking-at "=") | |
918 (delete-char 1)) | |
919 ((gnus-message 3 "Malformed MIME quoted-printable message"))))) | |
920 | |
921 (defun article-hide-pgp (&optional arg) | |
922 "Toggle hiding of any PGP headers and signatures in the current article. | |
923 If given a negative prefix, always show; if given a positive prefix, | |
924 always hide." | |
925 (interactive (gnus-article-hidden-arg)) | |
926 (unless (gnus-article-check-hidden-text 'pgp arg) | |
927 (save-excursion | |
928 (let ((inhibit-point-motion-hooks t) | |
929 buffer-read-only beg end) | |
930 (widen) | |
931 (goto-char (point-min)) | |
932 ;; Hide the "header". | |
933 (when (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t) | |
934 (gnus-article-hide-text-type (match-beginning 0) (match-end 0) 'pgp)) | |
935 (setq beg (point)) | |
936 ;; Hide the actual signature. | |
937 (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t) | |
938 (setq end (1+ (match-beginning 0))) | |
939 (gnus-article-hide-text-type | |
940 end | |
941 (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t) | |
942 (match-end 0) | |
943 ;; Perhaps we shouldn't hide to the end of the buffer | |
944 ;; if there is no end to the signature? | |
945 (point-max)) | |
946 'pgp)) | |
947 ;; Hide "- " PGP quotation markers. | |
948 (when (and beg end) | |
949 (narrow-to-region beg end) | |
950 (goto-char (point-min)) | |
951 (while (re-search-forward "^- " nil t) | |
952 (gnus-article-hide-text-type | |
953 (match-beginning 0) (match-end 0) 'pgp)) | |
954 (widen)))))) | |
955 | |
956 (defun article-hide-pem (&optional arg) | |
957 "Toggle hiding of any PEM headers and signatures in the current article. | |
958 If given a negative prefix, always show; if given a positive prefix, | |
959 always hide." | |
960 (interactive (gnus-article-hidden-arg)) | |
961 (unless (gnus-article-check-hidden-text 'pem arg) | |
962 (save-excursion | |
963 (let (buffer-read-only end) | |
964 (widen) | |
965 (goto-char (point-min)) | |
966 ;; hide the horrendously ugly "header". | |
967 (and (search-forward "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n" | |
968 nil | |
969 t) | |
970 (setq end (1+ (match-beginning 0))) | |
971 (gnus-article-hide-text-type | |
972 end | |
973 (if (search-forward "\n\n" nil t) | |
974 (match-end 0) | |
975 (point-max)) | |
976 'pem)) | |
977 ;; hide the trailer as well | |
978 (and (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n" | |
979 nil | |
980 t) | |
981 (gnus-article-hide-text-type | |
982 (match-beginning 0) (match-end 0) 'pem)))))) | |
983 | |
984 (defun article-hide-signature (&optional arg) | |
985 "Hide the signature in the current article. | |
986 If given a negative prefix, always show; if given a positive prefix, | |
987 always hide." | |
988 (interactive (gnus-article-hidden-arg)) | |
989 (unless (gnus-article-check-hidden-text 'signature arg) | |
990 (save-excursion | |
991 (save-restriction | |
992 (let ((buffer-read-only nil)) | |
993 (when (gnus-article-narrow-to-signature) | |
994 (gnus-article-hide-text-type | |
995 (point-min) (point-max) 'signature))))))) | |
996 | |
997 (defun article-strip-leading-blank-lines () | |
998 "Remove all blank lines from the beginning of the article." | |
999 (interactive) | |
1000 (save-excursion | |
1001 (let ((inhibit-point-motion-hooks t) | |
1002 buffer-read-only) | |
1003 (goto-char (point-min)) | |
1004 (when (search-forward "\n\n" nil t) | |
1005 (while (and (not (eobp)) | |
1006 (looking-at "[ \t]*$")) | |
1007 (gnus-delete-line)))))) | |
1008 | |
1009 (defun article-strip-multiple-blank-lines () | |
1010 "Replace consecutive blank lines with one empty line." | |
1011 (interactive) | |
1012 (save-excursion | |
1013 (let (buffer-read-only) | |
1014 ;; First make all blank lines empty. | |
1015 (goto-char (point-min)) | |
1016 (while (re-search-forward "^[ \t]+$" nil t) | |
1017 (replace-match "" nil t)) | |
1018 ;; Then replace multiple empty lines with a single empty line. | |
1019 (goto-char (point-min)) | |
1020 (while (re-search-forward "\n\n\n+" nil t) | |
1021 (replace-match "\n\n" t t))))) | |
1022 | |
1023 (defun article-strip-blank-lines () | |
1024 "Strip leading, trailing and multiple blank lines." | |
1025 (interactive) | |
1026 (article-strip-leading-blank-lines) | |
1027 (article-remove-trailing-blank-lines) | |
1028 (article-strip-multiple-blank-lines)) | |
1029 | |
1030 (defvar mime::preview/content-list) | |
1031 (defvar mime::preview-content-info/point-min) | |
1032 (defun gnus-article-narrow-to-signature () | |
1033 "Narrow to the signature; return t if a signature is found, else nil." | |
1034 (widen) | |
1035 (when (and (boundp 'mime::preview/content-list) | |
1036 mime::preview/content-list) | |
1037 ;; We have a MIMEish article, so we use the MIME data to narrow. | |
1038 (let ((pcinfo (car (last mime::preview/content-list)))) | |
1039 (ignore-errors | |
1040 (narrow-to-region | |
1041 (funcall (intern "mime::preview-content-info/point-min") pcinfo) | |
1042 (point-max))))) | |
1043 | |
1044 (when (gnus-article-search-signature) | |
1045 (forward-line 1) | |
1046 ;; Check whether we have some limits to what we consider | |
1047 ;; to be a signature. | |
1048 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit | |
1049 (list gnus-signature-limit))) | |
1050 limit limited) | |
1051 (while (setq limit (pop limits)) | |
1052 (if (or (and (integerp limit) | |
1053 (< (- (point-max) (point)) limit)) | |
1054 (and (floatp limit) | |
1055 (< (count-lines (point) (point-max)) limit)) | |
1056 (and (gnus-functionp limit) | |
1057 (funcall limit)) | |
1058 (and (stringp limit) | |
1059 (not (re-search-forward limit nil t)))) | |
1060 () ; This limit did not succeed. | |
1061 (setq limited t | |
1062 limits nil))) | |
1063 (unless limited | |
1064 (narrow-to-region (point) (point-max)) | |
1065 t)))) | |
1066 | |
1067 (defun gnus-article-search-signature () | |
1068 "Search the current buffer for the signature separator. | |
1069 Put point at the beginning of the signature separator." | |
1070 (let ((cur (point))) | |
1071 (goto-char (point-max)) | |
1072 (if (if (stringp gnus-signature-separator) | |
1073 (re-search-backward gnus-signature-separator nil t) | |
1074 (let ((seps gnus-signature-separator)) | |
1075 (while (and seps | |
1076 (not (re-search-backward (car seps) nil t))) | |
1077 (pop seps)) | |
1078 seps)) | |
1079 t | |
1080 (goto-char cur) | |
1081 nil))) | |
1082 | |
1083 (defun gnus-article-hidden-arg () | |
1084 "Return the current prefix arg as a number, or 0 if no prefix." | |
1085 (list (if current-prefix-arg | |
1086 (prefix-numeric-value current-prefix-arg) | |
1087 0))) | |
1088 | |
1089 (defun gnus-article-check-hidden-text (type arg) | |
1090 "Return nil if hiding is necessary. | |
1091 Arg can be nil or a number. Nil and positive means hide, negative | |
1092 means show, 0 means toggle." | |
1093 (save-excursion | |
1094 (save-restriction | |
1095 (widen) | |
1096 (let ((hide (gnus-article-hidden-text-p type))) | |
1097 (cond | |
1098 ((or (null arg) | |
1099 (> arg 0)) | |
1100 nil) | |
1101 ((< arg 0) | |
1102 (gnus-article-show-hidden-text type)) | |
1103 (t | |
1104 (if (eq hide 'hidden) | |
1105 (gnus-article-show-hidden-text type) | |
1106 nil))))))) | |
1107 | |
1108 (defun gnus-article-hidden-text-p (type) | |
1109 "Say whether the current buffer contains hidden text of type TYPE." | |
1110 (let ((pos (text-property-any (point-min) (point-max) 'article-type type))) | |
1111 (when pos | |
1112 (if (get-text-property pos 'invisible) | |
1113 'hidden | |
1114 'shown)))) | |
1115 | |
1116 (defun gnus-article-show-hidden-text (type &optional hide) | |
1117 "Show all hidden text of type TYPE. | |
1118 If HIDE, hide the text instead." | |
1119 (save-excursion | |
1120 (let ((buffer-read-only nil) | |
1121 (inhibit-point-motion-hooks t) | |
1122 (end (point-min)) | |
1123 beg) | |
1124 (while (setq beg (text-property-any end (point-max) 'article-type type)) | |
1125 (goto-char beg) | |
1126 (setq end (or | |
1127 (text-property-not-all beg (point-max) 'article-type type) | |
1128 (point-max))) | |
1129 (if hide | |
1130 (gnus-article-hide-text beg end gnus-hidden-properties) | |
1131 (gnus-article-unhide-text beg end)) | |
1132 (goto-char end)) | |
1133 t))) | |
1134 | |
1135 (defconst article-time-units | |
1136 `((year . ,(* 365.25 24 60 60)) | |
1137 (week . ,(* 7 24 60 60)) | |
1138 (day . ,(* 24 60 60)) | |
1139 (hour . ,(* 60 60)) | |
1140 (minute . 60) | |
1141 (second . 1)) | |
1142 "Mapping from time units to seconds.") | |
1143 | |
1144 (defun article-date-ut (&optional type highlight header) | |
1145 "Convert DATE date to universal time in the current article. | |
1146 If TYPE is `local', convert to local time; if it is `lapsed', output | |
1147 how much time has lapsed since DATE." | |
1148 (interactive (list 'ut t)) | |
1149 (let* ((header (or header | |
1150 (mail-header-date gnus-current-headers) | |
1151 (message-fetch-field "date") | |
1152 "")) | |
1153 (date (if (vectorp header) (mail-header-date header) | |
1154 header)) | |
1155 (date-regexp "^Date:[ \t]\\|^X-Sent:[ \t]") | |
1156 (inhibit-point-motion-hooks t) | |
1157 bface eface) | |
1158 (when (and date (not (string= date ""))) | |
1159 (save-excursion | |
1160 (save-restriction | |
1161 (nnheader-narrow-to-headers) | |
1162 (let ((buffer-read-only nil)) | |
1163 ;; Delete any old Date headers. | |
1164 (if (re-search-forward date-regexp nil t) | |
1165 (progn | |
1166 (setq bface (get-text-property (gnus-point-at-bol) 'face) | |
1167 eface (get-text-property (1- (gnus-point-at-eol)) | |
1168 'face)) | |
1169 (message-remove-header date-regexp t) | |
1170 (beginning-of-line)) | |
1171 (goto-char (point-max))) | |
1172 (insert (article-make-date-line date type)) | |
1173 ;; Do highlighting. | |
1174 (forward-line -1) | |
1175 (when (looking-at "\\([^:]+\\): *\\(.*\\)$") | |
1176 (put-text-property (match-beginning 1) (match-end 1) | |
1177 'face bface) | |
1178 (put-text-property (match-beginning 2) (match-end 2) | |
1179 'face eface)))))))) | |
1180 | |
1181 (defun article-make-date-line (date type) | |
1182 "Return a DATE line of TYPE." | |
1183 (cond | |
1184 ;; Convert to the local timezone. We have to slap a | |
1185 ;; `condition-case' round the calls to the timezone | |
1186 ;; functions since they aren't particularly resistant to | |
1187 ;; buggy dates. | |
1188 ((eq type 'local) | |
1189 (concat "Date: " (condition-case () | |
1190 (timezone-make-date-arpa-standard date) | |
1191 (error date)) | |
1192 "\n")) | |
1193 ;; Convert to Universal Time. | |
1194 ((eq type 'ut) | |
1195 (concat "Date: " | |
1196 (condition-case () | |
1197 (timezone-make-date-arpa-standard date nil "UT") | |
1198 (error date)) | |
1199 "\n")) | |
1200 ;; Get the original date from the article. | |
1201 ((eq type 'original) | |
1202 (concat "Date: " date "\n")) | |
1203 ;; Let the user define the format. | |
1204 ((eq type 'user) | |
1205 (concat | |
1206 (format-time-string gnus-article-time-format | |
1207 (ignore-errors | |
1208 (gnus-encode-date | |
1209 (timezone-make-date-arpa-standard | |
1210 date nil "UT")))) | |
1211 "\n")) | |
1212 ;; Do an X-Sent lapsed format. | |
1213 ((eq type 'lapsed) | |
1214 ;; If the date is seriously mangled, the timezone functions are | |
1215 ;; liable to bug out, so we ignore all errors. | |
1216 (let* ((now (current-time)) | |
1217 (real-time | |
1218 (ignore-errors | |
1219 (gnus-time-minus | |
1220 (gnus-encode-date | |
1221 (timezone-make-date-arpa-standard | |
1222 (current-time-string now) | |
1223 (current-time-zone now) "UT")) | |
1224 (gnus-encode-date | |
1225 (timezone-make-date-arpa-standard | |
1226 date nil "UT"))))) | |
1227 (real-sec (and real-time | |
1228 (+ (* (float (car real-time)) 65536) | |
1229 (cadr real-time)))) | |
1230 (sec (and real-time (abs real-sec))) | |
1231 num prev) | |
1232 (cond | |
1233 ((null real-time) | |
1234 "X-Sent: Unknown\n") | |
1235 ((zerop sec) | |
1236 "X-Sent: Now\n") | |
1237 (t | |
1238 (concat | |
1239 "X-Sent: " | |
1240 ;; This is a bit convoluted, but basically we go | |
1241 ;; through the time units for years, weeks, etc, | |
1242 ;; and divide things to see whether that results | |
1243 ;; in positive answers. | |
1244 (mapconcat | |
1245 (lambda (unit) | |
1246 (if (zerop (setq num (ffloor (/ sec (cdr unit))))) | |
1247 ;; The (remaining) seconds are too few to | |
1248 ;; be divided into this time unit. | |
1249 "" | |
1250 ;; It's big enough, so we output it. | |
1251 (setq sec (- sec (* num (cdr unit)))) | |
1252 (prog1 | |
1253 (concat (if prev ", " "") (int-to-string | |
1254 (floor num)) | |
1255 " " (symbol-name (car unit)) | |
1256 (if (> num 1) "s" "")) | |
1257 (setq prev t)))) | |
1258 article-time-units "") | |
1259 ;; If dates are odd, then it might appear like the | |
1260 ;; article was sent in the future. | |
1261 (if (> real-sec 0) | |
1262 " ago\n" | |
1263 " in the future\n")))))) | |
1264 (t | |
1265 (error "Unknown conversion type: %s" type)))) | |
1266 | |
1267 (defun article-date-local (&optional highlight) | |
1268 "Convert the current article date to the local timezone." | |
1269 (interactive (list t)) | |
1270 (article-date-ut 'local highlight)) | |
1271 | |
1272 (defun article-date-original (&optional highlight) | |
1273 "Convert the current article date to what it was originally. | |
1274 This is only useful if you have used some other date conversion | |
1275 function and want to see what the date was before converting." | |
1276 (interactive (list t)) | |
1277 (article-date-ut 'original highlight)) | |
1278 | |
1279 (defun article-date-lapsed (&optional highlight) | |
1280 "Convert the current article date to time lapsed since it was sent." | |
1281 (interactive (list t)) | |
1282 (article-date-ut 'lapsed highlight)) | |
1283 | |
1284 (defun article-date-user (&optional highlight) | |
1285 "Convert the current article date to the user-defined format." | |
1286 (interactive (list t)) | |
1287 (article-date-ut 'user highlight)) | |
1288 | |
1289 (defun article-show-all () | |
1290 "Show all hidden text in the article buffer." | |
1291 (interactive) | |
1292 (save-excursion | |
1293 (let ((buffer-read-only nil)) | |
1294 (gnus-article-unhide-text (point-min) (point-max))))) | |
1295 | |
1296 (defun article-emphasize (&optional arg) | |
1297 "Emphasize text according to `gnus-emphasis-alist'." | |
1298 (interactive (gnus-article-hidden-arg)) | |
1299 (unless (gnus-article-check-hidden-text 'emphasis arg) | |
1300 (save-excursion | |
1301 (let ((alist gnus-emphasis-alist) | |
1302 (buffer-read-only nil) | |
1303 (props (append '(article-type emphasis) | |
1304 gnus-hidden-properties)) | |
1305 regexp elem beg invisible visible face) | |
1306 (goto-char (point-min)) | |
1307 (search-forward "\n\n" nil t) | |
1308 (setq beg (point)) | |
1309 (while (setq elem (pop alist)) | |
1310 (goto-char beg) | |
1311 (setq regexp (car elem) | |
1312 invisible (nth 1 elem) | |
1313 visible (nth 2 elem) | |
1314 face (nth 3 elem)) | |
1315 (while (re-search-forward regexp nil t) | |
1316 (when (and (match-beginning visible) (match-beginning invisible)) | |
1317 (gnus-article-hide-text | |
1318 (match-beginning invisible) (match-end invisible) props) | |
1319 (gnus-article-unhide-text-type | |
1320 (match-beginning visible) (match-end visible) 'emphasis) | |
1321 (gnus-put-text-property-excluding-newlines | |
1322 (match-beginning visible) (match-end visible) 'face face) | |
1323 (goto-char (match-end invisible))))))))) | |
1324 | |
1325 (defvar gnus-summary-article-menu) | |
1326 (defvar gnus-summary-post-menu) | |
1327 | |
1328 ;;; Saving functions. | |
1329 | |
1330 (defun gnus-article-save (save-buffer file &optional num) | |
1331 "Save the currently selected article." | |
1332 (unless gnus-save-all-headers | |
1333 ;; Remove headers according to `gnus-saved-headers'. | |
1334 (let ((gnus-visible-headers | |
1335 (or gnus-saved-headers gnus-visible-headers)) | |
1336 (gnus-article-buffer save-buffer)) | |
1337 (gnus-article-hide-headers 1 t))) | |
1338 (save-window-excursion | |
1339 (if (not gnus-default-article-saver) | |
1340 (error "No default saver is defined.") | |
1341 ;; !!! Magic! The saving functions all save | |
1342 ;; `gnus-original-article-buffer' (or so they think), but we | |
1343 ;; bind that variable to our save-buffer. | |
1344 (set-buffer gnus-article-buffer) | |
1345 (let* ((gnus-save-article-buffer save-buffer) | |
1346 (filename | |
1347 (cond | |
1348 ((not gnus-prompt-before-saving) 'default) | |
1349 ((eq gnus-prompt-before-saving 'always) nil) | |
1350 (t file))) | |
1351 (gnus-number-of-articles-to-be-saved | |
1352 (when (eq gnus-prompt-before-saving t) | |
1353 num))) ; Magic | |
1354 (set-buffer gnus-summary-buffer) | |
1355 (funcall gnus-default-article-saver filename))))) | |
1356 | |
1357 (defun gnus-read-save-file-name (prompt default-name &optional filename) | |
1358 (cond | |
1359 ((eq filename 'default) | |
1360 default-name) | |
1361 (filename filename) | |
1362 (t | |
1363 (let* ((split-name (gnus-get-split-value gnus-split-methods)) | |
1364 (prompt | |
1365 (format prompt (if (and gnus-number-of-articles-to-be-saved | |
1366 (> gnus-number-of-articles-to-be-saved 1)) | |
1367 (format "these %d articles" | |
1368 gnus-number-of-articles-to-be-saved) | |
1369 "this article"))) | |
1370 (file | |
1371 ;; Let the split methods have their say. | |
1372 (cond | |
1373 ;; No split name was found. | |
1374 ((null split-name) | |
1375 (read-file-name | |
1376 (concat prompt " (default " | |
1377 (file-name-nondirectory default-name) ") ") | |
1378 (file-name-directory default-name) | |
1379 default-name)) | |
1380 ;; A single split name was found | |
1381 ((= 1 (length split-name)) | |
1382 (let* ((name (car split-name)) | |
1383 (dir (cond ((file-directory-p name) | |
1384 (file-name-as-directory name)) | |
1385 ((file-exists-p name) name) | |
1386 (t gnus-article-save-directory)))) | |
1387 (read-file-name | |
1388 (concat prompt " (default " name ") ") | |
1389 dir name))) | |
1390 ;; A list of splits was found. | |
1391 (t | |
1392 (setq split-name (nreverse split-name)) | |
1393 (let (result) | |
1394 (let ((file-name-history (nconc split-name file-name-history))) | |
1395 (setq result | |
1396 (expand-file-name | |
1397 (read-file-name | |
1398 (concat prompt " (`M-p' for defaults) ") | |
1399 gnus-article-save-directory | |
1400 (car split-name)) | |
1401 gnus-article-save-directory))) | |
1402 (car (push result file-name-history))))))) | |
1403 ;; Create the directory. | |
1404 (gnus-make-directory (file-name-directory file)) | |
1405 ;; If we have read a directory, we append the default file name. | |
1406 (when (file-directory-p file) | |
1407 (setq file (concat (file-name-as-directory file) | |
1408 (file-name-nondirectory default-name)))) | |
1409 ;; Possibly translate some characters. | |
1410 (nnheader-translate-file-chars file))))) | |
1411 | |
1412 (defun gnus-article-archive-name (group) | |
1413 "Return the first instance of an \"Archive-name\" in the current buffer." | |
1414 (let ((case-fold-search t)) | |
1415 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t) | |
1416 (nnheader-concat gnus-article-save-directory | |
1417 (match-string 1))))) | |
1418 | |
1419 (defun gnus-summary-save-in-rmail (&optional filename) | |
1420 "Append this article to Rmail file. | |
1421 Optional argument FILENAME specifies file name. | |
1422 Directory to save to is default to `gnus-article-save-directory'." | |
1423 (interactive) | |
1424 (gnus-set-global-variables) | |
1425 (let ((default-name | |
1426 (funcall gnus-rmail-save-name gnus-newsgroup-name | |
1427 gnus-current-headers gnus-newsgroup-last-rmail))) | |
1428 (setq filename (gnus-read-save-file-name | |
1429 "Save %s in rmail file:" default-name filename)) | |
1430 (gnus-make-directory (file-name-directory filename)) | |
1431 (gnus-eval-in-buffer-window gnus-save-article-buffer | |
1432 (save-excursion | |
1433 (save-restriction | |
1434 (widen) | |
1435 (gnus-output-to-rmail filename)))) | |
1436 ;; Remember the directory name to save articles | |
1437 (setq gnus-newsgroup-last-rmail filename))) | |
1438 | |
1439 (defun gnus-summary-save-in-mail (&optional filename) | |
1440 "Append this article to Unix mail file. | |
1441 Optional argument FILENAME specifies file name. | |
1442 Directory to save to is default to `gnus-article-save-directory'." | |
1443 (interactive) | |
1444 (gnus-set-global-variables) | |
1445 (let ((default-name | |
1446 (funcall gnus-mail-save-name gnus-newsgroup-name | |
1447 gnus-current-headers gnus-newsgroup-last-mail))) | |
1448 (setq filename (gnus-read-save-file-name | |
1449 "Save %s in Unix mail file:" default-name filename)) | |
1450 (setq filename | |
1451 (expand-file-name filename | |
1452 (and default-name | |
1453 (file-name-directory default-name)))) | |
1454 (gnus-make-directory (file-name-directory filename)) | |
1455 (gnus-eval-in-buffer-window gnus-save-article-buffer | |
1456 (save-excursion | |
1457 (save-restriction | |
1458 (widen) | |
1459 (if (and (file-readable-p filename) | |
1460 (mail-file-babyl-p filename)) | |
1461 (gnus-output-to-rmail filename t) | |
1462 (gnus-output-to-mail filename))))) | |
1463 ;; Remember the directory name to save articles. | |
1464 (setq gnus-newsgroup-last-mail filename))) | |
1465 | |
1466 (defun gnus-summary-save-in-file (&optional filename overwrite) | |
1467 "Append this article to file. | |
1468 Optional argument FILENAME specifies file name. | |
1469 Directory to save to is default to `gnus-article-save-directory'." | |
1470 (interactive) | |
1471 (gnus-set-global-variables) | |
1472 (let ((default-name | |
1473 (funcall gnus-file-save-name gnus-newsgroup-name | |
1474 gnus-current-headers gnus-newsgroup-last-file))) | |
1475 (setq filename (gnus-read-save-file-name | |
1476 "Save %s in file:" default-name filename)) | |
1477 (gnus-make-directory (file-name-directory filename)) | |
1478 (gnus-eval-in-buffer-window gnus-save-article-buffer | |
1479 (save-excursion | |
1480 (save-restriction | |
1481 (widen) | |
1482 (when (and overwrite | |
1483 (file-exists-p filename)) | |
1484 (delete-file filename)) | |
1485 (gnus-output-to-file filename)))) | |
1486 ;; Remember the directory name to save articles. | |
1487 (setq gnus-newsgroup-last-file filename))) | |
1488 | |
1489 (defun gnus-summary-write-to-file (&optional filename) | |
1490 "Write this article to a file. | |
1491 Optional argument FILENAME specifies file name. | |
1492 The directory to save in defaults to `gnus-article-save-directory'." | |
1493 (interactive) | |
1494 (gnus-summary-save-in-file nil t)) | |
1495 | |
1496 (defun gnus-summary-save-body-in-file (&optional filename) | |
1497 "Append this article body to a file. | |
1498 Optional argument FILENAME specifies file name. | |
1499 The directory to save in defaults to `gnus-article-save-directory'." | |
1500 (interactive) | |
1501 (gnus-set-global-variables) | |
1502 (let ((default-name | |
1503 (funcall gnus-file-save-name gnus-newsgroup-name | |
1504 gnus-current-headers gnus-newsgroup-last-file))) | |
1505 (setq filename (gnus-read-save-file-name | |
1506 "Save %s body in file:" default-name filename)) | |
1507 (gnus-make-directory (file-name-directory filename)) | |
1508 (gnus-eval-in-buffer-window gnus-save-article-buffer | |
1509 (save-excursion | |
1510 (save-restriction | |
1511 (widen) | |
1512 (goto-char (point-min)) | |
1513 (when (search-forward "\n\n" nil t) | |
1514 (narrow-to-region (point) (point-max))) | |
1515 (gnus-output-to-file filename)))) | |
1516 ;; Remember the directory name to save articles. | |
1517 (setq gnus-newsgroup-last-file filename))) | |
1518 | |
1519 (defun gnus-summary-save-in-pipe (&optional command) | |
1520 "Pipe this article to subprocess." | |
1521 (interactive) | |
1522 (gnus-set-global-variables) | |
1523 (setq command | |
1524 (cond ((eq command 'default) | |
1525 gnus-last-shell-command) | |
1526 (command command) | |
1527 (t (read-string | |
1528 (format | |
1529 "Shell command on %s: " | |
1530 (if (and gnus-number-of-articles-to-be-saved | |
1531 (> gnus-number-of-articles-to-be-saved 1)) | |
1532 (format "these %d articles" | |
1533 gnus-number-of-articles-to-be-saved) | |
1534 "this article")) | |
1535 gnus-last-shell-command)))) | |
1536 (when (string-equal command "") | |
1537 (setq command gnus-last-shell-command)) | |
1538 (gnus-eval-in-buffer-window gnus-article-buffer | |
1539 (save-restriction | |
1540 (widen) | |
1541 (shell-command-on-region (point-min) (point-max) command nil))) | |
1542 (setq gnus-last-shell-command command)) | |
1543 | |
1544 ;;; Article file names when saving. | |
1545 | |
1546 (defun gnus-capitalize-newsgroup (newsgroup) | |
1547 "Capitalize NEWSGROUP name." | |
1548 (when (not (zerop (length newsgroup))) | |
1549 (concat (char-to-string (upcase (aref newsgroup 0))) | |
1550 (substring newsgroup 1)))) | |
1551 | |
1552 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file) | |
1553 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
1554 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num. | |
1555 Otherwise, it is like ~/News/news/group/num." | |
1556 (let ((default | |
1557 (expand-file-name | |
1558 (concat (if (gnus-use-long-file-name 'not-save) | |
1559 (gnus-capitalize-newsgroup newsgroup) | |
1560 (gnus-newsgroup-directory-form newsgroup)) | |
1561 "/" (int-to-string (mail-header-number headers))) | |
1562 gnus-article-save-directory))) | |
1563 (if (and last-file | |
1564 (string-equal (file-name-directory default) | |
1565 (file-name-directory last-file)) | |
1566 (string-match "^[0-9]+$" (file-name-nondirectory last-file))) | |
1567 default | |
1568 (or last-file default)))) | |
1569 | |
1570 (defun gnus-numeric-save-name (newsgroup headers &optional last-file) | |
1571 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
1572 If variable `gnus-use-long-file-name' is non-nil, it is | |
1573 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num." | |
1574 (let ((default | |
1575 (expand-file-name | |
1576 (concat (if (gnus-use-long-file-name 'not-save) | |
1577 newsgroup | |
1578 (gnus-newsgroup-directory-form newsgroup)) | |
1579 "/" (int-to-string (mail-header-number headers))) | |
1580 gnus-article-save-directory))) | |
1581 (if (and last-file | |
1582 (string-equal (file-name-directory default) | |
1583 (file-name-directory last-file)) | |
1584 (string-match "^[0-9]+$" (file-name-nondirectory last-file))) | |
1585 default | |
1586 (or last-file default)))) | |
1587 | |
1588 (defun gnus-Plain-save-name (newsgroup headers &optional last-file) | |
1589 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
1590 If variable `gnus-use-long-file-name' is non-nil, it is | |
1591 ~/News/News.group. Otherwise, it is like ~/News/news/group/news." | |
1592 (or last-file | |
1593 (expand-file-name | |
1594 (if (gnus-use-long-file-name 'not-save) | |
1595 (gnus-capitalize-newsgroup newsgroup) | |
1596 (concat (gnus-newsgroup-directory-form newsgroup) "/news")) | |
1597 gnus-article-save-directory))) | |
1598 | |
1599 (defun gnus-plain-save-name (newsgroup headers &optional last-file) | |
1600 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
1601 If variable `gnus-use-long-file-name' is non-nil, it is | |
1602 ~/News/news.group. Otherwise, it is like ~/News/news/group/news." | |
1603 (or last-file | |
1604 (expand-file-name | |
1605 (if (gnus-use-long-file-name 'not-save) | |
1606 newsgroup | |
1607 (concat (gnus-newsgroup-directory-form newsgroup) "/news")) | |
1608 gnus-article-save-directory))) | |
1609 | |
1610 (eval-and-compile | |
1611 (mapcar | |
1612 (lambda (func) | |
1613 (let (afunc gfunc) | |
1614 (if (consp func) | |
1615 (setq afunc (car func) | |
1616 gfunc (cdr func)) | |
1617 (setq afunc func | |
1618 gfunc (intern (format "gnus-%s" func)))) | |
1619 (fset gfunc | |
1620 (if (not (fboundp afunc)) | |
1621 nil | |
1622 `(lambda (&optional interactive &rest args) | |
1623 ,(documentation afunc t) | |
1624 (interactive (list t)) | |
1625 (save-excursion | |
1626 (set-buffer gnus-article-buffer) | |
1627 (if interactive | |
1628 (call-interactively ',afunc) | |
1629 (apply ',afunc args)))))))) | |
1630 '(article-hide-headers | |
1631 article-hide-boring-headers | |
1632 article-treat-overstrike | |
1633 (article-fill . gnus-article-word-wrap) | |
1634 article-remove-cr | |
1635 article-display-x-face | |
1636 article-de-quoted-unreadable | |
1637 article-mime-decode-quoted-printable | |
1638 article-hide-pgp | |
1639 article-hide-pem | |
1640 article-hide-signature | |
1641 article-remove-trailing-blank-lines | |
1642 article-strip-leading-blank-lines | |
1643 article-strip-multiple-blank-lines | |
1644 article-strip-blank-lines | |
1645 article-date-local | |
1646 article-date-original | |
1647 article-date-ut | |
1648 article-date-user | |
1649 article-date-lapsed | |
1650 article-emphasize | |
1651 (article-show-all . gnus-article-show-all-headers)))) | |
1652 | |
1653 ;;; | |
1654 ;;; Gnus article mode | |
1655 ;;; | |
1656 | |
1657 (put 'gnus-article-mode 'mode-class 'special) | |
1658 | |
1659 (when t | |
1660 (gnus-define-keys gnus-article-mode-map | |
1661 " " gnus-article-goto-next-page | |
1662 "\177" gnus-article-goto-prev-page | |
1663 [delete] gnus-article-goto-prev-page | |
1664 "\C-c^" gnus-article-refer-article | |
1665 "h" gnus-article-show-summary | |
1666 "s" gnus-article-show-summary | |
1667 "\C-c\C-m" gnus-article-mail | |
1668 "?" gnus-article-describe-briefly | |
1669 gnus-mouse-2 gnus-article-push-button | |
1670 "\r" gnus-article-press-button | |
1671 "\t" gnus-article-next-button | |
1672 "\M-\t" gnus-article-prev-button | |
1673 "e" gnus-article-edit | |
1674 "<" beginning-of-buffer | |
1675 ">" end-of-buffer | |
1676 "\C-c\C-i" gnus-info-find-node | |
1677 "\C-c\C-b" gnus-bug | |
1678 | |
1679 "\C-d" gnus-article-read-summary-keys | |
1680 "\M-*" gnus-article-read-summary-keys | |
1681 "\M-#" gnus-article-read-summary-keys | |
1682 "\M-^" gnus-article-read-summary-keys | |
1683 "\M-g" gnus-article-read-summary-keys) | |
1684 | |
1685 (substitute-key-definition | |
1686 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)) | |
1687 | |
1688 (defun gnus-article-make-menu-bar () | |
1689 (gnus-turn-off-edit-menu 'article) | |
1690 (unless (boundp 'gnus-article-article-menu) | |
1691 (easy-menu-define | |
1692 gnus-article-article-menu gnus-article-mode-map "" | |
1693 '("Article" | |
1694 ["Scroll forwards" gnus-article-goto-next-page t] | |
1695 ["Scroll backwards" gnus-article-goto-prev-page t] | |
1696 ["Show summary" gnus-article-show-summary t] | |
1697 ["Fetch Message-ID at point" gnus-article-refer-article t] | |
1698 ["Mail to address at point" gnus-article-mail t])) | |
1699 | |
1700 (easy-menu-define | |
1701 gnus-article-treatment-menu gnus-article-mode-map "" | |
1702 '("Treatment" | |
1703 ["Hide headers" gnus-article-hide-headers t] | |
1704 ["Hide signature" gnus-article-hide-signature t] | |
1705 ["Hide citation" gnus-article-hide-citation t] | |
1706 ["Treat overstrike" gnus-article-treat-overstrike t] | |
1707 ["Remove carriage return" gnus-article-remove-cr t] | |
1708 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t])) | |
1709 | |
1710 (when nil | |
1711 (when (boundp 'gnus-summary-article-menu) | |
1712 (define-key gnus-article-mode-map [menu-bar commands] | |
1713 (cons "Commands" gnus-summary-article-menu)))) | |
1714 | |
1715 (when (boundp 'gnus-summary-post-menu) | |
1716 (define-key gnus-article-mode-map [menu-bar post] | |
1717 (cons "Post" gnus-summary-post-menu))) | |
1718 | |
1719 (run-hooks 'gnus-article-menu-hook))) | |
1720 | |
1721 (defun gnus-article-mode () | |
1722 "Major mode for displaying an article. | |
1723 | |
1724 All normal editing commands are switched off. | |
1725 | |
1726 The following commands are available in addition to all summary mode | |
1727 commands: | |
1728 \\<gnus-article-mode-map> | |
1729 \\[gnus-article-next-page]\t Scroll the article one page forwards | |
1730 \\[gnus-article-prev-page]\t Scroll the article one page backwards | |
1731 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point | |
1732 \\[gnus-article-show-summary]\t Display the summary buffer | |
1733 \\[gnus-article-mail]\t Send a reply to the address near point | |
1734 \\[gnus-article-describe-briefly]\t Describe the current mode briefly | |
1735 \\[gnus-info-find-node]\t Go to the Gnus info node" | |
1736 (interactive) | |
1737 (when (gnus-visual-p 'article-menu 'menu) | |
1738 (gnus-article-make-menu-bar)) | |
1739 (kill-all-local-variables) | |
1740 (gnus-simplify-mode-line) | |
1741 (setq mode-name "Article") | |
1742 (setq major-mode 'gnus-article-mode) | |
1743 (make-local-variable 'minor-mode-alist) | |
1744 (unless (assq 'gnus-show-mime minor-mode-alist) | |
1745 (push (list 'gnus-show-mime " MIME") minor-mode-alist)) | |
1746 (use-local-map gnus-article-mode-map) | |
1747 (gnus-update-format-specifications nil 'article-mode) | |
1748 (set (make-local-variable 'page-delimiter) gnus-page-delimiter) | |
1749 (gnus-set-default-directory) | |
1750 (buffer-disable-undo (current-buffer)) | |
1751 (setq buffer-read-only t) | |
1752 (set-syntax-table gnus-article-mode-syntax-table) | |
1753 (run-hooks 'gnus-article-mode-hook)) | |
1754 | |
1755 (defun gnus-article-setup-buffer () | |
1756 "Initialize the article buffer." | |
1757 (let* ((name (if gnus-single-article-buffer "*Article*" | |
1758 (concat "*Article " gnus-newsgroup-name "*"))) | |
1759 (original | |
1760 (progn (string-match "\\*Article" name) | |
1761 (concat " *Original Article" | |
1762 (substring name (match-end 0)))))) | |
1763 (setq gnus-article-buffer name) | |
1764 (setq gnus-original-article-buffer original) | |
1765 ;; This might be a variable local to the summary buffer. | |
1766 (unless gnus-single-article-buffer | |
1767 (save-excursion | |
1768 (set-buffer gnus-summary-buffer) | |
1769 (setq gnus-article-buffer name) | |
1770 (setq gnus-original-article-buffer original) | |
1771 (gnus-set-global-variables))) | |
1772 ;; Init original article buffer. | |
1773 (save-excursion | |
1774 (set-buffer (get-buffer-create gnus-original-article-buffer)) | |
1775 (buffer-disable-undo (current-buffer)) | |
1776 (setq major-mode 'gnus-original-article-mode) | |
1777 (gnus-add-current-to-buffer-list) | |
1778 (make-local-variable 'gnus-original-article)) | |
1779 (if (get-buffer name) | |
1780 (save-excursion | |
1781 (set-buffer name) | |
1782 (buffer-disable-undo (current-buffer)) | |
1783 (setq buffer-read-only t) | |
1784 (gnus-add-current-to-buffer-list) | |
1785 (unless (eq major-mode 'gnus-article-mode) | |
1786 (gnus-article-mode)) | |
1787 (current-buffer)) | |
1788 (save-excursion | |
1789 (set-buffer (get-buffer-create name)) | |
1790 (gnus-add-current-to-buffer-list) | |
1791 (gnus-article-mode) | |
1792 (make-local-variable 'gnus-summary-buffer) | |
1793 (current-buffer))))) | |
1794 | |
1795 ;; Set article window start at LINE, where LINE is the number of lines | |
1796 ;; from the head of the article. | |
1797 (defun gnus-article-set-window-start (&optional line) | |
1798 (set-window-start | |
1799 (get-buffer-window gnus-article-buffer t) | |
1800 (save-excursion | |
1801 (set-buffer gnus-article-buffer) | |
1802 (goto-char (point-min)) | |
1803 (if (not line) | |
1804 (point-min) | |
1805 (gnus-message 6 "Moved to bookmark") | |
1806 (search-forward "\n\n" nil t) | |
1807 (forward-line line) | |
1808 (point))))) | |
1809 | |
1810 (defun gnus-article-prepare (article &optional all-headers header) | |
1811 "Prepare ARTICLE in article mode buffer. | |
1812 ARTICLE should either be an article number or a Message-ID. | |
1813 If ARTICLE is an id, HEADER should be the article headers. | |
1814 If ALL-HEADERS is non-nil, no headers are hidden." | |
1815 (save-excursion | |
1816 ;; Make sure we start in a summary buffer. | |
1817 (unless (eq major-mode 'gnus-summary-mode) | |
1818 (set-buffer gnus-summary-buffer)) | |
1819 (setq gnus-summary-buffer (current-buffer)) | |
1820 ;; Make sure the connection to the server is alive. | |
1821 (unless (gnus-server-opened | |
1822 (gnus-find-method-for-group gnus-newsgroup-name)) | |
1823 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name)) | |
1824 (gnus-request-group gnus-newsgroup-name t)) | |
1825 (let* ((gnus-article (if header (mail-header-number header) article)) | |
1826 (summary-buffer (current-buffer)) | |
1827 (internal-hook gnus-article-internal-prepare-hook) | |
1828 (group gnus-newsgroup-name) | |
1829 result) | |
1830 (save-excursion | |
1831 (gnus-article-setup-buffer) | |
1832 (set-buffer gnus-article-buffer) | |
1833 ;; Deactivate active regions. | |
1834 (when (and (boundp 'transient-mark-mode) | |
1835 transient-mark-mode) | |
1836 (setq mark-active nil)) | |
1837 (if (not (setq result (let ((buffer-read-only nil)) | |
1838 (gnus-request-article-this-buffer | |
1839 article group)))) | |
1840 ;; There is no such article. | |
1841 (save-excursion | |
1842 (when (and (numberp article) | |
1843 (not (memq article gnus-newsgroup-sparse))) | |
1844 (setq gnus-article-current | |
1845 (cons gnus-newsgroup-name article)) | |
1846 (set-buffer gnus-summary-buffer) | |
1847 (setq gnus-current-article article) | |
1848 (gnus-summary-mark-article article gnus-canceled-mark)) | |
1849 (unless (memq article gnus-newsgroup-sparse) | |
1850 (gnus-error | |
1851 1 "No such article (may have expired or been canceled)"))) | |
1852 (if (or (eq result 'pseudo) (eq result 'nneething)) | |
1853 (progn | |
1854 (save-excursion | |
1855 (set-buffer summary-buffer) | |
1856 (setq gnus-last-article gnus-current-article | |
1857 gnus-newsgroup-history (cons gnus-current-article | |
1858 gnus-newsgroup-history) | |
1859 gnus-current-article 0 | |
1860 gnus-current-headers nil | |
1861 gnus-article-current nil) | |
1862 (if (eq result 'nneething) | |
1863 (gnus-configure-windows 'summary) | |
1864 (gnus-configure-windows 'article)) | |
1865 (gnus-set-global-variables)) | |
1866 (gnus-set-mode-line 'article)) | |
1867 ;; The result from the `request' was an actual article - | |
1868 ;; or at least some text that is now displayed in the | |
1869 ;; article buffer. | |
1870 (when (and (numberp article) | |
1871 (not (eq article gnus-current-article))) | |
1872 ;; Seems like a new article has been selected. | |
1873 ;; `gnus-current-article' must be an article number. | |
1874 (save-excursion | |
1875 (set-buffer summary-buffer) | |
1876 (setq gnus-last-article gnus-current-article | |
1877 gnus-newsgroup-history (cons gnus-current-article | |
1878 gnus-newsgroup-history) | |
1879 gnus-current-article article | |
1880 gnus-current-headers | |
1881 (gnus-summary-article-header gnus-current-article) | |
1882 gnus-article-current | |
1883 (cons gnus-newsgroup-name gnus-current-article)) | |
1884 (unless (vectorp gnus-current-headers) | |
1885 (setq gnus-current-headers nil)) | |
1886 (gnus-summary-show-thread) | |
1887 (run-hooks 'gnus-mark-article-hook) | |
1888 (gnus-set-mode-line 'summary) | |
1889 (when (gnus-visual-p 'article-highlight 'highlight) | |
1890 (run-hooks 'gnus-visual-mark-article-hook)) | |
1891 ;; Set the global newsgroup variables here. | |
1892 ;; Suggested by Jim Sisolak | |
1893 ;; <sisolak@trans4.neep.wisc.edu>. | |
1894 (gnus-set-global-variables) | |
1895 (setq gnus-have-all-headers | |
1896 (or all-headers gnus-show-all-headers)) | |
1897 (and gnus-use-cache | |
1898 (vectorp (gnus-summary-article-header article)) | |
1899 (gnus-cache-possibly-enter-article | |
1900 group article | |
1901 (gnus-summary-article-header article) | |
1902 (memq article gnus-newsgroup-marked) | |
1903 (memq article gnus-newsgroup-dormant) | |
1904 (memq article gnus-newsgroup-unreads))))) | |
1905 (when (or (numberp article) | |
1906 (stringp article)) | |
1907 ;; Hooks for getting information from the article. | |
1908 ;; This hook must be called before being narrowed. | |
1909 (let (buffer-read-only) | |
1910 (run-hooks 'internal-hook) | |
1911 (run-hooks 'gnus-article-prepare-hook) | |
1912 ;; Decode MIME message. | |
1913 (when gnus-show-mime | |
1914 (if (or (not gnus-strict-mime) | |
1915 (gnus-fetch-field "Mime-Version")) | |
1916 (funcall gnus-show-mime-method) | |
1917 (funcall gnus-decode-encoded-word-method))) | |
1918 ;; Perform the article display hooks. | |
1919 (run-hooks 'gnus-article-display-hook)) | |
1920 ;; Do page break. | |
1921 (goto-char (point-min)) | |
1922 (when gnus-break-pages | |
1923 (gnus-narrow-to-page))) | |
1924 (gnus-set-mode-line 'article) | |
1925 (gnus-configure-windows 'article) | |
1926 (goto-char (point-min)) | |
1927 t)))))) | |
1928 | |
1929 (defun gnus-article-wash-status () | |
1930 "Return a string which display status of article washing." | |
1931 (save-excursion | |
1932 (set-buffer gnus-article-buffer) | |
1933 (let ((cite (gnus-article-hidden-text-p 'cite)) | |
1934 (headers (gnus-article-hidden-text-p 'headers)) | |
1935 (boring (gnus-article-hidden-text-p 'boring-headers)) | |
1936 (pgp (gnus-article-hidden-text-p 'pgp)) | |
1937 (pem (gnus-article-hidden-text-p 'pem)) | |
1938 (signature (gnus-article-hidden-text-p 'signature)) | |
1939 (overstrike (gnus-article-hidden-text-p 'overstrike)) | |
1940 (emphasis (gnus-article-hidden-text-p 'emphasis)) | |
1941 (mime gnus-show-mime)) | |
1942 (format "%c%c%c%c%c%c%c" | |
1943 (if cite ?c ? ) | |
1944 (if (or headers boring) ?h ? ) | |
1945 (if (or pgp pem) ?p ? ) | |
1946 (if signature ?s ? ) | |
1947 (if overstrike ?o ? ) | |
1948 (if mime ?m ? ) | |
1949 (if emphasis ?e ? ))))) | |
1950 | |
1951 (defun gnus-article-hide-headers-if-wanted () | |
1952 "Hide unwanted headers if `gnus-have-all-headers' is nil. | |
1953 Provided for backwards compatibility." | |
1954 (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers) | |
1955 gnus-inhibit-hiding | |
1956 (gnus-article-hide-headers))) | |
1957 | |
1958 ;;; Article savers. | |
1959 | |
1960 (defun gnus-output-to-file (file-name) | |
1961 "Append the current article to a file named FILE-NAME." | |
1962 (let ((artbuf (current-buffer))) | |
1963 (nnheader-temp-write nil | |
1964 (insert-buffer-substring artbuf) | |
1965 ;; Append newline at end of the buffer as separator, and then | |
1966 ;; save it to file. | |
1967 (goto-char (point-max)) | |
1968 (insert "\n") | |
1969 (append-to-file (point-min) (point-max) file-name)))) | |
1970 | |
1971 (defun gnus-narrow-to-page (&optional arg) | |
1972 "Narrow the article buffer to a page. | |
1973 If given a numerical ARG, move forward ARG pages." | |
1974 (interactive "P") | |
1975 (setq arg (if arg (prefix-numeric-value arg) 0)) | |
1976 (save-excursion | |
1977 (set-buffer gnus-article-buffer) | |
1978 (goto-char (point-min)) | |
1979 (widen) | |
1980 ;; Remove any old next/prev buttons. | |
1981 (when (gnus-visual-p 'page-marker) | |
1982 (let ((buffer-read-only nil)) | |
1983 (gnus-remove-text-with-property 'gnus-prev) | |
1984 (gnus-remove-text-with-property 'gnus-next))) | |
1985 (when | |
1986 (cond ((< arg 0) | |
1987 (re-search-backward page-delimiter nil 'move (1+ (abs arg)))) | |
1988 ((> arg 0) | |
1989 (re-search-forward page-delimiter nil 'move arg))) | |
1990 (goto-char (match-end 0))) | |
1991 (narrow-to-region | |
1992 (point) | |
1993 (if (re-search-forward page-delimiter nil 'move) | |
1994 (match-beginning 0) | |
1995 (point))) | |
1996 (when (and (gnus-visual-p 'page-marker) | |
1997 (not (= (point-min) 1))) | |
1998 (save-excursion | |
1999 (goto-char (point-min)) | |
2000 (gnus-insert-prev-page-button))) | |
2001 (when (and (gnus-visual-p 'page-marker) | |
2002 (< (+ (point-max) 2) (buffer-size))) | |
2003 (save-excursion | |
2004 (goto-char (point-max)) | |
2005 (gnus-insert-next-page-button))))) | |
2006 | |
2007 ;; Article mode commands | |
2008 | |
2009 (defun gnus-article-goto-next-page () | |
2010 "Show the next page of the article." | |
2011 (interactive) | |
2012 (when (gnus-article-next-page) | |
2013 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n)))) | |
2014 | |
2015 (defun gnus-article-goto-prev-page () | |
2016 "Show the next page of the article." | |
2017 (interactive) | |
2018 (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?p)) | |
2019 (gnus-article-prev-page nil))) | |
2020 | |
2021 (defun gnus-article-next-page (&optional lines) | |
2022 "Show the next page of the current article. | |
2023 If end of article, return non-nil. Otherwise return nil. | |
2024 Argument LINES specifies lines to be scrolled up." | |
2025 (interactive "p") | |
2026 (move-to-window-line -1) | |
2027 (if (save-excursion | |
2028 (end-of-line) | |
2029 (and (pos-visible-in-window-p) ;Not continuation line. | |
2030 (eobp))) | |
2031 ;; Nothing in this page. | |
2032 (if (or (not gnus-break-pages) | |
2033 (save-excursion | |
2034 (save-restriction | |
2035 (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer? | |
2036 t ;Nothing more. | |
2037 (gnus-narrow-to-page 1) ;Go to next page. | |
2038 nil) | |
2039 ;; More in this page. | |
2040 (let ((scroll-in-place nil)) | |
2041 (condition-case () | |
2042 (scroll-up lines) | |
2043 (end-of-buffer | |
2044 ;; Long lines may cause an end-of-buffer error. | |
2045 (goto-char (point-max))))) | |
2046 (move-to-window-line 0) | |
2047 nil)) | |
2048 | |
2049 (defun gnus-article-prev-page (&optional lines) | |
2050 "Show previous page of current article. | |
2051 Argument LINES specifies lines to be scrolled down." | |
2052 (interactive "p") | |
2053 (move-to-window-line 0) | |
2054 (if (and gnus-break-pages | |
2055 (bobp) | |
2056 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer? | |
2057 (progn | |
2058 (gnus-narrow-to-page -1) ;Go to previous page. | |
2059 (goto-char (point-max)) | |
2060 (recenter -1)) | |
2061 (let ((scroll-in-place nil)) | |
2062 (prog1 | |
2063 (ignore-errors | |
2064 (scroll-down lines)) | |
2065 (move-to-window-line 0))))) | |
2066 | |
2067 (defun gnus-article-refer-article () | |
2068 "Read article specified by message-id around point." | |
2069 (interactive) | |
2070 (let ((point (point))) | |
2071 (search-forward ">" nil t) ;Move point to end of "<....>". | |
2072 (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t) | |
2073 (let ((message-id (match-string 1))) | |
2074 (goto-char point) | |
2075 (set-buffer gnus-summary-buffer) | |
2076 (gnus-summary-refer-article message-id)) | |
2077 (goto-char (point)) | |
2078 (error "No references around point")))) | |
2079 | |
2080 (defun gnus-article-show-summary () | |
2081 "Reconfigure windows to show summary buffer." | |
2082 (interactive) | |
2083 (gnus-configure-windows 'article) | |
2084 (gnus-summary-goto-subject gnus-current-article)) | |
2085 | |
2086 (defun gnus-article-describe-briefly () | |
2087 "Describe article mode commands briefly." | |
2088 (interactive) | |
2089 (gnus-message 6 | |
2090 (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help"))) | |
2091 | |
2092 (defun gnus-article-summary-command () | |
2093 "Execute the last keystroke in the summary buffer." | |
2094 (interactive) | |
2095 (let ((obuf (current-buffer)) | |
2096 (owin (current-window-configuration)) | |
2097 func) | |
2098 (switch-to-buffer gnus-summary-buffer 'norecord) | |
2099 (setq func (lookup-key (current-local-map) (this-command-keys))) | |
2100 (call-interactively func) | |
2101 (set-buffer obuf) | |
2102 (set-window-configuration owin) | |
2103 (set-window-point (get-buffer-window (current-buffer)) (point)))) | |
2104 | |
2105 (defun gnus-article-summary-command-nosave () | |
2106 "Execute the last keystroke in the summary buffer." | |
2107 (interactive) | |
2108 (let (func) | |
2109 (pop-to-buffer gnus-summary-buffer 'norecord) | |
2110 (setq func (lookup-key (current-local-map) (this-command-keys))) | |
2111 (call-interactively func))) | |
2112 | |
2113 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window) | |
2114 "Read a summary buffer key sequence and execute it from the article buffer." | |
2115 (interactive "P") | |
2116 (let ((nosaves | |
2117 '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F" | |
2118 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP" | |
2119 "=" "^" "\M-^" "|")) | |
2120 (nosave-but-article | |
2121 '("A\r")) | |
2122 (nosave-in-article | |
2123 '("\C-d")) | |
2124 keys) | |
2125 (save-excursion | |
2126 (set-buffer gnus-summary-buffer) | |
2127 (let (gnus-pick-mode) | |
2128 (push (or key last-command-event) unread-command-events) | |
2129 (setq keys (read-key-sequence nil)))) | |
2130 (message "") | |
2131 | |
2132 (if (or (member keys nosaves) | |
2133 (member keys nosave-but-article) | |
2134 (member keys nosave-in-article)) | |
2135 (let (func) | |
2136 (save-window-excursion | |
2137 (pop-to-buffer gnus-summary-buffer 'norecord) | |
2138 ;; We disable the pick minor mode commands. | |
2139 (let (gnus-pick-mode) | |
2140 (setq func (lookup-key (current-local-map) keys)))) | |
2141 (if (not func) | |
2142 (ding) | |
2143 (unless (member keys nosave-in-article) | |
2144 (set-buffer gnus-summary-buffer)) | |
2145 (call-interactively func)) | |
2146 (when (member keys nosave-but-article) | |
2147 (pop-to-buffer gnus-article-buffer 'norecord))) | |
2148 ;; These commands should restore window configuration. | |
2149 (let ((obuf (current-buffer)) | |
2150 (owin (current-window-configuration)) | |
2151 (opoint (point)) | |
2152 func in-buffer) | |
2153 (if not-restore-window | |
2154 (pop-to-buffer gnus-summary-buffer 'norecord) | |
2155 (switch-to-buffer gnus-summary-buffer 'norecord)) | |
2156 (setq in-buffer (current-buffer)) | |
2157 ;; We disable the pick minor mode commands. | |
2158 (if (setq func (let (gnus-pick-mode) | |
2159 (lookup-key (current-local-map) keys))) | |
2160 (call-interactively func) | |
2161 (ding)) | |
2162 (when (eq in-buffer (current-buffer)) | |
2163 (set-buffer obuf) | |
2164 (unless not-restore-window | |
2165 (set-window-configuration owin)) | |
2166 (set-window-point (get-buffer-window (current-buffer)) opoint)))))) | |
2167 | |
2168 (defun gnus-article-hide (&optional arg force) | |
2169 "Hide all the gruft in the current article. | |
2170 This means that PGP stuff, signatures, cited text and (some) | |
2171 headers will be hidden. | |
2172 If given a prefix, show the hidden text instead." | |
2173 (interactive (list current-prefix-arg 'force)) | |
2174 (gnus-article-hide-headers arg) | |
2175 (gnus-article-hide-pgp arg) | |
2176 (gnus-article-hide-citation-maybe arg force) | |
2177 (gnus-article-hide-signature arg)) | |
2178 | |
2179 (defun gnus-article-maybe-highlight () | |
2180 "Do some article highlighting if `article-visual' is non-nil." | |
2181 (when (gnus-visual-p 'article-highlight 'highlight) | |
2182 (gnus-article-highlight-some))) | |
2183 | |
2184 (defun gnus-request-article-this-buffer (article group) | |
2185 "Get an article and insert it into this buffer." | |
2186 (let (do-update-line) | |
2187 (prog1 | |
2188 (save-excursion | |
2189 (erase-buffer) | |
2190 (gnus-kill-all-overlays) | |
2191 (setq group (or group gnus-newsgroup-name)) | |
2192 | |
2193 ;; Open server if it has closed. | |
2194 (gnus-check-server (gnus-find-method-for-group group)) | |
2195 | |
2196 ;; Using `gnus-request-article' directly will insert the article into | |
2197 ;; `nntp-server-buffer' - so we'll save some time by not having to | |
2198 ;; copy it from the server buffer into the article buffer. | |
2199 | |
2200 ;; We only request an article by message-id when we do not have the | |
2201 ;; headers for it, so we'll have to get those. | |
2202 (when (stringp article) | |
2203 (let ((gnus-override-method gnus-refer-article-method)) | |
2204 (gnus-read-header article))) | |
2205 | |
2206 ;; If the article number is negative, that means that this article | |
2207 ;; doesn't belong in this newsgroup (possibly), so we find its | |
2208 ;; message-id and request it by id instead of number. | |
2209 (when (and (numberp article) | |
2210 gnus-summary-buffer | |
2211 (get-buffer gnus-summary-buffer) | |
2212 (buffer-name (get-buffer gnus-summary-buffer))) | |
2213 (save-excursion | |
2214 (set-buffer gnus-summary-buffer) | |
2215 (let ((header (gnus-summary-article-header article))) | |
2216 (when (< article 0) | |
2217 (cond | |
2218 ((memq article gnus-newsgroup-sparse) | |
2219 ;; This is a sparse gap article. | |
2220 (setq do-update-line article) | |
2221 (setq article (mail-header-id header)) | |
2222 (let ((gnus-override-method gnus-refer-article-method)) | |
2223 (gnus-read-header article)) | |
2224 (setq gnus-newsgroup-sparse | |
2225 (delq article gnus-newsgroup-sparse))) | |
2226 ((vectorp header) | |
2227 ;; It's a real article. | |
2228 (setq article (mail-header-id header))) | |
2229 (t | |
2230 ;; It is an extracted pseudo-article. | |
2231 (setq article 'pseudo) | |
2232 (gnus-request-pseudo-article header)))) | |
2233 | |
2234 (let ((method (gnus-find-method-for-group | |
2235 gnus-newsgroup-name))) | |
2236 (if (not (eq (car method) 'nneething)) | |
2237 () | |
2238 (let ((dir (concat (file-name-as-directory (nth 1 method)) | |
2239 (mail-header-subject header)))) | |
2240 (when (file-directory-p dir) | |
2241 (setq article 'nneething) | |
2242 (gnus-group-enter-directory dir)))))))) | |
2243 | |
2244 (cond | |
2245 ;; Refuse to select canceled articles. | |
2246 ((and (numberp article) | |
2247 gnus-summary-buffer | |
2248 (get-buffer gnus-summary-buffer) | |
2249 (buffer-name (get-buffer gnus-summary-buffer)) | |
2250 (eq (cdr (save-excursion | |
2251 (set-buffer gnus-summary-buffer) | |
2252 (assq article gnus-newsgroup-reads))) | |
2253 gnus-canceled-mark)) | |
2254 nil) | |
2255 ;; We first check `gnus-original-article-buffer'. | |
2256 ((and (get-buffer gnus-original-article-buffer) | |
2257 (numberp article) | |
2258 (save-excursion | |
2259 (set-buffer gnus-original-article-buffer) | |
2260 (and (equal (car gnus-original-article) group) | |
2261 (eq (cdr gnus-original-article) article)))) | |
2262 (insert-buffer-substring gnus-original-article-buffer) | |
2263 'article) | |
2264 ;; Check the backlog. | |
2265 ((and gnus-keep-backlog | |
2266 (gnus-backlog-request-article group article (current-buffer))) | |
2267 'article) | |
2268 ;; Check asynchronous pre-fetch. | |
2269 ((gnus-async-request-fetched-article group article (current-buffer)) | |
2270 (gnus-async-prefetch-next group article gnus-summary-buffer) | |
2271 'article) | |
2272 ;; Check the cache. | |
2273 ((and gnus-use-cache | |
2274 (numberp article) | |
2275 (gnus-cache-request-article article group)) | |
2276 'article) | |
2277 ;; Get the article and put into the article buffer. | |
2278 ((or (stringp article) (numberp article)) | |
2279 (let ((gnus-override-method | |
2280 (and (stringp article) gnus-refer-article-method)) | |
2281 (buffer-read-only nil)) | |
2282 (erase-buffer) | |
2283 (gnus-kill-all-overlays) | |
2284 (when (gnus-request-article article group (current-buffer)) | |
2285 (when (numberp article) | |
2286 (gnus-async-prefetch-next group article gnus-summary-buffer) | |
2287 (when gnus-keep-backlog | |
2288 (gnus-backlog-enter-article | |
2289 group article (current-buffer)))) | |
2290 'article))) | |
2291 ;; It was a pseudo. | |
2292 (t article))) | |
2293 | |
2294 ;; Take the article from the original article buffer | |
2295 ;; and place it in the buffer it's supposed to be in. | |
2296 (when (and (get-buffer gnus-article-buffer) | |
2297 ;;(numberp article) | |
2298 (equal (buffer-name (current-buffer)) | |
2299 (buffer-name (get-buffer gnus-article-buffer)))) | |
2300 (save-excursion | |
2301 (if (get-buffer gnus-original-article-buffer) | |
2302 (set-buffer (get-buffer gnus-original-article-buffer)) | |
2303 (set-buffer (get-buffer-create gnus-original-article-buffer)) | |
2304 (buffer-disable-undo (current-buffer)) | |
2305 (setq major-mode 'gnus-original-article-mode) | |
2306 (setq buffer-read-only t) | |
2307 (gnus-add-current-to-buffer-list)) | |
2308 (let (buffer-read-only) | |
2309 (erase-buffer) | |
2310 (insert-buffer-substring gnus-article-buffer)) | |
2311 (setq gnus-original-article (cons group article)))) | |
2312 | |
2313 ;; Update sparse articles. | |
2314 (when (and do-update-line | |
2315 (or (numberp article) | |
2316 (stringp article))) | |
2317 (let ((buf (current-buffer))) | |
2318 (set-buffer gnus-summary-buffer) | |
2319 (gnus-summary-update-article do-update-line) | |
2320 (gnus-summary-goto-subject do-update-line nil t) | |
2321 (set-window-point (get-buffer-window (current-buffer) t) | |
2322 (point)) | |
2323 (set-buffer buf)))))) | |
2324 | |
2325 ;;; | |
2326 ;;; Article editing | |
2327 ;;; | |
2328 | |
2329 (defcustom gnus-article-edit-mode-hook nil | |
2330 "Hook run in article edit mode buffers." | |
2331 :group 'gnus-article-various | |
2332 :type 'hook) | |
2333 | |
2334 (defvar gnus-article-edit-done-function nil) | |
2335 | |
2336 (defvar gnus-article-edit-mode-map nil) | |
2337 | |
2338 (unless gnus-article-edit-mode-map | |
2339 (setq gnus-article-edit-mode-map (copy-keymap text-mode-map)) | |
2340 | |
2341 (gnus-define-keys gnus-article-edit-mode-map | |
2342 "\C-c\C-c" gnus-article-edit-done | |
2343 "\C-c\C-k" gnus-article-edit-exit) | |
2344 | |
2345 (gnus-define-keys (gnus-article-edit-wash-map | |
2346 "\C-c\C-w" gnus-article-edit-mode-map) | |
2347 "f" gnus-article-edit-full-stops)) | |
2348 | |
2349 (defun gnus-article-edit-mode () | |
2350 "Major mode for editing articles. | |
2351 This is an extended text-mode. | |
2352 | |
2353 \\{gnus-article-edit-mode-map}" | |
2354 (interactive) | |
2355 (kill-all-local-variables) | |
2356 (setq major-mode 'gnus-article-edit-mode) | |
2357 (setq mode-name "Article Edit") | |
2358 (use-local-map gnus-article-edit-mode-map) | |
2359 (make-local-variable 'gnus-article-edit-done-function) | |
2360 (make-local-variable 'gnus-prev-winconf) | |
2361 (setq buffer-read-only nil) | |
2362 (buffer-enable-undo) | |
2363 (widen) | |
2364 (run-hooks 'text-mode 'gnus-article-edit-mode-hook)) | |
2365 | |
2366 (defun gnus-article-edit (&optional force) | |
2367 "Edit the current article. | |
2368 This will have permanent effect only in mail groups. | |
2369 If FORCE is non-nil, allow editing of articles even in read-only | |
2370 groups." | |
2371 (interactive "P") | |
2372 (when (and (not force) | |
2373 (gnus-group-read-only-p)) | |
2374 (error "The current newsgroup does not support article editing.")) | |
2375 (gnus-article-edit-article | |
2376 `(lambda () | |
2377 (gnus-summary-edit-article-done | |
2378 ,(or (mail-header-references gnus-current-headers) "") | |
2379 ,(gnus-group-read-only-p) ,gnus-summary-buffer)))) | |
2380 | |
2381 (defun gnus-article-edit-article (exit-func) | |
2382 "Start editing the contents of the current article buffer." | |
2383 (let ((winconf (current-window-configuration))) | |
2384 (set-buffer gnus-article-buffer) | |
2385 (gnus-article-edit-mode) | |
2386 (set-text-properties (point-min) (point-max) nil) | |
2387 (gnus-configure-windows 'edit-article) | |
2388 (setq gnus-article-edit-done-function exit-func) | |
2389 (setq gnus-prev-winconf winconf) | |
2390 (gnus-message 6 "C-c C-c to end edits"))) | |
2391 | |
2392 (defun gnus-article-edit-done () | |
2393 "Update the article edits and exit." | |
2394 (interactive) | |
2395 (let ((func gnus-article-edit-done-function) | |
2396 (buf (current-buffer)) | |
2397 (start (window-start))) | |
2398 (gnus-article-edit-exit) | |
2399 (save-excursion | |
2400 (set-buffer buf) | |
2401 (let ((buffer-read-only nil)) | |
2402 (funcall func))) | |
2403 (set-buffer buf) | |
2404 (set-window-start (get-buffer-window buf) start) | |
2405 (set-window-point (get-buffer-window buf) (point)))) | |
2406 | |
2407 (defun gnus-article-edit-exit () | |
2408 "Exit the article editing without updating." | |
2409 (interactive) | |
2410 ;; We remove all text props from the article buffer. | |
2411 (let ((buf (format "%s" (buffer-string))) | |
2412 (curbuf (current-buffer)) | |
2413 (p (point)) | |
2414 (window-start (window-start))) | |
2415 (erase-buffer) | |
2416 (insert buf) | |
2417 (let ((winconf gnus-prev-winconf)) | |
2418 (gnus-article-mode) | |
2419 ;; The cache and backlog have to be flushed somewhat. | |
2420 (when gnus-use-cache | |
2421 (gnus-cache-update-article | |
2422 (car gnus-article-current) (cdr gnus-article-current))) | |
2423 (when gnus-keep-backlog | |
2424 (gnus-backlog-remove-article | |
2425 (car gnus-article-current) (cdr gnus-article-current))) | |
2426 ;; Flush original article as well. | |
2427 (save-excursion | |
2428 (when (get-buffer gnus-original-article-buffer) | |
2429 (set-buffer gnus-original-article-buffer) | |
2430 (setq gnus-original-article nil))) | |
2431 (set-window-configuration winconf) | |
2432 ;; Tippy-toe some to make sure that point remains where it was. | |
2433 (let ((buf (current-buffer))) | |
2434 (set-buffer curbuf) | |
2435 (set-window-start (get-buffer-window (current-buffer)) window-start) | |
2436 (goto-char p) | |
2437 (set-buffer buf))))) | |
2438 | |
2439 (defun gnus-article-edit-full-stops () | |
2440 "Interactively repair spacing at end of sentences." | |
2441 (interactive) | |
2442 (save-excursion | |
2443 (goto-char (point-min)) | |
2444 (search-forward-regexp "^$" nil t) | |
2445 (let ((case-fold-search nil)) | |
2446 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2")))) | |
2447 | |
2448 ;;; | |
2449 ;;; Article highlights | |
2450 ;;; | |
2451 | |
2452 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>. | |
2453 | |
2454 ;;; Internal Variables: | |
2455 | |
2456 (defcustom gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?\\([-a-zA-Z0-9_=!?#$@~`%&*+|\\/:;.,]\\|\\w\\)+\\([-a-zA-Z0-9_=#$@~`%&*+|\\/]\\|\\w\\)" | |
2457 "Regular expression that matches URLs." | |
2458 :group 'gnus-article-buttons | |
2459 :type 'regexp) | |
2460 | |
2461 (defcustom gnus-button-alist | |
2462 `(("\\(\\b<\\(url: ?\\)?news:\\([^>\n\t ]*\\)>\\)" 1 t | |
2463 gnus-button-message-id 3) | |
2464 ("\\bnews:\\([^\n\t ]+\\)" 0 t gnus-button-message-id 1) | |
2465 ("\\(\\b<\\(url: ?\\)?news:\\(//\\)?\\([^>\n\t ]*\\)>\\)" 1 t | |
2466 gnus-button-fetch-group 4) | |
2467 ("\\bnews:\\(//\\)?\\([^>\n\t ]+\\)" 0 t gnus-button-fetch-group 2) | |
2468 ("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 | |
2469 t gnus-button-message-id 3) | |
2470 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" 0 t gnus-url-mailto 1) | |
2471 ("\\bmailto:\\([^ \n\t]+\\)" 0 t gnus-url-mailto 2) | |
2472 ;; This is how URLs _should_ be embedded in text... | |
2473 ("<URL: *\\([^>]*\\)>" 0 t gnus-button-embedded-url 1) | |
2474 ;; Raw URLs. | |
2475 (,gnus-button-url-regexp 0 t gnus-button-url 0)) | |
2476 "Alist of regexps matching buttons in article bodies. | |
2477 | |
2478 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where | |
2479 REGEXP: is the string matching text around the button, | |
2480 BUTTON: is the number of the regexp grouping actually matching the button, | |
2481 FORM: is a lisp expression which must eval to true for the button to | |
2482 be added, | |
2483 CALLBACK: is the function to call when the user push this button, and each | |
2484 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK. | |
2485 | |
2486 CALLBACK can also be a variable, in that case the value of that | |
2487 variable it the real callback function." | |
2488 :group 'gnus-article-buttons | |
2489 :type '(repeat (list regexp | |
2490 (integer :tag "Button") | |
2491 (sexp :tag "Form") | |
2492 (function :tag "Callback") | |
2493 (repeat :tag "Par" | |
2494 :inline t | |
2495 (integer :tag "Regexp group"))))) | |
2496 | |
2497 (defcustom gnus-header-button-alist | |
2498 `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>" | |
2499 0 t gnus-button-message-id 0) | |
2500 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" 1 t gnus-button-reply 1) | |
2501 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+" | |
2502 0 t gnus-button-mailto 0) | |
2503 ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0) | |
2504 ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0) | |
2505 ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t | |
2506 gnus-button-message-id 3)) | |
2507 "Alist of headers and regexps to match buttons in article heads. | |
2508 | |
2509 This alist is very similar to `gnus-button-alist', except that each | |
2510 alist has an additional HEADER element first in each entry: | |
2511 | |
2512 \(HEADER REGEXP BUTTON FORM CALLBACK PAR) | |
2513 | |
2514 HEADER is a regexp to match a header. For a fuller explanation, see | |
2515 `gnus-button-alist'." | |
2516 :group 'gnus-article-buttons | |
2517 :group 'gnus-article-headers | |
2518 :type '(repeat (list (regexp :tag "Header") | |
2519 regexp | |
2520 (integer :tag "Button") | |
2521 (sexp :tag "Form") | |
2522 (function :tag "Callback") | |
2523 (repeat :tag "Par" | |
2524 :inline t | |
2525 (integer :tag "Regexp group"))))) | |
2526 | |
2527 (defvar gnus-button-regexp nil) | |
2528 (defvar gnus-button-marker-list nil) | |
2529 ;; Regexp matching any of the regexps from `gnus-button-alist'. | |
2530 | |
2531 (defvar gnus-button-last nil) | |
2532 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build. | |
2533 | |
2534 ;;; Commands: | |
2535 | |
2536 (defun gnus-article-push-button (event) | |
2537 "Check text under the mouse pointer for a callback function. | |
2538 If the text under the mouse pointer has a `gnus-callback' property, | |
2539 call it with the value of the `gnus-data' text property." | |
2540 (interactive "e") | |
2541 (set-buffer (window-buffer (posn-window (event-start event)))) | |
2542 (let* ((pos (posn-point (event-start event))) | |
2543 (data (get-text-property pos 'gnus-data)) | |
2544 (fun (get-text-property pos 'gnus-callback))) | |
2545 (when fun | |
2546 (funcall fun data)))) | |
2547 | |
2548 (defun gnus-article-press-button () | |
2549 "Check text at point for a callback function. | |
2550 If the text at point has a `gnus-callback' property, | |
2551 call it with the value of the `gnus-data' text property." | |
2552 (interactive) | |
2553 (let* ((data (get-text-property (point) 'gnus-data)) | |
2554 (fun (get-text-property (point) 'gnus-callback))) | |
2555 (when fun | |
2556 (funcall fun data)))) | |
2557 | |
2558 (defun gnus-article-prev-button (n) | |
2559 "Move point to N buttons backward. | |
2560 If N is negative, move forward instead." | |
2561 (interactive "p") | |
2562 (gnus-article-next-button (- n))) | |
2563 | |
2564 (defun gnus-article-next-button (n) | |
2565 "Move point to N buttons forward. | |
2566 If N is negative, move backward instead." | |
2567 (interactive "p") | |
2568 (let ((function (if (< n 0) 'previous-single-property-change | |
2569 'next-single-property-change)) | |
2570 (inhibit-point-motion-hooks t) | |
2571 (backward (< n 0)) | |
2572 (limit (if (< n 0) (point-min) (point-max)))) | |
2573 (setq n (abs n)) | |
2574 (while (and (not (= limit (point))) | |
2575 (> n 0)) | |
2576 ;; Skip past the current button. | |
2577 (when (get-text-property (point) 'gnus-callback) | |
2578 (goto-char (funcall function (point) 'gnus-callback nil limit))) | |
2579 ;; Go to the next (or previous) button. | |
2580 (gnus-goto-char (funcall function (point) 'gnus-callback nil limit)) | |
2581 ;; Put point at the start of the button. | |
2582 (when (and backward (not (get-text-property (point) 'gnus-callback))) | |
2583 (goto-char (funcall function (point) 'gnus-callback nil limit))) | |
2584 ;; Skip past intangible buttons. | |
2585 (when (get-text-property (point) 'intangible) | |
2586 (incf n)) | |
2587 (decf n)) | |
2588 (unless (zerop n) | |
2589 (gnus-message 5 "No more buttons")) | |
2590 n)) | |
2591 | |
2592 (defun gnus-article-highlight (&optional force) | |
2593 "Highlight current article. | |
2594 This function calls `gnus-article-highlight-headers', | |
2595 `gnus-article-highlight-citation', | |
2596 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to | |
2597 do the highlighting. See the documentation for those functions." | |
2598 (interactive (list 'force)) | |
2599 (gnus-article-highlight-headers) | |
2600 (gnus-article-highlight-citation force) | |
2601 (gnus-article-highlight-signature) | |
2602 (gnus-article-add-buttons force) | |
2603 (gnus-article-add-buttons-to-head)) | |
2604 | |
2605 (defun gnus-article-highlight-some (&optional force) | |
2606 "Highlight current article. | |
2607 This function calls `gnus-article-highlight-headers', | |
2608 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to | |
2609 do the highlighting. See the documentation for those functions." | |
2610 (interactive (list 'force)) | |
2611 (gnus-article-highlight-headers) | |
2612 (gnus-article-highlight-signature) | |
2613 (gnus-article-add-buttons)) | |
2614 | |
2615 (defun gnus-article-highlight-headers () | |
2616 "Highlight article headers as specified by `gnus-header-face-alist'." | |
2617 (interactive) | |
2618 (save-excursion | |
2619 (set-buffer gnus-article-buffer) | |
2620 (save-restriction | |
2621 (let ((alist gnus-header-face-alist) | |
2622 (buffer-read-only nil) | |
2623 (case-fold-search t) | |
2624 (inhibit-point-motion-hooks t) | |
2625 entry regexp header-face field-face from hpoints fpoints) | |
2626 (goto-char (point-min)) | |
2627 (when (search-forward "\n\n" nil t) | |
2628 (narrow-to-region (1- (point)) (point-min)) | |
2629 (while (setq entry (pop alist)) | |
2630 (goto-char (point-min)) | |
2631 (setq regexp (concat "^\\(" | |
2632 (if (string-equal "" (nth 0 entry)) | |
2633 "[^\t ]" | |
2634 (nth 0 entry)) | |
2635 "\\)") | |
2636 header-face (nth 1 entry) | |
2637 field-face (nth 2 entry)) | |
2638 (while (and (re-search-forward regexp nil t) | |
2639 (not (eobp))) | |
2640 (beginning-of-line) | |
2641 (setq from (point)) | |
2642 (unless (search-forward ":" nil t) | |
2643 (forward-char 1)) | |
2644 (when (and header-face | |
2645 (not (memq (point) hpoints))) | |
2646 (push (point) hpoints) | |
2647 (gnus-put-text-property from (point) 'face header-face)) | |
2648 (when (and field-face | |
2649 (not (memq (setq from (point)) fpoints))) | |
2650 (push from fpoints) | |
2651 (if (re-search-forward "^[^ \t]" nil t) | |
2652 (forward-char -2) | |
2653 (goto-char (point-max))) | |
2654 (gnus-put-text-property from (point) 'face field-face))))))))) | |
2655 | |
2656 (defun gnus-article-highlight-signature () | |
2657 "Highlight the signature in an article. | |
2658 It does this by highlighting everything after | |
2659 `gnus-signature-separator' using `gnus-signature-face'." | |
2660 (interactive) | |
2661 (save-excursion | |
2662 (set-buffer gnus-article-buffer) | |
2663 (let ((buffer-read-only nil) | |
2664 (inhibit-point-motion-hooks t)) | |
2665 (save-restriction | |
2666 (when (and gnus-signature-face | |
2667 (gnus-article-narrow-to-signature)) | |
2668 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max)) | |
2669 'face gnus-signature-face) | |
2670 (widen) | |
2671 (gnus-article-search-signature) | |
2672 (let ((start (match-beginning 0)) | |
2673 (end (set-marker (make-marker) (1+ (match-end 0))))) | |
2674 (gnus-article-add-button start (1- end) 'gnus-signature-toggle | |
2675 end))))))) | |
2676 | |
2677 (defun gnus-article-add-buttons (&optional force) | |
2678 "Find external references in the article and make buttons of them. | |
2679 \"External references\" are things like Message-IDs and URLs, as | |
2680 specified by `gnus-button-alist'." | |
2681 (interactive (list 'force)) | |
2682 (save-excursion | |
2683 (set-buffer gnus-article-buffer) | |
2684 ;; Remove all old markers. | |
2685 (while gnus-button-marker-list | |
2686 (set-marker (pop gnus-button-marker-list) nil)) | |
2687 (let ((buffer-read-only nil) | |
2688 (inhibit-point-motion-hooks t) | |
2689 (case-fold-search t) | |
2690 (alist gnus-button-alist) | |
2691 beg entry regexp) | |
2692 (goto-char (point-min)) | |
2693 ;; We skip the headers. | |
2694 (unless (search-forward "\n\n" nil t) | |
2695 (goto-char (point-max))) | |
2696 (setq beg (point)) | |
2697 (while (setq entry (pop alist)) | |
2698 (setq regexp (car entry)) | |
2699 (goto-char beg) | |
2700 (while (re-search-forward regexp nil t) | |
2701 (let* ((start (and entry (match-beginning (nth 1 entry)))) | |
2702 (end (and entry (match-end (nth 1 entry)))) | |
2703 (from (match-beginning 0))) | |
2704 (when (and (or (eq t (nth 1 entry)) | |
2705 (eval (nth 1 entry))) | |
2706 (not (get-text-property (point) 'gnus-callback))) | |
2707 ;; That optional form returned non-nil, so we add the | |
2708 ;; button. | |
2709 (gnus-article-add-button | |
2710 start end 'gnus-button-push | |
2711 (car (push (set-marker (make-marker) from) | |
2712 gnus-button-marker-list)))))))))) | |
2713 | |
2714 ;; Add buttons to the head of an article. | |
2715 (defun gnus-article-add-buttons-to-head () | |
2716 "Add buttons to the head of the article." | |
2717 (interactive) | |
2718 (save-excursion | |
2719 (set-buffer gnus-article-buffer) | |
2720 (let ((buffer-read-only nil) | |
2721 (inhibit-point-motion-hooks t) | |
2722 (case-fold-search t) | |
2723 (alist gnus-header-button-alist) | |
2724 entry beg end) | |
2725 (nnheader-narrow-to-headers) | |
2726 (while alist | |
2727 ;; Each alist entry. | |
2728 (setq entry (car alist) | |
2729 alist (cdr alist)) | |
2730 (goto-char (point-min)) | |
2731 (while (re-search-forward (car entry) nil t) | |
2732 ;; Each header matching the entry. | |
2733 (setq beg (match-beginning 0)) | |
2734 (setq end (or (and (re-search-forward "^[^ \t]" nil t) | |
2735 (match-beginning 0)) | |
2736 (point-max))) | |
2737 (goto-char beg) | |
2738 (while (re-search-forward (nth 1 entry) end t) | |
2739 ;; Each match within a header. | |
2740 (let* ((entry (cdr entry)) | |
2741 (start (match-beginning (nth 1 entry))) | |
2742 (end (match-end (nth 1 entry))) | |
2743 (form (nth 2 entry))) | |
2744 (goto-char (match-end 0)) | |
2745 (when (eval form) | |
2746 (gnus-article-add-button | |
2747 start end (nth 3 entry) | |
2748 (buffer-substring (match-beginning (nth 4 entry)) | |
2749 (match-end (nth 4 entry))))))) | |
2750 (goto-char end)))) | |
2751 (widen))) | |
2752 | |
2753 ;;; External functions: | |
2754 | |
2755 (defun gnus-article-add-button (from to fun &optional data) | |
2756 "Create a button between FROM and TO with callback FUN and data DATA." | |
2757 (when gnus-article-button-face | |
2758 (gnus-overlay-put (gnus-make-overlay from to) | |
2759 'face gnus-article-button-face)) | |
2760 (gnus-add-text-properties | |
2761 from to | |
2762 (nconc (and gnus-article-mouse-face | |
2763 (list gnus-mouse-face-prop gnus-article-mouse-face)) | |
2764 (list 'gnus-callback fun) | |
2765 (and data (list 'gnus-data data))))) | |
2766 | |
2767 ;;; Internal functions: | |
2768 | |
2769 (defun gnus-signature-toggle (end) | |
2770 (save-excursion | |
2771 (set-buffer gnus-article-buffer) | |
2772 (let ((buffer-read-only nil) | |
2773 (inhibit-point-motion-hooks t)) | |
2774 (if (get-text-property end 'invisible) | |
2775 (gnus-article-unhide-text end (point-max)) | |
2776 (gnus-article-hide-text end (point-max) gnus-hidden-properties))))) | |
2777 | |
2778 (defun gnus-button-entry () | |
2779 ;; Return the first entry in `gnus-button-alist' matching this place. | |
2780 (let ((alist gnus-button-alist) | |
2781 (entry nil)) | |
2782 (while alist | |
2783 (setq entry (pop alist)) | |
2784 (if (looking-at (car entry)) | |
2785 (setq alist nil) | |
2786 (setq entry nil))) | |
2787 entry)) | |
2788 | |
2789 (defun gnus-button-push (marker) | |
2790 ;; Push button starting at MARKER. | |
2791 (save-excursion | |
2792 (set-buffer gnus-article-buffer) | |
2793 (goto-char marker) | |
2794 (let* ((entry (gnus-button-entry)) | |
2795 (inhibit-point-motion-hooks t) | |
2796 (fun (nth 3 entry)) | |
2797 (args (mapcar (lambda (group) | |
2798 (let ((string (match-string group))) | |
2799 (gnus-set-text-properties | |
2800 0 (length string) nil string) | |
2801 string)) | |
2802 (nthcdr 4 entry)))) | |
2803 (cond | |
2804 ((fboundp fun) | |
2805 (apply fun args)) | |
2806 ((and (boundp fun) | |
2807 (fboundp (symbol-value fun))) | |
2808 (apply (symbol-value fun) args)) | |
2809 (t | |
2810 (gnus-message 1 "You must define `%S' to use this button" | |
2811 (cons fun args))))))) | |
2812 | |
2813 (defun gnus-button-message-id (message-id) | |
2814 "Fetch MESSAGE-ID." | |
2815 (save-excursion | |
2816 (set-buffer gnus-summary-buffer) | |
2817 (gnus-summary-refer-article message-id))) | |
2818 | |
2819 (defun gnus-button-fetch-group (address) | |
2820 "Fetch GROUP specified by ADDRESS." | |
2821 (if (not (string-match "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\(.*\\)$" address)) | |
2822 (error "Can't parse %s" address) | |
2823 (gnus-group-read-ephemeral-group | |
2824 (match-string 4 address) | |
2825 `(nntp ,(match-string 1 address) (nntp-address ,(match-string 1 address)) | |
2826 (nntp-port-number ,(if (match-end 3) | |
2827 (match-string 3 address) | |
2828 "nntp")))))) | |
2829 | |
2830 (defun gnus-split-string (string pattern) | |
2831 "Return a list of substrings of STRING which are separated by PATTERN." | |
2832 (let (parts (start 0)) | |
2833 (while (string-match pattern string start) | |
2834 (setq parts (cons (substring string start (match-beginning 0)) parts) | |
2835 start (match-end 0))) | |
2836 (nreverse (cons (substring string start) parts)))) | |
2837 | |
2838 (defun gnus-url-parse-query-string (query &optional downcase) | |
2839 (let (retval pairs cur key val) | |
2840 (setq pairs (gnus-split-string query "&")) | |
2841 (while pairs | |
2842 (setq cur (car pairs) | |
2843 pairs (cdr pairs)) | |
2844 (if (not (string-match "=" cur)) | |
2845 nil ; Grace | |
2846 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0))) | |
2847 val (gnus-url-unhex-string (substring cur (match-end 0) nil))) | |
2848 (if downcase | |
2849 (setq key (downcase key))) | |
2850 (setq cur (assoc key retval)) | |
2851 (if cur | |
2852 (setcdr cur (cons val (cdr cur))) | |
2853 (setq retval (cons (list key val) retval))))) | |
2854 retval)) | |
2855 | |
2856 (defun gnus-url-unhex (x) | |
2857 (if (> x ?9) | |
2858 (if (>= x ?a) | |
2859 (+ 10 (- x ?a)) | |
2860 (+ 10 (- x ?A))) | |
2861 (- x ?0))) | |
2862 | |
2863 (defun gnus-url-unhex-string (str &optional allow-newlines) | |
2864 "Remove %XXX embedded spaces, etc in a url. | |
2865 If optional second argument ALLOW-NEWLINES is non-nil, then allow the | |
2866 decoding of carriage returns and line feeds in the string, which is normally | |
2867 forbidden in URL encoding." | |
2868 (setq str (or str "")) | |
2869 (let ((tmp "") | |
2870 (case-fold-search t)) | |
2871 (while (string-match "%[0-9a-f][0-9a-f]" str) | |
2872 (let* ((start (match-beginning 0)) | |
2873 (ch1 (gnus-url-unhex (elt str (+ start 1)))) | |
2874 (code (+ (* 16 ch1) | |
2875 (gnus-url-unhex (elt str (+ start 2)))))) | |
2876 (setq tmp (concat | |
2877 tmp (substring str 0 start) | |
2878 (cond | |
2879 (allow-newlines | |
2880 (char-to-string code)) | |
2881 ((or (= code ?\n) (= code ?\r)) | |
2882 " ") | |
2883 (t (char-to-string code)))) | |
2884 str (substring str (match-end 0))))) | |
2885 (setq tmp (concat tmp str)) | |
2886 tmp)) | |
2887 | |
2888 (defun gnus-url-mailto (url) | |
2889 ;; Send mail to someone | |
2890 (when (string-match "mailto:/*\\(.*\\)" url) | |
2891 (setq url (substring url (match-beginning 1) nil))) | |
2892 (let (to args source-url subject func) | |
2893 (if (string-match (regexp-quote "?") url) | |
2894 (setq to (gnus-url-unhex-string (substring url 0 (match-beginning 0))) | |
2895 args (gnus-url-parse-query-string | |
2896 (substring url (match-end 0) nil) t)) | |
2897 (setq to (gnus-url-unhex-string url))) | |
2898 (setq args (cons (list "to" to) args) | |
2899 subject (cdr-safe (assoc "subject" args))) | |
2900 (message-mail) | |
2901 (while args | |
2902 (setq func (intern-soft (concat "message-goto-" (downcase (caar args))))) | |
2903 (if (fboundp func) | |
2904 (funcall func) | |
2905 (message-position-on-field (caar args))) | |
2906 (insert (mapconcat 'identity (cdar args) ", ")) | |
2907 (setq args (cdr args))) | |
2908 (if subject | |
2909 (message-goto-body) | |
2910 (message-goto-subject)))) | |
2911 | |
2912 (defun gnus-button-mailto (address) | |
2913 ;; Mail to ADDRESS. | |
2914 (set-buffer (gnus-copy-article-buffer)) | |
2915 (message-reply address)) | |
2916 | |
2917 (defun gnus-button-reply (address) | |
2918 ;; Reply to ADDRESS. | |
2919 (message-reply address)) | |
2920 | |
2921 (defun gnus-button-url (address) | |
2922 "Browse ADDRESS." | |
2923 (funcall browse-url-browser-function address)) | |
2924 | |
2925 (defun gnus-button-embedded-url (address) | |
2926 "Browse ADDRESS." | |
2927 (funcall browse-url-browser-function (gnus-strip-whitespace address))) | |
2928 | |
2929 ;;; Next/prev buttons in the article buffer. | |
2930 | |
2931 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n") | |
2932 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n") | |
2933 | |
2934 (defvar gnus-prev-page-map nil) | |
2935 (unless gnus-prev-page-map | |
2936 (setq gnus-prev-page-map (make-sparse-keymap)) | |
2937 (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page) | |
2938 (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page)) | |
2939 | |
2940 (defun gnus-insert-prev-page-button () | |
2941 (let ((buffer-read-only nil)) | |
2942 (gnus-eval-format | |
2943 gnus-prev-page-line-format nil | |
2944 `(gnus-prev t local-map ,gnus-prev-page-map | |
2945 gnus-callback gnus-article-button-prev-page)))) | |
2946 | |
2947 (defvar gnus-next-page-map nil) | |
2948 (unless gnus-next-page-map | |
2949 (setq gnus-next-page-map (make-keymap)) | |
2950 (suppress-keymap gnus-prev-page-map) | |
2951 (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page) | |
2952 (define-key gnus-next-page-map "\r" 'gnus-button-next-page)) | |
2953 | |
2954 (defun gnus-button-next-page () | |
2955 "Go to the next page." | |
2956 (interactive) | |
2957 (let ((win (selected-window))) | |
2958 (select-window (get-buffer-window gnus-article-buffer t)) | |
2959 (gnus-article-next-page) | |
2960 (select-window win))) | |
2961 | |
2962 (defun gnus-button-prev-page () | |
2963 "Go to the prev page." | |
2964 (interactive) | |
2965 (let ((win (selected-window))) | |
2966 (select-window (get-buffer-window gnus-article-buffer t)) | |
2967 (gnus-article-prev-page) | |
2968 (select-window win))) | |
2969 | |
2970 (defun gnus-insert-next-page-button () | |
2971 (let ((buffer-read-only nil)) | |
2972 (gnus-eval-format gnus-next-page-line-format nil | |
2973 `(gnus-next t local-map ,gnus-next-page-map | |
2974 gnus-callback | |
2975 gnus-article-button-next-page)))) | |
2976 | |
2977 (defun gnus-article-button-next-page (arg) | |
2978 "Go to the next page." | |
2979 (interactive "P") | |
2980 (let ((win (selected-window))) | |
2981 (select-window (get-buffer-window gnus-article-buffer t)) | |
2982 (gnus-article-next-page) | |
2983 (select-window win))) | |
2984 | |
2985 (defun gnus-article-button-prev-page (arg) | |
2986 "Go to the prev page." | |
2987 (interactive "P") | |
2988 (let ((win (selected-window))) | |
2989 (select-window (get-buffer-window gnus-article-buffer t)) | |
2990 (gnus-article-prev-page) | |
2991 (select-window win))) | |
2992 | |
2993 (gnus-ems-redefine) | |
2994 | |
2995 (provide 'gnus-art) | |
2996 | |
2997 (run-hooks 'gnus-art-load-hook) | |
2998 | |
2999 ;;; gnus-art.el ends here |