gnus-cus.el 41 KB

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