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