1 ;;; gnus-cus.el --- customization commands for Gnus
3 ;; Copyright (C) 1996,1999, 2000 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
8 ;; This file is part of GNU Emacs.
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)
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.
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.
37 (defun gnus-custom-mode ()
38 "Major mode for editing Gnus customization buffers.
40 The following commands are available:
42 \\[widget-forward] Move to next button or editable field.
43 \\[widget-backward] Move to previous button or editable field.
44 \\[widget-button-click] Activate button under the mouse pointer.
45 \\[widget-button-press] Activate button under point.
47 Entry to this mode calls the value of `gnus-custom-mode-hook'
48 if that value is non-nil."
49 (kill-all-local-variables)
50 (setq major-mode 'gnus-custom-mode
51 mode-name "Gnus Customize")
52 (use-local-map widget-keymap)
54 (when (and (facep 'custom-button-face)
55 (facep 'custom-button-pressed-face))
56 (set (make-local-variable 'widget-button-face)
58 (set (make-local-variable 'widget-button-pressed-face)
59 'custom-button-pressed-face)
60 (set (make-local-variable 'widget-mouse-face)
61 'custom-button-pressed-face))
62 (when (and (boundp 'custom-raised-buttons)
63 (symbol-value 'custom-raised-buttons))
64 (set (make-local-variable 'widget-push-button-prefix) "")
65 (set (make-local-variable 'widget-push-button-suffix) "")
66 (set (make-local-variable 'widget-link-prefix) "")
67 (set (make-local-variable 'widget-link-suffix) ""))
68 (gnus-run-hooks 'gnus-custom-mode-hook))
70 ;;; Group Customization:
72 (defconst gnus-group-parameters
73 '((extra-aliases (choice
79 (gnus-email-address :tag "Address")))
80 (gnus-email-address :tag "Address")) "\
81 Store messages posted from or to this address in this group.
83 You must be using gnus-group-split for this to work. The VALUE of the
84 nnmail-split-fancy SPLIT generated for this group will match these
87 (split-regexp (regexp :tag "gnus-group-split Regular Expression") "\
88 Like gnus-group-split Address, but expects a regular expression.")
90 (split-exclude (list :tag "gnus-group-split Restricts"
92 :inline t (regexp :tag "Restrict"))) "\
93 Regular expression that cancels gnus-group-split matches.
95 Each entry is added to the nnmail-split-fancy SPLIT as a separate
98 (split-spec (choice :tag "gnus-group-split Overrider"
99 (sexp :tag "Fancy Split")
100 (const :tag "Catch All" catch-all)
101 (const :tag "Ignore" nil)) "\
102 Override all other gnus-group-split fields.
104 In `Fancy Split', you can enter any nnmail-split-fancy SPLIT. Note
105 that the name of this group won't be automatically assumed, you have
106 to add it to the SPLITs yourself. This means you can use such splits
107 to split messages to other groups too.
109 If you select `Catch All', this group will get postings for any
110 messages not matched in any other group. It overrides the variable
111 gnus-group-split-default-catch-all-group.
113 Selecting `Ignore' forces no SPLIT to be generated for this group,
114 disabling all other gnus-group-split fields.")
116 (broken-reply-to (const :tag "Broken Reply To" t) "\
117 Ignore `Reply-To' headers in this group.
119 That can be useful if you're reading a mailing list group where the
120 listserv has inserted `Reply-To' headers that point back to the
121 listserv itself. This is broken behavior. So there!")
123 (to-group (string :tag "To Group") "\
124 All posts will be sent to the specified group.")
126 (gcc-self (choice :tag "GCC"
128 (const :tag "To current group" t)
130 (string :format "%v" :hide-front-space t)) "\
131 Specify default value for GCC header.
133 If this symbol is present in the group parameter list and set to `t',
134 new composed messages will be `Gcc''d to the current group. If it is
135 present and set to `none', no `Gcc:' header will be generated, if it
136 is present and a string, this string will be inserted literally as a
137 `gcc' header (this symbol takes precedence over any default `Gcc'
138 rules as described later).")
140 (expiry-wait (choice :tag "Expire Wait"
144 (number :hide-front-space t
148 Overrides any `nnmail-expiry-wait' and `nnmail-expiry-wait-function'
149 when expiring expirable messages. The value can either be a number of
150 days (not necessarily an integer) or the symbols `never' or
153 (expiry-target (choice :tag "Expiry Target"
156 (function :format "%v" nnmail-)
158 Where expired messages end up.
160 Overrides `nnmail-expiry-target', which see.")
162 (score-file (file :tag "Score File") "\
163 Make the specified file into the current score file.
164 This means that all score commands you issue will end up in this file.")
166 (adapt-file (file :tag "Adapt File") "\
167 Make the specified file into the current adaptive file.
168 All adaptive score entries will be put into this file.")
170 (admin-address (gnus-email-address :tag "Admin Address") "\
171 Administration address for a mailing list.
173 When unsubscribing to a mailing list you should never send the
174 unsubscription notice to the mailing list itself. Instead, you'd
175 send messages to the administrative address. This parameter allows
176 you to put the admin address somewhere convenient.")
178 (display (choice :tag "Display"
182 Which articles to display on entering the group.
185 Display all articles, both read and unread.
188 Display the default visible articles, which normally includes
189 unread and ticked articles.")
191 (comment (string :tag "Comment") "\
192 An arbitrary comment on the group.")
194 (visible (const :tag "Permanently visible" t) "\
195 Always display this group, even when there are no unread articles
199 (choice :tag "Highlight words"
201 (repeat (list (regexp :tag "Highlight regexp")
202 (number :tag "Group for entire word" 0)
203 (number :tag "Group for displayed part" 0)
205 gnus-emphasis-highlight-words))))
207 See gnus-emphasis-alist.")
210 (choice :tag "Posting style"
216 (const signature-file)
221 (string :format "%v"))))
223 See gnus-posting-styles."))
224 "Alist of valid group or topic parameters.
226 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
227 itself (a symbol), TYPE is the parameters type (a sexp widget), and
228 DOC is a documentation string for the parameter.")
230 (defconst gnus-extra-topic-parameters
231 '((subscribe (regexp :tag "Subscribe") "\
232 If `gnus-subscribe-newsgroup-method' or
233 `gnus-subscribe-options-newsgroup-method' is set to
234 `gnus-subscribe-topics', new groups that matches this regexp will
235 automatically be subscribed to this topic"))
236 "Alist of topic parameters that are not also group parameters.
238 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
239 itself (a symbol), TYPE is the parameters type (a sexp widget), and
240 DOC is a documentation string for the parameter.")
242 (defconst gnus-extra-group-parameters
243 '((uidvalidity (string :tag "IMAP uidvalidity") "\
244 Server-assigned value attached to IMAP groups, used to maintain consistency."))
245 "Alist of group parameters that are not also topic parameters.
247 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
248 itself (a symbol), TYPE is the parameters type (a sexp widget), and
249 DOC is a documentation string for the parameter.")
250 (defvar gnus-custom-params)
251 (defvar gnus-custom-method)
252 (defvar gnus-custom-group)
253 (defvar gnus-custom-topic)
255 (defun gnus-group-customize (group &optional topic)
256 "Edit the group or topic on the current line."
257 (interactive (list (gnus-group-group-name) (gnus-group-topic-name)))
259 (types (mapcar (lambda (entry)
260 `(cons :format "%v%h\n"
262 (const :format "" ,(nth 0 entry))
264 (append (reverse gnus-group-parameters-more)
265 gnus-group-parameters
267 gnus-extra-group-parameters
268 gnus-extra-topic-parameters)))))
269 (unless (or group topic)
270 (error "No group on current line"))
271 (when (and group topic)
272 (error "Both a group an topic on current line"))
273 (unless (or topic (setq info (gnus-get-info group)))
274 (error "Killed group; can't be edited"))
276 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
277 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
279 (make-local-variable 'gnus-custom-group)
280 (setq gnus-custom-group group)
281 (make-local-variable 'gnus-custom-topic)
282 (setq gnus-custom-topic topic)
283 (buffer-disable-undo)
284 (widget-insert "Customize the ")
286 (widget-create 'info-link
287 :help-echo "Push me to learn more."
288 :tag "group parameters"
289 "(gnus)Group Parameters")
290 (widget-create 'info-link
291 :help-echo "Push me to learn more."
292 :tag "topic parameters"
293 "(gnus)Topic Parameters"))
294 (widget-insert " for <")
295 (widget-insert (gnus-group-decoded-name (or group topic)))
296 (widget-insert "> and press ")
297 (widget-create 'push-button
299 :help-echo "Push me when done customizing."
300 :action 'gnus-group-customize-done)
301 (widget-insert ".\n\n")
302 (make-local-variable 'gnus-custom-params)
303 (setq gnus-custom-params
304 (widget-create 'group
306 (gnus-info-params info)
307 (gnus-topic-parameters topic))
313 These special parameters are recognized by Gnus.
314 Check the [ ] for the parameters you want to apply to this group or
315 to the groups in this topic, then edit the value to suit your taste."
319 :format "%t:\n%h%v%i\n\n"
321 Set variables local to the group you are entering.
323 If you want to turn threading off in `news.answers', you could put
324 `(gnus-show-threads nil)' in the group parameters of that group.
325 `gnus-show-threads' will be made into a local variable in the summary
326 buffer you enter, and the form `nil' will be `eval'ed there.
328 This can also be used as a group-specific hook function, if you'd
329 like. If you want to hear a beep when you enter a group, you could
330 put something like `(dummy-variable (ding))' in the parameters of that
331 group. `dummy-variable' will be set to the result of the `(ding)'
332 form, but who cares?"
333 (list :format "%v" :value (nil nil)
334 (symbol :tag "Variable")
339 :tag "Unknown entries"
342 (widget-insert "\n\nYou can also edit the ")
343 (widget-create 'info-link
345 :help-echo "Push me to learn more about select methods."
346 "(gnus)Select Methods")
347 (widget-insert " for the group.\n")
348 (setq gnus-custom-method
351 :value (gnus-info-method info))))
352 (use-local-map widget-keymap)
355 (goto-char (point-min))))
357 (defun gnus-group-customize-done (&rest ignore)
358 "Apply changes and bury the buffer."
360 (if gnus-custom-topic
361 (gnus-topic-set-parameters gnus-custom-topic
362 (widget-value gnus-custom-params))
363 (gnus-group-edit-group-done 'params gnus-custom-group
364 (widget-value gnus-custom-params))
365 (gnus-group-edit-group-done 'method gnus-custom-group
366 (widget-value gnus-custom-method)))
369 ;;; Score Customization:
371 (defconst gnus-score-parameters
372 '((mark (number :tag "Mark") "\
373 The value of this entry should be a number.
374 Any articles with a score lower than this number will be marked as read.")
376 (expunge (number :tag "Expunge") "\
377 The value of this entry should be a number.
378 Any articles with a score lower than this number will be removed from
379 the summary buffer.")
381 (mark-and-expunge (number :tag "Mark-and-expunge") "\
382 The value of this entry should be a number.
383 Any articles with a score lower than this number will be marked as
384 read and removed from the summary buffer.")
386 (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
387 The value of this entry should be a number.
388 All articles that belong to a thread that has a total score below this
389 number will be marked as read and removed from the summary buffer.
390 `gnus-thread-score-function' says how to compute the total score
393 (files (repeat :inline t :tag "Files" file) "\
394 The value of this entry should be any number of file names.
395 These files are assumed to be score files as well, and will be loaded
396 the same way this one was.")
398 (exclude-files (repeat :inline t :tag "Exclude-files" file) "\
399 The clue of this entry should be any number of files.
400 These files will not be loaded, even though they would normally be so,
401 for some reason or other.")
403 (eval (sexp :tag "Eval" :value nil) "\
404 The value of this entry will be `eval'el.
405 This element will be ignored when handling global score files.")
407 (read-only (boolean :tag "Read-only" :value t) "\
408 Read-only score files will not be updated or saved.
409 Global score files should feature this atom.")
411 (orphan (number :tag "Orphan") "\
412 The value of this entry should be a number.
413 Articles that do not have parents will get this number added to their
414 scores. Imagine you follow some high-volume newsgroup, like
415 `comp.lang.c'. Most likely you will only follow a few of the threads,
416 also want to see any new threads.
418 You can do this with the following two score file entries:
421 (mark-and-expunge -100)
423 When you enter the group the first time, you will only see the new
424 threads. You then raise the score of the threads that you find
425 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
426 Next time you enter the group, you will see new articles in the
427 interesting threads, plus any new threads.
429 I.e.---the orphan score atom is for high-volume groups where there
430 exist a few interesting threads which can't be found automatically
431 by ordinary scoring rules.")
433 (adapt (choice :tag "Adapt"
437 :hide-front-space t)) "\
438 This entry controls the adaptive scoring.
439 If it is `t', the default adaptive scoring rules will be used. If it
440 is `ignore', no adaptive scoring will be performed on this group. If
441 it is a list, this list will be used as the adaptive scoring rules.
442 If it isn't present, or is something other than `t' or `ignore', the
443 default adaptive scoring rules will be used. If you want to use
444 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
445 to `t', and insert an `(adapt ignore)' in the groups where you do not
446 want adaptive scoring. If you only want adaptive scoring in a few
447 groups, you'd set `gnus-use-adaptive-scoring' to `nil', and insert
448 `(adapt t)' in the score files of the groups where you want it.")
450 (adapt-file (file :tag "Adapt-file") "\
451 All adaptive score entries will go to the file named by this entry.
452 It will also be applied when entering the group. This atom might
453 be handy if you want to adapt on several groups at once, using the
454 same adaptive file for a number of groups.")
456 (local (repeat :tag "Local"
457 (group :value (nil nil)
458 (symbol :tag "Variable")
459 (sexp :tag "Value"))) "\
460 The value of this entry should be a list of `(VAR VALUE)' pairs.
461 Each VAR will be made buffer-local to the current summary buffer,
462 and set to the value specified. This is a convenient, if somewhat
463 strange, way of setting variables in some groups if you don't like
465 (touched (sexp :format "Touched\n") "Internal variable."))
466 "Alist of valid symbolic score parameters.
468 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
469 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
470 documentation string for the parameter.")
472 (define-widget 'gnus-score-string 'group
473 "Edit score entries for string-valued headers."
474 :convert-widget 'gnus-score-string-convert)
476 (defun gnus-score-string-convert (widget)
477 ;; Set args appropriately.
478 (let* ((tag (widget-get widget :tag))
479 (item `(const :format "" :value ,(downcase tag)))
480 (match '(string :tag "Match"))
481 (score '(choice :tag "Score"
482 (const :tag "default" nil)
483 (integer :format "%v"
484 :hide-front-space t)))
485 (expire '(choice :tag "Expire"
486 (const :tag "off" nil)
487 (integer :format "%v"
488 :hide-front-space t)))
489 (type '(choice :tag "Type"
491 ;; I should really create a forgiving :match
492 ;; function for each type below, that only
493 ;; looked at the first letter.
494 (const :tag "Regexp" r)
495 (const :tag "Regexp (fixed case)" R)
496 (const :tag "Substring" s)
497 (const :tag "Substring (fixed case)" S)
498 (const :tag "Exact" e)
499 (const :tag "Exact (fixed case)" E)
500 (const :tag "Word" w)
501 (const :tag "Word (fixed case)" W)
502 (const :tag "default" nil)))
503 (group `(group ,match ,score ,expire ,type))
504 (doc (concat (or (widget-get widget :doc)
505 (concat "Change score based on the " tag
508 You can have an arbitrary number of score entries for this header,
509 each score entry has four elements:
511 1. The \"match element\". This should be the string to look for in the
514 2. The \"score element\". This number should be an integer in the
515 neginf to posinf interval. This number is added to the score
516 of the article if the match is successful. If this element is
517 not present, the `gnus-score-interactive-default-score' number
518 will be used instead. This is 1000 by default.
520 3. The \"date element\". This date says when the last time this score
521 entry matched, which provides a mechanism for expiring the
522 score entries. It this element is not present, the score
523 entry is permanent. The date is represented by the number of
524 days since December 31, 1 ce.
526 4. The \"type element\". This element specifies what function should
527 be used to see whether this score entry matches the article.
529 There are the regexp, as well as substring types, and exact match,
530 and word match types. If this element is not present, Gnus will
531 assume that substring matching should be used. There is case
532 sensitive variants of all match types.")))
533 (widget-put widget :args `(,item
538 :format "%t:\n%h%v%i\n\n"
540 :value ("" nil nil s)
545 (define-widget 'gnus-score-integer 'group
546 "Edit score entries for integer-valued headers."
547 :convert-widget 'gnus-score-integer-convert)
549 (defun gnus-score-integer-convert (widget)
550 ;; Set args appropriately.
551 (let* ((tag (widget-get widget :tag))
552 (item `(const :format "" :value ,(downcase tag)))
553 (match '(integer :tag "Match"))
554 (score '(choice :tag "Score"
555 (const :tag "default" nil)
556 (integer :format "%v"
557 :hide-front-space t)))
558 (expire '(choice :tag "Expire"
559 (const :tag "off" nil)
560 (integer :format "%v"
561 :hide-front-space t)))
562 (type '(choice :tag "Type"
569 (group `(group ,match ,score ,expire ,type))
570 (doc (concat (or (widget-get widget :doc)
571 (concat "Change score based on the " tag
573 (widget-put widget :args `(,item
578 :format "%t:\n%h%v%i\n\n"
582 (define-widget 'gnus-score-date 'group
583 "Edit score entries for date-valued headers."
584 :convert-widget 'gnus-score-date-convert)
586 (defun gnus-score-date-convert (widget)
587 ;; Set args appropriately.
588 (let* ((tag (widget-get widget :tag))
589 (item `(const :format "" :value ,(downcase tag)))
590 (match '(string :tag "Match"))
591 (score '(choice :tag "Score"
592 (const :tag "default" nil)
593 (integer :format "%v"
594 :hide-front-space t)))
595 (expire '(choice :tag "Expire"
596 (const :tag "off" nil)
597 (integer :format "%v"
598 :hide-front-space t)))
599 (type '(choice :tag "Type"
605 (group `(group ,match ,score ,expire ,type))
606 (doc (concat (or (widget-get widget :doc)
607 (concat "Change score based on the " tag
610 For the Date header we have three kinda silly match types: `before',
611 `at' and `after'. I can't really imagine this ever being useful, but,
612 like, it would feel kinda silly not to provide this function. Just in
613 case. You never know. Better safe than sorry. Once burnt, twice
614 shy. Don't judge a book by its cover. Never not have sex on a first
615 date. (I have been told that at least one person, and I quote,
616 \"found this function indispensable\", however.)
618 A more useful match type is `regexp'. With it, you can match the date
619 string using a regular expression. The date is normalized to ISO8601
620 compact format first---`YYYYMMDDTHHMMSS'. If you want to match all
621 articles that have been posted on April 1st in every year, you could
622 use `....0401.........' as a match string, for instance. (Note that
623 the date is kept in its original time zone, so this will match
624 articles that were posted when it was April 1st where the article was
625 posted from. Time zones are such wholesome fun for the whole family,
627 (widget-put widget :args `(,item
632 :format "%t:\n%h%v%i\n\n"
636 (defvar gnus-custom-scores)
637 (defvar gnus-custom-score-alist)
639 (defun gnus-score-customize (file)
640 "Customize score file FILE.
641 When called interactively, FILE defaults to the current score file.
642 This can be changed using the `\\[gnus-score-change-score-file]' command."
643 (interactive (list gnus-current-score-file))
645 (error (format "No score file for %s"
646 (gnus-group-decoded-name gnus-newsgroup-name))))
647 (let ((scores (gnus-score-load file))
648 (types (mapcar (lambda (entry)
649 `(group :format "%v%h\n"
651 (const :format "" ,(nth 0 entry))
653 gnus-score-parameters)))
655 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
656 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
658 (make-local-variable 'gnus-custom-score-alist)
659 (setq gnus-custom-score-alist scores)
660 (widget-insert "Customize the ")
661 (widget-create 'info-link
662 :help-echo "Push me to learn more."
664 "(gnus)Score File Format")
665 (widget-insert " for\n\t")
667 (widget-insert "\nand press ")
668 (widget-create 'push-button
670 :help-echo "Push me when done customizing."
671 :action 'gnus-score-customize-done)
673 Check the [ ] for the entries you want to apply to this score file, then
674 edit the value to suit your taste. Don't forget to mark the checkbox,
675 if you do all your changes will be lost. ")
676 (widget-create 'push-button
677 :action (lambda (&rest ignore)
678 (require 'gnus-audio)
679 (gnus-audio-play "Evil_Laugh.au"))
681 (widget-insert "\n\n")
682 (make-local-variable 'gnus-custom-scores)
683 (setq gnus-custom-scores
684 (widget-create 'group
686 `(checklist :inline t
688 (gnus-score-string :tag "From")
689 (gnus-score-string :tag "Subject")
690 (gnus-score-string :tag "References")
691 (gnus-score-string :tag "Xref")
692 (gnus-score-string :tag "Extra")
693 (gnus-score-string :tag "Message-ID")
694 (gnus-score-integer :tag "Lines")
695 (gnus-score-integer :tag "Chars")
696 (gnus-score-date :tag "Date")
697 (gnus-score-string :tag "Head"
699 Match all headers in the article.
701 Using one of `Head', `Body', `All' will slow down scoring considerable.
703 (gnus-score-string :tag "Body"
705 Match the body sans header of the article.
707 Using one of `Head', `Body', `All' will slow down scoring considerable.
709 (gnus-score-string :tag "All"
711 Match the entire article, including both headers and body.
713 Using one of `Head', `Body', `All' will slow down scoring
716 (gnus-score-string :tag
719 Score all followups to the specified authors.
721 This entry is somewhat special, in that it will match the `From:'
722 header, and affect the score of not only the matching articles, but
723 also all followups to the matching articles. This allows you
724 e.g. increase the score of followups to your own articles, or decrease
725 the score of followups to the articles of some known trouble-maker.
727 (gnus-score-string :tag "Thread"
729 Add a score entry on all articles that are part of a thread.
731 This match key works along the same lines as the `Followup' match key.
732 If you say that you want to score on a (sub-)thread that is started by
733 an article with a `Message-ID' X, then you add a `thread' match. This
734 will add a new `thread' match for each article that has X in its
735 `References' header. (These new `thread' matches will use the
736 `Message-ID's of these matching articles.) This will ensure that you
737 can raise/lower the score of an entire thread, even though some
738 articles in the thread may not have complete `References' headers.
739 Note that using this may lead to undeterministic scores of the
740 articles in the thread.
744 :tag "Unknown entries"
746 (use-local-map widget-keymap)
749 (defun gnus-score-customize-done (&rest ignore)
750 "Reset the score alist with the present value."
751 (let ((alist gnus-custom-score-alist)
752 (value (widget-value gnus-custom-scores)))
753 (setcar alist (car value))
754 (setcdr alist (cdr value))
755 (gnus-score-set 'touched '(t) alist))
762 ;;; gnus-cus.el ends here