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