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