1;;; gnus-cus.el --- customization commands for Gnus 2 3;; Copyright (C) 1996, 1999, 2000, 2001, 2002, 2003, 2004, 4;; 2005, 2006, 2007 Free Software Foundation, Inc. 5 6;; Author: Per Abrahamsen <abraham@dina.kvl.dk> 7;; Keywords: news 8 9;; This file is part of GNU Emacs. 10 11;; GNU Emacs is free software; you can redistribute it and/or modify 12;; it under the terms of the GNU General Public License as published by 13;; the Free Software Foundation; either version 2, or (at your option) 14;; any later version. 15 16;; GNU Emacs is distributed in the hope that it will be useful, 17;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19;; GNU General Public License for more details. 20 21;; You should have received a copy of the GNU General Public License 22;; along with GNU Emacs; see the file COPYING. If not, write to the 23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 24;; Boston, MA 02110-1301, USA. 25 26;;; Commentary: 27 28;;; Code: 29 30(require 'wid-edit) 31(require 'gnus) 32(require 'gnus-agent) 33(require 'gnus-score) 34(require 'gnus-topic) 35(require 'gnus-art) 36 37;;; Widgets: 38 39(defun gnus-custom-mode () 40 "Major mode for editing Gnus customization buffers. 41 42The following commands are available: 43 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. 48 49Entry to this mode calls the value of `gnus-custom-mode-hook' 50if 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 ;; Emacs 21 stuff: 56 (when (and (facep 'custom-button-face) 57 (facep 'custom-button-pressed-face)) 58 (set (make-local-variable 'widget-button-face) 59 'custom-button-face) 60 (set (make-local-variable 'widget-button-pressed-face) 61 'custom-button-pressed-face) 62 (set (make-local-variable 'widget-mouse-face) 63 'custom-button-pressed-face)) 64 (when (and (boundp 'custom-raised-buttons) 65 (symbol-value 'custom-raised-buttons)) 66 (set (make-local-variable 'widget-push-button-prefix) "") 67 (set (make-local-variable 'widget-push-button-suffix) "") 68 (set (make-local-variable 'widget-link-prefix) "") 69 (set (make-local-variable 'widget-link-suffix) "")) 70 (gnus-run-mode-hooks 'gnus-custom-mode-hook)) 71 72;;; Group Customization: 73 74(defconst gnus-group-parameters 75 '((extra-aliases (choice 76 :tag "Extra Aliases" 77 (list 78 :tag "List" 79 (editable-list 80 :inline t 81 (gnus-email-address :tag "Address"))) 82 (gnus-email-address :tag "Address")) "\ 83Store messages posted from or to this address in this group. 84 85You must be using gnus-group-split for this to work. The VALUE of the 86nnmail-split-fancy SPLIT generated for this group will match these 87addresses.") 88 89 (split-regexp (regexp :tag "gnus-group-split Regular Expression") "\ 90Like gnus-group-split Address, but expects a regular expression.") 91 92 (split-exclude (list :tag "gnus-group-split Restricts" 93 (editable-list 94 :inline t (regexp :tag "Restrict"))) "\ 95Regular expression that cancels gnus-group-split matches. 96 97Each entry is added to the nnmail-split-fancy SPLIT as a separate 98RESTRICT clause.") 99 100 (split-spec (choice :tag "gnus-group-split Overrider" 101 (sexp :tag "Fancy Split") 102 (const :tag "Catch All" catch-all) 103 (const :tag "Ignore" nil)) "\ 104Override all other gnus-group-split fields. 105 106In `Fancy Split', you can enter any nnmail-split-fancy SPLIT. Note 107that the name of this group won't be automatically assumed, you have 108to add it to the SPLITs yourself. This means you can use such splits 109to split messages to other groups too. 110 111If you select `Catch All', this group will get postings for any 112messages not matched in any other group. It overrides the variable 113gnus-group-split-default-catch-all-group. 114 115Selecting `Ignore' forces no SPLIT to be generated for this group, 116disabling all other gnus-group-split fields.") 117 118 (broken-reply-to (const :tag "Broken Reply To" t) "\ 119Ignore `Reply-To' headers in this group. 120 121That can be useful if you're reading a mailing list group where the 122listserv has inserted `Reply-To' headers that point back to the 123listserv itself. This is broken behavior. So there!") 124 125 (to-group (string :tag "To Group") "\ 126All posts will be sent to the specified group.") 127 128 (gcc-self (choice :tag "GCC" 129 :value t 130 (const :tag "To current group" t) 131 (const none) 132 (string :format "%v" :hide-front-space t)) "\ 133Specify default value for GCC header. 134 135If this symbol is present in the group parameter list and set to t, 136new composed messages will be `Gcc''d to the current group. If it is 137present and set to `none', no `Gcc:' header will be generated, if it 138is present and a string, this string will be inserted literally as a 139`gcc' header (this symbol takes precedence over any default `Gcc' 140rules as described later).") 141 142 (expiry-wait (choice :tag "Expire Wait" 143 :value never 144 (const never) 145 (const immediate) 146 (number :hide-front-space t 147 :format "%v")) "\ 148When to expire. 149 150Overrides any `nnmail-expiry-wait' and `nnmail-expiry-wait-function' 151when expiring expirable messages. The value can either be a number of 152days (not necessarily an integer) or the symbols `never' or 153`immediate'.") 154 155 (expiry-target (choice :tag "Expiry Target" 156 :value delete 157 (const delete) 158 (function :format "%v" nnmail-) 159 string) "\ 160Where expired messages end up. 161 162Overrides `nnmail-expiry-target'.") 163 164 (score-file (file :tag "Score File") "\ 165Make the specified file into the current score file. 166This means that all score commands you issue will end up in this file.") 167 168 (adapt-file (file :tag "Adapt File") "\ 169Make the specified file into the current adaptive file. 170All adaptive score entries will be put into this file.") 171 172 (admin-address (gnus-email-address :tag "Admin Address") "\ 173Administration address for a mailing list. 174 175When unsubscribing to a mailing list you should never send the 176unsubscription notice to the mailing list itself. Instead, you'd 177send messages to the administrative address. This parameter allows 178you to put the admin address somewhere convenient.") 179 180 (display (choice :tag "Display" 181 :value default 182 (const all) 183 (integer) 184 (const default) 185 (sexp :tag "Other")) "\ 186Which articles to display on entering the group. 187 188`all' 189 Display all articles, both read and unread. 190 191`integer' 192 Display the last NUMBER articles in the group. This is the same as 193 entering the group with C-u NUMBER. 194 195`default' 196 Display the default visible articles, which normally includes 197 unread and ticked articles. 198 199`Other' 200 Display the articles that satisfy the S-expression. The S-expression 201 should be in an array form.") 202 203 (comment (string :tag "Comment") "\ 204An arbitrary comment on the group.") 205 206 (visible (const :tag "Permanently visible" t) "\ 207Always display this group, even when there are no unread articles in it.") 208 209 (highlight-words 210 (choice :tag "Highlight words" 211 :value nil 212 (repeat (list (regexp :tag "Highlight regexp") 213 (number :tag "Group for entire word" 0) 214 (number :tag "Group for displayed part" 0) 215 (symbol :tag "Face" 216 gnus-emphasis-highlight-words)))) 217 "highlight regexps. 218See `gnus-emphasis-alist'.") 219 220 (posting-style 221 (choice :tag "Posting style" 222 :value nil 223 (repeat (list 224 (choice :tag "Type" 225 :value nil 226 (const signature) 227 (const signature-file) 228 (const organization) 229 (const address) 230 (const x-face-file) 231 (const name) 232 (const body) 233 (symbol) 234 (string :tag "Header")) 235 (string :format "%v")))) 236 "post style. 237See `gnus-posting-styles'.")) 238 "Alist of valid group or topic parameters. 239 240Each entry has the form (NAME TYPE DOC), where NAME is the parameter 241itself (a symbol), TYPE is the parameters type (a sexp widget), and 242DOC is a documentation string for the parameter.") 243 244(defconst gnus-extra-topic-parameters 245 '((subscribe (regexp :tag "Subscribe") "\ 246If `gnus-subscribe-newsgroup-method' or 247`gnus-subscribe-options-newsgroup-method' is set to 248`gnus-subscribe-topics', new groups that matches this regexp will 249automatically be subscribed to this topic") 250 (subscribe-level (integer :tag "Subscribe Level" :value 1) "\ 251If this topic parameter is set, when new groups are subscribed 252automatically under this topic (via the `subscribe' topic parameter) 253assign this level to the group, rather than the default level 254set in `gnus-level-default-subscribed'")) 255 "Alist of topic parameters that are not also group parameters. 256 257Each entry has the form (NAME TYPE DOC), where NAME is the parameter 258itself (a symbol), TYPE is the parameters type (a sexp widget), and 259DOC is a documentation string for the parameter.") 260 261(defconst gnus-extra-group-parameters 262 '((uidvalidity (string :tag "IMAP uidvalidity") "\ 263Server-assigned value attached to IMAP groups, used to maintain consistency.")) 264 "Alist of group parameters that are not also topic parameters. 265 266Each entry has the form (NAME TYPE DOC), where NAME is the parameter 267itself (a symbol), TYPE is the parameters type (a sexp widget), and 268DOC is a documentation string for the parameter.") 269 270(eval-and-compile 271 (defconst gnus-agent-parameters 272 '((agent-predicate 273 (sexp :tag "Selection Predicate" :value false) 274 "Predicate used to automatically select articles for downloading." 275 gnus-agent-cat-predicate) 276 (agent-score 277 (choice :tag "Score File" :value nil 278 (const file :tag "Use group's score files") 279 (repeat (list (string :format "%v" :tag "File name")))) 280 "Which score files to use when using score to select articles to fetch. 281 282 `nil' 283 All articles will be scored to zero (0). 284 285 `file' 286 The group's score files will be used to score the articles. 287 288 `List' 289 A list of score file names." 290 gnus-agent-cat-score-file) 291 (agent-short-article 292 (integer :tag "Max Length of Short Article" :value "") 293 "The SHORT predicate will evaluate to true when the article is 294shorter than this length." gnus-agent-cat-length-when-short) 295 (agent-long-article 296 (integer :tag "Min Length of Long Article" :value "") 297 "The LONG predicate will evaluate to true when the article is 298longer than this length." gnus-agent-cat-length-when-long) 299 (agent-low-score 300 (integer :tag "Low Score Limit" :value "") 301 "The LOW predicate will evaluate to true when the article scores 302lower than this limit." gnus-agent-cat-low-score) 303 (agent-high-score 304 (integer :tag "High Score Limit" :value "") 305 "The HIGH predicate will evaluate to true when the article scores 306higher than this limit." gnus-agent-cat-high-score) 307 (agent-days-until-old 308 (integer :tag "Days Until Old" :value "") 309 "The OLD predicate will evaluate to true when the fetched article 310has been stored locally for at least this many days." 311 gnus-agent-cat-days-until-old) 312 (agent-enable-expiration 313 (radio :tag "Expire in this Group or Topic" :value nil 314 (const :format "Enable " ENABLE) 315 (const :format "Disable " DISABLE)) 316 "\nEnable, or disable, agent expiration in this group or topic." 317 gnus-agent-cat-enable-expiration) 318 (agent-enable-undownloaded-faces 319 (boolean :tag "Enable Agent Faces") 320 "Have the summary buffer use the agent's undownloaded faces. 321These faces, when enabled, act as a warning that an article has not 322been fetched into either the agent nor the cache. This is of most use 323to users who use the agent as a cache (i.e. they only operate on 324articles that have been downloaded). Leave disabled to display normal 325article faces even when the article hasn't been downloaded." 326gnus-agent-cat-enable-undownloaded-faces)) 327 "Alist of group parameters that are not also topic parameters. 328 329Each entry has the form (NAME TYPE DOC ACCESSOR), where NAME is the 330parameter itself (a symbol), TYPE is the parameters type (a sexp 331widget), DOC is a documentation string for the parameter, and ACCESSOR 332is a function (symbol) that extracts the current value from the 333category.")) 334 335(defvar gnus-custom-params) 336(defvar gnus-custom-method) 337(defvar gnus-custom-group) 338(defvar gnus-custom-topic) 339 340(defun gnus-group-customize (group &optional topic) 341 "Edit the group or topic on the current line." 342 (interactive (list (gnus-group-group-name) (gnus-group-topic-name))) 343 (let (info 344 (types (mapcar (lambda (entry) 345 `(cons :format "%v%h\n" 346 :doc ,(nth 2 entry) 347 (const :format "" ,(nth 0 entry)) 348 ,(nth 1 entry))) 349 (append (reverse gnus-group-parameters-more) 350 gnus-group-parameters 351 (if group 352 gnus-extra-group-parameters 353 gnus-extra-topic-parameters)))) 354 (agent (mapcar (lambda (entry) 355 (let ((type (nth 1 entry)) 356 vcons) 357 (if (listp type) 358 (setq type (copy-sequence type))) 359 360 (setq vcons (cdr (memq :value type))) 361 362 (if (symbolp (car vcons)) 363 (condition-case nil 364 (setcar vcons (symbol-value (car vcons))) 365 (error))) 366 `(cons :format "%v%h\n" 367 :doc ,(nth 2 entry) 368 (const :format "" ,(nth 0 entry)) 369 ,type))) 370 (if gnus-agent 371 gnus-agent-parameters)))) 372 (unless (or group topic) 373 (error "No group on current line")) 374 (when (and group topic) 375 (error "Both a group an topic on current line")) 376 (unless (or topic (setq info (gnus-get-info group))) 377 (error "Killed group; can't be edited")) 378 ;; Ready. 379 (gnus-kill-buffer (gnus-get-buffer-create "*Gnus Customize*")) 380 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*")) 381 (gnus-custom-mode) 382 (make-local-variable 'gnus-custom-group) 383 (setq gnus-custom-group group) 384 (make-local-variable 'gnus-custom-topic) 385 (setq gnus-custom-topic topic) 386 (buffer-disable-undo) 387 (widget-insert "Customize the ") 388 (if group 389 (widget-create 'info-link 390 :help-echo "Push me to learn more." 391 :tag "group parameters" 392 "(gnus)Group Parameters") 393 (widget-create 'info-link 394 :help-echo "Push me to learn more." 395 :tag "topic parameters" 396 "(gnus)Topic Parameters")) 397 (widget-insert " for <") 398 (widget-insert (gnus-group-decoded-name (or group topic))) 399 (widget-insert "> and press ") 400 (widget-create 'push-button 401 :tag "done" 402 :help-echo "Push me when done customizing." 403 :action 'gnus-group-customize-done) 404 (widget-insert ".\n\n") 405 (make-local-variable 'gnus-custom-params) 406 407 (let ((values (if group 408 (gnus-info-params info) 409 (gnus-topic-parameters topic)))) 410 411 ;; The parameters in values may contain duplicates. This is 412 ;; normally OK as assq returns the first. However, right here 413 ;; every duplicate ends up being displayed. So, rather than 414 ;; display them, remove them from the list. 415 416 (let ((tmp (setq values (gnus-copy-sequence values))) 417 elem) 418 (while (cdr tmp) 419 (while (setq elem (assq (caar tmp) (cdr tmp))) 420 (delq elem tmp)) 421 (setq tmp (cdr tmp)))) 422 423 (setq gnus-custom-params 424 (apply 'widget-create 'group 425 :value values 426 (delq nil 427 (list `(set :inline t 428 :greedy t 429 :tag "Parameters" 430 :format "%t:\n%h%v" 431 :doc "\ 432These special parameters are recognized by Gnus. 433Check the [ ] for the parameters you want to apply to this group or 434to the groups in this topic, then edit the value to suit your taste." 435 ,@types) 436 (when gnus-agent 437 `(set :inline t 438 :greedy t 439 :tag "Agent Parameters" 440 :format "%t:\n%h%v" 441 :doc "\ These agent parameters are 442recognized by Gnus. They control article selection and expiration for 443use in the unplugged cache. Check the [ ] for the parameters you want 444to apply to this group or to the groups in this topic, then edit the 445value to suit your taste. 446 447For those interested, group parameters override topic parameters while 448topic parameters override agent category parameters. Underlying 449category parameters are the customizable variables." ,@agent)) 450 '(repeat :inline t 451 :tag "Variables" 452 :format "%t:\n%h%v%i\n\n" 453 :doc "\ 454Set variables local to the group you are entering. 455 456If you want to turn threading off in `news.answers', you could put 457`(gnus-show-threads nil)' in the group parameters of that group. 458`gnus-show-threads' will be made into a local variable in the summary 459buffer you enter, and the form nil will be `eval'ed there. 460 461This can also be used as a group-specific hook function, if you'd 462like. If you want to hear a beep when you enter a group, you could 463put something like `(dummy-variable (ding))' in the parameters of that 464group. `dummy-variable' will be set to the result of the `(ding)' 465form, but who cares?" 466 (list :format "%v" :value (nil nil) 467 (symbol :tag "Variable") 468 (sexp :tag 469 "Value"))) 470 471 '(repeat :inline t 472 :tag "Unknown entries" 473 sexp)))))) 474 (when group 475 (widget-insert "\n\nYou can also edit the ") 476 (widget-create 'info-link 477 :tag "select method" 478 :help-echo "Push me to learn more about select methods." 479 "(gnus)Select Methods") 480 (widget-insert " for the group.\n") 481 (setq gnus-custom-method 482 (widget-create 'sexp 483 :tag "Method" 484 :value (gnus-info-method info)))) 485 (use-local-map widget-keymap) 486 (widget-setup) 487 (buffer-enable-undo) 488 (goto-char (point-min)))) 489 490(defun gnus-group-customize-done (&rest ignore) 491 "Apply changes and bury the buffer." 492 (interactive) 493 (if gnus-custom-topic 494 (gnus-topic-set-parameters gnus-custom-topic 495 (widget-value gnus-custom-params)) 496 (gnus-group-edit-group-done 'params gnus-custom-group 497 (widget-value gnus-custom-params)) 498 (gnus-group-edit-group-done 'method gnus-custom-group 499 (widget-value gnus-custom-method))) 500 (bury-buffer)) 501 502;;; Score Customization: 503 504(defconst gnus-score-parameters 505 '((mark (number :tag "Mark") "\ 506The value of this entry should be a number. 507Any articles with a score lower than this number will be marked as read.") 508 509 (expunge (number :tag "Expunge") "\ 510The value of this entry should be a number. 511Any articles with a score lower than this number will be removed from 512the summary buffer.") 513 514 (mark-and-expunge (number :tag "Mark-and-expunge") "\ 515The value of this entry should be a number. 516Any articles with a score lower than this number will be marked as 517read and removed from the summary buffer.") 518 519 (thread-mark-and-expunge (number :tag "Thread-mark-and-expunge") "\ 520The value of this entry should be a number. 521All articles that belong to a thread that has a total score below this 522number will be marked as read and removed from the summary buffer. 523`gnus-thread-score-function' says how to compute the total score 524for a thread.") 525 526 (files (repeat :inline t :tag "Files" file) "\ 527The value of this entry should be any number of file names. 528These files are assumed to be score files as well, and will be loaded 529the same way this one was.") 530 531 (exclude-files (repeat :inline t :tag "Exclude-files" file) "\ 532The clue of this entry should be any number of files. 533These files will not be loaded, even though they would normally be so, 534for some reason or other.") 535 536 (eval (sexp :tag "Eval" :value nil) "\ 537The value of this entry will be `eval'el. 538This element will be ignored when handling global score files.") 539 540 (read-only (boolean :tag "Read-only" :value t) "\ 541Read-only score files will not be updated or saved. 542Global score files should feature this atom.") 543 544 (orphan (number :tag "Orphan") "\ 545The value of this entry should be a number. 546Articles that do not have parents will get this number added to their 547scores. Imagine you follow some high-volume newsgroup, like 548`comp.lang.c'. Most likely you will only follow a few of the threads, 549also want to see any new threads. 550 551You can do this with the following two score file entries: 552 553 (orphan -500) 554 (mark-and-expunge -100) 555 556When you enter the group the first time, you will only see the new 557threads. You then raise the score of the threads that you find 558interesting (with `I T' or `I S'), and ignore (`C y') the rest. 559Next time you enter the group, you will see new articles in the 560interesting threads, plus any new threads. 561 562I.e.---the orphan score atom is for high-volume groups where there 563exist a few interesting threads which can't be found automatically 564by ordinary scoring rules.") 565 566 (adapt (choice :tag "Adapt" 567 (const t) 568 (const ignore) 569 (sexp :format "%v" 570 :hide-front-space t)) "\ 571This entry controls the adaptive scoring. 572If it is t, the default adaptive scoring rules will be used. If it 573is `ignore', no adaptive scoring will be performed on this group. If 574it is a list, this list will be used as the adaptive scoring rules. 575If it isn't present, or is something other than t or `ignore', the 576default adaptive scoring rules will be used. If you want to use 577adaptive scoring on most groups, you'd set `gnus-use-adaptive-scoring' 578to t, and insert an `(adapt ignore)' in the groups where you do not 579want adaptive scoring. If you only want adaptive scoring in a few 580groups, you'd set `gnus-use-adaptive-scoring' to nil, and insert 581`(adapt t)' in the score files of the groups where you want it.") 582 583 (adapt-file (file :tag "Adapt-file") "\ 584All adaptive score entries will go to the file named by this entry. 585It will also be applied when entering the group. This atom might 586be handy if you want to adapt on several groups at once, using the 587same adaptive file for a number of groups.") 588 589 (local (repeat :tag "Local" 590 (group :value (nil nil) 591 (symbol :tag "Variable") 592 (sexp :tag "Value"))) "\ 593The value of this entry should be a list of `(VAR VALUE)' pairs. 594Each VAR will be made buffer-local to the current summary buffer, 595and set to the value specified. This is a convenient, if somewhat 596strange, way of setting variables in some groups if you don't like 597hooks much.") 598 (touched (sexp :format "Touched\n") "Internal variable.")) 599 "Alist of valid symbolic score parameters. 600 601Each entry has the form (NAME TYPE DOC), where NAME is the parameter 602itself (a symbol), TYPE is the parameters type (a sexp widget), and DOC is a 603documentation string for the parameter.") 604 605(define-widget 'gnus-score-string 'group 606 "Edit score entries for string-valued headers." 607 :convert-widget 'gnus-score-string-convert) 608 609(defun gnus-score-string-convert (widget) 610 ;; Set args appropriately. 611 (let* ((tag (widget-get widget :tag)) 612 (item `(const :format "" :value ,(downcase tag))) 613 (match '(string :tag "Match")) 614 (score '(choice :tag "Score" 615 (const :tag "default" nil) 616 (integer :format "%v" 617 :hide-front-space t))) 618 (expire '(choice :tag "Expire" 619 (const :tag "off" nil) 620 (integer :format "%v" 621 :hide-front-space t))) 622 (type '(choice :tag "Type" 623 :value s 624 ;; I should really create a forgiving :match 625 ;; function for each type below, that only 626 ;; looked at the first letter. 627 (const :tag "Regexp" r) 628 (const :tag "Regexp (fixed case)" R) 629 (const :tag "Substring" s) 630 (const :tag "Substring (fixed case)" S) 631 (const :tag "Exact" e) 632 (const :tag "Exact (fixed case)" E) 633 (const :tag "Word" w) 634 (const :tag "Word (fixed case)" W) 635 (const :tag "default" nil))) 636 (group `(group ,match ,score ,expire ,type)) 637 (doc (concat (or (widget-get widget :doc) 638 (concat "Change score based on the " tag 639 " header.\n")) 640 " 641You can have an arbitrary number of score entries for this header, 642each score entry has four elements: 643 6441. The \"match element\". This should be the string to look for in the 645 header. 646 6472. The \"score element\". This number should be an integer in the 648 neginf to posinf interval. This number is added to the score 649 of the article if the match is successful. If this element is 650 not present, the `gnus-score-interactive-default-score' number 651 will be used instead. This is 1000 by default. 652 6533. The \"date element\". This date says when the last time this score 654 entry matched, which provides a mechanism for expiring the 655 score entries. It this element is not present, the score 656 entry is permanent. The date is represented by the number of 657 days since December 31, 1 ce. 658 6594. The \"type element\". This element specifies what function should 660 be used to see whether this score entry matches the article. 661 662 There are the regexp, as well as substring types, and exact match, 663 and word match types. If this element is not present, Gnus will 664 assume that substring matching should be used. There is case 665 sensitive variants of all match types."))) 666 (widget-put widget :args `(,item 667 (repeat :inline t 668 :indent 0 669 :tag ,tag 670 :doc ,doc 671 :format "%t:\n%h%v%i\n\n" 672 (choice :format "%v" 673 :value ("" nil nil s) 674 ,group 675 sexp))))) 676 widget) 677 678(define-widget 'gnus-score-integer 'group 679 "Edit score entries for integer-valued headers." 680 :convert-widget 'gnus-score-integer-convert) 681 682(defun gnus-score-integer-convert (widget) 683 ;; Set args appropriately. 684 (let* ((tag (widget-get widget :tag)) 685 (item `(const :format "" :value ,(downcase tag))) 686 (match '(integer :tag "Match")) 687 (score '(choice :tag "Score" 688 (const :tag "default" nil) 689 (integer :format "%v" 690 :hide-front-space t))) 691 (expire '(choice :tag "Expire" 692 (const :tag "off" nil) 693 (integer :format "%v" 694 :hide-front-space t))) 695 (type '(choice :tag "Type" 696 :value < 697 (const <) 698 (const >) 699 (const =) 700 (const >=) 701 (const <=))) 702 (group `(group ,match ,score ,expire ,type)) 703 (doc (concat (or (widget-get widget :doc) 704 (concat "Change score based on the " tag 705 " header."))))) 706 (widget-put widget :args `(,item 707 (repeat :inline t 708 :indent 0 709 :tag ,tag 710 :doc ,doc 711 :format "%t:\n%h%v%i\n\n" 712 ,group)))) 713 widget) 714 715(define-widget 'gnus-score-date 'group 716 "Edit score entries for date-valued headers." 717 :convert-widget 'gnus-score-date-convert) 718 719(defun gnus-score-date-convert (widget) 720 ;; Set args appropriately. 721 (let* ((tag (widget-get widget :tag)) 722 (item `(const :format "" :value ,(downcase tag))) 723 (match '(string :tag "Match")) 724 (score '(choice :tag "Score" 725 (const :tag "default" nil) 726 (integer :format "%v" 727 :hide-front-space t))) 728 (expire '(choice :tag "Expire" 729 (const :tag "off" nil) 730 (integer :format "%v" 731 :hide-front-space t))) 732 (type '(choice :tag "Type" 733 :value regexp 734 (const regexp) 735 (const before) 736 (const at) 737 (const after))) 738 (group `(group ,match ,score ,expire ,type)) 739 (doc (concat (or (widget-get widget :doc) 740 (concat "Change score based on the " tag 741 " header.")) 742 " 743For the Date header we have three kinda silly match types: `before', 744`at' and `after'. I can't really imagine this ever being useful, but, 745like, it would feel kinda silly not to provide this function. Just in 746case. You never know. Better safe than sorry. Once burnt, twice 747shy. Don't judge a book by its cover. Never not have sex on a first 748date. (I have been told that at least one person, and I quote, 749\"found this function indispensable\", however.) 750 751A more useful match type is `regexp'. With it, you can match the date 752string using a regular expression. The date is normalized to ISO8601 753compact format first---`YYYYMMDDTHHMMSS'. If you want to match all 754articles that have been posted on April 1st in every year, you could 755use `....0401.........' as a match string, for instance. (Note that 756the date is kept in its original time zone, so this will match 757articles that were posted when it was April 1st where the article was 758posted from. Time zones are such wholesome fun for the whole family, 759eh?"))) 760 (widget-put widget :args `(,item 761 (repeat :inline t 762 :indent 0 763 :tag ,tag 764 :doc ,doc 765 :format "%t:\n%h%v%i\n\n" 766 ,group)))) 767 widget) 768 769(defvar gnus-custom-scores) 770(defvar gnus-custom-score-alist) 771 772(defun gnus-score-customize (file) 773 "Customize score file FILE. 774When called interactively, FILE defaults to the current score file. 775This can be changed using the `\\[gnus-score-change-score-file]' command." 776 (interactive (list gnus-current-score-file)) 777 (unless file 778 (error "No score file for %s" 779 (gnus-group-decoded-name gnus-newsgroup-name))) 780 (let ((scores (gnus-score-load file)) 781 (types (mapcar (lambda (entry) 782 `(group :format "%v%h\n" 783 :doc ,(nth 2 entry) 784 (const :format "" ,(nth 0 entry)) 785 ,(nth 1 entry))) 786 gnus-score-parameters))) 787 ;; Ready. 788 (kill-buffer (gnus-get-buffer-create "*Gnus Customize*")) 789 (switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*")) 790 (gnus-custom-mode) 791 (make-local-variable 'gnus-custom-score-alist) 792 (setq gnus-custom-score-alist scores) 793 (widget-insert "Customize the ") 794 (widget-create 'info-link 795 :help-echo "Push me to learn more." 796 :tag "score entries" 797 "(gnus)Score File Format") 798 (widget-insert " for\n\t") 799 (widget-insert file) 800 (widget-insert "\nand press ") 801 (widget-create 'push-button 802 :tag "done" 803 :help-echo "Push me when done customizing." 804 :action 'gnus-score-customize-done) 805 (widget-insert ".\n 806Check the [ ] for the entries you want to apply to this score file, then 807edit the value to suit your taste. Don't forget to mark the checkbox, 808if you do all your changes will be lost. ") 809 (widget-create 'push-button 810 :action (lambda (&rest ignore) 811 (require 'gnus-audio) 812 (gnus-audio-play "Evil_Laugh.au")) 813 "Bhahahah!") 814 (widget-insert "\n\n") 815 (make-local-variable 'gnus-custom-scores) 816 (setq gnus-custom-scores 817 (widget-create 'group 818 :value scores 819 `(checklist :inline t 820 :greedy t 821 (gnus-score-string :tag "From") 822 (gnus-score-string :tag "Subject") 823 (gnus-score-string :tag "References") 824 (gnus-score-string :tag "Xref") 825 (gnus-score-string :tag "Extra") 826 (gnus-score-string :tag "Message-ID") 827 (gnus-score-integer :tag "Lines") 828 (gnus-score-integer :tag "Chars") 829 (gnus-score-date :tag "Date") 830 (gnus-score-string :tag "Head" 831 :doc "\ 832Match all headers in the article. 833 834Using one of `Head', `Body', `All' will slow down scoring considerable. 835") 836 (gnus-score-string :tag "Body" 837 :doc "\ 838Match the body sans header of the article. 839 840Using one of `Head', `Body', `All' will slow down scoring considerable. 841") 842 (gnus-score-string :tag "All" 843 :doc "\ 844Match the entire article, including both headers and body. 845 846Using one of `Head', `Body', `All' will slow down scoring 847considerable. 848") 849 (gnus-score-string :tag 850 "Followup" 851 :doc "\ 852Score all followups to the specified authors. 853 854This entry is somewhat special, in that it will match the `From:' 855header, and affect the score of not only the matching articles, but 856also all followups to the matching articles. This allows you 857e.g. increase the score of followups to your own articles, or decrease 858the score of followups to the articles of some known trouble-maker. 859") 860 (gnus-score-string :tag "Thread" 861 :doc "\ 862Add a score entry on all articles that are part of a thread. 863 864This match key works along the same lines as the `Followup' match key. 865If you say that you want to score on a (sub-)thread that is started by 866an article with a `Message-ID' X, then you add a `thread' match. This 867will add a new `thread' match for each article that has X in its 868`References' header. (These new `thread' matches will use the 869`Message-ID's of these matching articles.) This will ensure that you 870can raise/lower the score of an entire thread, even though some 871articles in the thread may not have complete `References' headers. 872Note that using this may lead to undeterministic scores of the 873articles in the thread. 874") 875 ,@types) 876 '(repeat :inline t 877 :tag "Unknown entries" 878 sexp))) 879 (use-local-map widget-keymap) 880 (widget-setup))) 881 882(defun gnus-score-customize-done (&rest ignore) 883 "Reset the score alist with the present value." 884 (let ((alist gnus-custom-score-alist) 885 (value (widget-value gnus-custom-scores))) 886 (setcar alist (car value)) 887 (setcdr alist (cdr value)) 888 (gnus-score-set 'touched '(t) alist)) 889 (bury-buffer)) 890 891(eval-when-compile 892 (defvar category-fields nil) 893 (defvar gnus-agent-cat-name) 894 (defvar gnus-agent-cat-score-file) 895 (defvar gnus-agent-cat-length-when-short) 896 (defvar gnus-agent-cat-length-when-long) 897 (defvar gnus-agent-cat-low-score) 898 (defvar gnus-agent-cat-high-score) 899 (defvar gnus-agent-cat-enable-expiration) 900 (defvar gnus-agent-cat-days-until-old) 901 (defvar gnus-agent-cat-predicate) 902 (defvar gnus-agent-cat-groups) 903 (defvar gnus-agent-cat-enable-undownloaded-faces) 904) 905 906(defun gnus-trim-whitespace (s) 907 (when (string-match "\\`[ \n\t]+" s) 908 (setq s (substring s (match-end 0)))) 909 (when (string-match "[ \n\t]+\\'" s) 910 (setq s (substring s 0 (match-beginning 0)))) 911 s) 912 913(defmacro gnus-agent-cat-prepare-category-field (parameter) 914 (let* ((entry (assq parameter gnus-agent-parameters)) 915 (field (nth 3 entry))) 916 `(let* ((type (copy-sequence 917 (nth 1 (assq ',parameter gnus-agent-parameters)))) 918 (val (,field info)) 919 (deflt (if (,field defaults) 920 (concat " [" (gnus-trim-whitespace 921 (gnus-pp-to-string (,field defaults))) 922 "]"))) 923 symb) 924 925 (if (eq (car type) 'radio) 926 (let* ((rtype (nreverse type)) 927 (rt rtype)) 928 (while (listp (or (cadr rt) 'not-list)) 929 (setq rt (cdr rt))) 930 931 (setcdr rt (cons '(const :format "Inherit " nil) (cdr rt))) 932 (setq type (nreverse rtype)))) 933 934 (if deflt 935 (let ((tag (cdr (memq :tag type)))) 936 (when (string-match "\n" deflt) 937 (while (progn (setq deflt (replace-match "\n " t t 938 deflt)) 939 (string-match "\n" deflt (match-end 0)))) 940 (setq deflt (concat "\n" deflt))) 941 942 (setcar tag (concat (car tag) deflt)))) 943 944 (widget-insert "\n") 945 946 (setq val (if val 947 (widget-create type :value val) 948 (widget-create type)) 949 symb (set (make-local-variable ',field) val)) 950 951 (widget-put symb :default val) 952 (widget-put symb :accessor ',field) 953 (push symb category-fields)))) 954 955(defun gnus-agent-customize-category (category) 956 "Edit the CATEGORY." 957 (interactive (list (gnus-category-name))) 958 (let ((info (assq category gnus-category-alist)) 959 (defaults (list nil '(agent-predicate . false) 960 (cons 'agent-enable-expiration 961 gnus-agent-enable-expiration) 962 '(agent-days-until-old . 7) 963 (cons 'agent-length-when-short 964 gnus-agent-short-article) 965 (cons 'agent-length-when-long gnus-agent-long-article) 966 (cons 'agent-low-score gnus-agent-low-score) 967 (cons 'agent-high-score gnus-agent-high-score)))) 968 969 (let ((old (get-buffer "*Gnus Agent Category Customize*"))) 970 (when old 971 (gnus-kill-buffer old))) 972 (switch-to-buffer (gnus-get-buffer-create 973 "*Gnus Agent Category Customize*")) 974 975 (let ((inhibit-read-only t)) 976 (gnus-custom-mode) 977 (buffer-disable-undo) 978 979 (let* ((name (gnus-agent-cat-name info))) 980 (widget-insert "Customize the Agent Category '") 981 (widget-insert (symbol-name name)) 982 (widget-insert "' and press ") 983 (widget-create 984 'push-button 985 :notify 986 '(lambda (&rest ignore) 987 (let* ((info (assq gnus-agent-cat-name gnus-category-alist)) 988 (widgets category-fields)) 989 (while widgets 990 (let* ((widget (pop widgets)) 991 (value (condition-case nil (widget-value widget) (error)))) 992 (eval `(setf (,(widget-get widget :accessor) ',info) 993 ',value))))) 994 (gnus-category-write) 995 (gnus-kill-buffer (current-buffer)) 996 (when (get-buffer gnus-category-buffer) 997 (switch-to-buffer (get-buffer gnus-category-buffer)) 998 (gnus-category-list))) 999 "Done") 1000 (widget-insert 1001 "\n Note: Empty fields default to the customizable global\ 1002 variables.\n\n") 1003 1004 (set (make-local-variable 'gnus-agent-cat-name) 1005 name)) 1006 1007 (set (make-local-variable 'category-fields) nil) 1008 (gnus-agent-cat-prepare-category-field agent-predicate) 1009 1010 (gnus-agent-cat-prepare-category-field agent-score) 1011 (gnus-agent-cat-prepare-category-field agent-short-article) 1012 (gnus-agent-cat-prepare-category-field agent-long-article) 1013 (gnus-agent-cat-prepare-category-field agent-low-score) 1014 (gnus-agent-cat-prepare-category-field agent-high-score) 1015 1016 ;; The group list is NOT handled with 1017 ;; gnus-agent-cat-prepare-category-field as I don't want the 1018 ;; group list to appear when customizing a topic. 1019 (widget-insert "\n") 1020 1021 (let ((symb 1022 (set 1023 (make-local-variable 'gnus-agent-cat-groups) 1024 (widget-create 1025 `(choice 1026 :format "%[Select Member Groups%]\n%v" :value ignore 1027 (const :menu-tag "do not change" :tag "" :value ignore) 1028 (checklist :entry-format "%b %v" 1029 :menu-tag "display group selectors" 1030 :greedy t 1031 :value 1032 ,(delq nil 1033 (mapcar 1034 (lambda (newsrc) 1035 (car (member 1036 (gnus-info-group newsrc) 1037 (gnus-agent-cat-groups info)))) 1038 (cdr gnus-newsrc-alist))) 1039 ,@(mapcar (lambda (newsrc) 1040 `(const ,(gnus-info-group newsrc))) 1041 (cdr gnus-newsrc-alist)))))))) 1042 1043 (widget-put symb :default (gnus-agent-cat-groups info)) 1044 (widget-put symb :accessor 'gnus-agent-cat-groups) 1045 (push symb category-fields)) 1046 1047 (widget-insert "\nExpiration Settings ") 1048 1049 (gnus-agent-cat-prepare-category-field agent-enable-expiration) 1050 (gnus-agent-cat-prepare-category-field agent-days-until-old) 1051 1052 (widget-insert "\nVisual Settings ") 1053 1054 (gnus-agent-cat-prepare-category-field agent-enable-undownloaded-faces) 1055 1056 (use-local-map widget-keymap) 1057 (widget-setup) 1058 (buffer-enable-undo)))) 1059 1060;;; The End: 1061 1062(provide 'gnus-cus) 1063 1064;;; arch-tag: a37c285a-49bc-4235-8244-804536effeaf 1065;;; gnus-cus.el ends here 1066