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."))
172 "Alist of valid group parameters.
174 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
175 itself (a symbol), TYPE is the parameters type (a sexp widget), and
176 DOC is a documentation string for the parameter.")
178 (defvar gnus-custom-params)
179 (defvar gnus-custom-method)
180 (defvar gnus-custom-group)
181 (defvar gnus-custom-topic)
183 (defun gnus-group-customize (group &optional topic)
184 "Edit the group or topic on the current line."
185 (interactive (list (gnus-group-group-name) (gnus-group-topic-name)))
187 (types (mapcar (lambda (entry)
188 `(cons :format "%v%h\n"
190 (const :format "" ,(nth 0 entry))
192 gnus-group-parameters)))
193 (unless (or group topic)
194 (error "No group on current line"))
195 (when (and group topic)
196 (error "Both a group an topic on current line"))
197 (unless (or topic (setq info (gnus-get-info group)))
198 (error "Killed group; can't be edited"))
200 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
201 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
203 (make-local-variable 'gnus-custom-group)
204 (setq gnus-custom-group group)
205 (make-local-variable 'gnus-custom-topic)
206 (setq gnus-custom-topic topic)
207 (widget-insert "Customize the ")
209 (widget-create 'info-link
210 :help-echo "Push me to learn more."
211 :tag "group parameters"
212 "(gnus)Group Parameters")
213 (widget-create 'info-link
214 :help-echo "Push me to learn more."
215 :tag "topic parameters"
216 "(gnus)Topic Parameters"))
217 (widget-insert " for <")
218 (widget-insert (or group topic))
219 (widget-insert "> and press ")
220 (widget-create 'push-button
222 :help-echo "Push me when done customizing."
223 :action 'gnus-group-customize-done)
224 (widget-insert ".\n\n")
225 (make-local-variable 'gnus-custom-params)
226 (setq gnus-custom-params
227 (widget-create 'group
229 (gnus-info-params info)
230 (gnus-topic-parameters topic))
236 These special paramerters are recognized by Gnus.
237 Check the [ ] for the parameters you want to apply to this group or
238 to the groups in this topic, then edit the value to suit your taste."
242 :format "%t:\n%h%v%i\n\n"
244 Set variables local to the group you are entering.
246 If you want to turn threading off in `news.answers', you could put
247 `(gnus-show-threads nil)' in the group parameters of that group.
248 `gnus-show-threads' will be made into a local variable in the summary
249 buffer you enter, and the form `nil' will be `eval'ed there.
251 This can also be used as a group-specific hook function, if you'd
252 like. If you want to hear a beep when you enter a group, you could
253 put something like `(dummy-variable (ding))' in the parameters of that
254 group. `dummy-variable' will be set to the result of the `(ding)'
255 form, but who cares?"
256 (cons :format "%v" :value (nil . nil)
257 (symbol :tag "Variable")
262 :tag "Unknown entries"
265 (widget-insert "\n\nYou can also edit the ")
266 (widget-create 'info-link
268 :help-echo "Push me to learn more about select methods."
269 "(gnus)Select Methods")
270 (widget-insert " for the group.\n")
271 (setq gnus-custom-method
274 :value (gnus-info-method info))))
275 (use-local-map widget-keymap)
277 (goto-char (point-min))))
279 (defun gnus-group-customize-done (&rest ignore)
280 "Apply changes and bury the buffer."
282 (if gnus-custom-topic
283 (gnus-topic-set-parameters gnus-custom-topic
284 (widget-value gnus-custom-params))
285 (gnus-group-edit-group-done 'params gnus-custom-group
286 (widget-value gnus-custom-params))
287 (gnus-group-edit-group-done 'method gnus-custom-group
288 (widget-value gnus-custom-method)))
291 ;;; Score Customization:
293 (defconst gnus-score-parameters
294 '((mark (number :tag "Mark") "\
295 The value of this entry should be a number.
296 Any articles with a score lower than this number will be marked as read.")
298 (expunge (number :tag "Expunge") "\
299 The value of this entry should be a number.
300 Any articles with a score lower than this number will be removed from
301 the summary buffer.")
303 (mark-and-expunge (number :tag "Mark-and-expunge") "\
304 The value of this entry should be a number.
305 Any articles with a score lower than this number will be marked as
306 read and removed from the summary buffer.")
308 (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
309 The value of this entry should be a number.
310 All articles that belong to a thread that has a total score below this
311 number will be marked as read and removed from the summary buffer.
312 `gnus-thread-score-function' says how to compute the total score
315 (files (repeat :inline t :tag "Files" file) "\
316 The value of this entry should be any number of file names.
317 These files are assumed to be score files as well, and will be loaded
318 the same way this one was.")
320 (exclude-files (repeat :inline t :tag "Exclude-files" file) "\
321 The clue of this entry should be any number of files.
322 These files will not be loaded, even though they would normally be so,
323 for some reason or other.")
325 (eval (sexp :tag "Eval" :value nil) "\
326 The value of this entry will be `eval'el.
327 This element will be ignored when handling global score files.")
329 (read-only (boolean :tag "Read-only" :value t) "\
330 Read-only score files will not be updated or saved.
331 Global score files should feature this atom.")
333 (orphan (number :tag "Orphan") "\
334 The value of this entry should be a number.
335 Articles that do not have parents will get this number added to their
336 scores. Imagine you follow some high-volume newsgroup, like
337 `comp.lang.c'. Most likely you will only follow a few of the threads,
338 also want to see any new threads.
340 You can do this with the following two score file entries:
343 (mark-and-expunge -100)
345 When you enter the group the first time, you will only see the new
346 threads. You then raise the score of the threads that you find
347 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
348 Next time you enter the group, you will see new articles in the
349 interesting threads, plus any new threads.
351 I.e.---the orphan score atom is for high-volume groups where there
352 exist a few interesting threads which can't be found automatically
353 by ordinary scoring rules.")
355 (adapt (choice :tag "Adapt"
359 :hide-front-space t)) "\
360 This entry controls the adaptive scoring.
361 If it is `t', the default adaptive scoring rules will be used. If it
362 is `ignore', no adaptive scoring will be performed on this group. If
363 it is a list, this list will be used as the adaptive scoring rules.
364 If it isn't present, or is something other than `t' or `ignore', the
365 default adaptive scoring rules will be used. If you want to use
366 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
367 to `t', and insert an `(adapt ignore)' in the groups where you do not
368 want adaptive scoring. If you only want adaptive scoring in a few
369 groups, you'd set `gnus-use-adaptive-scoring' to `nil', and insert
370 `(adapt t)' in the score files of the groups where you want it.")
372 (adapt-file (file :tag "Adapt-file") "\
373 All adaptive score entries will go to the file named by this entry.
374 It will also be applied when entering the group. This atom might
375 be handy if you want to adapt on several groups at once, using the
376 same adaptive file for a number of groups.")
378 (local (repeat :tag "Local"
379 (group :value (nil nil)
380 (symbol :tag "Variable")
381 (sexp :tag "Value"))) "\
382 The value of this entry should be a list of `(VAR VALUE)' pairs.
383 Each VAR will be made buffer-local to the current summary buffer,
384 and set to the value specified. This is a convenient, if somewhat
385 strange, way of setting variables in some groups if you don't like
387 (touched (sexp :format "Touched\n") "Internal variable."))
388 "Alist of valid symbolic score parameters.
390 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
391 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
392 documentation string for the parameter.")
394 (define-widget 'gnus-score-string 'group
395 "Edit score entries for string-valued headers."
396 :convert-widget 'gnus-score-string-convert)
398 (defun gnus-score-string-convert (widget)
399 ;; Set args appropriately.
400 (let* ((tag (widget-get widget :tag))
401 (item `(const :format "" :value ,(downcase tag)))
402 (match '(string :tag "Match"))
403 (score '(choice :tag "Score"
404 (const :tag "default" nil)
405 (integer :format "%v"
406 :hide-front-space t)))
407 (expire '(choice :tag "Expire"
408 (const :tag "off" nil)
409 (integer :format "%v"
410 :hide-front-space t)))
411 (type '(choice :tag "Type"
413 ;; I should really create a forgiving :match
414 ;; function for each type below, that only
415 ;; looked at the first letter.
416 (const :tag "Regexp" r)
417 (const :tag "Regexp (fixed case)" R)
418 (const :tag "Substring" s)
419 (const :tag "Substring (fixed case)" S)
420 (const :tag "Exact" e)
421 (const :tag "Exact (fixed case)" E)
422 (const :tag "Word" w)
423 (const :tag "Word (fixed case)" W)
424 (const :tag "default" nil)))
425 (group `(group ,match ,score ,expire ,type))
426 (doc (concat (or (widget-get widget :doc)
427 (concat "Change score based on the " tag
430 You can have an arbitrary number of score entries for this header,
431 each score entry has four elements:
433 1. The \"match element\". This should be the string to look for in the
436 2. The \"score element\". This number should be an integer in the
437 neginf to posinf interval. This number is added to the score
438 of the article if the match is successful. If this element is
439 not present, the `gnus-score-interactive-default-score' number
440 will be used instead. This is 1000 by default.
442 3. The \"date element\". This date says when the last time this score
443 entry matched, which provides a mechanism for expiring the
444 score entries. It this element is not present, the score
445 entry is permanent. The date is represented by the number of
446 days since December 31, 1 ce.
448 4. The \"type element\". This element specifies what function should
449 be used to see whether this score entry matches the article.
451 There are the regexp, as well as substring types, and exact match,
452 and word match types. If this element is not present, Gnus will
453 assume that substring matching should be used. There is case
454 sensitive variants of all match types.")))
455 (widget-put widget :args `(,item
460 :format "%t:\n%h%v%i\n\n"
462 :value ("" nil nil s)
467 (define-widget 'gnus-score-integer 'group
468 "Edit score entries for integer-valued headers."
469 :convert-widget 'gnus-score-integer-convert)
471 (defun gnus-score-integer-convert (widget)
472 ;; Set args appropriately.
473 (let* ((tag (widget-get widget :tag))
474 (item `(const :format "" :value ,(downcase tag)))
475 (match '(integer :tag "Match"))
476 (score '(choice :tag "Score"
477 (const :tag "default" nil)
478 (integer :format "%v"
479 :hide-front-space t)))
480 (expire '(choice :tag "Expire"
481 (const :tag "off" nil)
482 (integer :format "%v"
483 :hide-front-space t)))
484 (type '(choice :tag "Type"
491 (group `(group ,match ,score ,expire ,type))
492 (doc (concat (or (widget-get widget :doc)
493 (concat "Change score based on the " tag
495 (widget-put widget :args `(,item
500 :format "%t:\n%h%v%i\n\n"
504 (define-widget 'gnus-score-date 'group
505 "Edit score entries for date-valued headers."
506 :convert-widget 'gnus-score-date-convert)
508 (defun gnus-score-date-convert (widget)
509 ;; Set args appropriately.
510 (let* ((tag (widget-get widget :tag))
511 (item `(const :format "" :value ,(downcase tag)))
512 (match '(string :tag "Match"))
513 (score '(choice :tag "Score"
514 (const :tag "default" nil)
515 (integer :format "%v"
516 :hide-front-space t)))
517 (expire '(choice :tag "Expire"
518 (const :tag "off" nil)
519 (integer :format "%v"
520 :hide-front-space t)))
521 (type '(choice :tag "Type"
527 (group `(group ,match ,score ,expire ,type))
528 (doc (concat (or (widget-get widget :doc)
529 (concat "Change score based on the " tag
532 For the Date header we have three kinda silly match types: `before',
533 `at' and `after'. I can't really imagine this ever being useful, but,
534 like, it would feel kinda silly not to provide this function. Just in
535 case. You never know. Better safe than sorry. Once burnt, twice
536 shy. Don't judge a book by its cover. Never not have sex on a first
537 date. (I have been told that at least one person, and I quote,
538 \"found this function indispensable\", however.)
540 A more useful match type is `regexp'. With it, you can match the date
541 string using a regular expression. The date is normalized to ISO8601
542 compact format first---`YYYYMMDDTHHMMSS'. If you want to match all
543 articles that have been posted on April 1st in every year, you could
544 use `....0401.........' as a match string, for instance. (Note that
545 the date is kept in its original time zone, so this will match
546 articles that were posted when it was April 1st where the article was
547 posted from. Time zones are such wholesome fun for the whole family,
549 (widget-put widget :args `(,item
554 :format "%t:\n%h%v%i\n\n"
558 (defvar gnus-custom-scores)
559 (defvar gnus-custom-score-alist)
561 (defun gnus-score-customize (file)
562 "Customize score file FILE."
563 (interactive (list gnus-current-score-file))
564 (let ((scores (gnus-score-load file))
565 (types (mapcar (lambda (entry)
566 `(group :format "%v%h\n"
568 (const :format "" ,(nth 0 entry))
570 gnus-score-parameters)))
572 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
573 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
575 (make-local-variable 'gnus-custom-score-alist)
576 (setq gnus-custom-score-alist scores)
577 (widget-insert "Customize the ")
578 (widget-create 'info-link
579 :help-echo "Push me to learn more."
581 "(gnus)Score File Format")
582 (widget-insert " for\n\t")
584 (widget-insert "\nand press ")
585 (widget-create 'push-button
587 :help-echo "Push me when done customizing."
588 :action 'gnus-score-customize-done)
590 Check the [ ] for the entries you want to apply to this score file, then
591 edit the value to suit your taste. Don't forget to mark the checkbox,
592 if you do all your changes will be lost. ")
593 (widget-create 'push-button
594 :action (lambda (&rest ignore)
595 (require 'gnus-audio)
596 (gnus-audio-play "Evil_Laugh.au"))
598 (widget-insert "\n\n")
599 (make-local-variable 'gnus-custom-scores)
600 (setq gnus-custom-scores
601 (widget-create 'group
603 `(checklist :inline t
605 (gnus-score-string :tag "From")
606 (gnus-score-string :tag "Subject")
607 (gnus-score-string :tag "References")
608 (gnus-score-string :tag "Xref")
609 (gnus-score-string :tag "Extra")
610 (gnus-score-string :tag "Message-ID")
611 (gnus-score-integer :tag "Lines")
612 (gnus-score-integer :tag "Chars")
613 (gnus-score-date :tag "Date")
614 (gnus-score-string :tag "Head"
616 Match all headers in the article.
618 Using one of `Head', `Body', `All' will slow down scoring considerable.
620 (gnus-score-string :tag "Body"
622 Match the body sans header of the article.
624 Using one of `Head', `Body', `All' will slow down scoring considerable.
626 (gnus-score-string :tag "All"
628 Match the entire article, including both headers and body.
630 Using one of `Head', `Body', `All' will slow down scoring
633 (gnus-score-string :tag
636 Score all followups to the specified authors.
638 This entry is somewhat special, in that it will match the `From:'
639 header, and affect the score of not only the matching articles, but
640 also all followups to the matching articles. This allows you
641 e.g. increase the score of followups to your own articles, or decrease
642 the score of followups to the articles of some known trouble-maker.
644 (gnus-score-string :tag "Thread"
646 Add a score entry on all articles that are part of a thread.
648 This match key works along the same lines as the `Followup' match key.
649 If you say that you want to score on a (sub-)thread that is started by
650 an article with a `Message-ID' X, then you add a `thread' match. This
651 will add a new `thread' match for each article that has X in its
652 `References' header. (These new `thread' matches will use the
653 `Message-ID's of these matching articles.) This will ensure that you
654 can raise/lower the score of an entire thread, even though some
655 articles in the thread may not have complete `References' headers.
656 Note that using this may lead to undeterministic scores of the
657 articles in the thread.
661 :tag "Unknown entries"
663 (use-local-map widget-keymap)
666 (defun gnus-score-customize-done (&rest ignore)
667 "Reset the score alist with the present value."
668 (let ((alist gnus-custom-score-alist)
669 (value (widget-value gnus-custom-scores)))
670 (setcar alist (car value))
671 (setcdr alist (cdr value))
672 (gnus-score-set 'touched '(t) alist))
679 ;;; gnus-cus.el ends here