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