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