1 ;;; gnus-cus.el --- customization commands for Gnus
3 ;; Copyright (C) 1996 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.
35 ;; There should be special validation for this.
36 (define-widget 'gnus-email-address 'string
39 (defun gnus-custom-mode ()
40 "Major mode for editing Gnus customization buffers.
42 The following commands are available:
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.
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))
57 ;;; Group Customization:
59 (defconst gnus-group-parameters
60 '((to-address (gnus-email-address :tag "To Address") "\
61 This will be used when doing followups and posts.
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.
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
76 (to-list (gnus-email-address :tag "To List") "\
77 This address will be used when doing a `a' in the group.
79 It is totally ignored when doing a followup--except that if it is
80 present in a news group, you'll get mail group semantics when doing
83 (broken-reply-to (const :tag "Broken Reply To" t) "\
84 Ignore `Reply-To' headers in this group.
86 That can be useful if you're reading a mailing list group where the
87 listserv has inserted `Reply-To' headers that point back to the
88 listserv itself. This is broken behavior. So there!")
90 (to-group (string :tag "To Group") "\
91 All posts will be send to the specified group.")
93 (gcc-self (choice :tag "GCC"
97 (string :format "%v" :hide-front-space t)) "\
98 Specify default value for GCC header.
100 If this symbol is present in the group parameter list and set to `t',
101 new composed messages will be `Gcc''d to the current group. If it is
102 present and set to `none', no `Gcc:' header will be generated, if it
103 is present and a string, this string will be inserted literally as a
104 `gcc' header (this symbol takes precedence over any default `Gcc'
105 rules as described later).")
107 (banner (choice :tag "Banner"
110 Banner to be removed from articles.")
112 (auto-expire (const :tag "Automatic Expire" t) "\
113 All articles that are read will be marked as expirable.")
115 (total-expire (const :tag "Total Expire" t) "\
116 All read articles will be put through the expiry process
118 This happens even if they are not marked as expirable.
121 (expiry-wait (choice :tag "Expire Wait"
125 (number :hide-front-space t
129 Overrides any `nnmail-expiry-wait' and `nnmail-expiry-wait-function'
130 when expiring expirable messages. The value can either be a number of
131 days (not necessarily an integer) or the symbols `never' or
134 (score-file (file :tag "Score File") "\
135 Make the specified file into the current score file.
136 This means that all score commands you issue will end up in this file.")
138 (adapt-file (file :tag "Adapt File") "\
139 Make the specified file into the current adaptive file.
140 All adaptive score entries will be put into this file.")
142 (admin-address (gnus-email-address :tag "Admin Address") "\
143 Administration address for a mailing list.
145 When unsubscribing to a mailing list you should never send the
146 unsubscription notice to the mailing list itself. Instead, you'd
147 send messages to the administrative address. This parameter allows
148 you to put the admin address somewhere convenient.")
150 (display (choice :tag "Display"
154 Which articles to display on entering the group.
157 Display all articles, both read and unread.
160 Display the default visible articles, which normally includes
161 unread and ticked articles.")
163 (comment (string :tag "Comment") "\
164 An arbitrary comment on the group.")
166 (visible (const :tag "Permanently visible" t) "\
167 Always display this group, even when there are no unread articles
170 (charset (symbol :tag "Charset") "\
171 The default charset to use in the group.")
174 (choice :tag "Highlight words"
176 (repeat (list (regexp :tag "Highlight regexp")
177 (number :tag "Group for entire word" 0)
178 (number :tag "Group for displayed part" 0)
180 gnus-emphasis-highlight-words))))
182 See gnus-emphasis-alist."))
183 "Alist of valid group parameters.
185 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
186 itself (a symbol), TYPE is the parameters type (a sexp widget), and
187 DOC is a documentation string for the parameter.")
189 (defvar gnus-custom-params)
190 (defvar gnus-custom-method)
191 (defvar gnus-custom-group)
192 (defvar gnus-custom-topic)
194 (defun gnus-group-customize (group &optional topic)
195 "Edit the group or topic on the current line."
196 (interactive (list (gnus-group-group-name) (gnus-group-topic-name)))
198 (types (mapcar (lambda (entry)
199 `(cons :format "%v%h\n"
201 (const :format "" ,(nth 0 entry))
203 gnus-group-parameters)))
204 (unless (or group topic)
205 (error "No group on current line"))
206 (when (and group topic)
207 (error "Both a group an topic on current line"))
208 (unless (or topic (setq info (gnus-get-info group)))
209 (error "Killed group; can't be edited"))
211 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
212 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
214 (make-local-variable 'gnus-custom-group)
215 (setq gnus-custom-group group)
216 (make-local-variable 'gnus-custom-topic)
217 (setq gnus-custom-topic topic)
218 (widget-insert "Customize the ")
220 (widget-create 'info-link
221 :help-echo "Push me to learn more."
222 :tag "group parameters"
223 "(gnus)Group Parameters")
224 (widget-create 'info-link
225 :help-echo "Push me to learn more."
226 :tag "topic parameters"
227 "(gnus)Topic Parameters"))
228 (widget-insert " for <")
229 (widget-insert (or group topic))
230 (widget-insert "> and press ")
231 (widget-create 'push-button
233 :help-echo "Push me when done customizing."
234 :action 'gnus-group-customize-done)
235 (widget-insert ".\n\n")
236 (make-local-variable 'gnus-custom-params)
237 (setq gnus-custom-params
238 (widget-create 'group
240 (gnus-info-params info)
241 (gnus-topic-parameters topic))
247 These special paramerters are recognized by Gnus.
248 Check the [ ] for the parameters you want to apply to this group or
249 to the groups in this topic, then edit the value to suit your taste."
253 :format "%t:\n%h%v%i\n\n"
255 Set variables local to the group you are entering.
257 If you want to turn threading off in `news.answers', you could put
258 `(gnus-show-threads nil)' in the group parameters of that group.
259 `gnus-show-threads' will be made into a local variable in the summary
260 buffer you enter, and the form `nil' will be `eval'ed there.
262 This can also be used as a group-specific hook function, if you'd
263 like. If you want to hear a beep when you enter a group, you could
264 put something like `(dummy-variable (ding))' in the parameters of that
265 group. `dummy-variable' will be set to the result of the `(ding)'
266 form, but who cares?"
267 (cons :format "%v" :value (nil . nil)
268 (symbol :tag "Variable")
273 :tag "Unknown entries"
276 (widget-insert "\n\nYou can also edit the ")
277 (widget-create 'info-link
279 :help-echo "Push me to learn more about select methods."
280 "(gnus)Select Methods")
281 (widget-insert " for the group.\n")
282 (setq gnus-custom-method
285 :value (gnus-info-method info))))
286 (use-local-map widget-keymap)
288 (goto-char (point-min))))
290 (defun gnus-group-customize-done (&rest ignore)
291 "Apply changes and bury the buffer."
293 (if gnus-custom-topic
294 (gnus-topic-set-parameters gnus-custom-topic
295 (widget-value gnus-custom-params))
296 (gnus-group-edit-group-done 'params gnus-custom-group
297 (widget-value gnus-custom-params))
298 (gnus-group-edit-group-done 'method gnus-custom-group
299 (widget-value gnus-custom-method)))
302 ;;; Score Customization:
304 (defconst gnus-score-parameters
305 '((mark (number :tag "Mark") "\
306 The value of this entry should be a number.
307 Any articles with a score lower than this number will be marked as read.")
309 (expunge (number :tag "Expunge") "\
310 The value of this entry should be a number.
311 Any articles with a score lower than this number will be removed from
312 the summary buffer.")
314 (mark-and-expunge (number :tag "Mark-and-expunge") "\
315 The value of this entry should be a number.
316 Any articles with a score lower than this number will be marked as
317 read and removed from the summary buffer.")
319 (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
320 The value of this entry should be a number.
321 All articles that belong to a thread that has a total score below this
322 number will be marked as read and removed from the summary buffer.
323 `gnus-thread-score-function' says how to compute the total score
326 (files (repeat :inline t :tag "Files" file) "\
327 The value of this entry should be any number of file names.
328 These files are assumed to be score files as well, and will be loaded
329 the same way this one was.")
331 (exclude-files (repeat :inline t :tag "Exclude-files" file) "\
332 The clue of this entry should be any number of files.
333 These files will not be loaded, even though they would normally be so,
334 for some reason or other.")
336 (eval (sexp :tag "Eval" :value nil) "\
337 The value of this entry will be `eval'el.
338 This element will be ignored when handling global score files.")
340 (read-only (boolean :tag "Read-only" :value t) "\
341 Read-only score files will not be updated or saved.
342 Global score files should feature this atom.")
344 (orphan (number :tag "Orphan") "\
345 The value of this entry should be a number.
346 Articles that do not have parents will get this number added to their
347 scores. Imagine you follow some high-volume newsgroup, like
348 `comp.lang.c'. Most likely you will only follow a few of the threads,
349 also want to see any new threads.
351 You can do this with the following two score file entries:
354 (mark-and-expunge -100)
356 When you enter the group the first time, you will only see the new
357 threads. You then raise the score of the threads that you find
358 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
359 Next time you enter the group, you will see new articles in the
360 interesting threads, plus any new threads.
362 I.e.---the orphan score atom is for high-volume groups where there
363 exist a few interesting threads which can't be found automatically
364 by ordinary scoring rules.")
366 (adapt (choice :tag "Adapt"
370 :hide-front-space t)) "\
371 This entry controls the adaptive scoring.
372 If it is `t', the default adaptive scoring rules will be used. If it
373 is `ignore', no adaptive scoring will be performed on this group. If
374 it is a list, this list will be used as the adaptive scoring rules.
375 If it isn't present, or is something other than `t' or `ignore', the
376 default adaptive scoring rules will be used. If you want to use
377 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
378 to `t', and insert an `(adapt ignore)' in the groups where you do not
379 want adaptive scoring. If you only want adaptive scoring in a few
380 groups, you'd set `gnus-use-adaptive-scoring' to `nil', and insert
381 `(adapt t)' in the score files of the groups where you want it.")
383 (adapt-file (file :tag "Adapt-file") "\
384 All adaptive score entries will go to the file named by this entry.
385 It will also be applied when entering the group. This atom might
386 be handy if you want to adapt on several groups at once, using the
387 same adaptive file for a number of groups.")
389 (local (repeat :tag "Local"
390 (group :value (nil nil)
391 (symbol :tag "Variable")
392 (sexp :tag "Value"))) "\
393 The value of this entry should be a list of `(VAR VALUE)' pairs.
394 Each VAR will be made buffer-local to the current summary buffer,
395 and set to the value specified. This is a convenient, if somewhat
396 strange, way of setting variables in some groups if you don't like
398 (touched (sexp :format "Touched\n") "Internal variable."))
399 "Alist of valid symbolic score parameters.
401 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
402 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
403 documentation string for the parameter.")
405 (define-widget 'gnus-score-string 'group
406 "Edit score entries for string-valued headers."
407 :convert-widget 'gnus-score-string-convert)
409 (defun gnus-score-string-convert (widget)
410 ;; Set args appropriately.
411 (let* ((tag (widget-get widget :tag))
412 (item `(const :format "" :value ,(downcase tag)))
413 (match '(string :tag "Match"))
414 (score '(choice :tag "Score"
415 (const :tag "default" nil)
416 (integer :format "%v"
417 :hide-front-space t)))
418 (expire '(choice :tag "Expire"
419 (const :tag "off" nil)
420 (integer :format "%v"
421 :hide-front-space t)))
422 (type '(choice :tag "Type"
424 ;; I should really create a forgiving :match
425 ;; function for each type below, that only
426 ;; looked at the first letter.
427 (const :tag "Regexp" r)
428 (const :tag "Regexp (fixed case)" R)
429 (const :tag "Substring" s)
430 (const :tag "Substring (fixed case)" S)
431 (const :tag "Exact" e)
432 (const :tag "Exact (fixed case)" E)
433 (const :tag "Word" w)
434 (const :tag "Word (fixed case)" W)
435 (const :tag "default" nil)))
436 (group `(group ,match ,score ,expire ,type))
437 (doc (concat (or (widget-get widget :doc)
438 (concat "Change score based on the " tag
441 You can have an arbitrary number of score entries for this header,
442 each score entry has four elements:
444 1. The \"match element\". This should be the string to look for in the
447 2. The \"score element\". This number should be an integer in the
448 neginf to posinf interval. This number is added to the score
449 of the article if the match is successful. If this element is
450 not present, the `gnus-score-interactive-default-score' number
451 will be used instead. This is 1000 by default.
453 3. The \"date element\". This date says when the last time this score
454 entry matched, which provides a mechanism for expiring the
455 score entries. It this element is not present, the score
456 entry is permanent. The date is represented by the number of
457 days since December 31, 1 ce.
459 4. The \"type element\". This element specifies what function should
460 be used to see whether this score entry matches the article.
462 There are the regexp, as well as substring types, and exact match,
463 and word match types. If this element is not present, Gnus will
464 assume that substring matching should be used. There is case
465 sensitive variants of all match types.")))
466 (widget-put widget :args `(,item
471 :format "%t:\n%h%v%i\n\n"
473 :value ("" nil nil s)
478 (define-widget 'gnus-score-integer 'group
479 "Edit score entries for integer-valued headers."
480 :convert-widget 'gnus-score-integer-convert)
482 (defun gnus-score-integer-convert (widget)
483 ;; Set args appropriately.
484 (let* ((tag (widget-get widget :tag))
485 (item `(const :format "" :value ,(downcase tag)))
486 (match '(integer :tag "Match"))
487 (score '(choice :tag "Score"
488 (const :tag "default" nil)
489 (integer :format "%v"
490 :hide-front-space t)))
491 (expire '(choice :tag "Expire"
492 (const :tag "off" nil)
493 (integer :format "%v"
494 :hide-front-space t)))
495 (type '(choice :tag "Type"
502 (group `(group ,match ,score ,expire ,type))
503 (doc (concat (or (widget-get widget :doc)
504 (concat "Change score based on the " tag
506 (widget-put widget :args `(,item
511 :format "%t:\n%h%v%i\n\n"
515 (define-widget 'gnus-score-date 'group
516 "Edit score entries for date-valued headers."
517 :convert-widget 'gnus-score-date-convert)
519 (defun gnus-score-date-convert (widget)
520 ;; Set args appropriately.
521 (let* ((tag (widget-get widget :tag))
522 (item `(const :format "" :value ,(downcase tag)))
523 (match '(string :tag "Match"))
524 (score '(choice :tag "Score"
525 (const :tag "default" nil)
526 (integer :format "%v"
527 :hide-front-space t)))
528 (expire '(choice :tag "Expire"
529 (const :tag "off" nil)
530 (integer :format "%v"
531 :hide-front-space t)))
532 (type '(choice :tag "Type"
538 (group `(group ,match ,score ,expire ,type))
539 (doc (concat (or (widget-get widget :doc)
540 (concat "Change score based on the " tag
543 For the Date header we have three kinda silly match types: `before',
544 `at' and `after'. I can't really imagine this ever being useful, but,
545 like, it would feel kinda silly not to provide this function. Just in
546 case. You never know. Better safe than sorry. Once burnt, twice
547 shy. Don't judge a book by its cover. Never not have sex on a first
548 date. (I have been told that at least one person, and I quote,
549 \"found this function indispensable\", however.)
551 A more useful match type is `regexp'. With it, you can match the date
552 string using a regular expression. The date is normalized to ISO8601
553 compact format first---`YYYYMMDDTHHMMSS'. If you want to match all
554 articles that have been posted on April 1st in every year, you could
555 use `....0401.........' as a match string, for instance. (Note that
556 the date is kept in its original time zone, so this will match
557 articles that were posted when it was April 1st where the article was
558 posted from. Time zones are such wholesome fun for the whole family,
560 (widget-put widget :args `(,item
565 :format "%t:\n%h%v%i\n\n"
569 (defvar gnus-custom-scores)
570 (defvar gnus-custom-score-alist)
572 (defun gnus-score-customize (file)
573 "Customize score file FILE."
574 (interactive (list gnus-current-score-file))
575 (let ((scores (gnus-score-load file))
576 (types (mapcar (lambda (entry)
577 `(group :format "%v%h\n"
579 (const :format "" ,(nth 0 entry))
581 gnus-score-parameters)))
583 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
584 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
586 (make-local-variable 'gnus-custom-score-alist)
587 (setq gnus-custom-score-alist scores)
588 (widget-insert "Customize the ")
589 (widget-create 'info-link
590 :help-echo "Push me to learn more."
592 "(gnus)Score File Format")
593 (widget-insert " for\n\t")
595 (widget-insert "\nand press ")
596 (widget-create 'push-button
598 :help-echo "Push me when done customizing."
599 :action 'gnus-score-customize-done)
601 Check the [ ] for the entries you want to apply to this score file, then
602 edit the value to suit your taste. Don't forget to mark the checkbox,
603 if you do all your changes will be lost. ")
604 (widget-create 'push-button
605 :action (lambda (&rest ignore)
606 (require 'gnus-audio)
607 (gnus-audio-play "Evil_Laugh.au"))
609 (widget-insert "\n\n")
610 (make-local-variable 'gnus-custom-scores)
611 (setq gnus-custom-scores
612 (widget-create 'group
614 `(checklist :inline t
616 (gnus-score-string :tag "From")
617 (gnus-score-string :tag "Subject")
618 (gnus-score-string :tag "References")
619 (gnus-score-string :tag "Xref")
620 (gnus-score-string :tag "Extra")
621 (gnus-score-string :tag "Message-ID")
622 (gnus-score-integer :tag "Lines")
623 (gnus-score-integer :tag "Chars")
624 (gnus-score-date :tag "Date")
625 (gnus-score-string :tag "Head"
627 Match all headers in the article.
629 Using one of `Head', `Body', `All' will slow down scoring considerable.
631 (gnus-score-string :tag "Body"
633 Match the body sans header of the article.
635 Using one of `Head', `Body', `All' will slow down scoring considerable.
637 (gnus-score-string :tag "All"
639 Match the entire article, including both headers and body.
641 Using one of `Head', `Body', `All' will slow down scoring
644 (gnus-score-string :tag
647 Score all followups to the specified authors.
649 This entry is somewhat special, in that it will match the `From:'
650 header, and affect the score of not only the matching articles, but
651 also all followups to the matching articles. This allows you
652 e.g. increase the score of followups to your own articles, or decrease
653 the score of followups to the articles of some known trouble-maker.
655 (gnus-score-string :tag "Thread"
657 Add a score entry on all articles that are part of a thread.
659 This match key works along the same lines as the `Followup' match key.
660 If you say that you want to score on a (sub-)thread that is started by
661 an article with a `Message-ID' X, then you add a `thread' match. This
662 will add a new `thread' match for each article that has X in its
663 `References' header. (These new `thread' matches will use the
664 `Message-ID's of these matching articles.) This will ensure that you
665 can raise/lower the score of an entire thread, even though some
666 articles in the thread may not have complete `References' headers.
667 Note that using this may lead to undeterministic scores of the
668 articles in the thread.
672 :tag "Unknown entries"
674 (use-local-map widget-keymap)
677 (defun gnus-score-customize-done (&rest ignore)
678 "Reset the score alist with the present value."
679 (let ((alist gnus-custom-score-alist)
680 (value (widget-value gnus-custom-scores)))
681 (setcar alist (car value))
682 (setcdr alist (cdr value))
683 (gnus-score-set 'touched '(t) alist))
690 ;;; gnus-cus.el ends here