715007d1ef41bebcc3804e03601e7fc3d0e2214c
[elisp/gnus.git-] / lisp / gnus-cus.el
1 ;;; gnus-cus.el --- customization commands for Gnus
2 ;;
3 ;; Copyright (C) 1996, 1999, 2000, 2001, 2002, 2003
4 ;;        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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (require 'wid-edit)
31 (require 'gnus)
32 (require 'gnus-score)
33 (require 'gnus-topic)
34 (require 'gnus-art)
35
36 ;;; Widgets:
37
38 (defun gnus-custom-mode ()
39   "Major mode for editing Gnus customization buffers.
40
41 The following commands are available:
42
43 \\[widget-forward]              Move to next button or editable field.
44 \\[widget-backward]             Move to previous button or editable field.
45 \\[widget-button-click]         Activate button under the mouse pointer.
46 \\[widget-button-press]         Activate button under point.
47
48 Entry to this mode calls the value of `gnus-custom-mode-hook'
49 if that value is non-nil."
50   (kill-all-local-variables)
51   (setq major-mode 'gnus-custom-mode
52         mode-name "Gnus Customize")
53   (use-local-map widget-keymap)
54   ;; Emacs 21 stuff:
55   (when (and (facep 'custom-button-face)
56              (facep 'custom-button-pressed-face))
57     (set (make-local-variable 'widget-button-face)
58          'custom-button-face)
59     (set (make-local-variable 'widget-button-pressed-face)
60          'custom-button-pressed-face)
61     (set (make-local-variable 'widget-mouse-face)
62          'custom-button-pressed-face))
63   (when (and (boundp 'custom-raised-buttons)
64              (symbol-value 'custom-raised-buttons))
65     (set (make-local-variable 'widget-push-button-prefix) "")
66     (set (make-local-variable 'widget-push-button-suffix) "")
67     (set (make-local-variable 'widget-link-prefix) "")
68     (set (make-local-variable 'widget-link-suffix) ""))
69   (gnus-run-hooks 'gnus-custom-mode-hook))
70
71 ;;; Group Customization:
72
73 (defconst gnus-group-parameters
74   '((extra-aliases (choice
75                     :tag "Extra Aliases"
76                     (list
77                      :tag "List"
78                      (editable-list
79                       :inline t
80                       (gnus-email-address :tag "Address")))
81                     (gnus-email-address :tag "Address")) "\
82 Store messages posted from or to this address in this group.
83
84 You must be using gnus-group-split for this to work.  The VALUE of the
85 nnmail-split-fancy SPLIT generated for this group will match these
86 addresses.")
87
88     (split-regexp (regexp :tag "gnus-group-split Regular Expression") "\
89 Like gnus-group-split Address, but expects a regular expression.")
90
91     (split-exclude (list :tag "gnus-group-split Restricts"
92                          (editable-list
93                           :inline t (regexp :tag "Restrict"))) "\
94 Regular expression that cancels gnus-group-split matches.
95
96 Each entry is added to the nnmail-split-fancy SPLIT as a separate
97 RESTRICT clause.")
98
99     (split-spec (choice :tag "gnus-group-split Overrider"
100                         (sexp :tag "Fancy Split")
101                         (const :tag "Catch All" catch-all)
102                         (const :tag "Ignore" nil)) "\
103 Override all other gnus-group-split fields.
104
105 In `Fancy Split', you can enter any nnmail-split-fancy SPLIT.  Note
106 that the name of this group won't be automatically assumed, you have
107 to add it to the SPLITs yourself.  This means you can use such splits
108 to split messages to other groups too.
109
110 If you select `Catch All', this group will get postings for any
111 messages not matched in any other group.  It overrides the variable
112 gnus-group-split-default-catch-all-group.
113
114 Selecting `Ignore' forces no SPLIT to be generated for this group,
115 disabling all other gnus-group-split fields.")
116
117     (broken-reply-to (const :tag "Broken Reply To" t) "\
118 Ignore `Reply-To' headers in this group.
119
120 That can be useful if you're reading a mailing list group where the
121 listserv has inserted `Reply-To' headers that point back to the
122 listserv itself.  This is broken behavior.  So there!")
123
124     (to-group (string :tag "To Group") "\
125 All posts will be sent to the specified group.")
126
127     (gcc-self (choice :tag  "GCC"
128                       :value t
129                       (const :tag "To current group" t)
130                       (const none)
131                       (string :format "%v" :hide-front-space t)) "\
132 Specify default value for GCC header.
133
134 If this symbol is present in the group parameter list and set to t,
135 new composed messages will be `Gcc''d to the current group.  If it is
136 present and set to `none', no `Gcc:' header will be generated, if it
137 is present and a string, this string will be inserted literally as a
138 `gcc' header (this symbol takes precedence over any default `Gcc'
139 rules as described later).")
140
141     (expiry-wait (choice :tag  "Expire Wait"
142                          :value never
143                          (const never)
144                          (const immediate)
145                          (number :hide-front-space t
146                                  :format "%v")) "\
147 When to expire.
148
149 Overrides any `nnmail-expiry-wait' and `nnmail-expiry-wait-function'
150 when expiring expirable messages.  The value can either be a number of
151 days (not necessarily an integer) or the symbols `never' or
152 `immediate'.")
153
154     (expiry-target (choice :tag "Expiry Target"
155                            :value delete
156                            (const delete)
157                            (function :format "%v" nnmail-)
158                            string) "\
159 Where expired messages end up.
160
161 Overrides `nnmail-expiry-target', which see.")
162
163     (score-file (file :tag "Score File") "\
164 Make the specified file into the current score file.
165 This means that all score commands you issue will end up in this file.")
166
167     (adapt-file (file :tag "Adapt File") "\
168 Make the specified file into the current adaptive file.
169 All adaptive score entries will be put into this file.")
170
171     (admin-address (gnus-email-address :tag "Admin Address") "\
172 Administration address for a mailing list.
173
174 When unsubscribing to a mailing list you should never send the
175 unsubscription notice to the mailing list itself.  Instead, you'd
176 send messages to the administrative address.  This parameter allows
177 you to put the admin address somewhere convenient.")
178
179     (display (choice :tag "Display"
180                      :value default
181                      (const all)
182                      (integer)
183                      (const default)
184                      (sexp  :tag "Other")) "\
185 Which articles to display on entering the group.
186
187 `all'
188      Display all articles, both read and unread.
189
190 `integer'
191      Display the last NUMBER articles in the group.  This is the same as
192      entering the group with C-u NUMBER.
193
194 `default'
195      Display the default visible articles, which normally includes
196      unread and ticked articles.
197
198 `Other'
199      Display the articles that satisfy the S-expression. The S-expression
200      should be in an array form.")
201
202     (comment (string :tag  "Comment") "\
203 An arbitrary comment on the group.")
204
205     (visible (const :tag "Permanently visible" t) "\
206 Always display this group, even when there are no unread articles
207 in it..")
208
209     (highlight-words
210      (choice :tag "Highlight words"
211              :value nil
212              (repeat (list (regexp :tag "Highlight regexp")
213                            (number :tag "Group for entire word" 0)
214                            (number :tag "Group for displayed part" 0)
215                            (symbol :tag "Face"
216                                    gnus-emphasis-highlight-words))))
217      "highlight regexps.
218 See `gnus-emphasis-alist'.")
219
220     (posting-style
221      (choice :tag "Posting style"
222              :value nil
223              (repeat (list
224                       (choice :tag "Type"
225                               :value nil
226                               (const signature)
227                               (const signature-file)
228                               (const organization)
229                               (const address)
230                               (const name)
231                               (const body)
232                               (const import))
233                       (string :format "%v"))))
234      "post style.
235 See `gnus-posting-styles'."))
236   "Alist of valid group or topic parameters.
237
238 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
239 itself (a symbol), TYPE is the parameters type (a sexp widget), and
240 DOC is a documentation string for the parameter.")
241
242 (defconst gnus-extra-topic-parameters
243   '((subscribe (regexp :tag "Subscribe") "\
244 If `gnus-subscribe-newsgroup-method' or
245 `gnus-subscribe-options-newsgroup-method' is set to
246 `gnus-subscribe-topics', new groups that matches this regexp will
247 automatically be subscribed to this topic")
248     (subscribe-level (integer :tag "Subscribe Level" :value 1) "\
249 If this topic parameter is set, when new groups are subscribed
250 automatically under this topic (via the `subscribe' topic parameter)
251 assign this level to the group, rather than the default level
252 set in `gnus-level-default-subscribed'"))
253   "Alist of topic parameters that are not also group parameters.
254
255 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
256 itself (a symbol), TYPE is the parameters type (a sexp widget), and
257 DOC is a documentation string for the parameter.")
258
259 (defconst gnus-extra-group-parameters
260   '((uidvalidity (string :tag "IMAP uidvalidity") "\
261 Server-assigned value attached to IMAP groups, used to maintain consistency."))
262   "Alist of group parameters that are not also topic parameters.
263
264 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
265 itself (a symbol), TYPE is the parameters type (a sexp widget), and
266 DOC is a documentation string for the parameter.")
267 (defvar gnus-custom-params)
268 (defvar gnus-custom-method)
269 (defvar gnus-custom-group)
270 (defvar gnus-custom-topic)
271
272 (defun gnus-group-customize (group &optional topic)
273   "Edit the group or topic on the current line."
274   (interactive (list (gnus-group-group-name) (gnus-group-topic-name)))
275   (let (info
276         (types (mapcar (lambda (entry)
277                          `(cons :format "%v%h\n"
278                                 :doc ,(nth 2 entry)
279                                 (const :format "" ,(nth 0 entry))
280                                 ,(nth 1 entry)))
281                        (append (reverse gnus-group-parameters-more)
282                                gnus-group-parameters
283                                (if group
284                                    gnus-extra-group-parameters
285                                  gnus-extra-topic-parameters)))))
286     (unless (or group topic)
287       (error "No group on current line"))
288     (when (and group topic)
289       (error "Both a group an topic on current line"))
290     (unless (or topic (setq info (gnus-get-info group)))
291       (error "Killed group; can't be edited"))
292     ;; Ready.
293     (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
294     (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
295     (gnus-custom-mode)
296     (make-local-variable 'gnus-custom-group)
297     (setq gnus-custom-group group)
298     (make-local-variable 'gnus-custom-topic)
299     (setq gnus-custom-topic topic)
300     (buffer-disable-undo)
301     (widget-insert "Customize the ")
302     (if group
303         (widget-create 'info-link
304                        :help-echo "Push me to learn more."
305                        :tag "group parameters"
306                        "(gnus)Group Parameters")
307       (widget-create 'info-link
308                      :help-echo "Push me to learn more."
309                      :tag  "topic parameters"
310                      "(gnus)Topic Parameters"))
311     (widget-insert " for <")
312     (widget-insert (gnus-group-decoded-name (or group topic)))
313     (widget-insert "> and press ")
314     (widget-create 'push-button
315                    :tag "done"
316                    :help-echo "Push me when done customizing."
317                    :action 'gnus-group-customize-done)
318     (widget-insert ".\n\n")
319     (make-local-variable 'gnus-custom-params)
320     (setq gnus-custom-params
321           (widget-create 'group
322                          :value (if group
323                                     (gnus-info-params info)
324                                   (gnus-topic-parameters topic))
325                          `(set :inline t
326                                :greedy t
327                                :tag "Parameters"
328                                :format "%t:\n%h%v"
329                                :doc "\
330 These special parameters are recognized by Gnus.
331 Check the [ ] for the parameters you want to apply to this group or
332 to the groups in this topic, then edit the value to suit your taste."
333                                ,@types)
334                          '(repeat :inline t
335                                   :tag "Variables"
336                                   :format "%t:\n%h%v%i\n\n"
337                                   :doc "\
338 Set variables local to the group you are entering.
339
340 If you want to turn threading off in `news.answers', you could put
341 `(gnus-show-threads nil)' in the group parameters of that group.
342 `gnus-show-threads' will be made into a local variable in the summary
343 buffer you enter, and the form nil will be `eval'ed there.
344
345 This can also be used as a group-specific hook function, if you'd
346 like.  If you want to hear a beep when you enter a group, you could
347 put something like `(dummy-variable (ding))' in the parameters of that
348 group.  `dummy-variable' will be set to the result of the `(ding)'
349 form, but who cares?"
350                                   (list :format "%v" :value (nil nil)
351                                         (symbol :tag "Variable")
352                                         (sexp :tag
353                                               "Value")))
354
355                          '(repeat :inline t
356                                   :tag "Unknown entries"
357                                   sexp)))
358     (when group
359       (widget-insert "\n\nYou can also edit the ")
360       (widget-create 'info-link
361                      :tag "select method"
362                      :help-echo "Push me to learn more about select methods."
363                      "(gnus)Select Methods")
364       (widget-insert " for the group.\n")
365       (setq gnus-custom-method
366             (widget-create 'sexp
367                            :tag "Method"
368                            :value (gnus-info-method info))))
369     (use-local-map widget-keymap)
370     (widget-setup)
371     (buffer-enable-undo)
372     (goto-char (point-min))))
373
374 (defun gnus-group-customize-done (&rest ignore)
375   "Apply changes and bury the buffer."
376   (interactive)
377   (if gnus-custom-topic
378       (gnus-topic-set-parameters gnus-custom-topic
379                                  (widget-value gnus-custom-params))
380     (gnus-group-edit-group-done 'params gnus-custom-group
381                                 (widget-value gnus-custom-params))
382     (gnus-group-edit-group-done 'method gnus-custom-group
383                                 (widget-value gnus-custom-method)))
384   (bury-buffer))
385
386 ;;; Score Customization:
387
388 (defconst gnus-score-parameters
389   '((mark (number :tag "Mark") "\
390 The value of this entry should be a number.
391 Any articles with a score lower than this number will be marked as read.")
392
393     (expunge (number :tag "Expunge") "\
394 The value of this entry should be a number.
395 Any articles with a score lower than this number will be removed from
396 the summary buffer.")
397
398     (mark-and-expunge (number :tag "Mark-and-expunge") "\
399 The value of this entry should be a number.
400 Any articles with a score lower than this number will be marked as
401 read and removed from the summary buffer.")
402
403     (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
404 The value of this entry should be a number.
405 All articles that belong to a thread that has a total score below this
406 number will be marked as read and removed from the summary buffer.
407 `gnus-thread-score-function' says how to compute the total score
408 for a thread.")
409
410     (files (repeat :inline t :tag "Files" file) "\
411 The value of this entry should be any number of file names.
412 These files are assumed to be score files as well, and will be loaded
413 the same way this one was.")
414
415     (exclude-files (repeat :inline t :tag "Exclude-files" file) "\
416 The clue of this entry should be any number of files.
417 These files will not be loaded, even though they would normally be so,
418 for some reason or other.")
419
420     (eval (sexp :tag "Eval" :value nil) "\
421 The value of this entry will be `eval'el.
422 This element will be ignored when handling global score files.")
423
424     (read-only (boolean :tag "Read-only" :value t) "\
425 Read-only score files will not be updated or saved.
426 Global score files should feature this atom.")
427
428     (orphan (number :tag "Orphan") "\
429 The value of this entry should be a number.
430 Articles that do not have parents will get this number added to their
431 scores.  Imagine you follow some high-volume newsgroup, like
432 `comp.lang.c'.  Most likely you will only follow a few of the threads,
433 also want to see any new threads.
434
435 You can do this with the following two score file entries:
436
437      (orphan -500)
438      (mark-and-expunge -100)
439
440 When you enter the group the first time, you will only see the new
441 threads.  You then raise the score of the threads that you find
442 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
443 Next time you enter the group, you will see new articles in the
444 interesting threads, plus any new threads.
445
446 I.e.---the orphan score atom is for high-volume groups where there
447 exist a few interesting threads which can't be found automatically
448 by ordinary scoring rules.")
449
450     (adapt (choice :tag "Adapt"
451                    (const t)
452                    (const ignore)
453                    (sexp :format "%v"
454                          :hide-front-space t)) "\
455 This entry controls the adaptive scoring.
456 If it is t, the default adaptive scoring rules will be used.  If it
457 is `ignore', no adaptive scoring will be performed on this group.  If
458 it is a list, this list will be used as the adaptive scoring rules.
459 If it isn't present, or is something other than t or `ignore', the
460 default adaptive scoring rules will be used.  If you want to use
461 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
462 to t, and insert an `(adapt ignore)' in the groups where you do not
463 want adaptive scoring.  If you only want adaptive scoring in a few
464 groups, you'd set `gnus-use-adaptive-scoring' to nil, and insert
465 `(adapt t)' in the score files of the groups where you want it.")
466
467     (adapt-file (file :tag "Adapt-file") "\
468 All adaptive score entries will go to the file named by this entry.
469 It will also be applied when entering the group.  This atom might
470 be handy if you want to adapt on several groups at once, using the
471 same adaptive file for a number of groups.")
472
473     (local (repeat :tag "Local"
474                    (group :value (nil nil)
475                           (symbol :tag "Variable")
476                           (sexp :tag "Value"))) "\
477 The value of this entry should be a list of `(VAR VALUE)' pairs.
478 Each VAR will be made buffer-local to the current summary buffer,
479 and set to the value specified.  This is a convenient, if somewhat
480 strange, way of setting variables in some groups if you don't like
481 hooks much.")
482     (touched (sexp :format "Touched\n") "Internal variable."))
483   "Alist of valid symbolic score parameters.
484
485 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
486 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
487 documentation string for the parameter.")
488
489 (define-widget 'gnus-score-string 'group
490   "Edit score entries for string-valued headers."
491   :convert-widget 'gnus-score-string-convert)
492
493 (defun gnus-score-string-convert (widget)
494   ;; Set args appropriately.
495   (let* ((tag (widget-get widget :tag))
496          (item `(const :format "" :value ,(downcase tag)))
497          (match '(string :tag "Match"))
498          (score '(choice :tag "Score"
499                          (const :tag "default" nil)
500                          (integer :format "%v"
501                                   :hide-front-space t)))
502          (expire '(choice :tag "Expire"
503                           (const :tag "off" nil)
504                           (integer :format "%v"
505                                    :hide-front-space t)))
506          (type '(choice :tag "Type"
507                         :value s
508                         ;; I should really create a forgiving :match
509                         ;; function for each type below, that only
510                         ;; looked at the first letter.
511                         (const :tag "Regexp" r)
512                         (const :tag "Regexp (fixed case)" R)
513                         (const :tag "Substring" s)
514                         (const :tag "Substring (fixed case)" S)
515                         (const :tag "Exact" e)
516                         (const :tag "Exact (fixed case)" E)
517                         (const :tag "Word" w)
518                         (const :tag "Word (fixed case)" W)
519                         (const :tag "default" nil)))
520          (group `(group ,match ,score ,expire ,type))
521          (doc (concat (or (widget-get widget :doc)
522                           (concat "Change score based on the " tag
523                                   " header.\n"))
524                       "
525 You can have an arbitrary number of score entries for this header,
526 each score entry has four elements:
527
528 1. The \"match element\".  This should be the string to look for in the
529    header.
530
531 2. The \"score element\".  This number should be an integer in the
532    neginf to posinf interval.  This number is added to the score
533    of the article if the match is successful.  If this element is
534    not present, the `gnus-score-interactive-default-score' number
535    will be used instead.  This is 1000 by default.
536
537 3. The \"date element\".  This date says when the last time this score
538    entry matched, which provides a mechanism for expiring the
539    score entries.  It this element is not present, the score
540    entry is permanent.  The date is represented by the number of
541    days since December 31, 1 ce.
542
543 4. The \"type element\".  This element specifies what function should
544    be used to see whether this score entry matches the article.
545
546    There are the regexp, as well as substring types, and exact match,
547    and word match types.  If this element is not present, Gnus will
548    assume that substring matching should be used.  There is case
549    sensitive variants of all match types.")))
550     (widget-put widget :args `(,item
551                                (repeat :inline t
552                                        :indent 0
553                                        :tag ,tag
554                                        :doc ,doc
555                                        :format "%t:\n%h%v%i\n\n"
556                                        (choice :format "%v"
557                                                :value ("" nil nil s)
558                                                ,group
559                                                sexp)))))
560   widget)
561
562 (define-widget 'gnus-score-integer 'group
563   "Edit score entries for integer-valued headers."
564   :convert-widget 'gnus-score-integer-convert)
565
566 (defun gnus-score-integer-convert (widget)
567   ;; Set args appropriately.
568   (let* ((tag (widget-get widget :tag))
569          (item `(const :format "" :value ,(downcase tag)))
570          (match '(integer :tag "Match"))
571          (score '(choice :tag "Score"
572                          (const :tag "default" nil)
573                          (integer :format "%v"
574                                   :hide-front-space t)))
575          (expire '(choice :tag "Expire"
576                           (const :tag "off" nil)
577                           (integer :format "%v"
578                                    :hide-front-space t)))
579          (type '(choice :tag "Type"
580                         :value <
581                         (const <)
582                         (const >)
583                         (const =)
584                         (const >=)
585                         (const <=)))
586          (group `(group ,match ,score ,expire ,type))
587          (doc (concat (or (widget-get widget :doc)
588                           (concat "Change score based on the " tag
589                                   " header.")))))
590     (widget-put widget :args `(,item
591                                (repeat :inline t
592                                        :indent 0
593                                        :tag ,tag
594                                        :doc ,doc
595                                        :format "%t:\n%h%v%i\n\n"
596                                        ,group))))
597   widget)
598
599 (define-widget 'gnus-score-date 'group
600   "Edit score entries for date-valued headers."
601   :convert-widget 'gnus-score-date-convert)
602
603 (defun gnus-score-date-convert (widget)
604   ;; Set args appropriately.
605   (let* ((tag (widget-get widget :tag))
606          (item `(const :format "" :value ,(downcase tag)))
607          (match '(string :tag "Match"))
608          (score '(choice :tag "Score"
609                          (const :tag "default" nil)
610                          (integer :format "%v"
611                                   :hide-front-space t)))
612          (expire '(choice :tag "Expire"
613                           (const :tag "off" nil)
614                           (integer :format "%v"
615                                    :hide-front-space t)))
616          (type '(choice :tag "Type"
617                         :value regexp
618                         (const regexp)
619                         (const before)
620                         (const at)
621                         (const after)))
622          (group `(group ,match ,score ,expire ,type))
623          (doc (concat (or (widget-get widget :doc)
624                           (concat "Change score based on the " tag
625                                   " header."))
626                       "
627 For the Date header we have three kinda silly match types: `before',
628 `at' and `after'.  I can't really imagine this ever being useful, but,
629 like, it would feel kinda silly not to provide this function.  Just in
630 case.  You never know.  Better safe than sorry.  Once burnt, twice
631 shy.  Don't judge a book by its cover.  Never not have sex on a first
632 date.  (I have been told that at least one person, and I quote,
633 \"found this function indispensable\", however.)
634
635 A more useful match type is `regexp'.  With it, you can match the date
636 string using a regular expression.  The date is normalized to ISO8601
637 compact format first---`YYYYMMDDTHHMMSS'.  If you want to match all
638 articles that have been posted on April 1st in every year, you could
639 use `....0401.........' as a match string, for instance.  (Note that
640 the date is kept in its original time zone, so this will match
641 articles that were posted when it was April 1st where the article was
642 posted from.  Time zones are such wholesome fun for the whole family,
643 eh?")))
644     (widget-put widget :args `(,item
645                                (repeat :inline t
646                                        :indent 0
647                                        :tag ,tag
648                                        :doc ,doc
649                                        :format "%t:\n%h%v%i\n\n"
650                                        ,group))))
651   widget)
652
653 (defvar gnus-custom-scores)
654 (defvar gnus-custom-score-alist)
655
656 (defun gnus-score-customize (file)
657   "Customize score file FILE.
658 When called interactively, FILE defaults to the current score file.
659 This can be changed using the `\\[gnus-score-change-score-file]' command."
660   (interactive (list gnus-current-score-file))
661   (unless file
662     (error (format "No score file for %s"
663                    (gnus-group-decoded-name gnus-newsgroup-name))))
664   (let ((scores (gnus-score-load file))
665         (types (mapcar (lambda (entry)
666                          `(group :format "%v%h\n"
667                                  :doc ,(nth 2 entry)
668                                  (const :format "" ,(nth 0 entry))
669                                  ,(nth 1 entry)))
670                        gnus-score-parameters)))
671     ;; Ready.
672     (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
673     (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
674     (gnus-custom-mode)
675     (make-local-variable 'gnus-custom-score-alist)
676     (setq gnus-custom-score-alist scores)
677     (widget-insert "Customize the ")
678     (widget-create 'info-link
679                    :help-echo "Push me to learn more."
680                    :tag "score entries"
681                    "(gnus)Score File Format")
682     (widget-insert " for\n\t")
683     (widget-insert file)
684     (widget-insert "\nand press ")
685     (widget-create 'push-button
686                    :tag "done"
687                    :help-echo "Push me when done customizing."
688                    :action 'gnus-score-customize-done)
689     (widget-insert ".\n
690 Check the [ ] for the entries you want to apply to this score file, then
691 edit the value to suit your taste.  Don't forget to mark the checkbox,
692 if you do all your changes will be lost.  ")
693     (widget-create 'push-button
694                    :action (lambda (&rest ignore)
695                              (require 'gnus-audio)
696                              (gnus-audio-play "Evil_Laugh.au"))
697                    "Bhahahah!")
698     (widget-insert "\n\n")
699     (make-local-variable 'gnus-custom-scores)
700     (setq gnus-custom-scores
701           (widget-create 'group
702                          :value scores
703                          `(checklist :inline t
704                                      :greedy t
705                                      (gnus-score-string :tag "From")
706                                      (gnus-score-string :tag "Subject")
707                                      (gnus-score-string :tag "References")
708                                      (gnus-score-string :tag "Xref")
709                                      (gnus-score-string :tag "Extra")
710                                      (gnus-score-string :tag "Message-ID")
711                                      (gnus-score-integer :tag "Lines")
712                                      (gnus-score-integer :tag "Chars")
713                                      (gnus-score-date :tag "Date")
714                                      (gnus-score-string :tag "Head"
715                                                         :doc "\
716 Match all headers in the article.
717
718 Using one of `Head', `Body', `All' will slow down scoring considerable.
719 ")
720                                      (gnus-score-string :tag "Body"
721                                                         :doc "\
722 Match the body sans header of the article.
723
724 Using one of `Head', `Body', `All' will slow down scoring considerable.
725 ")
726                                      (gnus-score-string :tag "All"
727                                                         :doc "\
728 Match the entire article, including both headers and body.
729
730 Using one of `Head', `Body', `All' will slow down scoring
731 considerable.
732 ")
733                                      (gnus-score-string :tag
734                                                         "Followup"
735                                                         :doc "\
736 Score all followups to the specified authors.
737
738 This entry is somewhat special, in that it will match the `From:'
739 header, and affect the score of not only the matching articles, but
740 also all followups to the matching articles.  This allows you
741 e.g. increase the score of followups to your own articles, or decrease
742 the score of followups to the articles of some known trouble-maker.
743 ")
744                                      (gnus-score-string :tag "Thread"
745                                                         :doc "\
746 Add a score entry on all articles that are part of a thread.
747
748 This match key works along the same lines as the `Followup' match key.
749 If you say that you want to score on a (sub-)thread that is started by
750 an article with a `Message-ID' X, then you add a `thread' match.  This
751 will add a new `thread' match for each article that has X in its
752 `References' header.  (These new `thread' matches will use the
753 `Message-ID's of these matching articles.)  This will ensure that you
754 can raise/lower the score of an entire thread, even though some
755 articles in the thread may not have complete `References' headers.
756 Note that using this may lead to undeterministic scores of the
757 articles in the thread.
758 ")
759                                      ,@types)
760                          '(repeat :inline t
761                                   :tag "Unknown entries"
762                                   sexp)))
763     (use-local-map widget-keymap)
764     (widget-setup)))
765
766 (defun gnus-score-customize-done (&rest ignore)
767   "Reset the score alist with the present value."
768   (let ((alist gnus-custom-score-alist)
769         (value (widget-value gnus-custom-scores)))
770     (setcar alist (car value))
771     (setcdr alist (cdr value))
772     (gnus-score-set 'touched '(t) alist))
773   (bury-buffer))
774
775 ;;; The End:
776
777 (provide 'gnus-cus)
778
779 ;;; gnus-cus.el ends here