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