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.
34 ;; There should be special validation for this.
35 (define-widget 'gnus-email-address 'string
38 (defun gnus-custom-mode ()
39 "Major mode for editing Gnus customization buffers.
41 The following commands are available:
43 \\[widget-forward] Move to next button or editable field.
44 \\[widget-backward] Move to previous button or editable field.
45 \\[widget-button-click] Activate button under the mouse pointer.
46 \\[widget-button-press] Activate button under point.
48 Entry to this mode calls the value of `gnus-custom-mode-hook'
49 if that value is non-nil."
50 (kill-all-local-variables)
51 (setq major-mode 'gnus-custom-mode
52 mode-name "Gnus Customize")
53 (use-local-map widget-keymap)
54 (gnus-run-hooks 'gnus-custom-mode-hook))
56 ;;; Group Customization:
58 (defconst gnus-group-parameters
59 '((to-address (gnus-email-address :tag "To Address") "\
60 This will be used when doing followups and posts.
62 This is primarily useful in mail groups that represent closed
63 mailing lists--mailing lists where it's expected that everybody that
64 writes to the mailing list is subscribed to it. Since using this
65 parameter ensures that the mail only goes to the mailing list itself,
66 it means that members won't receive two copies of your followups.
68 Using `to-address' will actually work whether the group is foreign or
69 not. Let's say there's a group on the server that is called
70 `fa.4ad-l'. This is a real newsgroup, but the server has gotten the
71 articles from a mail-to-news gateway. Posting directly to this group
72 is therefore impossible--you have to send mail to the mailing list
75 (to-list (gnus-email-address :tag "To List") "\
76 This address will be used when doing a `a' in the group.
78 It is totally ignored when doing a followup--except that if it is
79 present in a news group, you'll get mail group semantics when doing
82 (broken-reply-to (const :tag "Broken Reply To" t) "\
83 Ignore `Reply-To' headers in this group.
85 That can be useful if you're reading a mailing list group where the
86 listserv has inserted `Reply-To' headers that point back to the
87 listserv itself. This is broken behavior. So there!")
89 (to-group (string :tag "To Group") "\
90 All posts will be send to the specified group.")
92 (gcc-self (choice :tag "GCC"
96 (string :format "%v" :hide-front-space t)) "\
97 Specify default value for GCC header.
99 If this symbol is present in the group parameter list and set to `t',
100 new composed messages will be `Gcc''d to the current group. If it is
101 present and set to `none', no `Gcc:' header will be generated, if it
102 is present and a string, this string will be inserted literally as a
103 `gcc' header (this symbol takes precedence over any default `Gcc'
104 rules as described later).")
106 (auto-expire (const :tag "Automatic Expire" t) "\
107 All articles that are read will be marked as expirable.")
109 (total-expire (const :tag "Total Expire" t) "\
110 All read articles will be put through the expiry process
112 This happens even if they are not marked as expirable.
115 (expiry-wait (choice :tag "Expire Wait"
119 (number :hide-front-space t
123 Overrides any `nnmail-expiry-wait' and `nnmail-expiry-wait-function'
124 when expiring expirable messages. The value can either be a number of
125 days (not necessarily an integer) or the symbols `never' or
128 (score-file (file :tag "Score File") "\
129 Make the specified file into the current score file.
130 This means that all score commands you issue will end up in this file.")
132 (adapt-file (file :tag "Adapt File") "\
133 Make the specified file into the current adaptive file.
134 All adaptive score entries will be put into this file.")
136 (admin-address (gnus-email-address :tag "Admin Address") "\
137 Administration address for a mailing list.
139 When unsubscribing to a mailing list you should never send the
140 unsubscription notice to the mailing list itself. Instead, you'd
141 send messages to the administrative address. This parameter allows
142 you to put the admin address somewhere convenient.")
144 (display (choice :tag "Display"
148 Which articles to display on entering the group.
151 Display all articles, both read and unread.
154 Display the default visible articles, which normally includes
155 unread and ticked articles.")
157 (comment (string :tag "Comment") "\
158 An arbitrary comment on the group.")
160 (visible (const :tag "Permanently visible" t) "\
161 Always display this group, even when there are no unread articles
164 (charset (string :tag "Charset") "\
165 The default charset to use in the group.")
167 "Alist of valid group parameters.
169 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
170 itself (a symbol), TYPE is the parameters type (a sexp widget), and
171 DOC is a documentation string for the parameter.")
173 (defvar gnus-custom-params)
174 (defvar gnus-custom-method)
175 (defvar gnus-custom-group)
177 (defun gnus-group-customize (group)
178 "Edit the group on the current line."
179 (interactive (list (gnus-group-group-name)))
181 (types (mapcar (lambda (entry)
182 `(cons :format "%v%h\n"
184 (const :format "" ,(nth 0 entry))
186 gnus-group-parameters)))
188 (error "No group on current line"))
189 (unless (setq info (gnus-get-info group))
190 (error "Killed group; can't be edited"))
192 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
193 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
195 (make-local-variable 'gnus-custom-group)
196 (setq gnus-custom-group group)
197 (widget-insert "Customize the ")
198 (widget-create 'info-link
199 :help-echo "Push me to learn more."
200 :tag "group parameters"
201 "(gnus)Group Parameters")
202 (widget-insert " for <")
203 (widget-insert group)
204 (widget-insert "> and press ")
205 (widget-create 'push-button
207 :help-echo "Push me when done customizing."
208 :action 'gnus-group-customize-done)
209 (widget-insert ".\n\n")
210 (make-local-variable 'gnus-custom-params)
211 (setq gnus-custom-params
212 (widget-create 'group
213 :value (gnus-info-params info)
219 These special paramerters are recognized by Gnus.
220 Check the [ ] for the parameters you want to apply to this group, then
221 edit the value to suit your taste."
225 :format "%t:\n%h%v%i\n\n"
227 Set variables local to the group you are entering.
229 If you want to turn threading off in `news.answers', you could put
230 `(gnus-show-threads nil)' in the group parameters of that group.
231 `gnus-show-threads' will be made into a local variable in the summary
232 buffer you enter, and the form `nil' will be `eval'ed there.
234 This can also be used as a group-specific hook function, if you'd
235 like. If you want to hear a beep when you enter a group, you could
236 put something like `(dummy-variable (ding))' in the parameters of that
237 group. `dummy-variable' will be set to the result of the `(ding)'
238 form, but who cares?"
239 (cons :format "%v" :value (nil . nil)
240 (symbol :tag "Variable")
245 :tag "Unknown entries"
247 (widget-insert "\n\nYou can also edit the ")
248 (widget-create 'info-link
250 :help-echo "Push me to learn more about select methods."
251 "(gnus)Select Methods")
252 (widget-insert " for the group.\n")
253 (setq gnus-custom-method
256 :value (gnus-info-method info)))
257 (use-local-map widget-keymap)
260 (defun gnus-group-customize-done (&rest ignore)
261 "Apply changes and bury the buffer."
263 (gnus-group-edit-group-done 'params gnus-custom-group
264 (widget-value gnus-custom-params))
265 (gnus-group-edit-group-done 'method gnus-custom-group
266 (widget-value gnus-custom-method))
269 ;;; Score Customization:
271 (defconst gnus-score-parameters
272 '((mark (number :tag "Mark") "\
273 The value of this entry should be a number.
274 Any articles with a score lower than this number will be marked as read.")
276 (expunge (number :tag "Expunge") "\
277 The value of this entry should be a number.
278 Any articles with a score lower than this number will be removed from
279 the summary buffer.")
281 (mark-and-expunge (number :tag "Mark-and-expunge") "\
282 The value of this entry should be a number.
283 Any articles with a score lower than this number will be marked as
284 read and removed from the summary buffer.")
286 (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
287 The value of this entry should be a number.
288 All articles that belong to a thread that has a total score below this
289 number will be marked as read and removed from the summary buffer.
290 `gnus-thread-score-function' says how to compute the total score
293 (files (repeat :inline t :tag "Files" file) "\
294 The value of this entry should be any number of file names.
295 These files are assumed to be score files as well, and will be loaded
296 the same way this one was.")
298 (exclude-files (repeat :inline t :tag "Exclude-files" file) "\
299 The clue of this entry should be any number of files.
300 These files will not be loaded, even though they would normally be so,
301 for some reason or other.")
303 (eval (sexp :tag "Eval" :value nil) "\
304 The value of this entry will be `eval'el.
305 This element will be ignored when handling global score files.")
307 (read-only (boolean :tag "Read-only" :value t) "\
308 Read-only score files will not be updated or saved.
309 Global score files should feature this atom.")
311 (orphan (number :tag "Orphan") "\
312 The value of this entry should be a number.
313 Articles that do not have parents will get this number added to their
314 scores. Imagine you follow some high-volume newsgroup, like
315 `comp.lang.c'. Most likely you will only follow a few of the threads,
316 also want to see any new threads.
318 You can do this with the following two score file entries:
321 (mark-and-expunge -100)
323 When you enter the group the first time, you will only see the new
324 threads. You then raise the score of the threads that you find
325 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
326 Next time you enter the group, you will see new articles in the
327 interesting threads, plus any new threads.
329 I.e.---the orphan score atom is for high-volume groups where there
330 exist a few interesting threads which can't be found automatically
331 by ordinary scoring rules.")
333 (adapt (choice :tag "Adapt"
337 :hide-front-space t)) "\
338 This entry controls the adaptive scoring.
339 If it is `t', the default adaptive scoring rules will be used. If it
340 is `ignore', no adaptive scoring will be performed on this group. If
341 it is a list, this list will be used as the adaptive scoring rules.
342 If it isn't present, or is something other than `t' or `ignore', the
343 default adaptive scoring rules will be used. If you want to use
344 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
345 to `t', and insert an `(adapt ignore)' in the groups where you do not
346 want adaptive scoring. If you only want adaptive scoring in a few
347 groups, you'd set `gnus-use-adaptive-scoring' to `nil', and insert
348 `(adapt t)' in the score files of the groups where you want it.")
350 (adapt-file (file :tag "Adapt-file") "\
351 All adaptive score entries will go to the file named by this entry.
352 It will also be applied when entering the group. This atom might
353 be handy if you want to adapt on several groups at once, using the
354 same adaptive file for a number of groups.")
356 (local (repeat :tag "Local"
357 (group :value (nil nil)
358 (symbol :tag "Variable")
359 (sexp :tag "Value"))) "\
360 The value of this entry should be a list of `(VAR VALUE)' pairs.
361 Each VAR will be made buffer-local to the current summary buffer,
362 and set to the value specified. This is a convenient, if somewhat
363 strange, way of setting variables in some groups if you don't like
365 (touched (sexp :format "Touched\n") "Internal variable."))
366 "Alist of valid symbolic score parameters.
368 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
369 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
370 documentation string for the parameter.")
372 (define-widget 'gnus-score-string 'group
373 "Edit score entries for string-valued headers."
374 :convert-widget 'gnus-score-string-convert)
376 (defun gnus-score-string-convert (widget)
377 ;; Set args appropriately.
378 (let* ((tag (widget-get widget :tag))
379 (item `(const :format "" :value ,(downcase tag)))
380 (match '(string :tag "Match"))
381 (score '(choice :tag "Score"
382 (const :tag "default" nil)
383 (integer :format "%v"
384 :hide-front-space t)))
385 (expire '(choice :tag "Expire"
386 (const :tag "off" nil)
387 (integer :format "%v"
388 :hide-front-space t)))
389 (type '(choice :tag "Type"
391 ;; I should really create a forgiving :match
392 ;; function for each type below, that only
393 ;; looked at the first letter.
394 (const :tag "Regexp" r)
395 (const :tag "Regexp (fixed case)" R)
396 (const :tag "Substring" s)
397 (const :tag "Substring (fixed case)" S)
398 (const :tag "Exact" e)
399 (const :tag "Exact (fixed case)" E)
400 (const :tag "Word" w)
401 (const :tag "Word (fixed case)" W)
402 (const :tag "default" nil)))
403 (group `(group ,match ,score ,expire ,type))
404 (doc (concat (or (widget-get widget :doc)
405 (concat "Change score based on the " tag
408 You can have an arbitrary number of score entries for this header,
409 each score entry has four elements:
411 1. The \"match element\". This should be the string to look for in the
414 2. The \"score element\". This number should be an integer in the
415 neginf to posinf interval. This number is added to the score
416 of the article if the match is successful. If this element is
417 not present, the `gnus-score-interactive-default-score' number
418 will be used instead. This is 1000 by default.
420 3. The \"date element\". This date says when the last time this score
421 entry matched, which provides a mechanism for expiring the
422 score entries. It this element is not present, the score
423 entry is permanent. The date is represented by the number of
424 days since December 31, 1 ce.
426 4. The \"type element\". This element specifies what function should
427 be used to see whether this score entry matches the article.
429 There are the regexp, as well as substring types, and exact match,
430 and word match types. If this element is not present, Gnus will
431 assume that substring matching should be used. There is case
432 sensitive variants of all match types.")))
433 (widget-put widget :args `(,item
438 :format "%t:\n%h%v%i\n\n"
440 :value ("" nil nil s)
445 (define-widget 'gnus-score-integer 'group
446 "Edit score entries for integer-valued headers."
447 :convert-widget 'gnus-score-integer-convert)
449 (defun gnus-score-integer-convert (widget)
450 ;; Set args appropriately.
451 (let* ((tag (widget-get widget :tag))
452 (item `(const :format "" :value ,(downcase tag)))
453 (match '(integer :tag "Match"))
454 (score '(choice :tag "Score"
455 (const :tag "default" nil)
456 (integer :format "%v"
457 :hide-front-space t)))
458 (expire '(choice :tag "Expire"
459 (const :tag "off" nil)
460 (integer :format "%v"
461 :hide-front-space t)))
462 (type '(choice :tag "Type"
469 (group `(group ,match ,score ,expire ,type))
470 (doc (concat (or (widget-get widget :doc)
471 (concat "Change score based on the " tag
473 (widget-put widget :args `(,item
478 :format "%t:\n%h%v%i\n\n"
482 (define-widget 'gnus-score-date 'group
483 "Edit score entries for date-valued headers."
484 :convert-widget 'gnus-score-date-convert)
486 (defun gnus-score-date-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"
505 (group `(group ,match ,score ,expire ,type))
506 (doc (concat (or (widget-get widget :doc)
507 (concat "Change score based on the " tag
510 For the Date header we have three kinda silly match types: `before',
511 `at' and `after'. I can't really imagine this ever being useful, but,
512 like, it would feel kinda silly not to provide this function. Just in
513 case. You never know. Better safe than sorry. Once burnt, twice
514 shy. Don't judge a book by its cover. Never not have sex on a first
515 date. (I have been told that at least one person, and I quote,
516 \"found this function indispensable\", however.)
518 A more useful match type is `regexp'. With it, you can match the date
519 string using a regular expression. The date is normalized to ISO8601
520 compact format first---`YYYYMMDDTHHMMSS'. If you want to match all
521 articles that have been posted on April 1st in every year, you could
522 use `....0401.........' as a match string, for instance. (Note that
523 the date is kept in its original time zone, so this will match
524 articles that were posted when it was April 1st where the article was
525 posted from. Time zones are such wholesome fun for the whole family,
527 (widget-put widget :args `(,item
532 :format "%t:\n%h%v%i\n\n"
536 (defvar gnus-custom-scores)
537 (defvar gnus-custom-score-alist)
539 (defun gnus-score-customize (file)
540 "Customize score file FILE."
541 (interactive (list gnus-current-score-file))
542 (let ((scores (gnus-score-load file))
543 (types (mapcar (lambda (entry)
544 `(group :format "%v%h\n"
546 (const :format "" ,(nth 0 entry))
548 gnus-score-parameters)))
550 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
551 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
553 (make-local-variable 'gnus-custom-score-alist)
554 (setq gnus-custom-score-alist scores)
555 (widget-insert "Customize the ")
556 (widget-create 'info-link
557 :help-echo "Push me to learn more."
559 "(gnus)Score File Format")
560 (widget-insert " for\n\t")
562 (widget-insert "\nand press ")
563 (widget-create 'push-button
565 :help-echo "Push me when done customizing."
566 :action 'gnus-score-customize-done)
568 Check the [ ] for the entries you want to apply to this score file, then
569 edit the value to suit your taste. Don't forget to mark the checkbox,
570 if you do all your changes will be lost. ")
571 (widget-create 'push-button
572 :action (lambda (&rest ignore)
573 (require 'gnus-audio)
574 (gnus-audio-play "Evil_Laugh.au"))
576 (widget-insert "\n\n")
577 (make-local-variable 'gnus-custom-scores)
578 (setq gnus-custom-scores
579 (widget-create 'group
581 `(checklist :inline t
583 (gnus-score-string :tag "From")
584 (gnus-score-string :tag "Subject")
585 (gnus-score-string :tag "References")
586 (gnus-score-string :tag "Xref")
587 (gnus-score-string :tag "Message-ID")
588 (gnus-score-integer :tag "Lines")
589 (gnus-score-integer :tag "Chars")
590 (gnus-score-date :tag "Date")
591 (gnus-score-string :tag "Head"
593 Match all headers in the article.
595 Using one of `Head', `Body', `All' will slow down scoring considerable.
597 (gnus-score-string :tag "Body"
599 Match the body sans header of the article.
601 Using one of `Head', `Body', `All' will slow down scoring considerable.
603 (gnus-score-string :tag "All"
605 Match the entire article, including both headers and body.
607 Using one of `Head', `Body', `All' will slow down scoring
610 (gnus-score-string :tag
613 Score all followups to the specified authors.
615 This entry is somewhat special, in that it will match the `From:'
616 header, and affect the score of not only the matching articles, but
617 also all followups to the matching articles. This allows you
618 e.g. increase the score of followups to your own articles, or decrease
619 the score of followups to the articles of some known trouble-maker.
621 (gnus-score-string :tag "Thread"
623 Add a score entry on all articles that are part of a thread.
625 This match key works along the same lines as the `Followup' match key.
626 If you say that you want to score on a (sub-)thread that is started by
627 an article with a `Message-ID' X, then you add a `thread' match. This
628 will add a new `thread' match for each article that has X in its
629 `References' header. (These new `thread' matches will use the
630 `Message-ID's of these matching articles.) This will ensure that you
631 can raise/lower the score of an entire thread, even though some
632 articles in the thread may not have complete `References' headers.
633 Note that using this may lead to undeterministic scores of the
634 articles in the thread.
638 :tag "Unknown entries"
640 (use-local-map widget-keymap)
643 (defun gnus-score-customize-done (&rest ignore)
644 "Reset the score alist with the present value."
645 (let ((alist gnus-custom-score-alist)
646 (value (widget-value gnus-custom-scores)))
647 (setcar alist (car value))
648 (setcdr alist (cdr value))
649 (gnus-score-set 'touched '(t) alist))
656 ;;; gnus-cus.el ends here