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