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