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 "Ignored charsets"
176 (repeat (symbol))) "\
177 List of charsets that should be ignored.
179 When these charsets are used in the \"charset\" parameter, the
180 default charset will be used instead.")
183 (choice :tag "Highlight words"
185 (repeat (list (regexp :tag "Highlight regexp")
186 (number :tag "Group for entire word" 0)
187 (number :tag "Group for displayed part" 0)
189 gnus-emphasis-highlight-words))))
191 See gnus-emphasis-alist."))
192 "Alist of valid group parameters.
194 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
195 itself (a symbol), TYPE is the parameters type (a sexp widget), and
196 DOC is a documentation string for the parameter.")
198 (defvar gnus-custom-params)
199 (defvar gnus-custom-method)
200 (defvar gnus-custom-group)
201 (defvar gnus-custom-topic)
203 (defun gnus-group-customize (group &optional topic)
204 "Edit the group or topic on the current line."
205 (interactive (list (gnus-group-group-name) (gnus-group-topic-name)))
207 (types (mapcar (lambda (entry)
208 `(cons :format "%v%h\n"
210 (const :format "" ,(nth 0 entry))
212 gnus-group-parameters)))
213 (unless (or group topic)
214 (error "No group on current line"))
215 (when (and group topic)
216 (error "Both a group an topic on current line"))
217 (unless (or topic (setq info (gnus-get-info group)))
218 (error "Killed group; can't be edited"))
220 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
221 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
223 (make-local-variable 'gnus-custom-group)
224 (setq gnus-custom-group group)
225 (make-local-variable 'gnus-custom-topic)
226 (setq gnus-custom-topic topic)
227 (widget-insert "Customize the ")
229 (widget-create 'info-link
230 :help-echo "Push me to learn more."
231 :tag "group parameters"
232 "(gnus)Group Parameters")
233 (widget-create 'info-link
234 :help-echo "Push me to learn more."
235 :tag "topic parameters"
236 "(gnus)Topic Parameters"))
237 (widget-insert " for <")
238 (widget-insert (or group topic))
239 (widget-insert "> and press ")
240 (widget-create 'push-button
242 :help-echo "Push me when done customizing."
243 :action 'gnus-group-customize-done)
244 (widget-insert ".\n\n")
245 (make-local-variable 'gnus-custom-params)
246 (setq gnus-custom-params
247 (widget-create 'group
249 (gnus-info-params info)
250 (gnus-topic-parameters topic))
256 These special paramerters are recognized by Gnus.
257 Check the [ ] for the parameters you want to apply to this group or
258 to the groups in this topic, then edit the value to suit your taste."
262 :format "%t:\n%h%v%i\n\n"
264 Set variables local to the group you are entering.
266 If you want to turn threading off in `news.answers', you could put
267 `(gnus-show-threads nil)' in the group parameters of that group.
268 `gnus-show-threads' will be made into a local variable in the summary
269 buffer you enter, and the form `nil' will be `eval'ed there.
271 This can also be used as a group-specific hook function, if you'd
272 like. If you want to hear a beep when you enter a group, you could
273 put something like `(dummy-variable (ding))' in the parameters of that
274 group. `dummy-variable' will be set to the result of the `(ding)'
275 form, but who cares?"
276 (cons :format "%v" :value (nil . nil)
277 (symbol :tag "Variable")
282 :tag "Unknown entries"
285 (widget-insert "\n\nYou can also edit the ")
286 (widget-create 'info-link
288 :help-echo "Push me to learn more about select methods."
289 "(gnus)Select Methods")
290 (widget-insert " for the group.\n")
291 (setq gnus-custom-method
294 :value (gnus-info-method info))))
295 (use-local-map widget-keymap)
297 (goto-char (point-min))))
299 (defun gnus-group-customize-done (&rest ignore)
300 "Apply changes and bury the buffer."
302 (if gnus-custom-topic
303 (gnus-topic-set-parameters gnus-custom-topic
304 (widget-value gnus-custom-params))
305 (gnus-group-edit-group-done 'params gnus-custom-group
306 (widget-value gnus-custom-params))
307 (gnus-group-edit-group-done 'method gnus-custom-group
308 (widget-value gnus-custom-method)))
311 ;;; Score Customization:
313 (defconst gnus-score-parameters
314 '((mark (number :tag "Mark") "\
315 The value of this entry should be a number.
316 Any articles with a score lower than this number will be marked as read.")
318 (expunge (number :tag "Expunge") "\
319 The value of this entry should be a number.
320 Any articles with a score lower than this number will be removed from
321 the summary buffer.")
323 (mark-and-expunge (number :tag "Mark-and-expunge") "\
324 The value of this entry should be a number.
325 Any articles with a score lower than this number will be marked as
326 read and removed from the summary buffer.")
328 (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
329 The value of this entry should be a number.
330 All articles that belong to a thread that has a total score below this
331 number will be marked as read and removed from the summary buffer.
332 `gnus-thread-score-function' says how to compute the total score
335 (files (repeat :inline t :tag "Files" file) "\
336 The value of this entry should be any number of file names.
337 These files are assumed to be score files as well, and will be loaded
338 the same way this one was.")
340 (exclude-files (repeat :inline t :tag "Exclude-files" file) "\
341 The clue of this entry should be any number of files.
342 These files will not be loaded, even though they would normally be so,
343 for some reason or other.")
345 (eval (sexp :tag "Eval" :value nil) "\
346 The value of this entry will be `eval'el.
347 This element will be ignored when handling global score files.")
349 (read-only (boolean :tag "Read-only" :value t) "\
350 Read-only score files will not be updated or saved.
351 Global score files should feature this atom.")
353 (orphan (number :tag "Orphan") "\
354 The value of this entry should be a number.
355 Articles that do not have parents will get this number added to their
356 scores. Imagine you follow some high-volume newsgroup, like
357 `comp.lang.c'. Most likely you will only follow a few of the threads,
358 also want to see any new threads.
360 You can do this with the following two score file entries:
363 (mark-and-expunge -100)
365 When you enter the group the first time, you will only see the new
366 threads. You then raise the score of the threads that you find
367 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
368 Next time you enter the group, you will see new articles in the
369 interesting threads, plus any new threads.
371 I.e.---the orphan score atom is for high-volume groups where there
372 exist a few interesting threads which can't be found automatically
373 by ordinary scoring rules.")
375 (adapt (choice :tag "Adapt"
379 :hide-front-space t)) "\
380 This entry controls the adaptive scoring.
381 If it is `t', the default adaptive scoring rules will be used. If it
382 is `ignore', no adaptive scoring will be performed on this group. If
383 it is a list, this list will be used as the adaptive scoring rules.
384 If it isn't present, or is something other than `t' or `ignore', the
385 default adaptive scoring rules will be used. If you want to use
386 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
387 to `t', and insert an `(adapt ignore)' in the groups where you do not
388 want adaptive scoring. If you only want adaptive scoring in a few
389 groups, you'd set `gnus-use-adaptive-scoring' to `nil', and insert
390 `(adapt t)' in the score files of the groups where you want it.")
392 (adapt-file (file :tag "Adapt-file") "\
393 All adaptive score entries will go to the file named by this entry.
394 It will also be applied when entering the group. This atom might
395 be handy if you want to adapt on several groups at once, using the
396 same adaptive file for a number of groups.")
398 (local (repeat :tag "Local"
399 (group :value (nil nil)
400 (symbol :tag "Variable")
401 (sexp :tag "Value"))) "\
402 The value of this entry should be a list of `(VAR VALUE)' pairs.
403 Each VAR will be made buffer-local to the current summary buffer,
404 and set to the value specified. This is a convenient, if somewhat
405 strange, way of setting variables in some groups if you don't like
407 (touched (sexp :format "Touched\n") "Internal variable."))
408 "Alist of valid symbolic score parameters.
410 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
411 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
412 documentation string for the parameter.")
414 (define-widget 'gnus-score-string 'group
415 "Edit score entries for string-valued headers."
416 :convert-widget 'gnus-score-string-convert)
418 (defun gnus-score-string-convert (widget)
419 ;; Set args appropriately.
420 (let* ((tag (widget-get widget :tag))
421 (item `(const :format "" :value ,(downcase tag)))
422 (match '(string :tag "Match"))
423 (score '(choice :tag "Score"
424 (const :tag "default" nil)
425 (integer :format "%v"
426 :hide-front-space t)))
427 (expire '(choice :tag "Expire"
428 (const :tag "off" nil)
429 (integer :format "%v"
430 :hide-front-space t)))
431 (type '(choice :tag "Type"
433 ;; I should really create a forgiving :match
434 ;; function for each type below, that only
435 ;; looked at the first letter.
436 (const :tag "Regexp" r)
437 (const :tag "Regexp (fixed case)" R)
438 (const :tag "Substring" s)
439 (const :tag "Substring (fixed case)" S)
440 (const :tag "Exact" e)
441 (const :tag "Exact (fixed case)" E)
442 (const :tag "Word" w)
443 (const :tag "Word (fixed case)" W)
444 (const :tag "default" nil)))
445 (group `(group ,match ,score ,expire ,type))
446 (doc (concat (or (widget-get widget :doc)
447 (concat "Change score based on the " tag
450 You can have an arbitrary number of score entries for this header,
451 each score entry has four elements:
453 1. The \"match element\". This should be the string to look for in the
456 2. The \"score element\". This number should be an integer in the
457 neginf to posinf interval. This number is added to the score
458 of the article if the match is successful. If this element is
459 not present, the `gnus-score-interactive-default-score' number
460 will be used instead. This is 1000 by default.
462 3. The \"date element\". This date says when the last time this score
463 entry matched, which provides a mechanism for expiring the
464 score entries. It this element is not present, the score
465 entry is permanent. The date is represented by the number of
466 days since December 31, 1 ce.
468 4. The \"type element\". This element specifies what function should
469 be used to see whether this score entry matches the article.
471 There are the regexp, as well as substring types, and exact match,
472 and word match types. If this element is not present, Gnus will
473 assume that substring matching should be used. There is case
474 sensitive variants of all match types.")))
475 (widget-put widget :args `(,item
480 :format "%t:\n%h%v%i\n\n"
482 :value ("" nil nil s)
487 (define-widget 'gnus-score-integer 'group
488 "Edit score entries for integer-valued headers."
489 :convert-widget 'gnus-score-integer-convert)
491 (defun gnus-score-integer-convert (widget)
492 ;; Set args appropriately.
493 (let* ((tag (widget-get widget :tag))
494 (item `(const :format "" :value ,(downcase tag)))
495 (match '(integer :tag "Match"))
496 (score '(choice :tag "Score"
497 (const :tag "default" nil)
498 (integer :format "%v"
499 :hide-front-space t)))
500 (expire '(choice :tag "Expire"
501 (const :tag "off" nil)
502 (integer :format "%v"
503 :hide-front-space t)))
504 (type '(choice :tag "Type"
511 (group `(group ,match ,score ,expire ,type))
512 (doc (concat (or (widget-get widget :doc)
513 (concat "Change score based on the " tag
515 (widget-put widget :args `(,item
520 :format "%t:\n%h%v%i\n\n"
524 (define-widget 'gnus-score-date 'group
525 "Edit score entries for date-valued headers."
526 :convert-widget 'gnus-score-date-convert)
528 (defun gnus-score-date-convert (widget)
529 ;; Set args appropriately.
530 (let* ((tag (widget-get widget :tag))
531 (item `(const :format "" :value ,(downcase tag)))
532 (match '(string :tag "Match"))
533 (score '(choice :tag "Score"
534 (const :tag "default" nil)
535 (integer :format "%v"
536 :hide-front-space t)))
537 (expire '(choice :tag "Expire"
538 (const :tag "off" nil)
539 (integer :format "%v"
540 :hide-front-space t)))
541 (type '(choice :tag "Type"
547 (group `(group ,match ,score ,expire ,type))
548 (doc (concat (or (widget-get widget :doc)
549 (concat "Change score based on the " tag
552 For the Date header we have three kinda silly match types: `before',
553 `at' and `after'. I can't really imagine this ever being useful, but,
554 like, it would feel kinda silly not to provide this function. Just in
555 case. You never know. Better safe than sorry. Once burnt, twice
556 shy. Don't judge a book by its cover. Never not have sex on a first
557 date. (I have been told that at least one person, and I quote,
558 \"found this function indispensable\", however.)
560 A more useful match type is `regexp'. With it, you can match the date
561 string using a regular expression. The date is normalized to ISO8601
562 compact format first---`YYYYMMDDTHHMMSS'. If you want to match all
563 articles that have been posted on April 1st in every year, you could
564 use `....0401.........' as a match string, for instance. (Note that
565 the date is kept in its original time zone, so this will match
566 articles that were posted when it was April 1st where the article was
567 posted from. Time zones are such wholesome fun for the whole family,
569 (widget-put widget :args `(,item
574 :format "%t:\n%h%v%i\n\n"
578 (defvar gnus-custom-scores)
579 (defvar gnus-custom-score-alist)
581 (defun gnus-score-customize (file)
582 "Customize score file FILE."
583 (interactive (list gnus-current-score-file))
584 (let ((scores (gnus-score-load file))
585 (types (mapcar (lambda (entry)
586 `(group :format "%v%h\n"
588 (const :format "" ,(nth 0 entry))
590 gnus-score-parameters)))
592 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
593 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
595 (make-local-variable 'gnus-custom-score-alist)
596 (setq gnus-custom-score-alist scores)
597 (widget-insert "Customize the ")
598 (widget-create 'info-link
599 :help-echo "Push me to learn more."
601 "(gnus)Score File Format")
602 (widget-insert " for\n\t")
604 (widget-insert "\nand press ")
605 (widget-create 'push-button
607 :help-echo "Push me when done customizing."
608 :action 'gnus-score-customize-done)
610 Check the [ ] for the entries you want to apply to this score file, then
611 edit the value to suit your taste. Don't forget to mark the checkbox,
612 if you do all your changes will be lost. ")
613 (widget-create 'push-button
614 :action (lambda (&rest ignore)
615 (require 'gnus-audio)
616 (gnus-audio-play "Evil_Laugh.au"))
618 (widget-insert "\n\n")
619 (make-local-variable 'gnus-custom-scores)
620 (setq gnus-custom-scores
621 (widget-create 'group
623 `(checklist :inline t
625 (gnus-score-string :tag "From")
626 (gnus-score-string :tag "Subject")
627 (gnus-score-string :tag "References")
628 (gnus-score-string :tag "Xref")
629 (gnus-score-string :tag "Extra")
630 (gnus-score-string :tag "Message-ID")
631 (gnus-score-integer :tag "Lines")
632 (gnus-score-integer :tag "Chars")
633 (gnus-score-date :tag "Date")
634 (gnus-score-string :tag "Head"
636 Match all headers in the article.
638 Using one of `Head', `Body', `All' will slow down scoring considerable.
640 (gnus-score-string :tag "Body"
642 Match the body sans header of the article.
644 Using one of `Head', `Body', `All' will slow down scoring considerable.
646 (gnus-score-string :tag "All"
648 Match the entire article, including both headers and body.
650 Using one of `Head', `Body', `All' will slow down scoring
653 (gnus-score-string :tag
656 Score all followups to the specified authors.
658 This entry is somewhat special, in that it will match the `From:'
659 header, and affect the score of not only the matching articles, but
660 also all followups to the matching articles. This allows you
661 e.g. increase the score of followups to your own articles, or decrease
662 the score of followups to the articles of some known trouble-maker.
664 (gnus-score-string :tag "Thread"
666 Add a score entry on all articles that are part of a thread.
668 This match key works along the same lines as the `Followup' match key.
669 If you say that you want to score on a (sub-)thread that is started by
670 an article with a `Message-ID' X, then you add a `thread' match. This
671 will add a new `thread' match for each article that has X in its
672 `References' header. (These new `thread' matches will use the
673 `Message-ID's of these matching articles.) This will ensure that you
674 can raise/lower the score of an entire thread, even though some
675 articles in the thread may not have complete `References' headers.
676 Note that using this may lead to undeterministic scores of the
677 articles in the thread.
681 :tag "Unknown entries"
683 (use-local-map widget-keymap)
686 (defun gnus-score-customize-done (&rest ignore)
687 "Reset the score alist with the present value."
688 (let ((alist gnus-custom-score-alist)
689 (value (widget-value gnus-custom-scores)))
690 (setcar alist (car value))
691 (setcdr alist (cdr value))
692 (gnus-score-set 'touched '(t) alist))
699 ;;; gnus-cus.el ends here