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