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