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