(article-strip-banner): Use gnus-extract-address-components instead of
[gnus] / lisp / gnus-cus.el
1 ;;; gnus-cus.el --- customization commands for Gnus
2
3 ;; Copyright (C) 1996, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (require 'wid-edit)
31 (require 'gnus)
32 (require 'gnus-agent)
33 (require 'gnus-score)
34 (require 'gnus-topic)
35 (require 'gnus-art)
36
37 ;;; Widgets:
38
39 (defvar gnus-custom-map
40   (let ((map (make-keymap)))
41     (set-keymap-parent map widget-keymap)
42     (suppress-keymap map)
43     (define-key map [mouse-1] 'widget-move-and-invoke)
44     map)
45   "Keymap for editing Gnus customization buffers.")
46
47 (defun gnus-custom-mode ()
48   "Major mode for editing Gnus customization buffers.
49
50 The following commands are available:
51
52 \\[widget-forward]              Move to next button or editable field.
53 \\[widget-backward]             Move to previous button or editable field.
54 \\[widget-button-click]         Activate button under the mouse pointer.
55 \\[widget-button-press]         Activate button under point.
56
57 Entry to this mode calls the value of `gnus-custom-mode-hook'
58 if that value is non-nil."
59   (kill-all-local-variables)
60   (setq major-mode 'gnus-custom-mode
61         mode-name "Gnus Customize")
62   (use-local-map gnus-custom-map)
63   ;; Emacs 21 stuff:
64   (when (and (facep 'custom-button-face)
65              (facep 'custom-button-pressed-face))
66     (set (make-local-variable 'widget-button-face)
67          'custom-button-face)
68     (set (make-local-variable 'widget-button-pressed-face)
69          'custom-button-pressed-face)
70     (set (make-local-variable 'widget-mouse-face)
71          'custom-button-pressed-face))
72   (when (and (boundp 'custom-raised-buttons)
73              (symbol-value 'custom-raised-buttons))
74     (set (make-local-variable 'widget-push-button-prefix) "")
75     (set (make-local-variable 'widget-push-button-suffix) "")
76     (set (make-local-variable 'widget-link-prefix) "")
77     (set (make-local-variable 'widget-link-suffix) ""))
78   (gnus-run-mode-hooks 'gnus-custom-mode-hook))
79
80 ;;; Group Customization:
81
82 (defconst gnus-group-parameters
83   '((extra-aliases (choice
84                     :tag "Extra Aliases"
85                     (list
86                      :tag "List"
87                      (editable-list
88                       :inline t
89                       (gnus-email-address :tag "Address")))
90                     (gnus-email-address :tag "Address")) "\
91 Store messages posted from or to this address in this group.
92
93 You must be using gnus-group-split for this to work.  The VALUE of the
94 nnmail-split-fancy SPLIT generated for this group will match these
95 addresses.")
96
97     (split-regexp (regexp :tag "gnus-group-split Regular Expression") "\
98 Like gnus-group-split Address, but expects a regular expression.")
99
100     (split-exclude (list :tag "gnus-group-split Restricts"
101                          (editable-list
102                           :inline t (regexp :tag "Restrict"))) "\
103 Regular expression that cancels gnus-group-split matches.
104
105 Each entry is added to the nnmail-split-fancy SPLIT as a separate
106 RESTRICT clause.")
107
108     (split-spec (choice :tag "gnus-group-split Overrider"
109                         (sexp :tag "Fancy Split")
110                         (const :tag "Catch All" catch-all)
111                         (const :tag "Ignore" nil)) "\
112 Override all other gnus-group-split fields.
113
114 In `Fancy Split', you can enter any nnmail-split-fancy SPLIT.  Note
115 that the name of this group won't be automatically assumed, you have
116 to add it to the SPLITs yourself.  This means you can use such splits
117 to split messages to other groups too.
118
119 If you select `Catch All', this group will get postings for any
120 messages not matched in any other group.  It overrides the variable
121 gnus-group-split-default-catch-all-group.
122
123 Selecting `Ignore' forces no SPLIT to be generated for this group,
124 disabling all other gnus-group-split fields.")
125
126     (broken-reply-to (const :tag "Broken Reply To" t) "\
127 Ignore `Reply-To' headers in this group.
128
129 That can be useful if you're reading a mailing list group where the
130 listserv has inserted `Reply-To' headers that point back to the
131 listserv itself.  This is broken behavior.  So there!")
132
133     (to-group (string :tag "To Group") "\
134 All posts will be sent to the specified group.")
135
136     (gcc-self (choice :tag  "GCC"
137                       :value t
138                       (const :tag "To current group" t)
139                       (const none)
140                       (string :format "%v" :hide-front-space t)) "\
141 Specify default value for GCC header.
142
143 If this symbol is present in the group parameter list and set to t,
144 new composed messages will be `Gcc''d to the current group.  If it is
145 present and set to `none', no `Gcc:' header will be generated, if it
146 is present and a string, this string will be inserted literally as a
147 `gcc' header (this symbol takes precedence over any default `Gcc'
148 rules as described later).")
149
150     (expiry-wait (choice :tag  "Expire Wait"
151                          :value never
152                          (const never)
153                          (const immediate)
154                          (number :hide-front-space t
155                                  :format "%v")) "\
156 When to expire.
157
158 Overrides any `nnmail-expiry-wait' and `nnmail-expiry-wait-function'
159 when expiring expirable messages.  The value can either be a number of
160 days (not necessarily an integer) or the symbols `never' or
161 `immediate'.")
162
163     (expiry-target (choice :tag "Expiry Target"
164                            :value delete
165                            (const delete)
166                            (function :format "%v" nnmail-)
167                            string) "\
168 Where expired messages end up.
169
170 Overrides `nnmail-expiry-target'.")
171
172     (score-file (file :tag "Score File") "\
173 Make the specified file into the current score file.
174 This means that all score commands you issue will end up in this file.")
175
176     (adapt-file (file :tag "Adapt File") "\
177 Make the specified file into the current adaptive file.
178 All adaptive score entries will be put into this file.")
179
180     (admin-address (gnus-email-address :tag "Admin Address") "\
181 Administration address for a mailing list.
182
183 When unsubscribing to a mailing list you should never send the
184 unsubscription notice to the mailing list itself.  Instead, you'd
185 send messages to the administrative address.  This parameter allows
186 you to put the admin address somewhere convenient.")
187
188     (display (choice :tag "Display"
189                      :value default
190                      (const all)
191                      (integer)
192                      (const default)
193                      (sexp  :tag "Other")) "\
194 Which articles to display on entering the group.
195
196 `all'
197      Display all articles, both read and unread.
198
199 `integer'
200      Display the last NUMBER articles in the group.  This is the same as
201      entering the group with C-u NUMBER.
202
203 `default'
204      Display the default visible articles, which normally includes
205      unread and ticked articles.
206
207 `Other'
208      Display the articles that satisfy the S-expression. The S-expression
209      should be in an array form.")
210
211     (comment (string :tag  "Comment") "\
212 An arbitrary comment on the group.")
213
214     (visible (const :tag "Permanently visible" t) "\
215 Always display this group, even when there are no unread articles in it.")
216
217     (highlight-words
218      (choice :tag "Highlight words"
219              :value nil
220              (repeat (list (regexp :tag "Highlight regexp")
221                            (number :tag "Group for entire word" 0)
222                            (number :tag "Group for displayed part" 0)
223                            (symbol :tag "Face"
224                                    gnus-emphasis-highlight-words))))
225      "highlight regexps.
226 See `gnus-emphasis-alist'.")
227
228     (posting-style
229      (choice :tag "Posting style"
230              :value nil
231              (repeat (list
232                       (choice :tag "Type"
233                               :value nil
234                               (const signature)
235                               (const signature-file)
236                               (const organization)
237                               (const address)
238                               (const x-face-file)
239                               (const name)
240                               (const body)
241                               (symbol)
242                               (string :tag "Header"))
243                       (string :format "%v"))))
244      "post style.
245 See `gnus-posting-styles'."))
246   "Alist of valid group or topic parameters.
247
248 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
249 itself (a symbol), TYPE is the parameters type (a sexp widget), and
250 DOC is a documentation string for the parameter.")
251
252 (defconst gnus-extra-topic-parameters
253   '((subscribe (regexp :tag "Subscribe") "\
254 If `gnus-subscribe-newsgroup-method' or
255 `gnus-subscribe-options-newsgroup-method' is set to
256 `gnus-subscribe-topics', new groups that matches this regexp will
257 automatically be subscribed to this topic")
258     (subscribe-level (integer :tag "Subscribe Level" :value 1) "\
259 If this topic parameter is set, when new groups are subscribed
260 automatically under this topic (via the `subscribe' topic parameter)
261 assign this level to the group, rather than the default level
262 set in `gnus-level-default-subscribed'"))
263   "Alist of topic parameters that are not also group parameters.
264
265 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
266 itself (a symbol), TYPE is the parameters type (a sexp widget), and
267 DOC is a documentation string for the parameter.")
268
269 (defconst gnus-extra-group-parameters
270   '((uidvalidity (string :tag "IMAP uidvalidity") "\
271 Server-assigned value attached to IMAP groups, used to maintain consistency."))
272   "Alist of group parameters that are not also topic parameters.
273
274 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
275 itself (a symbol), TYPE is the parameters type (a sexp widget), and
276 DOC is a documentation string for the parameter.")
277
278 (eval-and-compile
279   (defconst gnus-agent-parameters
280     '((agent-predicate
281        (sexp :tag "Selection Predicate" :value false)
282        "Predicate used to automatically select articles for downloading."
283        gnus-agent-cat-predicate)
284       (agent-score
285        (choice :tag "Score File" :value nil
286                (const file :tag "Use group's score files")
287                (repeat (list (string :format "%v" :tag "File name"))))
288        "Which score files to use when using score to select articles to fetch.
289
290     `nil'
291          All articles will be scored to zero (0).
292
293     `file'
294          The group's score files will be used to score the articles.
295
296     `List'
297          A list of score file names."
298        gnus-agent-cat-score-file)
299       (agent-short-article
300        (integer :tag "Max Length of Short Article" :value "")
301        "The SHORT predicate will evaluate to true when the article is
302 shorter than this length."  gnus-agent-cat-length-when-short)
303       (agent-long-article
304        (integer :tag "Min Length of Long Article" :value "")
305        "The LONG predicate will evaluate to true when the article is
306 longer than this length."  gnus-agent-cat-length-when-long)
307       (agent-low-score
308        (integer :tag "Low Score Limit" :value "")
309        "The LOW predicate will evaluate to true when the article scores
310 lower than this limit."  gnus-agent-cat-low-score)
311       (agent-high-score
312        (integer :tag "High Score Limit" :value "")
313        "The HIGH predicate will evaluate to true when the article scores
314 higher than this limit."  gnus-agent-cat-high-score)
315       (agent-days-until-old
316        (integer :tag "Days Until Old" :value "")
317        "The OLD predicate will evaluate to true when the fetched article
318 has been stored locally for at least this many days."
319        gnus-agent-cat-days-until-old)
320       (agent-enable-expiration
321        (radio :tag "Expire in this Group or Topic" :value nil
322               (const :format "Enable " ENABLE)
323               (const :format "Disable " DISABLE))
324        "\nEnable, or disable, agent expiration in this group or topic."
325        gnus-agent-cat-enable-expiration)
326       (agent-enable-undownloaded-faces
327        (boolean :tag "Enable Agent Faces")
328        "Have the summary buffer use the agent's undownloaded faces.
329 These faces, when enabled, act as a warning that an article has not
330 been fetched into either the agent nor the cache.  This is of most use
331 to users who use the agent as a cache (i.e. they only operate on
332 articles that have been downloaded).  Leave disabled to display normal
333 article faces even when the article hasn't been downloaded."
334 gnus-agent-cat-enable-undownloaded-faces))
335     "Alist of group parameters that are not also topic parameters.
336
337 Each entry has the form (NAME TYPE DOC ACCESSOR), where NAME is the
338 parameter itself (a symbol), TYPE is the parameters type (a sexp
339 widget), DOC is a documentation string for the parameter, and ACCESSOR
340 is a function (symbol) that extracts the current value from the
341 category."))
342
343 (defvar gnus-custom-params)
344 (defvar gnus-custom-method)
345 (defvar gnus-custom-group)
346 (defvar gnus-custom-topic)
347
348 (defun gnus-group-customize (group &optional topic)
349   "Edit the group or topic on the current line."
350   (interactive (list (gnus-group-group-name) (gnus-group-topic-name)))
351   (let (info
352         (types (mapcar (lambda (entry)
353                          `(cons :format "%v%h\n"
354                                 :doc ,(nth 2 entry)
355                                 (const :format "" ,(nth 0 entry))
356                                 ,(nth 1 entry)))
357                        (append (reverse gnus-group-parameters-more)
358                                gnus-group-parameters
359                                (if group
360                                    gnus-extra-group-parameters
361                                  gnus-extra-topic-parameters))))
362         (agent (mapcar (lambda (entry)
363                          (let ((type (nth 1 entry))
364                                vcons)
365                            (if (listp type)
366                                (setq type (copy-sequence type)))
367
368                            (setq vcons (cdr (memq :value type)))
369
370                            (if (symbolp (car vcons))
371                                (condition-case nil
372                                    (setcar vcons (symbol-value (car vcons)))
373                                  (error)))
374                            `(cons :format "%v%h\n"
375                                   :doc ,(nth 2 entry)
376                                   (const :format "" ,(nth 0 entry))
377                                   ,type)))
378                        (if gnus-agent
379                            gnus-agent-parameters))))
380     (unless (or group topic)
381       (error "No group on current line"))
382     (when (and group topic)
383       (error "Both a group an topic on current line"))
384     (unless (or topic (setq info (gnus-get-info group)))
385       (error "Killed group; can't be edited"))
386     ;; Ready.
387     (gnus-kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
388     (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
389     (gnus-custom-mode)
390     (make-local-variable 'gnus-custom-group)
391     (setq gnus-custom-group group)
392     (make-local-variable 'gnus-custom-topic)
393     (setq gnus-custom-topic topic)
394     (buffer-disable-undo)
395     (widget-insert "Customize the ")
396     (if group
397         (widget-create 'info-link
398                        :help-echo "Push me to learn more."
399                        :tag "group parameters"
400                        "(gnus)Group Parameters")
401       (widget-create 'info-link
402                      :help-echo "Push me to learn more."
403                      :tag  "topic parameters"
404                      "(gnus)Topic Parameters"))
405     (widget-insert " for <")
406     (widget-insert (gnus-group-decoded-name (or group topic)))
407     (widget-insert "> and press ")
408     (widget-create 'push-button
409                    :tag "done"
410                    :help-echo "Push me when done customizing."
411                    :action 'gnus-group-customize-done)
412     (widget-insert ".\n\n")
413     (make-local-variable 'gnus-custom-params)
414
415     (let ((values (if group
416                       (gnus-info-params info)
417                     (gnus-topic-parameters topic))))
418
419       ;; The parameters in values may contain duplicates.  This is
420       ;; normally OK as assq returns the first. However, right here
421       ;; every duplicate ends up being displayed.  So, rather than
422       ;; display them, remove them from the list.
423
424       (let ((tmp (setq values (gnus-copy-sequence values)))
425             elem)
426         (while (cdr tmp)
427           (while (setq elem (assq (caar tmp) (cdr tmp)))
428             (delq elem tmp))
429           (setq tmp (cdr tmp))))
430
431       (setq gnus-custom-params
432             (apply 'widget-create 'group
433                    :value values
434                    (delq nil
435                          (list `(set :inline t
436                                      :greedy t
437                                      :tag "Parameters"
438                                      :format "%t:\n%h%v"
439                                      :doc "\
440 These special parameters are recognized by Gnus.
441 Check the [ ] for the parameters you want to apply to this group or
442 to the groups in this topic, then edit the value to suit your taste."
443                                      ,@types)
444                                (when gnus-agent
445                                  `(set :inline t
446                                        :greedy t
447                                        :tag "Agent Parameters"
448                                        :format "%t:\n%h%v"
449                                        :doc "\ These agent parameters are
450 recognized by Gnus.  They control article selection and expiration for
451 use in the unplugged cache.  Check the [ ] for the parameters you want
452 to apply to this group or to the groups in this topic, then edit the
453 value to suit your taste.
454
455 For those interested, group parameters override topic parameters while
456 topic parameters override agent category parameters.  Underlying
457 category parameters are the customizable variables."  ,@agent))
458                                '(repeat :inline t
459                                         :tag "Variables"
460                                         :format "%t:\n%h%v%i\n\n"
461                                         :doc "\
462 Set variables local to the group you are entering.
463
464 If you want to turn threading off in `news.answers', you could put
465 `(gnus-show-threads nil)' in the group parameters of that group.
466 `gnus-show-threads' will be made into a local variable in the summary
467 buffer you enter, and the form nil will be `eval'ed there.
468
469 This can also be used as a group-specific hook function, if you'd
470 like.  If you want to hear a beep when you enter a group, you could
471 put something like `(dummy-variable (ding))' in the parameters of that
472 group.  `dummy-variable' will be set to the result of the `(ding)'
473 form, but who cares?"
474                                         (list :format "%v" :value (nil nil)
475                                               (symbol :tag "Variable")
476                                               (sexp :tag
477                                                     "Value")))
478
479                                '(repeat :inline t
480                                         :tag "Unknown entries"
481                                         sexp))))))
482     (when group
483       (widget-insert "\n\nYou can also edit the ")
484       (widget-create 'info-link
485                      :tag "select method"
486                      :help-echo "Push me to learn more about select methods."
487                      "(gnus)Select Methods")
488       (widget-insert " for the group.\n")
489       (setq gnus-custom-method
490             (widget-create 'sexp
491                            :tag "Method"
492                            :value (gnus-info-method info))))
493     (use-local-map gnus-custom-map)
494     (widget-setup)
495     (buffer-enable-undo)
496     (goto-char (point-min))))
497
498 (defun gnus-group-customize-done (&rest ignore)
499   "Apply changes and bury the buffer."
500   (interactive)
501   (if gnus-custom-topic
502       (gnus-topic-set-parameters gnus-custom-topic
503                                  (widget-value gnus-custom-params))
504     (gnus-group-edit-group-done 'params gnus-custom-group
505                                 (widget-value gnus-custom-params))
506     (gnus-group-edit-group-done 'method gnus-custom-group
507                                 (widget-value gnus-custom-method)))
508   (bury-buffer))
509
510 ;;; Score Customization:
511
512 (defconst gnus-score-parameters
513   '((mark (number :tag "Mark") "\
514 The value of this entry should be a number.
515 Any articles with a score lower than this number will be marked as read.")
516
517     (expunge (number :tag "Expunge") "\
518 The value of this entry should be a number.
519 Any articles with a score lower than this number will be removed from
520 the summary buffer.")
521
522     (mark-and-expunge (number :tag "Mark-and-expunge") "\
523 The value of this entry should be a number.
524 Any articles with a score lower than this number will be marked as
525 read and removed from the summary buffer.")
526
527     (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
528 The value of this entry should be a number.
529 All articles that belong to a thread that has a total score below this
530 number will be marked as read and removed from the summary buffer.
531 `gnus-thread-score-function' says how to compute the total score
532 for a thread.")
533
534     (files (repeat :inline t :tag "Files" file) "\
535 The value of this entry should be any number of file names.
536 These files are assumed to be score files as well, and will be loaded
537 the same way this one was.")
538
539     (exclude-files (repeat :inline t :tag "Exclude-files" file) "\
540 The clue of this entry should be any number of files.
541 These files will not be loaded, even though they would normally be so,
542 for some reason or other.")
543
544     (eval (sexp :tag "Eval" :value nil) "\
545 The value of this entry will be `eval'el.
546 This element will be ignored when handling global score files.")
547
548     (read-only (boolean :tag "Read-only" :value t) "\
549 Read-only score files will not be updated or saved.
550 Global score files should feature this atom.")
551
552     (orphan (number :tag "Orphan") "\
553 The value of this entry should be a number.
554 Articles that do not have parents will get this number added to their
555 scores.  Imagine you follow some high-volume newsgroup, like
556 `comp.lang.c'.  Most likely you will only follow a few of the threads,
557 also want to see any new threads.
558
559 You can do this with the following two score file entries:
560
561      (orphan -500)
562      (mark-and-expunge -100)
563
564 When you enter the group the first time, you will only see the new
565 threads.  You then raise the score of the threads that you find
566 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
567 Next time you enter the group, you will see new articles in the
568 interesting threads, plus any new threads.
569
570 I.e.---the orphan score atom is for high-volume groups where there
571 exist a few interesting threads which can't be found automatically
572 by ordinary scoring rules.")
573
574     (adapt (choice :tag "Adapt"
575                    (const t)
576                    (const ignore)
577                    (sexp :format "%v"
578                          :hide-front-space t)) "\
579 This entry controls the adaptive scoring.
580 If it is t, the default adaptive scoring rules will be used.  If it
581 is `ignore', no adaptive scoring will be performed on this group.  If
582 it is a list, this list will be used as the adaptive scoring rules.
583 If it isn't present, or is something other than t or `ignore', the
584 default adaptive scoring rules will be used.  If you want to use
585 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
586 to t, and insert an `(adapt ignore)' in the groups where you do not
587 want adaptive scoring.  If you only want adaptive scoring in a few
588 groups, you'd set `gnus-use-adaptive-scoring' to nil, and insert
589 `(adapt t)' in the score files of the groups where you want it.")
590
591     (adapt-file (file :tag "Adapt-file") "\
592 All adaptive score entries will go to the file named by this entry.
593 It will also be applied when entering the group.  This atom might
594 be handy if you want to adapt on several groups at once, using the
595 same adaptive file for a number of groups.")
596
597     (local (repeat :tag "Local"
598                    (group :value (nil nil)
599                           (symbol :tag "Variable")
600                           (sexp :tag "Value"))) "\
601 The value of this entry should be a list of `(VAR VALUE)' pairs.
602 Each VAR will be made buffer-local to the current summary buffer,
603 and set to the value specified.  This is a convenient, if somewhat
604 strange, way of setting variables in some groups if you don't like
605 hooks much.")
606     (touched (sexp :format "Touched\n") "Internal variable."))
607   "Alist of valid symbolic score parameters.
608
609 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
610 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
611 documentation string for the parameter.")
612
613 (define-widget 'gnus-score-string 'group
614   "Edit score entries for string-valued headers."
615   :convert-widget 'gnus-score-string-convert)
616
617 (defun gnus-score-string-convert (widget)
618   ;; Set args appropriately.
619   (let* ((tag (widget-get widget :tag))
620          (item `(const :format "" :value ,(downcase tag)))
621          (match '(string :tag "Match"))
622          (score '(choice :tag "Score"
623                          (const :tag "default" nil)
624                          (integer :format "%v"
625                                   :hide-front-space t)))
626          (expire '(choice :tag "Expire"
627                           (const :tag "off" nil)
628                           (integer :format "%v"
629                                    :hide-front-space t)))
630          (type '(choice :tag "Type"
631                         :value s
632                         ;; I should really create a forgiving :match
633                         ;; function for each type below, that only
634                         ;; looked at the first letter.
635                         (const :tag "Regexp" r)
636                         (const :tag "Regexp (fixed case)" R)
637                         (const :tag "Substring" s)
638                         (const :tag "Substring (fixed case)" S)
639                         (const :tag "Exact" e)
640                         (const :tag "Exact (fixed case)" E)
641                         (const :tag "Word" w)
642                         (const :tag "Word (fixed case)" W)
643                         (const :tag "default" nil)))
644          (group `(group ,match ,score ,expire ,type))
645          (doc (concat (or (widget-get widget :doc)
646                           (concat "Change score based on the " tag
647                                   " header.\n"))
648                       "
649 You can have an arbitrary number of score entries for this header,
650 each score entry has four elements:
651
652 1. The \"match element\".  This should be the string to look for in the
653    header.
654
655 2. The \"score element\".  This number should be an integer in the
656    neginf to posinf interval.  This number is added to the score
657    of the article if the match is successful.  If this element is
658    not present, the `gnus-score-interactive-default-score' number
659    will be used instead.  This is 1000 by default.
660
661 3. The \"date element\".  This date says when the last time this score
662    entry matched, which provides a mechanism for expiring the
663    score entries.  It this element is not present, the score
664    entry is permanent.  The date is represented by the number of
665    days since December 31, 1 ce.
666
667 4. The \"type element\".  This element specifies what function should
668    be used to see whether this score entry matches the article.
669
670    There are the regexp, as well as substring types, and exact match,
671    and word match types.  If this element is not present, Gnus will
672    assume that substring matching should be used.  There is case
673    sensitive variants of all match types.")))
674     (widget-put widget :args `(,item
675                                (repeat :inline t
676                                        :indent 0
677                                        :tag ,tag
678                                        :doc ,doc
679                                        :format "%t:\n%h%v%i\n\n"
680                                        (choice :format "%v"
681                                                :value ("" nil nil s)
682                                                ,group
683                                                sexp)))))
684   widget)
685
686 (define-widget 'gnus-score-integer 'group
687   "Edit score entries for integer-valued headers."
688   :convert-widget 'gnus-score-integer-convert)
689
690 (defun gnus-score-integer-convert (widget)
691   ;; Set args appropriately.
692   (let* ((tag (widget-get widget :tag))
693          (item `(const :format "" :value ,(downcase tag)))
694          (match '(integer :tag "Match"))
695          (score '(choice :tag "Score"
696                          (const :tag "default" nil)
697                          (integer :format "%v"
698                                   :hide-front-space t)))
699          (expire '(choice :tag "Expire"
700                           (const :tag "off" nil)
701                           (integer :format "%v"
702                                    :hide-front-space t)))
703          (type '(choice :tag "Type"
704                         :value <
705                         (const <)
706                         (const >)
707                         (const =)
708                         (const >=)
709                         (const <=)))
710          (group `(group ,match ,score ,expire ,type))
711          (doc (concat (or (widget-get widget :doc)
712                           (concat "Change score based on the " tag
713                                   " header.")))))
714     (widget-put widget :args `(,item
715                                (repeat :inline t
716                                        :indent 0
717                                        :tag ,tag
718                                        :doc ,doc
719                                        :format "%t:\n%h%v%i\n\n"
720                                        ,group))))
721   widget)
722
723 (define-widget 'gnus-score-date 'group
724   "Edit score entries for date-valued headers."
725   :convert-widget 'gnus-score-date-convert)
726
727 (defun gnus-score-date-convert (widget)
728   ;; Set args appropriately.
729   (let* ((tag (widget-get widget :tag))
730          (item `(const :format "" :value ,(downcase tag)))
731          (match '(string :tag "Match"))
732          (score '(choice :tag "Score"
733                          (const :tag "default" nil)
734                          (integer :format "%v"
735                                   :hide-front-space t)))
736          (expire '(choice :tag "Expire"
737                           (const :tag "off" nil)
738                           (integer :format "%v"
739                                    :hide-front-space t)))
740          (type '(choice :tag "Type"
741                         :value regexp
742                         (const regexp)
743                         (const before)
744                         (const at)
745                         (const after)))
746          (group `(group ,match ,score ,expire ,type))
747          (doc (concat (or (widget-get widget :doc)
748                           (concat "Change score based on the " tag
749                                   " header."))
750                       "
751 For the Date header we have three kinda silly match types: `before',
752 `at' and `after'.  I can't really imagine this ever being useful, but,
753 like, it would feel kinda silly not to provide this function.  Just in
754 case.  You never know.  Better safe than sorry.  Once burnt, twice
755 shy.  Don't judge a book by its cover.  Never not have sex on a first
756 date.  (I have been told that at least one person, and I quote,
757 \"found this function indispensable\", however.)
758
759 A more useful match type is `regexp'.  With it, you can match the date
760 string using a regular expression.  The date is normalized to ISO8601
761 compact format first---`YYYYMMDDTHHMMSS'.  If you want to match all
762 articles that have been posted on April 1st in every year, you could
763 use `....0401.........' as a match string, for instance.  (Note that
764 the date is kept in its original time zone, so this will match
765 articles that were posted when it was April 1st where the article was
766 posted from.  Time zones are such wholesome fun for the whole family,
767 eh?")))
768     (widget-put widget :args `(,item
769                                (repeat :inline t
770                                        :indent 0
771                                        :tag ,tag
772                                        :doc ,doc
773                                        :format "%t:\n%h%v%i\n\n"
774                                        ,group))))
775   widget)
776
777 (defvar gnus-custom-scores)
778 (defvar gnus-custom-score-alist)
779
780 (defun gnus-score-customize (file)
781   "Customize score file FILE.
782 When called interactively, FILE defaults to the current score file.
783 This can be changed using the `\\[gnus-score-change-score-file]' command."
784   (interactive (list gnus-current-score-file))
785   (unless file
786     (error "No score file for %s"
787            (gnus-group-decoded-name gnus-newsgroup-name)))
788   (let ((scores (gnus-score-load file))
789         (types (mapcar (lambda (entry)
790                          `(group :format "%v%h\n"
791                                  :doc ,(nth 2 entry)
792                                  (const :format "" ,(nth 0 entry))
793                                  ,(nth 1 entry)))
794                        gnus-score-parameters)))
795     ;; Ready.
796     (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
797     (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
798     (gnus-custom-mode)
799     (make-local-variable 'gnus-custom-score-alist)
800     (setq gnus-custom-score-alist scores)
801     (widget-insert "Customize the ")
802     (widget-create 'info-link
803                    :help-echo "Push me to learn more."
804                    :tag "score entries"
805                    "(gnus)Score File Format")
806     (widget-insert " for\n\t")
807     (widget-insert file)
808     (widget-insert "\nand press ")
809     (widget-create 'push-button
810                    :tag "done"
811                    :help-echo "Push me when done customizing."
812                    :action 'gnus-score-customize-done)
813     (widget-insert ".\n
814 Check the [ ] for the entries you want to apply to this score file, then
815 edit the value to suit your taste.  Don't forget to mark the checkbox,
816 if you do all your changes will be lost.  ")
817     (widget-create 'push-button
818                    :action (lambda (&rest ignore)
819                              (require 'gnus-audio)
820                              (gnus-audio-play "Evil_Laugh.au"))
821                    "Bhahahah!")
822     (widget-insert "\n\n")
823     (make-local-variable 'gnus-custom-scores)
824     (setq gnus-custom-scores
825           (widget-create 'group
826                          :value scores
827                          `(checklist :inline t
828                                      :greedy t
829                                      (gnus-score-string :tag "From")
830                                      (gnus-score-string :tag "Subject")
831                                      (gnus-score-string :tag "References")
832                                      (gnus-score-string :tag "Xref")
833                                      (gnus-score-string :tag "Extra")
834                                      (gnus-score-string :tag "Message-ID")
835                                      (gnus-score-integer :tag "Lines")
836                                      (gnus-score-integer :tag "Chars")
837                                      (gnus-score-date :tag "Date")
838                                      (gnus-score-string :tag "Head"
839                                                         :doc "\
840 Match all headers in the article.
841
842 Using one of `Head', `Body', `All' will slow down scoring considerable.
843 ")
844                                      (gnus-score-string :tag "Body"
845                                                         :doc "\
846 Match the body sans header of the article.
847
848 Using one of `Head', `Body', `All' will slow down scoring considerable.
849 ")
850                                      (gnus-score-string :tag "All"
851                                                         :doc "\
852 Match the entire article, including both headers and body.
853
854 Using one of `Head', `Body', `All' will slow down scoring
855 considerable.
856 ")
857                                      (gnus-score-string :tag
858                                                         "Followup"
859                                                         :doc "\
860 Score all followups to the specified authors.
861
862 This entry is somewhat special, in that it will match the `From:'
863 header, and affect the score of not only the matching articles, but
864 also all followups to the matching articles.  This allows you
865 e.g. increase the score of followups to your own articles, or decrease
866 the score of followups to the articles of some known trouble-maker.
867 ")
868                                      (gnus-score-string :tag "Thread"
869                                                         :doc "\
870 Add a score entry on all articles that are part of a thread.
871
872 This match key works along the same lines as the `Followup' match key.
873 If you say that you want to score on a (sub-)thread that is started by
874 an article with a `Message-ID' X, then you add a `thread' match.  This
875 will add a new `thread' match for each article that has X in its
876 `References' header.  (These new `thread' matches will use the
877 `Message-ID's of these matching articles.)  This will ensure that you
878 can raise/lower the score of an entire thread, even though some
879 articles in the thread may not have complete `References' headers.
880 Note that using this may lead to undeterministic scores of the
881 articles in the thread.
882 ")
883                                      ,@types)
884                          '(repeat :inline t
885                                   :tag "Unknown entries"
886                                   sexp)))
887     (use-local-map gnus-custom-map)
888     (widget-setup)))
889
890 (defun gnus-score-customize-done (&rest ignore)
891   "Reset the score alist with the present value."
892   (let ((alist gnus-custom-score-alist)
893         (value (widget-value gnus-custom-scores)))
894     (setcar alist (car value))
895     (setcdr alist (cdr value))
896     (gnus-score-set 'touched '(t) alist))
897   (bury-buffer))
898
899 (eval-when-compile
900   (defvar category-fields nil)
901   (defvar gnus-agent-cat-name)
902   (defvar gnus-agent-cat-score-file)
903   (defvar gnus-agent-cat-length-when-short)
904   (defvar gnus-agent-cat-length-when-long)
905   (defvar gnus-agent-cat-low-score)
906   (defvar gnus-agent-cat-high-score)
907   (defvar gnus-agent-cat-enable-expiration)
908   (defvar gnus-agent-cat-days-until-old)
909   (defvar gnus-agent-cat-predicate)
910   (defvar gnus-agent-cat-groups)
911   (defvar gnus-agent-cat-enable-undownloaded-faces)
912 )
913
914 (defun gnus-trim-whitespace (s)
915   (when (string-match "\\`[ \n\t]+" s)
916     (setq s (substring s (match-end 0))))
917   (when (string-match "[ \n\t]+\\'" s)
918     (setq s (substring s 0 (match-beginning 0))))
919   s)
920
921 (defmacro gnus-agent-cat-prepare-category-field (parameter)
922   (let* ((entry (assq parameter gnus-agent-parameters))
923          (field (nth 3 entry)))
924     `(let* ((type (copy-sequence
925                    (nth 1 (assq ',parameter gnus-agent-parameters))))
926             (val (,field info))
927             (deflt (if (,field defaults)
928                        (concat " [" (gnus-trim-whitespace
929                                      (gnus-pp-to-string (,field defaults)))
930                                "]")))
931             symb)
932
933        (if (eq (car type) 'radio)
934            (let* ((rtype (nreverse type))
935                   (rt rtype))
936              (while (listp (or (cadr rt) 'not-list))
937                (setq rt (cdr rt)))
938
939              (setcdr rt (cons '(const :format "Inherit " nil) (cdr rt)))
940              (setq type (nreverse rtype))))
941
942        (if deflt
943            (let ((tag (cdr (memq :tag type))))
944              (when (string-match "\n" deflt)
945                (while (progn (setq deflt (replace-match "\n " t t
946                                                         deflt))
947                              (string-match "\n" deflt (match-end 0))))
948                (setq deflt (concat "\n" deflt)))
949
950              (setcar tag (concat (car tag) deflt))))
951
952        (widget-insert "\n")
953
954        (setq val (if val
955                      (widget-create type :value val)
956                    (widget-create type))
957              symb (set (make-local-variable ',field) val))
958
959        (widget-put symb :default val)
960        (widget-put symb :accessor ',field)
961        (push symb category-fields))))
962
963 (defun gnus-agent-customize-category (category)
964   "Edit the CATEGORY."
965   (interactive (list (gnus-category-name)))
966   (let ((info (assq category gnus-category-alist))
967         (defaults (list nil '(agent-predicate . false)
968                         (cons 'agent-enable-expiration
969                               gnus-agent-enable-expiration)
970                         '(agent-days-until-old . 7)
971                         (cons 'agent-length-when-short
972                               gnus-agent-short-article)
973                         (cons 'agent-length-when-long gnus-agent-long-article)
974                         (cons 'agent-low-score gnus-agent-low-score)
975                         (cons 'agent-high-score gnus-agent-high-score))))
976
977     (let ((old (get-buffer "*Gnus Agent Category Customize*")))
978       (when old
979         (gnus-kill-buffer old)))
980     (switch-to-buffer (gnus-get-buffer-create
981                        "*Gnus Agent Category Customize*"))
982
983     (let ((inhibit-read-only t))
984       (gnus-custom-mode)
985       (buffer-disable-undo)
986
987       (let* ((name (gnus-agent-cat-name info)))
988         (widget-insert "Customize the Agent Category '")
989         (widget-insert (symbol-name name))
990         (widget-insert "' and press ")
991         (widget-create
992          'push-button
993          :notify
994          '(lambda (&rest ignore)
995             (let* ((info (assq gnus-agent-cat-name gnus-category-alist))
996                    (widgets category-fields))
997               (while widgets
998                 (let* ((widget (pop widgets))
999                        (value (condition-case nil (widget-value widget) (error))))
1000                   (eval `(setf (,(widget-get widget :accessor) ',info)
1001                                ',value)))))
1002             (gnus-category-write)
1003             (gnus-kill-buffer (current-buffer))
1004             (when (get-buffer gnus-category-buffer)
1005               (switch-to-buffer (get-buffer gnus-category-buffer))
1006               (gnus-category-list)))
1007                        "Done")
1008         (widget-insert
1009          "\n    Note: Empty fields default to the customizable global\
1010  variables.\n\n")
1011
1012         (set (make-local-variable 'gnus-agent-cat-name)
1013              name))
1014
1015       (set (make-local-variable 'category-fields) nil)
1016       (gnus-agent-cat-prepare-category-field agent-predicate)
1017
1018       (gnus-agent-cat-prepare-category-field agent-score)
1019       (gnus-agent-cat-prepare-category-field agent-short-article)
1020       (gnus-agent-cat-prepare-category-field agent-long-article)
1021       (gnus-agent-cat-prepare-category-field agent-low-score)
1022       (gnus-agent-cat-prepare-category-field agent-high-score)
1023
1024       ;; The group list is NOT handled with
1025       ;; gnus-agent-cat-prepare-category-field as I don't want the
1026       ;; group list to appear when customizing a topic.
1027       (widget-insert "\n")
1028
1029       (let ((symb
1030              (set
1031               (make-local-variable 'gnus-agent-cat-groups)
1032               (widget-create
1033                `(choice
1034                  :format "%[Select Member Groups%]\n%v" :value ignore
1035                  (const :menu-tag "do not change" :tag "" :value ignore)
1036                  (checklist :entry-format "%b %v"
1037                             :menu-tag "display group selectors"
1038                             :greedy t
1039                             :value
1040                             ,(delq nil
1041                                    (mapcar
1042                                     (lambda (newsrc)
1043                                       (car (member
1044                                             (gnus-info-group newsrc)
1045                                             (gnus-agent-cat-groups info))))
1046                                     (cdr gnus-newsrc-alist)))
1047                             ,@(mapcar (lambda (newsrc)
1048                                         `(const ,(gnus-info-group newsrc)))
1049                                       (cdr gnus-newsrc-alist))))))))
1050
1051       (widget-put symb :default (gnus-agent-cat-groups info))
1052       (widget-put symb :accessor 'gnus-agent-cat-groups)
1053       (push symb category-fields))
1054
1055       (widget-insert "\nExpiration Settings ")
1056
1057       (gnus-agent-cat-prepare-category-field agent-enable-expiration)
1058       (gnus-agent-cat-prepare-category-field agent-days-until-old)
1059
1060       (widget-insert "\nVisual Settings ")
1061
1062       (gnus-agent-cat-prepare-category-field agent-enable-undownloaded-faces)
1063
1064       (use-local-map gnus-custom-map)
1065       (widget-setup)
1066       (buffer-enable-undo))))
1067
1068 ;;; The End:
1069
1070 (provide 'gnus-cus)
1071
1072 ;;; arch-tag: a37c285a-49bc-4235-8244-804536effeaf
1073 ;;; gnus-cus.el ends here