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"
183 (sexp :tag "Other")) "\
184 Which articles to display on entering the group.
187 Display all articles, both read and unread.
190 Display the last NUMBER articles in the group. This is the same as
191 entering the group with C-u NUMBER.
194 Display the default visible articles, which normally includes
195 unread and ticked articles.
198 Display the articles that satisfy the S-expression. The S-expression
199 should be in an array form.")
201 (comment (string :tag "Comment") "\
202 An arbitrary comment on the group.")
204 (visible (const :tag "Permanently visible" t) "\
205 Always display this group, even when there are no unread articles
209 (choice :tag "Highlight words"
211 (repeat (list (regexp :tag "Highlight regexp")
212 (number :tag "Group for entire word" 0)
213 (number :tag "Group for displayed part" 0)
215 gnus-emphasis-highlight-words))))
217 See gnus-emphasis-alist.")
220 (choice :tag "Posting style"
226 (const signature-file)
231 (string :format "%v"))))
233 See gnus-posting-styles."))
234 "Alist of valid group or topic parameters.
236 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
237 itself (a symbol), TYPE is the parameters type (a sexp widget), and
238 DOC is a documentation string for the parameter.")
240 (defconst gnus-extra-topic-parameters
241 '((subscribe (regexp :tag "Subscribe") "\
242 If `gnus-subscribe-newsgroup-method' or
243 `gnus-subscribe-options-newsgroup-method' is set to
244 `gnus-subscribe-topics', new groups that matches this regexp will
245 automatically be subscribed to this topic"))
246 "Alist of topic parameters that are not also group parameters.
248 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
249 itself (a symbol), TYPE is the parameters type (a sexp widget), and
250 DOC is a documentation string for the parameter.")
252 (defconst gnus-extra-group-parameters
253 '((uidvalidity (string :tag "IMAP uidvalidity") "\
254 Server-assigned value attached to IMAP groups, used to maintain consistency."))
255 "Alist of group parameters that are not also topic parameters.
257 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
258 itself (a symbol), TYPE is the parameters type (a sexp widget), and
259 DOC is a documentation string for the parameter.")
260 (defvar gnus-custom-params)
261 (defvar gnus-custom-method)
262 (defvar gnus-custom-group)
263 (defvar gnus-custom-topic)
265 (defun gnus-group-customize (group &optional topic)
266 "Edit the group or topic on the current line."
267 (interactive (list (gnus-group-group-name) (gnus-group-topic-name)))
269 (types (mapcar (lambda (entry)
270 `(cons :format "%v%h\n"
272 (const :format "" ,(nth 0 entry))
274 (append (reverse gnus-group-parameters-more)
275 gnus-group-parameters
277 gnus-extra-group-parameters
278 gnus-extra-topic-parameters)))))
279 (unless (or group topic)
280 (error "No group on current line"))
281 (when (and group topic)
282 (error "Both a group an topic on current line"))
283 (unless (or topic (setq info (gnus-get-info group)))
284 (error "Killed group; can't be edited"))
286 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
287 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
289 (make-local-variable 'gnus-custom-group)
290 (setq gnus-custom-group group)
291 (make-local-variable 'gnus-custom-topic)
292 (setq gnus-custom-topic topic)
293 (buffer-disable-undo)
294 (widget-insert "Customize the ")
296 (widget-create 'info-link
297 :help-echo "Push me to learn more."
298 :tag "group parameters"
299 "(gnus)Group Parameters")
300 (widget-create 'info-link
301 :help-echo "Push me to learn more."
302 :tag "topic parameters"
303 "(gnus)Topic Parameters"))
304 (widget-insert " for <")
305 (widget-insert (gnus-group-decoded-name (or group topic)))
306 (widget-insert "> and press ")
307 (widget-create 'push-button
309 :help-echo "Push me when done customizing."
310 :action 'gnus-group-customize-done)
311 (widget-insert ".\n\n")
312 (make-local-variable 'gnus-custom-params)
313 (setq gnus-custom-params
314 (widget-create 'group
316 (gnus-info-params info)
317 (gnus-topic-parameters topic))
323 These special parameters are recognized by Gnus.
324 Check the [ ] for the parameters you want to apply to this group or
325 to the groups in this topic, then edit the value to suit your taste."
329 :format "%t:\n%h%v%i\n\n"
331 Set variables local to the group you are entering.
333 If you want to turn threading off in `news.answers', you could put
334 `(gnus-show-threads nil)' in the group parameters of that group.
335 `gnus-show-threads' will be made into a local variable in the summary
336 buffer you enter, and the form `nil' will be `eval'ed there.
338 This can also be used as a group-specific hook function, if you'd
339 like. If you want to hear a beep when you enter a group, you could
340 put something like `(dummy-variable (ding))' in the parameters of that
341 group. `dummy-variable' will be set to the result of the `(ding)'
342 form, but who cares?"
343 (list :format "%v" :value (nil nil)
344 (symbol :tag "Variable")
349 :tag "Unknown entries"
352 (widget-insert "\n\nYou can also edit the ")
353 (widget-create 'info-link
355 :help-echo "Push me to learn more about select methods."
356 "(gnus)Select Methods")
357 (widget-insert " for the group.\n")
358 (setq gnus-custom-method
361 :value (gnus-info-method info))))
362 (use-local-map widget-keymap)
365 (goto-char (point-min))))
367 (defun gnus-group-customize-done (&rest ignore)
368 "Apply changes and bury the buffer."
370 (if gnus-custom-topic
371 (gnus-topic-set-parameters gnus-custom-topic
372 (widget-value gnus-custom-params))
373 (gnus-group-edit-group-done 'params gnus-custom-group
374 (widget-value gnus-custom-params))
375 (gnus-group-edit-group-done 'method gnus-custom-group
376 (widget-value gnus-custom-method)))
379 ;;; Score Customization:
381 (defconst gnus-score-parameters
382 '((mark (number :tag "Mark") "\
383 The value of this entry should be a number.
384 Any articles with a score lower than this number will be marked as read.")
386 (expunge (number :tag "Expunge") "\
387 The value of this entry should be a number.
388 Any articles with a score lower than this number will be removed from
389 the summary buffer.")
391 (mark-and-expunge (number :tag "Mark-and-expunge") "\
392 The value of this entry should be a number.
393 Any articles with a score lower than this number will be marked as
394 read and removed from the summary buffer.")
396 (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
397 The value of this entry should be a number.
398 All articles that belong to a thread that has a total score below this
399 number will be marked as read and removed from the summary buffer.
400 `gnus-thread-score-function' says how to compute the total score
403 (files (repeat :inline t :tag "Files" file) "\
404 The value of this entry should be any number of file names.
405 These files are assumed to be score files as well, and will be loaded
406 the same way this one was.")
408 (exclude-files (repeat :inline t :tag "Exclude-files" file) "\
409 The clue of this entry should be any number of files.
410 These files will not be loaded, even though they would normally be so,
411 for some reason or other.")
413 (eval (sexp :tag "Eval" :value nil) "\
414 The value of this entry will be `eval'el.
415 This element will be ignored when handling global score files.")
417 (read-only (boolean :tag "Read-only" :value t) "\
418 Read-only score files will not be updated or saved.
419 Global score files should feature this atom.")
421 (orphan (number :tag "Orphan") "\
422 The value of this entry should be a number.
423 Articles that do not have parents will get this number added to their
424 scores. Imagine you follow some high-volume newsgroup, like
425 `comp.lang.c'. Most likely you will only follow a few of the threads,
426 also want to see any new threads.
428 You can do this with the following two score file entries:
431 (mark-and-expunge -100)
433 When you enter the group the first time, you will only see the new
434 threads. You then raise the score of the threads that you find
435 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
436 Next time you enter the group, you will see new articles in the
437 interesting threads, plus any new threads.
439 I.e.---the orphan score atom is for high-volume groups where there
440 exist a few interesting threads which can't be found automatically
441 by ordinary scoring rules.")
443 (adapt (choice :tag "Adapt"
447 :hide-front-space t)) "\
448 This entry controls the adaptive scoring.
449 If it is `t', the default adaptive scoring rules will be used. If it
450 is `ignore', no adaptive scoring will be performed on this group. If
451 it is a list, this list will be used as the adaptive scoring rules.
452 If it isn't present, or is something other than `t' or `ignore', the
453 default adaptive scoring rules will be used. If you want to use
454 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
455 to `t', and insert an `(adapt ignore)' in the groups where you do not
456 want adaptive scoring. If you only want adaptive scoring in a few
457 groups, you'd set `gnus-use-adaptive-scoring' to `nil', and insert
458 `(adapt t)' in the score files of the groups where you want it.")
460 (adapt-file (file :tag "Adapt-file") "\
461 All adaptive score entries will go to the file named by this entry.
462 It will also be applied when entering the group. This atom might
463 be handy if you want to adapt on several groups at once, using the
464 same adaptive file for a number of groups.")
466 (local (repeat :tag "Local"
467 (group :value (nil nil)
468 (symbol :tag "Variable")
469 (sexp :tag "Value"))) "\
470 The value of this entry should be a list of `(VAR VALUE)' pairs.
471 Each VAR will be made buffer-local to the current summary buffer,
472 and set to the value specified. This is a convenient, if somewhat
473 strange, way of setting variables in some groups if you don't like
475 (touched (sexp :format "Touched\n") "Internal variable."))
476 "Alist of valid symbolic score parameters.
478 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
479 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
480 documentation string for the parameter.")
482 (define-widget 'gnus-score-string 'group
483 "Edit score entries for string-valued headers."
484 :convert-widget 'gnus-score-string-convert)
486 (defun gnus-score-string-convert (widget)
487 ;; Set args appropriately.
488 (let* ((tag (widget-get widget :tag))
489 (item `(const :format "" :value ,(downcase tag)))
490 (match '(string :tag "Match"))
491 (score '(choice :tag "Score"
492 (const :tag "default" nil)
493 (integer :format "%v"
494 :hide-front-space t)))
495 (expire '(choice :tag "Expire"
496 (const :tag "off" nil)
497 (integer :format "%v"
498 :hide-front-space t)))
499 (type '(choice :tag "Type"
501 ;; I should really create a forgiving :match
502 ;; function for each type below, that only
503 ;; looked at the first letter.
504 (const :tag "Regexp" r)
505 (const :tag "Regexp (fixed case)" R)
506 (const :tag "Substring" s)
507 (const :tag "Substring (fixed case)" S)
508 (const :tag "Exact" e)
509 (const :tag "Exact (fixed case)" E)
510 (const :tag "Word" w)
511 (const :tag "Word (fixed case)" W)
512 (const :tag "default" nil)))
513 (group `(group ,match ,score ,expire ,type))
514 (doc (concat (or (widget-get widget :doc)
515 (concat "Change score based on the " tag
518 You can have an arbitrary number of score entries for this header,
519 each score entry has four elements:
521 1. The \"match element\". This should be the string to look for in the
524 2. The \"score element\". This number should be an integer in the
525 neginf to posinf interval. This number is added to the score
526 of the article if the match is successful. If this element is
527 not present, the `gnus-score-interactive-default-score' number
528 will be used instead. This is 1000 by default.
530 3. The \"date element\". This date says when the last time this score
531 entry matched, which provides a mechanism for expiring the
532 score entries. It this element is not present, the score
533 entry is permanent. The date is represented by the number of
534 days since December 31, 1 ce.
536 4. The \"type element\". This element specifies what function should
537 be used to see whether this score entry matches the article.
539 There are the regexp, as well as substring types, and exact match,
540 and word match types. If this element is not present, Gnus will
541 assume that substring matching should be used. There is case
542 sensitive variants of all match types.")))
543 (widget-put widget :args `(,item
548 :format "%t:\n%h%v%i\n\n"
550 :value ("" nil nil s)
555 (define-widget 'gnus-score-integer 'group
556 "Edit score entries for integer-valued headers."
557 :convert-widget 'gnus-score-integer-convert)
559 (defun gnus-score-integer-convert (widget)
560 ;; Set args appropriately.
561 (let* ((tag (widget-get widget :tag))
562 (item `(const :format "" :value ,(downcase tag)))
563 (match '(integer :tag "Match"))
564 (score '(choice :tag "Score"
565 (const :tag "default" nil)
566 (integer :format "%v"
567 :hide-front-space t)))
568 (expire '(choice :tag "Expire"
569 (const :tag "off" nil)
570 (integer :format "%v"
571 :hide-front-space t)))
572 (type '(choice :tag "Type"
579 (group `(group ,match ,score ,expire ,type))
580 (doc (concat (or (widget-get widget :doc)
581 (concat "Change score based on the " tag
583 (widget-put widget :args `(,item
588 :format "%t:\n%h%v%i\n\n"
592 (define-widget 'gnus-score-date 'group
593 "Edit score entries for date-valued headers."
594 :convert-widget 'gnus-score-date-convert)
596 (defun gnus-score-date-convert (widget)
597 ;; Set args appropriately.
598 (let* ((tag (widget-get widget :tag))
599 (item `(const :format "" :value ,(downcase tag)))
600 (match '(string :tag "Match"))
601 (score '(choice :tag "Score"
602 (const :tag "default" nil)
603 (integer :format "%v"
604 :hide-front-space t)))
605 (expire '(choice :tag "Expire"
606 (const :tag "off" nil)
607 (integer :format "%v"
608 :hide-front-space t)))
609 (type '(choice :tag "Type"
615 (group `(group ,match ,score ,expire ,type))
616 (doc (concat (or (widget-get widget :doc)
617 (concat "Change score based on the " tag
620 For the Date header we have three kinda silly match types: `before',
621 `at' and `after'. I can't really imagine this ever being useful, but,
622 like, it would feel kinda silly not to provide this function. Just in
623 case. You never know. Better safe than sorry. Once burnt, twice
624 shy. Don't judge a book by its cover. Never not have sex on a first
625 date. (I have been told that at least one person, and I quote,
626 \"found this function indispensable\", however.)
628 A more useful match type is `regexp'. With it, you can match the date
629 string using a regular expression. The date is normalized to ISO8601
630 compact format first---`YYYYMMDDTHHMMSS'. If you want to match all
631 articles that have been posted on April 1st in every year, you could
632 use `....0401.........' as a match string, for instance. (Note that
633 the date is kept in its original time zone, so this will match
634 articles that were posted when it was April 1st where the article was
635 posted from. Time zones are such wholesome fun for the whole family,
637 (widget-put widget :args `(,item
642 :format "%t:\n%h%v%i\n\n"
646 (defvar gnus-custom-scores)
647 (defvar gnus-custom-score-alist)
649 (defun gnus-score-customize (file)
650 "Customize score file FILE.
651 When called interactively, FILE defaults to the current score file.
652 This can be changed using the `\\[gnus-score-change-score-file]' command."
653 (interactive (list gnus-current-score-file))
655 (error (format "No score file for %s"
656 (gnus-group-decoded-name gnus-newsgroup-name))))
657 (let ((scores (gnus-score-load file))
658 (types (mapcar (lambda (entry)
659 `(group :format "%v%h\n"
661 (const :format "" ,(nth 0 entry))
663 gnus-score-parameters)))
665 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
666 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
668 (make-local-variable 'gnus-custom-score-alist)
669 (setq gnus-custom-score-alist scores)
670 (widget-insert "Customize the ")
671 (widget-create 'info-link
672 :help-echo "Push me to learn more."
674 "(gnus)Score File Format")
675 (widget-insert " for\n\t")
677 (widget-insert "\nand press ")
678 (widget-create 'push-button
680 :help-echo "Push me when done customizing."
681 :action 'gnus-score-customize-done)
683 Check the [ ] for the entries you want to apply to this score file, then
684 edit the value to suit your taste. Don't forget to mark the checkbox,
685 if you do all your changes will be lost. ")
686 (widget-create 'push-button
687 :action (lambda (&rest ignore)
688 (require 'gnus-audio)
689 (gnus-audio-play "Evil_Laugh.au"))
691 (widget-insert "\n\n")
692 (make-local-variable 'gnus-custom-scores)
693 (setq gnus-custom-scores
694 (widget-create 'group
696 `(checklist :inline t
698 (gnus-score-string :tag "From")
699 (gnus-score-string :tag "Subject")
700 (gnus-score-string :tag "References")
701 (gnus-score-string :tag "Xref")
702 (gnus-score-string :tag "Extra")
703 (gnus-score-string :tag "Message-ID")
704 (gnus-score-integer :tag "Lines")
705 (gnus-score-integer :tag "Chars")
706 (gnus-score-date :tag "Date")
707 (gnus-score-string :tag "Head"
709 Match all headers in the article.
711 Using one of `Head', `Body', `All' will slow down scoring considerable.
713 (gnus-score-string :tag "Body"
715 Match the body sans header of the article.
717 Using one of `Head', `Body', `All' will slow down scoring considerable.
719 (gnus-score-string :tag "All"
721 Match the entire article, including both headers and body.
723 Using one of `Head', `Body', `All' will slow down scoring
726 (gnus-score-string :tag
729 Score all followups to the specified authors.
731 This entry is somewhat special, in that it will match the `From:'
732 header, and affect the score of not only the matching articles, but
733 also all followups to the matching articles. This allows you
734 e.g. increase the score of followups to your own articles, or decrease
735 the score of followups to the articles of some known trouble-maker.
737 (gnus-score-string :tag "Thread"
739 Add a score entry on all articles that are part of a thread.
741 This match key works along the same lines as the `Followup' match key.
742 If you say that you want to score on a (sub-)thread that is started by
743 an article with a `Message-ID' X, then you add a `thread' match. This
744 will add a new `thread' match for each article that has X in its
745 `References' header. (These new `thread' matches will use the
746 `Message-ID's of these matching articles.) This will ensure that you
747 can raise/lower the score of an entire thread, even though some
748 articles in the thread may not have complete `References' headers.
749 Note that using this may lead to undeterministic scores of the
750 articles in the thread.
754 :tag "Unknown entries"
756 (use-local-map widget-keymap)
759 (defun gnus-score-customize-done (&rest ignore)
760 "Reset the score alist with the present value."
761 (let ((alist gnus-custom-score-alist)
762 (value (widget-value gnus-custom-scores)))
763 (setcar alist (car value))
764 (setcdr alist (cdr value))
765 (gnus-score-set 'touched '(t) alist))
772 ;;; gnus-cus.el ends here