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