1 ;;; gnus-cus.el --- customization commands for Gnus
3 ;; Copyright (C) 1996, 1999-2012 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 3 of the License, or
13 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
36 (defun gnus-custom-mode ()
37 "Major mode for editing Gnus customization buffers.
39 The following commands are available:
41 \\[widget-forward] Move to next button or editable field.
42 \\[widget-backward] Move to previous button or editable field.
43 \\[widget-button-click] Activate button under the mouse pointer.
44 \\[widget-button-press] Activate button under point.
46 Entry to this mode calls the value of `gnus-custom-mode-hook'
47 if that value is non-nil."
48 (kill-all-local-variables)
49 (setq major-mode
'gnus-custom-mode
50 mode-name
"Gnus Customize")
51 (use-local-map widget-keymap
)
53 (when (and (facep 'custom-button-face
)
54 (facep 'custom-button-pressed-face
))
55 (set (make-local-variable 'widget-button-face
)
57 (set (make-local-variable 'widget-button-pressed-face
)
58 'custom-button-pressed-face
)
59 (set (make-local-variable 'widget-mouse-face
)
60 'custom-button-pressed-face
))
61 (when (and (boundp 'custom-raised-buttons
)
62 (symbol-value 'custom-raised-buttons
))
63 (set (make-local-variable 'widget-push-button-prefix
) "")
64 (set (make-local-variable 'widget-push-button-suffix
) "")
65 (set (make-local-variable 'widget-link-prefix
) "")
66 (set (make-local-variable 'widget-link-suffix
) ""))
67 (gnus-run-mode-hooks 'gnus-custom-mode-hook
))
69 ;;; Group Customization:
71 (defconst gnus-group-parameters
72 '((extra-aliases (choice
78 (gnus-email-address :tag
"Address")))
79 (gnus-email-address :tag
"Address")) "\
80 Store messages posted from or to this address in this group.
82 You must be using gnus-group-split for this to work. The VALUE of the
83 nnmail-split-fancy SPLIT generated for this group will match these
86 (split-regexp (regexp :tag
"gnus-group-split Regular Expression") "\
87 Like gnus-group-split Address, but expects a regular expression.")
89 (split-exclude (list :tag
"gnus-group-split Restricts"
91 :inline t
(regexp :tag
"Restrict"))) "\
92 Regular expression that cancels gnus-group-split matches.
94 Each entry is added to the nnmail-split-fancy SPLIT as a separate
97 (split-spec (choice :tag
"gnus-group-split Overrider"
98 (sexp :tag
"Fancy Split")
99 (const :tag
"Catch All" catch-all
)
100 (const :tag
"Ignore" nil
)) "\
101 Override all other gnus-group-split fields.
103 In `Fancy Split', you can enter any nnmail-split-fancy SPLIT. Note
104 that the name of this group won't be automatically assumed, you have
105 to add it to the SPLITs yourself. This means you can use such splits
106 to split messages to other groups too.
108 If you select `Catch All', this group will get postings for any
109 messages not matched in any other group. It overrides the variable
110 gnus-group-split-default-catch-all-group.
112 Selecting `Ignore' forces no SPLIT to be generated for this group,
113 disabling all other gnus-group-split fields.")
115 (broken-reply-to (const :tag
"Broken Reply To" t
) "\
116 Ignore `Reply-To' headers in this group.
118 That can be useful if you're reading a mailing list group where the
119 listserv has inserted `Reply-To' headers that point back to the
120 listserv itself. This is broken behavior. So there!")
122 (to-group (string :tag
"To Group") "\
123 All posts will be sent to the specified group.")
125 (gcc-self (choice :tag
"GCC"
127 (const :tag
"To current group" t
)
129 (string :format
"%v" :hide-front-space t
)) "\
130 Specify default value for GCC header.
132 If this symbol is present in the group parameter list and set to t,
133 new composed messages will be `Gcc''d to the current group. If it is
134 present and set to `none', no `Gcc:' header will be generated, if it
135 is present and a string, this string will be inserted literally as a
136 `gcc' header (this symbol takes precedence over any default `Gcc'
137 rules as described later).")
139 (expiry-wait (choice :tag
"Expire Wait"
143 (number :hide-front-space t
147 Overrides any `nnmail-expiry-wait' and `nnmail-expiry-wait-function'
148 when expiring expirable messages. The value can either be a number of
149 days (not necessarily an integer) or the symbols `never' or
152 (expiry-target (choice :tag
"Expiry Target"
155 (function :format
"%v" nnmail-
)
157 Where expired messages end up.
159 Overrides `nnmail-expiry-target'.")
161 (score-file (file :tag
"Score File") "\
162 Make the specified file into the current score file.
163 This means that all score commands you issue will end up in this file.")
165 (adapt-file (file :tag
"Adapt File") "\
166 Make the specified file into the current adaptive file.
167 All adaptive score entries will be put into this file.")
169 (admin-address (gnus-email-address :tag
"Admin Address") "\
170 Administration address for a mailing list.
172 When unsubscribing to a mailing list you should never send the
173 unsubscription notice to the mailing list itself. Instead, you'd
174 send messages to the administrative address. This parameter allows
175 you to put the admin address somewhere convenient.")
177 (display (choice :tag
"Display"
182 (sexp :tag
"Other")) "\
183 Which articles to display on entering the group.
186 Display all articles, both read and unread.
189 Display the last NUMBER articles in the group. This is the same as
190 entering the group with C-u NUMBER.
193 Display the default visible articles, which normally includes
194 unread and ticked articles.
197 Display the articles that satisfy the S-expression. The S-expression
198 should be in an array form.")
200 (comment (string :tag
"Comment") "\
201 An arbitrary comment on the group.")
203 (visible (const :tag
"Permanently visible" t
) "\
204 Always display this group, even when there are no unread articles in it.")
207 (choice :tag
"Highlight words"
209 (repeat (list (regexp :tag
"Highlight regexp")
210 (number :tag
"Group for entire word" 0)
211 (number :tag
"Group for displayed part" 0)
213 gnus-emphasis-highlight-words
))))
215 See `gnus-emphasis-alist'.")
218 (choice :tag
"Posting style"
224 (const signature-file
)
231 (string :tag
"Header"))
232 (string :format
"%v"))))
234 See `gnus-posting-styles'."))
235 "Alist of valid group or topic parameters.
237 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
238 itself (a symbol), TYPE is the parameters type (a sexp widget), and
239 DOC is a documentation string for the parameter.")
241 (defconst gnus-extra-topic-parameters
242 '((subscribe (regexp :tag
"Subscribe") "\
243 If `gnus-subscribe-newsgroup-method' or
244 `gnus-subscribe-options-newsgroup-method' is set to
245 `gnus-subscribe-topics', new groups that matches this regexp will
246 automatically be subscribed to this topic")
247 (subscribe-level (integer :tag
"Subscribe Level" :value
1) "\
248 If this topic parameter is set, when new groups are subscribed
249 automatically under this topic (via the `subscribe' topic parameter)
250 assign this level to the group, rather than the default level
251 set in `gnus-level-default-subscribed'"))
252 "Alist of topic parameters that are not also group parameters.
254 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
255 itself (a symbol), TYPE is the parameters type (a sexp widget), and
256 DOC is a documentation string for the parameter.")
258 (defconst gnus-extra-group-parameters
259 '((uidvalidity (string :tag
"IMAP uidvalidity") "\
260 Server-assigned value attached to IMAP groups, used to maintain consistency."))
261 "Alist of group parameters that are not also topic parameters.
263 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
264 itself (a symbol), TYPE is the parameters type (a sexp widget), and
265 DOC is a documentation string for the parameter.")
268 (defconst gnus-agent-parameters
270 (sexp :tag
"Selection Predicate" :value false
)
271 "Predicate used to automatically select articles for downloading."
272 gnus-agent-cat-predicate
)
274 (choice :tag
"Score File" :value nil
275 (const file
:tag
"Use group's score files")
276 (repeat (list (string :format
"%v" :tag
"File name"))))
277 "Which score files to use when using score to select articles to fetch.
280 All articles will be scored to zero (0).
283 The group's score files will be used to score the articles.
286 A list of score file names."
287 gnus-agent-cat-score-file
)
289 (integer :tag
"Max Length of Short Article" :value
"")
290 "The SHORT predicate will evaluate to true when the article is
291 shorter than this length." gnus-agent-cat-length-when-short
)
293 (integer :tag
"Min Length of Long Article" :value
"")
294 "The LONG predicate will evaluate to true when the article is
295 longer than this length." gnus-agent-cat-length-when-long
)
297 (integer :tag
"Low Score Limit" :value
"")
298 "The LOW predicate will evaluate to true when the article scores
299 lower than this limit." gnus-agent-cat-low-score
)
301 (integer :tag
"High Score Limit" :value
"")
302 "The HIGH predicate will evaluate to true when the article scores
303 higher than this limit." gnus-agent-cat-high-score
)
304 (agent-days-until-old
305 (integer :tag
"Days Until Old" :value
"")
306 "The OLD predicate will evaluate to true when the fetched article
307 has been stored locally for at least this many days."
308 gnus-agent-cat-days-until-old
)
309 (agent-enable-expiration
310 (radio :tag
"Expire in this Group or Topic" :value nil
311 (const :format
"Enable " ENABLE
)
312 (const :format
"Disable " DISABLE
))
313 "\nEnable, or disable, agent expiration in this group or topic."
314 gnus-agent-cat-enable-expiration
)
315 (agent-enable-undownloaded-faces
316 (boolean :tag
"Enable Agent Faces")
317 "Have the summary buffer use the agent's undownloaded faces.
318 These faces, when enabled, act as a warning that an article has not
319 been fetched into either the agent nor the cache. This is of most use
320 to users who use the agent as a cache (i.e. they only operate on
321 articles that have been downloaded). Leave disabled to display normal
322 article faces even when the article hasn't been downloaded."
323 gnus-agent-cat-enable-undownloaded-faces
))
324 "Alist of group parameters that are not also topic parameters.
326 Each entry has the form (NAME TYPE DOC ACCESSOR), where NAME is the
327 parameter itself (a symbol), TYPE is the parameters type (a sexp
328 widget), DOC is a documentation string for the parameter, and ACCESSOR
329 is a function (symbol) that extracts the current value from the
332 (defvar gnus-custom-params
)
333 (defvar gnus-custom-method
)
334 (defvar gnus-custom-group
)
335 (defvar gnus-custom-topic
)
337 (defun gnus-group-customize (group &optional topic
)
338 "Edit the group or topic on the current line."
339 (interactive (list (gnus-group-group-name) (gnus-group-topic-name)))
341 (types (mapcar (lambda (entry)
342 `(cons :format
"%v%h\n"
344 (const :format
"" ,(nth 0 entry
))
346 (append (reverse gnus-group-parameters-more
)
347 gnus-group-parameters
349 gnus-extra-group-parameters
350 gnus-extra-topic-parameters
))))
351 (agent (mapcar (lambda (entry)
352 (let ((type (nth 1 entry
))
355 (setq type
(copy-sequence type
)))
357 (setq vcons
(cdr (memq :value type
)))
359 (if (symbolp (car vcons
))
361 (setcar vcons
(symbol-value (car vcons
)))
363 `(cons :format
"%v%h\n"
365 (const :format
"" ,(nth 0 entry
))
368 gnus-agent-parameters
))))
369 (unless (or group topic
)
370 (error "No group on current line"))
371 (when (and group topic
)
372 (error "Both a group an topic on current line"))
373 (unless (or topic
(setq info
(gnus-get-info group
)))
374 (error "Killed group; can't be edited"))
376 (gnus-kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
377 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
379 (make-local-variable 'gnus-custom-group
)
380 (setq gnus-custom-group group
)
381 (make-local-variable 'gnus-custom-topic
)
382 (setq gnus-custom-topic topic
)
383 (buffer-disable-undo)
384 (widget-insert "Customize the ")
386 (widget-create 'info-link
387 :help-echo
"Push me to learn more."
388 :tag
"group parameters"
389 "(gnus)Group Parameters")
390 (widget-create 'info-link
391 :help-echo
"Push me to learn more."
392 :tag
"topic parameters"
393 "(gnus)Topic Parameters"))
394 (widget-insert " for <")
395 (widget-insert (gnus-group-decoded-name (or group topic
)))
396 (widget-insert "> and press ")
397 (widget-create 'push-button
399 :help-echo
"Push me when done customizing."
400 :action
'gnus-group-customize-done
)
401 (widget-insert ".\n\n")
402 (make-local-variable 'gnus-custom-params
)
404 (let ((values (if group
405 (gnus-info-params info
)
406 (gnus-topic-parameters topic
))))
408 ;; The parameters in values may contain duplicates. This is
409 ;; normally OK as assq returns the first. However, right here
410 ;; every duplicate ends up being displayed. So, rather than
411 ;; display them, remove them from the list.
413 (let ((tmp (setq values
(gnus-copy-sequence values
)))
416 (while (setq elem
(assq (caar tmp
) (cdr tmp
)))
418 (setq tmp
(cdr tmp
))))
420 ;; Decode values posting-style holds.
421 (dolist (style (cdr (assq 'posting-style values
)))
422 (when (stringp (cadr style
))
423 (setcdr style
(list (mm-decode-coding-string (cadr style
) 'utf-8
)))))
425 (setq gnus-custom-params
426 (apply 'widget-create
'group
429 (list `(set :inline t
434 These special parameters are recognized by Gnus.
435 Check the [ ] for the parameters you want to apply to this group or
436 to the groups in this topic, then edit the value to suit your taste."
441 :tag
"Agent Parameters"
443 :doc
"\ These agent parameters are
444 recognized by Gnus. They control article selection and expiration for
445 use in the unplugged cache. Check the [ ] for the parameters you want
446 to apply to this group or to the groups in this topic, then edit the
447 value to suit your taste.
449 For those interested, group parameters override topic parameters while
450 topic parameters override agent category parameters. Underlying
451 category parameters are the customizable variables." ,@agent
))
454 :format
"%t:\n%h%v%i\n\n"
456 Set variables local to the group you are entering.
458 If you want to turn threading off in `news.answers', you could put
459 `(gnus-show-threads nil)' in the group parameters of that group.
460 `gnus-show-threads' will be made into a local variable in the summary
461 buffer you enter, and the form nil will be `eval'ed there.
463 This can also be used as a group-specific hook function, if you'd
464 like. If you want to hear a beep when you enter a group, you could
465 put something like `(dummy-variable (ding))' in the parameters of that
466 group. `dummy-variable' will be set to the result of the `(ding)'
467 form, but who cares?"
468 (list :format
"%v" :value
(nil nil
)
469 (symbol :tag
"Variable")
474 :tag
"Unknown entries"
477 (widget-insert "\n\nYou can also edit the ")
478 (widget-create 'info-link
480 :help-echo
"Push me to learn more about select methods."
481 "(gnus)Select Methods")
482 (widget-insert " for the group.\n")
483 (setq gnus-custom-method
486 :value
(gnus-info-method info
))))
487 (use-local-map widget-keymap
)
490 (goto-char (point-min))))
492 (defun gnus-group-customize-done (&rest ignore
)
493 "Apply changes and bury the buffer."
495 (let ((params (widget-value gnus-custom-params
)))
496 ;; Encode values posting-style holds.
497 (dolist (style (cdr (assq 'posting-style params
)))
498 (when (stringp (cadr style
))
499 (setcdr style
(list (mm-encode-coding-string (cadr style
) 'utf-8
)))))
500 (if gnus-custom-topic
501 (gnus-topic-set-parameters gnus-custom-topic params
)
502 (gnus-group-edit-group-done 'params gnus-custom-group params
)
503 (gnus-group-edit-group-done 'method gnus-custom-group
504 (widget-value gnus-custom-method
)))
507 ;;; Score Customization:
509 (defconst gnus-score-parameters
510 '((mark (number :tag
"Mark") "\
511 The value of this entry should be a number.
512 Any articles with a score lower than this number will be marked as read.")
514 (expunge (number :tag
"Expunge") "\
515 The value of this entry should be a number.
516 Any articles with a score lower than this number will be removed from
517 the summary buffer.")
519 (mark-and-expunge (number :tag
"Mark-and-expunge") "\
520 The value of this entry should be a number.
521 Any articles with a score lower than this number will be marked as
522 read and removed from the summary buffer.")
524 (thread-mark-and-expunge (number :tag
"Thread-mark-and-expunge") "\
525 The value of this entry should be a number.
526 All articles that belong to a thread that has a total score below this
527 number will be marked as read and removed from the summary buffer.
528 `gnus-thread-score-function' says how to compute the total score
531 (files (repeat :inline t
:tag
"Files" file
) "\
532 The value of this entry should be any number of file names.
533 These files are assumed to be score files as well, and will be loaded
534 the same way this one was.")
536 (exclude-files (repeat :inline t
:tag
"Exclude-files" file
) "\
537 The clue of this entry should be any number of files.
538 These files will not be loaded, even though they would normally be so,
539 for some reason or other.")
541 (eval (sexp :tag
"Eval" :value nil
) "\
542 The value of this entry will be `eval'el.
543 This element will be ignored when handling global score files.")
545 (read-only (boolean :tag
"Read-only" :value t
) "\
546 Read-only score files will not be updated or saved.
547 Global score files should feature this atom.")
549 (orphan (number :tag
"Orphan") "\
550 The value of this entry should be a number.
551 Articles that do not have parents will get this number added to their
552 scores. Imagine you follow some high-volume newsgroup, like
553 `comp.lang.c'. Most likely you will only follow a few of the threads,
554 also want to see any new threads.
556 You can do this with the following two score file entries:
559 (mark-and-expunge -100)
561 When you enter the group the first time, you will only see the new
562 threads. You then raise the score of the threads that you find
563 interesting (with `I T' or `I S'), and ignore (`C y') the rest.
564 Next time you enter the group, you will see new articles in the
565 interesting threads, plus any new threads.
567 I.e.---the orphan score atom is for high-volume groups where there
568 exist a few interesting threads which can't be found automatically
569 by ordinary scoring rules.")
571 (adapt (choice :tag
"Adapt"
575 :hide-front-space t
)) "\
576 This entry controls the adaptive scoring.
577 If it is t, the default adaptive scoring rules will be used. If it
578 is `ignore', no adaptive scoring will be performed on this group. If
579 it is a list, this list will be used as the adaptive scoring rules.
580 If it isn't present, or is something other than t or `ignore', the
581 default adaptive scoring rules will be used. If you want to use
582 adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring'
583 to t, and insert an `(adapt ignore)' in the groups where you do not
584 want adaptive scoring. If you only want adaptive scoring in a few
585 groups, you'd set `gnus-use-adaptive-scoring' to nil, and insert
586 `(adapt t)' in the score files of the groups where you want it.")
588 (adapt-file (file :tag
"Adapt-file") "\
589 All adaptive score entries will go to the file named by this entry.
590 It will also be applied when entering the group. This atom might
591 be handy if you want to adapt on several groups at once, using the
592 same adaptive file for a number of groups.")
594 (local (repeat :tag
"Local"
595 (group :value
(nil nil
)
596 (symbol :tag
"Variable")
597 (sexp :tag
"Value"))) "\
598 The value of this entry should be a list of `(VAR VALUE)' pairs.
599 Each VAR will be made buffer-local to the current summary buffer,
600 and set to the value specified. This is a convenient, if somewhat
601 strange, way of setting variables in some groups if you don't like
603 (touched (sexp :format
"Touched\n") "Internal variable."))
604 "Alist of valid symbolic score parameters.
606 Each entry has the form (NAME TYPE DOC), where NAME is the parameter
607 itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a
608 documentation string for the parameter.")
610 (define-widget 'gnus-score-string
'group
611 "Edit score entries for string-valued headers."
612 :convert-widget
'gnus-score-string-convert
)
614 (defun gnus-score-string-convert (widget)
615 ;; Set args appropriately.
616 (let* ((tag (widget-get widget
:tag
))
617 (item `(const :format
"" :value
,(downcase tag
)))
618 (match '(string :tag
"Match"))
619 (score '(choice :tag
"Score"
620 (const :tag
"default" nil
)
621 (integer :format
"%v"
622 :hide-front-space t
)))
623 (expire '(choice :tag
"Expire"
624 (const :tag
"off" nil
)
625 (integer :format
"%v"
626 :hide-front-space t
)))
627 (type '(choice :tag
"Type"
629 ;; I should really create a forgiving :match
630 ;; function for each type below, that only
631 ;; looked at the first letter.
632 (const :tag
"Regexp" r
)
633 (const :tag
"Regexp (fixed case)" R
)
634 (const :tag
"Substring" s
)
635 (const :tag
"Substring (fixed case)" S
)
636 (const :tag
"Exact" e
)
637 (const :tag
"Exact (fixed case)" E
)
638 (const :tag
"Word" w
)
639 (const :tag
"Word (fixed case)" W
)
640 (const :tag
"default" nil
)))
641 (group `(group ,match
,score
,expire
,type
))
642 (doc (concat (or (widget-get widget
:doc
)
643 (concat "Change score based on the " tag
646 You can have an arbitrary number of score entries for this header,
647 each score entry has four elements:
649 1. The \"match element\". This should be the string to look for in the
652 2. The \"score element\". This number should be an integer in the
653 neginf to posinf interval. This number is added to the score
654 of the article if the match is successful. If this element is
655 not present, the `gnus-score-interactive-default-score' number
656 will be used instead. This is 1000 by default.
658 3. The \"date element\". This date says when the last time this score
659 entry matched, which provides a mechanism for expiring the
660 score entries. It this element is not present, the score
661 entry is permanent. The date is represented by the number of
662 days since December 31, 1 ce.
664 4. The \"type element\". This element specifies what function should
665 be used to see whether this score entry matches the article.
667 There are the regexp, as well as substring types, and exact match,
668 and word match types. If this element is not present, Gnus will
669 assume that substring matching should be used. There is case
670 sensitive variants of all match types.")))
671 (widget-put widget
:args
`(,item
676 :format
"%t:\n%h%v%i\n\n"
678 :value
("" nil nil s
)
683 (define-widget 'gnus-score-integer
'group
684 "Edit score entries for integer-valued headers."
685 :convert-widget
'gnus-score-integer-convert
)
687 (defun gnus-score-integer-convert (widget)
688 ;; Set args appropriately.
689 (let* ((tag (widget-get widget
:tag
))
690 (item `(const :format
"" :value
,(downcase tag
)))
691 (match '(integer :tag
"Match"))
692 (score '(choice :tag
"Score"
693 (const :tag
"default" nil
)
694 (integer :format
"%v"
695 :hide-front-space t
)))
696 (expire '(choice :tag
"Expire"
697 (const :tag
"off" nil
)
698 (integer :format
"%v"
699 :hide-front-space t
)))
700 (type '(choice :tag
"Type"
707 (group `(group ,match
,score
,expire
,type
))
708 (doc (concat (or (widget-get widget
:doc
)
709 (concat "Change score based on the " tag
711 (widget-put widget
:args
`(,item
716 :format
"%t:\n%h%v%i\n\n"
720 (define-widget 'gnus-score-date
'group
721 "Edit score entries for date-valued headers."
722 :convert-widget
'gnus-score-date-convert
)
724 (defun gnus-score-date-convert (widget)
725 ;; Set args appropriately.
726 (let* ((tag (widget-get widget
:tag
))
727 (item `(const :format
"" :value
,(downcase tag
)))
728 (match '(string :tag
"Match"))
729 (score '(choice :tag
"Score"
730 (const :tag
"default" nil
)
731 (integer :format
"%v"
732 :hide-front-space t
)))
733 (expire '(choice :tag
"Expire"
734 (const :tag
"off" nil
)
735 (integer :format
"%v"
736 :hide-front-space t
)))
737 (type '(choice :tag
"Type"
743 (group `(group ,match
,score
,expire
,type
))
744 (doc (concat (or (widget-get widget
:doc
)
745 (concat "Change score based on the " tag
748 For the Date header we have three kinda silly match types: `before',
749 `at' and `after'. I can't really imagine this ever being useful, but,
750 like, it would feel kinda silly not to provide this function. Just in
751 case. You never know. Better safe than sorry. Once burnt, twice
752 shy. Don't judge a book by its cover. Never not have sex on a first
753 date. (I have been told that at least one person, and I quote,
754 \"found this function indispensable\", however.)
756 A more useful match type is `regexp'. With it, you can match the date
757 string using a regular expression. The date is normalized to ISO8601
758 compact format first---`YYYYMMDDTHHMMSS'. If you want to match all
759 articles that have been posted on April 1st in every year, you could
760 use `....0401.........' as a match string, for instance. (Note that
761 the date is kept in its original time zone, so this will match
762 articles that were posted when it was April 1st where the article was
763 posted from. Time zones are such wholesome fun for the whole family,
765 (widget-put widget
:args
`(,item
770 :format
"%t:\n%h%v%i\n\n"
774 (define-widget 'gnus-score-extra
'group
775 "Edit score entries for extra headers."
776 :convert-widget
'gnus-score-extra-convert
)
778 (defun gnus-score-extra-convert (widget)
779 ;; Set args appropriately.
780 (let* ((tag (widget-get widget
:tag
))
781 (item `(const :format
"" :value
,(downcase tag
)))
782 (match '(string :tag
"Match"))
783 (score '(choice :tag
"Score"
784 (const :tag
"default" nil
)
785 (integer :format
"%v"
786 :hide-front-space t
)))
787 (expire '(choice :tag
"Expire"
788 (const :tag
"off" nil
)
789 (integer :format
"%v"
790 :hide-front-space t
)))
791 (type '(choice :tag
"Type"
793 ;; I should really create a forgiving :match
794 ;; function for each type below, that only
795 ;; looked at the first letter.
796 (const :tag
"Regexp" r
)
797 (const :tag
"Regexp (fixed case)" R
)
798 (const :tag
"Substring" s
)
799 (const :tag
"Substring (fixed case)" S
)
800 (const :tag
"Exact" e
)
801 (const :tag
"Exact (fixed case)" E
)
802 (const :tag
"Word" w
)
803 (const :tag
"Word (fixed case)" W
)
804 (const :tag
"default" nil
)))
805 (header (if gnus-extra-headers
807 `(choice :tag
"Header"
808 ,@(mapcar (lambda (h)
809 (setq name
(symbol-name h
))
810 (list 'const
:tag name name
))
812 (string :tag
"Other" :format
"%v")))
813 '(string :tag
"Header")))
814 (group `(group ,match
,score
,expire
,type
,header
))
815 (doc (concat (or (widget-get widget
:doc
)
816 (concat "Change score based on the " tag
825 :format
"%t:\n%h%v%i\n\n"
828 ,(if gnus-extra-headers
829 (symbol-name (car gnus-extra-headers
))
835 (defvar gnus-custom-scores
)
836 (defvar gnus-custom-score-alist
)
838 (defun gnus-score-customize (file)
839 "Customize score file FILE.
840 When called interactively, FILE defaults to the current score file.
841 This can be changed using the `\\[gnus-score-change-score-file]' command."
842 (interactive (list gnus-current-score-file
))
844 (error "No score file for %s"
845 (gnus-group-decoded-name gnus-newsgroup-name
)))
846 (let ((scores (gnus-score-load file
))
847 (types (mapcar (lambda (entry)
848 `(group :format
"%v%h\n"
850 (const :format
"" ,(nth 0 entry
))
852 gnus-score-parameters
)))
854 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
855 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
857 (make-local-variable 'gnus-custom-score-alist
)
858 (setq gnus-custom-score-alist scores
)
859 (widget-insert "Customize the ")
860 (widget-create 'info-link
861 :help-echo
"Push me to learn more."
863 "(gnus)Score File Format")
864 (widget-insert " for\n\t")
866 (widget-insert "\nand press ")
867 (widget-create 'push-button
869 :help-echo
"Push me when done customizing."
870 :action
'gnus-score-customize-done
)
872 Check the [ ] for the entries you want to apply to this score file, then
873 edit the value to suit your taste. Don't forget to mark the checkbox,
874 if you do all your changes will be lost. ")
875 (widget-insert "\n\n")
876 (make-local-variable 'gnus-custom-scores
)
877 (setq gnus-custom-scores
878 (widget-create 'group
880 `(checklist :inline t
882 (gnus-score-string :tag
"From")
883 (gnus-score-string :tag
"Subject")
884 (gnus-score-string :tag
"References")
885 (gnus-score-string :tag
"Xref")
886 (gnus-score-extra :tag
"Extra")
887 (gnus-score-string :tag
"Message-ID")
888 (gnus-score-integer :tag
"Lines")
889 (gnus-score-integer :tag
"Chars")
890 (gnus-score-date :tag
"Date")
891 (gnus-score-string :tag
"Head"
893 Match all headers in the article.
895 Using one of `Head', `Body', `All' will slow down scoring considerable.
897 (gnus-score-string :tag
"Body"
899 Match the body sans header of the article.
901 Using one of `Head', `Body', `All' will slow down scoring considerable.
903 (gnus-score-string :tag
"All"
905 Match the entire article, including both headers and body.
907 Using one of `Head', `Body', `All' will slow down scoring
910 (gnus-score-string :tag
913 Score all followups to the specified authors.
915 This entry is somewhat special, in that it will match the `From:'
916 header, and affect the score of not only the matching articles, but
917 also all followups to the matching articles. This allows you
918 e.g. increase the score of followups to your own articles, or decrease
919 the score of followups to the articles of some known trouble-maker.
921 (gnus-score-string :tag
"Thread"
923 Add a score entry on all articles that are part of a thread.
925 This match key works along the same lines as the `Followup' match key.
926 If you say that you want to score on a (sub-)thread that is started by
927 an article with a `Message-ID' X, then you add a `thread' match. This
928 will add a new `thread' match for each article that has X in its
929 `References' header. (These new `thread' matches will use the
930 `Message-ID's of these matching articles.) This will ensure that you
931 can raise/lower the score of an entire thread, even though some
932 articles in the thread may not have complete `References' headers.
933 Note that using this may lead to nondeterministic scores of the
934 articles in the thread.
938 :tag
"Unknown entries"
940 (use-local-map widget-keymap
)
943 (defun gnus-score-customize-done (&rest ignore
)
944 "Reset the score alist with the present value."
945 (let ((alist gnus-custom-score-alist
)
946 (value (widget-value gnus-custom-scores
)))
947 (setcar alist
(car value
))
948 (setcdr alist
(cdr value
))
949 (gnus-score-set 'touched
'(t) alist
))
952 (defvar category-fields nil
)
953 (defvar gnus-agent-cat-name
)
954 (defvar gnus-agent-cat-score-file
)
955 (defvar gnus-agent-cat-length-when-short
)
956 (defvar gnus-agent-cat-length-when-long
)
957 (defvar gnus-agent-cat-low-score
)
958 (defvar gnus-agent-cat-high-score
)
959 (defvar gnus-agent-cat-enable-expiration
)
960 (defvar gnus-agent-cat-days-until-old
)
961 (defvar gnus-agent-cat-predicate
)
962 (defvar gnus-agent-cat-groups
)
963 (defvar gnus-agent-cat-enable-undownloaded-faces
)
965 (defun gnus-trim-whitespace (s)
966 (when (string-match "\\`[ \n\t]+" s
)
967 (setq s
(substring s
(match-end 0))))
968 (when (string-match "[ \n\t]+\\'" s
)
969 (setq s
(substring s
0 (match-beginning 0))))
972 (defmacro gnus-agent-cat-prepare-category-field
(parameter)
973 (let* ((entry (assq parameter gnus-agent-parameters
))
974 (field (nth 3 entry
)))
975 `(let* ((type (copy-sequence
976 (nth 1 (assq ',parameter gnus-agent-parameters
))))
978 (deflt (if (,field defaults
)
979 (concat " [" (gnus-trim-whitespace
980 (gnus-pp-to-string (,field defaults
)))
984 (if (eq (car type
) 'radio
)
985 (let* ((rtype (nreverse type
))
987 (while (listp (or (cadr rt
) 'not-list
))
990 (setcdr rt
(cons '(const :format
"Inherit " nil
) (cdr rt
)))
991 (setq type
(nreverse rtype
))))
994 (let ((tag (cdr (memq :tag type
))))
995 (when (string-match "\n" deflt
)
996 (while (progn (setq deflt
(replace-match "\n " t t
998 (string-match "\n" deflt
(match-end 0))))
999 (setq deflt
(concat "\n" deflt
)))
1001 (setcar tag
(concat (car tag
) deflt
))))
1003 (widget-insert "\n")
1006 (widget-create type
:value val
)
1007 (widget-create type
))
1008 symb
(set (make-local-variable ',field
) val
))
1010 (widget-put symb
:default val
)
1011 (widget-put symb
:accessor
',field
)
1012 (push symb category-fields
))))
1014 (defun gnus-agent-customize-category (category)
1015 "Edit the CATEGORY."
1016 (interactive (list (gnus-category-name)))
1017 (let ((info (assq category gnus-category-alist
))
1018 (defaults (list nil
'(agent-predicate . false
)
1019 (cons 'agent-enable-expiration
1020 gnus-agent-enable-expiration
)
1021 '(agent-days-until-old .
7)
1022 (cons 'agent-length-when-short
1023 gnus-agent-short-article
)
1024 (cons 'agent-length-when-long gnus-agent-long-article
)
1025 (cons 'agent-low-score gnus-agent-low-score
)
1026 (cons 'agent-high-score gnus-agent-high-score
))))
1028 (let ((old (get-buffer "*Gnus Agent Category Customize*")))
1030 (gnus-kill-buffer old
)))
1031 (switch-to-buffer (gnus-get-buffer-create
1032 "*Gnus Agent Category Customize*"))
1034 (let ((inhibit-read-only t
))
1036 (buffer-disable-undo)
1038 (let* ((name (gnus-agent-cat-name info
)))
1039 (widget-insert "Customize the Agent Category '")
1040 (widget-insert (symbol-name name
))
1041 (widget-insert "' and press ")
1045 (lambda (&rest ignore
)
1046 (let* ((info (assq gnus-agent-cat-name gnus-category-alist
))
1047 (widgets category-fields
))
1049 (let* ((widget (pop widgets
))
1050 (value (condition-case nil
(widget-value widget
) (error))))
1051 (eval `(setf (,(widget-get widget
:accessor
) ',info
)
1053 (gnus-category-write)
1054 (gnus-kill-buffer (current-buffer))
1055 (when (get-buffer gnus-category-buffer
)
1056 (switch-to-buffer (get-buffer gnus-category-buffer
))
1057 (gnus-category-list)))
1060 "\n Note: Empty fields default to the customizable global\
1063 (set (make-local-variable 'gnus-agent-cat-name
)
1066 (set (make-local-variable 'category-fields
) nil
)
1067 (gnus-agent-cat-prepare-category-field agent-predicate
)
1069 (gnus-agent-cat-prepare-category-field agent-score
)
1070 (gnus-agent-cat-prepare-category-field agent-short-article
)
1071 (gnus-agent-cat-prepare-category-field agent-long-article
)
1072 (gnus-agent-cat-prepare-category-field agent-low-score
)
1073 (gnus-agent-cat-prepare-category-field agent-high-score
)
1075 ;; The group list is NOT handled with
1076 ;; gnus-agent-cat-prepare-category-field as I don't want the
1077 ;; group list to appear when customizing a topic.
1078 (widget-insert "\n")
1082 (make-local-variable 'gnus-agent-cat-groups
)
1085 :format
"%[Select Member Groups%]\n%v" :value ignore
1086 (const :menu-tag
"do not change" :tag
"" :value ignore
)
1087 (checklist :entry-format
"%b %v"
1088 :menu-tag
"display group selectors"
1095 (gnus-info-group newsrc
)
1096 (gnus-agent-cat-groups info
))))
1097 (cdr gnus-newsrc-alist
)))
1098 ,@(mapcar (lambda (newsrc)
1099 `(const ,(gnus-info-group newsrc
)))
1100 (cdr gnus-newsrc-alist
))))))))
1102 (widget-put symb
:default
(gnus-agent-cat-groups info
))
1103 (widget-put symb
:accessor
'gnus-agent-cat-groups
)
1104 (push symb category-fields
))
1106 (widget-insert "\nExpiration Settings ")
1108 (gnus-agent-cat-prepare-category-field agent-enable-expiration
)
1109 (gnus-agent-cat-prepare-category-field agent-days-until-old
)
1111 (widget-insert "\nVisual Settings ")
1113 (gnus-agent-cat-prepare-category-field agent-enable-undownloaded-faces
)
1115 (use-local-map widget-keymap
)
1117 (buffer-enable-undo))))
1123 ;;; gnus-cus.el ends here