gnus-cus.el 41 KB

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