2f80b477f59c51fe8001c7e4a9528439e70ac8e6
[elisp/gnus.git-] / lisp / gnus-cus.el
1 ;;; gnus-cus.el --- customization commands for Gnus
2 ;;
3 ;; Copyright (C) 1996, 1999, 2000, 2001, 2002, 2003
4 ;;        Free Software Foundation, Inc.
5
6 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (require 'wid-edit)
31 (require 'gnus)
32 (require 'gnus-score)
33 (require 'gnus-topic)
34 (require 'gnus-art)
35
36 ;;; Widgets:
37
38 (defun gnus-custom-mode ()
39   "Major mode for editing Gnus customization buffers.
40
41 The following commands are available:
42
43 \\[widget-forward]              Move to next button or editable field.
44 \\[widget-backward]             Move to previous button or editable field.
45 \\[widget-button-click]         Activate button under the mouse pointer.
46 \\[widget-button-press]         Activate button under point.
47
48 Entry to this mode calls the value of `gnus-custom-mode-hook'
49 if that value is non-nil."
50   (kill-all-local-variables)
51   (setq major-mode 'gnus-custom-mode
52         mode-name "Gnus Customize")
53   (use-local-map widget-keymap)
54   ;; Emacs 21 stuff:
55   (when (and (facep 'custom-button-face)
56              (facep 'custom-button-pressed-face))
57     (set (make-local-variable 'widget-button-face)
58          'custom-button-face)
59     (set (make-local-variable 'widget-button-pressed-face)
60          'custom-button-pressed-face)
61     (set (make-local-variable 'widget-mouse-face)
62          'custom-button-pressed-face))
63   (when (and (boundp 'custom-raised-buttons)
64              (symbol-value 'custom-raised-buttons))
65     (set (make-local-variable 'widget-push-button-prefix) "")
66     (set (make-local-variable 'widget-push-button-suffix) "")
67     (set (make-local-variable 'widget-link-prefix) "")
68     (set (make-local-variable 'widget-link-suffix) ""))
69   (gnus-run-hooks 'gnus-custom-mode-hook))
70
71 ;;; Group Customization:
72
73 (defconst gnus-group-parameters
74   '((extra-aliases (choice
75                     :tag "Extra Aliases"
76                     (list
77                      :tag "List"
78                      (editable-list
79                       :inline t
80                       (gnus-email-address :tag "Address")))
81                     (gnus-email-address :tag "Address")) "\
82 Store messages posted from or to this address in this group.
83
84 You must be using gnus-group-split for this to work.  The VALUE of the
85 nnmail-split-fancy SPLIT generated for this group will match these
86 addresses.")
87
88     (split-regexp (regexp :tag "gnus-group-split Regular Expression") "\
89 Like gnus-group-split Address, but expects a regular expression.")
90
91     (split-exclude (list :tag "gnus-group-split Restricts"
92                          (editable-list
93                           :inline t (regexp :tag "Restrict"))) "\
94 Regular expression that cancels gnus-group-split matches.
95
96 Each entry is added to the nnmail-split-fancy SPLIT as a separate
97 RESTRICT clause.")
98
99     (split-spec (choice :tag "gnus-group-split Overrider"
100                         (sexp :tag "Fancy Split")
101                         (const :tag "Catch All" catch-all)
102                         (const :tag "Ignore" nil)) "\
103 Override all other gnus-group-split fields.
104
105 In `Fancy Split', you can enter any nnmail-split-fancy SPLIT.  Note
106 that the name of this group won't be automatically assumed, you have
107 to add it to the SPLITs yourself.  This means you can use such splits
108 to split messages to other groups too.
109
110 If you select `Catch All', this group will get postings for any
111 messages not matched in any other group.  It overrides the variable
112 gnus-group-split-default-catch-all-group.
113
114 Selecting `Ignore' forces no SPLIT to be generated for this group,
115 disabling all other gnus-group-split fields.")
116
117     (broken-reply-to (const :tag "Broken Reply To" t) "\
118 Ignore `Reply-To' headers in this group.
119
120 That can be useful if you're reading a mailing list group where the
121 listserv has inserted `Reply-To' headers that point back to the
122 listserv itself.  This is broken behavior.  So there!")
123
124     (to-group (string :tag "To Group") "\
125 All posts will be sent to the specified group.")
126
127     (gcc-self (choice :tag  "GCC"
128                       :value t
129                       (const :tag "To current group" t)
130                       (const none)
131                       (string :format "%v" :hide-front-space t)) "\
132 Specify default value for GCC header.
133
134 If this symbol is present in the group parameter list and set to t,
135 new composed messages will be `Gcc''d to the current group.  If it is
136 present and set to `none', no `Gcc:' header will be generated, if it
137 is present and a string, this string will be inserted literally as a
138 `gcc' header (this symbol takes precedence over any default `Gcc'
139 rules as described later).")
140
141     (expiry-wait (choice :tag  "Expire Wait"
142                          :value never
143                          (const never)
144                          (const immediate)
145                          (number :hide-front-space t
146                                  :format "%v")) "\
147 When to expire.
148
149 Overrides any `nnmail-expiry-wait' and `nnmail-expiry-wait-function'
150 when expiring expirable messages.  The value can either be a number of
151 days (not necessarily an integer) or the symbols `never' or
152 `immediate'.")
153
154     (expiry-target (choice :tag "Expiry Target"
155                            :value delete
156                            (const delete)
157                            (function :format "%v" nnmail-)
158                            string) "\
159 Where expired messages end up.
160
161 Overrides `nnmail-expiry-target', which see.")
162
163     (score-file (file :tag "Score File") "\
164 Make the specified file into the current score file.
165 This means that all score commands you issue will end up in this file.")
166
167     (adapt-file (file :tag "Adapt File") "\
168 Make the specified file into the current adaptive file.
169 All adaptive score entries will be put into this file.")
170
171     (admin-address (gnus-email-address :tag "Admin Address") "\
172 Administration address for a mailing list.
173
174 When unsubscribing to a mailing list you should never send the
175 unsubscription notice to the mailing list itself.  Instead, you'd
176 send messages to the administrative address.  This parameter allows
177 you to put the admin address somewhere convenient.")
178
179     (display (choice :tag "Display"
180                      :value default
181                      (const all)
182                      (integer)
183                      (const default)
184                      (sexp  :tag "Other")) "\
185 Which articles to display on entering the group.
186
187 `all'
188      Display all articles, both read and unread.
189
190 `integer'
191      Display the last NUMBER articles in the group.  This is the same as
192      entering the group with C-u NUMBER.
193
194 `default'
195      Display the default visible articles, which normally includes
196      unread and ticked articles.
197
198 `Other'
199      Display the articles that satisfy the S-expression. The S-expression
200      should be in an array form.")
201
202     (comment (string :tag  "Comment") "\
203 An arbitrary comment on the group.")
204
205     (visible (const :tag "Permanently visible" t) "\
206 Always display this group, even when there are no unread articles
207 in it..")
208
209     (highlight-words
210      (choice :tag "Highlight words"
211              :value nil
212              (repeat (list (regexp :tag "Highlight regexp")
213                            (number :tag "Group for entire word" 0)
214                            (number :tag "Group for displayed part" 0)
215                            (symbol :tag "Face"
216                                    gnus-emphasis-highlight-words))))
217      "highlight regexps.
218 See `gnus-emphasis-alist'.")
219
220     (posting-style
221      (choice :tag "Posting style"
222              :value nil
223              (repeat (list
224                       (choice :tag "Type"
225                               :value nil
226                               (const signature)
227                               (const signature-file)
228                               (const organization)
229                               (const address)
230                               (const name)
231                               (const body))
232                       (string :format "%v"))))
233      "post style.
234 See `gnus-posting-styles'."))
235   "Alist of valid group or topic parameters.
236
237 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
238 itself (a symbol), TYPE is the parameters type (a sexp widget), and
239 DOC is a documentation string for the parameter.")
240
241 (defconst gnus-extra-topic-parameters
242   '((subscribe (regexp :tag "Subscribe") "\
243 If `gnus-subscribe-newsgroup-method' or
244 `gnus-subscribe-options-newsgroup-method' is set to
245 `gnus-subscribe-topics', new groups that matches this regexp will
246 automatically be subscribed to this topic")
247     (subscribe-level (integer :tag "Subscribe Level" :value 1) "\
248 If this topic parameter is set, when new groups are subscribed
249 automatically under this topic (via the `subscribe' topic parameter)
250 assign this level to the group, rather than the default level
251 set in `gnus-level-default-subscribed'"))
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