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.
29 (require 'widget-edit)
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 (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."))
159 "Alist of valid group parameters.
161 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
162 itself (a symbol), TYPE is the parameters type (a sexp widget), and
163 DOC is a documentation string for the parameter.")
165 (defvar gnus-custom-params)
166 (defvar gnus-custom-method)
167 (defvar gnus-custom-group)
169 (defun gnus-group-customize (group &optional part)
170 "Edit the group on the current line."
171 (interactive (list (gnus-group-group-name)))
172 (let ((part (or part 'info))
174 (types (mapcar (lambda (entry)
175 `(cons :format "%v%h\n"
177 (const :format "" ,(nth 0 entry))
179 gnus-group-parameters)))
181 (error "No group on current line"))
182 (unless (setq info (gnus-get-info group))
183 (error "Killed group; can't be edited"))
185 (kill-buffer (get-buffer-create "*Gnus Customize*"))
186 (switch-to-buffer (get-buffer-create "*Gnus Customize*"))
188 (make-local-variable 'gnus-custom-group)
189 (setq gnus-custom-group group)
190 (widget-insert "Customize the ")
191 (widget-create 'info-link
192 :help-echo "Push me to learn more."
193 :tag "group parameters"
194 "(gnus)Group Parameters")
195 (widget-insert " for <")
196 (widget-insert group)
197 (widget-insert "> and press ")
198 (widget-create 'push-button
200 :help-echo "Push me when done customizing."
201 :action 'gnus-group-customize-done)
202 (widget-insert ".\n\n")
203 (make-local-variable 'gnus-custom-params)
204 (setq gnus-custom-params
205 (widget-create 'group
206 :value (gnus-info-params info)
212 These special paramerters are recognized by Gnus.
213 Check the [ ] for the parameters you want to apply to this group, then
214 edit the value to suit your taste."
218 :format "%t:\n%h%v%i"
220 Set variables local to the group you are entering.
222 If you want to turn threading off in `news.answers', you could put
223 `(gnus-show-threads nil)' in the group parameters of that group.
224 `gnus-show-threads' will be made into a local variable in the summary
225 buffer you enter, and the form `nil' will be `eval'ed there.
227 This can also be used as a group-specific hook function, if you'd
228 like. If you want to hear a beep when you enter a group, you could
229 put something like `(dummy-variable (ding))' in the parameters of that
230 group. `dummy-variable' will be set to the result of the `(ding)'
231 form, but who cares?"
232 (group :value (nil nil)
233 (symbol :tag "Variable")
236 (widget-insert "\n\nYou can also edit the ")
237 (widget-create 'info-link
239 :help-echo "Push me to learn more about select methods."
240 "(gnus)Select Methods")
241 (widget-insert " for the group.\n")
242 (setq gnus-custom-method
245 :value (gnus-info-method info)))
246 (use-local-map widget-keymap)
249 (defun gnus-group-customize-done (&rest ignore)
250 "Apply changes and bury the buffer."
252 (gnus-group-edit-group-done 'params gnus-custom-group
253 (widget-value gnus-custom-params))
254 (gnus-group-edit-group-done 'method gnus-custom-group
255 (widget-value gnus-custom-method))
258 ;;; Score Customization:
260 (defconst gnus-score-parameters
261 '((mark (number :tag "Mark") "\
262 The value of this entry should be a number.
263 Any articles with a score lower than this number will be marked as read.")
265 (expunge (number :tag "Expunge") "\
266 The value of this entry should be a number.
267 Any articles with a score lower than this number will be removed from
268 the summary buffer.")
270 (mark-and-expunge (number :tag "Mark-and-expunge") "\
271 The value of this entry should be a number.
272 Any articles with a score lower than this number will be marked as
273 read and removed from the summary buffer.")
275 (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\
276 The value of this entry should be a number.
277 All articles that belong to a thread that has a total score below this
278 number will be marked as read and removed from the summary buffer.
279 `gnus-thread-score-function' says how to compute the total score
282 (files (repeat :tag "Files" file) "\
283 The value of this entry should be any number of file names.
284 These files are assumed to be score files as well, and will be loaded
285 the same way this one was.")
287 (exclude-files (repeat :tag "Exclude-files" file) "\
288 The clue of this entry should be any number of files.
289 These files will not be loaded, even though they would normally be so,
290 for some reason or other.")
292 (eval (sexp :tag "Eval" :value nil) "\
293 The value of this entry will be `eval'el.
294 This element will be ignored when handling global score files.")
296 (read-only (boolean :tag "Read-only" :value t) "\
297 Read-only score files will not be updated or saved.
298 Global score files should feature this atom.")
300 (orphan (number :tag "Orphan") "\
301 The value of this entry should be a number.
302 Articles that do not have parents will get this number added to their
303 scores. Imagine you follow some high-volume newsgroup, like
304 `comp.lang.c'. Most likely you will only follow a few of the threads,
305 also want to see any new threads.
307 You can do this with the following two score file entries:
310 (mark-and-expunge -100)
312 When you enter the group the first time, you will only see the new
313 threads. You then raise the score of the threads that you find
314 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
315 Next time you enter the group, you will see new articles in the
316 interesting threads, plus any new threads.
318 I.e.---the orphan score atom is for high-volume groups where there
319 exist a few interesting threads which can't be found automatically
320 by ordinary scoring rules.")
322 (adapt (choice :tag "Adapt"
326 :hide-front-space t)) "\
327 This entry controls the adaptive scoring.
328 If it is `t', the default adaptive scoring rules will be used. If it
329 is `ignore', no adaptive scoring will be performed on this group. If
330 it is a list, this list will be used as the adaptive scoring rules.
331 If it isn't present, or is something other than `t' or `ignore', the
332 default adaptive scoring rules will be used. If you want to use
333 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
334 to `t', and insert an `(adapt ignore)' in the groups where you do not
335 want adaptive scoring. If you only want adaptive scoring in a few
336 groups, you'd set `gnus-use-adaptive-scoring' to `nil', and insert
337 `(adapt t)' in the score files of the groups where you want it.")
339 (adapt-file (file :tag "Adapt-file") "\
340 All adaptive score entries will go to the file named by this entry.
341 It will also be applied when entering the group. This atom might
342 be handy if you want to adapt on several groups at once, using the
343 same adaptive file for a number of groups.")
345 (local (repeat :tag "Local"
346 (group :value (nil nil)
347 (symbol :tag "Variable")
348 (sexp :tag "Value"))) "\
349 The value of this entry should be a list of `(VAR VALUE)' pairs.
350 Each VAR will be made buffer-local to the current summary buffer,
351 and set to the value specified. This is a convenient, if somewhat
352 strange, way of setting variables in some groups if you don't like
354 "Alist of valid symbolic score parameters.
356 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
357 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
358 documentation string for the parameter.")
360 (define-widget 'gnus-score-string 'group
361 "Edit score entries for string-valued headers."
362 :convert-widget 'gnus-score-string-convert)
364 (defun gnus-score-string-convert (widget)
365 ;; Set args appropriately.
366 (let* ((tag (widget-get widget :tag))
367 (item `(const :format "" :value ,(downcase tag)))
368 (match '(string :tag "Match"))
369 (score '(choice :tag "Score"
370 (const :tag "default" nil)
371 (integer :format "%v"
372 :hide-front-space t)))
373 (expire '(choice :tag "Expire"
374 (const :tag "off" nil)
375 (integer :format "%v"
376 :hide-front-space t)))
377 (type '(choice :tag "Type"
379 ;; I should really create a forgiving :match
380 ;; function for each type below, that only
381 ;; looked at the first letter.
382 (const :tag "Regexp" r)
383 (const :tag "Regexp (fixed case)" R)
384 (const :tag "Substring" s)
385 (const :tag "Substring (fixed case)" S)
386 (const :tag "Exact" e)
387 (const :tag "Exact (fixed case)" E)
388 (const :tag "Word" w)
389 (const :tag "Word (fixed case)" W)
390 (const :tag "default" nil)))
391 (group `(group ,match ,score ,expire ,type))
392 (doc (concat (or (widget-get widget :doc)
393 (concat "Change score based on the " tag
396 You can have an arbitrary number of score entries for this header,
397 each score entry has four elements:
399 1. The \"match element\". This should be the string to look for in the
402 2. The \"score element\". This number should be an integer in the
403 neginf to posinf interval. This number is added to the score
404 of the article if the match is successful. If this element is
405 not present, the `gnus-score-interactive-default-score' number
406 will be used instead. This is 1000 by default.
408 3. The \"date element\". This date says when the last time this score
409 entry matched, which provides a mechanism for expiring the
410 score entries. It this element is not present, the score
411 entry is permanent. The date is represented by the number of
412 days since December 31, 1 ce.
414 4. The \"type element\". This element specifies what function should
415 be used to see whether this score entry matches the article.
417 There are the regexp, as well as substring types, and exact match,
418 and word match types. If this element is not present, Gnus will
419 assume that substring matching should be used. There is case
420 sensitive variants of all match types.")))
421 (widget-put widget :args `(,item
426 :format "%t:\n%h%v%i\n\n"
430 (define-widget 'gnus-score-integer 'group
431 "Edit score entries for integer-valued headers."
432 :convert-widget 'gnus-score-integer-convert)
434 (defun gnus-score-integer-convert (widget)
435 ;; Set args appropriately.
436 (let* ((tag (widget-get widget :tag))
437 (item `(const :format "" :value ,(downcase tag)))
438 (match '(integer :tag "Match"))
439 (score '(choice :tag "Score"
440 (const :tag "default" nil)
441 (integer :format "%v"
442 :hide-front-space t)))
443 (expire '(choice :tag "Expire"
444 (const :tag "off" nil)
445 (integer :format "%v"
446 :hide-front-space t)))
447 (type '(choice :tag "Type"
454 (group `(group ,match ,score ,expire ,type))
455 (doc (concat (or (widget-get widget :doc)
456 (concat "Change score based on the " tag
458 (widget-put widget :args `(,item
463 :format "%t:\n%h%v%i\n\n"
467 (define-widget 'gnus-score-date 'group
468 "Edit score entries for date-valued headers."
469 :convert-widget 'gnus-score-date-convert)
471 (defun gnus-score-date-convert (widget)
472 ;; Set args appropriately.
473 (let* ((tag (widget-get widget :tag))
474 (item `(const :format "" :value ,(downcase tag)))
475 (match '(string :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"
490 (group `(group ,match ,score ,expire ,type))
491 (doc (concat (or (widget-get widget :doc)
492 (concat "Change score based on the " tag
495 For the Date header we have three kinda silly match types: `before',
496 `at' and `after'. I can't really imagine this ever being useful, but,
497 like, it would feel kinda silly not to provide this function. Just in
498 case. You never know. Better safe than sorry. Once burnt, twice
499 shy. Don't judge a book by its cover. Never not have sex on a first
500 date. (I have been told that at least one person, and I quote,
501 \"found this function indispensable\", however.)
503 A more useful match type is `regexp'. With it, you can match the date
504 string using a regular expression. The date is normalized to ISO8601
505 compact format first---`YYYYMMDDTHHMMSS'. If you want to match all
506 articles that have been posted on April 1st in every year, you could
507 use `....0401.........' as a match string, for instance. (Note that
508 the date is kept in its original time zone, so this will match
509 articles that were posted when it was April 1st where the article was
510 posted from. Time zones are such wholesome fun for the whole family,
512 (widget-put widget :args `(,item
517 :format "%t:\n%h%v%i\n\n"
521 (defvar gnus-custom-scores)
522 (defvar gnus-custom-score-alist)
524 (defun gnus-score-customize (file)
525 "Customize score file FILE."
526 (interactive (list gnus-current-score-file))
527 (let ((scores (gnus-score-load file))
528 (types (mapcar (lambda (entry)
529 `(group :format "%v%h\n"
531 (const :format "" ,(nth 0 entry))
533 gnus-score-parameters)))
535 (kill-buffer (get-buffer-create "*Gnus Customize*"))
536 (switch-to-buffer (get-buffer-create "*Gnus Customize*"))
538 (make-local-variable 'gnus-custom-score-alist)
539 (setq gnus-custom-score-alist scores)
540 (widget-insert "Customize the ")
541 (widget-create 'info-link
542 :help-echo "Push me to learn more."
544 "(gnus)Score File Format")
545 (widget-insert " for\n\t")
547 (widget-insert "\nand press ")
548 (widget-create 'push-button
550 :help-echo "Push me when done customizing."
551 :action 'gnus-score-customize-done)
553 Check the [ ] for the entries you want to apply to this score file, then
554 edit the value to suit your taste. Don't forget to mark the checkbox,
555 if you do all your changes will be lost. ")
556 (widget-create 'push-button
557 :action (lambda (&rest ignore)
558 (require 'gnus-audio)
559 (gnus-audio-play "Evil_Laugh.au"))
561 (widget-insert "\n\n")
562 (make-local-variable 'gnus-custom-scores)
563 (setq gnus-custom-scores
564 (widget-create 'group
566 `(checklist :inline t
568 (gnus-score-string :tag "From")
569 (gnus-score-string :tag "Subject")
570 (gnus-score-string :tag "References")
571 (gnus-score-string :tag "Xref")
572 (gnus-score-string :tag "Message-ID")
573 (gnus-score-integer :tag "Lines")
574 (gnus-score-integer :tag "Chars")
575 (gnus-score-date :tag "Date")
576 (gnus-score-string :tag "Head"
578 Match all headers in the article.
580 Using one of `Head', `Body', `All' will slow down scoring considerable.
582 (gnus-score-string :tag "Body"
584 Match the body sans header of the article.
586 Using one of `Head', `Body', `All' will slow down scoring considerable.
588 (gnus-score-string :tag "All"
590 Match the entire article, including both headers and body.
592 Using one of `Head', `Body', `All' will slow down scoring
595 (gnus-score-string :tag
598 Score all followups to the specified authors.
600 This entry is somewhat special, in that it will match the `From:'
601 header, and affect the score of not only the matching articles, but
602 also all followups to the matching articles. This allows you
603 e.g. increase the score of followups to your own articles, or decrease
604 the score of followups to the articles of some known trouble-maker.
606 (gnus-score-string :tag "Thread"
608 Add a score entry on all articles that are part of a thread.
610 This match key works along the same lines as the `Followup' match key.
611 If you say that you want to score on a (sub-)thread that is started by
612 an article with a `Message-ID' X, then you add a `thread' match. This
613 will add a new `thread' match for each article that has X in its
614 `References' header. (These new `thread' matches will use the
615 `Message-ID's of these matching articles.) This will ensure that you
616 can raise/lower the score of an entire thread, even though some
617 articles in the thread may not have complete `References' headers.
618 Note that using this may lead to undeterministic scores of the
619 articles in the thread.
622 (use-local-map widget-keymap)
625 (defun gnus-score-customize-done (&rest ignore)
626 "Reset the score alist with the present value."
627 (let ((alist gnus-custom-score-alist)
628 (value (widget-value gnus-custom-scores)))
629 (setcar alist (car value))
630 (setcdr alist (cdr value))
631 (gnus-score-set 'touched '(t) alist))
638 ;;; gnus-cus.el ends here