home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac_os2 / e31el3.zip / EMACS / 19.31 / LISP / GNUS.EL < prev    next >
Lisp/Scheme  |  1996-05-23  |  538KB  |  14,182 lines

  1. ;;; gnus.el --- a newsreader for GNU Emacs
  2.  
  3. ;; Copyright (C) 1987,88,89,90,93,94,95,96 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
  6. ;;    Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
  7. ;; Keywords: news
  8.  
  9. ;; This file is part of GNU Emacs.
  10.  
  11. ;; GNU Emacs is free software; you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ;; GNU General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  23. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; Although Gnus looks suspiciously like GNUS, it isn't quite the same
  29. ;; beast. Most internal structures have been changed. If you have
  30. ;; written packages that depend on any of the hash tables,
  31. ;; `gnus-newsrc-alist', `gnus-killed-assoc', marked lists, the .newsrc
  32. ;; buffer, or internal knowledge of the `nntp-header-' macros, or
  33. ;; dependence on the buffers having a certain format, your code will
  34. ;; fail.
  35.  
  36. ;;; Code:
  37.  
  38. (eval '(run-hooks 'gnus-load-hook))
  39.  
  40. (require 'mail-utils)
  41. (require 'timezone)
  42. (require 'nnheader)
  43.  
  44. ;; Site dependent variables. These variables should be defined in
  45. ;; paths.el.
  46.  
  47. (defvar gnus-default-nntp-server nil
  48.   "Specify a default NNTP server.
  49. This variable should be defined in paths.el, and should never be set
  50. by the user.
  51. If you want to change servers, you should use `gnus-select-method'.
  52. See the documentation to that variable.")
  53.  
  54. (defconst gnus-backup-default-subscribed-newsgroups 
  55.   '("news.announce.newusers" "news.groups.questions" "gnu.emacs.gnus")
  56.   "Default default new newsgroups the first time Gnus is run.
  57. Should be set in paths.el, and shouldn't be touched by the user.")
  58.  
  59. (defvar gnus-local-domain nil
  60.   "Local domain name without a host name.
  61. The DOMAINNAME environment variable is used instead if it is defined.
  62. If the `system-name' function returns the full Internet name, there is
  63. no need to set this variable.")
  64.  
  65. (defvar gnus-local-organization nil
  66.   "String with a description of what organization (if any) the user belongs to.
  67. The ORGANIZATION environment variable is used instead if it is defined.
  68. If this variable contains a function, this function will be called
  69. with the current newsgroup name as the argument. The function should
  70. return a string.
  71.  
  72. In any case, if the string (either in the variable, in the environment
  73. variable, or returned by the function) is a file name, the contents of
  74. this file will be used as the organization.")
  75.  
  76. (defvar gnus-use-generic-from nil
  77.   "If nil, the full host name will be the system name prepended to the domain name.
  78. If this is a string, the full host name will be this string.
  79. If this is non-nil, non-string, the domain name will be used as the
  80. full host name.")
  81.  
  82. (defvar gnus-use-generic-path nil
  83.   "If nil, use the NNTP server name in the Path header.
  84. If stringp, use this; if non-nil, use no host name (user name only).")
  85.  
  86.  
  87. ;; Customization variables
  88.  
  89. ;; Don't touch this variable.
  90. (defvar gnus-nntp-service "nntp"
  91.   "*NNTP service name (\"nntp\" or 119).
  92. This is an obsolete variable, which is scarcely used. If you use an
  93. nntp server for your newsgroup and want to change the port number
  94. used to 899, you would say something along these lines:
  95.  
  96.  (setq gnus-select-method '(nntp \"my.nntp.server\" (nntp-port-number 899)))")
  97.  
  98. (defvar gnus-select-method 
  99.   (nconc
  100.    (list 'nntp (or (getenv "NNTPSERVER") 
  101.            (if (and gnus-default-nntp-server
  102.                 (not (string= gnus-default-nntp-server "")))
  103.                gnus-default-nntp-server)
  104.            (system-name)))
  105.    (if (or (null gnus-nntp-service)
  106.        (equal gnus-nntp-service "nntp"))
  107.        nil 
  108.      (list gnus-nntp-service)))
  109.   "*Default method for selecting a newsgroup.
  110. This variable should be a list, where the first element is how the
  111. news is to be fetched, the second is the address. 
  112.  
  113. For instance, if you want to get your news via NNTP from
  114. \"flab.flab.edu\", you could say:
  115.  
  116. (setq gnus-select-method '(nntp \"flab.flab.edu\"))
  117.  
  118. If you want to use your local spool, say:
  119.  
  120. (setq gnus-select-method (list 'nnspool (system-name)))
  121.  
  122. If you use this variable, you must set `gnus-nntp-server' to nil.
  123.  
  124. There is a lot more to know about select methods and virtual servers -
  125. see the manual for details.")
  126.  
  127. ;; Added by Sudish Joseph <joseph@cis.ohio-state.edu>.
  128. (defvar gnus-post-method nil
  129.   "*Preferred method for posting USENET news.
  130. If this variable is nil, Gnus will use the current method to decide
  131. which method to use when posting.  If it is non-nil, it will override
  132. the current method.  This method will not be used in mail groups and
  133. the like, only in \"real\" newsgroups.
  134.  
  135. The value must be a valid method as discussed in the documentation of
  136. `gnus-select-method'.")
  137.  
  138. (defvar gnus-refer-article-method nil
  139.   "*Preferred method for fetching an article by Message-ID.
  140. If you are reading news from the local spool (with nnspool), fetching
  141. articles by Message-ID is painfully slow. By setting this method to an
  142. nntp method, you might get acceptable results.
  143.  
  144. The value of this variable must be a valid select method as discussed
  145. in the documentation of `gnus-select-method'")
  146.  
  147. (defvar gnus-secondary-select-methods nil
  148.   "*A list of secondary methods that will be used for reading news.
  149. This is a list where each element is a complete select method (see
  150. `gnus-select-method').  
  151.  
  152. If, for instance, you want to read your mail with the nnml backend,
  153. you could set this variable:
  154.  
  155. (setq gnus-secondary-select-methods '((nnml \"\")))")
  156.  
  157. (defvar gnus-secondary-servers nil
  158.   "*List of NNTP servers that the user can choose between interactively.
  159. To make Gnus query you for a server, you have to give `gnus' a
  160. non-numeric prefix - `C-u M-x gnus', in short.")
  161.  
  162. (defvar gnus-nntp-server nil
  163.   "*The name of the host running the NNTP server.
  164. This variable is semi-obsolete. Use the `gnus-select-method'
  165. variable instead.")
  166.  
  167. (defvar gnus-startup-file "~/.newsrc"
  168.   "*Your `.newsrc' file.
  169. `.newsrc-SERVER' will be used instead if that exists.")
  170.  
  171. (defvar gnus-init-file "~/.gnus"
  172.   "*Your Gnus elisp startup file.
  173. If a file with the .el or .elc suffixes exist, it will be read
  174. instead.") 
  175.  
  176. (defvar gnus-group-faq-directory
  177.   "/ftp@mirrors.aol.com:/pub/rtfm/usenet/"
  178.   "*Directory where the group FAQs are stored.
  179. This will most commonly be on a remote machine, and the file will be
  180. fetched by ange-ftp.
  181.  
  182. Note that Gnus uses an aol machine as the default directory.  If this
  183. feels fundamentally unclean, just think of it as a way to finally get
  184. something of value back from them.
  185.  
  186. If the default site is too slow, try one of these:
  187.  
  188.    North America: ftp.uu.net                     /usenet/news.answers
  189.           mirrors.aol.com                /pub/rtfm/usenet
  190.           ftp.seas.gwu.edu               /pub/rtfm
  191.                   rtfm.mit.edu                   /pub/usenet/news.answers
  192.    Europe:        ftp.uni-paderborn.de           /pub/FAQ
  193.           ftp.Germany.EU.net             /pub/newsarchive/news.answers
  194.           ftp.sunet.se                   /pub/usenet
  195.    Asia:          nctuccca.edu.tw                /USENET/FAQ
  196.           hwarang.postech.ac.kr          /pub/usenet/news.answers
  197.           ftp.hk.super.net               /mirror/faqs")
  198.  
  199. (defvar gnus-group-archive-directory
  200.   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/" 
  201.   "*The address of the (ding) archives.")
  202.  
  203. (defvar gnus-group-recent-archive-directory
  204.   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
  205.   "*The address of the most recent (ding) articles.")
  206.  
  207. (defvar gnus-default-subscribed-newsgroups nil
  208.   "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
  209. It should be a list of strings.
  210. If it is `t', Gnus will not do anything special the first time it is
  211. started; it'll just use the normal newsgroups subscription methods.")
  212.  
  213. (defvar gnus-use-cross-reference t
  214.   "*Non-nil means that cross referenced articles will be marked as read.
  215. If nil, ignore cross references.  If t, mark articles as read in
  216. subscribed newsgroups. If neither t nor nil, mark as read in all
  217. newsgroups.") 
  218.  
  219. (defvar gnus-use-dribble-file t
  220.   "*Non-nil means that Gnus will use a dribble file to store user updates.
  221. If Emacs should crash without saving the .newsrc files, complete
  222. information can be restored from the dribble file.")
  223.  
  224. (defvar gnus-asynchronous nil
  225.   "*If non-nil, Gnus will supply backends with data needed for async article fetching.")
  226.  
  227. (defvar gnus-asynchronous-article-function nil
  228.   "*Function for picking articles to pre-fetch, possibly.")
  229.  
  230. (defvar gnus-score-file-single-match-alist nil
  231.   "*Alist mapping regexps to lists of score files.
  232. Each element of this alist should be of the form
  233.     (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
  234.  
  235. If the name of a group is matched by REGEXP, the corresponding scorefiles
  236. will be used for that group.
  237. The first match found is used, subsequent matching entries are ignored (to
  238. use multiple matches, see gnus-score-file-multiple-match-alist).
  239.  
  240. These score files are loaded in addition to any files returned by
  241. gnus-score-find-score-files-function (which see).")
  242.  
  243. (defvar gnus-score-file-multiple-match-alist nil
  244.   "*Alist mapping regexps to lists of score files.
  245. Each element of this alist should be of the form
  246.     (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
  247.  
  248. If the name of a group is matched by REGEXP, the corresponding scorefiles
  249. will be used for that group.
  250. If multiple REGEXPs match a group, the score files corresponding to each
  251. match will be used (for only one match to be used, see
  252. gnus-score-file-single-match-alist).
  253.  
  254. These score files are loaded in addition to any files returned by
  255. gnus-score-find-score-files-function (which see).")
  256.  
  257.  
  258. (defvar gnus-score-file-suffix "SCORE"
  259.   "*Suffix of the score files.")
  260.  
  261. (defvar gnus-adaptive-file-suffix "ADAPT"
  262.   "*Suffix of the adaptive score files.")
  263.  
  264. (defvar gnus-score-find-score-files-function 'gnus-score-find-bnews
  265.   "*Function used to find score files.
  266. The function will be called with the group name as the argument, and
  267. should return a list of score files to apply to that group.  The score
  268. files do not actually have to exist.
  269.  
  270. Predefined values are:
  271.  
  272. gnus-score-find-single: Only apply the group's own score file.
  273. gnus-score-find-hierarchical: Also apply score files from parent groups.
  274. gnus-score-find-bnews: Apply score files whose names matches.
  275.  
  276. See the documentation to these functions for more information.
  277.  
  278. This variable can also be a list of functions to be called.  Each
  279. function should either return a list of score files, or a list of
  280. score alists.")
  281.  
  282. (defvar gnus-score-interactive-default-score 1000
  283.   "*Scoring commands will raise/lower the score with this number as the default.")
  284.  
  285. (defvar gnus-large-newsgroup 200
  286.   "*The number of articles which indicates a large newsgroup.
  287. If the number of articles in a newsgroup is greater than this value,
  288. confirmation is required for selecting the newsgroup.")
  289.  
  290. ;; Suggested by Andrew Eskilsson <pi92ae@lelle.pt.hk-r.se>.
  291. (defvar gnus-no-groups-message "No news is horrible news"
  292.   "*Message displayed by Gnus when no groups are available.")
  293.  
  294. (defvar gnus-use-long-file-name (not (memq system-type '(usg-unix-v xenix)))
  295.   "*Non-nil means that the default name of a file to save articles in is the group name.
  296. If it's nil, the directory form of the group name is used instead.
  297.  
  298. If this variable is a list, and the list contains the element
  299. `not-score', long file names will not be used for score files; if it
  300. contains the element `not-save', long file names will not be used for
  301. saving; and if it contains the element `not-kill', long file names
  302. will not be used for kill files.")
  303.  
  304. (defvar gnus-article-save-directory (or (getenv "SAVEDIR") "~/News/")
  305.   "*Name of the directory articles will be saved in (default \"~/News\").
  306. Initialized from the SAVEDIR environment variable.")
  307.  
  308. (defvar gnus-kill-files-directory (or (getenv "SAVEDIR") "~/News/")
  309.   "*Name of the directory where kill files will be stored (default \"~/News\").
  310. Initialized from the SAVEDIR environment variable.")
  311.  
  312. (defvar gnus-default-article-saver 'gnus-summary-save-in-rmail
  313.   "*A function to save articles in your favorite format.
  314. The function must be interactively callable (in other words, it must
  315. be an Emacs command).
  316.  
  317. Gnus provides the following functions:
  318.  
  319. * gnus-summary-save-in-rmail (Rmail format)
  320. * gnus-summary-save-in-mail (Unix mail format)
  321. * gnus-summary-save-in-folder (MH folder)
  322. * gnus-summary-save-in-file (article format).
  323. * gnus-summary-save-in-vm (use VM's folder format).")
  324.  
  325. (defvar gnus-rmail-save-name (function gnus-plain-save-name)
  326.   "*A function generating a file name to save articles in Rmail format.
  327. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
  328.  
  329. (defvar gnus-mail-save-name (function gnus-plain-save-name)
  330.   "*A function generating a file name to save articles in Unix mail format.
  331. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
  332.  
  333. (defvar gnus-folder-save-name (function gnus-folder-save-name)
  334.   "*A function generating a file name to save articles in MH folder.
  335. The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.")
  336.  
  337. (defvar gnus-file-save-name (function gnus-numeric-save-name)
  338.   "*A function generating a file name to save articles in article format.
  339. The function is called with NEWSGROUP, HEADERS, and optional
  340. LAST-FILE.")
  341.  
  342. (defvar gnus-split-methods nil
  343.   "*Variable used to suggest where articles are to be saved.
  344. The syntax of this variable is the same as `nnmail-split-methods'.  
  345.  
  346. For instance, if you would like to save articles related to Gnus in
  347. the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
  348. you could set this variable to something like:
  349.  
  350.  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
  351.    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))")
  352.  
  353. (defvar gnus-save-score nil
  354.   "*If non-nil, save group scoring info.")
  355.  
  356. (defvar gnus-use-adaptive-scoring nil
  357.   "*If non-nil, use some adaptive scoring scheme.")
  358.  
  359. (defvar gnus-use-cache nil
  360.   "*If non-nil, Gnus will cache (some) articles locally.")
  361.  
  362. (defvar gnus-use-scoring t
  363.   "*If non-nil, enable scoring.")
  364.  
  365. (defvar gnus-fetch-old-headers nil
  366.   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
  367. If an unread article in the group refers to an older, already read (or
  368. just marked as read) article, the old article will not normally be
  369. displayed in the Summary buffer.  If this variable is non-nil, Gnus
  370. will attempt to grab the headers to the old articles, and thereby
  371. build complete threads.  If it has the value `some', only enough
  372. headers to connect otherwise loose threads will be displayed.
  373.  
  374. The server has to support XOVER for any of this to work.")
  375.  
  376. ;see gnus-cus.el
  377. ;(defvar gnus-visual t
  378. ;  "*If non-nil, will do various highlighting.
  379. ;If nil, no mouse highlights (or any other highlights) will be
  380. ;performed.  This might speed up Gnus some when generating large group
  381. ;and summary buffers.")
  382.  
  383. (defvar gnus-novice-user t
  384.   "*Non-nil means that you are a usenet novice.
  385. If non-nil, verbose messages may be displayed and confirmations may be
  386. required.")
  387.  
  388. (defvar gnus-expert-user nil
  389.   "*Non-nil means that you will never be asked for confirmation about anything.
  390. And that means *anything*.")
  391.  
  392. (defvar gnus-verbose 7
  393.   "*Integer that says how verbose Gnus should be.
  394. The higher the number, the more messages Gnus will flash to say what
  395. it's doing.  At zero, Gnus will be totally mute; at five, Gnus will
  396. display most important messages; and at ten, Gnus will keep on
  397. jabbering all the time.")
  398.  
  399. (defvar gnus-keep-same-level nil
  400.   "*Non-nil means that the next newsgroup after the current will be on the same level.
  401. When you type, for instance, `n' after reading the last article in the
  402. current newsgroup, you will go to the next newsgroup. If this variable
  403. is nil, the next newsgroup will be the next from the group
  404. buffer. 
  405. If this variable is non-nil, Gnus will either put you in the
  406. next newsgroup with the same level, or, if no such newsgroup is
  407. available, the next newsgroup with the lowest possible level higher
  408. than the current level.
  409. If this variable is `best', Gnus will make the next newsgroup the one
  410. with the best level.")
  411.  
  412. (defvar gnus-summary-make-false-root 'adopt
  413.   "*nil means that Gnus won't gather loose threads.
  414. If the root of a thread has expired or been read in a previous
  415. session, the information necessary to build a complete thread has been
  416. lost. Instead of having many small sub-threads from this original thread
  417. scattered all over the summary buffer, Gnus can gather them. 
  418.  
  419. If non-nil, Gnus will try to gather all loose sub-threads from an
  420. original thread into one large thread.
  421.  
  422. If this variable is non-nil, it should be one of `none', `adopt',
  423. `dummy' or `empty'.
  424.  
  425. If this variable is `none', Gnus will not make a false root, but just
  426. present the sub-threads after another.
  427. If this variable is `dummy', Gnus will create a dummy root that will
  428. have all the sub-threads as children.
  429. If this variable is `adopt', Gnus will make one of the \"children\"
  430. the parent and mark all the step-children as such.
  431. If this variable is `empty', the \"children\" are printed with empty
  432. subject fields.  (Or rather, they will be printed with a string
  433. given by the `gnus-summary-same-subject' variable.)")
  434.  
  435. (defvar gnus-summary-gather-subject-limit nil
  436.   "*Maximum length of subject comparisons when gathering loose threads.
  437. Use nil to compare full subjects.  Setting this variable to a low
  438. number will help gather threads that have been corrupted by
  439. newsreaders chopping off subject lines, but it might also mean that
  440. unrelated articles that have subject that happen to begin with the
  441. same few characters will be incorrectly gathered.
  442.  
  443. If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
  444. comparing subjects.")
  445.  
  446. ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
  447. (defvar gnus-summary-same-subject ""
  448.   "*String indicating that the current article has the same subject as the previous.
  449. This variable will only be used if the value of
  450. `gnus-summary-make-false-root' is `empty'.")
  451.  
  452. (defvar gnus-summary-goto-unread t
  453.   "*If non-nil, marking commands will go to the next unread article.")
  454.  
  455. (defvar gnus-group-goto-unread t
  456.   "*If non-nil, movement commands will go to the next unread and subscribed group.")
  457.  
  458. (defvar gnus-check-new-newsgroups t
  459.   "*Non-nil means that Gnus will add new newsgroups at startup.
  460. If this variable is `ask-server', Gnus will ask the server for new
  461. groups since the last time it checked. This means that the killed list
  462. is no longer necessary, so you could set `gnus-save-killed-list' to
  463. nil. 
  464.  
  465. A variant is to have this variable be a list of select methods. Gnus
  466. will then use the `ask-server' method on all these select methods to
  467. query for new groups from all those servers.
  468.  
  469. Eg.
  470.   (setq gnus-check-new-newsgroups 
  471.         '((nntp \"some.server\") (nntp \"other.server\")))
  472.  
  473. If this variable is nil, then you have to tell Gnus explicitly to
  474. check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
  475.  
  476. (defvar gnus-check-bogus-newsgroups nil
  477.   "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
  478. If this variable is nil, then you have to tell Gnus explicitly to
  479. check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
  480.  
  481. (defvar gnus-read-active-file t
  482.   "*Non-nil means that Gnus will read the entire active file at startup.
  483. If this variable is nil, Gnus will only know about the groups in your
  484. `.newsrc' file.
  485.  
  486. If this variable is `some', Gnus will try to only read the relevant
  487. parts of the active file from the server.  Not all servers support
  488. this, and it might be quite slow with other servers, but this should
  489. generally be faster than both the t and nil value.
  490.  
  491. If you set this variable to nil or `some', you probably still want to
  492. be told about new newsgroups that arrive.  To do that, set
  493. `gnus-check-new-newsgroups' to `ask-server'.  This may not work
  494. properly with all servers.")
  495.  
  496. (defvar gnus-level-subscribed 5
  497.   "*Groups with levels less than or equal to this variable are subscribed.")
  498.  
  499. (defvar gnus-level-unsubscribed 7
  500.   "*Groups with levels less than or equal to this variable are unsubscribed.
  501. Groups with levels less than `gnus-level-subscribed', which should be
  502. less than this variable, are subscribed.")
  503.  
  504. (defvar gnus-level-zombie 8
  505.   "*Groups with this level are zombie groups.")
  506.  
  507. (defvar gnus-level-killed 9
  508.   "*Groups with this level are killed.")
  509.  
  510. (defvar gnus-level-default-subscribed 3
  511.   "*New subscribed groups will be subscribed at this level.")
  512.  
  513. (defvar gnus-level-default-unsubscribed 6
  514.   "*New unsubscribed groups will be unsubscribed at this level.")
  515.  
  516. (defvar gnus-activate-foreign-newsgroups 4
  517.   "*If nil, Gnus will not check foreign newsgroups at startup.
  518. If it is non-nil, it should be a number between one and nine. Foreign
  519. newsgroups that have a level lower or equal to this number will be
  520. activated on startup. For instance, if you want to active all
  521. subscribed newsgroups, but not the rest, you'd set this variable to 
  522. `gnus-level-subscribed'.
  523.  
  524. If you subscribe to lots of newsgroups from different servers, startup
  525. might take a while. By setting this variable to nil, you'll save time,
  526. but you won't be told how many unread articles there are in the
  527. groups.")
  528.  
  529. (defvar gnus-save-newsrc-file t
  530.   "*Non-nil means that Gnus will save the `.newsrc' file.
  531. Gnus always saves its own startup file, which is called
  532. \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
  533. be readily understood by other newsreaders.  If you don't plan on
  534. using other newsreaders, set this variable to nil to save some time on
  535. exit.")
  536.  
  537. (defvar gnus-save-killed-list t
  538.   "*If non-nil, save the list of killed groups to the startup file.
  539. This will save both time (when starting and quitting) and space (both
  540. memory and disk), but it will also mean that Gnus has no record of
  541. which groups are new and which are old, so the automatic new
  542. newsgroups subscription methods become meaningless. You should always
  543. set `gnus-check-new-newsgroups' to `ask-server' or nil if you set this
  544. variable to nil.")
  545.  
  546. (defvar gnus-interactive-catchup t
  547.   "*If non-nil, require your confirmation when catching up a group.")
  548.  
  549. (defvar gnus-interactive-post t
  550.   "*If non-nil, group name will be asked for when posting.")
  551.  
  552. (defvar gnus-interactive-exit t
  553.   "*If non-nil, require your confirmation when exiting Gnus.")
  554.  
  555. (defvar gnus-kill-killed t
  556.   "*If non-nil, Gnus will apply kill files to already killed articles.
  557. If it is nil, Gnus will never apply kill files to articles that have
  558. already been through the scoring process, which might very well save lots
  559. of time.")
  560.  
  561. (defvar gnus-extract-address-components 'gnus-extract-address-components
  562.   "*Function for extracting address components from a From header.
  563. Two pre-defined function exist: `gnus-extract-address-components',
  564. which is the default, quite fast, and too simplistic solution, and
  565. `mail-extract-address-components', which works much better, but is
  566. slower.")
  567.  
  568. (defvar gnus-summary-default-score 0
  569.   "*Default article score level.
  570. If this variable is nil, scoring will be disabled.")
  571.  
  572. (defvar gnus-summary-zcore-fuzz 0
  573.   "*Fuzziness factor for the zcore in the summary buffer.
  574. Articles with scores closer than this to `gnus-summary-default-score'
  575. will not be marked.")
  576.  
  577. (defvar gnus-simplify-subject-fuzzy-regexp nil
  578.   "*Regular expression that will be removed from subject strings if
  579. fuzzy subject simplification is selected.")
  580.  
  581. (defvar gnus-group-default-list-level gnus-level-subscribed
  582.   "*Default listing level. 
  583. Ignored if `gnus-group-use-permanent-levels' is non-nil.")
  584.  
  585. (defvar gnus-group-use-permanent-levels nil
  586.   "*If non-nil, once you set a level, Gnus will use this level.")
  587.  
  588. (defvar gnus-show-mime nil
  589.   "*If non-nil, do mime processing of articles.
  590. The articles will simply be fed to the function given by
  591. `gnus-show-mime-method'.")
  592.  
  593. (defvar gnus-strict-mime t
  594.   "*If nil, decode MIME header even if there is not Mime-Version field.")
  595.  
  596. (defvar gnus-show-mime-method (function metamail-buffer)
  597.   "*Function to process a MIME message.
  598. The function is called from the article buffer.")
  599.  
  600. (defvar gnus-show-threads t
  601.   "*If non-nil, display threads in summary mode.")
  602.  
  603. (defvar gnus-thread-hide-subtree nil
  604.   "*If non-nil, hide all threads initially.
  605. If threads are hidden, you have to run the command
  606. `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
  607. to expose hidden threads.")
  608.  
  609. (defvar gnus-thread-hide-killed t
  610.   "*If non-nil, hide killed threads automatically.")
  611.  
  612. (defvar gnus-thread-ignore-subject nil
  613.   "*If non-nil, ignore subjects and do all threading based on the Reference header.
  614. If nil, which is the default, articles that have different subjects
  615. from their parents will start separate threads.")
  616.  
  617. (defvar gnus-thread-indent-level 4
  618.   "*Number that says how much each sub-thread should be indented.")
  619.  
  620. (defvar gnus-ignored-newsgroups 
  621.   (purecopy (mapconcat 'identity
  622.                        '("^to\\."       ; not "real" groups
  623.                          "^[0-9. \t]+ " ; all digits in name
  624.                          "[][\"#'()]"   ; bogus characters
  625.                          )
  626.                        "\\|"))
  627.   "*A regexp to match uninteresting newsgroups in the active file.
  628. Any lines in the active file matching this regular expression are
  629. removed from the newsgroup list before anything else is done to it,
  630. thus making them effectively non-existent.")
  631.  
  632. (defvar gnus-ignored-headers
  633.   "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:\\|^Received:\\|^Mail-from:"
  634.   "*All headers that match this regexp will be hidden.
  635. If `gnus-visible-headers' is non-nil, this variable will be ignored.")
  636.  
  637. (defvar gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:"
  638.   "*All headers that do not match this regexp will be hidden.
  639. If this variable is non-nil, `gnus-ignored-headers' will be ignored.")
  640.  
  641. (defvar gnus-sorted-header-list
  642.   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:" 
  643.     "^Cc:" "^Date:" "^Organization:")
  644.   "*This variable is a list of regular expressions.
  645. If it is non-nil, headers that match the regular expressions will
  646. be placed first in the article buffer in the sequence specified by
  647. this list.")
  648.  
  649. (defvar gnus-show-all-headers nil
  650.   "*If non-nil, don't hide any headers.")
  651.  
  652. (defvar gnus-save-all-headers t
  653.   "*If non-nil, don't remove any headers before saving.")
  654.  
  655. (defvar gnus-inhibit-startup-message nil
  656.   "*If non-nil, the startup message will not be displayed.")
  657.  
  658. (defvar gnus-signature-separator "^-- *$"
  659.   "Regexp matching signature separator.")
  660.  
  661. (defvar gnus-auto-extend-newsgroup t
  662.   "*If non-nil, extend newsgroup forward and backward when requested.")
  663.  
  664. (defvar gnus-auto-select-first t
  665.   "*If non-nil, select the first unread article when entering a group.
  666. If you want to prevent automatic selection of the first unread article
  667. in some newsgroups, set the variable to nil in
  668. `gnus-select-group-hook'.") 
  669.  
  670. (defvar gnus-auto-select-next t
  671.   "*If non-nil, offer to go to the next group from the end of the previous.
  672. If the value is t and the next newsgroup is empty, Gnus will exit
  673. summary mode and go back to group mode.  If the value is neither nil
  674. nor t, Gnus will select the following unread newsgroup.  In
  675. particular, if the value is the symbol `quietly', the next unread
  676. newsgroup will be selected without any confirmations.")
  677.  
  678. (defvar gnus-auto-select-same nil
  679.   "*If non-nil, select the next article with the same subject.")
  680.  
  681. (defvar gnus-summary-check-current nil
  682.   "*If non-nil, consider the current article when moving.
  683. The \"unread\" movement commands will stay on the same line if the
  684. current article is unread.")
  685.  
  686. (defvar gnus-auto-center-summary t
  687.   "*If non-nil, always center the current summary buffer.")
  688.  
  689. (defvar gnus-break-pages t
  690.   "*If non-nil, do page breaking on articles.
  691. The page delimiter is specified by the `gnus-page-delimiter'
  692. variable.")
  693.  
  694. (defvar gnus-page-delimiter "^\^L"
  695.   "*Regexp describing what to use as article page delimiters.
  696. The default value is \"^\^L\", which is a form linefeed at the
  697. beginning of a line.")
  698.  
  699. (defvar gnus-use-full-window t
  700.   "*If non-nil, use the entire Emacs screen.")
  701.  
  702. (defvar gnus-window-configuration nil
  703.   "Obsolete variable.  See `gnus-buffer-configuration'.")
  704.  
  705. (defvar gnus-buffer-configuration
  706.   '((group ([group 1.0 point] 
  707.         (if gnus-carpal [group-carpal 4])))
  708.     (summary ([summary 1.0 point]
  709.           (if gnus-carpal [summary-carpal 4])))
  710.     (article ([summary 0.25 point] 
  711.           (if gnus-carpal [summary-carpal 4]) 
  712.           [article 1.0]))
  713.     (pipe ([summary 0.25 point] 
  714.        (if gnus-carpal [summary-carpal 4]) 
  715.        [pipe 1.0]))
  716.     (server ([server 1.0 point]
  717.          (if gnus-carpal [server-carpal 2])))
  718.     (browse ([browse 1.0 point]
  719.          (if gnus-carpal [browse-carpal 2])))
  720.     (group-mail ([mail 1.0 point]))
  721.     (summary-mail ([mail 1.0 point]))
  722.     (summary-reply ([article 0.5]
  723.             [mail 1.0 point]))
  724.     (info ([nil 1.0 point]))
  725.     (summary-faq ([summary 0.25]
  726.           [faq 1.0 point]))
  727.     (edit-group ([group 0.5]
  728.          [edit-group 1.0 point]))
  729.     (edit-server ([server 0.5]
  730.           [edit-server 1.0 point]))
  731.     (edit-score ([summary 0.25]
  732.          [edit-score 1.0 point]))
  733.     (post ([post 1.0 point]))
  734.     (reply ([article 0.5]
  735.         [mail 1.0 point]))
  736.     (mail-forward ([mail 1.0 point]))
  737.     (post-forward ([post 1.0 point]))
  738.     (reply-yank ([mail 1.0 point]))
  739.     (followup ([article 0.5]
  740.            [post 1.0 point]))
  741.     (followup-yank ([post 1.0 point])))
  742.   "Window configuration for all possible Gnus buffers.
  743. This variable is a list of lists.  Each of these lists has a NAME and
  744. a RULE.  The NAMEs are common-sense names like `group', which names a
  745. rule used when displaying the group buffer; `summary', which names a
  746. rule for what happens when you enter a group and do not display an
  747. article buffer; and so on.  See the value of this variable for a
  748. complete list of NAMEs.
  749.  
  750. Each RULE is a list of vectors.  The first element in this vector is
  751. the name of the buffer to be displayed; the second element is the
  752. percentage of the screen this buffer is to occupy (a number in the
  753. 0.0-0.99 range); the optional third element is `point', which should
  754. be present to denote which buffer point is to go to after making this
  755. buffer configuration.")
  756.  
  757. (defvar gnus-window-to-buffer
  758.   '((group . gnus-group-buffer)
  759.     (summary . gnus-summary-buffer)
  760.     (article . gnus-article-buffer)
  761.     (server . gnus-server-buffer)
  762.     (browse . "*Gnus Browse Server*")
  763.     (pipe . "*Shell Command Output*")
  764.     (edit-group . gnus-group-edit-buffer)
  765.     (edit-server . gnus-server-edit-buffer)
  766.     (group-carpal . gnus-carpal-group-buffer)
  767.     (summary-carpal . gnus-carpal-summary-buffer)
  768.     (server-carpal . gnus-carpal-server-buffer)
  769.     (browse-carpal . gnus-carpal-browse-buffer)
  770.     (edit-score . gnus-score-edit-buffer)
  771.     (mail . gnus-mail-buffer)
  772.     (post . gnus-post-news-buffer)
  773.     (faq . gnus-faq-buffer))
  774.   "Mapping from short symbols to buffer names or buffer variables.")
  775.  
  776. (defvar gnus-carpal nil
  777.   "*If non-nil, display clickable icons.")
  778.  
  779. (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
  780.   "*Function called with a group name when new group is detected.
  781. A few pre-made functions are supplied: `gnus-subscribe-randomly'
  782. inserts new groups at the beginning of the list of groups;
  783. `gnus-subscribe-alphabetically' inserts new groups in strict
  784. alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
  785. in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
  786. for your decision.")
  787.  
  788. ;; Suggested by a bug report by Hallvard B Furuseth.
  789. ;; <h.b.furuseth@usit.uio.no>. 
  790. (defvar gnus-subscribe-options-newsgroup-method
  791.   (function gnus-subscribe-alphabetically)
  792.   "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
  793. If, for instance, you want to subscribe to all newsgroups in the
  794. \"no\" and \"alt\" hierarchies, you'd put the following in your
  795. .newsrc file:
  796.  
  797. options -n no.all alt.all
  798.  
  799. Gnus will the subscribe all new newsgroups in these hierarchies with
  800. the subscription method in this variable.")
  801.  
  802. (defvar gnus-subscribe-hierarchical-interactive nil
  803.   "*If non-nil, Gnus will offer to subscribe hierarchically.
  804. When a new hierarchy appears, Gnus will ask the user:
  805.  
  806. 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
  807.  
  808. If the user pressed `d', Gnus will descend the hierarchy, `y' will
  809. subscribe to all newsgroups in the hierarchy and `s' will skip this
  810. hierarchy in its entirety.")
  811.  
  812. (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
  813.   "*Function used for sorting the group buffer.
  814. This function will be called with group info entries as the arguments
  815. for the groups to be sorted.  Pre-made functions include
  816. `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread' and
  817. `gnus-group-sort-by-level'")
  818.  
  819. ;; Mark variables suggested by Thomas Michanek
  820. ;; <Thomas.Michanek@telelogic.se>. 
  821. (defvar gnus-unread-mark ? 
  822.   "*Mark used for unread articles.")
  823. (defvar gnus-ticked-mark ?!
  824.   "*Mark used for ticked articles.")
  825. (defvar gnus-dormant-mark ??
  826.   "*Mark used for dormant articles.")
  827. (defvar gnus-del-mark ?r
  828.   "*Mark used for del'd articles.")
  829. (defvar gnus-read-mark ?R
  830.   "*Mark used for read articles.")
  831. (defvar gnus-expirable-mark ?E
  832.   "*Mark used for expirable articles.")
  833. (defvar gnus-killed-mark ?K
  834.   "*Mark used for killed articles.")
  835. (defvar gnus-kill-file-mark ?X
  836.   "*Mark used for articles killed by kill files.")
  837. (defvar gnus-low-score-mark ?Y
  838.   "*Mark used for articles with a low score.")
  839. (defvar gnus-catchup-mark ?C
  840.   "*Mark used for articles that are caught up.")
  841. (defvar gnus-replied-mark ?A
  842.   "*Mark used for articles that have been replied to.")
  843. (defvar gnus-process-mark ?# 
  844.   "*Process mark.")
  845. (defvar gnus-ancient-mark ?O
  846.   "*Mark used for ancient articles.")
  847. (defvar gnus-canceled-mark ?G
  848.   "*Mark used for canceled articles.")
  849. (defvar gnus-score-over-mark ?+
  850.   "*Score mark used for articles with high scores.")
  851. (defvar gnus-score-below-mark ?-
  852.   "*Score mark used for articles with low scores.")
  853. (defvar gnus-empty-thread-mark ? 
  854.   "*There is no thread under the article.")
  855. (defvar gnus-not-empty-thread-mark ?=
  856.   "*There is a thread under the article.")
  857. (defvar gnus-dummy-mark ?Z
  858.   "*This is a dummy article.")
  859.  
  860. (defvar gnus-view-pseudo-asynchronously nil
  861.   "*If non-nil, Gnus will view pseudo-articles asynchronously.")
  862.  
  863. (defvar gnus-view-pseudos nil
  864.   "*If `automatic', pseudo-articles will be viewed automatically.
  865. If `not-confirm', pseudos will be viewed automatically, and the user
  866. will not be asked to confirm the command.")
  867.  
  868. (defvar gnus-view-pseudos-separately t
  869.   "*If non-nil, one pseudo-article will be created for each file to be viewed.
  870. If nil, all files that use the same viewing command will be given as a
  871. list of parameters to that command.")
  872.  
  873. (defvar gnus-group-line-format "%M%S%p%5y: %(%g%)\n"
  874.   "*Format of group lines.
  875. It works along the same lines as a normal formatting string,
  876. with some simple extensions.
  877.  
  878. %M    Only marked articles (character, \"*\" or \" \")
  879. %S    Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
  880. %L    Level of subscribedness (integer)
  881. %N    Number of unread articles (integer)
  882. %I    Number of dormant articles (integer)
  883. %i    Number of ticked and dormant (integer)
  884. %T    Number of ticked articles (integer)
  885. %R    Number of read articles (integer)
  886. %t    Total number of articles (integer)
  887. %y    Number of unread, unticked articles (integer)
  888. %G    Group name (string)
  889. %g    Qualified group name (string)
  890. %D    Group description (string)
  891. %s    Select method (string)
  892. %o    Moderated group (char, \"m\")
  893. %p    Process mark (char)
  894. %O    Moderated group (string, \"(m)\" or \"\")
  895. %n    Select from where (string)
  896. %z    A string that look like `<%s:%n>' if a foreign select method is used
  897. %u    User defined specifier. The next character in the format string should
  898.       be a letter.  Gnus will call the function gnus-user-format-function-X,
  899.       where X is the letter following %u. The function will be passed the
  900.       current header as argument. The function should return a string, which
  901.       will be inserted into the buffer just like information from any other
  902.       group specifier.
  903.  
  904. Text between %( and %) will be highlighted with `gnus-mouse-face' when
  905. the mouse point move inside the area.  There can only be one such area.
  906.  
  907. Note that this format specification is not always respected. For
  908. reasons of efficiency, when listing killed groups, this specification
  909. is ignored altogether. If the spec is changed considerably, your
  910. output may end up looking strange when listing both alive and killed
  911. groups.
  912.  
  913. If you use %o or %O, reading the active file will be slower and quite
  914. a bit of extra memory will be used. %D will also worsen performance.
  915. Also note that if you change the format specification to include any
  916. of these specs, you must probably re-start Gnus to see them go into
  917. effect.") 
  918.  
  919. (defvar gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n"
  920.   "*The format specification of the lines in the summary buffer.
  921.  
  922. It works along the same lines as a normal formatting string,
  923. with some simple extensions.
  924.  
  925. %N   Article number, left padded with spaces (string)
  926. %S   Subject (string)
  927. %s   Subject if it is at the root of a thread, and \"\" otherwise (string)
  928. %n   Name of the poster (string)
  929. %a   Extracted name of the poster (string)
  930. %A   Extracted address of the poster (string)
  931. %F   Contents of the From: header (string)
  932. %x   Contents of the Xref: header (string)
  933. %D   Date of the article (string)
  934. %d   Date of the article (string) in DD-MMM format
  935. %M   Message-id of the article (string)
  936. %r   References of the article (string)
  937. %c   Number of characters in the article (integer)
  938. %L   Number of lines in the article (integer)
  939. %I   Indentation based on thread level (a string of spaces)
  940. %T   A string with two possible values: 80 spaces if the article
  941.      is on thread level two or larger and 0 spaces on level one
  942. %R   \"A\" if this article has been replied to, \" \" otherwise (character)
  943. %U   Status of this article (character, \"R\", \"K\", \"-\" or \" \")
  944. %[   Opening bracket (character, \"[\" or \"<\")
  945. %]   Closing bracket (character, \"]\" or \">\")
  946. %>   Spaces of length thread-level (string)
  947. %<   Spaces of length (- 20 thread-level) (string)
  948. %i   Article score (number)
  949. %z   Article zcore (character)
  950. %t   Number of articles under the current thread (number).
  951. %e   Whether the thread is empty or not (character).
  952. %u   User defined specifier. The next character in the format string should
  953.      be a letter.  Gnus will call the function gnus-user-format-function-X,
  954.      where X is the letter following %u. The function will be passed the
  955.      current header as argument. The function should return a string, which
  956.      will be inserted into the summary just like information from any other
  957.      summary specifier.
  958.  
  959. Text between %( and %) will be highlighted with `gnus-mouse-face'
  960. when the mouse point is placed inside the area.  There can only be one
  961. such area.
  962.  
  963. The %U (status), %R (replied) and %z (zcore) specs have to be handled
  964. with care. For reasons of efficiency, Gnus will compute what column
  965. these characters will end up in, and \"hard-code\" that. This means that
  966. it is illegal to have these specs after a variable-length spec. Well,
  967. you might not be arrested, but your summary buffer will look strange,
  968. which is bad enough.
  969.  
  970. The smart choice is to have these specs as for to the left as
  971. possible. 
  972.  
  973. This restriction may disappear in later versions of Gnus.")
  974.  
  975. (defvar gnus-summary-dummy-line-format "*  :                          : %S\n"
  976.   "*The format specification for the dummy roots in the summary buffer.
  977. It works along the same lines as a normal formatting string,
  978. with some simple extensions.
  979.  
  980. %S  The subject")
  981.  
  982. (defvar gnus-summary-mode-line-format "Gnus: %b [%A] %Z"
  983.   "*The format specification for the summary mode line.")
  984.  
  985. (defvar gnus-article-mode-line-format "Gnus: %b %S"
  986.   "*The format specification for the article mode line.")
  987.  
  988. (defvar gnus-group-mode-line-format "Gnus: %b {%M:%S}  "
  989.   "*The format specification for the group mode line.")
  990.  
  991. (defvar gnus-valid-select-methods
  992.   '(("nntp" post address prompt-address)
  993.     ("nnspool" post)
  994.     ("nnvirtual" none virtual prompt-address) 
  995.     ("nnmbox" mail respool) 
  996.     ("nnml" mail respool)
  997.     ("nnmh" mail respool) 
  998.     ("nndir" none prompt-address address)
  999.     ("nneething" none prompt-address)
  1000.     ("nndigest" none) 
  1001.     ("nndoc" none prompt-address) 
  1002.     ("nnbabyl" mail respool) 
  1003.     ("nnkiboze" post virtual) 
  1004.     ;;("nnsoup" post)
  1005.     ("nnfolder" mail respool))
  1006.   "An alist of valid select methods.
  1007. The first element of each list lists should be a string with the name
  1008. of the select method. The other elements may be be the category of
  1009. this method (ie. `post', `mail', `none' or whatever) or other
  1010. properties that this method has (like being respoolable).
  1011. If you implement a new select method, all you should have to change is
  1012. this variable. I think.")
  1013.  
  1014. (defvar gnus-updated-mode-lines '(group article summary)
  1015.   "*List of buffers that should update their mode lines.
  1016. The list may contain the symbols `group', `article' and `summary'. If
  1017. the corresponding symbol is present, Gnus will keep that mode line
  1018. updated with information that may be pertinent. 
  1019. If this variable is nil, screen refresh may be quicker.")
  1020.  
  1021. ;; Added by Keinonen Kari <kk85613@cs.tut.fi>.
  1022. (defvar gnus-mode-non-string-length nil
  1023.   "*Max length of mode-line non-string contents.
  1024. If this is nil, Gnus will take space as is needed, leaving the rest
  1025. of the modeline intact.")
  1026.  
  1027. ;see gnus-cus.el
  1028. ;(defvar gnus-mouse-face 'highlight
  1029. ;  "*Face used for mouse highlighting in Gnus.
  1030. ;No mouse highlights will be done if `gnus-visual' is nil.")
  1031.  
  1032. (defvar gnus-summary-mark-below nil
  1033.   "*Mark all articles with a score below this variable as read.
  1034. This variable is local to each summary buffer and usually set by the
  1035. score file.")  
  1036.  
  1037. (defvar gnus-thread-sort-functions '(gnus-thread-sort-by-number)
  1038.   "*List of functions used for sorting threads in the summary buffer.
  1039. By default, threads are sorted by article number.
  1040.  
  1041. Each function takes two threads and return non-nil if the first thread
  1042. should be sorted before the other.  If you use more than one function,
  1043. the primary sort function should be the last.
  1044.  
  1045. Ready-mady functions include `gnus-thread-sort-by-number',
  1046. `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
  1047. `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
  1048. `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').")
  1049.  
  1050. (defvar gnus-thread-score-function '+
  1051.   "*Function used for calculating the total score of a thread.
  1052.  
  1053. The function is called with the scores of the article and each
  1054. subthread and should then return the score of the thread.
  1055.  
  1056. Some functions you can use are `+', `max', or `min'.")
  1057.  
  1058. (defvar gnus-options-subscribe nil
  1059.   "*All new groups matching this regexp will be subscribed unconditionally.
  1060. Note that this variable deals only with new newsgroups.  This variable
  1061. does not affect old newsgroups.")
  1062.  
  1063. (defvar gnus-options-not-subscribe nil
  1064.   "*All new groups matching this regexp will be ignored.
  1065. Note that this variable deals only with new newsgroups.  This variable
  1066. does not affect old (already subscribed) newsgroups.")
  1067.  
  1068. (defvar gnus-auto-expirable-newsgroups nil
  1069.   "*Groups in which to automatically mark read articles as expirable.
  1070. If non-nil, this should be a regexp that should match all groups in
  1071. which to perform auto-expiry.  This only makes sense for mail groups.")
  1072.  
  1073. (defvar gnus-hidden-properties '(invisible t intangible t)
  1074.   "Property list to use for hiding text.")
  1075.  
  1076. (defvar gnus-modtime-botch nil
  1077.   "*Non-nil means .newsrc should be deleted prior to save.  Its use is
  1078. due to the bogus appearance that .newsrc was modified on disc.")
  1079.  
  1080. ;; Hooks.
  1081.  
  1082. (defvar gnus-group-mode-hook nil
  1083.   "*A hook for Gnus group mode.")
  1084.  
  1085. (defvar gnus-summary-mode-hook nil
  1086.   "*A hook for Gnus summary mode.
  1087. This hook is run before any variables are set in the summary buffer.")
  1088.  
  1089. (defvar gnus-article-mode-hook nil
  1090.   "*A hook for Gnus article mode.")
  1091.  
  1092. (defun gnus-summary-prepare-exit-hook nil
  1093.   "*A hook called when preparing to exit from the summary buffer.
  1094. It calls `gnus-summary-expire-articles' by default.")
  1095. (add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-expire-articles)
  1096.  
  1097. (defun gnus-summary-exit-hook nil
  1098.   "*A hook called on exit from the summary buffer.")
  1099.  
  1100. (defvar gnus-open-server-hook nil
  1101.   "*A hook called just before opening connection to the news server.")
  1102.  
  1103. (defvar gnus-load-hook nil
  1104.   "*A hook run while Gnus is loaded.")
  1105.  
  1106. (defvar gnus-startup-hook nil
  1107.   "*A hook called at startup.
  1108. This hook is called after Gnus is connected to the NNTP server.")
  1109.  
  1110. (defvar gnus-get-new-news-hook nil
  1111.   "*A hook run just before Gnus checks for new news.")
  1112.  
  1113. (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
  1114.   "*A function that is called to generate the group buffer.
  1115. The function is called with three arguments: The first is a number;
  1116. all group with a level less or equal to that number should be listed,
  1117. if the second is non-nil, empty groups should also be displayed. If
  1118. the third is non-nil, it is a number. No groups with a level lower
  1119. than this number should be displayed.
  1120.  
  1121. The only current function implemented is `gnus-group-prepare-flat'.")
  1122.  
  1123. (defvar gnus-group-prepare-hook nil
  1124.   "*A hook called after the group buffer has been generated.
  1125. If you want to modify the group buffer, you can use this hook.")
  1126.  
  1127. (defvar gnus-summary-prepare-hook nil
  1128.   "*A hook called after the summary buffer has been generated.
  1129. If you want to modify the summary buffer, you can use this hook.")
  1130.  
  1131. (defvar gnus-article-prepare-hook nil
  1132.   "*A hook called after an article has been prepared in the article buffer.
  1133. If you want to run a special decoding program like nkf, use this hook.")
  1134.  
  1135. ;(defvar gnus-article-display-hook nil
  1136. ;  "*A hook called after the article is displayed in the article buffer.
  1137. ;The hook is designed to change the contents of the article
  1138. ;buffer. Typical functions that this hook may contain are
  1139. ;`gnus-article-hide-headers' (hide selected headers),
  1140. ;`gnus-article-maybe-highlight' (perform fancy article highlighting), 
  1141. ;`gnus-article-hide-signature' (hide signature) and
  1142. ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
  1143. ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
  1144. ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
  1145. ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
  1146.  
  1147. (defvar gnus-article-x-face-command
  1148.   "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
  1149.   "String or function to be executed to display an X-Face header.
  1150. If it is a string, the command will be executed in a sub-shell
  1151. asynchronously. The compressed face will be piped to this command.") 
  1152.  
  1153. (defvar gnus-article-x-face-too-ugly nil
  1154.   "Regexp matching posters whose face shouldn't be shown automatically.")
  1155.  
  1156. (defvar gnus-select-group-hook nil
  1157.   "*A hook called when a newsgroup is selected.
  1158.  
  1159. If you'd like to simplify subjects like the
  1160. `gnus-summary-next-same-subject' command does, you can use the
  1161. following hook:
  1162.  
  1163.  (setq gnus-select-group-hook
  1164.       (list
  1165.     (lambda ()
  1166.       (mapcar (lambda (header)
  1167.              (mail-header-set-subject
  1168.               header
  1169.               (gnus-simplify-subject
  1170.                (mail-header-subject header) 're-only)))
  1171.           gnus-newsgroup-headers))))")
  1172.  
  1173. (defvar gnus-select-article-hook
  1174.   '(gnus-summary-show-thread)
  1175.   "*A hook called when an article is selected.
  1176. The default hook shows conversation thread subtrees of the selected
  1177. article automatically using `gnus-summary-show-thread'.")
  1178.  
  1179. (defvar gnus-apply-kill-hook '(gnus-apply-kill-file)
  1180.   "*A hook called to apply kill files to a group.
  1181. This hook is intended to apply a kill file to the selected newsgroup.
  1182. The function `gnus-apply-kill-file' is called by default.
  1183.  
  1184. Since a general kill file is too heavy to use only for a few
  1185. newsgroups, I recommend you to use a lighter hook function. For
  1186. example, if you'd like to apply a kill file to articles which contains
  1187. a string `rmgroup' in subject in newsgroup `control', you can use the
  1188. following hook:
  1189.  
  1190.  (setq gnus-apply-kill-hook
  1191.       (list
  1192.     (lambda ()
  1193.       (cond ((string-match \"control\" gnus-newsgroup-name)
  1194.          (gnus-kill \"Subject\" \"rmgroup\")
  1195.          (gnus-expunge \"X\"))))))")
  1196.  
  1197. (defvar gnus-visual-mark-article-hook 
  1198.   (list 'gnus-highlight-selected-summary)
  1199.   "*Hook run after selecting an article in the summary buffer.
  1200. It is meant to be used for highlighting the article in some way.  It
  1201. is not run if `gnus-visual' is nil.")
  1202.  
  1203. (defun gnus-parse-headers-hook nil
  1204.   "*A hook called before parsing the headers.")
  1205.  
  1206. (defvar gnus-exit-group-hook nil
  1207.   "*A hook called when exiting (not quitting) summary mode.")
  1208.  
  1209. (defvar gnus-suspend-gnus-hook nil
  1210.   "*A hook called when suspending (not exiting) Gnus.")
  1211.  
  1212. (defvar gnus-exit-gnus-hook nil
  1213.   "*A hook called when exiting Gnus.")
  1214.  
  1215. (defvar gnus-save-newsrc-hook nil
  1216.   "*A hook called when saving the newsrc file.")
  1217.  
  1218. (defvar gnus-summary-update-hook 
  1219.   (list 'gnus-summary-highlight-line)
  1220.   "*A hook called when a summary line is changed.
  1221. The hook will not be called if `gnus-visual' is nil.
  1222.  
  1223. The default function `gnus-summary-highlight-line' will
  1224. highlight the line according to the `gnus-summary-highlight'
  1225. variable.")
  1226.  
  1227. (defvar gnus-mark-article-hook (list 'gnus-summary-mark-unread-as-read)
  1228.   "*A hook called when an article is selected for the first time.
  1229. The hook is intended to mark an article as read (or unread)
  1230. automatically when it is selected.")
  1231.  
  1232. ;; Remove any hilit infestation.
  1233. (add-hook 'gnus-startup-hook
  1234.       (lambda ()
  1235.         (remove-hook 'gnus-summary-prepare-hook
  1236.              'hilit-rehighlight-buffer-quietly)
  1237.         (remove-hook 'gnus-summary-prepare-hook 'hilit-install-line-hooks)
  1238.         (setq gnus-mark-article-hook '(gnus-summary-mark-unread-as-read))
  1239.         (remove-hook 'gnus-article-prepare-hook
  1240.              'hilit-rehighlight-buffer-quietly)))
  1241.  
  1242.  
  1243.  
  1244. ;; Internal variables
  1245.  
  1246. ;; Avoid highlighting in kill files.
  1247. (defvar gnus-summary-inhibit-highlight nil)
  1248. (defvar gnus-newsgroup-selected-overlay nil)
  1249.  
  1250. (defvar gnus-article-mode-map nil)
  1251. (defvar gnus-dribble-buffer nil)
  1252. (defvar gnus-headers-retrieved-by nil)
  1253. (defvar gnus-article-reply nil)
  1254. (defvar gnus-override-method nil)
  1255. (defvar gnus-article-check-size nil)
  1256.  
  1257. (defvar gnus-current-score-file nil)
  1258. (defvar gnus-internal-global-score-files nil)
  1259. (defvar gnus-score-file-list nil)
  1260. (defvar gnus-scores-exclude-files nil)
  1261.  
  1262. (defvar gnus-current-move-group nil)
  1263.  
  1264. (defvar gnus-newsgroup-dependencies nil)
  1265. (defvar gnus-newsgroup-threads nil)
  1266. (defvar gnus-newsgroup-async nil)
  1267. (defconst gnus-group-edit-buffer "*Gnus edit newsgroup*")
  1268.  
  1269. (defvar gnus-newsgroup-adaptive nil)
  1270.  
  1271. (defvar gnus-summary-display-table nil)
  1272.  
  1273. (defconst gnus-group-line-format-alist
  1274.   (list (list ?M 'marked ?c)
  1275.     (list ?S 'subscribed ?c)
  1276.     (list ?L 'level ?d)
  1277.     (list ?N 'number ?s)
  1278.     (list ?I 'number-of-dormant ?d)
  1279.     (list ?T 'number-of-ticked ?d)
  1280.     (list ?R 'number-of-read ?s)
  1281.     (list ?t 'number-total ?d)
  1282.     (list ?y 'number-of-unread-unticked ?s)
  1283.     (list ?i 'number-of-ticked-and-dormant ?d)
  1284.     (list ?g 'group ?s)
  1285.     (list ?G 'qualified-group ?s)
  1286.     (list ?D 'newsgroup-description ?s)
  1287.     (list ?o 'moderated ?c)
  1288.     (list ?O 'moderated-string ?s)
  1289.     (list ?p 'process-marked ?c)
  1290.     (list ?s 'news-server ?s)
  1291.     (list ?n 'news-method ?s)
  1292.     (list ?z 'news-method-string ?s)
  1293.     (list ?u 'user-defined ?s)))
  1294.  
  1295. (defconst gnus-summary-line-format-alist 
  1296.   (list (list ?N 'number ?d)
  1297.     (list ?S 'subject ?s)
  1298.     (list ?s 'subject-or-nil ?s)
  1299.     (list ?n 'name ?s)
  1300.     (list ?A '(car (cdr (funcall gnus-extract-address-components from)))
  1301.           ?s)
  1302.     (list ?a '(or (car (funcall gnus-extract-address-components from)) 
  1303.               from) ?s)
  1304.     (list ?F 'from ?s)
  1305.     (list ?x (macroexpand '(mail-header-xref header)) ?s)
  1306.     (list ?D (macroexpand '(mail-header-date header)) ?s)
  1307.       (list ?d '(gnus-dd-mmm (mail-header-date header)) ?s)
  1308.     (list ?M (macroexpand '(mail-header-id header)) ?s)
  1309.     (list ?r (macroexpand '(mail-header-references header)) ?s)
  1310.     (list ?c '(or (mail-header-chars header) 0) ?d)
  1311.     (list ?L 'lines ?d)
  1312.     (list ?I 'indentation ?s)
  1313.     (list ?T '(if (= level 0) "" (make-string (frame-width) ? )) ?s)
  1314.     (list ?R 'replied ?c)
  1315.     (list ?\[ 'opening-bracket ?c)
  1316.     (list ?\] 'closing-bracket ?c)
  1317.     (list ?\> '(make-string level ? ) ?s)
  1318.     (list ?\< '(make-string (max 0 (- 20 level)) ? ) ?s)
  1319.     (list ?i 'score ?d)
  1320.     (list ?z 'score-char ?c)
  1321.     (list ?U 'unread ?c)
  1322.     (list ?t '(gnus-summary-number-of-articles-in-thread 
  1323.            (and (boundp 'thread) (car thread)))
  1324.           ?d)
  1325.     (list ?e '(gnus-summary-number-of-articles-in-thread 
  1326.            (and (boundp 'thread) (car thread)) t)
  1327.           ?c)
  1328.     (list ?u 'user-defined ?s))
  1329.   "An alist of format specifications that can appear in summary lines,
  1330. and what variables they correspond with, along with the type of the
  1331. variable (string, integer, character, etc).")
  1332.  
  1333. (defconst gnus-summary-dummy-line-format-alist
  1334.   (list (list ?S 'subject ?s)
  1335.     (list ?N 'number ?d)
  1336.     (list ?u 'user-defined ?s)))
  1337.  
  1338. (defconst gnus-summary-mode-line-format-alist 
  1339.   (list (list ?G 'group-name ?s)
  1340.     (list ?g '(gnus-short-group-name group-name) ?s)
  1341.     (list ?A 'article-number ?d)
  1342.     (list ?Z 'unread-and-unselected ?s)
  1343.     (list ?V 'gnus-version ?s)
  1344.     (list ?U 'unread ?d)
  1345.     (list ?S 'subject ?s)
  1346.     (list ?e 'unselected ?d)
  1347.     (list ?u 'user-defined ?s)
  1348.     (list ?b 'buffer-name ?s)
  1349.     (list ?s '(gnus-current-score-file-nondirectory) ?s)))
  1350.  
  1351. (defconst gnus-group-mode-line-format-alist 
  1352.   (list (list ?S 'news-server ?s)
  1353.     (list ?M 'news-method ?s)
  1354.     (list ?b '(buffer-name) ?s)
  1355.     (list ?u 'user-defined ?s)))
  1356.  
  1357. (defvar gnus-have-read-active-file nil)
  1358.  
  1359. (defconst gnus-maintainer
  1360.   "gnus-bug@ifi.uio.no (The Gnus Bugfixing Girls + Boys)"
  1361.   "The mail address of the Gnus maintainers.")
  1362.  
  1363. (defconst gnus-version "Gnus v5.1"
  1364.   "Version number for this version of Gnus.")
  1365.  
  1366. (defvar gnus-info-nodes
  1367.   '((gnus-group-mode        "(gnus)The Group Buffer")
  1368.     (gnus-summary-mode        "(gnus)The Summary Buffer")
  1369.     (gnus-article-mode        "(gnus)The Article Buffer"))
  1370.   "Assoc list of major modes and related Info nodes.")
  1371.  
  1372. (defvar gnus-group-buffer "*Group*")
  1373. (defvar gnus-summary-buffer "*Summary*")
  1374. (defvar gnus-article-buffer "*Article*")
  1375. (defvar gnus-server-buffer "*Server*")
  1376.  
  1377. (defvar gnus-work-buffer " *gnus work*")
  1378.  
  1379. (defvar gnus-buffer-list nil
  1380.   "Gnus buffers that should be killed on exit.")
  1381.  
  1382. (defvar gnus-server-alist nil
  1383.   "List of available servers.")
  1384.  
  1385. (defvar gnus-variable-list
  1386.   '(gnus-newsrc-options gnus-newsrc-options-n
  1387.     gnus-newsrc-last-checked-date 
  1388.     gnus-newsrc-alist gnus-server-alist
  1389.     gnus-killed-list gnus-zombie-list)
  1390.   "Gnus variables saved in the quick startup file.")
  1391.  
  1392. (defvar gnus-overload-functions
  1393.   '((news-inews gnus-inews-news "rnewspost"))
  1394.   "Functions overloaded by gnus.
  1395. It is a list of `(original overload &optional file)'.")
  1396.  
  1397. (defvar gnus-newsrc-options nil
  1398.   "Options line in the .newsrc file.")
  1399.  
  1400. (defvar gnus-newsrc-options-n nil
  1401.   "List of regexps representing groups to be subscribed/ignored unconditionally.") 
  1402.  
  1403. (defvar gnus-newsrc-last-checked-date nil
  1404.   "Date Gnus last asked server for new newsgroups.")
  1405.  
  1406. (defvar gnus-newsrc-alist nil
  1407.   "Assoc list of read articles.
  1408. gnus-newsrc-hashtb should be kept so that both hold the same information.")
  1409.  
  1410. (defvar gnus-newsrc-hashtb nil
  1411.   "Hashtable of gnus-newsrc-alist.")
  1412.  
  1413. (defvar gnus-killed-list nil
  1414.   "List of killed newsgroups.")
  1415.  
  1416. (defvar gnus-killed-hashtb nil
  1417.   "Hash table equivalent of gnus-killed-list.")
  1418.  
  1419. (defvar gnus-zombie-list nil
  1420.   "List of almost dead newsgroups.")
  1421.  
  1422. (defvar gnus-description-hashtb nil
  1423.   "Descriptions of newsgroups.")
  1424.  
  1425. (defvar gnus-list-of-killed-groups nil
  1426.   "List of newsgroups that have recently been killed by the user.")
  1427.  
  1428. (defvar gnus-active-hashtb nil
  1429.   "Hashtable of active articles.")
  1430.  
  1431. (defvar gnus-moderated-list nil
  1432.   "List of moderated newsgroups.")
  1433.  
  1434. (defvar gnus-group-marked nil)
  1435.  
  1436. (defvar gnus-current-startup-file nil
  1437.   "Startup file for the current host.")
  1438.  
  1439. (defvar gnus-last-search-regexp nil
  1440.   "Default regexp for article search command.")
  1441.  
  1442. (defvar gnus-last-shell-command nil
  1443.   "Default shell command on article.")
  1444.  
  1445. (defvar gnus-current-select-method nil
  1446.   "The current method for selecting a newsgroup.")
  1447.  
  1448. (defvar gnus-group-list-mode nil)
  1449.  
  1450. (defvar gnus-article-internal-prepare-hook nil)
  1451.  
  1452. (defvar gnus-newsgroup-name nil)
  1453. (defvar gnus-newsgroup-begin nil)
  1454. (defvar gnus-newsgroup-end nil)
  1455. (defvar gnus-newsgroup-last-rmail nil)
  1456. (defvar gnus-newsgroup-last-mail nil)
  1457. (defvar gnus-newsgroup-last-folder nil)
  1458. (defvar gnus-newsgroup-last-file nil)
  1459. (defvar gnus-newsgroup-auto-expire nil)
  1460. (defvar gnus-newsgroup-active nil)
  1461.  
  1462. (defvar gnus-newsgroup-unreads nil
  1463.   "List of unread articles in the current newsgroup.")
  1464.  
  1465. (defvar gnus-newsgroup-unselected nil
  1466.   "List of unselected unread articles in the current newsgroup.")
  1467.  
  1468. (defvar gnus-newsgroup-reads nil
  1469.   "Alist of read articles and article marks in the current newsgroup.")
  1470.  
  1471. (defvar gnus-newsgroup-marked nil
  1472.   "List of ticked articles in the current newsgroup (a subset of unread art).")
  1473.  
  1474. (defvar gnus-newsgroup-killed nil
  1475.   "List of ranges of articles that have been through the scoring process.")
  1476.  
  1477. (defvar gnus-newsgroup-kill-headers nil)
  1478.  
  1479. (defvar gnus-newsgroup-replied nil
  1480.   "List of articles that have been replied to in the current newsgroup.")
  1481.  
  1482. (defvar gnus-newsgroup-expirable nil
  1483.   "List of articles in the current newsgroup that can be expired.")
  1484.  
  1485. (defvar gnus-newsgroup-processable nil
  1486.   "List of articles in the current newsgroup that can be processed.")
  1487.  
  1488. (defvar gnus-newsgroup-bookmarks nil
  1489.   "List of articles in the current newsgroup that have bookmarks.")
  1490.  
  1491. (defvar gnus-newsgroup-dormant nil
  1492.   "List of dormant articles in the current newsgroup.")
  1493.  
  1494. (defvar gnus-newsgroup-scored nil
  1495.   "List of scored articles in the current newsgroup.")
  1496.  
  1497. (defvar gnus-newsgroup-headers nil
  1498.   "List of article headers in the current newsgroup.")
  1499. (defvar gnus-newsgroup-headers-hashtb-by-number nil)
  1500.  
  1501. (defvar gnus-newsgroup-ancient nil
  1502.   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
  1503.  
  1504. (defvar gnus-current-article nil)
  1505. (defvar gnus-article-current nil)
  1506. (defvar gnus-current-headers nil)
  1507. (defvar gnus-have-all-headers nil)
  1508. (defvar gnus-last-article nil)
  1509. (defvar gnus-newsgroup-history nil)
  1510. (defvar gnus-current-kill-article nil)
  1511.  
  1512. ;; Save window configuration.
  1513. (defvar gnus-prev-winconf nil)
  1514.  
  1515. ;; Format specs
  1516. (defvar gnus-summary-line-format-spec nil)
  1517. (defvar gnus-summary-dummy-line-format-spec nil)
  1518. (defvar gnus-group-line-format-spec nil)
  1519. (defvar gnus-summary-mode-line-format-spec nil)
  1520. (defvar gnus-article-mode-line-format-spec nil)
  1521. (defvar gnus-group-mode-line-format-spec nil)
  1522. (defvar gnus-summary-mark-positions nil)
  1523. (defvar gnus-group-mark-positions nil)
  1524.  
  1525. (defvar gnus-summary-expunge-below nil)
  1526. (defvar gnus-reffed-article-number nil)
  1527.  
  1528. ; Let the byte-compiler know that we know about this variable.
  1529. (defvar rmail-default-rmail-file)
  1530.  
  1531. (defvar gnus-cache-removable-articles nil)
  1532.  
  1533. (defconst gnus-summary-local-variables 
  1534.   '(gnus-newsgroup-name 
  1535.     gnus-newsgroup-begin gnus-newsgroup-end 
  1536.     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail 
  1537.     gnus-newsgroup-last-folder gnus-newsgroup-last-file 
  1538.     gnus-newsgroup-auto-expire gnus-newsgroup-unreads 
  1539.     gnus-newsgroup-unselected gnus-newsgroup-marked
  1540.     gnus-newsgroup-reads
  1541.     gnus-newsgroup-replied gnus-newsgroup-expirable
  1542.     gnus-newsgroup-processable gnus-newsgroup-killed
  1543.     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
  1544.     gnus-newsgroup-headers gnus-newsgroup-headers-hashtb-by-number
  1545.     gnus-current-article gnus-current-headers gnus-have-all-headers
  1546.     gnus-last-article gnus-article-internal-prepare-hook
  1547.     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
  1548.     gnus-newsgroup-scored gnus-newsgroup-kill-headers
  1549.     gnus-newsgroup-threads gnus-newsgroup-async
  1550.     gnus-score-alist gnus-current-score-file gnus-summary-expunge-below 
  1551.     gnus-summary-mark-below gnus-newsgroup-active gnus-scores-exclude-files
  1552.     gnus-newsgroup-history gnus-newsgroup-ancient
  1553.     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
  1554.     gnus-cache-removable-articles)
  1555.   "Variables that are buffer-local to the summary buffers.")
  1556.  
  1557. (defconst gnus-bug-message
  1558.   "Sending a bug report to the Gnus Towers.
  1559. ========================================
  1560.  
  1561. The buffer below is a mail buffer.  When you press `C-c C-c', it will
  1562. be sent to the Gnus Bug Exterminators. 
  1563.  
  1564. At the bottom of the buffer you'll see lots of variable settings.
  1565. Please do not delete those.  They will tell the Bug People what your
  1566. environment is, so that it will be easier to locate the bugs.
  1567.  
  1568. If you have found a bug that makes Emacs go \"beep\", set
  1569. debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET') 
  1570. and include the backtrace in your bug report.
  1571.  
  1572. Please describe the bug in annoying, painstaking detail.
  1573.  
  1574. Thank you for your help in stamping out bugs.
  1575. ")
  1576.  
  1577. ;;; End of variables.
  1578.  
  1579. ;; Define some autoload functions Gnus might use.
  1580. (eval-and-compile
  1581.  
  1582.   ;; Various 
  1583.   (autoload 'metamail-buffer "metamail")
  1584.   (autoload 'Info-goto-node "info")
  1585.   (autoload 'hexl-hex-string-to-integer "hexl")
  1586.   (autoload 'pp "pp")
  1587.   (autoload 'pp-to-string "pp")
  1588.   (autoload 'pp-eval-expression "pp")
  1589.   (autoload 'mail-extract-address-components "mail-extr")
  1590.  
  1591.   (autoload 'nnmail-split-fancy "nnmail")
  1592.   (autoload 'nnvirtual-catchup-group "nnvirtual")
  1593.  
  1594.   ;; timezone
  1595.   (autoload 'timezone-make-date-arpa-standard "timezone")
  1596.   (autoload 'timezone-fix-time "timezone")
  1597.   (autoload 'timezone-make-sortable-date "timezone")
  1598.   (autoload 'timezone-make-time-string "timezone")
  1599.  
  1600.   ;; rmail & friends
  1601.   (autoload 'mail-position-on-field "sendmail")
  1602.   (autoload 'mail-setup "sendmail")
  1603.   (autoload 'rmail-output "rmailout")
  1604.   (autoload 'news-mail-other-window "rnewspost")
  1605.   (autoload 'news-reply-yank-original "rnewspost")
  1606.   (autoload 'news-caesar-buffer-body "rnewspost")
  1607.   (autoload 'rmail-insert-rmail-file-header "rmail")
  1608.   (autoload 'rmail-count-new-messages "rmail")
  1609.   (autoload 'rmail-show-message "rmail")
  1610.  
  1611.   ;; gnus-soup
  1612.   ;;(autoload 'gnus-group-brew-soup "gnus-soup" nil t)
  1613.   ;;(autoload 'gnus-brew-soup "gnus-soup" nil t)
  1614.   ;;(autoload 'gnus-soup-add-article "gnus-soup" nil t)
  1615.   ;;(autoload 'gnus-soup-send-replies "gnus-soup" nil t)
  1616.   ;;(autoload 'gnus-soup-save-areas "gnus-soup" nil t)
  1617.   ;;(autoload 'gnus-soup-pack-packet "gnus-soup" nil t)
  1618.   ;;(autoload 'nnsoup-pack-replies "nnsoup" nil t)
  1619.  
  1620.   ;; gnus-mh
  1621.   (autoload 'gnus-mail-reply-using-mhe "gnus-mh")
  1622.   (autoload 'gnus-mail-forward-using-mhe "gnus-mh")
  1623.   (autoload 'gnus-mail-other-window-using-mhe "gnus-mh")
  1624.   (autoload 'gnus-summary-save-in-folder "gnus-mh" nil t)
  1625.   (autoload 'gnus-summary-save-article-folder "gnus-mh")
  1626.   (autoload 'gnus-Folder-save-name "gnus-mh")
  1627.   (autoload 'gnus-folder-save-name "gnus-mh")
  1628.  
  1629.   ;; gnus-vis misc
  1630.   (autoload 'gnus-group-make-menu-bar "gnus-vis")
  1631.   (autoload 'gnus-summary-make-menu-bar "gnus-vis")
  1632.   (autoload 'gnus-server-make-menu-bar "gnus-vis")
  1633.   (autoload 'gnus-article-make-menu-bar "gnus-vis")
  1634.   (autoload 'gnus-browse-make-menu-bar "gnus-vis")
  1635.   (autoload 'gnus-highlight-selected-summary "gnus-vis")
  1636.   (autoload 'gnus-summary-highlight-line "gnus-vis")
  1637.   (autoload 'gnus-carpal-setup-buffer "gnus-vis")
  1638.  
  1639.   ;; gnus-vis article
  1640.   (autoload 'gnus-article-push-button "gnus-vis" nil t)
  1641.   (autoload 'gnus-article-press-button "gnus-vis" nil t)
  1642.   (autoload 'gnus-article-highlight "gnus-vis" nil t)
  1643.   (autoload 'gnus-article-highlight-some "gnus-vis" nil t)
  1644.   (autoload 'gnus-article-hide "gnus-vis" nil t)
  1645.   (autoload 'gnus-article-hide-signature "gnus-vis" nil t)
  1646.   (autoload 'gnus-article-highlight-headers "gnus-vis" nil t)
  1647.   (autoload 'gnus-article-highlight-signature "gnus-vis" nil t)
  1648.   (autoload 'gnus-article-add-buttons "gnus-vis" nil t)
  1649.   (autoload 'gnus-article-next-button "gnus-vis" nil t)
  1650.   (autoload 'gnus-article-add-button "gnus-vis")
  1651.  
  1652.   ;; gnus-cite
  1653.   (autoload 'gnus-article-highlight-citation "gnus-cite" nil t)
  1654.   (autoload 'gnus-article-hide-citation-maybe "gnus-cite" nil t)
  1655.   (autoload 'gnus-article-hide-citation "gnus-cite" nil t)
  1656.  
  1657.   ;; gnus-kill
  1658.   (autoload 'gnus-kill "gnus-kill")
  1659.   (autoload 'gnus-apply-kill-file-internal "gnus-kill")
  1660.   (autoload 'gnus-kill-file-edit-file "gnus-kill")
  1661.   (autoload 'gnus-kill-file-raise-followups-to-author "gnus-kill")
  1662.   (autoload 'gnus-execute "gnus-kill")
  1663.   (autoload 'gnus-expunge "gnus-kill")
  1664.  
  1665.   ;; gnus-cache
  1666.   (autoload 'gnus-cache-possibly-enter-article "gnus-cache")
  1667.   (autoload 'gnus-cache-save-buffers "gnus-cache")
  1668.   (autoload 'gnus-cache-possibly-remove-articles "gnus-cache")
  1669.   (autoload 'gnus-cache-request-article "gnus-cache")
  1670.   (autoload 'gnus-cache-retrieve-headers "gnus-cache")
  1671.   (autoload 'gnus-cache-possibly-alter-active "gnus-cache")
  1672.   (autoload 'gnus-jog-cache "gnus-cache" nil t)
  1673.   (autoload 'gnus-cache-enter-remove-article "gnus-cache")
  1674.  
  1675.   ;; gnus-score
  1676.   (autoload 'gnus-summary-increase-score "gnus-score" nil t)
  1677.   (autoload 'gnus-summary-lower-score "gnus-score" nil t)
  1678.   (autoload 'gnus-summary-score-map "gnus-score" nil nil 'keymap)
  1679.   (autoload 'gnus-score-save "gnus-score")
  1680.   (autoload 'gnus-score-headers "gnus-score")
  1681.   (autoload 'gnus-current-score-file-nondirectory "gnus-score")
  1682.   (autoload 'gnus-score-adaptive "gnus-score")
  1683.   (autoload 'gnus-score-remove-lines-adaptive "gnus-score")
  1684.   (autoload 'gnus-score-find-trace "gnus-score")
  1685.  
  1686.   ;; gnus-edit
  1687.   (autoload 'gnus-score-customize "gnus-edit" nil t)
  1688.  
  1689.   ;; gnus-uu
  1690.   (autoload 'gnus-uu-extract-map "gnus-uu" nil nil 'keymap)
  1691.   (autoload 'gnus-uu-mark-map "gnus-uu" nil nil 'keymap)
  1692.   (autoload 'gnus-uu-digest-mail-forward "gnus-uu" nil t)
  1693.   (autoload 'gnus-uu-digest-post-forward "gnus-uu" nil t)
  1694.   (autoload 'gnus-uu-mark-series "gnus-uu" nil t)
  1695.   (autoload 'gnus-uu-mark-region "gnus-uu" nil t)
  1696.   (autoload 'gnus-uu-mark-by-regexp "gnus-uu" nil t)
  1697.   (autoload 'gnus-uu-mark-all "gnus-uu" nil t)
  1698.   (autoload 'gnus-uu-mark-sparse "gnus-uu" nil t)
  1699.   (autoload 'gnus-uu-mark-thread "gnus-uu" nil t)
  1700.   (autoload 'gnus-uu-decode-uu "gnus-uu" nil t)
  1701.   (autoload 'gnus-uu-decode-uu-and-save "gnus-uu" nil t)
  1702.   (autoload 'gnus-uu-decode-unshar "gnus-uu" nil t)
  1703.   (autoload 'gnus-uu-decode-unshar-and-save "gnus-uu" nil t)
  1704.   (autoload 'gnus-uu-decode-save "gnus-uu" nil t)
  1705.   (autoload 'gnus-uu-decode-binhex "gnus-uu" nil t)
  1706.   (autoload 'gnus-uu-decode-uu-view "gnus-uu" nil t)
  1707.   (autoload 'gnus-uu-decode-uu-and-save-view "gnus-uu" nil t)
  1708.   (autoload 'gnus-uu-decode-unshar-view "gnus-uu" nil t)
  1709.   (autoload 'gnus-uu-decode-unshar-and-save-view "gnus-uu" nil t)
  1710.   (autoload 'gnus-uu-decode-save-view "gnus-uu" nil t)
  1711.   (autoload 'gnus-uu-decode-binhex-view "gnus-uu" nil t)
  1712.  
  1713.   ;; gnus-msg
  1714.   (autoload 'gnus-summary-send-map "gnus-msg" nil nil 'keymap)
  1715.   (autoload 'gnus-group-post-news "gnus-msg" nil t)
  1716.   (autoload 'gnus-group-mail "gnus-msg" nil t)
  1717.   (autoload 'gnus-summary-post-news "gnus-msg" nil t)
  1718.   (autoload 'gnus-summary-followup "gnus-msg" nil t)
  1719.   (autoload 'gnus-summary-followup-with-original "gnus-msg" nil t)
  1720.   (autoload 'gnus-summary-followup-and-reply "gnus-msg" nil t)
  1721.   (autoload 'gnus-summary-followup-and-reply-with-original "gnus-msg" nil t)
  1722.   (autoload 'gnus-summary-cancel-article "gnus-msg" nil t)
  1723.   (autoload 'gnus-summary-supersede-article "gnus-msg" nil t)
  1724.   (autoload 'gnus-post-news "gnus-msg" nil t)
  1725.   (autoload 'gnus-inews-news "gnus-msg" nil t)
  1726.   (autoload 'gnus-cancel-news "gnus-msg" nil t)
  1727.   (autoload 'gnus-summary-reply "gnus-msg" nil t)
  1728.   (autoload 'gnus-summary-reply-with-original "gnus-msg" nil t)
  1729.   (autoload 'gnus-summary-mail-forward "gnus-msg" nil t)
  1730.   (autoload 'gnus-summary-mail-other-window "gnus-msg" nil t)
  1731.   (autoload 'gnus-mail-reply-using-mail "gnus-msg")
  1732.   (autoload 'gnus-mail-yank-original "gnus-msg")
  1733.   (autoload 'gnus-mail-send-and-exit "gnus-msg")
  1734.   (autoload 'gnus-mail-forward-using-mail "gnus-msg")
  1735.   (autoload 'gnus-mail-other-window-using-mail "gnus-msg")
  1736.   (autoload 'gnus-article-mail "gnus-msg")
  1737.   (autoload 'gnus-bug "gnus-msg" nil t)
  1738.  
  1739.   ;; gnus-vm
  1740.   (autoload 'gnus-summary-save-in-vm "gnus-vm" nil t)
  1741.   (autoload 'gnus-summary-save-article-vm "gnus-vm" nil t)
  1742.   (autoload 'gnus-mail-forward-using-vm "gnus-vm")
  1743.   (autoload 'gnus-mail-reply-using-vm "gnus-vm")
  1744.   (autoload 'gnus-mail-other-window-using-vm "gnus-vm" nil t)
  1745.   (autoload 'gnus-yank-article "gnus-vm" nil t)
  1746.  
  1747.   )
  1748.  
  1749.  
  1750.  
  1751. ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
  1752. ;; If you want the cursor to go somewhere else, set these two
  1753. ;; functions in some startup hook to whatever you want.
  1754. (defalias 'gnus-summary-position-cursor 'gnus-goto-colon)
  1755. (defalias 'gnus-group-position-cursor 'gnus-goto-colon)
  1756.  
  1757. ;;; Various macros and substs.
  1758.  
  1759. (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
  1760.   "Pop to BUFFER, evaluate FORMS, and then returns to original window."
  1761.   (` (let ((GnusStartBufferWindow (selected-window)))
  1762.        (unwind-protect
  1763.        (progn
  1764.          (pop-to-buffer (, buffer))
  1765.          (,@ forms))
  1766.      (select-window GnusStartBufferWindow)))))
  1767.  
  1768. (defmacro gnus-gethash (string hashtable)
  1769.   "Get hash value of STRING in HASHTABLE."
  1770.   ;;(` (symbol-value (abbrev-symbol (, string) (, hashtable))))
  1771.   ;;(` (abbrev-expansion (, string) (, hashtable)))
  1772.   (` (symbol-value (intern-soft (, string) (, hashtable)))))
  1773.  
  1774. (defmacro gnus-sethash (string value hashtable)
  1775.   "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
  1776.   ;; We cannot use define-abbrev since it only accepts string as value.
  1777.   ;; (set (intern string hashtable) value))
  1778.   (` (set (intern (, string) (, hashtable)) (, value))))
  1779.  
  1780. (defsubst gnus-buffer-substring (beg end)
  1781.   (buffer-substring (match-beginning beg) (match-end end)))
  1782.  
  1783. ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  1784. ;;   function `substring' might cut on a middle of multi-octet
  1785. ;;   character.
  1786. (defun gnus-truncate-string (str width)
  1787.   (substring str 0 width))
  1788.  
  1789. ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>. A safe way
  1790. ;; to limit the length of a string. This function is necessary since
  1791. ;; `(substr "abc" 0 30)' pukes with "Args out of range".
  1792. (defsubst gnus-limit-string (str width)
  1793.   (if (> (length str) width)
  1794.       (substring str 0 width)
  1795.     str))
  1796.  
  1797. (defsubst gnus-simplify-subject-re (subject)
  1798.   "Remove \"Re:\" from subject lines."
  1799.   (let ((case-fold-search t))
  1800.     (if (string-match "^re: *" subject)
  1801.     (substring subject (match-end 0))
  1802.       subject)))
  1803.  
  1804. (defsubst gnus-goto-char (point)
  1805.   (and point (goto-char point)))
  1806.  
  1807. (defmacro gnus-buffer-exists-p (buffer)
  1808.   (` (and (, buffer)
  1809.       (funcall (if (stringp (, buffer)) 'get-buffer 'buffer-name)
  1810.            (, buffer)))))
  1811.  
  1812. (defmacro gnus-kill-buffer (buffer)
  1813.   (` (if (gnus-buffer-exists-p (, buffer))
  1814.      (kill-buffer (, buffer)))))
  1815.  
  1816. (defsubst gnus-point-at-bol ()
  1817.   "Return point at the beginning of line."
  1818.   (let ((p (point)))
  1819.     (beginning-of-line)
  1820.     (prog1
  1821.     (point)
  1822.       (goto-char p))))
  1823.  
  1824. (defsubst gnus-point-at-eol ()
  1825.   "Return point at the beginning of line."
  1826.   (let ((p (point)))
  1827.     (end-of-line)
  1828.     (prog1
  1829.     (point)
  1830.       (goto-char p))))
  1831.  
  1832. ;; Delete the current line (and the next N lines.);
  1833. (defmacro gnus-delete-line (&optional n)
  1834.   (` (delete-region (progn (beginning-of-line) (point))
  1835.             (progn (forward-line (, (or n 1))) (point)))))
  1836.  
  1837. ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
  1838. (defvar gnus-init-inhibit nil)
  1839. (defun gnus-read-init-file (&optional inhibit-next)
  1840.   (if gnus-init-inhibit
  1841.       (setq gnus-init-inhibit nil)
  1842.     (setq gnus-init-inhibit inhibit-next)
  1843.     (and gnus-init-file
  1844.      (or (and (file-exists-p gnus-init-file) 
  1845.           ;; Don't try to load a directory.
  1846.           (not (file-directory-p gnus-init-file)))
  1847.          (file-exists-p (concat gnus-init-file ".el"))
  1848.          (file-exists-p (concat gnus-init-file ".elc")))
  1849.      (load gnus-init-file nil t))))
  1850.  
  1851. ;;; Load the user startup file.
  1852. ;; (eval '(gnus-read-init-file 'inhibit))
  1853.  
  1854. ;;; Load the compatibility functions. 
  1855.  
  1856. (require 'gnus-cus)
  1857. (require 'gnus-ems)
  1858.  
  1859.  
  1860. ;;;
  1861. ;;; Gnus Utility Functions
  1862. ;;;
  1863.  
  1864. (defun gnus-extract-address-components (from)
  1865.   (let (name address)
  1866.     ;; First find the address - the thing with the @ in it.  This may
  1867.     ;; not be accurate in mail addresses, but does the trick most of
  1868.     ;; the time in news messages.
  1869.     (if (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
  1870.     (setq address (substring from (match-beginning 0) (match-end 0))))
  1871.     ;; Then we check whether the "name <address>" format is used.
  1872.     (and address
  1873.       ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  1874.       ;; Linear white space is not required.
  1875.       (string-match (concat "[ \t]*<" (regexp-quote address) ">") from)
  1876.       (and (setq name (substring from 0 (match-beginning 0)))
  1877.           ;; Strip any quotes from the name.
  1878.           (string-match "\".*\"" name)
  1879.           (setq name (substring name 1 (1- (match-end 0))))))
  1880.     ;; If not, then "address (name)" is used.
  1881.     (or name
  1882.     (and (string-match "(.+)" from)
  1883.          (setq name (substring from (1+ (match-beginning 0)) 
  1884.                    (1- (match-end 0)))))
  1885.     (and (string-match "()" from)
  1886.          (setq name address))
  1887.     ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>.
  1888.     ;; XOVER might not support folded From headers.
  1889.     (and (string-match "(.*" from)
  1890.          (setq name (substring from (1+ (match-beginning 0)) 
  1891.                    (match-end 0)))))
  1892.     ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
  1893.     (list (or name from) (or address from))))
  1894.  
  1895. (defun gnus-fetch-field (field)
  1896.   "Return the value of the header FIELD of current article."
  1897.   (save-excursion
  1898.     (save-restriction
  1899.       (let ((case-fold-search t))
  1900.     (gnus-narrow-to-headers)
  1901.     (mail-fetch-field field)))))
  1902.  
  1903. (defun gnus-goto-colon ()
  1904.   (beginning-of-line)
  1905.   (search-forward ":" (gnus-point-at-eol) t))
  1906.  
  1907. (defun gnus-narrow-to-headers ()
  1908.   (widen)
  1909.   (save-excursion
  1910.     (narrow-to-region
  1911.      (goto-char (point-min))
  1912.      (if (search-forward "\n\n" nil t)
  1913.      (1- (point))
  1914.        (point-max)))))
  1915.  
  1916. (defvar gnus-old-specs nil)
  1917.  
  1918. (defun gnus-update-format-specifications ()
  1919.   (gnus-make-thread-indent-array)
  1920.  
  1921.   (let ((formats '(summary summary-dummy group 
  1922.                summary-mode group-mode article-mode))
  1923.     old-format new-format)
  1924.     (while formats
  1925.       (setq new-format (symbol-value
  1926.             (intern (format "gnus-%s-line-format" (car formats)))))
  1927.       (or (and (setq old-format (cdr (assq (car formats) gnus-old-specs)))
  1928.            (equal old-format new-format))
  1929.       (set (intern (format "gnus-%s-line-format-spec" (car formats)))
  1930.            (gnus-parse-format
  1931.         new-format
  1932.         (symbol-value 
  1933.          (intern (format "gnus-%s-line-format-alist"
  1934.                  (if (eq (car formats) 'article-mode)
  1935.                      'summary-mode (car formats))))))))
  1936.       (setq gnus-old-specs (cons (cons (car formats) new-format)
  1937.                  (delq (car formats) gnus-old-specs)))
  1938.       (setq formats (cdr formats))))
  1939.       
  1940.   (gnus-update-group-mark-positions)
  1941.   (gnus-update-summary-mark-positions)
  1942.  
  1943.   (if (and (string-match "%D" gnus-group-line-format)
  1944.        (not gnus-description-hashtb)
  1945.        gnus-read-active-file)
  1946.       (gnus-read-all-descriptions-files)))
  1947.  
  1948. (defun gnus-update-summary-mark-positions ()
  1949.   (save-excursion
  1950.     (let ((gnus-replied-mark 129)
  1951.       (gnus-score-below-mark 130)
  1952.       (gnus-score-over-mark 130)
  1953.       (thread nil)
  1954.       pos)
  1955.       (gnus-set-work-buffer)
  1956.       (gnus-summary-insert-line 
  1957.        nil [0 "" "" "" "" "" 0 0 ""]  0 nil 128 t nil "" nil 1)
  1958.       (goto-char (point-min))
  1959.       (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
  1960.                      (- (point) 2)))))
  1961.       (goto-char (point-min))
  1962.       (setq pos (cons (cons 'replied (and (search-forward "\201" nil t)
  1963.                       (- (point) 2))) pos))
  1964.       (goto-char (point-min))
  1965.       (setq pos (cons (cons 'score (and (search-forward "\202" nil t)
  1966.                     (- (point) 2))) pos))
  1967.       (setq gnus-summary-mark-positions pos))))
  1968.  
  1969. (defun gnus-update-group-mark-positions ()
  1970.   (save-excursion
  1971.     (let ((gnus-process-mark 128)
  1972.       (gnus-group-marked '("dummy.group")))
  1973.       (gnus-sethash "dummy.group" '(0 . 0) gnus-active-hashtb)
  1974.       (gnus-set-work-buffer)
  1975.       (gnus-group-insert-group-line nil "dummy.group" 0 nil 0 nil)
  1976.       (goto-char (point-min))
  1977.       (setq gnus-group-mark-positions
  1978.         (list (cons 'process (and (search-forward "\200" nil t)
  1979.                       (- (point) 2))))))))
  1980.  
  1981. (defun gnus-mouse-face-function (form)
  1982.   (` (let ((string (, form)))
  1983.        (put-text-property 0 (length string) 'mouse-face gnus-mouse-face string)
  1984.        string)))
  1985.  
  1986. (defun gnus-max-width-function (el max-width)
  1987.   (or (numberp max-width) (signal 'wrong-type-argument '(numberp max-width)))
  1988.   (` (let* ((val (eval (, el)))
  1989.         (valstr (if (numberp val)
  1990.             (int-to-string val) val)))
  1991.        (if (> (length valstr) (, max-width))
  1992.        (substring valstr 0 (, max-width))
  1993.      valstr))))
  1994.  
  1995. (defun gnus-parse-format (format spec-alist)
  1996.   ;; This function parses the FORMAT string with the help of the
  1997.   ;; SPEC-ALIST and returns a list that can be eval'ed to return the
  1998.   ;; string.  If the FORMAT string contains the specifiers %( and %)
  1999.   ;; the text between them will have the mouse-face text property.
  2000.   (if (string-match "\\`\\(.*\\)%(\\(.*\\)%)\\(.*\n?\\)\\'" format)
  2001.       (if (and gnus-visual gnus-mouse-face)
  2002.       (let ((pre (substring format (match-beginning 1) (match-end 1)))
  2003.         (button (substring format (match-beginning 2) (match-end 2)))
  2004.         (post (substring format (match-beginning 3) (match-end 3))))
  2005.         (list 'concat
  2006.           (gnus-parse-simple-format pre spec-alist)
  2007.           (gnus-mouse-face-function 
  2008.            (gnus-parse-simple-format button spec-alist))
  2009.           (gnus-parse-simple-format post spec-alist)))
  2010.     (gnus-parse-simple-format
  2011.      (concat (substring format (match-beginning 1) (match-end 1))
  2012.          (substring format (match-beginning 2) (match-end 2))
  2013.          (substring format (match-beginning 3) (match-end 3)))
  2014.      spec-alist))
  2015.     (gnus-parse-simple-format format spec-alist)))
  2016.  
  2017. (defun gnus-parse-simple-format (format spec-alist)
  2018.   ;; This function parses the FORMAT string with the help of the
  2019.   ;; SPEC-ALIST and returns a list that can be eval'ed to return the
  2020.   ;; string. The list will consist of the symbol `format', a format
  2021.   ;; specification string, and a list of forms depending on the
  2022.   ;; SPEC-ALIST.
  2023.   (let ((max-width 0)
  2024.     spec flist fstring newspec elem beg)
  2025.     (save-excursion
  2026.       (gnus-set-work-buffer)
  2027.       (insert format)
  2028.       (goto-char (point-min))
  2029.       (while (re-search-forward "%[-0-9]*\\(,[0-9]+\\)?\\([^0-9]\\)\\(.\\)?" nil t)
  2030.     (setq spec (string-to-char (buffer-substring (match-beginning 2)
  2031.                              (match-end 2))))
  2032.     ;; First check if there are any specs that look anything like
  2033.     ;; "%12,12A", ie. with a "max width specification". These have
  2034.     ;; to be treated specially.
  2035.     (if (setq beg (match-beginning 1))
  2036.         (setq max-width 
  2037.           (string-to-int 
  2038.            (buffer-substring (1+ (match-beginning 1)) (match-end 1))))
  2039.       (setq max-width 0)
  2040.       (setq beg (match-beginning 2)))
  2041.     ;; Find the specification from `spec-alist'.
  2042.     (if (not (setq elem (cdr (assq spec spec-alist))))
  2043.         (setq elem '("*" ?s)))
  2044.     ;; Treat user defined format specifiers specially
  2045.     (and (eq (car elem) 'user-defined)
  2046.          (setq elem
  2047.            (list 
  2048.             (list (intern (concat "gnus-user-format-function-"
  2049.                       (buffer-substring
  2050.                        (match-beginning 3)
  2051.                        (match-end 3))))
  2052.               'header)
  2053.             ?s))
  2054.          (delete-region (match-beginning 3) (match-end 3)))
  2055.     (if (not (zerop max-width))
  2056.         (let ((el (car elem)))
  2057.           (cond ((= (car (cdr elem)) ?c) 
  2058.              (setq el (list 'char-to-string el)))
  2059.             ((= (car (cdr elem)) ?d)
  2060.              (numberp el) (setq el (list 'int-to-string el))))
  2061.           (setq flist (cons (gnus-max-width-function el max-width)
  2062.                 flist))
  2063.           (setq newspec ?s))
  2064.       (setq flist (cons (car elem) flist))
  2065.       (setq newspec (car (cdr elem))))
  2066.     ;; Remove the old specification (and possibly a ",12" string).
  2067.     (delete-region beg (match-end 2))
  2068.     ;; Insert the new specification.
  2069.     (goto-char beg)
  2070.     (insert newspec))
  2071.       (setq fstring (buffer-substring 1 (point-max))))
  2072.     (cons 'format (cons fstring (nreverse flist)))))
  2073.  
  2074. (defun gnus-set-work-buffer ()
  2075.   (if (get-buffer gnus-work-buffer)
  2076.       (progn
  2077.     (set-buffer gnus-work-buffer)
  2078.     (erase-buffer))
  2079.     (set-buffer (get-buffer-create gnus-work-buffer))
  2080.     (kill-all-local-variables)
  2081.     (buffer-disable-undo (current-buffer))
  2082.     (gnus-add-current-to-buffer-list)))
  2083.  
  2084. ;; Article file names when saving.
  2085.  
  2086. (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
  2087.   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  2088. If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
  2089. Otherwise, it is like ~/News/news/group/num."
  2090.   (let ((default
  2091.       (expand-file-name
  2092.        (concat (if (gnus-use-long-file-name 'not-save)
  2093.                (gnus-capitalize-newsgroup newsgroup)
  2094.              (gnus-newsgroup-directory-form newsgroup))
  2095.            "/" (int-to-string (mail-header-number headers)))
  2096.        (or gnus-article-save-directory "~/News"))))
  2097.     (if (and last-file
  2098.          (string-equal (file-name-directory default)
  2099.                (file-name-directory last-file))
  2100.          (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  2101.     default
  2102.       (or last-file default))))
  2103.  
  2104. (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
  2105.   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  2106. If variable `gnus-use-long-file-name' is non-nil, it is
  2107. ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
  2108.   (let ((default
  2109.       (expand-file-name
  2110.        (concat (if (gnus-use-long-file-name 'not-save)
  2111.                newsgroup
  2112.              (gnus-newsgroup-directory-form newsgroup))
  2113.            "/" (int-to-string (mail-header-number headers)))
  2114.        (or gnus-article-save-directory "~/News"))))
  2115.     (if (and last-file
  2116.          (string-equal (file-name-directory default)
  2117.                (file-name-directory last-file))
  2118.          (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  2119.     default
  2120.       (or last-file default))))
  2121.  
  2122. (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
  2123.   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  2124. If variable `gnus-use-long-file-name' is non-nil, it is
  2125. ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
  2126.   (or last-file
  2127.       (expand-file-name
  2128.        (if (gnus-use-long-file-name 'not-save)
  2129.        (gnus-capitalize-newsgroup newsgroup)
  2130.      (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
  2131.        (or gnus-article-save-directory "~/News"))))
  2132.  
  2133. (defun gnus-plain-save-name (newsgroup headers &optional last-file)
  2134.   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  2135. If variable `gnus-use-long-file-name' is non-nil, it is
  2136. ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
  2137.   (or last-file
  2138.       (expand-file-name
  2139.        (if (gnus-use-long-file-name 'not-save)
  2140.        newsgroup
  2141.      (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
  2142.        (or gnus-article-save-directory "~/News"))))
  2143.  
  2144. ;; For subscribing new newsgroup
  2145.  
  2146. (defun gnus-subscribe-hierarchical-interactive (groups)
  2147.   (let ((groups (sort groups 'string<))
  2148.     prefixes prefix start ans group starts)
  2149.     (while groups
  2150.       (setq prefixes (list "^"))
  2151.       (while (and groups prefixes)
  2152.     (while (not (string-match (car prefixes) (car groups)))
  2153.       (setq prefixes (cdr prefixes)))
  2154.     (setq prefix (car prefixes))
  2155.     (setq start (1- (length prefix)))
  2156.     (if (and (string-match "[^\\.]\\." (car groups) start)
  2157.          (cdr groups)
  2158.          (setq prefix 
  2159.                (concat "^" (substring (car groups) 0 (match-end 0))))
  2160.          (string-match prefix (car (cdr groups))))
  2161.         (progn
  2162.           (setq prefixes (cons prefix prefixes))
  2163.           (message "Descend hierarchy %s? ([y]nsq): " 
  2164.                (substring prefix 1 (1- (length prefix))))
  2165.           (setq ans (read-char))
  2166.           (cond ((= ans ?n)
  2167.              (while (and groups 
  2168.                  (string-match prefix 
  2169.                            (setq group (car groups))))
  2170.                (setq gnus-killed-list 
  2171.                  (cons group gnus-killed-list))
  2172.                (gnus-sethash group group gnus-killed-hashtb)
  2173.                (setq groups (cdr groups)))
  2174.              (setq starts (cdr starts)))
  2175.             ((= ans ?s)
  2176.              (while (and groups 
  2177.                  (string-match prefix 
  2178.                            (setq group (car groups))))
  2179.                (gnus-sethash group group gnus-killed-hashtb)
  2180.                (gnus-subscribe-alphabetically (car groups))
  2181.                (setq groups (cdr groups)))
  2182.              (setq starts (cdr starts)))
  2183.             ((= ans ?q)
  2184.              (while groups
  2185.                (setq group (car groups))
  2186.                (setq gnus-killed-list (cons group gnus-killed-list))
  2187.                (gnus-sethash group group gnus-killed-hashtb)
  2188.                (setq groups (cdr groups))))
  2189.             (t nil)))
  2190.       (message "Subscribe %s? ([n]yq)" (car groups))
  2191.       (setq ans (read-char))
  2192.       (setq group (car groups))
  2193.       (cond ((= ans ?y)
  2194.          (gnus-subscribe-alphabetically (car groups))
  2195.          (gnus-sethash group group gnus-killed-hashtb))
  2196.         ((= ans ?q)
  2197.          (while groups
  2198.            (setq group (car groups))
  2199.            (setq gnus-killed-list (cons group gnus-killed-list))
  2200.            (gnus-sethash group group gnus-killed-hashtb)
  2201.            (setq groups (cdr groups))))
  2202.         (t 
  2203.          (setq gnus-killed-list (cons group gnus-killed-list))
  2204.          (gnus-sethash group group gnus-killed-hashtb)))
  2205.       (setq groups (cdr groups)))))))
  2206.  
  2207. (defun gnus-subscribe-randomly (newsgroup)
  2208.   "Subscribe new NEWSGROUP by making it the first newsgroup."
  2209.   (gnus-subscribe-newsgroup newsgroup))
  2210.  
  2211. (defun gnus-subscribe-alphabetically (newgroup)
  2212.   "Subscribe new NEWSGROUP and insert it in alphabetical order."
  2213.   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
  2214.   (let ((groups (cdr gnus-newsrc-alist))
  2215.     before)
  2216.     (while (and (not before) groups)
  2217.       (if (string< newgroup (car (car groups)))
  2218.       (setq before (car (car groups)))
  2219.     (setq groups (cdr groups))))
  2220.     (gnus-subscribe-newsgroup newgroup before)))
  2221.  
  2222. (defun gnus-subscribe-hierarchically (newgroup)
  2223.   "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
  2224.   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
  2225.   (save-excursion
  2226.     (set-buffer (find-file-noselect gnus-current-startup-file))
  2227.     (let ((groupkey newgroup)
  2228.       before)
  2229.       (while (and (not before) groupkey)
  2230.     (goto-char (point-min))
  2231.     (let ((groupkey-re
  2232.            (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
  2233.       (while (and (re-search-forward groupkey-re nil t)
  2234.               (progn
  2235.             (setq before (buffer-substring
  2236.                       (match-beginning 1) (match-end 1)))
  2237.             (string< before newgroup)))))
  2238.     ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
  2239.     (setq groupkey
  2240.           (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
  2241.           (substring groupkey (match-beginning 1) (match-end 1)))))
  2242.       (gnus-subscribe-newsgroup newgroup before))))
  2243.  
  2244. (defun gnus-subscribe-interactively (newsgroup)
  2245.   "Subscribe new NEWSGROUP interactively.
  2246. It is inserted in hierarchical newsgroup order if subscribed. If not,
  2247. it is killed."
  2248.   (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup))
  2249.       (gnus-subscribe-hierarchically newsgroup)
  2250.     (setq gnus-killed-list (cons newsgroup gnus-killed-list))))
  2251.  
  2252. (defun gnus-subscribe-zombies (newsgroup)
  2253.   "Make new NEWSGROUP a zombie group."
  2254.   (setq gnus-zombie-list (cons newsgroup gnus-zombie-list)))
  2255.  
  2256. (defun gnus-subscribe-newsgroup (newsgroup &optional next)
  2257.   "Subscribe new NEWSGROUP.
  2258. If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
  2259. the first newsgroup."
  2260.   ;; We subscribe the group by changing its level to `subscribed'.
  2261.   (gnus-group-change-level 
  2262.    newsgroup gnus-level-default-subscribed
  2263.    gnus-level-killed (gnus-gethash (or next "dummy.group") gnus-newsrc-hashtb))
  2264.   (gnus-message 5 "Subscribe newsgroup: %s" newsgroup))
  2265.  
  2266. ;; For directories
  2267.  
  2268. (defun gnus-newsgroup-directory-form (newsgroup)
  2269.   "Make hierarchical directory name from NEWSGROUP name."
  2270.   (let ((newsgroup (gnus-newsgroup-savable-name newsgroup))
  2271.     (len (length newsgroup))
  2272.     idx)
  2273.     ;; If this is a foreign group, we don't want to translate the
  2274.     ;; entire name.  
  2275.     (if (setq idx (string-match ":" newsgroup))
  2276.     (aset newsgroup idx ?/)
  2277.       (setq idx 0))
  2278.     ;; Replace all occurrences of `.' with `/'.
  2279.     (while (< idx len)
  2280.       (if (= (aref newsgroup idx) ?.)
  2281.       (aset newsgroup idx ?/))
  2282.       (setq idx (1+ idx)))
  2283.     newsgroup))
  2284.  
  2285. (defun gnus-newsgroup-savable-name (group)
  2286.   ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
  2287.   ;; with dots.
  2288.   (gnus-replace-chars-in-string group ?/ ?.))
  2289.  
  2290. (defun gnus-make-directory (dir)
  2291.   "Make DIRECTORY recursively."
  2292.   ;; Why don't we use `(make-directory dir 'parents)'? That's just one
  2293.   ;; of the many mysteries of the universe.
  2294.   (let* ((dir (expand-file-name dir default-directory))
  2295.      dirs err)
  2296.     (if (string-match "/$" dir)
  2297.     (setq dir (substring dir 0 (match-beginning 0))))
  2298.     ;; First go down the path until we find a directory that exists.
  2299.     (while (not (file-exists-p dir))
  2300.       (setq dirs (cons dir dirs))
  2301.       (string-match "/[^/]+$" dir)
  2302.       (setq dir (substring dir 0 (match-beginning 0))))
  2303.     ;; Then create all the subdirs.
  2304.     (while (and dirs (not err))
  2305.       (condition-case ()
  2306.       (make-directory (car dirs))
  2307.     (error (setq err t)))
  2308.       (setq dirs (cdr dirs)))
  2309.     ;; We return whether we were successful or not. 
  2310.     (not dirs)))
  2311.  
  2312. (defun gnus-capitalize-newsgroup (newsgroup)
  2313.   "Capitalize NEWSGROUP name."
  2314.   (and (not (zerop (length newsgroup)))
  2315.        (concat (char-to-string (upcase (aref newsgroup 0)))
  2316.            (substring newsgroup 1))))
  2317.  
  2318. ;; Var
  2319.  
  2320. (defun gnus-simplify-subject (subject &optional re-only)
  2321.   "Remove `Re:' and words in parentheses.
  2322. If optional argument RE-ONLY is non-nil, strip `Re:' only."
  2323.   (let ((case-fold-search t))        ;Ignore case.
  2324.     ;; Remove `Re:' and `Re^N:'.
  2325.     (if (string-match "^re:[ \t]*" subject)
  2326.     (setq subject (substring subject (match-end 0))))
  2327.     ;; Remove words in parentheses from end.
  2328.     (or re-only
  2329.     (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
  2330.       (setq subject (substring subject 0 (match-beginning 0)))))
  2331.     ;; Return subject string.
  2332.     subject))
  2333.  
  2334. ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
  2335. ;; all whitespace.
  2336. (defun gnus-simplify-subject-fuzzy (subject)
  2337.   (let ((case-fold-search t))
  2338.     (save-excursion
  2339.       (gnus-set-work-buffer)
  2340.       (insert subject)
  2341.       (inline (gnus-simplify-buffer-fuzzy))
  2342.       (buffer-string))))
  2343.  
  2344. (defun gnus-simplify-buffer-fuzzy ()
  2345.   (goto-char (point-min))
  2346.   ;; Fix by Stainless Steel Rat <ratinox@ccs.neu.edu>.
  2347.   (while (re-search-forward "^[ \t]*\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;][ \t]*"
  2348.                 nil t)
  2349.     (replace-match "" t t))
  2350.   (goto-char (point-min))
  2351.   (while (re-search-forward "[ \t\n]*([^()]*)[ \t\n]*$" nil t)
  2352.     (replace-match "" t t))
  2353.   (goto-char (point-min))
  2354.   (while (re-search-forward "[ \t]+" nil t)
  2355.     (replace-match " " t t))
  2356.   (goto-char (point-min))
  2357.   (while (re-search-forward "[ \t]+$" nil t)
  2358.     (replace-match "" t t))
  2359.   (goto-char (point-min))
  2360.   (while (re-search-forward "^[ \t]+" nil t)
  2361.     (replace-match "" t t))
  2362.   (if gnus-simplify-subject-fuzzy-regexp
  2363.       (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t)
  2364.     (replace-match "" t t))))
  2365.  
  2366. ;; Add the current buffer to the list of buffers to be killed on exit. 
  2367. (defun gnus-add-current-to-buffer-list ()
  2368.   (or (memq (current-buffer) gnus-buffer-list)
  2369.       (setq gnus-buffer-list (cons (current-buffer) gnus-buffer-list))))
  2370.  
  2371. (defun gnus-string> (s1 s2)
  2372.   (not (or (string< s1 s2)
  2373.        (string= s1 s2))))
  2374.  
  2375. ;; Functions accessing headers.
  2376. ;; Functions are more convenient than macros in some cases.
  2377.  
  2378. (defun gnus-header-number (header)
  2379.   (mail-header-number header))
  2380.  
  2381. (defun gnus-header-subject (header)
  2382.   (mail-header-subject header))
  2383.  
  2384. (defun gnus-header-from (header)
  2385.   (mail-header-from header))
  2386.  
  2387. (defun gnus-header-xref (header)
  2388.   (mail-header-xref header))
  2389.  
  2390. (defun gnus-header-lines (header)
  2391.   (mail-header-lines header))
  2392.  
  2393. (defun gnus-header-date (header)
  2394.   (mail-header-date header))
  2395.  
  2396. (defun gnus-header-id (header)
  2397.   (mail-header-id header))
  2398.  
  2399. (defun gnus-header-message-id (header)
  2400.   (mail-header-id header))
  2401.  
  2402. (defun gnus-header-chars (header)
  2403.   (mail-header-chars header))
  2404.  
  2405. (defun gnus-header-references (header)
  2406.   (mail-header-references header))
  2407.  
  2408. ;;; General various misc type functions.
  2409.  
  2410. (defun gnus-clear-system ()
  2411.   "Clear all variables and buffers."
  2412.   ;; Clear Gnus variables.
  2413.   (let ((variables gnus-variable-list))
  2414.     (while variables
  2415.       (set (car variables) nil)
  2416.       (setq variables (cdr variables))))
  2417.   ;; Clear other internal variables.
  2418.   (setq gnus-list-of-killed-groups nil
  2419.     gnus-have-read-active-file nil
  2420.     gnus-newsrc-alist nil
  2421.     gnus-newsrc-hashtb nil
  2422.     gnus-killed-list nil
  2423.     gnus-zombie-list nil
  2424.     gnus-killed-hashtb nil
  2425.     gnus-active-hashtb nil
  2426.     gnus-moderated-list nil
  2427.     gnus-description-hashtb nil
  2428.     gnus-newsgroup-headers nil
  2429.     gnus-newsgroup-headers-hashtb-by-number nil
  2430.     gnus-newsgroup-name nil
  2431.     gnus-server-alist nil
  2432.     gnus-current-select-method nil)
  2433.   ;; Reset any score variables.
  2434.   (and (boundp 'gnus-score-cache)
  2435.        (set 'gnus-score-cache nil))
  2436.   (and (boundp 'gnus-internal-global-score-files)
  2437.        (set 'gnus-internal-global-score-files nil))
  2438.   ;; Kill the startup file.
  2439.   (and gnus-current-startup-file
  2440.        (get-file-buffer gnus-current-startup-file)
  2441.        (kill-buffer (get-file-buffer gnus-current-startup-file)))
  2442.   ;; Save any cache buffers.
  2443.   (and gnus-use-cache (gnus-cache-save-buffers))
  2444.   ;; Clear the dribble buffer.
  2445.   (gnus-dribble-clear)
  2446.   ;; Kill global KILL file buffer.
  2447.   (if (get-file-buffer (gnus-newsgroup-kill-file nil))
  2448.       (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
  2449.   (gnus-kill-buffer nntp-server-buffer)
  2450.   ;; Kill Gnus buffers.
  2451.   (while gnus-buffer-list
  2452.     (gnus-kill-buffer (car gnus-buffer-list))
  2453.     (setq gnus-buffer-list (cdr gnus-buffer-list))))
  2454.  
  2455. (defun gnus-windows-old-to-new (setting)
  2456.   ;; First we take care of the really, really old Gnus 3 actions.
  2457.   (if (symbolp setting)
  2458.       (setq setting 
  2459.         (cond ((memq setting '(SelectArticle))
  2460.            'article)
  2461.           ((memq setting '(SelectSubject ExpandSubject))
  2462.            'summary)
  2463.           ((memq setting '(SelectNewsgroup ExitNewsgroup))
  2464.            'group)
  2465.           (t setting))))
  2466.   (if (or (listp setting)
  2467.       (not (and gnus-window-configuration
  2468.             (memq setting '(group summary article)))))
  2469.       setting
  2470.     (let* ((setting (if (eq setting 'group) 
  2471.             (if (assq 'newsgroup gnus-window-configuration)
  2472.                 'newsgroup
  2473.               'newsgroups) setting))
  2474.        (elem (car (cdr (assq setting gnus-window-configuration))))
  2475.        (total (apply '+ elem))
  2476.        (types '(group summary article))
  2477.        (pbuf (if (eq setting 'newsgroups) 'group 'summary))
  2478.        (i 0)
  2479.        perc
  2480.        out)
  2481.       (while (< i 3)
  2482.     (or (not (numberp (nth i elem)))
  2483.         (zerop (nth i elem))
  2484.         (progn
  2485.           (setq perc  (/ (* 1.0 (nth 0 elem)) total))
  2486.           (setq out (cons (if (eq pbuf (nth i types))
  2487.                   (vector (nth i types) perc 'point)
  2488.                 (vector (nth i types) perc))
  2489.                   out))))
  2490.     (setq i (1+ i)))
  2491.       (list (nreverse out)))))
  2492.        
  2493. (defun gnus-add-configuration (conf)
  2494.   (setq gnus-buffer-configuration 
  2495.     (cons conf (delq (assq (car conf) gnus-buffer-configuration)
  2496.              gnus-buffer-configuration))))
  2497.  
  2498. (defun gnus-configure-windows (setting &optional force)
  2499.   (setq setting (gnus-windows-old-to-new setting))
  2500.   (let ((r (if (symbolp setting)
  2501.            (cdr (assq setting gnus-buffer-configuration))
  2502.          setting))
  2503.     (in-buf (current-buffer))
  2504.     rule val w height hor ohor heights sub jump-buffer
  2505.     rel total to-buf all-visible)
  2506.     (or r (error "No such setting: %s" setting))
  2507.  
  2508.     (if (and (not force) (setq all-visible (gnus-all-windows-visible-p r)))
  2509.     ;; All the windows mentioned are already visible, so we just
  2510.     ;; put point in the assigned buffer, and do not touch the
  2511.     ;; winconf. 
  2512.     (select-window (get-buffer-window all-visible t))
  2513.      
  2514.  
  2515.       ;; Either remove all windows or just remove all Gnus windows.
  2516.       (if gnus-use-full-window
  2517.       (delete-other-windows)
  2518.     (gnus-remove-some-windows)
  2519.     (switch-to-buffer nntp-server-buffer))
  2520.  
  2521.       (while r
  2522.     (setq hor (car r)
  2523.           ohor nil)
  2524.  
  2525.     ;; We have to do the (possible) horizontal splitting before the
  2526.     ;; vertical. 
  2527.     (if (and (listp (car hor)) 
  2528.          (eq (car (car hor)) 'horizontal))
  2529.         (progn
  2530.           (split-window 
  2531.            nil
  2532.            (if (integerp (nth 1 (car hor)))
  2533.            (nth 1 (car hor))
  2534.          (- (frame-width) (floor (* (frame-width) (nth 1 (car hor))))))
  2535.            t)
  2536.           (setq hor (cdr hor))))
  2537.  
  2538.     ;; Go through the rules and eval the elements that are to be
  2539.     ;; evalled.  
  2540.     (while hor
  2541.       (if (setq val (if (vectorp (car hor)) (car hor) (eval (car hor))))
  2542.           (progn
  2543.         ;; Expand short buffer name.
  2544.         (setq w (aref val 0))
  2545.         (and (setq w (cdr (assq w gnus-window-to-buffer)))
  2546.              (progn
  2547.                (setq val (apply 'vector (mapcar 'identity val)))
  2548.                (aset val 0 w)))
  2549.         (setq ohor (cons val ohor))))
  2550.       (setq hor (cdr hor)))
  2551.     (setq rule (cons (nreverse ohor) rule))
  2552.     (setq r (cdr r)))
  2553.       (setq rule (nreverse rule))
  2554.  
  2555.       ;; We tally the window sizes.
  2556.       (setq total (window-height))
  2557.       (while rule
  2558.     (setq hor (car rule))
  2559.     (if (and (listp (car hor)) (eq (car (car hor)) 'horizontal))
  2560.         (setq hor (cdr hor)))
  2561.     (setq sub 0)
  2562.     (while hor
  2563.       (setq rel (aref (car hor) 1)
  2564.         heights (cons
  2565.              (cond ((and (floatp rel) (= 1.0 rel))
  2566.                 'x)
  2567.                    ((integerp rel)
  2568.                 rel)
  2569.                    (t
  2570.                 (max (floor (* total rel)) 4)))
  2571.              heights)
  2572.         sub (+ sub (if (numberp (car heights)) (car heights) 0))
  2573.         hor (cdr hor)))
  2574.     (setq heights (nreverse heights)
  2575.           hor (car rule))
  2576.  
  2577.     ;; We then go through these heights and create windows for them.
  2578.     (while heights
  2579.       (setq height (car heights)
  2580.         heights (cdr heights))
  2581.       (and (eq height 'x)
  2582.            (setq height (- total sub)))
  2583.       (and heights
  2584.            (split-window nil height))
  2585.       (setq to-buf (aref (car hor) 0))
  2586.       (switch-to-buffer 
  2587.        (cond ((not to-buf)
  2588.           in-buf)
  2589.          ((symbolp to-buf)
  2590.           (symbol-value (aref (car hor) 0)))
  2591.          (t
  2592.           (aref (car hor) 0))))
  2593.       (and (> (length (car hor)) 2)
  2594.            (eq (aref (car hor) 2) 'point)
  2595.            (setq jump-buffer (current-buffer)))
  2596.       (other-window 1)
  2597.       (setq hor (cdr hor)))
  2598.       
  2599.     (setq rule (cdr rule)))
  2600.  
  2601.       ;; Finally, we pop to the buffer that's supposed to have point. 
  2602.       (or jump-buffer (error "Missing `point' in spec for %s" setting))
  2603.  
  2604.       (select-window (get-buffer-window jump-buffer t))
  2605.       (set-buffer jump-buffer))))
  2606.  
  2607. (defun gnus-all-windows-visible-p (rule)
  2608.   (let (invisible hor jump-buffer val buffer)
  2609.     ;; Go through the rules and eval the elements that are to be
  2610.     ;; evalled.  
  2611.     (while (and rule (not invisible))
  2612.       (setq hor (car rule)
  2613.         rule (cdr rule))
  2614.       (while (and hor (not invisible))
  2615.     (if (setq val (if (vectorp (car hor)) 
  2616.               (car hor)
  2617.             (if (not (eq (car (car hor)) 'horizontal))
  2618.                 (eval (car hor)))))
  2619.         (progn
  2620.           ;; Expand short buffer name.
  2621.           (setq buffer (or (cdr (assq (aref val 0) gnus-window-to-buffer))
  2622.                    (aref val 0)))
  2623.           (setq buffer (if (symbolp buffer) (symbol-value buffer)
  2624.                  buffer))
  2625.           (and (> (length val) 2) (eq 'point (aref val 2))
  2626.            (setq jump-buffer buffer))
  2627.           (setq invisible (not (and buffer (get-buffer-window buffer))))))
  2628.     (setq hor (cdr hor))))
  2629.     (and (not invisible) jump-buffer)))
  2630.  
  2631. (defun gnus-window-top-edge (&optional window)
  2632.   (nth 1 (window-edges window)))
  2633.  
  2634. (defun gnus-remove-some-windows ()
  2635.   (let ((buffers gnus-window-to-buffer)
  2636.     buf bufs lowest-buf lowest)
  2637.     (save-excursion
  2638.       ;; Remove windows on all known Gnus buffers.
  2639.       (while buffers
  2640.     (setq buf (cdr (car buffers)))
  2641.     (if (symbolp buf)
  2642.         (setq buf (and (boundp buf) (symbol-value buf))))
  2643.     (and buf 
  2644.          (get-buffer-window buf)
  2645.          (progn
  2646.            (setq bufs (cons buf bufs))
  2647.            (pop-to-buffer buf)
  2648.            (if (or (not lowest)
  2649.                (< (gnus-window-top-edge) lowest))
  2650.            (progn
  2651.              (setq lowest (gnus-window-top-edge))
  2652.              (setq lowest-buf buf)))))
  2653.     (setq buffers (cdr buffers)))
  2654.       ;; Remove windows on *all* summary buffers.
  2655.       (let (wins)
  2656.     (walk-windows
  2657.      (lambda (win)
  2658.        (let ((buf (window-buffer win)))
  2659.          (if (string-match  "^\\*Summary" (buffer-name buf))
  2660.          (progn
  2661.            (setq bufs (cons buf bufs))
  2662.            (pop-to-buffer buf)
  2663.            (if (or (not lowest)
  2664.                (< (gnus-window-top-edge) lowest))
  2665.                (progn
  2666.              (setq lowest-buf buf)
  2667.              (setq lowest (gnus-window-top-edge))))))))))
  2668.       (and lowest-buf 
  2669.        (progn
  2670.          (pop-to-buffer lowest-buf)
  2671.          (switch-to-buffer nntp-server-buffer)))
  2672.       (while bufs
  2673.     (and (not (eq (car bufs) lowest-buf))
  2674.          (delete-windows-on (car bufs)))
  2675.     (setq bufs (cdr bufs))))))
  2676.               
  2677. (defun gnus-version ()
  2678.   "Version numbers of this version of Gnus."
  2679.   (interactive)
  2680.   (let ((methods gnus-valid-select-methods)
  2681.     (mess gnus-version)
  2682.     meth)
  2683.     ;; Go through all the legal select methods and add their version
  2684.     ;; numbers to the total version string. Only the backends that are
  2685.     ;; currently in use will have their message numbers taken into
  2686.     ;; consideration. 
  2687.     (while methods
  2688.       (setq meth (intern (concat (car (car methods)) "-version")))
  2689.       (and (boundp meth)
  2690.        (stringp (symbol-value meth))
  2691.        (setq mess (concat mess "; " (symbol-value meth))))
  2692.       (setq methods (cdr methods)))
  2693.     (gnus-message 2 mess)))
  2694.  
  2695. (defun gnus-info-find-node ()
  2696.   "Find Info documentation of Gnus."
  2697.   (interactive)
  2698.   ;; Enlarge info window if needed.
  2699.   (let ((mode major-mode))
  2700.     (gnus-configure-windows 'info)
  2701.     (Info-goto-node (car (cdr (assq mode gnus-info-nodes))))))
  2702.  
  2703. (defun gnus-overload-functions (&optional overloads)
  2704.   "Overload functions specified by optional argument OVERLOADS.
  2705. If nothing is specified, use the variable gnus-overload-functions."
  2706.   (let ((defs nil)
  2707.     (overloads (or overloads gnus-overload-functions)))
  2708.     (while overloads
  2709.       (setq defs (car overloads))
  2710.       (setq overloads (cdr overloads))
  2711.       ;; Load file before overloading function if necessary.  Make
  2712.       ;; sure we cannot use `require' always.
  2713.       (and (not (fboundp (car defs)))
  2714.        (car (cdr (cdr defs)))
  2715.        (load (car (cdr (cdr defs))) nil 'nomessage))
  2716.       (fset (car defs) (car (cdr defs))))))
  2717.  
  2718. (defun gnus-replace-chars-in-string (string &rest pairs)
  2719.   "Replace characters in STRING from FROM to TO."
  2720.   (let ((string (substring string 0))    ;Copy string.
  2721.     (len (length string))
  2722.     (idx 0)
  2723.     sym to)
  2724.     (or (zerop (% (length pairs) 2)) 
  2725.     (error "Odd number of translation pairs"))
  2726.     (setplist 'sym pairs)
  2727.     ;; Replace all occurrences of FROM with TO.
  2728.     (while (< idx len)
  2729.       (if (setq to (get 'sym (aref string idx)))
  2730.       (aset string idx to))
  2731.       (setq idx (1+ idx)))
  2732.     string))
  2733.  
  2734. (defun gnus-days-between (date1 date2)
  2735.   ;; Return the number of days between date1 and date2.
  2736.   (- (gnus-day-number date1) (gnus-day-number date2)))
  2737.  
  2738. (defun gnus-day-number (date)
  2739.   (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) )
  2740.              (timezone-parse-date date))))
  2741.     (timezone-absolute-from-gregorian 
  2742.      (nth 1 dat) (nth 2 dat) (car dat))))
  2743.  
  2744. ;; Returns a floating point number that says how many seconds have
  2745. ;; lapsed between Jan 1 12:00:00 1970 and DATE.
  2746. (defun gnus-seconds-since-epoch (date)
  2747.   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
  2748.             (timezone-parse-date date)))
  2749.      (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
  2750.             (timezone-parse-time
  2751.              (aref (timezone-parse-date date) 3))))
  2752.      (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
  2753.             (timezone-parse-date "Jan 1 12:00:00 1970")))
  2754.      (tday (- (timezone-absolute-from-gregorian 
  2755.            (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
  2756.           (timezone-absolute-from-gregorian 
  2757.            (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
  2758.     (+ (nth 2 ttime)
  2759.        (* (nth 1 ttime) 60)
  2760.        (* 1.0 (nth 0 ttime) 60 60)
  2761.        (* 1.0 tday 60 60 24))))
  2762.  
  2763. (defun gnus-file-newer-than (file date)
  2764.   (let ((fdate (nth 5 (file-attributes file))))
  2765.     (or (> (car fdate) (car date))
  2766.     (and (= (car fdate) (car date))
  2767.          (> (nth 1 fdate) (nth 1 date))))))
  2768.  
  2769. (defun gnus-group-read-only-p (&optional group)
  2770.   "Check whether GROUP supports editing or not.
  2771. If GROUP is nil, `gnus-newsgroup-name' will be checked instead.  Note
  2772. that that variable is buffer-local to the summary buffers."
  2773.   (let ((group (or group gnus-newsgroup-name)))
  2774.     (not (gnus-check-backend-function 'request-replace-article group))))
  2775.  
  2776. ;; Two silly functions to ensure that all `y-or-n-p' questions clear
  2777. ;; the echo area.
  2778. (defun gnus-y-or-n-p (prompt)
  2779.   (prog1
  2780.       (y-or-n-p prompt)
  2781.     (message "")))
  2782.  
  2783. (defun gnus-yes-or-no-p (prompt)
  2784.   (prog1
  2785.       (yes-or-no-p prompt)
  2786.     (message "")))
  2787.  
  2788. ;; Check whether to use long file names.
  2789. (defun gnus-use-long-file-name (symbol)
  2790.   ;; The variable has to be set...
  2791.   (and gnus-use-long-file-name
  2792.        ;; If it isn't a list, then we return t.
  2793.        (or (not (listp gnus-use-long-file-name))
  2794.        ;; If it is a list, and the list contains `symbol', we
  2795.        ;; return nil.  
  2796.        (not (memq symbol gnus-use-long-file-name)))))
  2797.  
  2798. ;; I suspect there's a better way, but I haven't taken the time to do
  2799. ;; it yet. -erik selberg@cs.washington.edu
  2800. (defun gnus-dd-mmm (messy-date)
  2801.   "Return a string like DD-MMM from a big messy string"
  2802.   (let ((datevec (timezone-parse-date messy-date)))
  2803.     (format "%2s-%s"
  2804.         (or (aref datevec 2) "??")
  2805.         (capitalize
  2806.          (or (car 
  2807.           (nth (1- (string-to-number (aref datevec 1)))
  2808.                timezone-months-assoc))
  2809.          "???")))))
  2810.  
  2811. ;; Make a hash table (default and minimum size is 255).
  2812. ;; Optional argument HASHSIZE specifies the table size.
  2813. (defun gnus-make-hashtable (&optional hashsize)
  2814.   (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 255) 255) 0))
  2815.  
  2816. ;; Make a number that is suitable for hashing; bigger than MIN and one
  2817. ;; less than 2^x.
  2818. (defun gnus-create-hash-size (min)
  2819.   (let ((i 1))
  2820.     (while (< i min)
  2821.       (setq i (* 2 i)))
  2822.     (1- i)))
  2823.  
  2824. ;; Show message if message has a lower level than `gnus-verbose'. 
  2825. ;; Guide-line for numbers:
  2826. ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
  2827. ;; for things that take a long time, 7 - not very important messages
  2828. ;; on stuff, 9 - messages inside loops.
  2829. (defun gnus-message (level &rest args)
  2830.   (if (<= level gnus-verbose)
  2831.       (apply 'message args)
  2832.     ;; We have to do this format thingy here even if the result isn't
  2833.     ;; shown - the return value has to be the same as the return value
  2834.     ;; from `message'.
  2835.     (apply 'format args)))
  2836.  
  2837. ;; Generate a unique new group name.
  2838. (defun gnus-generate-new-group-name (leaf)
  2839.   (let ((name leaf)
  2840.     (num 0))
  2841.     (while (gnus-gethash name gnus-newsrc-hashtb)
  2842.       (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">")))
  2843.     name))
  2844.  
  2845. (defun gnus-ephemeral-group-p (group)
  2846.   "Say whether GROUP is ephemeral or not."
  2847.   (assoc 'quit-config (gnus-find-method-for-group group)))
  2848.  
  2849. (defun gnus-group-quit-config (group)
  2850.   "Return the quit-config of GROUP."
  2851.   (nth 1 (assoc 'quit-config (gnus-find-method-for-group group))))
  2852.  
  2853. (defun gnus-simplify-mode-line ()
  2854.   "Make mode lines a bit simpler."
  2855.   (setq mode-line-modified "-- ")
  2856.   (if (listp mode-line-format)
  2857.       (progn
  2858.     (make-local-variable 'mode-line-format)
  2859.     (setq mode-line-format (copy-sequence mode-line-format))
  2860.     (and (equal (nth 3 mode-line-format) "   ")
  2861.          (setcar (nthcdr 3 mode-line-format) "")))))
  2862.  
  2863. ;;; List and range functions
  2864.  
  2865. (defun gnus-last-element (list)
  2866.   "Return last element of LIST."
  2867.   (while (cdr list)
  2868.     (setq list (cdr list)))
  2869.   (car list))
  2870.  
  2871. (defun gnus-copy-sequence (list)
  2872.   "Do a complete, total copy of a list."
  2873.   (if (and (consp list) (not (consp (cdr list))))
  2874.       (cons (car list) (cdr list))
  2875.     (mapcar (lambda (elem) (if (consp elem) 
  2876.                    (if (consp (cdr elem))
  2877.                    (gnus-copy-sequence elem)
  2878.                  (cons (car elem) (cdr elem)))
  2879.                  elem))
  2880.         list)))
  2881.  
  2882. (defun gnus-set-difference (list1 list2)
  2883.   "Return a list of elements of LIST1 that do not appear in LIST2."
  2884.   (let ((list1 (copy-sequence list1)))
  2885.     (while list2
  2886.       (setq list1 (delq (car list2) list1))
  2887.       (setq list2 (cdr list2)))
  2888.     list1))
  2889.  
  2890. (defun gnus-sorted-complement (list1 list2)
  2891.   "Return a list of elements of LIST1 that do not appear in LIST2.
  2892. Both lists have to be sorted over <."
  2893.   (let (out)
  2894.     (if (or (null list1) (null list2))
  2895.     (or list1 list2)
  2896.       (while (and list1 list2)
  2897.     (cond ((= (car list1) (car list2))
  2898.            (setq list1 (cdr list1)
  2899.              list2 (cdr list2)))
  2900.           ((< (car list1) (car list2))
  2901.            (setq out (cons (car list1) out))
  2902.            (setq list1 (cdr list1)))
  2903.           (t
  2904.            (setq out (cons (car list2) out))
  2905.            (setq list2 (cdr list2)))))
  2906.       (nconc (nreverse out) (or list1 list2)))))
  2907.  
  2908. (defun gnus-intersection (list1 list2)      
  2909.   (let ((result nil))
  2910.     (while list2
  2911.       (if (memq (car list2) list1)
  2912.       (setq result (cons (car list2) result)))
  2913.       (setq list2 (cdr list2)))
  2914.     result))
  2915.  
  2916. (defun gnus-sorted-intersection (list1 list2)
  2917.   ;; LIST1 and LIST2 have to be sorted over <.
  2918.   (let (out)
  2919.     (while (and list1 list2)
  2920.       (cond ((= (car list1) (car list2))
  2921.          (setq out (cons (car list1) out)
  2922.            list1 (cdr list1)
  2923.            list2 (cdr list2)))
  2924.         ((< (car list1) (car list2))
  2925.          (setq list1 (cdr list1)))
  2926.         (t
  2927.          (setq list2 (cdr list2)))))
  2928.     (nreverse out)))
  2929.  
  2930. (defun gnus-set-sorted-intersection (list1 list2)
  2931.   ;; LIST1 and LIST2 have to be sorted over <.
  2932.   ;; This function modifies LIST1.
  2933.   (let* ((top (cons nil list1))
  2934.      (prev top))
  2935.     (while (and list1 list2)
  2936.       (cond ((= (car list1) (car list2))
  2937.          (setq prev list1
  2938.            list1 (cdr list1)
  2939.            list2 (cdr list2)))
  2940.         ((< (car list1) (car list2))
  2941.          (setcdr prev (cdr list1))
  2942.          (setq list1 (cdr list1)))
  2943.         (t
  2944.          (setq list2 (cdr list2)))))
  2945.     (setcdr prev nil)
  2946.     (cdr top)))
  2947.  
  2948. (defun gnus-compress-sequence (numbers &optional always-list)
  2949.   "Convert list of numbers to a list of ranges or a single range.
  2950. If ALWAYS-LIST is non-nil, this function will always release a list of
  2951. ranges."
  2952.   (let* ((first (car numbers))
  2953.      (last (car numbers))
  2954.      result)
  2955.     (if (null numbers)
  2956.     nil
  2957.       (if (not (listp (cdr numbers)))
  2958.       numbers
  2959.     (while numbers
  2960.       (cond ((= last (car numbers)) nil) ;Omit duplicated number
  2961.         ((= (1+ last) (car numbers)) ;Still in sequence
  2962.          (setq last (car numbers)))
  2963.         (t            ;End of one sequence
  2964.          (setq result 
  2965.                (cons (if (= first last) first
  2966.                    (cons first last)) result))
  2967.          (setq first (car numbers))
  2968.          (setq last  (car numbers))))
  2969.       (setq numbers (cdr numbers)))
  2970.     (if (and (not always-list) (null result))
  2971.         (if (= first last) (list first) (cons first last))
  2972.       (nreverse (cons (if (= first last) first (cons first last))
  2973.               result)))))))
  2974.  
  2975. (defalias 'gnus-uncompress-sequence 'gnus-uncompress-range)
  2976. (defun gnus-uncompress-range (ranges)
  2977.   "Expand a list of ranges into a list of numbers.
  2978. RANGES is either a single range on the form `(num . num)' or a list of
  2979. these ranges."
  2980.   (let (first last result)
  2981.     (cond 
  2982.      ((null ranges)
  2983.       nil)
  2984.      ((not (listp (cdr ranges)))
  2985.       (setq first (car ranges))
  2986.       (setq last (cdr ranges))
  2987.       (while (<= first last)
  2988.     (setq result (cons first result))
  2989.     (setq first (1+ first)))
  2990.       (nreverse result))
  2991.      (t
  2992.       (while ranges
  2993.     (if (atom (car ranges))
  2994.         (if (numberp (car ranges))
  2995.         (setq result (cons (car ranges) result)))
  2996.       (setq first (car (car ranges)))
  2997.       (setq last  (cdr (car ranges)))
  2998.       (while (<= first last)
  2999.         (setq result (cons first result))
  3000.         (setq first (1+ first))))
  3001.     (setq ranges (cdr ranges)))
  3002.       (nreverse result)))))
  3003.  
  3004. (defun gnus-add-to-range (ranges list)
  3005.   "Return a list of ranges that has all articles from both RANGES and LIST.
  3006. Note: LIST has to be sorted over `<'."
  3007.   (if (not ranges)
  3008.       (gnus-compress-sequence list t)
  3009.     (setq list (copy-sequence list))
  3010.     (or (listp (cdr ranges))
  3011.     (setq ranges (list ranges)))
  3012.     (let ((out ranges)
  3013.       ilist lowest highest temp)
  3014.       (while (and ranges list)
  3015.     (setq ilist list)
  3016.     (setq lowest (or (and (atom (car ranges)) (car ranges))
  3017.              (car (car ranges))))
  3018.     (while (and list (cdr list) (< (car (cdr list)) lowest))
  3019.       (setq list (cdr list)))
  3020.     (if (< (car ilist) lowest)
  3021.         (progn
  3022.           (setq temp list)
  3023.           (setq list (cdr list))
  3024.           (setcdr temp nil)
  3025.           (setq out (nconc (gnus-compress-sequence ilist t) out))))
  3026.     (setq highest (or (and (atom (car ranges)) (car ranges))
  3027.               (cdr (car ranges))))
  3028.     (while (and list (<= (car list) highest))
  3029.       (setq list (cdr list)))
  3030.     (setq ranges (cdr ranges)))
  3031.       (if list
  3032.       (setq out (nconc (gnus-compress-sequence list t) out)))
  3033.       (setq out (sort out (lambda (r1 r2) 
  3034.                 (< (or (and (atom r1) r1) (car r1))
  3035.                    (or (and (atom r2) r2) (car r2))))))
  3036.       (setq ranges out)
  3037.       (while ranges
  3038.     (if (atom (car ranges))
  3039.         (if (cdr ranges)
  3040.         (if (atom (car (cdr ranges)))
  3041.             (if (= (1+ (car ranges)) (car (cdr ranges)))
  3042.             (progn
  3043.               (setcar ranges (cons (car ranges) 
  3044.                            (car (cdr ranges))))
  3045.               (setcdr ranges (cdr (cdr ranges)))))
  3046.           (if (= (1+ (car ranges)) (car (car (cdr ranges))))
  3047.               (progn
  3048.             (setcar (car (cdr ranges)) (car ranges))
  3049.             (setcar ranges (car (cdr ranges)))
  3050.             (setcdr ranges (cdr (cdr ranges)))))))
  3051.       (if (cdr ranges)
  3052.           (if (atom (car (cdr ranges)))
  3053.           (if (= (1+ (cdr (car ranges))) (car (cdr ranges)))
  3054.               (progn
  3055.             (setcdr (car ranges) (car (cdr ranges)))
  3056.             (setcdr ranges (cdr (cdr ranges)))))
  3057.         (if (= (1+ (cdr (car ranges))) (car (car (cdr ranges))))
  3058.             (progn
  3059.               (setcdr (car ranges) (cdr (car (cdr ranges))))
  3060.               (setcdr ranges (cdr (cdr ranges))))))))
  3061.     (setq ranges (cdr ranges)))
  3062.       out)))
  3063.  
  3064. (defun gnus-remove-from-range (ranges list)
  3065.   "Return a list of ranges that has all articles from LIST removed from RANGES.
  3066. Note: LIST has to be sorted over `<'."
  3067.   ;; !!! This function shouldn't look like this, but I've got a headache.
  3068.   (gnus-compress-sequence 
  3069.    (gnus-sorted-complement
  3070.     (gnus-uncompress-range ranges) list)))
  3071.  
  3072. (defun gnus-member-of-range (number ranges)
  3073.   (if (not (listp (cdr ranges)))
  3074.       (and (>= number (car ranges)) 
  3075.        (<= number (cdr ranges)))
  3076.     (let ((not-stop t))
  3077.       (while (and ranges 
  3078.           (if (numberp (car ranges))
  3079.               (>= number (car ranges))
  3080.             (>= number (car (car ranges))))
  3081.           not-stop)
  3082.     (if (if (numberp (car ranges))
  3083.         (= number (car ranges))
  3084.           (and (>= number (car (car ranges)))
  3085.            (<= number (cdr (car ranges)))))
  3086.         (setq not-stop nil))
  3087.     (setq ranges (cdr ranges)))
  3088.       (not not-stop))))
  3089.  
  3090.  
  3091. ;;;
  3092. ;;; Gnus group mode
  3093. ;;;
  3094.  
  3095. (defvar gnus-group-mode-map nil)
  3096. (defvar gnus-group-group-map nil)
  3097. (defvar gnus-group-mark-map nil)
  3098. (defvar gnus-group-list-map nil)
  3099. (defvar gnus-group-help-map nil)
  3100. (defvar gnus-group-sub-map nil)
  3101. (put 'gnus-group-mode 'mode-class 'special)
  3102.  
  3103. (if gnus-group-mode-map
  3104.     nil
  3105.   (setq gnus-group-mode-map (make-keymap))
  3106.   (suppress-keymap gnus-group-mode-map)
  3107.   (define-key gnus-group-mode-map " " 'gnus-group-read-group)
  3108.   (define-key gnus-group-mode-map "=" 'gnus-group-select-group)
  3109.   (define-key gnus-group-mode-map "\r" 'gnus-group-select-group)
  3110.   (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group)
  3111.   (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group)
  3112.   (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group)
  3113.   (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group)
  3114.   (define-key gnus-group-mode-map "N" 'gnus-group-next-group)
  3115.   (define-key gnus-group-mode-map "P" 'gnus-group-prev-group)
  3116.   (define-key gnus-group-mode-map
  3117.     "\M-n" 'gnus-group-next-unread-group-same-level)
  3118.   (define-key gnus-group-mode-map 
  3119.     "\M-p" 'gnus-group-prev-unread-group-same-level)
  3120.   (define-key gnus-group-mode-map "," 'gnus-group-best-unread-group)
  3121.   (define-key gnus-group-mode-map "." 'gnus-group-first-unread-group)
  3122.   (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group)
  3123.   (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group)
  3124.   (define-key gnus-group-mode-map "c" 'gnus-group-catchup-current)
  3125.   (define-key gnus-group-mode-map "C" 'gnus-group-catchup-current-all)
  3126.   (define-key gnus-group-mode-map "l" 'gnus-group-list-groups)
  3127.   (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups)
  3128.   (define-key gnus-group-mode-map "m" 'gnus-group-mail)
  3129.   (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news)
  3130.   (define-key gnus-group-mode-map "\M-g" 'gnus-group-get-new-news-this-group)
  3131.   (define-key gnus-group-mode-map "R" 'gnus-group-restart)
  3132.   (define-key gnus-group-mode-map "r" 'gnus-group-read-init-file)
  3133.   (define-key gnus-group-mode-map "B" 'gnus-group-browse-foreign-server)
  3134.   (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups)
  3135.   (define-key gnus-group-mode-map "F" 'gnus-find-new-newsgroups)
  3136.   (define-key gnus-group-mode-map "\C-c\C-d" 'gnus-group-describe-group)
  3137.   (define-key gnus-group-mode-map "\M-d" 'gnus-group-describe-all-groups)
  3138.   (define-key gnus-group-mode-map "\C-c\C-a" 'gnus-group-apropos)
  3139.   (define-key gnus-group-mode-map "\C-c\M-\C-a" 'gnus-group-description-apropos)
  3140.   (define-key gnus-group-mode-map "a" 'gnus-group-post-news)
  3141.   (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill)
  3142.   (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill)
  3143.   (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group)
  3144.   (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group)
  3145.   (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region)
  3146.   (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups)
  3147.   (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-group-list-killed)
  3148.   (define-key gnus-group-mode-map "\C-c\C-x" 'gnus-group-expire-articles)
  3149.   (define-key gnus-group-mode-map "\C-c\M-\C-x" 'gnus-group-expire-all-groups)
  3150.   (define-key gnus-group-mode-map "V" 'gnus-version)
  3151.   (define-key gnus-group-mode-map "s" 'gnus-group-save-newsrc)
  3152.   (define-key gnus-group-mode-map "z" 'gnus-group-suspend)
  3153.   (define-key gnus-group-mode-map "Z" 'gnus-group-clear-dribble)
  3154.   (define-key gnus-group-mode-map "q" 'gnus-group-exit)
  3155.   (define-key gnus-group-mode-map "Q" 'gnus-group-quit)
  3156.   (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly)
  3157.   (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node)
  3158.   (define-key gnus-group-mode-map "\M-e" 'gnus-group-edit-group-method)
  3159.   (define-key gnus-group-mode-map "^" 'gnus-group-enter-server-mode)
  3160.   (define-key gnus-group-mode-map gnus-mouse-2 'gnus-mouse-pick-group)
  3161.   (define-key gnus-group-mode-map "<" 'beginning-of-buffer)
  3162.   (define-key gnus-group-mode-map ">" 'end-of-buffer)
  3163.   (define-key gnus-group-mode-map "\C-c\C-b" 'gnus-bug)
  3164.   (define-key gnus-group-mode-map "\C-c\C-s" 'gnus-group-sort-groups)
  3165.  
  3166.   (define-key gnus-group-mode-map "#" 'gnus-group-mark-group)
  3167.   (define-key gnus-group-mode-map "\M-#" 'gnus-group-unmark-group)
  3168.   (define-prefix-command 'gnus-group-mark-map)
  3169.   (define-key gnus-group-mode-map "M" 'gnus-group-mark-map)
  3170.   (define-key gnus-group-mark-map "m" 'gnus-group-mark-group)
  3171.   (define-key gnus-group-mark-map "u" 'gnus-group-unmark-group)
  3172.   (define-key gnus-group-mark-map "w" 'gnus-group-mark-region)
  3173.  
  3174.   (define-prefix-command 'gnus-group-group-map)
  3175.   (define-key gnus-group-mode-map "G" 'gnus-group-group-map)
  3176.   (define-key gnus-group-group-map "d" 'gnus-group-make-directory-group)
  3177.   (define-key gnus-group-group-map "h" 'gnus-group-make-help-group)
  3178.   (define-key gnus-group-group-map "a" 'gnus-group-make-archive-group)
  3179.   (define-key gnus-group-group-map "k" 'gnus-group-make-kiboze-group)
  3180.   (define-key gnus-group-group-map "m" 'gnus-group-make-group)
  3181.   (define-key gnus-group-group-map "E" 'gnus-group-edit-group)
  3182.   (define-key gnus-group-group-map "e" 'gnus-group-edit-group-method)
  3183.   (define-key gnus-group-group-map "p" 'gnus-group-edit-group-parameters)
  3184.   (define-key gnus-group-group-map "v" 'gnus-group-add-to-virtual)
  3185.   (define-key gnus-group-group-map "V" 'gnus-group-make-empty-virtual)
  3186.   (define-key gnus-group-group-map "D" 'gnus-group-enter-directory)
  3187.   (define-key gnus-group-group-map "f" 'gnus-group-make-doc-group)
  3188.   ;;(define-key gnus-group-group-map "sb" 'gnus-group-brew-soup)
  3189.   ;;(define-key gnus-group-group-map "sw" 'gnus-soup-save-areas)
  3190.   ;;(define-key gnus-group-group-map "ss" 'gnus-soup-send-replies)
  3191.   ;;(define-key gnus-group-group-map "sp" 'gnus-soup-pack-packet)
  3192.   ;;(define-key gnus-group-group-map "sr" 'nnsoup-pack-replies)
  3193.  
  3194.   (define-prefix-command 'gnus-group-list-map)
  3195.   (define-key gnus-group-mode-map "A" 'gnus-group-list-map)
  3196.   (define-key gnus-group-list-map "k" 'gnus-group-list-killed)
  3197.   (define-key gnus-group-list-map "z" 'gnus-group-list-zombies)
  3198.   (define-key gnus-group-list-map "s" 'gnus-group-list-groups)
  3199.   (define-key gnus-group-list-map "u" 'gnus-group-list-all-groups)
  3200.   (define-key gnus-group-list-map "a" 'gnus-group-apropos)
  3201.   (define-key gnus-group-list-map "d" 'gnus-group-description-apropos)
  3202.   (define-key gnus-group-list-map "m" 'gnus-group-list-matching)
  3203.   (define-key gnus-group-list-map "M" 'gnus-group-list-all-matching)
  3204.  
  3205.   (define-prefix-command 'gnus-group-help-map)
  3206.   (define-key gnus-group-mode-map "H" 'gnus-group-help-map)
  3207.   (define-key gnus-group-help-map "f" 'gnus-group-fetch-faq)
  3208.  
  3209.   (define-prefix-command 'gnus-group-sub-map)
  3210.   (define-key gnus-group-mode-map "S" 'gnus-group-sub-map)
  3211.   (define-key gnus-group-sub-map "l" 'gnus-group-set-current-level)
  3212.   (define-key gnus-group-sub-map "t" 'gnus-group-unsubscribe-current-group)
  3213.   (define-key gnus-group-sub-map "s" 'gnus-group-unsubscribe-group)
  3214.   (define-key gnus-group-sub-map "k" 'gnus-group-kill-group)
  3215.   (define-key gnus-group-sub-map "y" 'gnus-group-yank-group)
  3216.   (define-key gnus-group-sub-map "w" 'gnus-group-kill-region)
  3217.   (define-key gnus-group-sub-map "z" 'gnus-group-kill-all-zombies))
  3218.  
  3219. (defun gnus-group-mode ()
  3220.   "Major mode for reading news.
  3221.  
  3222. All normal editing commands are switched off.
  3223. \\<gnus-group-mode-map>
  3224. The group buffer lists (some of) the groups available.  For instance,
  3225. `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
  3226. lists all zombie groups. 
  3227.  
  3228. Groups that are displayed can be entered with `\\[gnus-group-read-group]'.  To subscribe 
  3229. to a group not displayed, type `\\[gnus-group-unsubscribe-group]'. 
  3230.  
  3231. For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]'). 
  3232.  
  3233. The following commands are available:
  3234.  
  3235. \\{gnus-group-mode-map}"
  3236.   (interactive)
  3237.   (if gnus-visual (gnus-group-make-menu-bar))
  3238.   (kill-all-local-variables)
  3239.   (gnus-simplify-mode-line)
  3240.   (setq major-mode 'gnus-group-mode)
  3241.   (setq mode-name "Group")
  3242.   (gnus-group-set-mode-line)
  3243.   (setq mode-line-process nil)
  3244.   (use-local-map gnus-group-mode-map)
  3245.   (buffer-disable-undo (current-buffer))
  3246.   (setq truncate-lines t)
  3247.   (setq buffer-read-only t)
  3248.   (run-hooks 'gnus-group-mode-hook))
  3249.  
  3250. (defun gnus-mouse-pick-group (e)
  3251.   (interactive "e")
  3252.   (mouse-set-point e)
  3253.   (gnus-group-read-group nil))
  3254.  
  3255. ;; Look at LEVEL and find out what the level is really supposed to be.
  3256. ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
  3257. ;; will depend on whether `gnus-group-use-permanent-levels' is used.
  3258. (defun gnus-group-default-level (&optional level number-or-nil)
  3259.   (cond  
  3260.    (gnus-group-use-permanent-levels
  3261.     (setq gnus-group-default-list-level 
  3262.       (or level gnus-group-default-list-level))
  3263.     (or gnus-group-default-list-level gnus-level-subscribed))
  3264.    (number-or-nil
  3265.     level)
  3266.    (t
  3267.     (or level gnus-group-default-list-level gnus-level-subscribed))))
  3268.   
  3269.  
  3270. (defvar gnus-tmp-prev-perm nil)
  3271.  
  3272. ;;;###autoload
  3273. (defun gnus-no-server (&optional arg)
  3274.   "Read network news.
  3275. If ARG is a positive number, Gnus will use that as the
  3276. startup level. If ARG is nil, Gnus will be started at level 2. 
  3277. If ARG is non-nil and not a positive number, Gnus will
  3278. prompt the user for the name of an NNTP server to use.
  3279. As opposed to `gnus', this command will not connect to the local server."
  3280.   (interactive "P")
  3281.   (let ((perm
  3282.      (cons gnus-group-use-permanent-levels gnus-group-default-list-level)))
  3283.     (setq gnus-tmp-prev-perm nil)
  3284.     (setq gnus-group-use-permanent-levels t)
  3285.     (gnus (or arg (1- gnus-level-default-subscribed)) t)
  3286.     (setq gnus-tmp-prev-perm perm)))
  3287.  
  3288. ;;;###autoload
  3289. (defun read-news (&optional arg dont-connect)
  3290.   "Read network news.  This is an alias for the `gnus' command."
  3291.   (gnus arg dont-connect))
  3292.  
  3293. ;;;###autoload
  3294. (defun gnus (&optional arg dont-connect)
  3295.   "Read network news.
  3296. If ARG is non-nil and a positive number, Gnus will use that as the
  3297. startup level. If ARG is non-nil and not a positive number, Gnus will
  3298. prompt the user for the name of an NNTP server to use."
  3299.   (interactive "P")
  3300.   (if (get-buffer gnus-group-buffer)
  3301.       (progn
  3302.     (switch-to-buffer gnus-group-buffer)
  3303.     (gnus-group-get-new-news))
  3304.  
  3305.     (gnus-clear-system)
  3306.  
  3307.     (nnheader-init-server-buffer)
  3308.     ;; We do this if `gnus-no-server' has been run.
  3309.     (if gnus-tmp-prev-perm 
  3310.     (setq gnus-group-use-permanent-levels (car gnus-tmp-prev-perm)
  3311.           gnus-group-default-list-level (cdr gnus-tmp-prev-perm)
  3312.           gnus-tmp-prev-perm nil))
  3313.     (gnus-read-init-file)
  3314.  
  3315.     (gnus-group-setup-buffer)
  3316.     (let ((buffer-read-only nil))
  3317.       (erase-buffer)
  3318.       (if (not gnus-inhibit-startup-message)
  3319.       (progn
  3320.         (gnus-group-startup-message)
  3321.         (sit-for 0))))
  3322.     
  3323.     (let ((level (and arg (numberp arg) (> arg 0) arg))
  3324.       did-connect)
  3325.       (unwind-protect
  3326.       (progn
  3327.         (or dont-connect 
  3328.         (setq did-connect
  3329.               (gnus-start-news-server (and arg (not level))))))
  3330.     (if (and (not dont-connect) 
  3331.          (not did-connect))
  3332.         (gnus-group-quit)
  3333.       (run-hooks 'gnus-startup-hook)
  3334.       ;; NNTP server is successfully open. 
  3335.  
  3336.       ;; Find the current startup file name.
  3337.       (setq gnus-current-startup-file 
  3338.         (gnus-make-newsrc-file gnus-startup-file))
  3339.  
  3340.       ;; Read the dribble file.
  3341.       (and gnus-use-dribble-file (gnus-dribble-read-file))
  3342.  
  3343.       (gnus-summary-make-display-table)
  3344.       (gnus-setup-news nil level)
  3345.       (gnus-group-list-groups level)
  3346.       (gnus-configure-windows 'group))))))
  3347.  
  3348. (defun gnus-unload ()
  3349.   "Unload all Gnus features."
  3350.   (interactive)
  3351.   (or (boundp 'load-history)
  3352.       (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
  3353.   (let ((history load-history)
  3354.     feature)
  3355.     (while history
  3356.       (and (string-match "^gnus" (car (car history)))
  3357.        (setq feature (cdr (assq 'provide (car history))))
  3358.        (unload-feature feature 'force))
  3359.       (setq history (cdr history)))))
  3360.  
  3361. (defun gnus-group-startup-message (&optional x y)
  3362.   "Insert startup message in current buffer."
  3363.   ;; Insert the message.
  3364.   (erase-buffer)
  3365.   (insert
  3366.    (format "
  3367.           _    ___ _             _      
  3368.           _ ___ __ ___  __    _ ___     
  3369.           __   _     ___    __  ___     
  3370.               _           ___     _     
  3371.              _  _ __             _      
  3372.              ___   __            _      
  3373.                    __           _       
  3374.                     _      _   _        
  3375.                    _      _    _        
  3376.                       _  _    _         
  3377.                   __  ___               
  3378.                  _   _ _     _          
  3379.                 _   _                   
  3380.               _    _                    
  3381.              _    _                     
  3382.             _                         
  3383.           __                             
  3384.  
  3385.  
  3386.       Gnus * A newsreader for Emacsen
  3387.     A Praxis release * larsi@ifi.uio.no
  3388.        gnus-version))
  3389.   ;; And then hack it.
  3390.   ;; 18 is the longest line.
  3391.   (indent-rigidly (point-min) (point-max) 
  3392.           (/ (max (- (window-width) (or x 46)) 0) 2))
  3393.   (goto-char (point-min))
  3394.   (let* ((pheight (count-lines (point-min) (point-max)))
  3395.      (wheight (window-height))
  3396.      (rest (- wheight  pheight)))
  3397.     (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
  3398.     
  3399.     
  3400.  
  3401.   ;; Fontify some.
  3402.   (goto-char (point-min))
  3403.   (search-forward "Praxis")
  3404.   (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
  3405.   (goto-char (point-min)))
  3406.  
  3407. (defun gnus-group-startup-message-old (&optional x y)
  3408.   "Insert startup message in current buffer."
  3409.   ;; Insert the message.
  3410.   (erase-buffer)
  3411.   (insert
  3412.    (format "
  3413.      %s
  3414.            A newsreader 
  3415.       for GNU Emacs
  3416.  
  3417.         Based on GNUS 
  3418.              written by 
  3419.      Masanobu UMEDA
  3420.  
  3421.        A Praxis Release
  3422.       larsi@ifi.uio.no
  3423.        gnus-version))
  3424.   ;; And then hack it.
  3425.   ;; 18 is the longest line.
  3426.   (indent-rigidly (point-min) (point-max) 
  3427.           (/ (max (- (window-width) (or x 28)) 0) 2))
  3428.   (goto-char (point-min))
  3429.   ;; +4 is fuzzy factor.
  3430.   (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2))
  3431.  
  3432.   ;; Fontify some.
  3433.   (goto-char (point-min))
  3434.   (search-forward "Praxis")
  3435.   (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
  3436.   (goto-char (point-min)))
  3437.  
  3438. (defun gnus-group-setup-buffer ()
  3439.   (or (get-buffer gnus-group-buffer)
  3440.       (progn
  3441.     (switch-to-buffer gnus-group-buffer)
  3442.     (gnus-add-current-to-buffer-list)
  3443.     (gnus-group-mode)
  3444.     (and gnus-carpal (gnus-carpal-setup-buffer 'group)))))
  3445.  
  3446. (defun gnus-group-list-groups (&optional level unread)
  3447.   "List newsgroups with level LEVEL or lower that have unread articles.
  3448. Default is all subscribed groups.
  3449. If argument UNREAD is non-nil, groups with no unread articles are also
  3450. listed." 
  3451.   (interactive (list (if current-prefix-arg
  3452.              (prefix-numeric-value current-prefix-arg)
  3453.                (or
  3454.             (gnus-group-default-level nil t)
  3455.             gnus-group-default-list-level
  3456.             gnus-level-subscribed))))
  3457.   (or level
  3458.       (setq level (car gnus-group-list-mode)
  3459.         unread (cdr gnus-group-list-mode)))
  3460.   (setq level (gnus-group-default-level level))
  3461.   (gnus-group-setup-buffer)        ;May call from out of group buffer
  3462.   (let ((case-fold-search nil)
  3463.     (group (gnus-group-group-name)))
  3464.     (funcall gnus-group-prepare-function level unread nil)
  3465.     (if (zerop (buffer-size))
  3466.     (gnus-message 5 gnus-no-groups-message)
  3467.       (goto-char (point-min))
  3468.       (if (not group)
  3469.       ;; Go to the first group with unread articles.
  3470.       (gnus-group-search-forward nil nil nil t)
  3471.     ;; Find the right group to put point on. If the current group
  3472.     ;; has disappeared in the new listing, try to find the next
  3473.     ;; one. If no next one can be found, just leave point at the
  3474.     ;; first newsgroup in the buffer.
  3475.     (if (not (gnus-goto-char
  3476.           (text-property-any (point-min) (point-max) 
  3477.                      'gnus-group (intern group))))
  3478.         (let ((newsrc (nthcdr 3 (gnus-gethash group gnus-newsrc-hashtb))))
  3479.           (while (and newsrc
  3480.               (not (gnus-goto-char 
  3481.                 (text-property-any 
  3482.                  (point-min) (point-max) 'gnus-group 
  3483.                  (intern (car (car newsrc)))))))
  3484.         (setq newsrc (cdr newsrc)))
  3485.           (or newsrc (progn (goto-char (point-max))
  3486.                 (forward-line -1))))))
  3487.       ;; Adjust cursor point.
  3488.       (gnus-group-position-cursor))))
  3489.  
  3490. (defun gnus-group-prepare-flat (level &optional all lowest regexp) 
  3491.   "List all newsgroups with unread articles of level LEVEL or lower.
  3492. If ALL is non-nil, list groups that have no unread articles.
  3493. If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
  3494. If REGEXP, only list groups matching REGEXP."
  3495.   (set-buffer gnus-group-buffer)
  3496.   (let ((buffer-read-only nil)
  3497.     (newsrc (cdr gnus-newsrc-alist))
  3498.     (lowest (or lowest 1))
  3499.     info clevel unread group)
  3500.     (erase-buffer)
  3501.     (if (< lowest gnus-level-zombie)
  3502.     ;; List living groups.
  3503.     (while newsrc
  3504.       (setq info (car newsrc)
  3505.         group (car info)
  3506.         newsrc (cdr newsrc)
  3507.         unread (car (gnus-gethash group gnus-newsrc-hashtb)))
  3508.       (and unread            ; This group might be bogus
  3509.            (or (not regexp)
  3510.            (string-match regexp group))
  3511.            (<= (setq clevel (car (cdr info))) level) 
  3512.            (>= clevel lowest)
  3513.            (or all            ; We list all groups?
  3514.            (eq unread t)    ; We list unactivated groups
  3515.            (> unread 0)        ; We list groups with unread articles
  3516.            (cdr (assq 'tick (nth 3 info)))) ; And ticked groups
  3517.            (gnus-group-insert-group-line 
  3518.         nil group (car (cdr info)) (nth 3 info) unread (nth 4 info)))))
  3519.  
  3520.     ;; List dead groups.
  3521.     (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
  3522.      (gnus-group-prepare-flat-list-dead 
  3523.       (setq gnus-zombie-list (sort gnus-zombie-list 'string<)) 
  3524.       gnus-level-zombie ?Z
  3525.       regexp))
  3526.     (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
  3527.      (gnus-group-prepare-flat-list-dead 
  3528.       (setq gnus-killed-list (sort gnus-killed-list 'string<)) 
  3529.       gnus-level-killed ?K regexp))
  3530.  
  3531.     (gnus-group-set-mode-line)
  3532.     (setq gnus-group-list-mode (cons level all))
  3533.     (run-hooks 'gnus-group-prepare-hook)))
  3534.  
  3535. (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
  3536.   ;; List zombies and killed lists somewhat faster, which was
  3537.   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
  3538.   ;; this by ignoring the group format specification altogether.
  3539.   (let (group beg)
  3540.     (while groups
  3541.       (setq group (car groups)
  3542.         groups (cdr groups))
  3543.       (if (or (not regexp)
  3544.           (string-match regexp group))
  3545.       (progn
  3546.         (setq beg (point))
  3547.         (insert (format " %c     *: %s\n" mark group))
  3548.         (add-text-properties 
  3549.          beg (1+ beg) 
  3550.          (list 'gnus-group (intern group)
  3551.            'gnus-unread t
  3552.            'gnus-level level)))))))
  3553.  
  3554. (defun gnus-group-real-name (group)
  3555.   "Find the real name of a foreign newsgroup."
  3556.   (if (string-match ":[^:]+$" group)
  3557.       (substring group (1+ (match-beginning 0)))
  3558.     group))
  3559.  
  3560. (defun gnus-group-prefixed-name (group method)
  3561.   "Return the whole name from GROUP and METHOD."
  3562.   (and (stringp method) (setq method (gnus-server-to-method method)))
  3563.   (concat (format "%s" (car method))
  3564.       (if (and 
  3565.            (assoc (format "%s" (car method)) (gnus-methods-using 'address))
  3566.            (not (string= (nth 1 method) "")))
  3567.           (concat "+" (nth 1 method)))
  3568.       ":" group))
  3569.  
  3570. (defun gnus-group-real-prefix (group)
  3571.   "Return the prefix of the current group name."
  3572.   (if (string-match "^[^:]+:" group)
  3573.       (substring group 0 (match-end 0))
  3574.     ""))
  3575.  
  3576. (defun gnus-group-method-name (group)
  3577.   "Return the method used for selecting GROUP."
  3578.   (let ((prefix (gnus-group-real-prefix group)))
  3579.     (if (equal prefix "")
  3580.     gnus-select-method
  3581.       (if (string-match "^[^\\+]+\\+" prefix)
  3582.       (list (intern (substring prefix 0 (1- (match-end 0))))
  3583.         (substring prefix (match-end 0) (1- (length prefix))))
  3584.     (list (intern (substring prefix 0 (1- (length prefix)))) "")))))
  3585.  
  3586. (defun gnus-group-foreign-p (group)
  3587.   "Return nil if GROUP is native, non-nil if it is foreign."
  3588.   (string-match ":" group))
  3589.  
  3590. (defun gnus-group-set-info (info &optional method-only-group part)
  3591.   (let* ((entry (gnus-gethash
  3592.          (or method-only-group (car info)) gnus-newsrc-hashtb))
  3593.      (part-info info)
  3594.      (info (if method-only-group (nth 2 entry) info)))
  3595.     (if (not method-only-group)
  3596.     ()
  3597.       (or entry
  3598.       (error "Trying to change non-existent group %s" method-only-group))
  3599.       ;; We have received parts of the actual group info - either the
  3600.       ;; select method or the group parameters.  We first check
  3601.       ;; whether we have to extend the info, and if so, do that.
  3602.       (let ((len (length info))
  3603.         (total (if (eq part 'method) 5 6)))
  3604.     (and (< len total)
  3605.          (setcdr (nthcdr (1- len) info)
  3606.              (make-list (- total len) nil)))
  3607.     ;; Then we enter the new info.
  3608.     (setcar (nthcdr (1- total) info) part-info)))
  3609.     ;; We uncompress some lists of marked articles.
  3610.     (let (marked)
  3611.       (if (not (setq marked (nth 3 info)))
  3612.       ()
  3613.     (while marked
  3614.       (or (eq 'score (car (car marked)))
  3615.           (eq 'bookmark (car (car marked)))
  3616.           (eq 'killed (car (car marked)))
  3617.           (setcdr (car marked) 
  3618.               (gnus-uncompress-range (cdr (car marked)))))
  3619.       (setq marked (cdr marked)))))
  3620.     (if entry
  3621.     ()
  3622.       ;; This is a new group, so we just create it.
  3623.       (save-excursion
  3624.     (set-buffer gnus-group-buffer)
  3625.     (if (nth 4 info)
  3626.         ;; It's a foreign group...
  3627.         (gnus-group-make-group 
  3628.          (gnus-group-real-name (car info))
  3629.          (prin1-to-string (car (nth 4 info)))
  3630.          (nth 1 (nth 4 info)))
  3631.       ;; It's a native group.
  3632.       (gnus-group-make-group (car info)))
  3633.     (gnus-message 6 "Note: New group created")
  3634.     (setq entry 
  3635.           (gnus-gethash (gnus-group-prefixed-name 
  3636.                  (gnus-group-real-name (car info))
  3637.                  (or (nth 4 info) gnus-select-method))
  3638.                 gnus-newsrc-hashtb))))
  3639.     ;; Whether it was a new group or not, we now have the entry, so we
  3640.     ;; can do the update.
  3641.     (if entry
  3642.     (progn
  3643.       (setcar (nthcdr 2 entry) info)
  3644.       (if (and (not (eq (car entry) t)) 
  3645.            (gnus-gethash (car info) gnus-active-hashtb))
  3646.           (let ((marked (nth 3 info)))
  3647.         (setcar entry 
  3648.             (max 0 (- (length (gnus-list-of-unread-articles 
  3649.                        (car info)))
  3650.                   (length (cdr (assq 'tick marked)))
  3651.                   (length (cdr (assq 'dormant marked)))))))))
  3652.       (error "No such group: %s" (car info)))))
  3653.  
  3654. (defun gnus-group-set-method-info (group select-method)
  3655.   (gnus-group-set-info select-method group 'method))
  3656.  
  3657. (defun gnus-group-set-params-info (group params)
  3658.   (gnus-group-set-info params group 'params))
  3659.  
  3660. (defun gnus-group-update-group-line ()
  3661.   "This function updates the current line in the newsgroup buffer and
  3662. moves the point to the colon."
  3663.   (let* ((buffer-read-only nil)
  3664.      (group (gnus-group-group-name))
  3665.      (entry (and group (gnus-gethash group gnus-newsrc-hashtb))))
  3666.     (if (and entry (not (gnus-ephemeral-group-p group)))
  3667.     (gnus-dribble-enter 
  3668.      (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
  3669.          ")")))
  3670.     (beginning-of-line)
  3671.     (delete-region (point) (progn (forward-line 1) (point)))
  3672.     (gnus-group-insert-group-line-info group)
  3673.     (forward-line -1)
  3674.     (gnus-group-position-cursor)))
  3675.  
  3676. (defun gnus-group-insert-group-line-info (group)
  3677.   (let ((entry (gnus-gethash group gnus-newsrc-hashtb)) 
  3678.     active info)
  3679.     (if entry
  3680.     (progn
  3681.       (setq info (nth 2 entry))
  3682.       (gnus-group-insert-group-line 
  3683.        nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
  3684.       (setq active (gnus-gethash group gnus-active-hashtb))
  3685.       (gnus-group-insert-group-line 
  3686.        nil group 
  3687.        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
  3688.        nil (if active (- (1+ (cdr active)) (car active)) 0) nil))))
  3689.  
  3690. (defun gnus-group-insert-group-line (gformat group level marked number method)
  3691.   (let* ((gformat (or gformat gnus-group-line-format-spec))
  3692.      (active (gnus-gethash group gnus-active-hashtb))
  3693.      (number-total (if active (1+ (- (cdr active) (car active))) 0))
  3694.      (number-of-dormant (length (cdr (assq 'dormant marked))))
  3695.      (number-of-ticked (length (cdr (assq 'tick marked))))
  3696.      (number-of-ticked-and-dormant
  3697.       (+ number-of-ticked number-of-dormant))
  3698.      (number-of-unread-unticked 
  3699.       (if (numberp number) (int-to-string (max 0 number))
  3700.         "*"))
  3701.      (number-of-read
  3702.       (if (numberp number)
  3703.           (max 0 (- number-total number))
  3704.         "*"))
  3705.      (subscribed (cond ((<= level gnus-level-subscribed) ? )
  3706.                ((<= level gnus-level-unsubscribed) ?U)
  3707.                ((= level gnus-level-zombie) ?Z)
  3708.                (t ?K)))
  3709.      (qualified-group (gnus-group-real-name group))
  3710.      (newsgroup-description 
  3711.       (if gnus-description-hashtb
  3712.           (or (gnus-gethash group gnus-description-hashtb) "")
  3713.         ""))
  3714.      (moderated (if (member group gnus-moderated-list) ?m ? ))
  3715.      (moderated-string (if (eq moderated ?m) "(m)" ""))
  3716.      (method (gnus-server-get-method group method))
  3717.      (news-server (or (car (cdr method)) ""))
  3718.      (news-method (or (car method) ""))
  3719.      (news-method-string 
  3720.       (if method (format "(%s:%s)" (car method) (car (cdr method))) ""))
  3721.      (marked (if (and 
  3722.               (numberp number) 
  3723.               (zerop number)
  3724.               (> number-of-ticked 0))
  3725.              ?* ? ))
  3726.      (number (if (eq number t) "*" (+ number number-of-dormant 
  3727.                       number-of-ticked)))
  3728.      (process-marked (if (member group gnus-group-marked)
  3729.                  gnus-process-mark ? ))
  3730.      (buffer-read-only nil)
  3731.      header                ; passed as parameter to user-funcs.
  3732.      b)
  3733.     (beginning-of-line)
  3734.     (setq b (point))
  3735.     ;; Insert the text.
  3736.     (insert (eval gformat))
  3737.  
  3738.     (add-text-properties 
  3739.      b (1+ b) (list 'gnus-group (intern group)
  3740.             'gnus-unread (if (numberp number)
  3741.                      (string-to-int number-of-unread-unticked)
  3742.                    t)
  3743.             'gnus-marked marked
  3744.             'gnus-level level))))
  3745.  
  3746. (defun gnus-group-update-group (group &optional visible-only)
  3747.   "Update newsgroup info of GROUP.
  3748. If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't already."
  3749.   (save-excursion
  3750.     (set-buffer gnus-group-buffer)
  3751.     (let ((buffer-read-only nil)
  3752.       visible)
  3753.       (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
  3754.     (if (and entry
  3755.          (not (gnus-ephemeral-group-p group)))
  3756.         (gnus-dribble-enter 
  3757.          (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
  3758.              ")"))))
  3759.       ;; Buffer may be narrowed.
  3760.       (save-restriction
  3761.     (widen)
  3762.     ;; Search a line to modify.  If the buffer is large, the search
  3763.     ;; takes long time.  In most cases, current point is on the line
  3764.     ;; we are looking for.  So, first of all, check current line. 
  3765.     (if (or (progn
  3766.           (beginning-of-line)
  3767.           (eq (get-text-property (point) 'gnus-group)
  3768.               (intern group)))
  3769.         (progn
  3770.           (gnus-goto-char 
  3771.            (text-property-any 
  3772.             (point-min) (point-max) 'gnus-group (intern group)))))
  3773.         ;; GROUP is listed in current buffer. So, delete old line.
  3774.         (progn
  3775.           (setq visible t)
  3776.           (beginning-of-line)
  3777.           (delete-region (point) (progn (forward-line 1) (point))))
  3778.       ;; No such line in the buffer, find out where it's supposed to
  3779.       ;; go, and insert it there (or at the end of the buffer).
  3780.       ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
  3781.       (or visible-only
  3782.           (let ((entry 
  3783.              (cdr (cdr (gnus-gethash group gnus-newsrc-hashtb)))))
  3784.         (while (and entry
  3785.                 (car entry)
  3786.                 (not
  3787.                  (gnus-goto-char
  3788.                   (text-property-any
  3789.                    (point-min) (point-max) 
  3790.                    'gnus-group (intern (car (car entry)))))))
  3791.           (setq entry (cdr entry)))
  3792.         (or entry (goto-char (point-max)))))))
  3793.       (if (or visible (not visible-only))
  3794.       (gnus-group-insert-group-line-info group))
  3795.       (gnus-group-set-mode-line))))
  3796.  
  3797. (defun gnus-group-set-mode-line ()
  3798.   (if (memq 'group gnus-updated-mode-lines)
  3799.       (let* ((gformat (or gnus-group-mode-line-format-spec
  3800.               (setq gnus-group-mode-line-format-spec
  3801.                 (gnus-parse-format 
  3802.                  gnus-group-mode-line-format 
  3803.                  gnus-group-mode-line-format-alist))))
  3804.          (news-server (car (cdr gnus-select-method)))
  3805.          (news-method (car gnus-select-method))
  3806.          (max-len 60)
  3807.          header            ;Dummy binding for user-defined specs.
  3808.          (mode-string (eval gformat)))
  3809.     (setq mode-string (eval gformat))
  3810.     (if (> (length mode-string) max-len) 
  3811.         (setq mode-string (substring mode-string 0 (- max-len 4))))
  3812.     (setq mode-line-buffer-identification mode-string)
  3813.     (set-buffer-modified-p t))))
  3814.  
  3815. (defun gnus-group-group-name ()
  3816.   "Get the name of the newsgroup on the current line."
  3817.   (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
  3818.     (and group (symbol-name group))))
  3819.  
  3820. (defun gnus-group-group-level ()
  3821.   "Get the level of the newsgroup on the current line."
  3822.   (get-text-property (gnus-point-at-bol) 'gnus-level))
  3823.  
  3824. (defun gnus-group-group-unread ()
  3825.   "Get the number of unread articles of the newsgroup on the current line."
  3826.   (get-text-property (gnus-point-at-bol) 'gnus-unread))
  3827.  
  3828. (defun gnus-group-search-forward (&optional backward all level first-too)
  3829.   "Find the next newsgroup with unread articles.
  3830. If BACKWARD is non-nil, find the previous newsgroup instead.
  3831. If ALL is non-nil, just find any newsgroup.
  3832. If LEVEL is non-nil, find group with level LEVEL, or higher if no such
  3833. group exists.
  3834. If FIRST-TOO, the current line is also eligible as a target."
  3835.   (let ((way (if backward -1 1))
  3836.     (low gnus-level-killed)
  3837.     (beg (point))
  3838.     pos found lev)
  3839.     (if (and backward (progn (beginning-of-line)) (bobp))
  3840.     nil
  3841.       (or first-too (forward-line way))
  3842.       (while (and 
  3843.           (not (eobp))
  3844.           (not (setq 
  3845.             found 
  3846.             (and (or all
  3847.                  (and
  3848.                   (let ((unread 
  3849.                      (get-text-property (point) 'gnus-unread)))
  3850.                 (or (eq unread t) (and unread (> unread 0))))
  3851.                   (setq lev (get-text-property (point)
  3852.                                'gnus-level))
  3853.                   (<= lev gnus-level-subscribed)))
  3854.              (or (not level)
  3855.                  (and (setq lev (get-text-property (point)
  3856.                                    'gnus-level))
  3857.                   (or (= lev level)
  3858.                       (and (< lev low)
  3859.                        (< level lev)
  3860.                        (progn
  3861.                          (setq low lev)
  3862.                          (setq pos (point))
  3863.                          nil))))))))
  3864.           (zerop (forward-line way)))))
  3865.     (if found 
  3866.     (progn (gnus-group-position-cursor) t)
  3867.       (goto-char (or pos beg))
  3868.       (and pos t))))
  3869.  
  3870. ;;; Gnus group mode commands
  3871.  
  3872. ;; Group marking.
  3873.  
  3874. (defun gnus-group-mark-group (n &optional unmark no-advance)
  3875.   "Mark the current group."
  3876.   (interactive "p")
  3877.   (let ((buffer-read-only nil)
  3878.     group)
  3879.     (while 
  3880.     (and (> n 0) 
  3881.          (setq group (gnus-group-group-name))
  3882.          (progn
  3883.            (beginning-of-line)
  3884.            (forward-char 
  3885.         (or (cdr (assq 'process gnus-group-mark-positions)) 2))
  3886.            (delete-char 1)
  3887.            (if unmark
  3888.            (progn
  3889.              (insert " ")
  3890.              (setq gnus-group-marked (delete group gnus-group-marked)))
  3891.          (insert "#")
  3892.          (setq gnus-group-marked
  3893.                (cons group (delete group gnus-group-marked))))
  3894.            t)
  3895.          (or no-advance (zerop (gnus-group-next-group 1))))
  3896.       (setq n (1- n)))
  3897.     (gnus-summary-position-cursor)
  3898.     n))
  3899.  
  3900. (defun gnus-group-unmark-group (n)
  3901.   "Remove the mark from the current group."
  3902.   (interactive "p")
  3903.   (gnus-group-mark-group n 'unmark))
  3904.  
  3905. (defun gnus-group-mark-region (unmark beg end)
  3906.   "Mark all groups between point and mark.
  3907. If UNMARK, remove the mark instead."
  3908.   (interactive "P\nr")
  3909.   (let ((num (count-lines beg end)))
  3910.     (save-excursion
  3911.       (goto-char beg)
  3912.       (- num (gnus-group-mark-group num unmark)))))
  3913.  
  3914. (defun gnus-group-remove-mark (group)
  3915.   (and (gnus-group-goto-group group)
  3916.        (save-excursion
  3917.      (gnus-group-mark-group 1 'unmark t))))
  3918.  
  3919. ;; Return a list of groups to work on.  Take into consideration N (the
  3920. ;; prefix) and the list of marked groups.
  3921. (defun gnus-group-process-prefix (n)
  3922.   (cond (n
  3923.      (setq n (prefix-numeric-value n))
  3924.      ;; There is a prefix, so we return a list of the N next
  3925.      ;; groups. 
  3926.      (let ((way (if (< n 0) -1 1))
  3927.            (n (abs n))
  3928.            group groups)
  3929.        (save-excursion
  3930.          (while (and (> n 0)
  3931.              (setq group (gnus-group-group-name)))
  3932.            (setq groups (cons group groups))
  3933.            (setq n (1- n))
  3934.            (forward-line way)))
  3935.        (nreverse groups)))
  3936.     (gnus-group-marked
  3937.      ;; No prefix, but a list of marked articles.
  3938.      (reverse gnus-group-marked))
  3939.     (t
  3940.      ;; Neither marked articles or a prefix, so we return the
  3941.      ;; current group.
  3942.      (let ((group (gnus-group-group-name)))
  3943.        (and group (list group))))))
  3944.  
  3945. ;; Selecting groups.
  3946.  
  3947. (defun gnus-group-read-group (&optional all no-article group)
  3948.   "Read news in this newsgroup.
  3949. If the prefix argument ALL is non-nil, already read articles become
  3950. readable. If the optional argument NO-ARTICLE is non-nil, no article
  3951. will be auto-selected upon group entry."
  3952.   (interactive "P")
  3953.   (let ((group (or group (gnus-group-group-name)))
  3954.     number active marked entry)
  3955.     (or group (error "No group on current line"))
  3956.     (setq marked 
  3957.       (nth 3 (nth 2 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))))
  3958.     ;; This group might be a dead group. In that case we have to get
  3959.     ;; the number of unread articles from `gnus-active-hashtb'.
  3960.     (if entry
  3961.     (setq number (car entry))
  3962.       (if (setq active (gnus-gethash group gnus-active-hashtb))
  3963.       (setq number (- (1+ (cdr active)) (car active)))))
  3964.     (gnus-summary-read-group 
  3965.      group (or all (and (numberp number) 
  3966.             (zerop (+ number (length (cdr (assq 'tick marked)))
  3967.                   (length (cdr (assq 'dormant marked)))))))
  3968.      no-article)))
  3969.  
  3970. (defun gnus-group-select-group (&optional all)
  3971.   "Select this newsgroup.
  3972. No article is selected automatically.
  3973. If argument ALL is non-nil, already read articles become readable."
  3974.   (interactive "P")
  3975.   (gnus-group-read-group all t))
  3976.  
  3977. (defun gnus-group-select-group-all ()
  3978.   "Select the current group and display all articles in it."
  3979.   (interactive)
  3980.   (gnus-group-select-group 'all))
  3981.  
  3982. ;; Enter a group that is not in the group buffer. Non-nil is returned
  3983. ;; if selection was successful.
  3984. (defun gnus-group-read-ephemeral-group 
  3985.   (group method &optional activate quit-config)
  3986.   (let ((group (if (gnus-group-foreign-p group) group
  3987.          (gnus-group-prefixed-name group method))))
  3988.     (gnus-sethash 
  3989.      group
  3990.      (list t nil (list group gnus-level-default-subscribed nil nil 
  3991.                (append method
  3992.                    (list
  3993.                 (list 'quit-config 
  3994.                       (if quit-config quit-config
  3995.                     (cons (current-buffer) 'summary)))))))
  3996.      gnus-newsrc-hashtb)
  3997.     (set-buffer gnus-group-buffer)
  3998.     (or (gnus-check-server method)
  3999.     (error "Unable to contact server: %s" (gnus-status-message method)))
  4000.     (if activate (or (gnus-request-group group)
  4001.              (error "Couldn't request group")))
  4002.     (condition-case ()
  4003.     (gnus-group-read-group t t group)
  4004.       (error nil)
  4005.       (quit nil))
  4006.     (not (equal major-mode 'gnus-group-mode))))
  4007.   
  4008. (defun gnus-group-jump-to-group (group)
  4009.   "Jump to newsgroup GROUP."
  4010.   (interactive 
  4011.    (list (completing-read 
  4012.       "Group: " gnus-active-hashtb nil 
  4013.       (memq gnus-select-method gnus-have-read-active-file))))
  4014.  
  4015.   (if (equal group "")
  4016.       (error "Empty group name"))
  4017.  
  4018.   (let ((b (text-property-any 
  4019.         (point-min) (point-max) 'gnus-group (intern group))))
  4020.     (if b
  4021.     ;; Either go to the line in the group buffer...
  4022.     (goto-char b)
  4023.       ;; ... or insert the line.
  4024.       (or
  4025.        (gnus-gethash group gnus-active-hashtb)
  4026.        (gnus-activate-group group)
  4027.        (error "%s error: %s" group (gnus-status-message group)))
  4028.  
  4029.       (gnus-group-update-group group)
  4030.       (goto-char (text-property-any 
  4031.           (point-min) (point-max) 'gnus-group (intern group)))))
  4032.   ;; Adjust cursor point.
  4033.   (gnus-group-position-cursor))
  4034.  
  4035. (defun gnus-group-goto-group (group)
  4036.   "Goto to newsgroup GROUP."
  4037.   (let ((b (text-property-any (point-min) (point-max) 
  4038.                   'gnus-group (intern group))))
  4039.     (and b (goto-char b))))
  4040.  
  4041. (defun gnus-group-next-group (n)
  4042.   "Go to next N'th newsgroup.
  4043. If N is negative, search backward instead.
  4044. Returns the difference between N and the number of skips actually
  4045. done."
  4046.   (interactive "p")
  4047.   (gnus-group-next-unread-group n t))
  4048.  
  4049. (defun gnus-group-next-unread-group (n &optional all level)
  4050.   "Go to next N'th unread newsgroup.
  4051. If N is negative, search backward instead.
  4052. If ALL is non-nil, choose any newsgroup, unread or not.
  4053. If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
  4054. such group can be found, the next group with a level higher than
  4055. LEVEL.
  4056. Returns the difference between N and the number of skips actually
  4057. made."
  4058.   (interactive "p")
  4059.   (let ((backward (< n 0))
  4060.     (n (abs n)))
  4061.     (while (and (> n 0)
  4062.         (gnus-group-search-forward 
  4063.          backward (or (not gnus-group-goto-unread) all) level))
  4064.       (setq n (1- n)))
  4065.     (if (/= 0 n) (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
  4066.                    (if level " on this level or higher" "")))
  4067.     n))
  4068.  
  4069. (defun gnus-group-prev-group (n)
  4070.   "Go to previous N'th newsgroup.
  4071. Returns the difference between N and the number of skips actually
  4072. done."
  4073.   (interactive "p")
  4074.   (gnus-group-next-unread-group (- n) t))
  4075.  
  4076. (defun gnus-group-prev-unread-group (n)
  4077.   "Go to previous N'th unread newsgroup.
  4078. Returns the difference between N and the number of skips actually
  4079. done."  
  4080.   (interactive "p")
  4081.   (gnus-group-next-unread-group (- n)))
  4082.  
  4083. (defun gnus-group-next-unread-group-same-level (n)
  4084.   "Go to next N'th unread newsgroup on the same level.
  4085. If N is negative, search backward instead.
  4086. Returns the difference between N and the number of skips actually
  4087. done."
  4088.   (interactive "p")
  4089.   (gnus-group-next-unread-group n t (gnus-group-group-level))
  4090.   (gnus-group-position-cursor))
  4091.  
  4092. (defun gnus-group-prev-unread-group-same-level (n)
  4093.   "Go to next N'th unread newsgroup on the same level.
  4094. Returns the difference between N and the number of skips actually
  4095. done."
  4096.   (interactive "p")
  4097.   (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
  4098.   (gnus-group-position-cursor))
  4099.  
  4100. (defun gnus-group-best-unread-group (&optional exclude-group)
  4101.   "Go to the group with the highest level.
  4102. If EXCLUDE-GROUP, do not go to that group."
  4103.   (interactive)
  4104.   (goto-char (point-min))
  4105.   (let ((best 100000)
  4106.     unread best-point)
  4107.     (while (setq unread (get-text-property (point) 'gnus-unread))
  4108.       (if (and (numberp unread) (> unread 0))
  4109.       (progn
  4110.         (if (and (< (get-text-property (point) 'gnus-level) best)
  4111.              (or (not exclude-group)
  4112.              (not (equal exclude-group (gnus-group-group-name)))))
  4113.         (progn 
  4114.           (setq best (get-text-property (point) 'gnus-level))
  4115.           (setq best-point (point))))))
  4116.       (forward-line 1))
  4117.     (if best-point (goto-char best-point))
  4118.     (gnus-summary-position-cursor)
  4119.     (and best-point (gnus-group-group-name))))
  4120.  
  4121. (defun gnus-group-first-unread-group ()
  4122.   "Go to the first group with unread articles."
  4123.   (interactive)
  4124.   (prog1
  4125.       (let ((opoint (point))
  4126.         unread)
  4127.     (goto-char (point-min))
  4128.     (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
  4129.         (not (zerop unread))    ; Has unread articles.
  4130.         (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
  4131.         (point)            ; Success.
  4132.       (goto-char opoint)
  4133.       nil))                ; Not success.
  4134.     (gnus-group-position-cursor)))
  4135.  
  4136. (defun gnus-group-enter-server-mode ()
  4137.   "Jump to the server buffer."
  4138.   (interactive)
  4139.   (gnus-server-setup-buffer)
  4140.   (gnus-configure-windows 'server)
  4141.   (gnus-server-prepare))
  4142.  
  4143. (defun gnus-group-make-group (name &optional method address)
  4144.   "Add a new newsgroup.
  4145. The user will be prompted for a NAME, for a select METHOD, and an
  4146. ADDRESS."
  4147.   (interactive
  4148.    (cons 
  4149.     (read-string "Group name: ")
  4150.     (let ((method
  4151.        (completing-read 
  4152.         "Method: " (append gnus-valid-select-methods gnus-server-alist)
  4153.         nil t)))
  4154.       (if (assoc method gnus-valid-select-methods)
  4155.       (list method
  4156.         (if (memq 'prompt-address
  4157.               (assoc method gnus-valid-select-methods))
  4158.             (read-string "Address: ")
  4159.           ""))
  4160.     (list method nil)))))
  4161.   
  4162.   (let* ((meth (and method (if address (list (intern method) address) method)))
  4163.      (nname (if method (gnus-group-prefixed-name name meth) name))
  4164.      info)
  4165.     (and (gnus-gethash nname gnus-newsrc-hashtb)
  4166.      (error "Group %s already exists" nname))
  4167.     (gnus-group-change-level 
  4168.      (setq info (list t nname gnus-level-default-subscribed nil nil meth))
  4169.      gnus-level-default-subscribed gnus-level-killed 
  4170.      (and (gnus-group-group-name)
  4171.       (gnus-gethash (gnus-group-group-name)
  4172.             gnus-newsrc-hashtb))
  4173.      t)
  4174.     (gnus-sethash nname (cons 1 0) gnus-active-hashtb)
  4175.     (or (gnus-ephemeral-group-p name)
  4176.     (gnus-dribble-enter 
  4177.      (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
  4178.     (gnus-group-insert-group-line-info nname)
  4179.  
  4180.     (if (assoc method gnus-valid-select-methods)
  4181.     (require (intern method)))
  4182.     (and (gnus-check-backend-function 'request-create-group nname)
  4183.      (gnus-request-create-group nname))))
  4184.  
  4185. (defun gnus-group-edit-group (group &optional part)
  4186.   "Edit the group on the current line."
  4187.   (interactive (list (gnus-group-group-name)))
  4188.   (let ((done-func '(lambda () 
  4189.               "Exit editing mode and update the information."
  4190.               (interactive)
  4191.               (gnus-group-edit-group-done 'part 'group)))
  4192.     (part (or part 'info))
  4193.     (winconf (current-window-configuration))
  4194.     info)
  4195.     (or group (error "No group on current line"))
  4196.     (or (setq info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
  4197.     (error "Killed group; can't be edited"))
  4198.     (set-buffer (get-buffer-create gnus-group-edit-buffer))
  4199.     (gnus-configure-windows 'edit-group)
  4200.     (gnus-add-current-to-buffer-list)
  4201.     (emacs-lisp-mode)
  4202.     ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
  4203.     (use-local-map (copy-keymap emacs-lisp-mode-map))
  4204.     (local-set-key "\C-c\C-c" done-func)
  4205.     (make-local-variable 'gnus-prev-winconf)
  4206.     (setq gnus-prev-winconf winconf)
  4207.     ;; We modify the func to let it know what part it is editing.
  4208.     (setcar (cdr (nth 4 done-func)) (list 'quote part))
  4209.     (setcar (cdr (cdr (nth 4 done-func))) group)
  4210.     (erase-buffer)
  4211.     (insert
  4212.      (cond 
  4213.       ((eq part 'method)
  4214.        ";; Type `C-c C-c' after editing the select method.\n\n")
  4215.       ((eq part 'params)
  4216.        ";; Type `C-c C-c' after editing the group parameters.\n\n")
  4217.       ((eq part 'info)
  4218.        ";; Type `C-c C-c' after editing the group info.\n\n")))
  4219.     (let ((cinfo (gnus-copy-sequence info))
  4220.       marked)
  4221.       (if (not (setq marked (nth 3 cinfo)))
  4222.       ()
  4223.     (while marked
  4224.       (or (eq 'score (car (car marked)))
  4225.           (eq 'bookmark (car (car marked)))
  4226.           (eq 'killed (car (car marked)))
  4227.           (not (numberp (car (cdr (car marked)))))
  4228.           (setcdr (car marked) 
  4229.               (gnus-compress-sequence (sort (cdr (car marked)) '<) t)))
  4230.       (setq marked (cdr marked))))
  4231.       (insert 
  4232.        (pp-to-string
  4233.     (cond ((eq part 'method)
  4234.            (or (nth 4 info) "native"))
  4235.           ((eq part 'params)
  4236.            (nth 5 info))
  4237.           (t
  4238.            cinfo)))
  4239.        "\n"))))
  4240.  
  4241. (defun gnus-group-edit-group-method (group)
  4242.   "Edit the select method of GROUP."
  4243.   (interactive (list (gnus-group-group-name)))
  4244.   (gnus-group-edit-group group 'method))
  4245.  
  4246. (defun gnus-group-edit-group-parameters (group)
  4247.   "Edit the group parameters of GROUP."
  4248.   (interactive (list (gnus-group-group-name)))
  4249.   (gnus-group-edit-group group 'params))
  4250.  
  4251. (defun gnus-group-edit-group-done (part group)
  4252.   "Get info from buffer, update variables and jump to the group buffer."
  4253.   (set-buffer (get-buffer-create gnus-group-edit-buffer))
  4254.   (goto-char (point-min))
  4255.   (let ((form (read (current-buffer)))
  4256.     (winconf gnus-prev-winconf))
  4257.     (if (eq part 'info) 
  4258.     (gnus-group-set-info form)
  4259.       (gnus-group-set-info form group part))
  4260.     (kill-buffer (current-buffer))
  4261.     (and winconf (set-window-configuration winconf))
  4262.     (set-buffer gnus-group-buffer)
  4263.     (gnus-group-update-group (gnus-group-group-name))
  4264.     (gnus-group-position-cursor)))
  4265.  
  4266. (defun gnus-group-make-help-group ()
  4267.   "Create the Gnus documentation group."
  4268.   (interactive)
  4269.   (let ((path (if installation-directory
  4270.           (cons (concat installation-directory "etc/") load-path)
  4271.             (cons data-directory load-path)))
  4272.     (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
  4273.     file)
  4274.     (and (gnus-gethash name gnus-newsrc-hashtb)
  4275.      (error "Documentation group already exists"))
  4276.     (while (and path
  4277.         (not (file-exists-p 
  4278.               (setq file (concat (file-name-as-directory (car path))
  4279.                      "gnus-tut.txt")))))
  4280.       (setq path (cdr path)))
  4281.     (if (not path)
  4282.     (message "Couldn't find doc group")
  4283.       (gnus-group-make-group 
  4284.        (gnus-group-real-name name)
  4285.        (list 'nndoc name
  4286.          (list 'nndoc-address file)
  4287.          (list 'nndoc-article-type 'mbox)))))
  4288.   (gnus-group-position-cursor))
  4289.  
  4290. (defun gnus-group-make-doc-group (file type)
  4291.   "Create a group that uses a single file as the source."
  4292.   (interactive 
  4293.    (list (read-file-name "File name: ") 
  4294.      (let ((err "")
  4295.            found char)
  4296.        (while (not found)
  4297.          (message "%sFile type (mbox, babyl, digest) [mbd]: " err)
  4298.          (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
  4299.                    ((= char ?b) 'babyl)
  4300.                    ((= char ?d) 'digest)
  4301.                    (t (setq err (format "%c unknown. " char))
  4302.                   nil))))
  4303.        found)))
  4304.   (let* ((file (expand-file-name file))
  4305.      (name (gnus-generate-new-group-name
  4306.         (gnus-group-prefixed-name
  4307.          (file-name-nondirectory file) '(nndoc "")))))
  4308.     (gnus-group-make-group 
  4309.      (gnus-group-real-name name)
  4310.      (list 'nndoc name
  4311.        (list 'nndoc-address file)
  4312.        (list 'nndoc-article-type type)))))
  4313.  
  4314. (defun gnus-group-make-archive-group (&optional all)
  4315.   "Create the (ding) Gnus archive group of the most recent articles.
  4316. Given a prefix, create a full group."
  4317.   (interactive "P")
  4318.   (let ((group (gnus-group-prefixed-name 
  4319.         (if all "ding.archives" "ding.recent") '(nndir ""))))
  4320.     (and (gnus-gethash group gnus-newsrc-hashtb)
  4321.      (error "Archive group already exists"))
  4322.     (gnus-group-make-group
  4323.      (gnus-group-real-name group)
  4324.      "nndir" 
  4325.      (if all gnus-group-archive-directory 
  4326.        gnus-group-recent-archive-directory)))
  4327.   (gnus-group-position-cursor))
  4328.  
  4329. (defun gnus-group-make-directory-group (dir)
  4330.   "Create an nndir group.
  4331. The user will be prompted for a directory. The contents of this
  4332. directory will be used as a newsgroup. The directory should contain
  4333. mail messages or news articles in files that have numeric names."
  4334.   (interactive
  4335.    (list (read-file-name "Create group from directory: ")))
  4336.   (or (file-exists-p dir) (error "No such directory"))
  4337.   (or (file-directory-p dir) (error "Not a directory"))
  4338.   (gnus-group-make-group dir "nndir" dir)
  4339.   (gnus-group-position-cursor))
  4340.  
  4341. (defun gnus-group-make-kiboze-group (group address scores)
  4342.   "Create an nnkiboze group.
  4343. The user will be prompted for a name, a regexp to match groups, and
  4344. score file entries for articles to include in the group."
  4345.   (interactive
  4346.    (list
  4347.     (read-string "nnkiboze group name: ")
  4348.     (read-string "Source groups (regexp): ")
  4349.     (let ((headers (mapcar (lambda (group) (list group))
  4350.                '("subject" "from" "number" "date" "message-id"
  4351.                  "references" "chars" "lines" "xref")))
  4352.       scores header regexp regexps)
  4353.       (while (not (equal "" (setq header (completing-read 
  4354.                       "Match on header: " headers nil t))))
  4355.     (setq regexps nil)
  4356.     (while (not (equal "" (setq regexp (read-string 
  4357.                         (format "Match on %s (string): "
  4358.                             header)))))
  4359.       (setq regexps (cons (list regexp nil nil 'r) regexps)))
  4360.     (setq scores (cons (cons header regexps) scores)))
  4361.       scores)))
  4362.   (gnus-group-make-group group "nnkiboze" address)
  4363.   (save-excursion
  4364.     (gnus-set-work-buffer)
  4365.     (let (emacs-lisp-mode-hook)
  4366.       (pp scores (current-buffer)))
  4367.     (write-region (point-min) (point-max) 
  4368.           (concat (or gnus-kill-files-directory "~/News")
  4369.               "nnkiboze:" group "." gnus-score-file-suffix)))
  4370.   (gnus-group-position-cursor))
  4371.  
  4372. (defun gnus-group-add-to-virtual (n vgroup)
  4373.   "Add the current group to a virtual group."
  4374.   (interactive
  4375.    (list current-prefix-arg
  4376.      (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
  4377.               "nnvirtual:")))
  4378.   (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
  4379.       (error "%s is not an nnvirtual group" vgroup))
  4380.   (let* ((groups (gnus-group-process-prefix n))
  4381.      (method (nth 4 (nth 2 (gnus-gethash vgroup gnus-newsrc-hashtb)))))
  4382.     (setcar (cdr method)
  4383.         (concat 
  4384.          (nth 1 method) "\\|"
  4385.          (mapconcat 
  4386.           (lambda (s) 
  4387.         (gnus-group-remove-mark s)
  4388.         (concat "\\(^" (regexp-quote s) "$\\)"))
  4389.           groups "\\|"))))
  4390.   (gnus-group-position-cursor))
  4391.  
  4392. (defun gnus-group-make-empty-virtual (group)
  4393.   "Create a new, fresh, empty virtual group."
  4394.   (interactive "sCreate new, empty virtual group: ")
  4395.   (let* ((method (list 'nnvirtual "^$"))
  4396.      (pgroup (gnus-group-prefixed-name group method)))
  4397.     ;; Check whether it exists already.
  4398.     (and (gnus-gethash pgroup gnus-newsrc-hashtb)
  4399.      (error "Group %s already exists." pgroup))
  4400.     ;; Subscribe the new group after the group on the current line.
  4401.     (gnus-subscribe-group pgroup (gnus-group-group-name) method)
  4402.     (gnus-group-update-group pgroup)
  4403.     (forward-line -1)
  4404.     (gnus-group-position-cursor)))
  4405.  
  4406. (defun gnus-group-enter-directory (dir)
  4407.   "Enter an ephemeral nneething group."
  4408.   (interactive "DDirectory to read: ")
  4409.   (let* ((method (list 'nneething dir))
  4410.      (leaf (gnus-group-prefixed-name
  4411.         (file-name-nondirectory (directory-file-name dir))
  4412.         method))
  4413.      (name (gnus-generate-new-group-name leaf)))
  4414.     (let ((nneething-read-only t))
  4415.       (or (gnus-group-read-ephemeral-group 
  4416.        name method t
  4417.        (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
  4418.                       'summary 'group)))
  4419.       (error "Couldn't enter %s" dir)))))
  4420.  
  4421. ;; Group sorting commands
  4422. ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
  4423.  
  4424. (defun gnus-group-sort-groups ()
  4425.   "Sort the group buffer using `gnus-group-sort-function'."
  4426.   (interactive)
  4427.   (setq gnus-newsrc-alist 
  4428.     (sort (cdr gnus-newsrc-alist) gnus-group-sort-function))
  4429.   (gnus-make-hashtable-from-newsrc-alist)
  4430.   (gnus-group-list-groups))
  4431.  
  4432. (defun gnus-group-sort-by-alphabet (info1 info2)
  4433.   (string< (car info1) (car info2)))
  4434.  
  4435. (defun gnus-group-sort-by-unread (info1 info2)
  4436.   (let ((n1 (car (gnus-gethash (car info1) gnus-newsrc-hashtb)))
  4437.     (n2 (car (gnus-gethash (car info2) gnus-newsrc-hashtb))))
  4438.     (< (or (and (numberp n1) n1) 0)
  4439.        (or (and (numberp n2) n2) 0))))
  4440.  
  4441. (defun gnus-group-sort-by-level (info1 info2)
  4442.   (< (nth 1 info1) (nth 1 info2)))
  4443.  
  4444. ;; Group catching up.
  4445.  
  4446. (defun gnus-group-catchup-current (&optional n all)
  4447.   "Mark all articles not marked as unread in current newsgroup as read.
  4448. If prefix argument N is numeric, the ARG next newsgroups will be
  4449. caught up. If ALL is non-nil, marked articles will also be marked as
  4450. read. Cross references (Xref: header) of articles are ignored.
  4451. The difference between N and actual number of newsgroups that were
  4452. caught up is returned."
  4453.   (interactive "P")
  4454.   (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
  4455.            gnus-expert-user
  4456.            (gnus-y-or-n-p
  4457.         (if all
  4458.             "Do you really want to mark all articles as read? "
  4459.           "Mark all unread articles as read? "))))
  4460.       n
  4461.     (let ((groups (gnus-group-process-prefix n))
  4462.       (ret 0))
  4463.       (while groups
  4464.     ;; Virtual groups have to be given special treatment. 
  4465.     (let ((method (gnus-find-method-for-group (car groups))))
  4466.       (if (eq 'nnvirtual (car method))
  4467.           (nnvirtual-catchup-group
  4468.            (gnus-group-real-name (car groups)) (nth 1 method) all)))
  4469.     (gnus-group-remove-mark (car groups))
  4470.     (if (prog1
  4471.         (gnus-group-goto-group (car groups))
  4472.           (gnus-group-catchup (car groups) all))
  4473.         (gnus-group-update-group-line)
  4474.       (setq ret (1+ ret)))
  4475.     (setq groups (cdr groups)))
  4476.       (gnus-group-next-unread-group 1)
  4477.       ret)))
  4478.  
  4479. (defun gnus-group-catchup-current-all (&optional n)
  4480.   "Mark all articles in current newsgroup as read.
  4481. Cross references (Xref: header) of articles are ignored."
  4482.   (interactive "P")
  4483.   (gnus-group-catchup-current n 'all))
  4484.  
  4485. (defun gnus-group-catchup (group &optional all)
  4486.   "Mark all articles in GROUP as read.
  4487. If ALL is non-nil, all articles are marked as read.
  4488. The return value is the number of articles that were marked as read,
  4489. or nil if no action could be taken."
  4490.   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
  4491.      (num (car entry))
  4492.      (marked (nth 3 (nth 2 entry))))
  4493.     (if (not (numberp (car entry)))
  4494.     (gnus-message 1 "Can't catch up; non-active group")
  4495.       ;; Do the updating only if the newsgroup isn't killed.
  4496.       (if (not entry)
  4497.       ()
  4498.     (gnus-update-read-articles 
  4499.      group (and (not all) (append (cdr (assq 'tick marked))
  4500.                       (cdr (assq 'dormant marked))))
  4501.      nil (and (not all) (cdr (assq 'tick marked))))
  4502.     (and all 
  4503.          (setq marked (nth 3 (nth 2 entry)))
  4504.          (setcar (nthcdr 3 (nth 2 entry)) 
  4505.              (delq (assq 'dormant marked) 
  4506.                (nth 3 (nth 2 entry)))))))
  4507.     num))
  4508.  
  4509. (defun gnus-group-expire-articles (&optional n)
  4510.   "Expire all expirable articles in the current newsgroup."
  4511.   (interactive "P")
  4512.   (let ((groups (gnus-group-process-prefix n))
  4513.     group)
  4514.     (or groups (error "No groups to expire"))
  4515.     (while groups
  4516.       (setq group (car groups)
  4517.         groups (cdr groups))
  4518.       (gnus-group-remove-mark group)
  4519.       (if (not (gnus-check-backend-function 'request-expire-articles group))
  4520.       ()
  4521.     (let* ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
  4522.            (expirable (if (memq 'total-expire (nth 5 info))
  4523.                   (cons nil (gnus-list-of-read-articles group))
  4524.                 (assq 'expire (nth 3 info)))))
  4525.       (and expirable 
  4526.            (setcdr expirable
  4527.                (gnus-request-expire-articles 
  4528.             (cdr expirable) group))))))))
  4529.  
  4530. (defun gnus-group-expire-all-groups ()
  4531.   "Expire all expirable articles in all newsgroups."
  4532.   (interactive)
  4533.   (save-excursion
  4534.     (gnus-message 5 "Expiring...")
  4535.     (let ((gnus-group-marked (mapcar (lambda (info) (car info))
  4536.                      (cdr gnus-newsrc-alist))))
  4537.       (gnus-group-expire-articles nil)))
  4538.   (gnus-group-position-cursor)
  4539.   (gnus-message 5 "Expiring...done"))
  4540.  
  4541. (defun gnus-group-set-current-level (n level)
  4542.   "Set the level of the next N groups to LEVEL."
  4543.   (interactive "P\nnLevel: ")
  4544.   (or (and (>= level 1) (<= level gnus-level-killed))
  4545.       (error "Illegal level: %d" level))
  4546.   (let ((groups (gnus-group-process-prefix n))
  4547.     group)
  4548.     (while groups
  4549.       (setq group (car groups)
  4550.         groups (cdr groups))
  4551.       (gnus-group-remove-mark group)
  4552.       (gnus-message 6 "Changed level of %s from %d to %d" 
  4553.             group (gnus-group-group-level) level)
  4554.       (gnus-group-change-level group level
  4555.                    (gnus-group-group-level))
  4556.       (gnus-group-update-group-line)))
  4557.   (gnus-group-position-cursor))
  4558.  
  4559. (defun gnus-group-unsubscribe-current-group (&optional n)
  4560.   "Toggle subscription of the current group.
  4561. If given numerical prefix, toggle the N next groups."
  4562.   (interactive "P")
  4563.   (let ((groups (gnus-group-process-prefix n))
  4564.     group)
  4565.     (while groups
  4566.       (setq group (car groups)
  4567.         groups (cdr groups))
  4568.       (gnus-group-remove-mark group)
  4569.       (gnus-group-unsubscribe-group
  4570.        group (if (<= (gnus-group-group-level) gnus-level-subscribed)
  4571.          gnus-level-default-unsubscribed
  4572.            gnus-level-default-subscribed))
  4573.       (gnus-group-update-group-line))
  4574.     (gnus-group-next-group 1)))
  4575.  
  4576. (defun gnus-group-unsubscribe-group (group &optional level)
  4577.   "Toggle subscribe from/to unsubscribe GROUP.
  4578. New newsgroup is added to .newsrc automatically."
  4579.   (interactive
  4580.    (list (completing-read
  4581.       "Group: " gnus-active-hashtb nil 
  4582.       (memq gnus-select-method gnus-have-read-active-file))))
  4583.   (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
  4584.     (cond
  4585.      ((string-match "^[ \t]$" group)
  4586.       (error "Empty group name"))
  4587.      (newsrc
  4588.       ;; Toggle subscription flag.
  4589.       (gnus-group-change-level 
  4590.        newsrc (if level level (if (<= (nth 1 (nth 2 newsrc)) 
  4591.                       gnus-level-subscribed) 
  4592.                   (1+ gnus-level-subscribed)
  4593.                 gnus-level-default-subscribed)))
  4594.       (gnus-group-update-group group))
  4595.      ((and (stringp group)
  4596.        (or (not (memq gnus-select-method gnus-have-read-active-file))
  4597.            (gnus-gethash group gnus-active-hashtb)))
  4598.       ;; Add new newsgroup.
  4599.       (gnus-group-change-level 
  4600.        group 
  4601.        (if level level gnus-level-default-subscribed) 
  4602.        (or (and (member group gnus-zombie-list) 
  4603.         gnus-level-zombie) 
  4604.        gnus-level-killed)
  4605.        (and (gnus-group-group-name)
  4606.         (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
  4607.       (gnus-group-update-group group))
  4608.      (t (error "No such newsgroup: %s" group)))
  4609.     (gnus-group-position-cursor)))
  4610.  
  4611. (defun gnus-group-transpose-groups (n)
  4612.   "Move the current newsgroup up N places.
  4613. If given a negative prefix, move down instead. The difference between
  4614. N and the number of steps taken is returned." 
  4615.   (interactive "p")
  4616.   (or (gnus-group-group-name)
  4617.       (error "No group on current line"))
  4618.   (gnus-group-kill-group 1)
  4619.   (prog1
  4620.       (forward-line (- n))
  4621.     (gnus-group-yank-group)
  4622.     (gnus-group-position-cursor)))
  4623.  
  4624. (defun gnus-group-kill-all-zombies ()
  4625.   "Kill all zombie newsgroups."
  4626.   (interactive)
  4627.   (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
  4628.   (setq gnus-zombie-list nil)
  4629.   (gnus-group-list-groups))
  4630.  
  4631. (defun gnus-group-kill-region (begin end)
  4632.   "Kill newsgroups in current region (excluding current point).
  4633. The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
  4634.   (interactive "r")
  4635.   (let ((lines
  4636.      ;; Count lines.
  4637.      (save-excursion
  4638.        (count-lines
  4639.         (progn
  4640.           (goto-char begin)
  4641.           (beginning-of-line)
  4642.           (point))
  4643.         (progn
  4644.           (goto-char end)
  4645.           (beginning-of-line)
  4646.           (point))))))
  4647.     (goto-char begin)
  4648.     (beginning-of-line)            ;Important when LINES < 1
  4649.     (gnus-group-kill-group lines)))
  4650.  
  4651. (defun gnus-group-kill-group (&optional n)
  4652.   "The the next N groups.
  4653. The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
  4654. However, only groups that were alive can be yanked; already killed 
  4655. groups or zombie groups can't be yanked.
  4656. The return value is the name of the (last) group that was killed."
  4657.   (interactive "P")
  4658.   (let ((buffer-read-only nil)
  4659.     (groups (gnus-group-process-prefix n))
  4660.     group entry level)
  4661.     (while groups
  4662.       (setq group (car groups)
  4663.         groups (cdr groups))
  4664.       (gnus-group-remove-mark group)
  4665.       (setq level (gnus-group-group-level))
  4666.       (gnus-delete-line)
  4667.       (if (setq entry (gnus-gethash group gnus-newsrc-hashtb))
  4668.       (setq gnus-list-of-killed-groups 
  4669.         (cons (cons (car entry) (nth 2 entry)) 
  4670.               gnus-list-of-killed-groups)))
  4671.       (gnus-group-change-level 
  4672.        (if entry entry group) gnus-level-killed (if entry nil level)))
  4673.     (gnus-group-position-cursor)
  4674.     group))
  4675.  
  4676. (defun gnus-group-yank-group (&optional arg)
  4677.   "Yank the last newsgroups killed with \\[gnus-group-kill-group],
  4678. inserting it before the current newsgroup.  The numeric ARG specifies
  4679. how many newsgroups are to be yanked.  The name of the (last)
  4680. newsgroup yanked is returned."
  4681.   (interactive "p")
  4682.   (if (not arg) (setq arg 1))
  4683.   (let (info group prev)
  4684.     (while (>= (setq arg (1- arg)) 0)
  4685.       (if (not (setq info (car gnus-list-of-killed-groups)))
  4686.       (error "No more newsgroups to yank"))
  4687.       (setq group (nth 2 info))
  4688.       ;; Find which newsgroup to insert this one before - search
  4689.       ;; backward until something suitable is found. If there are no
  4690.       ;; other newsgroups in this buffer, just make this newsgroup the
  4691.       ;; first newsgroup.
  4692.       (setq prev (gnus-group-group-name))
  4693.       (gnus-group-change-level 
  4694.        info (nth 2 info) gnus-level-killed 
  4695.        (and prev (gnus-gethash prev gnus-newsrc-hashtb))
  4696.        t)
  4697.       (gnus-group-insert-group-line-info (nth 1 info))
  4698.       (setq gnus-list-of-killed-groups 
  4699.         (cdr gnus-list-of-killed-groups)))
  4700.     (forward-line -1)
  4701.     (gnus-group-position-cursor)
  4702.     group))
  4703.       
  4704. (defun gnus-group-list-all-groups (&optional arg)
  4705.   "List all newsgroups with level ARG or lower.
  4706. Default is gnus-level-unsubscribed, which lists all subscribed and most
  4707. unsubscribed groups."
  4708.   (interactive "P")
  4709.   (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
  4710.  
  4711. (defun gnus-group-list-killed ()
  4712.   "List all killed newsgroups in the group buffer."
  4713.   (interactive)
  4714.   (if (not gnus-killed-list)
  4715.       (gnus-message 6 "No killed groups")
  4716.     (let (gnus-group-list-mode)
  4717.       (funcall gnus-group-prepare-function 
  4718.            gnus-level-killed t gnus-level-killed))
  4719.     (goto-char (point-min)))
  4720.   (gnus-group-position-cursor))
  4721.  
  4722. (defun gnus-group-list-zombies ()
  4723.   "List all zombie newsgroups in the group buffer."
  4724.   (interactive)
  4725.   (if (not gnus-zombie-list)
  4726.       (gnus-message 6 "No zombie groups")
  4727.     (let (gnus-group-list-mode)
  4728.       (funcall gnus-group-prepare-function
  4729.            gnus-level-zombie t gnus-level-zombie))
  4730.     (goto-char (point-min)))
  4731.   (gnus-group-position-cursor))
  4732.  
  4733. (defun gnus-group-get-new-news (&optional arg)
  4734.   "Get newly arrived articles.
  4735. If ARG is non-nil, it should be a number between one and nine to
  4736. specify which levels you are interested in re-scanning."
  4737.   (interactive "P")
  4738.   (run-hooks 'gnus-get-new-news-hook)
  4739.   (setq arg (gnus-group-default-level arg t))
  4740.   (if (and gnus-read-active-file (not arg))
  4741.       (progn
  4742.     (gnus-read-active-file)
  4743.     (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed))))
  4744.     (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
  4745.       (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed)))))
  4746.   (gnus-group-list-groups))
  4747.  
  4748. (defun gnus-group-get-new-news-this-group (&optional n)
  4749.   "Check for newly arrived news in the current group (and the N-1 next groups).
  4750. The difference between N and the number of newsgroup checked is returned.
  4751. If N is negative, this group and the N-1 previous groups will be checked."
  4752.   (interactive "P")
  4753.   (let* ((groups (gnus-group-process-prefix n))
  4754.      (ret (if (numberp n) (- n (length groups)) 0))
  4755.      group)
  4756.     (while groups
  4757.       (setq group (car groups)
  4758.         groups (cdr groups))
  4759.       (gnus-group-remove-mark group)
  4760.       (or (gnus-get-new-news-in-group group)
  4761.       (progn 
  4762.         (ding) 
  4763.         (message "%s error: %s" group (gnus-status-message group))
  4764.         (sit-for 2))))
  4765.     (gnus-group-next-unread-group 1 t)
  4766.     (gnus-summary-position-cursor)
  4767.     ret))
  4768.  
  4769. (defun gnus-get-new-news-in-group (group)
  4770.   (and group 
  4771.        (gnus-activate-group group)
  4772.        (progn
  4773.      (gnus-get-unread-articles-in-group 
  4774.       (nth 2 (gnus-gethash group gnus-newsrc-hashtb))
  4775.       (gnus-gethash group gnus-active-hashtb))
  4776.      (gnus-group-update-group-line)
  4777.      t)))
  4778.  
  4779. (defun gnus-group-fetch-faq (group)
  4780.   "Fetch the FAQ for the current group."
  4781.   (interactive (list (gnus-group-real-name (gnus-group-group-name))))
  4782.   (or group (error "No group name given"))
  4783.   (let ((file (concat gnus-group-faq-directory (gnus-group-real-name group))))
  4784.     (if (not (file-exists-p file))
  4785.     (error "No such file: %s" file)
  4786.       (find-file file))))
  4787.   
  4788. (defun gnus-group-describe-group (force &optional group)
  4789.   "Display a description of the current newsgroup."
  4790.   (interactive (list current-prefix-arg (gnus-group-group-name)))
  4791.   (and force (setq gnus-description-hashtb nil))
  4792.   (let ((method (gnus-find-method-for-group group))
  4793.     desc)
  4794.     (or group (error "No group name given"))
  4795.     (and (or (and gnus-description-hashtb
  4796.           ;; We check whether this group's method has been
  4797.           ;; queried for a description file.  
  4798.           (gnus-gethash 
  4799.            (gnus-group-prefixed-name "" method) 
  4800.            gnus-description-hashtb))
  4801.          (setq desc (gnus-group-get-description group))
  4802.          (gnus-read-descriptions-file method))
  4803.      (message
  4804.       (or desc (gnus-gethash group gnus-description-hashtb)
  4805.           "No description available")))))
  4806.  
  4807. ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
  4808. (defun gnus-group-describe-all-groups (&optional force)
  4809.   "Pop up a buffer with descriptions of all newsgroups."
  4810.   (interactive "P")
  4811.   (and force (setq gnus-description-hashtb nil))
  4812.   (if (not (or gnus-description-hashtb
  4813.            (gnus-read-all-descriptions-files)))
  4814.       (error "Couldn't request descriptions file"))
  4815.   (let ((buffer-read-only nil)
  4816.     b)
  4817.     (erase-buffer)
  4818.     (mapatoms
  4819.      (lambda (group)
  4820.        (setq b (point))
  4821.        (insert (format "      *: %-20s %s\n" (symbol-name group)
  4822.                (symbol-value group)))
  4823.        (add-text-properties 
  4824.     b (1+ b) (list 'gnus-group group
  4825.                'gnus-unread t 'gnus-marked nil
  4826.                'gnus-level (1+ gnus-level-subscribed))))
  4827.      gnus-description-hashtb)
  4828.     (goto-char (point-min))
  4829.     (gnus-group-position-cursor)))
  4830.  
  4831. ;; Suggested by by Daniel Quinlan <quinlan@best.com>.
  4832. (defun gnus-group-apropos (regexp &optional search-description)
  4833.   "List all newsgroups that have names that match a regexp."
  4834.   (interactive "sGnus apropos (regexp): ")
  4835.   (let ((prev "")
  4836.     (obuf (current-buffer))
  4837.     groups des)
  4838.     ;; Go through all newsgroups that are known to Gnus.
  4839.     (mapatoms 
  4840.      (lambda (group)
  4841.        (and (symbol-name group)
  4842.         (string-match regexp (symbol-name group))
  4843.         (setq groups (cons (symbol-name group) groups))))
  4844.      gnus-active-hashtb)
  4845.     ;; Go through all descriptions that are known to Gnus. 
  4846.     (if search-description
  4847.     (mapatoms 
  4848.      (lambda (group)
  4849.        (and (string-match regexp (symbol-value group))
  4850.         (gnus-gethash (symbol-name group) gnus-active-hashtb)
  4851.         (setq groups (cons (symbol-name group) groups))))
  4852.      gnus-description-hashtb))
  4853.     (if (not groups)
  4854.     (gnus-message 3 "No groups matched \"%s\"." regexp)
  4855.       ;; Print out all the groups.
  4856.       (save-excursion
  4857.     (pop-to-buffer "*Gnus Help*")
  4858.     (buffer-disable-undo (current-buffer))
  4859.     (erase-buffer)
  4860.     (setq groups (sort groups 'string<))
  4861.     (while groups
  4862.       ;; Groups may be entered twice into the list of groups.
  4863.       (if (not (string= (car groups) prev))
  4864.           (progn
  4865.         (insert (setq prev (car groups)) "\n")
  4866.         (if (and gnus-description-hashtb
  4867.              (setq des (gnus-gethash (car groups) 
  4868.                          gnus-description-hashtb)))
  4869.             (insert "  " des "\n"))))
  4870.       (setq groups (cdr groups)))
  4871.     (goto-char (point-min))))
  4872.     (pop-to-buffer obuf)))
  4873.  
  4874. (defun gnus-group-description-apropos (regexp)
  4875.   "List all newsgroups that have names or descriptions that match a regexp."
  4876.   (interactive "sGnus description apropos (regexp): ")
  4877.   (if (not (or gnus-description-hashtb
  4878.            (gnus-read-all-descriptions-files)))
  4879.       (error "Couldn't request descriptions file"))
  4880.   (gnus-group-apropos regexp t))
  4881.  
  4882. ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
  4883. (defun gnus-group-list-matching (level regexp &optional all lowest) 
  4884.   "List all groups with unread articles that match REGEXP.
  4885. If the prefix LEVEL is non-nil, it should be a number that says which
  4886. level to cut off listing groups. 
  4887. If ALL, also list groups with no unread articles.
  4888. If LOWEST, don't list groups with level lower than LOWEST."
  4889.   (interactive "P\nsList newsgroups matching: ")
  4890.   (gnus-group-prepare-flat (or level gnus-level-subscribed)
  4891.                all (or lowest 1) regexp)
  4892.   (goto-char (point-min))
  4893.   (gnus-group-position-cursor))
  4894.  
  4895. (defun gnus-group-list-all-matching (level regexp &optional lowest) 
  4896.   "List all groups that match REGEXP.
  4897. If the prefix LEVEL is non-nil, it should be a number that says which
  4898. level to cut off listing groups. 
  4899. If LOWEST, don't list groups with level lower than LOWEST."
  4900.   (interactive "P\nsList newsgroups matching: ")
  4901.   (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
  4902.  
  4903. ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
  4904. (defun gnus-group-save-newsrc ()
  4905.   "Save the Gnus startup files."
  4906.   (interactive)
  4907.   (gnus-save-newsrc-file))
  4908.  
  4909. (defun gnus-group-restart (&optional arg)
  4910.   "Force Gnus to read the .newsrc file."
  4911.   (interactive "P")
  4912.   (gnus-save-newsrc-file)
  4913.   (gnus-setup-news 'force)
  4914.   (gnus-group-list-groups arg))
  4915.  
  4916. (defun gnus-group-read-init-file ()
  4917.   "Read the Gnus elisp init file."
  4918.   (interactive)
  4919.   (gnus-read-init-file))
  4920.  
  4921. (defun gnus-group-check-bogus-groups (&optional silent)
  4922.   "Check bogus newsgroups.
  4923. If given a prefix, don't ask for confirmation before removing a bogus
  4924. group."
  4925.   (interactive "P")
  4926.   (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
  4927.   (gnus-group-list-groups))
  4928.  
  4929. (defun gnus-group-edit-global-kill (&optional article group)
  4930.   "Edit the global kill file.
  4931. If GROUP, edit that local kill file instead."
  4932.   (interactive "P")
  4933.   (setq gnus-current-kill-article article)
  4934.   (gnus-kill-file-edit-file group)
  4935.   (gnus-message 
  4936.    6
  4937.    (substitute-command-keys
  4938.     "Editing a global kill file (Type \\[gnus-kill-file-exit] to exit)")))
  4939.  
  4940. (defun gnus-group-edit-local-kill (article group)
  4941.   "Edit a local kill file."
  4942.   (interactive (list nil (gnus-group-group-name)))
  4943.   (gnus-group-edit-global-kill article group))
  4944.  
  4945. (defun gnus-group-force-update ()
  4946.   "Update `.newsrc' file."
  4947.   (interactive)
  4948.   (gnus-save-newsrc-file))
  4949.  
  4950. (defun gnus-group-suspend ()
  4951.   "Suspend the current Gnus session.
  4952. In fact, cleanup buffers except for group mode buffer.
  4953. The hook gnus-suspend-gnus-hook is called before actually suspending."
  4954.   (interactive)
  4955.   (run-hooks 'gnus-suspend-gnus-hook)
  4956.   ;; Kill Gnus buffers except for group mode buffer.
  4957.   (let ((group-buf (get-buffer gnus-group-buffer)))
  4958.     ;; Do this on a separate list in case the user does a ^G before we finish
  4959.     (let ((gnus-buffer-list
  4960.        (delq group-buf (delq gnus-dribble-buffer
  4961.                  (append gnus-buffer-list nil)))))
  4962.       (while gnus-buffer-list
  4963.     (gnus-kill-buffer (car gnus-buffer-list))
  4964.     (setq gnus-buffer-list (cdr gnus-buffer-list))))
  4965.     (if group-buf
  4966.     (progn
  4967.       (setq gnus-buffer-list (list group-buf))
  4968.       (bury-buffer group-buf)
  4969.       (delete-windows-on group-buf t)))))
  4970.  
  4971. (defun gnus-group-clear-dribble ()
  4972.   "Clear all information from the dribble buffer."
  4973.   (interactive)
  4974.   (gnus-dribble-clear))
  4975.  
  4976. (defun gnus-group-exit ()
  4977.   "Quit reading news after updating .newsrc.eld and .newsrc.
  4978. The hook `gnus-exit-gnus-hook' is called before actually exiting."
  4979.   (interactive)
  4980.   (if (or noninteractive        ;For gnus-batch-kill
  4981.       (not (gnus-server-opened gnus-select-method)) ;NNTP connection closed
  4982.       (not gnus-interactive-exit)    ;Without confirmation
  4983.       gnus-expert-user
  4984.       (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
  4985.       (progn
  4986.     (run-hooks 'gnus-exit-gnus-hook)
  4987.     ;; Offer to save data from non-quitted summary buffers.
  4988.     (gnus-offer-save-summaries)
  4989.     ;; Save the newsrc file(s).
  4990.     (gnus-save-newsrc-file)
  4991.     ;; Kill-em-all.
  4992.     (gnus-close-backends)
  4993.     ;; Reset everything.
  4994.     (gnus-clear-system))))
  4995.  
  4996. (defun gnus-close-backends ()
  4997.   ;; Send a close request to all backends that support such a request. 
  4998.   (let ((methods gnus-valid-select-methods)
  4999.     func)
  5000.     (while methods
  5001.       (if (fboundp (setq func (intern (concat (car (car methods))
  5002.                           "-request-close"))))
  5003.       (funcall func))
  5004.       (setq methods (cdr methods)))))
  5005.  
  5006. (defun gnus-group-quit ()
  5007.   "Quit reading news without updating .newsrc.eld or .newsrc.
  5008. The hook `gnus-exit-gnus-hook' is called before actually exiting."
  5009.   (interactive)
  5010.   (if (or noninteractive        ;For gnus-batch-kill
  5011.       (zerop (buffer-size))
  5012.       (not (gnus-server-opened gnus-select-method))
  5013.       gnus-expert-user
  5014.       (not gnus-current-startup-file)
  5015.       (gnus-yes-or-no-p
  5016.        (format "Quit reading news without saving %s? "
  5017.            (file-name-nondirectory gnus-current-startup-file))))
  5018.       (progn
  5019.     (run-hooks 'gnus-exit-gnus-hook)
  5020.     (if gnus-use-full-window
  5021.         (delete-other-windows)
  5022.       (gnus-remove-some-windows))
  5023.     (gnus-dribble-save)
  5024.     (gnus-close-backends)
  5025.     (gnus-clear-system))))
  5026.  
  5027. (defun gnus-offer-save-summaries ()
  5028.   (save-excursion
  5029.     (let ((buflist (buffer-list)) 
  5030.       buffers bufname)
  5031.       (while buflist
  5032.     (and (setq bufname (buffer-name (car buflist)))
  5033.          (string-match "Summary" bufname)
  5034.          (save-excursion
  5035.            (set-buffer bufname)
  5036.            ;; We check that this is, indeed, a summary buffer.
  5037.            (eq major-mode 'gnus-summary-mode))
  5038.          (setq buffers (cons bufname buffers)))
  5039.     (setq buflist (cdr buflist)))
  5040.       (and buffers
  5041.        (map-y-or-n-p 
  5042.         "Update summary buffer %s? "
  5043.         (lambda (buf)
  5044.           (set-buffer buf)
  5045.           (gnus-summary-exit))
  5046.         buffers)))))
  5047.  
  5048. (defun gnus-group-describe-briefly ()
  5049.   "Give a one line description of the group mode commands."
  5050.   (interactive)
  5051.   (gnus-message 7 (substitute-command-keys "\\<gnus-group-mode-map>\\[gnus-group-read-group]:Select  \\[gnus-group-next-unread-group]:Forward  \\[gnus-group-prev-unread-group]:Backward  \\[gnus-group-exit]:Exit  \\[gnus-info-find-node]:Run Info  \\[gnus-group-describe-briefly]:This help")))
  5052.  
  5053. (defun gnus-group-browse-foreign-server (method)
  5054.   "Browse a foreign news server.
  5055. If called interactively, this function will ask for a select method
  5056.  (nntp, nnspool, etc.) and a server address (eg. nntp.some.where). 
  5057. If not, METHOD should be a list where the first element is the method
  5058. and the second element is the address."
  5059.   (interactive
  5060.    (list (let ((how (completing-read 
  5061.              "Which backend: "
  5062.              (append gnus-valid-select-methods gnus-server-alist)
  5063.              nil t "nntp")))
  5064.        ;; We either got a backend name or a virtual server name.
  5065.        ;; If the first, we also need an address.
  5066.        (if (assoc how gnus-valid-select-methods)
  5067.            (list (intern how)
  5068.              ;; Suggested by mapjph@bath.ac.uk.
  5069.              (completing-read 
  5070.               "Address: " 
  5071.               (mapcar (lambda (server) (list server))
  5072.                   gnus-secondary-servers)))
  5073.          ;; We got a server name, so we find the method.
  5074.          (gnus-server-to-method how)))))
  5075.   (gnus-browse-foreign-server method))
  5076.  
  5077.  
  5078. ;;;
  5079. ;;; Browse Server Mode
  5080. ;;;
  5081.  
  5082. (defvar gnus-browse-mode-hook nil)
  5083. (defvar gnus-browse-mode-map nil)
  5084. (put 'gnus-browse-mode 'mode-class 'special)
  5085.  
  5086. (if gnus-browse-mode-map
  5087.     nil
  5088.   (setq gnus-browse-mode-map (make-keymap))
  5089.   (suppress-keymap gnus-browse-mode-map)
  5090.   (define-key gnus-browse-mode-map " " 'gnus-browse-read-group)
  5091.   (define-key gnus-browse-mode-map "=" 'gnus-browse-select-group)
  5092.   (define-key gnus-browse-mode-map "n" 'gnus-browse-next-group)
  5093.   (define-key gnus-browse-mode-map "p" 'gnus-browse-prev-group)
  5094.   (define-key gnus-browse-mode-map "\177" 'gnus-browse-prev-group)
  5095.   (define-key gnus-browse-mode-map "N" 'gnus-browse-next-group)
  5096.   (define-key gnus-browse-mode-map "P" 'gnus-browse-prev-group)
  5097.   (define-key gnus-browse-mode-map "\M-n" 'gnus-browse-next-group)
  5098.   (define-key gnus-browse-mode-map "\M-p" 'gnus-browse-prev-group)
  5099.   (define-key gnus-browse-mode-map "\r" 'gnus-browse-select-group)
  5100.   (define-key gnus-browse-mode-map "u" 'gnus-browse-unsubscribe-current-group)
  5101.   (define-key gnus-browse-mode-map "l" 'gnus-browse-exit)
  5102.   (define-key gnus-browse-mode-map "L" 'gnus-browse-exit)
  5103.   (define-key gnus-browse-mode-map "q" 'gnus-browse-exit)
  5104.   (define-key gnus-browse-mode-map "Q" 'gnus-browse-exit)
  5105.   (define-key gnus-browse-mode-map "\C-c\C-c" 'gnus-browse-exit)
  5106.   (define-key gnus-browse-mode-map "?" 'gnus-browse-describe-briefly)
  5107.   (define-key gnus-browse-mode-map "\C-c\C-i" 'gnus-info-find-node)
  5108.   )
  5109.  
  5110. (defvar gnus-browse-current-method nil)
  5111. (defvar gnus-browse-return-buffer nil)
  5112.  
  5113. (defvar gnus-browse-buffer "*Gnus Browse Server*")
  5114.  
  5115. (defun gnus-browse-foreign-server (method &optional return-buffer)
  5116.   (setq gnus-browse-current-method method)
  5117.   (setq gnus-browse-return-buffer return-buffer)
  5118.   (let ((gnus-select-method method)
  5119.     groups group)
  5120.     (gnus-message 5 "Connecting to %s..." (nth 1 method))
  5121.     (or (gnus-check-server method)
  5122.     (error "Unable to contact server: %s" (gnus-status-message method)))
  5123.     (or (gnus-request-list method)
  5124.     (error "Couldn't request list: %s" (gnus-status-message method)))
  5125.     (get-buffer-create gnus-browse-buffer)
  5126.     (gnus-add-current-to-buffer-list)
  5127.     (and gnus-carpal (gnus-carpal-setup-buffer 'browse))
  5128.     (gnus-configure-windows 'browse)
  5129.     (buffer-disable-undo (current-buffer))
  5130.     (let ((buffer-read-only nil))
  5131.       (erase-buffer))
  5132.     (gnus-browse-mode)
  5133.     (setq mode-line-buffer-identification
  5134.       (format
  5135.        "Gnus  Browse Server {%s:%s}" (car method) (car (cdr method))))
  5136.     (save-excursion
  5137.       (set-buffer nntp-server-buffer)
  5138.       (let ((cur (current-buffer)))
  5139.     (goto-char (point-min))
  5140.     (or (string= gnus-ignored-newsgroups "")
  5141.         (delete-matching-lines gnus-ignored-newsgroups))
  5142.     (while (re-search-forward 
  5143.         "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t)
  5144.       (goto-char (match-end 1))
  5145.       (setq groups (cons (cons (buffer-substring (match-beginning 1)
  5146.                              (match-end 1))
  5147.                    (max 0 (- (1+ (read cur)) (read cur))))
  5148.                  groups)))))
  5149.     (setq groups (sort groups 
  5150.                (lambda (l1 l2)
  5151.              (string< (car l1) (car l2)))))
  5152.     (let ((buffer-read-only nil))
  5153.       (while groups
  5154.     (setq group (car groups))
  5155.     (insert 
  5156.      (format "K%7d: %s\n" (cdr group) (car group)))
  5157.     (setq groups (cdr groups))))
  5158.     (switch-to-buffer (current-buffer))
  5159.     (goto-char (point-min))
  5160.     (gnus-group-position-cursor)))
  5161.  
  5162. (defun gnus-browse-mode ()
  5163.   "Major mode for browsing a foreign server.
  5164.  
  5165. All normal editing commands are switched off.
  5166.  
  5167. \\<gnus-browse-mode-map>
  5168. The only things you can do in this buffer is
  5169.  
  5170. 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
  5171. The group will be inserted into the group buffer upon exit from this
  5172. buffer.  
  5173.  
  5174. 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
  5175.  
  5176. 3) `\\[gnus-browse-exit]' to return to the group buffer."
  5177.   (interactive)
  5178.   (kill-all-local-variables)
  5179.   (if gnus-visual (gnus-browse-make-menu-bar))
  5180.   (gnus-simplify-mode-line)
  5181.   (setq major-mode 'gnus-browse-mode)
  5182.   (setq mode-name "Browse Server")
  5183.   (setq mode-line-process nil)
  5184.   (use-local-map gnus-browse-mode-map)
  5185.   (buffer-disable-undo (current-buffer))
  5186.   (setq truncate-lines t)
  5187.   (setq buffer-read-only t)
  5188.   (run-hooks 'gnus-browse-mode-hook))
  5189.  
  5190. (defun gnus-browse-read-group (&optional no-article)
  5191.   "Enter the group at the current line."
  5192.   (interactive)
  5193.   (let ((group (gnus-browse-group-name)))
  5194.     (or (gnus-group-read-ephemeral-group 
  5195.      group gnus-browse-current-method nil
  5196.      (cons (current-buffer) 'browse))
  5197.     (error "Couldn't enter %s" group))))
  5198.  
  5199. (defun gnus-browse-select-group ()
  5200.   "Select the current group."
  5201.   (interactive)
  5202.   (gnus-browse-read-group 'no))
  5203.  
  5204. (defun gnus-browse-next-group (n)
  5205.   "Go to the next group."
  5206.   (interactive "p")
  5207.   (prog1
  5208.       (forward-line n)
  5209.     (gnus-group-position-cursor)))
  5210.  
  5211. (defun gnus-browse-prev-group (n)
  5212.   "Go to the next group."
  5213.   (interactive "p")
  5214.   (gnus-browse-next-group (- n)))
  5215.  
  5216. (defun gnus-browse-unsubscribe-current-group (arg)
  5217.   "(Un)subscribe to the next ARG groups."
  5218.   (interactive "p")
  5219.   (and (eobp)
  5220.        (error "No group at current line."))
  5221.   (let ((ward (if (< arg 0) -1 1))
  5222.     (arg (abs arg)))
  5223.     (while (and (> arg 0)
  5224.         (not (eobp))
  5225.         (gnus-browse-unsubscribe-group)
  5226.         (zerop (gnus-browse-next-group ward)))
  5227.       (setq arg (1- arg)))
  5228.     (gnus-group-position-cursor)
  5229.     (if (/= 0 arg) (gnus-message 7 "No more newsgroups"))
  5230.     arg))
  5231.  
  5232. (defun gnus-browse-group-name ()
  5233.   (save-excursion
  5234.     (beginning-of-line)
  5235.     (if (not (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t))
  5236.     ()
  5237.       (gnus-group-prefixed-name 
  5238.        (buffer-substring (match-beginning 1) (match-end 1))
  5239.        gnus-browse-current-method))))
  5240.   
  5241. (defun gnus-browse-unsubscribe-group ()
  5242.   "Toggle subscription of the current group in the browse buffer."
  5243.   (let ((sub nil)
  5244.     (buffer-read-only nil)
  5245.     group)
  5246.     (save-excursion
  5247.       (beginning-of-line)
  5248.       ;; If this group it killed, then we want to subscribe it.
  5249.       (if (= (following-char) ?K) (setq sub t))
  5250.       (setq group (gnus-browse-group-name))
  5251.       (delete-char 1)
  5252.       (if sub
  5253.       (progn
  5254.         (gnus-group-change-level 
  5255.          (list t group gnus-level-default-subscribed
  5256.            nil nil gnus-browse-current-method) 
  5257.          gnus-level-default-subscribed gnus-level-killed
  5258.          (and (car (nth 1 gnus-newsrc-alist))
  5259.           (gnus-gethash (car (nth 1 gnus-newsrc-alist))
  5260.                 gnus-newsrc-hashtb))
  5261.          t)
  5262.         (insert ? ))
  5263.     (gnus-group-change-level 
  5264.      group gnus-level-killed gnus-level-default-subscribed)
  5265.     (insert ?K)))
  5266.     t))
  5267.  
  5268. (defun gnus-browse-exit ()
  5269.   "Quit browsing and return to the group buffer."
  5270.   (interactive)
  5271.   (if (eq major-mode 'gnus-browse-mode)
  5272.       (kill-buffer (current-buffer)))
  5273.   (if gnus-browse-return-buffer
  5274.       (gnus-configure-windows 'server 'force)
  5275.     (gnus-configure-windows 'group 'force)
  5276.     (gnus-group-list-groups nil)))
  5277.  
  5278. (defun gnus-browse-describe-briefly ()
  5279.   "Give a one line description of the group mode commands."
  5280.   (interactive)
  5281.   (gnus-message 6
  5282.         (substitute-command-keys "\\<gnus-browse-mode-map>\\[gnus-group-next-group]:Forward  \\[gnus-group-prev-group]:Backward  \\[gnus-browse-exit]:Exit  \\[gnus-info-find-node]:Run Info  \\[gnus-browse-describe-briefly]:This help")))
  5283.       
  5284.  
  5285. ;;;
  5286. ;;; Gnus summary mode
  5287. ;;;
  5288.  
  5289. (defvar gnus-summary-mode-map nil)
  5290. (defvar gnus-summary-mark-map nil)
  5291. (defvar gnus-summary-mscore-map nil)
  5292. (defvar gnus-summary-article-map nil)
  5293. (defvar gnus-summary-thread-map nil)
  5294. (defvar gnus-summary-goto-map nil)
  5295. (defvar gnus-summary-exit-map nil)
  5296. (defvar gnus-summary-interest-map nil)
  5297. (defvar gnus-summary-sort-map nil)
  5298. (defvar gnus-summary-backend-map nil)
  5299. (defvar gnus-summary-save-map nil)
  5300. (defvar gnus-summary-wash-map nil)
  5301. (defvar gnus-summary-wash-hide-map nil)
  5302. (defvar gnus-summary-wash-highlight-map nil)
  5303. (defvar gnus-summary-wash-time-map nil)
  5304. (defvar gnus-summary-help-map nil)
  5305.  
  5306. (put 'gnus-summary-mode 'mode-class 'special)
  5307.  
  5308. (if gnus-summary-mode-map
  5309.     nil
  5310.   (setq gnus-summary-mode-map (make-keymap))
  5311.   (suppress-keymap gnus-summary-mode-map)
  5312.  
  5313.   ;; Non-orthogonal keys
  5314.  
  5315.   (define-key gnus-summary-mode-map " " 'gnus-summary-next-page)
  5316.   (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page)
  5317.   (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up)
  5318.   (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article)
  5319.   (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article)
  5320.   (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article)
  5321.   (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article)
  5322.   (define-key gnus-summary-mode-map "\M-\C-n" 'gnus-summary-next-same-subject)
  5323.   (define-key gnus-summary-mode-map "\M-\C-p" 'gnus-summary-prev-same-subject)
  5324.   (define-key gnus-summary-mode-map "\M-n" 'gnus-summary-next-unread-subject)
  5325.   (define-key gnus-summary-mode-map "\M-p" 'gnus-summary-prev-unread-subject)
  5326.   (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article)
  5327.   (define-key gnus-summary-mode-map "," 'gnus-summary-best-unread-article)
  5328.   (define-key gnus-summary-mode-map 
  5329.     "\M-s" 'gnus-summary-search-article-forward)
  5330.   (define-key gnus-summary-mode-map 
  5331.     "\M-r" 'gnus-summary-search-article-backward)
  5332.   (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article)
  5333.   (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article)
  5334.   (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-subject)
  5335.   (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article)
  5336.   (define-key gnus-summary-mode-map "\M-^" 'gnus-summary-refer-article)
  5337.   (define-key gnus-summary-mode-map "u" 'gnus-summary-tick-article-forward)
  5338.   (define-key gnus-summary-mode-map "!" 'gnus-summary-tick-article-forward)
  5339.   (define-key gnus-summary-mode-map "U" 'gnus-summary-tick-article-backward)
  5340.   (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward)
  5341.   (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward)
  5342.   (define-key gnus-summary-mode-map "E" 'gnus-summary-mark-as-expirable)
  5343.   (define-key gnus-summary-mode-map "\M-u" 'gnus-summary-clear-mark-forward)
  5344.   (define-key gnus-summary-mode-map "\M-U" 'gnus-summary-clear-mark-backward)
  5345.   (define-key gnus-summary-mode-map 
  5346.     "k" 'gnus-summary-kill-same-subject-and-select)
  5347.   (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject)
  5348.   (define-key gnus-summary-mode-map "\M-\C-k" 'gnus-summary-kill-thread)
  5349.   (define-key gnus-summary-mode-map "\M-\C-l" 'gnus-summary-lower-thread)
  5350.   (define-key gnus-summary-mode-map "e" 'gnus-summary-edit-article)
  5351.   (define-key gnus-summary-mode-map "#" 'gnus-summary-mark-as-processable)
  5352.   (define-key gnus-summary-mode-map "\M-#" 'gnus-summary-unmark-as-processable)
  5353.   (define-key gnus-summary-mode-map "\M-\C-t" 'gnus-summary-toggle-threads)
  5354.   (define-key gnus-summary-mode-map "\M-\C-s" 'gnus-summary-show-thread)
  5355.   (define-key gnus-summary-mode-map "\M-\C-h" 'gnus-summary-hide-thread)
  5356.   (define-key gnus-summary-mode-map "\M-\C-f" 'gnus-summary-next-thread)
  5357.   (define-key gnus-summary-mode-map "\M-\C-b" 'gnus-summary-prev-thread)
  5358.   (define-key gnus-summary-mode-map "\M-\C-u" 'gnus-summary-up-thread)
  5359.   (define-key gnus-summary-mode-map "\M-\C-d" 'gnus-summary-down-thread)
  5360.   (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command)
  5361.   (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit)
  5362.   (define-key gnus-summary-mode-map "\C-w" 'gnus-summary-mark-region-as-read)
  5363.   (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation)
  5364.   (define-key gnus-summary-mode-map "?" 'gnus-summary-mark-as-dormant)
  5365.   (define-key gnus-summary-mode-map 
  5366.     "\C-c\M-\C-s" 'gnus-summary-show-all-expunged)
  5367.   (define-key gnus-summary-mode-map 
  5368.     "\C-c\C-s\C-n" 'gnus-summary-sort-by-number)
  5369.   (define-key gnus-summary-mode-map 
  5370.     "\C-c\C-s\C-a" 'gnus-summary-sort-by-author)
  5371.   (define-key gnus-summary-mode-map 
  5372.     "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject)
  5373.   (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date)
  5374.   (define-key gnus-summary-mode-map "\C-c\C-s\C-i" 'gnus-summary-sort-by-score)
  5375.   (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window)
  5376.   (define-key gnus-summary-mode-map 
  5377.     "\C-x\C-s" 'gnus-summary-reselect-current-group)
  5378.   (define-key gnus-summary-mode-map "\M-g" 'gnus-summary-rescan-group)
  5379.   (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking)
  5380.   (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message)
  5381.   (define-key gnus-summary-mode-map "\M-t" 'gnus-summary-toggle-mime)
  5382.   (define-key gnus-summary-mode-map "f" 'gnus-summary-followup)
  5383.   (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original)
  5384.   (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article)
  5385.   (define-key gnus-summary-mode-map "r" 'gnus-summary-reply)
  5386.   (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original)
  5387.   (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward)
  5388.   (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article)
  5389.   (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-article-mail)
  5390.   (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output)
  5391.   (define-key gnus-summary-mode-map "\M-k" 'gnus-summary-edit-local-kill)
  5392.   (define-key gnus-summary-mode-map "\M-K" 'gnus-summary-edit-global-kill)
  5393.   (define-key gnus-summary-mode-map "V" 'gnus-version)
  5394.   (define-key gnus-summary-mode-map "\C-c\C-d" 'gnus-summary-describe-group)
  5395.   (define-key gnus-summary-mode-map "q" 'gnus-summary-exit)
  5396.   (define-key gnus-summary-mode-map "Q" 'gnus-summary-exit-no-update)
  5397.   (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node)
  5398.   (define-key gnus-summary-mode-map gnus-mouse-2 'gnus-mouse-pick-article)
  5399.   (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window)
  5400.   (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news)
  5401.   (define-key gnus-summary-mode-map 
  5402.     "x" 'gnus-summary-remove-lines-marked-as-read)
  5403. ; (define-key gnus-summary-mode-map "X" 'gnus-summary-remove-lines-marked-with)
  5404.   (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article)
  5405.   (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header)
  5406.   (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article)
  5407. ;  (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly)
  5408.   (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article)
  5409.   (define-key gnus-summary-mode-map "\C-c\C-v\C-v" 'gnus-uu-decode-uu-view)
  5410.   (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-enter-digest-group)
  5411.   (define-key gnus-summary-mode-map "v" 'gnus-summary-verbose-headers)
  5412.   (define-key gnus-summary-mode-map "\C-c\C-b" 'gnus-bug)
  5413.  
  5414.  
  5415.   ;; Sort of orthogonal keymap
  5416.   (define-prefix-command 'gnus-summary-mark-map)
  5417.   (define-key gnus-summary-mode-map "M" 'gnus-summary-mark-map)
  5418.   (define-key gnus-summary-mark-map "t" 'gnus-summary-tick-article-forward)
  5419.   (define-key gnus-summary-mark-map "!" 'gnus-summary-tick-article-forward)
  5420.   (define-key gnus-summary-mark-map "d" 'gnus-summary-mark-as-read-forward)
  5421.   (define-key gnus-summary-mark-map "r" 'gnus-summary-mark-as-read-forward)
  5422.   (define-key gnus-summary-mark-map "c" 'gnus-summary-clear-mark-forward)
  5423.   (define-key gnus-summary-mark-map " " 'gnus-summary-clear-mark-forward)
  5424.   (define-key gnus-summary-mark-map "e" 'gnus-summary-mark-as-expirable)
  5425.   (define-key gnus-summary-mark-map "x" 'gnus-summary-mark-as-expirable)
  5426.   (define-key gnus-summary-mark-map "?" 'gnus-summary-mark-as-dormant)
  5427.   (define-key gnus-summary-mark-map "b" 'gnus-summary-set-bookmark)
  5428.   (define-key gnus-summary-mark-map "B" 'gnus-summary-remove-bookmark)
  5429.   (define-key gnus-summary-mark-map "#" 'gnus-summary-mark-as-processable)
  5430.   (define-key gnus-summary-mark-map "\M-#" 'gnus-summary-unmark-as-processable)
  5431.   (define-key gnus-summary-mark-map 
  5432.     "\M-r" 'gnus-summary-remove-lines-marked-as-read)
  5433.   (define-key gnus-summary-mark-map 
  5434.     "\M-\C-r" 'gnus-summary-remove-lines-marked-with)
  5435.   (define-key gnus-summary-mark-map "D" 'gnus-summary-show-all-dormant)
  5436.   (define-key gnus-summary-mark-map "\M-D" 'gnus-summary-hide-all-dormant)
  5437.   (define-key gnus-summary-mark-map "S" 'gnus-summary-show-all-expunged)
  5438.   (define-key gnus-summary-mark-map "C" 'gnus-summary-catchup)
  5439.   (define-key gnus-summary-mark-map "H" 'gnus-summary-catchup-to-here)
  5440.   (define-key gnus-summary-mark-map "\C-c" 'gnus-summary-catchup-all)
  5441.   (define-key gnus-summary-mark-map 
  5442.     "k" 'gnus-summary-kill-same-subject-and-select)
  5443.   (define-key gnus-summary-mark-map "K" 'gnus-summary-kill-same-subject)
  5444.  
  5445.   (define-prefix-command 'gnus-summary-mscore-map)
  5446.   (define-key gnus-summary-mark-map "V" 'gnus-summary-mscore-map)
  5447.   (define-key gnus-summary-mscore-map "c" 'gnus-summary-clear-above)
  5448.   (define-key gnus-summary-mscore-map "u" 'gnus-summary-tick-above)
  5449.   (define-key gnus-summary-mscore-map "m" 'gnus-summary-mark-above)
  5450.   (define-key gnus-summary-mscore-map "k" 'gnus-summary-kill-below)
  5451.  
  5452.   (define-key gnus-summary-mark-map "P" 'gnus-uu-mark-map)
  5453.   
  5454.   (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
  5455.   
  5456.   (define-prefix-command 'gnus-summary-goto-map)
  5457.   (define-key gnus-summary-mode-map "G" 'gnus-summary-goto-map)
  5458.   (define-key gnus-summary-goto-map "n" 'gnus-summary-next-unread-article)
  5459.   (define-key gnus-summary-goto-map "p" 'gnus-summary-prev-unread-article)
  5460.   (define-key gnus-summary-goto-map "N" 'gnus-summary-next-article)
  5461.   (define-key gnus-summary-goto-map "P" 'gnus-summary-prev-article)
  5462.   (define-key gnus-summary-goto-map "\C-n" 'gnus-summary-next-same-subject)
  5463.   (define-key gnus-summary-goto-map "\C-p" 'gnus-summary-prev-same-subject)
  5464.   (define-key gnus-summary-goto-map "\M-n" 'gnus-summary-next-unread-subject)
  5465.   (define-key gnus-summary-goto-map "\M-p" 'gnus-summary-prev-unread-subject)
  5466.   (define-key gnus-summary-goto-map "f" 'gnus-summary-first-unread-article)
  5467.   (define-key gnus-summary-goto-map "b" 'gnus-summary-best-unread-article)
  5468.   (define-key gnus-summary-goto-map "g" 'gnus-summary-goto-subject)
  5469.   (define-key gnus-summary-goto-map "l" 'gnus-summary-goto-last-article)
  5470.   (define-key gnus-summary-goto-map "p" 'gnus-summary-pop-article)
  5471.  
  5472.  
  5473.   (define-prefix-command 'gnus-summary-thread-map)
  5474.   (define-key gnus-summary-mode-map "T" 'gnus-summary-thread-map)
  5475.   (define-key gnus-summary-thread-map "k" 'gnus-summary-kill-thread)
  5476.   (define-key gnus-summary-thread-map "l" 'gnus-summary-lower-thread)
  5477.   (define-key gnus-summary-thread-map "i" 'gnus-summary-raise-thread)
  5478.   (define-key gnus-summary-thread-map "T" 'gnus-summary-toggle-threads)
  5479.   (define-key gnus-summary-thread-map "s" 'gnus-summary-show-thread)
  5480.   (define-key gnus-summary-thread-map "S" 'gnus-summary-show-all-threads)
  5481.   (define-key gnus-summary-thread-map "h" 'gnus-summary-hide-thread)
  5482.   (define-key gnus-summary-thread-map "H" 'gnus-summary-hide-all-threads)
  5483.   (define-key gnus-summary-thread-map "n" 'gnus-summary-next-thread)
  5484.   (define-key gnus-summary-thread-map "p" 'gnus-summary-prev-thread)
  5485.   (define-key gnus-summary-thread-map "u" 'gnus-summary-up-thread)
  5486.   (define-key gnus-summary-thread-map "d" 'gnus-summary-down-thread)
  5487.   (define-key gnus-summary-thread-map "#" 'gnus-uu-mark-thread)
  5488.  
  5489.   
  5490.   (define-prefix-command 'gnus-summary-exit-map)
  5491.   (define-key gnus-summary-mode-map "Z" 'gnus-summary-exit-map)
  5492.   (define-key gnus-summary-exit-map "c" 'gnus-summary-catchup-and-exit)
  5493.   (define-key gnus-summary-exit-map "C" 'gnus-summary-catchup-all-and-exit)
  5494.   (define-key gnus-summary-exit-map "E" 'gnus-summary-exit-no-update)
  5495.   (define-key gnus-summary-exit-map "Q" 'gnus-summary-exit)
  5496.   (define-key gnus-summary-exit-map "Z" 'gnus-summary-exit)
  5497.   (define-key gnus-summary-exit-map 
  5498.     "n" 'gnus-summary-catchup-and-goto-next-group)
  5499.   (define-key gnus-summary-exit-map "R" 'gnus-summary-reselect-current-group)
  5500.   (define-key gnus-summary-exit-map "G" 'gnus-summary-rescan-group)
  5501.   (define-key gnus-summary-exit-map "N" 'gnus-summary-next-group)
  5502.   (define-key gnus-summary-exit-map "P" 'gnus-summary-prev-group)
  5503.  
  5504.  
  5505.   (define-prefix-command 'gnus-summary-article-map)
  5506.   (define-key gnus-summary-mode-map "A" 'gnus-summary-article-map)
  5507.   (define-key gnus-summary-article-map " " 'gnus-summary-next-page)
  5508.   (define-key gnus-summary-article-map "n" 'gnus-summary-next-page)
  5509.   (define-key gnus-summary-article-map "\177" 'gnus-summary-prev-page)
  5510.   (define-key gnus-summary-article-map "p" 'gnus-summary-prev-page)
  5511.   (define-key gnus-summary-article-map "\r" 'gnus-summary-scroll-up)
  5512.   (define-key gnus-summary-article-map "<" 'gnus-summary-beginning-of-article)
  5513.   (define-key gnus-summary-article-map ">" 'gnus-summary-end-of-article)
  5514.   (define-key gnus-summary-article-map "b" 'gnus-summary-beginning-of-article)
  5515.   (define-key gnus-summary-article-map "e" 'gnus-summary-end-of-article)
  5516.   (define-key gnus-summary-article-map "^" 'gnus-summary-refer-parent-article)
  5517.   (define-key gnus-summary-article-map "r" 'gnus-summary-refer-parent-article)
  5518.   (define-key gnus-summary-article-map "g" 'gnus-summary-show-article)
  5519.   (define-key gnus-summary-article-map "s" 'gnus-summary-isearch-article)
  5520.  
  5521.  
  5522.  
  5523.   (define-prefix-command 'gnus-summary-wash-map)
  5524.   (define-key gnus-summary-mode-map "W" 'gnus-summary-wash-map)
  5525.  
  5526.   (define-prefix-command 'gnus-summary-wash-hide-map)
  5527.   (define-key gnus-summary-wash-map "W" 'gnus-summary-wash-hide-map)
  5528.   (define-key gnus-summary-wash-hide-map "a" 'gnus-article-hide)
  5529.   (define-key gnus-summary-wash-hide-map "h" 'gnus-article-hide-headers)
  5530.   (define-key gnus-summary-wash-hide-map "s" 'gnus-article-hide-signature)
  5531.   (define-key gnus-summary-wash-hide-map "c" 'gnus-article-hide-citation)
  5532.   (define-key gnus-summary-wash-hide-map 
  5533.     "\C-c" 'gnus-article-hide-citation-maybe)
  5534.  
  5535.   (define-prefix-command 'gnus-summary-wash-highlight-map)
  5536.   (define-key gnus-summary-wash-map "H" 'gnus-summary-wash-highlight-map)
  5537.   (define-key gnus-summary-wash-highlight-map "a" 'gnus-article-highlight)
  5538.   (define-key gnus-summary-wash-highlight-map 
  5539.     "h" 'gnus-article-highlight-headers)
  5540.   (define-key gnus-summary-wash-highlight-map
  5541.     "c" 'gnus-article-highlight-citation)
  5542.   (define-key gnus-summary-wash-highlight-map
  5543.     "s" 'gnus-article-highlight-signature)
  5544.  
  5545.   (define-prefix-command 'gnus-summary-wash-time-map)
  5546.   (define-key gnus-summary-wash-map "T" 'gnus-summary-wash-time-map)
  5547.   (define-key gnus-summary-wash-time-map "z" 'gnus-article-date-ut)
  5548.   (define-key gnus-summary-wash-time-map "u" 'gnus-article-date-ut)
  5549.   (define-key gnus-summary-wash-time-map "l" 'gnus-article-date-local)
  5550.   (define-key gnus-summary-wash-time-map "e" 'gnus-article-date-lapsed)
  5551.  
  5552.   (define-key gnus-summary-wash-map "b" 'gnus-article-add-buttons)
  5553.   (define-key gnus-summary-wash-map "o" 'gnus-article-treat-overstrike)
  5554.   (define-key gnus-summary-wash-map "w" 'gnus-article-word-wrap)
  5555.   (define-key gnus-summary-wash-map "c" 'gnus-article-remove-cr)
  5556.   (define-key gnus-summary-wash-map "q" 'gnus-article-de-quoted-unreadable)
  5557.   (define-key gnus-summary-wash-map "f" 'gnus-article-display-x-face)
  5558.   (define-key gnus-summary-wash-map "l" 'gnus-summary-stop-page-breaking)
  5559.   (define-key gnus-summary-wash-map "r" 'gnus-summary-caesar-message)
  5560.   (define-key gnus-summary-wash-map "t" 'gnus-summary-toggle-header)
  5561.   (define-key gnus-summary-wash-map "m" 'gnus-summary-toggle-mime)
  5562.  
  5563.  
  5564.   (define-prefix-command 'gnus-summary-help-map)
  5565.   (define-key gnus-summary-mode-map "H" 'gnus-summary-help-map)
  5566.   (define-key gnus-summary-help-map "v" 'gnus-version)
  5567.   (define-key gnus-summary-help-map "f" 'gnus-summary-fetch-faq)
  5568.   (define-key gnus-summary-help-map "d" 'gnus-summary-describe-group)
  5569.   (define-key gnus-summary-help-map "h" 'gnus-summary-describe-briefly)
  5570.   (define-key gnus-summary-help-map "i" 'gnus-info-find-node)
  5571.  
  5572.  
  5573.   (define-prefix-command 'gnus-summary-backend-map)
  5574.   (define-key gnus-summary-mode-map "B" 'gnus-summary-backend-map)
  5575.   (define-key gnus-summary-backend-map "e" 'gnus-summary-expire-articles)
  5576.   (define-key gnus-summary-backend-map "\M-\C-e" 
  5577.     'gnus-summary-expire-articles-now)
  5578.   (define-key gnus-summary-backend-map "\177" 'gnus-summary-delete-article)
  5579.   (define-key gnus-summary-backend-map "m" 'gnus-summary-move-article)
  5580.   (define-key gnus-summary-backend-map "r" 'gnus-summary-respool-article)
  5581.   (define-key gnus-summary-backend-map "w" 'gnus-summary-edit-article)
  5582.   (define-key gnus-summary-backend-map "c" 'gnus-summary-copy-article)
  5583.   (define-key gnus-summary-backend-map "q" 'gnus-summary-fancy-query)
  5584.   (define-key gnus-summary-backend-map "i" 'gnus-summary-import-article)
  5585.  
  5586.  
  5587.   (define-prefix-command 'gnus-summary-save-map)
  5588.   (define-key gnus-summary-mode-map "O" 'gnus-summary-save-map)
  5589.   (define-key gnus-summary-save-map "o" 'gnus-summary-save-article)
  5590.   (define-key gnus-summary-save-map "m" 'gnus-summary-save-article-mail)
  5591.   (define-key gnus-summary-save-map "r" 'gnus-summary-save-article-rmail)
  5592.   (define-key gnus-summary-save-map "f" 'gnus-summary-save-article-file)
  5593.   (define-key gnus-summary-save-map "h" 'gnus-summary-save-article-folder)
  5594.   (define-key gnus-summary-save-map "v" 'gnus-summary-save-article-vm)
  5595.   (define-key gnus-summary-save-map "p" 'gnus-summary-pipe-output)
  5596. ;  (define-key gnus-summary-save-map "s" 'gnus-soup-add-article)
  5597.  
  5598.   (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map)
  5599.  
  5600.   (define-key gnus-summary-mode-map "\M-&" 'gnus-summary-universal-argument)
  5601. ;  (define-key gnus-summary-various-map "\C-s" 'gnus-summary-search-article-forward)
  5602. ;  (define-key gnus-summary-various-map "\C-r" 'gnus-summary-search-article-backward)
  5603. ;  (define-key gnus-summary-various-map "r" 'gnus-summary-refer-article)
  5604. ;  (define-key gnus-summary-various-map "&" 'gnus-summary-execute-command)
  5605. ;  (define-key gnus-summary-various-map "T" 'gnus-summary-toggle-truncation)
  5606. ;  (define-key gnus-summary-various-map "e" 'gnus-summary-expand-window)
  5607.   (define-key gnus-summary-article-map "D" 'gnus-summary-enter-digest-group)
  5608. ;  (define-key gnus-summary-various-map "k" 'gnus-summary-edit-local-kill)
  5609. ;  (define-key gnus-summary-various-map "K" 'gnus-summary-edit-global-kill)
  5610.  
  5611.   (define-key gnus-summary-mode-map "V" 'gnus-summary-score-map)
  5612.  
  5613. ;  (define-prefix-command 'gnus-summary-sort-map)
  5614. ;  (define-key gnus-summary-various-map "s" 'gnus-summary-sort-map)
  5615. ;  (define-key gnus-summary-sort-map "n" 'gnus-summary-sort-by-number)
  5616. ;  (define-key gnus-summary-sort-map "a" 'gnus-summary-sort-by-author)
  5617. ;  (define-key gnus-summary-sort-map "s" 'gnus-summary-sort-by-subject)
  5618. ;  (define-key gnus-summary-sort-map "d" 'gnus-summary-sort-by-date)
  5619. ;  (define-key gnus-summary-sort-map "i" 'gnus-summary-sort-by-score)
  5620.  
  5621.   (define-key gnus-summary-mode-map "I" 'gnus-summary-increase-score)
  5622.   (define-key gnus-summary-mode-map "L" 'gnus-summary-lower-score)
  5623.   )
  5624.  
  5625.  
  5626.  
  5627.  
  5628. (defun gnus-summary-mode (&optional group)
  5629.   "Major mode for reading articles.
  5630.  
  5631. All normal editing commands are switched off.
  5632. \\<gnus-summary-mode-map>
  5633. Each line in this buffer represents one article.  To read an
  5634. article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
  5635. and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]', 
  5636. respectively.
  5637.  
  5638. You can also post articles and send mail from this buffer.  To 
  5639. follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author 
  5640. of an article, type `\\[gnus-summary-reply]'.
  5641.  
  5642. There are approx. one gazillion commands you can execute in this 
  5643. buffer; read the info pages for more information (`\\[gnus-info-find-node]'). 
  5644.  
  5645. The following commands are available:
  5646.  
  5647. \\{gnus-summary-mode-map}"
  5648.   (interactive)
  5649.   (if gnus-visual (gnus-summary-make-menu-bar))
  5650.   (kill-all-local-variables)
  5651.   (let ((locals gnus-summary-local-variables))
  5652.     (while locals
  5653.       (if (consp (car locals))
  5654.       (progn
  5655.         (make-local-variable (car (car locals)))
  5656.         (set (car (car locals)) (eval (cdr (car locals)))))
  5657.     (make-local-variable (car locals))
  5658.     (set (car locals) nil))
  5659.       (setq locals (cdr locals))))
  5660.   (gnus-make-thread-indent-array)
  5661.   (gnus-simplify-mode-line)
  5662.   (setq major-mode 'gnus-summary-mode)
  5663.   (setq mode-name "Summary")
  5664.   (make-local-variable 'minor-mode-alist)
  5665.   (use-local-map gnus-summary-mode-map)
  5666.   (buffer-disable-undo (current-buffer))
  5667.   (setq buffer-read-only t)        ;Disable modification
  5668.   (setq truncate-lines t)
  5669.   (setq selective-display t)
  5670.   (setq selective-display-ellipses t)    ;Display `...'
  5671.   (setq buffer-display-table gnus-summary-display-table)
  5672.   (setq gnus-newsgroup-name group)
  5673.   (run-hooks 'gnus-summary-mode-hook))
  5674.  
  5675. (defun gnus-summary-make-display-table ()
  5676.   ;; Change the display table.  Odd characters have a tendency to mess
  5677.   ;; up nicely formatted displays - we make all possible glyphs
  5678.   ;; display only a single character.
  5679.  
  5680.   ;; We start from the standard display table, if any.
  5681.   (setq gnus-summary-display-table 
  5682.     (or (copy-sequence standard-display-table)
  5683.         (make-display-table)))
  5684.   ;; Nix out all the control chars...
  5685.   (let ((i 32))
  5686.     (while (>= (setq i (1- i)) 0)
  5687.       (aset gnus-summary-display-table i [??])))
  5688.   ;; ... but not newline and cr, of course. (cr is necessary for the
  5689.   ;; selective display).  
  5690.   (aset gnus-summary-display-table ?\n nil)
  5691.   (aset gnus-summary-display-table ?\r nil)
  5692.   ;; We nix out any glyphs over 126 that are not set already.  
  5693.   (let ((i 256))
  5694.     (while (>= (setq i (1- i)) 127)
  5695.       ;; Only modify if the entry is nil.
  5696.       (or (aref gnus-summary-display-table i) 
  5697.       (aset gnus-summary-display-table i [??])))))
  5698.  
  5699. (defun gnus-summary-clear-local-variables ()
  5700.   (let ((locals gnus-summary-local-variables))
  5701.     (while locals
  5702.       (if (consp (car locals))
  5703.       (and (vectorp (car (car locals)))
  5704.            (set (car (car locals)) nil))
  5705.     (and (vectorp (car locals))
  5706.          (set (car locals) nil)))
  5707.       (setq locals (cdr locals)))))
  5708.  
  5709. ;; Some summary mode macros.
  5710.  
  5711. ;; Return a header specified by a NUMBER.
  5712. (defun gnus-get-header-by-number (number)
  5713.   (save-excursion
  5714.     (set-buffer gnus-summary-buffer)
  5715.     (or gnus-newsgroup-headers-hashtb-by-number
  5716.     (gnus-make-headers-hashtable-by-number))
  5717.     (gnus-gethash (int-to-string number)
  5718.           gnus-newsgroup-headers-hashtb-by-number)))
  5719.  
  5720. ;; Fast version of the function above.
  5721. (defmacro gnus-get-header-by-num (number)
  5722.   (` (gnus-gethash (int-to-string (, number)) 
  5723.            gnus-newsgroup-headers-hashtb-by-number)))
  5724.  
  5725. (defmacro gnus-summary-search-forward (&optional unread subject backward)
  5726.   "Search for article forward.
  5727. If UNREAD is non-nil, only unread articles are selected.
  5728. If SUBJECT is non-nil, the article which has the same subject will be
  5729. searched for. 
  5730. If BACKWARD is non-nil, the search will be performed backwards instead."
  5731.   (` (gnus-summary-search-subject (, backward) (, unread) (, subject))))
  5732.  
  5733. (defmacro gnus-summary-search-backward (&optional unread subject)
  5734.   "Search for article backward.
  5735. If 1st optional argument UNREAD is non-nil, only unread article is selected.
  5736. If 2nd optional argument SUBJECT is non-nil, the article which has
  5737. the same subject will be searched for."
  5738.   (` (gnus-summary-search-forward (, unread) (, subject) t)))
  5739.  
  5740. (defmacro gnus-summary-article-number (&optional number-or-nil)
  5741.   "The article number of the article on the current line.
  5742. If there isn's an article number here, then we return the current
  5743. article number."
  5744.   (if number-or-nil
  5745.       '(get-text-property (gnus-point-at-bol) 'gnus-number)
  5746.     '(or (get-text-property (gnus-point-at-bol) 'gnus-number) 
  5747.      gnus-current-article)))
  5748.  
  5749. (defmacro gnus-summary-thread-level ()
  5750.   "The thread level of the article on the current line."
  5751.   '(or (get-text-property (gnus-point-at-bol) 'gnus-level)
  5752.        0))
  5753.  
  5754. (defmacro gnus-summary-article-mark ()
  5755.   "The mark on the current line."
  5756.   '(get-text-property (gnus-point-at-bol) 'gnus-mark))
  5757.  
  5758. (defun gnus-summary-subject-string ()
  5759.   "Return current subject string or nil if nothing."
  5760.   (let ((article (gnus-summary-article-number))
  5761.     header)
  5762.     (and article 
  5763.      (setq header (gnus-get-header-by-num article))
  5764.      (vectorp header)
  5765.      (mail-header-subject header))))
  5766.  
  5767. ;; Various summary mode internalish functions.
  5768.  
  5769. (defun gnus-mouse-pick-article (e)
  5770.   (interactive "e")
  5771.   (mouse-set-point e)
  5772.   (gnus-summary-next-page nil t))
  5773.  
  5774. (defun gnus-summary-setup-buffer (group)
  5775.   "Initialize summary buffer."
  5776.   (let ((buffer (concat "*Summary " group "*")))
  5777.     (if (get-buffer buffer)
  5778.     (progn
  5779.       (set-buffer buffer)
  5780.       (not gnus-newsgroup-begin))
  5781.       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
  5782.       (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
  5783.       (gnus-add-current-to-buffer-list)
  5784.       (gnus-summary-mode group)
  5785.       (and gnus-carpal (gnus-carpal-setup-buffer 'summary))
  5786.       (setq gnus-newsgroup-name group)
  5787.       t)))
  5788.  
  5789. (defun gnus-set-global-variables ()
  5790.   ;; Set the global equivalents of the summary buffer-local variables
  5791.   ;; to the latest values they had. These reflect the summary buffer
  5792.   ;; that was in action when the last article was fetched.
  5793.   (if (eq major-mode 'gnus-summary-mode) 
  5794.       (progn
  5795.     (setq gnus-summary-buffer (current-buffer))
  5796.     (let ((name gnus-newsgroup-name)
  5797.           (marked gnus-newsgroup-marked)
  5798.           (unread gnus-newsgroup-unreads)
  5799.           (headers gnus-current-headers)
  5800.           (score-file gnus-current-score-file))
  5801.       (save-excursion
  5802.         (set-buffer gnus-group-buffer)
  5803.         (setq gnus-newsgroup-name name)
  5804.         (setq gnus-newsgroup-marked marked)
  5805.         (setq gnus-newsgroup-unreads unread)
  5806.         (setq gnus-current-headers headers)
  5807.         (setq gnus-current-score-file score-file))))))
  5808.  
  5809. (defun gnus-summary-insert-dummy-line (sformat subject number)
  5810.   (if (not sformat) 
  5811.       (setq sformat gnus-summary-dummy-line-format-spec))
  5812.   (let (b)
  5813.     (beginning-of-line)
  5814.     (setq b (point))
  5815.     (insert (eval sformat))
  5816.     (add-text-properties
  5817.      b (1+ b)
  5818.      (list 'gnus-number number 
  5819.        'gnus-mark gnus-dummy-mark
  5820.        'gnus-level 0))))
  5821.  
  5822. (defvar gnus-thread-indent-array nil)
  5823. (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
  5824. (defun gnus-make-thread-indent-array ()
  5825.   (let ((n 200))
  5826.     (if (and gnus-thread-indent-array
  5827.          (= gnus-thread-indent-level gnus-thread-indent-array-level))
  5828.     nil
  5829.       (setq gnus-thread-indent-array (make-vector 201 "")
  5830.         gnus-thread-indent-array-level gnus-thread-indent-level)
  5831.       (while (>= n 0)
  5832.     (aset gnus-thread-indent-array n
  5833.           (make-string (* n gnus-thread-indent-level) ? ))
  5834.     (setq n (1- n))))))
  5835.  
  5836. (defun gnus-summary-insert-line 
  5837.   (sformat header level current unread replied expirable subject-or-nil
  5838.        &optional dummy score process)
  5839.   (or sformat (setq sformat gnus-summary-line-format-spec))
  5840.   (let* ((indentation (aref gnus-thread-indent-array level))
  5841.      (lines (mail-header-lines header))
  5842.      (score (or score gnus-summary-default-score 0))
  5843.      (score-char
  5844.       (if (or (null gnus-summary-default-score)
  5845.           (<= (abs (- score gnus-summary-default-score))
  5846.               gnus-summary-zcore-fuzz)) ? 
  5847.         (if (< score gnus-summary-default-score)
  5848.         gnus-score-below-mark gnus-score-over-mark)))
  5849.      (replied (cond (process gnus-process-mark)
  5850.             (replied gnus-replied-mark)
  5851.             (t gnus-unread-mark)))
  5852.      (from (mail-header-from header))
  5853.      (name (cond 
  5854.         ((string-match "(.+)" from)
  5855.          (substring from (1+ (match-beginning 0)) (1- (match-end 0))))
  5856.         ((string-match "<[^>]+> *$" from)
  5857.          (let ((beg (match-beginning 0)))
  5858.            (or (and (string-match "^\"[^\"]*\"" from)
  5859.                 (substring from (1+ (match-beginning 0))
  5860.                        (1- (match-end 0))))
  5861.                (substring from 0 beg))))
  5862.         (t from)))
  5863.      (subject (mail-header-subject header))
  5864.      (number (mail-header-number header))
  5865.      (opening-bracket (if dummy ?\< ?\[))
  5866.      (closing-bracket (if dummy ?\> ?\]))
  5867.      (buffer-read-only nil)
  5868.      (b (progn (beginning-of-line) (point))))
  5869.     (or (numberp lines) (setq lines 0))
  5870.     (insert (eval sformat))
  5871.     (add-text-properties
  5872.      b (1+ b) (list 'gnus-number number 
  5873.             'gnus-mark (or unread gnus-unread-mark)
  5874.             'gnus-level level))))
  5875.  
  5876. (defun gnus-summary-update-line (&optional dont-update)
  5877.   ;; Update summary line after change.
  5878.   (or (not gnus-summary-default-score)
  5879.       gnus-summary-inhibit-highlight
  5880.       (let ((gnus-summary-inhibit-highlight t)
  5881.         (article (gnus-summary-article-number)))
  5882.     (progn
  5883.       (or dont-update
  5884.           (if (and gnus-summary-mark-below
  5885.                (< (gnus-summary-article-score)
  5886.               gnus-summary-mark-below))
  5887.           (and (not (memq article gnus-newsgroup-marked))
  5888.                (not (memq article gnus-newsgroup-dormant))
  5889.                (memq article gnus-newsgroup-unreads)
  5890.                (gnus-summary-mark-article-as-read gnus-low-score-mark))
  5891.         (and (eq (gnus-summary-article-mark) gnus-low-score-mark)
  5892.              (gnus-summary-mark-article-as-unread gnus-unread-mark))))
  5893.       (and gnus-visual
  5894.            (run-hooks 'gnus-summary-update-hook))))))
  5895.  
  5896. (defun gnus-summary-update-lines (&optional beg end)
  5897.   ;; Mark article as read (or not) by taking into account scores.
  5898.   (let ((beg (or beg (point-min)))
  5899.     (end (or end (point-max))))
  5900.     (if (or (not gnus-summary-default-score)
  5901.         gnus-summary-inhibit-highlight)
  5902.     ()
  5903.       (let ((gnus-summary-inhibit-highlight t)
  5904.         article)
  5905.     (save-excursion
  5906.       (set-buffer gnus-summary-buffer)
  5907.       (goto-char beg)
  5908.       (beginning-of-line)
  5909.       (while (and (not (eobp)) (< (point) end))
  5910.         (if (and gnus-summary-mark-below
  5911.              (< (or (cdr (assq 
  5912.                   (setq article (get-text-property 
  5913.                          (point) 'gnus-number))
  5914.                   gnus-newsgroup-scored))
  5915.                 gnus-summary-default-score 0)
  5916.             gnus-summary-mark-below))
  5917.         ;; We want to possibly mark it as read...
  5918.         (and (not (memq article gnus-newsgroup-marked))
  5919.              (not (memq article gnus-newsgroup-dormant))
  5920.              (memq article gnus-newsgroup-unreads)
  5921.              (gnus-summary-mark-article-as-read gnus-low-score-mark))
  5922.           ;; We want to possibly mark it as unread.
  5923.           (and (eq (get-text-property (point) 'gnus-mark)
  5924.                gnus-low-score-mark)
  5925.            (gnus-summary-mark-article-as-unread gnus-unread-mark)))
  5926.         ;; Do the visual highlights at the same time.
  5927.         (and gnus-visual (run-hooks 'gnus-summary-update-hook))
  5928.         (forward-line 1)))))))
  5929.  
  5930. (defvar gnus-tmp-gathered nil)
  5931.  
  5932. (defun gnus-summary-number-of-articles-in-thread (thread &optional char)
  5933.   ;; Sum up all elements (and sub-elements) in a list.
  5934.   (let* ((number
  5935.       ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
  5936.       (if (and (consp thread) (cdr thread))
  5937.           (apply
  5938.            '+ 1 (mapcar
  5939.              'gnus-summary-number-of-articles-in-thread 
  5940.              (cdr thread)))
  5941.         1)))
  5942.     (if char 
  5943.     (if (> number 1) gnus-not-empty-thread-mark
  5944.       gnus-empty-thread-mark)
  5945.       number)))
  5946.  
  5947. (defun gnus-summary-read-group 
  5948.   (group &optional show-all no-article kill-buffer)
  5949.   "Start reading news in newsgroup GROUP.
  5950. If SHOW-ALL is non-nil, already read articles are also listed.
  5951. If NO-ARTICLE is non-nil, no article is selected initially."
  5952.   (gnus-message 5 "Retrieving newsgroup: %s..." group)
  5953.   (let* ((new-group (gnus-summary-setup-buffer group))
  5954.      (quit-config (gnus-group-quit-config group))
  5955.      (did-select (and new-group (gnus-select-newsgroup group show-all))))
  5956.     (cond 
  5957.      ((not new-group)
  5958.       (gnus-set-global-variables)
  5959.       (gnus-kill-buffer kill-buffer)
  5960.       (gnus-configure-windows 'summary 'force)
  5961.       (gnus-set-mode-line 'summary)
  5962.       (gnus-summary-position-cursor)
  5963.       (message "")
  5964.       t)
  5965.      ((null did-select) 
  5966.       (and (eq major-mode 'gnus-summary-mode)
  5967.        (not (equal (current-buffer) kill-buffer))
  5968.        (progn
  5969.          (kill-buffer (current-buffer))
  5970.          (if (not quit-config)
  5971.          (progn
  5972.            (set-buffer gnus-group-buffer)
  5973.            (gnus-group-jump-to-group group)
  5974.            (gnus-group-next-unread-group 1))
  5975.            (if (not (buffer-name (car quit-config)))
  5976.            (gnus-configure-windows 'group 'force)
  5977.          (set-buffer (car quit-config))
  5978.          (and (eq major-mode 'gnus-summary-mode)
  5979.               (gnus-set-global-variables))
  5980.          (gnus-configure-windows (cdr quit-config))))))
  5981.       (message "Can't select group")
  5982.       nil)
  5983.      ((eq did-select 'quit)
  5984.       (and (eq major-mode 'gnus-summary-mode)
  5985.        (not (equal (current-buffer) kill-buffer))
  5986.        (kill-buffer (current-buffer)))
  5987.       (gnus-kill-buffer kill-buffer)
  5988.       (if (not quit-config)
  5989.       (progn
  5990.         (set-buffer gnus-group-buffer)
  5991.         (gnus-group-jump-to-group group)
  5992.         (gnus-group-next-unread-group 1)
  5993.         (gnus-configure-windows 'group 'force))
  5994.     (if (not (buffer-name (car quit-config)))
  5995.         (gnus-configure-windows 'group 'force)
  5996.       (set-buffer (car quit-config))
  5997.       (and (eq major-mode 'gnus-summary-mode)
  5998.            (gnus-set-global-variables))
  5999.       (gnus-configure-windows (cdr quit-config))))
  6000.       (signal 'quit nil))
  6001.      (t
  6002.       (gnus-set-global-variables)
  6003.       ;; Save the active value in effect when the group was entered.
  6004.       (setq gnus-newsgroup-active 
  6005.         (gnus-copy-sequence
  6006.          (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
  6007.       ;; You can change the subjects in this hook.
  6008.       (run-hooks 'gnus-select-group-hook)
  6009.       ;; Do score processing.
  6010.       (and gnus-use-scoring (gnus-possibly-score-headers))
  6011.       (gnus-update-format-specifications)
  6012.       ;; Generate the summary buffer.
  6013.       (gnus-summary-prepare)
  6014.       (if (zerop (buffer-size))
  6015.       (cond (gnus-newsgroup-dormant
  6016.          (gnus-summary-show-all-dormant))
  6017.         ((and gnus-newsgroup-scored show-all)
  6018.          (gnus-summary-show-all-expunged))))
  6019.       ;; Function `gnus-apply-kill-file' must be called in this hook.
  6020.       (run-hooks 'gnus-apply-kill-hook)
  6021.       (if (zerop (buffer-size))
  6022.       (progn
  6023.         ;; This newsgroup is empty.
  6024.         (gnus-summary-catchup-and-exit nil t) ;Without confirmations.
  6025.         (gnus-message 6 "No unread news")
  6026.         (gnus-kill-buffer kill-buffer)
  6027.         nil)
  6028.     ;;(save-excursion
  6029.     ;;  (if kill-buffer
  6030.     ;;      (let ((gnus-summary-buffer kill-buffer))
  6031.     ;;    (gnus-configure-windows 'group))))
  6032.     ;; Hide conversation thread subtrees.  We cannot do this in
  6033.     ;; gnus-summary-prepare-hook since kill processing may not
  6034.     ;; work with hidden articles.
  6035.     (and gnus-show-threads
  6036.          gnus-thread-hide-subtree
  6037.          (gnus-summary-hide-all-threads))
  6038.     ;; Show first unread article if requested.
  6039.     (goto-char (point-min))
  6040.     (if (and (not no-article)
  6041.          gnus-auto-select-first
  6042.          (gnus-summary-first-unread-article))
  6043.         ()
  6044.       (gnus-configure-windows 'summary 'force))
  6045.     (gnus-set-mode-line 'summary)
  6046.     (gnus-summary-position-cursor)
  6047.     ;; If in async mode, we send some info to the backend.
  6048.     (and gnus-newsgroup-async
  6049.          (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
  6050.          (gnus-request-asynchronous 
  6051.           gnus-newsgroup-name
  6052.           (if (and gnus-asynchronous-article-function
  6053.                (fboundp gnus-asynchronous-article-function))
  6054.           (funcall gnus-asynchronous-article-function
  6055.                gnus-newsgroup-threads)
  6056.         gnus-newsgroup-threads)))
  6057.     (gnus-kill-buffer kill-buffer)
  6058.     (if (not (get-buffer-window gnus-group-buffer))
  6059.         ()
  6060.       ;; gotta use windows, because recenter does weird stuff if
  6061.       ;; the current buffer ain't the displayed window.
  6062.        (let ((owin (selected-window))) 
  6063.          (select-window (get-buffer-window gnus-group-buffer))
  6064.           (and (gnus-group-goto-group group)
  6065.            (recenter))
  6066.          (select-window owin))))
  6067.       t))))
  6068.  
  6069. (defun gnus-summary-prepare ()
  6070.   ;; Generate the summary buffer.
  6071.   (let ((buffer-read-only nil))
  6072.     (erase-buffer)
  6073.     (gnus-summary-prepare-threads 
  6074.      (if gnus-show-threads
  6075.      (gnus-gather-threads 
  6076.       (gnus-sort-threads 
  6077.        (if (and gnus-summary-expunge-below
  6078.             (not gnus-fetch-old-headers))
  6079.            (gnus-make-threads-and-expunge)
  6080.          (gnus-make-threads))))
  6081.        gnus-newsgroup-headers)
  6082.      'cull)
  6083.     (gnus-summary-update-lines)
  6084.     ;; Create the header hashtb.
  6085.     (gnus-make-headers-hashtable-by-number)
  6086.     ;; Call hooks for modifying summary buffer.
  6087.     ;; Suggested by sven@tde.LTH.Se (Sven Mattisson).
  6088.     (goto-char (point-min))
  6089.     (run-hooks 'gnus-summary-prepare-hook)))
  6090.  
  6091. (defun gnus-gather-threads (threads)
  6092.   "Gather threads that have lost their roots."
  6093.   (if (not gnus-summary-make-false-root)
  6094.       threads 
  6095.     (let ((hashtb (gnus-make-hashtable 1023))
  6096.       (prev threads)
  6097.       (result threads)
  6098.       subject hthread whole-subject)
  6099.       (while threads
  6100.     (setq whole-subject 
  6101.           (setq subject (mail-header-subject (car (car threads)))))
  6102.     (if gnus-summary-gather-subject-limit
  6103.         (or (and (numberp gnus-summary-gather-subject-limit)
  6104.              (> (length subject) gnus-summary-gather-subject-limit)
  6105.              (setq subject
  6106.                (substring subject 0 
  6107.                       gnus-summary-gather-subject-limit)))
  6108.         (and (eq 'fuzzy gnus-summary-gather-subject-limit)
  6109.              (setq subject (gnus-simplify-subject-fuzzy subject))))
  6110.       (setq subject (gnus-simplify-subject-re subject)))
  6111.     (if (setq hthread 
  6112.           (gnus-gethash subject hashtb))
  6113.         (progn
  6114.           (or (stringp (car (car hthread)))
  6115.           (setcar hthread (list whole-subject (car hthread))))
  6116.           (setcdr (car hthread) (nconc (cdr (car hthread)) 
  6117.                        (list (car threads))))
  6118.           (setcdr prev (cdr threads))
  6119.           (setq threads prev))
  6120.       (gnus-sethash subject threads hashtb))
  6121.     (setq prev threads)
  6122.     (setq threads (cdr threads)))
  6123.       result)))
  6124.  
  6125. (defun gnus-make-threads ()
  6126.   ;; This function takes the dependencies already made by 
  6127.   ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
  6128.   ;; through the dependencies in the hash table and finds all the
  6129.   ;; roots. Roots do not refer back to any valid articles.
  6130.   (gnus-message 6 "Threading...")
  6131.   (let (roots new-roots)
  6132.     (and gnus-fetch-old-headers
  6133.      (eq gnus-headers-retrieved-by 'nov)
  6134.      (gnus-build-old-threads))
  6135.     (mapatoms
  6136.      (lambda (refs)
  6137.        (if (not (car (symbol-value refs)))
  6138.        (setq roots (append (cdr (symbol-value refs)) roots))
  6139.      ;; Ok, these refer back to valid articles, but if
  6140.      ;; `gnus-thread-ignore-subject' is nil, we have to check that
  6141.      ;; the root has the same subject as its children. The children
  6142.      ;; that do not are made into roots and removed from the list
  6143.      ;; of children. 
  6144.      (or gnus-thread-ignore-subject
  6145.          (let* ((prev (symbol-value refs))
  6146.             (subject (gnus-simplify-subject-re 
  6147.                   (mail-header-subject (car prev))))
  6148.             (headers (cdr prev)))
  6149.            (while headers
  6150.          (if (not (string= subject
  6151.                    (gnus-simplify-subject-re 
  6152.                     (mail-header-subject (car headers)))))
  6153.              (progn
  6154.                (setq new-roots (cons (car headers) new-roots))
  6155.                (setcdr prev (cdr headers)))
  6156.            (setq prev headers))
  6157.          (setq headers (cdr headers)))))))
  6158.      gnus-newsgroup-dependencies)
  6159.  
  6160.     ;; We enter the new roots into the dependencies structure to
  6161.     ;; ensure that any possible later thread-regeneration will be
  6162.     ;; possible. 
  6163.     (let ((r new-roots))
  6164.       (while r
  6165.     (gnus-sethash (concat (mail-header-id (car r)) ".boo")
  6166.               (list nil (car r)) gnus-newsgroup-dependencies)
  6167.     (setq r (cdr r))))
  6168.  
  6169.     (setq roots (nconc new-roots roots))
  6170.  
  6171.     (prog1
  6172.     (mapcar 'gnus-trim-thread
  6173.         (apply 'append
  6174.                (mapcar 'gnus-cut-thread
  6175.                    (mapcar 'gnus-make-sub-thread roots))))
  6176.       (gnus-message 6 "Threading...done"))))
  6177.  
  6178.   
  6179. (defun gnus-make-threads-and-expunge ()
  6180.   ;; This function takes the dependencies already made by 
  6181.   ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
  6182.   ;; through the dependencies in the hash table and finds all the
  6183.   ;; roots. Roots do not refer back to any valid articles.
  6184.   (gnus-message 6 "Threading...")
  6185.   (let ((default (or gnus-summary-default-score 0))
  6186.     (below gnus-summary-expunge-below)
  6187.     roots article new-roots)
  6188.     (and gnus-fetch-old-headers
  6189.      (eq gnus-headers-retrieved-by 'nov)
  6190.      (gnus-build-old-threads))
  6191.     (mapatoms
  6192.      (lambda (refs)
  6193.        (if (not (car (symbol-value refs)))
  6194.        ;; These articles do not refer back to any other articles -
  6195.        ;; they are roots.
  6196.        (let ((headers (cdr (symbol-value refs))))
  6197.          ;; We weed out the low-scored articles.
  6198.          (while headers
  6199.            (if (not (< (or (cdr (assq (mail-header-number (car headers))
  6200.                       gnus-newsgroup-scored)) default)
  6201.                below))
  6202.            ;; It is over.
  6203.            (setq roots (cons (car headers) roots))
  6204.          ;; It is below, so we mark it as read.
  6205.          (setq gnus-newsgroup-unreads
  6206.                (delq (mail-header-number (car headers))
  6207.                  gnus-newsgroup-unreads))
  6208.          (setq gnus-newsgroup-reads 
  6209.                (cons (cons (mail-header-number (car headers))
  6210.                    gnus-low-score-mark) 
  6211.                  gnus-newsgroup-reads)))
  6212.            (setq headers (cdr headers))))
  6213.      ;; Ok, these refer back to valid articles, but if
  6214.      ;; `gnus-thread-ignore-subject' is nil, we have to check that
  6215.      ;; the root has the same subject as its children. The children
  6216.      ;; that do not are made into roots and removed from the list
  6217.      ;; of children. 
  6218.      (or gnus-thread-ignore-subject
  6219.          (let* ((prev (symbol-value refs))
  6220.             (subject (gnus-simplify-subject-re 
  6221.                   (mail-header-subject (car prev))))
  6222.             (headers (cdr prev)))
  6223.            (while headers
  6224.          (if (not (string= subject
  6225.                    (gnus-simplify-subject-re 
  6226.                     (mail-header-subject (car headers)))))
  6227.              (progn
  6228.                (if (not (< (or (cdr (assq (mail-header-number
  6229.                            (car headers))
  6230.                           gnus-newsgroup-scored))
  6231.                        default) below))
  6232.                (setq new-roots (cons (car headers) new-roots))
  6233.              (setq gnus-newsgroup-unreads
  6234.                    (delq (mail-header-number (car headers))
  6235.                      gnus-newsgroup-unreads))
  6236.              (setq gnus-newsgroup-reads
  6237.                    (cons (cons (mail-header-number (car headers)) 
  6238.                        gnus-low-score-mark) 
  6239.                      gnus-newsgroup-reads)))
  6240.                (setcdr prev (cdr headers)))
  6241.            (setq prev headers))
  6242.          (setq headers (cdr headers)))))
  6243.      ;; If this article is expunged, some of the children might be
  6244.      ;; roots.  
  6245.      (if (< (or (cdr (assq (mail-header-number (car (symbol-value refs)))
  6246.                    gnus-newsgroup-scored)) default)
  6247.         below)
  6248.          (let* ((prev (symbol-value refs))
  6249.             (headers (cdr prev)))
  6250.            (while headers
  6251.          (setq article (mail-header-number (car headers)))
  6252.          (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
  6253.                  default) below))
  6254.              (progn (setq new-roots (cons (car headers) new-roots))
  6255.                 (setq prev headers))
  6256.            (setq gnus-newsgroup-unreads 
  6257.              (delq article gnus-newsgroup-unreads))
  6258.            (setq gnus-newsgroup-reads 
  6259.              (cons (cons article gnus-low-score-mark) 
  6260.                    gnus-newsgroup-reads))
  6261.            (setcdr prev (cdr headers)))
  6262.          (setq headers (cdr headers))))
  6263.        ;; It was not expunged, but we look at expunged children.
  6264.        (let* ((prev (symbol-value refs))
  6265.           (headers (cdr prev))
  6266.           article)
  6267.          (while headers
  6268.            (setq article (mail-header-number (car headers)))
  6269.            (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
  6270.                    default) below))
  6271.            (setq prev headers)
  6272.          (setq gnus-newsgroup-unreads 
  6273.                (delq article gnus-newsgroup-unreads))
  6274.          (setq gnus-newsgroup-reads 
  6275.                (cons (cons article gnus-low-score-mark)
  6276.                  gnus-newsgroup-reads))
  6277.          (setcdr prev (cdr headers)))
  6278.            (setq headers (cdr headers)))))))
  6279.      gnus-newsgroup-dependencies)
  6280.  
  6281.     ;; We enter the new roots into the dependencies structure to
  6282.     ;; ensure that any possible later thread-regeneration will be
  6283.     ;; possible. 
  6284.     (let ((r new-roots))
  6285.       (while r
  6286.     (gnus-sethash (concat (mail-header-id (car r)) ".boo")
  6287.               (list nil (car r)) gnus-newsgroup-dependencies)
  6288.     (setq r (cdr r))))
  6289.  
  6290.     (setq roots (nconc new-roots roots))
  6291.  
  6292.     (prog1
  6293.     (mapcar 'gnus-trim-thread
  6294.         (apply 'append
  6295.                (mapcar 'gnus-cut-thread
  6296.                    (mapcar 'gnus-make-sub-thread roots))))
  6297.       (gnus-message 6 "Threading...done"))))
  6298.  
  6299.   
  6300. (defun gnus-cut-thread (thread)
  6301.   ;; Remove leaf dormant or ancient articles from THREAD.
  6302.   (let ((head (car thread))
  6303.     (tail (apply 'append (mapcar 'gnus-cut-thread (cdr thread)))))
  6304.     (if (and (null tail)
  6305.          (let ((number (mail-header-number head)))
  6306.            (or (memq number gnus-newsgroup-ancient)
  6307.            (memq number gnus-newsgroup-dormant)
  6308.            (and gnus-summary-expunge-below
  6309.             (eq gnus-fetch-old-headers 'some)
  6310.             (< (or (cdr (assq number gnus-newsgroup-scored))
  6311.                    gnus-summary-default-score 0)
  6312.                gnus-summary-expunge-below)
  6313.             (progn
  6314.               (setq gnus-newsgroup-unreads
  6315.                 (delq number gnus-newsgroup-unreads))
  6316.               (setq gnus-newsgroup-reads
  6317.                 (cons (cons number gnus-low-score-mark)
  6318.                       gnus-newsgroup-reads))
  6319.               t)))))
  6320.     nil
  6321.       (list (cons head tail)))))
  6322.  
  6323. (defun gnus-trim-thread (thread)
  6324.   ;; Remove root ancient articles with only one child from THREAD.
  6325.   (if (and (eq gnus-fetch-old-headers 'some)
  6326.        (memq (mail-header-number (car thread)) gnus-newsgroup-ancient)
  6327.        (= (length thread) 2))
  6328.       (gnus-trim-thread (nth 1 thread))
  6329.     thread))
  6330.  
  6331. (defun gnus-make-sub-thread (root)
  6332.   ;; This function makes a sub-tree for a node in the tree.
  6333.   (let ((children (reverse (cdr (gnus-gethash (downcase (mail-header-id root))
  6334.                           gnus-newsgroup-dependencies)))))
  6335.     (cons root (mapcar 'gnus-make-sub-thread children))))
  6336.  
  6337. (defun gnus-build-old-threads ()
  6338.   ;; Look at all the articles that refer back to old articles, and
  6339.   ;; fetch the headers for the articles that aren't there. This will
  6340.   ;; build complete threads - if the roots haven't been expired by the
  6341.   ;; server, that is.
  6342.   (let (id heads)
  6343.     (mapatoms
  6344.      (lambda (refs)
  6345.        (if (not (car (symbol-value refs)))
  6346.        (progn
  6347.          (setq heads (cdr (symbol-value refs)))
  6348.          (while heads
  6349.            (if (not (memq (mail-header-number (car heads))
  6350.                   gnus-newsgroup-dormant))
  6351.            (progn
  6352.              (setq id (symbol-name refs))
  6353.              (while (and (setq id (gnus-build-get-header id))
  6354.                  (not (car (gnus-gethash 
  6355.                         id gnus-newsgroup-dependencies)))))
  6356.              (setq heads nil))
  6357.          (setq heads (cdr heads)))))))
  6358.      gnus-newsgroup-dependencies)))
  6359.  
  6360. (defun gnus-build-get-header (id)
  6361.   ;; Look through the buffer of NOV lines and find the header to
  6362.   ;; ID. Enter this line into the dependencies hash table, and return
  6363.   ;; the id of the parent article (if any).
  6364.   (let ((deps gnus-newsgroup-dependencies)
  6365.     found header)
  6366.     (prog1
  6367.     (save-excursion
  6368.       (set-buffer nntp-server-buffer)
  6369.       (goto-char (point-min))
  6370.       (while (and (not found) (search-forward id nil t))
  6371.         (beginning-of-line)
  6372.         (setq found (looking-at 
  6373.              (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
  6374.                  (regexp-quote id))))
  6375.         (or found (beginning-of-line 2)))
  6376.       (if found
  6377.           (let (ref)
  6378.         (beginning-of-line)
  6379.         (and
  6380.          (setq header (gnus-nov-parse-line 
  6381.                    (read (current-buffer)) deps))
  6382.          (setq ref (mail-header-references header))
  6383.          (string-match "\\(<[^>]+>\\) *$" ref)
  6384.          (substring ref (match-beginning 1) (match-end 1))))))
  6385.       (and header
  6386.        (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers)
  6387.          gnus-newsgroup-ancient (cons (mail-header-number header)
  6388.                           gnus-newsgroup-ancient))))))
  6389.  
  6390. ;; Re-build the thread containing ID.
  6391. (defun gnus-rebuild-thread (id)
  6392.   (let ((dep gnus-newsgroup-dependencies)
  6393.     (buffer-read-only nil)
  6394.     parent headers refs thread art)
  6395.     (while (and id (setq headers
  6396.              (car (setq art (gnus-gethash (downcase id) dep)))))
  6397.       (setq parent art)
  6398.       (setq id (and (setq refs (mail-header-references headers))
  6399.             (string-match "\\(<[^>]+>\\) *$" refs)
  6400.             (substring refs (match-beginning 1) (match-end 1)))))
  6401.     (setq thread (gnus-make-sub-thread (car parent)))
  6402.     (gnus-rebuild-remove-articles thread)
  6403.     (let ((beg (point)))
  6404.       (gnus-summary-prepare-threads (list thread))
  6405.       (gnus-summary-update-lines beg (point)))))
  6406.  
  6407. ;; Delete all lines in the summary buffer that correspond to articles
  6408. ;; in this thread.
  6409. (defun gnus-rebuild-remove-articles (thread)
  6410.   (and (gnus-summary-goto-subject (mail-header-number (car thread)))
  6411.        (gnus-delete-line))
  6412.   (mapcar (lambda (th) (gnus-rebuild-remove-articles th)) (cdr thread)))
  6413.  
  6414. (defun gnus-sort-threads (threads)
  6415.   ;; Sort threads as specified in `gnus-thread-sort-functions'.
  6416.   (let ((fun gnus-thread-sort-functions))
  6417.     (while fun
  6418.       (gnus-message 6 "Sorting with %S..." fun)
  6419.       (setq threads (sort threads (car fun))
  6420.         fun (cdr fun))))
  6421.   (if gnus-thread-sort-functions
  6422.       (gnus-message 6 "Sorting...done"))
  6423.   threads)
  6424.  
  6425. ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
  6426. (defmacro gnus-thread-header (thread)
  6427.   ;; Return header of first article in THREAD.
  6428.   ;; Note that THREAD must never, evr be anything else than a variable -
  6429.   ;; using some other form will lead to serious barfage.
  6430.   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
  6431.   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
  6432.   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ; 
  6433.     (vector thread) 2))
  6434.  
  6435. (defun gnus-thread-sort-by-number (h1 h2)
  6436.   "Sort threads by root article number."
  6437.   (< (mail-header-number (gnus-thread-header h1))
  6438.      (mail-header-number (gnus-thread-header h2))))
  6439.  
  6440. (defun gnus-thread-sort-by-author (h1 h2)
  6441.   "Sort threads by root author."
  6442.   (string-lessp
  6443.    (let ((extract (funcall 
  6444.            gnus-extract-address-components
  6445.            (mail-header-from (gnus-thread-header h1)))))
  6446.      (or (car extract) (cdr extract)))
  6447.    (let ((extract (funcall
  6448.            gnus-extract-address-components 
  6449.            (mail-header-from (gnus-thread-header h2)))))
  6450.      (or (car extract) (cdr extract)))))
  6451.  
  6452. (defun gnus-thread-sort-by-subject (h1 h2)
  6453.   "Sort threads by root subject."
  6454.   (string-lessp
  6455.    (downcase (gnus-simplify-subject-re
  6456.           (mail-header-subject (gnus-thread-header h1))))
  6457.    (downcase (gnus-simplify-subject-re 
  6458.           (mail-header-subject (gnus-thread-header h2))))))
  6459.  
  6460. (defun gnus-thread-sort-by-date (h1 h2)
  6461.   "Sort threads by root article date."
  6462.   (string-lessp
  6463.    (gnus-sortable-date (mail-header-date (gnus-thread-header h1)))
  6464.    (gnus-sortable-date (mail-header-date (gnus-thread-header h2)))))
  6465.  
  6466. (defun gnus-thread-sort-by-score (h1 h2)
  6467.   "Sort threads by root article score.
  6468. Unscored articles will be counted as having a score of zero."
  6469.   (> (or (cdr (assq (mail-header-number (gnus-thread-header h1))
  6470.             gnus-newsgroup-scored))
  6471.      gnus-summary-default-score 0)
  6472.      (or (cdr (assq (mail-header-number (gnus-thread-header h2))
  6473.             gnus-newsgroup-scored))
  6474.      gnus-summary-default-score 0)))
  6475.  
  6476. (defun gnus-thread-sort-by-total-score (h1 h2)
  6477.   "Sort threads by the sum of all scores in the thread.
  6478. Unscored articles will be counted as having a score of zero."
  6479.   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
  6480.  
  6481. (defun gnus-thread-total-score (thread)
  6482.   ;;  This function find the total score of THREAD.
  6483.   (if (consp thread)
  6484.       (if (stringp (car thread))
  6485.       (apply gnus-thread-score-function 0
  6486.          (mapcar 'gnus-thread-total-score-1 (cdr thread)))
  6487.     (gnus-thread-total-score-1 thread))
  6488.     (gnus-thread-total-score-1 (list thread))))
  6489.  
  6490. (defun gnus-thread-total-score-1 (root)
  6491.   ;; This function find the total score of the thread below ROOT.
  6492.   (setq root (car root))
  6493.   (apply gnus-thread-score-function
  6494.      (or (cdr (assq (mail-header-number root) gnus-newsgroup-scored))
  6495.          gnus-summary-default-score 0)
  6496.      (mapcar 'gnus-thread-total-score
  6497.          (cdr (gnus-gethash (downcase (mail-header-id root))
  6498.                     gnus-newsgroup-dependencies)))))
  6499.  
  6500. ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
  6501. (defvar gnus-tmp-prev-subject "")
  6502.  
  6503. (defun gnus-summary-prepare-threads (threads &optional cull)
  6504.   "Prepare summary buffer from THREADS and indentation LEVEL.  
  6505. THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'  
  6506. or a straight list of headers."
  6507.   (gnus-message 5 "Generating summary...")
  6508.   (let ((level 0)
  6509.     thread header number subject stack state gnus-tmp-gathered)
  6510.     (if (vectorp (car threads))
  6511.     ;; If this is a straight (sic) list of headers, then a
  6512.     ;; threaded summary display isn't required, so we just create
  6513.     ;; an unthreaded one.
  6514.     (gnus-summary-prepare-unthreaded threads cull)
  6515.  
  6516.       ;; Do the threaded display.
  6517.  
  6518.       (while (or threads stack)
  6519.     
  6520.     (if threads
  6521.         ;; If there are some threads, we do them before the
  6522.         ;; threads on the stack.
  6523.         (setq thread threads
  6524.           header (car (car thread)))
  6525.       ;; There were no current threads, so we pop something off
  6526.       ;; the stack. 
  6527.       (setq state (car stack)
  6528.         level (car state)
  6529.         thread (cdr state)
  6530.         stack (cdr stack)
  6531.         header (car (car thread))))
  6532.  
  6533.     (if (stringp header)
  6534.         (progn
  6535.           ;; The header is a dummy root.
  6536.           (cond 
  6537.            ((eq gnus-summary-make-false-root 'adopt)
  6538.         ;; We let the first article adopt the rest.
  6539.         (let ((th (car (cdr (car thread)))))
  6540.           (while (cdr th)
  6541.             (setq th (cdr th)))
  6542.           (setcdr th (cdr (cdr (car thread))))
  6543.           (setq gnus-tmp-gathered 
  6544.             (nconc (mapcar
  6545.                 (lambda (h) (mail-header-number (car h)))
  6546.                 (cdr (cdr (car thread))))
  6547.                    gnus-tmp-gathered))
  6548.           (setcdr (cdr (car thread)) nil))
  6549.         (setq level -1))
  6550.            ((eq gnus-summary-make-false-root 'empty)
  6551.         ;; We print adopted articles with empty subject fields.
  6552.         (setq gnus-tmp-gathered 
  6553.               (nconc (mapcar
  6554.                   (lambda (h) (mail-header-number (car h)))
  6555.                   (cdr (cdr (car thread))))
  6556.                  gnus-tmp-gathered))
  6557.         (setq level -1))
  6558.            ((eq gnus-summary-make-false-root 'dummy)
  6559.         ;; We output a dummy root.
  6560.         (gnus-summary-insert-dummy-line 
  6561.          nil header (mail-header-number
  6562.                  (car (car (cdr (car thread)))))))
  6563.            (t
  6564.         ;; We do not make a root for the gathered
  6565.         ;; sub-threads at all.  
  6566.         (setq level -1))))
  6567.       
  6568.       (setq number (mail-header-number header)
  6569.         subject (mail-header-subject header))
  6570.  
  6571.       ;; Do the async thing.
  6572.       (and gnus-newsgroup-async
  6573.            (setq gnus-newsgroup-threads
  6574.              (cons (cons number (mail-header-lines header)) 
  6575.                gnus-newsgroup-threads)))
  6576.  
  6577.       ;; We may have to root out some bad articles...
  6578.       (and cull
  6579.            (= level 0)
  6580.            (cond ((and (memq (setq number (mail-header-number header))
  6581.                  gnus-newsgroup-dormant)
  6582.                (null thread))
  6583.               (setq header nil))
  6584.              ((and gnus-summary-expunge-below
  6585.                (< (or (cdr (assq number gnus-newsgroup-scored))
  6586.                   gnus-summary-default-score 0)
  6587.                   gnus-summary-expunge-below))
  6588.               (setq header nil)
  6589.               (setq gnus-newsgroup-unreads 
  6590.                 (delq number gnus-newsgroup-unreads))
  6591.               (setq gnus-newsgroup-reads
  6592.                 (cons (cons number gnus-low-score-mark)
  6593.                   gnus-newsgroup-reads)))))
  6594.       
  6595.       (and
  6596.        header
  6597.        (progn
  6598.          (inline
  6599.            (gnus-summary-insert-line
  6600.         nil header level nil 
  6601.         (cond 
  6602.          ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
  6603.          ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
  6604.          ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
  6605.          ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
  6606.          (t (or (cdr (assq number gnus-newsgroup-reads))
  6607.             gnus-ancient-mark)))
  6608.         (memq number gnus-newsgroup-replied)
  6609.         (memq number gnus-newsgroup-expirable)
  6610.         (cond
  6611.          ((and gnus-thread-ignore-subject
  6612.                (not (string= 
  6613.                  (gnus-simplify-subject-re gnus-tmp-prev-subject)
  6614.                  (gnus-simplify-subject-re subject))))
  6615.           subject)
  6616.          ((zerop level)
  6617.           (if (and (eq gnus-summary-make-false-root 'empty)
  6618.                (memq number gnus-tmp-gathered))
  6619.               gnus-summary-same-subject
  6620.             subject))
  6621.          (t gnus-summary-same-subject))
  6622.         (and (eq gnus-summary-make-false-root 'adopt)
  6623.              (memq number gnus-tmp-gathered))
  6624.         (cdr (assq number gnus-newsgroup-scored))
  6625.         (memq number gnus-newsgroup-processable))
  6626.  
  6627.            (setq gnus-tmp-prev-subject subject)))))
  6628.  
  6629.     (if (nth 1 thread) 
  6630.         (setq stack (cons (cons (max 0 level) (nthcdr 1 thread)) stack)))
  6631.     (setq level (1+ level))
  6632.     (setq threads (cdr (car thread))))))
  6633.   (gnus-message 5 "Generating summary...done"))
  6634.  
  6635.  
  6636.  
  6637. (defun gnus-summary-prepare-unthreaded (headers &optional cull)
  6638.   (let (header number)
  6639.  
  6640.     ;; Do the async thing, if that is required.
  6641.     (if gnus-newsgroup-async
  6642.     (setq gnus-newsgroup-threads
  6643.           (mapcar (lambda (h) 
  6644.             (cons (mail-header-number h) (mail-header-lines h)))
  6645.               headers)))
  6646.  
  6647.     (while headers
  6648.       (setq header (car headers)
  6649.         headers (cdr headers)
  6650.         number (mail-header-number header))
  6651.  
  6652.       ;; We may have to root out some bad articles...
  6653.       (cond 
  6654.        ((and cull
  6655.          (memq (setq number (mail-header-number header))
  6656.            gnus-newsgroup-dormant)))
  6657.        ((and cull gnus-summary-expunge-below
  6658.          (< (or (cdr (assq number gnus-newsgroup-scored))
  6659.             gnus-summary-default-score 0)
  6660.         gnus-summary-expunge-below))
  6661.     (setq gnus-newsgroup-unreads 
  6662.           (delq number gnus-newsgroup-unreads))
  6663.     (setq gnus-newsgroup-reads
  6664.           (cons (cons number gnus-low-score-mark)
  6665.             gnus-newsgroup-reads)))
  6666.        (t
  6667.     (gnus-summary-insert-line
  6668.      nil header 0 nil 
  6669.      (cond ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
  6670.            ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
  6671.            ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
  6672.            ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
  6673.            (t (or (cdr (assq number gnus-newsgroup-reads))
  6674.               gnus-ancient-mark)))
  6675.      (memq number gnus-newsgroup-replied)
  6676.      (memq number gnus-newsgroup-expirable)
  6677.      (mail-header-subject header) nil
  6678.      (cdr (assq number gnus-newsgroup-scored))
  6679.      (memq number gnus-newsgroup-processable)))))))
  6680.  
  6681. (defun gnus-select-newsgroup (group &optional read-all)
  6682.   "Select newsgroup GROUP.
  6683. If READ-ALL is non-nil, all articles in the group are selected."
  6684.   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
  6685.      (info (nth 2 entry))
  6686.      articles)
  6687.  
  6688.     (or (gnus-check-server
  6689.      (setq gnus-current-select-method (gnus-find-method-for-group group)))
  6690.     (error "Couldn't open server"))
  6691.     
  6692.     (or (and entry (not (eq (car entry) t))) ; Either it's active...
  6693.     (gnus-activate-group group) ; Or we can activate it...
  6694.     (progn ; Or we bug out.
  6695.       (kill-buffer (current-buffer))
  6696.       (error "Couldn't request group %s: %s" 
  6697.          group (gnus-status-message group))))
  6698.  
  6699.     (setq gnus-newsgroup-name group)
  6700.     (setq gnus-newsgroup-unselected nil)
  6701.     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
  6702.  
  6703.     (and gnus-asynchronous
  6704.      (gnus-check-backend-function 
  6705.       'request-asynchronous gnus-newsgroup-name)
  6706.      (setq gnus-newsgroup-async
  6707.            (gnus-request-asynchronous gnus-newsgroup-name)))
  6708.  
  6709.     (setq articles (gnus-articles-to-read group read-all))
  6710.  
  6711.     (cond 
  6712.      ((null articles) 
  6713.       (gnus-message 3 "Couldn't select newsgroup")
  6714.       'quit)
  6715.      ((eq articles 0) nil)
  6716.      (t
  6717.       ;; Init the dependencies hash table.
  6718.       (setq gnus-newsgroup-dependencies 
  6719.         (gnus-make-hashtable (length articles)))
  6720.       ;; Retrieve the headers and read them in.
  6721.       (gnus-message 5 "Fetching headers...")
  6722.       (setq gnus-newsgroup-headers 
  6723.         (if (eq 'nov (setq gnus-headers-retrieved-by
  6724.                    ;; This is a naughty hack. To get the
  6725.                    ;; retrieval of old headers to work, we
  6726.                    ;; set `nntp-nov-gap' to nil (locally),
  6727.                    ;; and then just retrieve the headers.
  6728.                    ;; Mucho magic.
  6729.                    (if gnus-fetch-old-headers
  6730.                    (let (nntp-nov-gap)
  6731.                      (gnus-retrieve-headers 
  6732.                       (if (not (eq 1 (car articles)))
  6733.                       (cons 1 articles)
  6734.                     articles)
  6735.                       gnus-newsgroup-name))
  6736.                  (gnus-retrieve-headers 
  6737.                   articles gnus-newsgroup-name))))
  6738.         (progn
  6739.           (gnus-get-newsgroup-headers-xover articles))
  6740.           ;; If we were to fetch old headers, but the backend didn't
  6741.           ;; support XOVER, then it is possible we fetched one article
  6742.           ;; that we shouldn't have. If that's the case, we remove it.
  6743.           (if (or (not gnus-fetch-old-headers)
  6744.               (eq 1 (car articles)))
  6745.           ()
  6746.         (save-excursion
  6747.           (set-buffer nntp-server-buffer)
  6748.           (goto-char (point-min))
  6749.           (and 
  6750.            (looking-at "[0-9]+[ \t]+1[ \t]") ; This is not a NOV line.
  6751.            (delete-region    ; So we delete this head.
  6752.             (point) 
  6753.             (search-forward "\n.\n" nil t)))))
  6754.           (gnus-get-newsgroup-headers)))
  6755.       (gnus-message 5 "Fetching headers...done")      
  6756.       ;; Remove canceled articles from the list of unread articles.
  6757.       (setq gnus-newsgroup-unreads
  6758.         (gnus-set-sorted-intersection 
  6759.          gnus-newsgroup-unreads
  6760.          (mapcar (lambda (headers) (mail-header-number headers))
  6761.              gnus-newsgroup-headers)))
  6762.       ;; Adjust and set lists of article marks.
  6763.       (and info
  6764.        (let (marked)
  6765.          (gnus-adjust-marked-articles info)
  6766.          (setq gnus-newsgroup-marked 
  6767.            (copy-sequence
  6768.             (cdr (assq 'tick (setq marked (nth 3 info))))))
  6769.          (setq gnus-newsgroup-replied 
  6770.            (copy-sequence (cdr (assq 'reply marked))))
  6771.          (setq gnus-newsgroup-expirable
  6772.            (copy-sequence (cdr (assq 'expire marked))))
  6773.          (setq gnus-newsgroup-killed
  6774.            (copy-sequence (cdr (assq 'killed marked))))
  6775.          (setq gnus-newsgroup-bookmarks 
  6776.            (copy-sequence (cdr (assq 'bookmark marked))))
  6777.          (setq gnus-newsgroup-dormant 
  6778.            (copy-sequence (cdr (assq 'dormant marked))))
  6779.          (setq gnus-newsgroup-scored 
  6780.            (copy-sequence (cdr (assq 'score marked))))
  6781.          (setq gnus-newsgroup-processable nil)))
  6782.       ;; Check whether auto-expire is to be done in this group.
  6783.       (setq gnus-newsgroup-auto-expire
  6784.         (or (and (stringp gnus-auto-expirable-newsgroups)
  6785.              (string-match gnus-auto-expirable-newsgroups group))
  6786.         (memq 'auto-expire (nth 5 info))))
  6787.       ;; First and last article in this newsgroup.
  6788.       (and gnus-newsgroup-headers
  6789.        (setq gnus-newsgroup-begin 
  6790.          (mail-header-number (car gnus-newsgroup-headers)))
  6791.        (setq gnus-newsgroup-end
  6792.          (mail-header-number
  6793.           (gnus-last-element gnus-newsgroup-headers))))
  6794.       (setq gnus-reffed-article-number -1)
  6795.       ;; GROUP is successfully selected.
  6796.       (or gnus-newsgroup-headers t)))))
  6797.  
  6798. (defun gnus-articles-to-read (group read-all)
  6799.   ;; Find out what articles the user wants to read.
  6800.   (let* ((articles
  6801.       ;; Select all articles if `read-all' is non-nil, or if all the
  6802.       ;; unread articles are dormant articles.
  6803.       (if (or read-all
  6804.           (= (length gnus-newsgroup-unreads) 
  6805.              (length gnus-newsgroup-dormant)))
  6806.           (gnus-uncompress-range 
  6807.            (gnus-gethash group gnus-active-hashtb))
  6808.         gnus-newsgroup-unreads))
  6809.      (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
  6810.      (scored (length scored-list))
  6811.      (number (length articles))
  6812.      (marked (+ (length gnus-newsgroup-marked)
  6813.             (length gnus-newsgroup-dormant)))
  6814.      (select
  6815.       (cond 
  6816.        ((numberp read-all)
  6817.         read-all)
  6818.        (t
  6819.         (condition-case ()
  6820.         (cond ((and (or (<= scored marked)
  6821.                 (= scored number))
  6822.                 (numberp gnus-large-newsgroup)
  6823.                 (> number gnus-large-newsgroup))
  6824.                (let ((input
  6825.                   (read-string
  6826.                    (format
  6827.                 "How many articles from %s (default %d): "
  6828.                 gnus-newsgroup-name number))))
  6829.              (if (string-match "^[ \t]*$" input)
  6830.                  number input)))
  6831.               ((and (> scored marked) (< scored number))
  6832.                (let ((input
  6833.                   (read-string
  6834.                    (format 
  6835.                 "%s %s (%d scored, %d total): "
  6836.                 "How many articles from"
  6837.                 group scored number))))
  6838.              (if (string-match "^[ \t]*$" input)
  6839.                  number input)))
  6840.               (t number))
  6841.           (quit nil))))))
  6842.     (setq select (if (stringp select) (string-to-number select) select))
  6843.     (if (or (null select) (zerop select))
  6844.     select
  6845.       (if (and (not (zerop scored)) (<= (abs select) scored))
  6846.       (progn
  6847.         (setq articles (sort scored-list '<))
  6848.         (setq number (length articles)))
  6849.     (setq articles (copy-sequence articles)))
  6850.  
  6851.       (if (< (abs select) number)
  6852.       (if (< select 0) 
  6853.           ;; Select the N oldest articles.
  6854.           (setcdr (nthcdr (1- (abs select)) articles) nil)
  6855.         ;; Select the N most recent articles.
  6856.         (setq articles (nthcdr (- number select) articles))))
  6857.       (setq gnus-newsgroup-unselected
  6858.         (gnus-sorted-intersection
  6859.          gnus-newsgroup-unreads
  6860.          (gnus-sorted-complement gnus-newsgroup-unreads articles)))
  6861.       articles)))
  6862.  
  6863. (defun gnus-killed-articles (killed articles)
  6864.   (let (out)
  6865.     (while articles
  6866.       (if (inline (gnus-member-of-range (car articles) killed))
  6867.       (setq out (cons (car articles) out)))
  6868.       (setq articles (cdr articles)))
  6869.     out))
  6870.  
  6871. (defun gnus-adjust-marked-articles (info &optional active)
  6872.   "Remove all marked articles that are no longer legal."
  6873.   (let ((marked-lists (nth 3 info))
  6874.     (active (or active (gnus-gethash (car info) gnus-active-hashtb)))
  6875.     m prev)
  6876.     ;; There are many types of marked articles.
  6877.     (while marked-lists
  6878.       (setq m (cdr (setq prev (car marked-lists))))
  6879.       (cond ((or (eq 'tick (car prev)) (eq 'dormant (car prev)))
  6880.          ;; Make sure that all ticked articles are a subset of the
  6881.          ;; unread/unselected articles.
  6882.          ;;(while m
  6883.          ;;  (if (or (memq (car m) gnus-newsgroup-unreads)
  6884.          ;;  (memq (car m) gnus-newsgroup-unselected))
  6885.          ;; (setq prev m)
  6886.          ;; (setcdr prev (cdr m)))
  6887.          ;; (setq m (cdr m)))
  6888.          )
  6889.         ((eq 'score (car prev))
  6890.          ;; Scored articles should be a subset of
  6891.          ;; unread/unselected articles. 
  6892.          (while m
  6893.            (if (or (memq (car (car m)) gnus-newsgroup-unreads)
  6894.                (memq (car (car m)) gnus-newsgroup-unreads))
  6895.            (setq prev m)
  6896.          (setcdr prev (cdr m)))
  6897.            (setq m (cdr m))))
  6898.         ((eq 'bookmark (car prev))
  6899.          ;; Bookmarks should be a subset of active articles.
  6900.          (while m
  6901.            (if (< (car (car m)) (car active))
  6902.            (setcdr prev (cdr m))
  6903.          (setq prev m))
  6904.            (setq m (cdr m))))
  6905.         ((eq 'killed (car prev))
  6906.          ;; Articles that have been through the kill process are
  6907.          ;; to be a subset of active articles.
  6908.          (while (and m (< (or (and (numberp (car m)) (car m))
  6909.                   (cdr (car m)))
  6910.                   (car active)))
  6911.            (setcdr prev (cdr m))
  6912.            (setq m (cdr m)))
  6913.          (if (and m (< (or (and (numberp (car m)) (car m))
  6914.                    (car (car m)))
  6915.                (car active))) 
  6916.          (setcar (if (numberp (car m)) m (car m)) (car active))))
  6917.         ((or (eq 'reply (car prev)) (eq 'expire (car prev)))
  6918.          ;; The replied and expirable articles have to be articles
  6919.          ;; that are active. 
  6920.          (while m
  6921.            (if (< (car m) (car active))
  6922.            (setcdr prev (cdr m))
  6923.          (setq prev m))
  6924.            (setq m (cdr m)))))
  6925.       (setq marked-lists (cdr marked-lists)))
  6926.     ;; Remove all lists that are empty.
  6927.     (setq marked-lists (nth 3 info))
  6928.     (if marked-lists
  6929.     (progn
  6930.       (while (= 1 (length (car marked-lists)))
  6931.         (setq marked-lists (cdr marked-lists)))
  6932.       (setq m (cdr (setq prev marked-lists)))
  6933.       (while m
  6934.         (if (= 1 (length (car m)))
  6935.         (setcdr prev (cdr m))
  6936.           (setq prev m))
  6937.         (setq m (cdr m)))
  6938.       (setcar (nthcdr 3 info) marked-lists)))
  6939.     ;; Finally, if there are no marked lists at all left, and if there
  6940.     ;; are no elements after the lists in the info list, we just chop
  6941.     ;; the info list off before the marked lists.
  6942.     (and (null marked-lists) 
  6943.      (not (nthcdr 4 info))
  6944.      (setcdr (nthcdr 2 info) nil)))
  6945.   info)
  6946.  
  6947. (defun gnus-set-marked-articles 
  6948.   (info ticked replied expirable killed dormant bookmark score) 
  6949.   "Enter the various lists of marked articles into the newsgroup info list."
  6950.   (let (newmarked)
  6951.     (and ticked (setq newmarked (cons (cons 'tick ticked) nil)))
  6952.     (and replied (setq newmarked (cons (cons 'reply replied) newmarked)))
  6953.     (and expirable (setq newmarked (cons (cons 'expire expirable) 
  6954.                      newmarked)))
  6955.     (and killed (setq newmarked (cons (cons 'killed killed) newmarked)))
  6956.     (and dormant (setq newmarked (cons (cons 'dormant dormant) newmarked)))
  6957.     (and bookmark (setq newmarked (cons (cons 'bookmark bookmark) 
  6958.                     newmarked)))
  6959.     (and score (setq newmarked (cons (cons 'score score) newmarked)))
  6960.     (if (nthcdr 3 info)
  6961.     (progn
  6962.       (setcar (nthcdr 3 info) newmarked)
  6963.       (and (not newmarked)
  6964.            (not (nthcdr 4 info))
  6965.            (setcdr (nthcdr 2 info) nil)))
  6966.       (if newmarked
  6967.       (setcdr (nthcdr 2 info) (list newmarked))))))
  6968.  
  6969. (defun gnus-add-marked-articles (group type articles &optional info force)
  6970.   ;; Add ARTICLES of TYPE to the info of GROUP.
  6971.   ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
  6972.   ;; add, but replace marked articles of TYPE with ARTICLES.
  6973.   (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
  6974.     marked m)
  6975.     (or (not info)
  6976.     (and (not (setq marked (nthcdr 3 info)))
  6977.          (setcdr (nthcdr 2 info) (list (list (cons type articles)))))
  6978.     (and (not (setq m (assq type (car marked))))
  6979.          (setcar marked (cons (cons type articles) (car marked))))
  6980.     (if force
  6981.         (setcdr m articles)
  6982.       (nconc m articles)))))
  6983.      
  6984. (defun gnus-set-mode-line (where)
  6985.   "This function sets the mode line of the article or summary buffers.
  6986. If WHERE is `summary', the summary mode line format will be used."
  6987.   (if (memq where gnus-updated-mode-lines)
  6988.       (let (mode-string)
  6989.     (save-excursion
  6990.       (set-buffer gnus-summary-buffer)
  6991.       (let* ((mformat (if (eq where 'article) 
  6992.                   gnus-article-mode-line-format-spec
  6993.                 gnus-summary-mode-line-format-spec))
  6994.          (buffer-name (if (eq where 'article)
  6995.                   (buffer-name
  6996.                    (get-buffer gnus-article-buffer))
  6997.                 (buffer-name)))
  6998.          (group-name gnus-newsgroup-name)
  6999.          (article-number (or gnus-current-article 0))
  7000.          (unread (- (length gnus-newsgroup-unreads)
  7001.                 (length gnus-newsgroup-dormant)))
  7002.          (unread-and-unticked 
  7003.           (- unread (length gnus-newsgroup-marked)))
  7004.          (unselected (length gnus-newsgroup-unselected))
  7005.          (unread-and-unselected
  7006.           (cond ((and (zerop unread-and-unticked)
  7007.                   (zerop unselected)) "")
  7008.             ((zerop unselected) 
  7009.              (format "{%d more}" unread-and-unticked))
  7010.             (t (format "{%d(+%d) more}"
  7011.                    unread-and-unticked unselected))))
  7012.          (subject
  7013.           (if gnus-current-headers
  7014.               (mail-header-subject gnus-current-headers) ""))
  7015.          (max-len (and gnus-mode-non-string-length
  7016.                    (- (frame-width) gnus-mode-non-string-length)))
  7017.          header);; passed as argument to any user-format-funcs
  7018.         (setq mode-string (eval mformat))
  7019.             (or (numberp max-len)
  7020.         (setq max-len (length mode-string)))
  7021.         (if (< max-len 4) (setq max-len 4))
  7022.         (if (> (length mode-string) max-len)
  7023.         ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  7024.         ;;  function `substring' might cut on a middle
  7025.         ;;  of multi-octet character.
  7026.         (setq mode-string 
  7027.               (concat (gnus-truncate-string mode-string (- max-len 3))
  7028.                   "...")))
  7029.         (setq mode-string (format (format "%%-%ds" max-len)
  7030.                       mode-string))))
  7031.     (setq mode-line-buffer-identification mode-string)
  7032.     (set-buffer-modified-p t))))
  7033.  
  7034. (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
  7035.   "Go through the HEADERS list and add all Xrefs to a hash table.
  7036. The resulting hash table is returned, or nil if no Xrefs were found."
  7037.   (let* ((from-method (gnus-find-method-for-group from-newsgroup))
  7038.      (prefix (if (and 
  7039.               (gnus-group-foreign-p from-newsgroup)
  7040.               (not (memq 'virtual 
  7041.                  (assoc (symbol-name (car from-method))
  7042.                     gnus-valid-select-methods))))
  7043.              (gnus-group-real-prefix from-newsgroup)))
  7044.      (xref-hashtb (make-vector 63 0))
  7045.      start group entry number xrefs header)
  7046.     (while headers
  7047.       (setq header (car headers))
  7048.       (if (and (setq xrefs (mail-header-xref header))
  7049.            (not (memq (mail-header-number header) unreads)))
  7050.       (progn
  7051.         (setq start 0)
  7052.         (while (string-match "\\([^ ]+\\):\\([0-9]+\\)" xrefs start)
  7053.           (setq start (match-end 0))
  7054.           (setq group (concat prefix (substring xrefs (match-beginning 1) 
  7055.                             (match-end 1))))
  7056.           (setq number 
  7057.             (string-to-int (substring xrefs (match-beginning 2) 
  7058.                           (match-end 2))))
  7059.           (if (setq entry (gnus-gethash group xref-hashtb))
  7060.           (setcdr entry (cons number (cdr entry)))
  7061.         (gnus-sethash group (cons number nil) xref-hashtb)))))
  7062.       (setq headers (cdr headers)))
  7063.     (if start xref-hashtb nil)))
  7064.  
  7065. (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads expirable)
  7066.   "Look through all the headers and mark the Xrefs as read."
  7067.   (let ((virtual (memq 'virtual 
  7068.                (assoc (symbol-name (car (gnus-find-method-for-group 
  7069.                          from-newsgroup)))
  7070.                   gnus-valid-select-methods)))
  7071.     name entry info xref-hashtb idlist method
  7072.     nth4)
  7073.     (save-excursion
  7074.       (set-buffer gnus-group-buffer)
  7075.       (if (setq xref-hashtb 
  7076.         (gnus-create-xref-hashtb from-newsgroup headers unreads))
  7077.       (mapatoms 
  7078.        (lambda (group)
  7079.          (if (string= from-newsgroup (setq name (symbol-name group)))
  7080.          ()
  7081.            (setq idlist (symbol-value group))
  7082.            ;; Dead groups are not updated.
  7083.            (if (and (prog1 
  7084.                 (setq entry (gnus-gethash name gnus-newsrc-hashtb)
  7085.                   info (nth 2 entry))
  7086.               (if (stringp (setq nth4 (nth 4 info)))
  7087.                   (setq nth4 (gnus-server-to-method nth4))))
  7088.             ;; Only do the xrefs if the group has the same
  7089.             ;; select method as the group we have just read.
  7090.             (or (gnus-methods-equal-p 
  7091.                  nth4 (gnus-find-method-for-group from-newsgroup))
  7092.                 virtual
  7093.                 (equal nth4 
  7094.                    (setq method (gnus-find-method-for-group 
  7095.                          from-newsgroup)))
  7096.                 (and (equal (car nth4) (car method))
  7097.                  (equal (nth 1 nth4) (nth 1 method))))
  7098.             gnus-use-cross-reference
  7099.             (or (not (eq gnus-use-cross-reference t))
  7100.                 virtual
  7101.                 ;; Only do cross-references on subscribed
  7102.                 ;; groups, if that is what is wanted.  
  7103.                 (<= (nth 1 info) gnus-level-subscribed)))
  7104.            (gnus-group-make-articles-read name idlist expirable))))
  7105.        xref-hashtb)))))
  7106.  
  7107. (defun gnus-group-make-articles-read (group articles expirable)
  7108.   (let* ((num 0)
  7109.      (entry (gnus-gethash group gnus-newsrc-hashtb))
  7110.      (info (nth 2 entry))
  7111.      (active (gnus-gethash group gnus-active-hashtb))
  7112.      exps expirable range)
  7113.     ;; First peel off all illegal article numbers.
  7114.     (if active
  7115.     (let ((ids articles)
  7116.           (ticked (cdr (assq 'tick (nth 3 info))))
  7117.           (dormant (cdr (assq 'dormant (nth 3 info))))
  7118.           id first)
  7119.       (setq exps nil)
  7120.       (while ids
  7121.         (setq id (car ids))
  7122.         (if (and first (> id (cdr active)))
  7123.         (progn
  7124.           ;; We'll end up in this situation in one particular
  7125.           ;; obscure situation. If you re-scan a group and get
  7126.           ;; a new article that is cross-posted to a different
  7127.           ;; group that has not been re-scanned, you might get
  7128.           ;; crossposted article that has a higher number than
  7129.           ;; Gnus believes possible. So we re-activate this
  7130.           ;; group as well. This might mean doing the
  7131.           ;; crossposting thingy will *increase* the number
  7132.           ;; of articles in some groups. Tsk, tsk.
  7133.           (setq active (or (gnus-activate-group group) active))))
  7134.         (if (or (> id (cdr active))
  7135.             (< id (car active))
  7136.             (memq id ticked)
  7137.             (memq id dormant))
  7138.         (setq articles (delq id articles)))
  7139.         (and (memq id expirable)
  7140.          (setq exps (cons id exps)))
  7141.         (setq ids (cdr ids)))))
  7142.     ;; Update expirable articles.
  7143.     (gnus-add-marked-articles nil 'expirable exps info)
  7144.     (and active
  7145.      (null (nth 2 info))
  7146.      (> (car active) 1)
  7147.      (setcar (nthcdr 2 info) (cons 1 (1- (car active)))))
  7148.     (setcar (nthcdr 2 info)
  7149.         (setq range
  7150.           (gnus-add-to-range 
  7151.            (nth 2 info) 
  7152.            (setq articles (sort articles '<)))))
  7153.     ;; Then we have to re-compute how many unread
  7154.     ;; articles there are in this group.
  7155.     (if active
  7156.     (progn
  7157.       (cond 
  7158.        ((not range)
  7159.         (setq num (- (1+ (cdr active)) (car active))))
  7160.        ((not (listp (cdr range)))
  7161.         (setq num (- (cdr active) (- (1+ (cdr range)) 
  7162.                      (car range)))))
  7163.        (t
  7164.         (while range
  7165.           (if (numberp (car range))
  7166.           (setq num (1+ num))
  7167.         (setq num (+ num (- (1+ (cdr (car range)))
  7168.                     (car (car range))))))
  7169.           (setq range (cdr range)))
  7170.         (setq num (- (cdr active) num))))
  7171.       ;; Update the number of unread articles.
  7172.       (setcar 
  7173.        entry 
  7174.        (max 0 (- num 
  7175.              (length (cdr (assq 'tick (nth 3 info))))
  7176.              (length 
  7177.               (cdr (assq 'dormant (nth 3 info)))))))
  7178.       ;; Update the group buffer.
  7179.       (gnus-group-update-group group t)))))
  7180.  
  7181. (defun gnus-methods-equal-p (m1 m2)
  7182.   (let ((m1 (or m1 gnus-select-method))
  7183.     (m2 (or m2 gnus-select-method)))
  7184.     (or (equal m1 m2)
  7185.     (and (eq (car m1) (car m2))
  7186.          (or (not (memq 'address (assoc (symbol-name (car m1))
  7187.                         gnus-valid-select-methods)))
  7188.          (equal (nth 1 m1) (nth 1 m2)))))))
  7189.  
  7190. (defsubst gnus-header-value ()
  7191.   (buffer-substring (match-end 0) (gnus-point-at-eol)))
  7192.  
  7193. (defvar gnus-newsgroup-none-id 0)
  7194.  
  7195. (defun gnus-get-newsgroup-headers ()
  7196.   (setq gnus-article-internal-prepare-hook nil)
  7197.   (let ((cur nntp-server-buffer)
  7198.     (dependencies gnus-newsgroup-dependencies)
  7199.     headers id dep end ref)
  7200.     (save-excursion
  7201.       (set-buffer nntp-server-buffer)
  7202.       ;; Allow the user to mangle the headers before parsing them.
  7203.       (run-hooks 'gnus-parse-headers-hook)
  7204.       (goto-char (point-min))
  7205.       ;; Search to the beginning of the next header. Error messages
  7206.       ;; do not begin with 2 or 3.
  7207.       (while (re-search-forward "^[23][0-9]+ " nil t)
  7208.     (let ((header (make-vector 9 nil))
  7209.           (case-fold-search t)
  7210.           (p (point))
  7211.           in-reply-to)
  7212.       (setq id nil
  7213.         ref nil)
  7214.       (mail-header-set-number header (read cur))
  7215.       ;; This implementation of this function, with nine
  7216.       ;; search-forwards instead of the one re-search-forward and
  7217.       ;; a case (which basically was the old function) is actually
  7218.       ;; about twice as fast, even though it looks messier. You
  7219.       ;; can't have everything, I guess. Speed and elegance
  7220.       ;; doesn't always come hand in hand.
  7221.       (save-restriction
  7222.         (narrow-to-region (point) (or (save-excursion 
  7223.                         (search-forward "\n.\n" nil t))
  7224.                       (point)))
  7225.         (if (search-forward "\nfrom: " nil t)
  7226.         (mail-header-set-from header (gnus-header-value))
  7227.           (mail-header-set-from header "(nobody)"))
  7228.         (goto-char p)
  7229.         (if (search-forward "\nsubject: " nil t)
  7230.         (mail-header-set-subject header (gnus-header-value))
  7231.           (mail-header-set-subject header "(none)"))
  7232.         (goto-char p)
  7233.         (and (search-forward "\nxref: " nil t)
  7234.          (mail-header-set-xref header (gnus-header-value)))
  7235.         (goto-char p)
  7236.         (or (numberp (and (search-forward "\nlines: " nil t)
  7237.                   (mail-header-set-lines header (read cur))))
  7238.         (mail-header-set-lines header 0))
  7239.         (goto-char p)
  7240.         (and (search-forward "\ndate: " nil t)
  7241.          (mail-header-set-date header (gnus-header-value)))
  7242.         (goto-char p)
  7243.         (if (search-forward "\nmessage-id: " nil t)
  7244.         (mail-header-set-id header (setq id (gnus-header-value)))
  7245.           ;; If there was no message-id, we just fake one to make
  7246.           ;; subsequent routines simpler.
  7247.           (mail-header-set-id 
  7248.            header 
  7249.            (setq id (concat "none+" 
  7250.                 (int-to-string 
  7251.                  (setq gnus-newsgroup-none-id 
  7252.                        (1+ gnus-newsgroup-none-id)))))))
  7253.         (goto-char p)
  7254.         (if (search-forward "\nreferences: " nil t)
  7255.         (progn
  7256.           (mail-header-set-references header (gnus-header-value))
  7257.           (setq end (match-end 0))
  7258.           (save-excursion
  7259.             (setq ref 
  7260.               (downcase
  7261.                (buffer-substring
  7262.                 (progn 
  7263.                   (end-of-line)
  7264.                   (search-backward ">" end t)
  7265.                   (1+ (point)))
  7266.                 (progn
  7267.                   (search-backward "<" end t)
  7268.                   (point)))))))
  7269.           ;; Get the references from the in-reply-to header if there
  7270.           ;; ware no references and the in-reply-to header looks
  7271.           ;; promising. 
  7272.           (if (and (search-forward "\nin-reply-to: " nil t)
  7273.                (setq in-reply-to (gnus-header-value))
  7274.                (string-match "<[^>]+>" in-reply-to))
  7275.           (progn
  7276.             (mail-header-set-references 
  7277.              header 
  7278.              (setq ref (substring in-reply-to (match-beginning 0)
  7279.                       (match-end 0))))
  7280.             (setq ref (downcase ref)))
  7281.         (setq ref "none")))
  7282.         ;; We do some threading while we read the headers. The
  7283.         ;; message-id and the last reference are both entered into
  7284.         ;; the same hash table. Some tippy-toeing around has to be
  7285.         ;; done in case an article has arrived before the article
  7286.         ;; which it refers to.
  7287.         (if (boundp (setq dep (intern (downcase id) dependencies)))
  7288.         (if (car (symbol-value dep))
  7289.             ;; An article with this Message-ID has already
  7290.             ;; been seen, so we ignore this one, except we add
  7291.             ;; any additional Xrefs (in case the two articles
  7292.             ;; came from different servers.
  7293.             (progn
  7294.               (mail-header-set-xref 
  7295.                (car (symbol-value dep))
  7296.                (concat (or (mail-header-xref 
  7297.                     (car (symbol-value dep))) "")
  7298.                    (or (mail-header-xref header) "")))
  7299.               (setq header nil))
  7300.           (setcar (symbol-value dep) header))
  7301.           (set dep (list header)))
  7302.         (if header
  7303.         (progn
  7304.           (if (boundp (setq dep (intern ref dependencies)))
  7305.               (setcdr (symbol-value dep) 
  7306.                   (cons header (cdr (symbol-value dep))))
  7307.             (set dep (list nil header)))
  7308.           (setq headers (cons header headers))))
  7309.         (goto-char (point-max))))))
  7310.     (nreverse headers)))
  7311.  
  7312. ;; The following macros and functions were written by Felix Lee
  7313. ;; <flee@cse.psu.edu>. 
  7314.  
  7315. (defmacro gnus-nov-read-integer ()
  7316.   '(prog1
  7317.        (if (= (following-char) ?\t)
  7318.        0
  7319.      (let ((num (condition-case nil (read buffer) (error nil))))
  7320.        (if (numberp num) num 0)))
  7321.      (or (eobp) (forward-char 1))))
  7322.  
  7323. (defmacro gnus-nov-skip-field ()
  7324.   '(search-forward "\t" eol 'move))
  7325.  
  7326. (defmacro gnus-nov-field ()
  7327.   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
  7328.  
  7329. ;; Goes through the xover lines and returns a list of vectors
  7330. (defun gnus-get-newsgroup-headers-xover (sequence)
  7331.   "Parse the news overview data in the server buffer, and return a
  7332. list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
  7333.   ;; Get the Xref when the users reads the articles since most/some
  7334.   ;; NNTP servers do not include Xrefs when using XOVER.
  7335.   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
  7336.   (let ((cur nntp-server-buffer)
  7337.     (dependencies gnus-newsgroup-dependencies)
  7338.     number headers header)
  7339.     (save-excursion
  7340.       (set-buffer nntp-server-buffer)
  7341.       ;; Allow the user to mangle the headers before parsing them.
  7342.       (run-hooks 'gnus-parse-headers-hook)
  7343.       (goto-char (point-min))
  7344.       (while (and sequence (not (eobp)))
  7345.     (setq number (read cur))
  7346.     (while (and sequence (< (car sequence) number))
  7347.       (setq sequence (cdr sequence)))
  7348.     (and sequence 
  7349.          (eq number (car sequence))
  7350.          (progn
  7351.            (setq sequence (cdr sequence))
  7352.            (if (setq header 
  7353.              (inline (gnus-nov-parse-line number dependencies)))
  7354.            (setq headers (cons header headers)))))
  7355.     (forward-line 1))
  7356.       (setq headers (nreverse headers)))
  7357.     headers))
  7358.  
  7359. ;; This function has to be called with point after the article number
  7360. ;; on the beginning of the line.
  7361. (defun gnus-nov-parse-line (number dependencies)
  7362.   (let ((none 0)
  7363.     (eol (gnus-point-at-eol)) 
  7364.     (buffer (current-buffer))
  7365.     header ref id dep)
  7366.  
  7367.     ;; overview: [num subject from date id refs chars lines misc]
  7368.     (narrow-to-region (point) eol)
  7369.     (or (eobp) (forward-char))
  7370.  
  7371.     (condition-case nil
  7372.     (setq header
  7373.           (vector 
  7374.            number            ; number
  7375.            (gnus-nov-field)          ; subject
  7376.            (gnus-nov-field)          ; from
  7377.            (gnus-nov-field)        ; date
  7378.            (setq id (or (gnus-nov-field)
  7379.                 (concat "none+"
  7380.                     (int-to-string 
  7381.                      (setq none (1+ none)))))) ; id
  7382.            (progn
  7383.          (save-excursion
  7384.            (let ((beg (point)))
  7385.              (search-forward "\t" eol)
  7386.              (if (search-backward ">" beg t)
  7387.              (setq ref 
  7388.                    (downcase 
  7389.                 (buffer-substring 
  7390.                  (1+ (point))
  7391.                  (progn
  7392.                    (search-backward "<" beg t)
  7393.                    (point)))))
  7394.                (setq ref nil))))
  7395.          (gnus-nov-field))    ; refs
  7396.            (gnus-nov-read-integer)    ; chars
  7397.            (gnus-nov-read-integer)    ; lines
  7398.            (if (= (following-char) ?\n)
  7399.            nil
  7400.          (gnus-nov-field))    ; misc
  7401.            ))
  7402.       (error (progn 
  7403.            (ding)
  7404.            (message "Strange nov line.")
  7405.            (setq header nil)
  7406.            (goto-char eol))))
  7407.  
  7408.     (widen)
  7409.  
  7410.     ;; We build the thread tree.
  7411.     (and header
  7412.      (if (boundp (setq dep (intern (downcase id) dependencies)))
  7413.          (if (car (symbol-value dep))
  7414.          ;; An article with this Message-ID has already been seen,
  7415.          ;; so we ignore this one, except we add any additional
  7416.          ;; Xrefs (in case the two articles came from different
  7417.          ;; servers.
  7418.          (progn
  7419.            (mail-header-set-xref 
  7420.             (car (symbol-value dep))
  7421.             (concat (or (mail-header-xref (car (symbol-value dep))) "")
  7422.                 (or (mail-header-xref header) "")))
  7423.            (setq header nil))
  7424.            (setcar (symbol-value dep) header))
  7425.        (set dep (list header))))
  7426.     (if header
  7427.     (progn
  7428.       (if (boundp (setq dep (intern (or ref "none") 
  7429.                     dependencies)))
  7430.           (setcdr (symbol-value dep) 
  7431.               (cons header (cdr (symbol-value dep))))
  7432.         (set dep (list nil header)))))
  7433.     header))
  7434.  
  7435. (defun gnus-article-get-xrefs ()
  7436.   "Fill in the Xref value in `gnus-current-headers', if necessary.
  7437. This is meant to be called in `gnus-article-internal-prepare-hook'."
  7438.   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
  7439.                  gnus-current-headers)))
  7440.     (or (not gnus-use-cross-reference)
  7441.     (not headers)
  7442.     (and (mail-header-xref headers)
  7443.          (not (string= (mail-header-xref headers) "")))
  7444.     (let ((case-fold-search t)
  7445.           xref)
  7446.       (save-restriction
  7447.         (gnus-narrow-to-headers)
  7448.         (goto-char (point-min))
  7449.         (if (or (and (eq (downcase (following-char)) ?x)
  7450.              (looking-at "Xref:"))
  7451.             (search-forward "\nXref:" nil t))
  7452.         (progn
  7453.           (goto-char (1+ (match-end 0)))
  7454.           (setq xref (buffer-substring (point) 
  7455.                            (progn (end-of-line) (point))))
  7456.           (mail-header-set-xref headers xref))))))))
  7457.  
  7458. (defalias 'gnus-find-header-by-number 'gnus-get-header-by-number)
  7459. (make-obsolete 'gnus-find-header-by-number 'gnus-get-header-by-number)
  7460.  
  7461. (defun gnus-make-headers-hashtable-by-number ()
  7462.   "Make hashtable for the variable gnus-newsgroup-headers by number."
  7463.   (save-excursion
  7464.     (set-buffer gnus-summary-buffer)
  7465.     (let ((headers gnus-newsgroup-headers)
  7466.       header)
  7467.       (setq gnus-newsgroup-headers-hashtb-by-number
  7468.         (gnus-make-hashtable (length headers)))
  7469.       (while headers
  7470.     (setq header (car headers))
  7471.     (gnus-sethash (int-to-string (mail-header-number header))
  7472.               header gnus-newsgroup-headers-hashtb-by-number)
  7473.     (setq headers (cdr headers))))))
  7474.  
  7475. (defun gnus-more-header-backward ()
  7476.   "Find new header backward."
  7477.   (let ((first (car (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
  7478.     (artnum gnus-newsgroup-begin)
  7479.     (header nil))
  7480.     (while (and (not header)
  7481.         (> artnum first))
  7482.       (setq artnum (1- artnum))
  7483.       (setq header (gnus-read-header artnum)))
  7484.     header))
  7485.  
  7486. (defun gnus-more-header-forward (&optional backward)
  7487.   "Find new header forward.
  7488. If BACKWARD, find new header backward instead."
  7489.   (if backward
  7490.       (gnus-more-header-backward)
  7491.     (let ((last (cdr (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
  7492.       (artnum gnus-newsgroup-end)
  7493.       (header nil))
  7494.       (while (and (not header)
  7495.           (< artnum last))
  7496.     (setq artnum (1+ artnum))
  7497.     (setq header (gnus-read-header artnum)))
  7498.       header)))
  7499.  
  7500. (defun gnus-extend-newsgroup (header &optional backward)
  7501.   "Extend newsgroup selection with HEADER.
  7502. Optional argument BACKWARD means extend toward backward."
  7503.   (if header
  7504.       (let ((artnum (mail-header-number header)))
  7505.     (setq gnus-newsgroup-headers
  7506.           (if backward
  7507.           (cons header gnus-newsgroup-headers)
  7508.         (nconc gnus-newsgroup-headers (list header))))
  7509.     (setq gnus-newsgroup-unselected
  7510.           (delq artnum gnus-newsgroup-unselected))
  7511.     (setq gnus-newsgroup-begin (min gnus-newsgroup-begin artnum))
  7512.     (setq gnus-newsgroup-end (max gnus-newsgroup-end artnum)))))
  7513.  
  7514. (defun gnus-summary-work-articles (n)
  7515.   "Return a list of articles to be worked upon. The prefix argument,
  7516. the list of process marked articles, and the current article will be
  7517. taken into consideration."
  7518.   (let (articles)
  7519.     (if (and n (numberp n))
  7520.     (let ((backward (< n 0))
  7521.           (n (abs n)))
  7522.       (save-excursion
  7523.         (while (and (> n 0)
  7524.             (setq articles (cons (gnus-summary-article-number) 
  7525.                          articles))
  7526.             (gnus-summary-search-forward nil nil backward))
  7527.           (setq n (1- n))))
  7528.       (sort articles (function <)))
  7529.       (or (reverse gnus-newsgroup-processable)
  7530.       (list (gnus-summary-article-number))))))
  7531.  
  7532. (defun gnus-summary-search-group (&optional backward use-level)
  7533.   "Search for next unread newsgroup.
  7534. If optional argument BACKWARD is non-nil, search backward instead."
  7535.   (save-excursion
  7536.     (set-buffer gnus-group-buffer)
  7537.     (if (gnus-group-search-forward 
  7538.      backward nil (if use-level (gnus-group-group-level) nil))
  7539.     (gnus-group-group-name))))
  7540.  
  7541. (defun gnus-summary-best-group (&optional exclude-group)
  7542.   "Find the name of the best unread group.
  7543. If EXCLUDE-GROUP, do not go to this group."
  7544.   (save-excursion
  7545.     (set-buffer gnus-group-buffer)
  7546.     (save-excursion
  7547.       (gnus-group-best-unread-group exclude-group))))
  7548.  
  7549. (defun gnus-subject-equal (s1 s2)
  7550.   (cond
  7551.    ((null gnus-summary-gather-subject-limit)
  7552.     (equal (gnus-simplify-subject-re s1)
  7553.        (gnus-simplify-subject-re s2)))
  7554.    ((eq gnus-summary-gather-subject-limit 'fuzzy)
  7555.     (equal (gnus-simplify-subject-fuzzy s1)
  7556.        (gnus-simplify-subject-fuzzy s2)))
  7557.    ((numberp gnus-summary-gather-subject-limit)
  7558.     (equal (gnus-limit-string s1 gnus-summary-gather-subject-limit)
  7559.        (gnus-limit-string s2 gnus-summary-gather-subject-limit)))
  7560.    (t
  7561.     (equal s1 s2))))
  7562.     
  7563. (defun gnus-summary-search-subject (&optional backward unread subject)
  7564.   "Search for article forward.
  7565. If BACKWARD is non-nil, search backward.
  7566. If UNREAD is non-nil, only unread articles are selected.
  7567. If SUBJECT is non-nil, the article which has the same subject will be
  7568. searched for." 
  7569.   (let ((func (if backward 'previous-single-property-change
  7570.         'next-single-property-change))
  7571.     (beg (point))
  7572.     (did t)
  7573.     pos psubject)
  7574.     (beginning-of-line)
  7575.     (and gnus-summary-check-current unread
  7576.      (eq (get-text-property (point) 'gnus-mark) gnus-unread-mark)
  7577.      (setq did nil))
  7578.     (if (not did)
  7579.     ()
  7580.       (forward-char (if backward (if (bobp) 0 -1) (if (eobp) 0 1)))
  7581.       (while
  7582.       (and 
  7583.        (setq pos (funcall func (point) 'gnus-number))
  7584.        (goto-char (if backward (1- pos) pos))
  7585.        (setq did
  7586.          (not (and
  7587.                (or (not unread)
  7588.                (eq (get-text-property (point) 'gnus-mark)
  7589.                    gnus-unread-mark))
  7590.                (or (not subject)
  7591.                (and (setq psubject 
  7592.                       (inline (gnus-summary-subject-string)))
  7593.                 (inline 
  7594.                   (gnus-subject-equal subject psubject)))))))
  7595.        (if backward (if (bobp) nil (forward-char -1) t)
  7596.          (if (eobp) nil (forward-char 1) t)))))
  7597.     (if did
  7598.     (progn (goto-char beg) nil)
  7599.       (prog1
  7600.       (get-text-property (point) 'gnus-number)
  7601.     (gnus-summary-show-thread)
  7602.     (gnus-summary-position-cursor)))))
  7603.  
  7604. (defun gnus-summary-pseudo-article ()
  7605.   "The thread level of the article on the current line."
  7606.   (get-text-property (gnus-point-at-bol) 'gnus-pseudo))
  7607.  
  7608. (defalias 'gnus-summary-score 'gnus-summary-article-score)
  7609. (make-obsolete 'gnus-summary-score 'gnus-summary-article-score)
  7610. (defun gnus-summary-article-score ()
  7611.   "Return current article score."
  7612.   (or (cdr (assq (gnus-summary-article-number) gnus-newsgroup-scored))
  7613.       gnus-summary-default-score 0))
  7614.  
  7615. (defun gnus-summary-recenter ()
  7616.   "Center point in the summary window.
  7617. If `gnus-auto-center-summary' is nil, or the article buffer isn't
  7618. displayed, no centering will be performed." 
  7619.   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
  7620.   ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
  7621.   (let* ((top (cond ((< (window-height) 4) 0)
  7622.             ((< (window-height) 7) 1)
  7623.             (t 2)))
  7624.      (height (1- (window-height)))
  7625.      (bottom (save-excursion (goto-char (point-max))
  7626.                  (forward-line (- height))
  7627.                  (point)))
  7628.      (window (get-buffer-window (current-buffer))))
  7629.     (and 
  7630.      ;; The user has to want it,
  7631.      gnus-auto-center-summary 
  7632.      ;; the article buffer must be displayed,
  7633.      (get-buffer-window gnus-article-buffer)
  7634.      ;; Set the window start to either `bottom', which is the biggest
  7635.      ;; possible valid number, or the second line from the top,
  7636.      ;; whichever is the least.
  7637.      (set-window-start
  7638.       window (min bottom (save-excursion (forward-line (- top)) (point)))))))
  7639.  
  7640. ;; Function written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
  7641. (defun gnus-short-group-name (group &optional levels)
  7642.   "Collapse GROUP name LEVELS."
  7643.   (let* ((name "") (foreign "") (depth -1) (skip 1)
  7644.      (levels (or levels
  7645.              (progn
  7646.                (while (string-match "\\." group skip)
  7647.              (setq skip (match-end 0)
  7648.                    depth (+ depth 1)))
  7649.                depth))))
  7650.     (if (string-match ":" group)
  7651.     (setq foreign (substring group 0 (match-end 0))
  7652.           group (substring group (match-end 0))))
  7653.     (while group
  7654.       (if (and (string-match "\\." group) (> levels 0))
  7655.       (setq name (concat name (substring group 0 1))
  7656.         group (substring group (match-end 0))
  7657.         levels (- levels 1)
  7658.         name (concat name "."))
  7659.     (setq name (concat foreign name group)
  7660.           group nil)))
  7661.     name))
  7662.  
  7663. (defun gnus-summary-jump-to-group (newsgroup)
  7664.   "Move point to NEWSGROUP in group mode buffer."
  7665.   ;; Keep update point of group mode buffer if visible.
  7666.   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
  7667.       (save-window-excursion
  7668.     ;; Take care of tree window mode.
  7669.     (if (get-buffer-window gnus-group-buffer)
  7670.         (pop-to-buffer gnus-group-buffer))
  7671.     (gnus-group-jump-to-group newsgroup))
  7672.     (save-excursion
  7673.       ;; Take care of tree window mode.
  7674.       (if (get-buffer-window gnus-group-buffer)
  7675.       (pop-to-buffer gnus-group-buffer)
  7676.     (set-buffer gnus-group-buffer))
  7677.       (gnus-group-jump-to-group newsgroup))))
  7678.  
  7679. ;; This function returns a list of article numbers based on the
  7680. ;; difference between the ranges of read articles in this group and
  7681. ;; the range of active articles.
  7682. (defun gnus-list-of-unread-articles (group)
  7683.   (let* ((read (nth 2 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
  7684.      (active (gnus-gethash group gnus-active-hashtb))
  7685.      (last (cdr active))
  7686.      first nlast unread)
  7687.     ;; If none are read, then all are unread. 
  7688.     (if (not read)
  7689.     (setq first (car active))
  7690.       ;; If the range of read articles is a single range, then the
  7691.       ;; first unread article is the article after the last read
  7692.       ;; article. Sounds logical, doesn't it?
  7693.       (if (not (listp (cdr read)))
  7694.       (setq first (1+ (cdr read)))
  7695.     ;; `read' is a list of ranges.
  7696.     (if (/= (setq nlast (or (and (numberp (car read)) (car read)) 
  7697.                 (car (car read)))) 1)
  7698.         (setq first 1))
  7699.     (while read
  7700.       (if first 
  7701.           (while (< first nlast)
  7702.         (setq unread (cons first unread))
  7703.         (setq first (1+ first))))
  7704.       (setq first (1+ (if (atom (car read)) (car read) (cdr (car read)))))
  7705.       (setq nlast (if (atom (car (cdr read))) 
  7706.               (car (cdr read))
  7707.             (car (car (cdr read)))))
  7708.       (setq read (cdr read)))))
  7709.     ;; And add the last unread articles.
  7710.     (while (<= first last)
  7711.       (setq unread (cons first unread))
  7712.       (setq first (1+ first)))
  7713.     ;; Return the list of unread articles.
  7714.     (nreverse unread)))
  7715.  
  7716. (defun gnus-list-of-read-articles (group)
  7717.   (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
  7718.     (active (gnus-gethash group gnus-active-hashtb)))
  7719.     (and info active
  7720.      (gnus-sorted-complement 
  7721.       (gnus-uncompress-range active) 
  7722.       (gnus-list-of-unread-articles group)))))
  7723.  
  7724. ;; Various summary commands
  7725.  
  7726. (defun gnus-summary-universal-argument ()
  7727.   "Perform any operation on all articles marked with the process mark."
  7728.   (interactive)
  7729.   (gnus-set-global-variables)
  7730.   (let ((articles (reverse gnus-newsgroup-processable))
  7731.     func)
  7732.     (or articles (error "No articles marked"))
  7733.     (or (setq func (key-binding (read-key-sequence "C-c C-u")))
  7734.     (error "Undefined key"))
  7735.     (while articles
  7736.       (gnus-summary-goto-subject (car articles))
  7737.       (command-execute func)
  7738.       (gnus-summary-remove-process-mark (car articles))
  7739.       (setq articles (cdr articles)))))
  7740.  
  7741. (defun gnus-summary-toggle-truncation (&optional arg)
  7742.   "Toggle truncation of summary lines.
  7743. With arg, turn line truncation on iff arg is positive."
  7744.   (interactive "P")
  7745.   (setq truncate-lines
  7746.     (if (null arg) (not truncate-lines)
  7747.       (> (prefix-numeric-value arg) 0)))
  7748.   (redraw-display))
  7749.  
  7750. (defun gnus-summary-reselect-current-group (&optional all)
  7751.   "Once exit and then reselect the current newsgroup.
  7752. The prefix argument ALL means to select all articles."
  7753.   (interactive "P")
  7754.   (gnus-set-global-variables)
  7755.   (let ((current-subject (gnus-summary-article-number))
  7756.     (group gnus-newsgroup-name))
  7757.     (setq gnus-newsgroup-begin nil)
  7758.     (gnus-summary-exit t)
  7759.     ;; We have to adjust the point of group mode buffer because the
  7760.     ;; current point was moved to the next unread newsgroup by
  7761.     ;; exiting.
  7762.     (gnus-summary-jump-to-group group)
  7763.     (gnus-group-read-group all t)
  7764.     (gnus-summary-goto-subject current-subject)))
  7765.  
  7766. (defun gnus-summary-rescan-group (&optional all)
  7767.   "Exit the newsgroup, ask for new articles, and select the newsgroup."
  7768.   (interactive "P")
  7769.   (gnus-set-global-variables)
  7770.   ;; Fix by Ilja Weis <kult@uni-paderborn.de>.
  7771.   (let ((group gnus-newsgroup-name))
  7772.     (gnus-summary-exit)
  7773.     (gnus-summary-jump-to-group group)
  7774.     (save-excursion
  7775.       (set-buffer gnus-group-buffer)
  7776.       (gnus-group-get-new-news-this-group 1))
  7777.     (gnus-summary-jump-to-group group)
  7778.     (gnus-group-read-group all)))
  7779.  
  7780. (defun gnus-summary-update-info ()
  7781.   (let* ((group gnus-newsgroup-name))
  7782.     (if gnus-newsgroup-kill-headers
  7783.     (setq gnus-newsgroup-killed
  7784.           (gnus-compress-sequence
  7785.            (nconc
  7786.         (gnus-set-sorted-intersection
  7787.          (gnus-uncompress-range gnus-newsgroup-killed)
  7788.          (setq gnus-newsgroup-unselected
  7789.                (sort gnus-newsgroup-unselected '<)))
  7790.         (setq gnus-newsgroup-unreads
  7791.               (sort gnus-newsgroup-unreads '<))) t)))
  7792.     (or (listp (cdr gnus-newsgroup-killed))
  7793.     (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
  7794.     (let ((headers gnus-newsgroup-headers))
  7795.       (gnus-close-group group)
  7796.       (run-hooks 'gnus-exit-group-hook)
  7797.       (gnus-update-read-articles 
  7798.        group gnus-newsgroup-unreads gnus-newsgroup-unselected 
  7799.        gnus-newsgroup-marked
  7800.        t gnus-newsgroup-replied gnus-newsgroup-expirable
  7801.        gnus-newsgroup-killed gnus-newsgroup-dormant
  7802.        gnus-newsgroup-bookmarks 
  7803.        (and gnus-save-score gnus-newsgroup-scored))
  7804.       (and gnus-use-cross-reference
  7805.        (gnus-mark-xrefs-as-read 
  7806.         group headers gnus-newsgroup-unreads gnus-newsgroup-expirable))
  7807.       ;; Do adaptive scoring, and possibly save score files.
  7808.       (and gnus-newsgroup-adaptive
  7809.        (gnus-score-adaptive))
  7810.       (and gnus-use-scoring 
  7811.        (fboundp 'gnus-score-save)
  7812.        (funcall 'gnus-score-save))
  7813.       ;; Do not switch windows but change the buffer to work.
  7814.       (set-buffer gnus-group-buffer)
  7815.       (or (gnus-ephemeral-group-p gnus-newsgroup-name)
  7816.       (gnus-group-update-group group)))))
  7817.   
  7818. (defun gnus-summary-exit (&optional temporary)
  7819.   "Exit reading current newsgroup, and then return to group selection mode.
  7820. gnus-exit-group-hook is called with no arguments if that value is non-nil."
  7821.   (interactive)
  7822.   (gnus-set-global-variables)
  7823.   (gnus-kill-save-kill-buffer)
  7824.   (let* ((group gnus-newsgroup-name)
  7825.      (quit-config (gnus-group-quit-config gnus-newsgroup-name))
  7826.      (mode major-mode)
  7827.      (buf (current-buffer)))
  7828.     (run-hooks 'gnus-summary-prepare-exit-hook)
  7829.     ;; Make all changes in this group permanent.
  7830.     (gnus-summary-update-info)        
  7831.     (set-buffer buf)
  7832.     (and gnus-use-cache (gnus-cache-possibly-remove-articles))
  7833.     ;; Make sure where I was, and go to next newsgroup.
  7834.     (set-buffer gnus-group-buffer)
  7835.     (or quit-config
  7836.     (progn
  7837.       (gnus-group-jump-to-group group)
  7838.       (gnus-group-next-unread-group 1)))
  7839.     (if temporary
  7840.     nil                ;Nothing to do.
  7841.       ;; We set all buffer-local variables to nil. It is unclear why
  7842.       ;; this is needed, but if we don't, buffer-local variables are
  7843.       ;; not garbage-collected, it seems. This would the lead to en
  7844.       ;; ever-growing Emacs.
  7845.       (set-buffer buf)
  7846.       (gnus-summary-clear-local-variables)
  7847.       ;; We clear the global counterparts of the buffer-local
  7848.       ;; variables as well, just to be on the safe side.
  7849.       (gnus-configure-windows 'group 'force)
  7850.       (gnus-summary-clear-local-variables)
  7851.       ;; Return to group mode buffer. 
  7852.       (if (eq mode 'gnus-summary-mode)
  7853.       (gnus-kill-buffer buf))
  7854.       (if (get-buffer gnus-article-buffer)
  7855.       (bury-buffer gnus-article-buffer))
  7856.       (setq gnus-current-select-method gnus-select-method)
  7857.       (pop-to-buffer gnus-group-buffer)
  7858.       (if (not quit-config)
  7859.       (progn
  7860.         (gnus-group-jump-to-group group)
  7861.         (gnus-group-next-unread-group 1))
  7862.     (if (not (buffer-name (car quit-config)))
  7863.         (gnus-configure-windows 'group 'force)
  7864.       (set-buffer (car quit-config))
  7865.       (and (eq major-mode 'gnus-summary-mode)
  7866.            (gnus-set-global-variables))
  7867.       (gnus-configure-windows (cdr quit-config))))
  7868.       (run-hooks 'gnus-summary-exit-hook))))
  7869.  
  7870. (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
  7871. (defun gnus-summary-exit-no-update (&optional no-questions)
  7872.   "Quit reading current newsgroup without updating read article info."
  7873.   (interactive)
  7874.   (gnus-set-global-variables)
  7875.   (let* ((group gnus-newsgroup-name)
  7876.      (quit-config (gnus-group-quit-config group)))
  7877.     (if (or no-questions
  7878.         gnus-expert-user
  7879.         (gnus-y-or-n-p "Do you really wanna quit reading this group? "))
  7880.     (progn
  7881.       (gnus-close-group group)
  7882.       (gnus-summary-clear-local-variables)
  7883.       (set-buffer gnus-group-buffer)
  7884.       (gnus-summary-clear-local-variables)
  7885.       ;; Return to group selection mode.
  7886.       (gnus-configure-windows 'group 'force)
  7887.       (if (get-buffer gnus-summary-buffer)
  7888.           (kill-buffer gnus-summary-buffer))
  7889.       (if (get-buffer gnus-article-buffer)
  7890.           (bury-buffer gnus-article-buffer))
  7891.       (if (equal (gnus-group-group-name) group)
  7892.           (gnus-group-next-unread-group 1))
  7893.       (if quit-config
  7894.           (progn
  7895.         (if (not (buffer-name (car quit-config)))
  7896.             (gnus-configure-windows 'group 'force)
  7897.           (set-buffer (car quit-config))
  7898.           (and (eq major-mode 'gnus-summary-mode)
  7899.                (gnus-set-global-variables))
  7900.           (gnus-configure-windows (cdr quit-config)))))))))
  7901.  
  7902. ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
  7903. (defun gnus-summary-fetch-faq (group)
  7904.   "Fetch the FAQ for the current group."
  7905.   (interactive (list gnus-newsgroup-name))
  7906.   (let (gnus-faq-buffer)
  7907.     (and (setq gnus-faq-buffer (gnus-group-fetch-faq group))
  7908.      (gnus-configure-windows 'summary-faq))))
  7909.  
  7910. ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
  7911. (defun gnus-summary-describe-group (&optional force)
  7912.   "Describe the current newsgroup."
  7913.   (interactive "P")
  7914.   (gnus-group-describe-group force gnus-newsgroup-name))
  7915.  
  7916. (defun gnus-summary-describe-briefly ()
  7917.   "Describe summary mode commands briefly."
  7918.   (interactive)
  7919.   (gnus-message 6
  7920.         (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select  \\[gnus-summary-next-unread-article]:Forward  \\[gnus-summary-prev-unread-article]:Backward  \\[gnus-summary-exit]:Exit  \\[gnus-info-find-node]:Run Info  \\[gnus-summary-describe-briefly]:This help")))
  7921.  
  7922. ;; Walking around group mode buffer from summary mode.
  7923.  
  7924. (defun gnus-summary-next-group (&optional no-article target-group backward)
  7925.   "Exit current newsgroup and then select next unread newsgroup.
  7926. If prefix argument NO-ARTICLE is non-nil, no article is selected
  7927. initially. If NEXT-GROUP, go to this group. If BACKWARD, go to
  7928. previous group instead."
  7929.   (interactive "P")
  7930.   (gnus-set-global-variables)
  7931.   (let ((current-group gnus-newsgroup-name)
  7932.     (current-buffer (current-buffer))
  7933.     entered)
  7934.     ;; First we semi-exit this group to update Xrefs and all variables.
  7935.     ;; We can't do a real exit, because the window conf must remain
  7936.     ;; the same in case the user is prompted for info, and we don't
  7937.     ;; want the window conf to change before that...
  7938.     (gnus-summary-exit t)
  7939.     (while (not entered)
  7940.       ;; Then we find what group we are supposed to enter.
  7941.       (set-buffer gnus-group-buffer)
  7942.       (gnus-group-jump-to-group current-group)
  7943.       (setq target-group 
  7944.         (or target-group         
  7945.         (if (eq gnus-keep-same-level 'best) 
  7946.             (gnus-summary-best-group gnus-newsgroup-name)
  7947.           (gnus-summary-search-group backward gnus-keep-same-level))))
  7948.       (if (not target-group)
  7949.       ;; There are no further groups, so we return to the group
  7950.       ;; buffer.
  7951.       (progn
  7952.         (gnus-message 5 "Returning to the group buffer")
  7953.         (setq entered t)
  7954.         (set-buffer current-buffer)
  7955.         (gnus-summary-exit))
  7956.     ;; We try to enter the target group.
  7957.     (gnus-group-jump-to-group target-group)
  7958.     (let ((unreads (gnus-group-group-unread)))
  7959.       (if (and (or (eq t unreads)
  7960.                (and unreads (not (zerop unreads))))
  7961.            (gnus-summary-read-group
  7962.             target-group nil no-article current-buffer))
  7963.           (setq entered t)
  7964.         (setq current-group target-group
  7965.           target-group nil)))))))
  7966.  
  7967. (defun gnus-summary-next-group-old (&optional no-article group backward)
  7968.   "Exit current newsgroup and then select next unread newsgroup.
  7969. If prefix argument NO-ARTICLE is non-nil, no article is selected initially.
  7970. If BACKWARD, go to previous group instead."
  7971.   (interactive "P")
  7972.   (gnus-set-global-variables)
  7973.   (let ((ingroup gnus-newsgroup-name)
  7974.     (sumbuf (current-buffer))
  7975.     num)
  7976.     (set-buffer gnus-group-buffer)
  7977.     (if (and group
  7978.          (or (and (numberp (setq num (car (gnus-gethash
  7979.                            group gnus-newsrc-hashtb))))
  7980.               (< num 1))
  7981.          (null num)))
  7982.     (progn
  7983.       (gnus-group-jump-to-group group)
  7984.       (setq group nil))
  7985.       (gnus-group-jump-to-group ingroup))
  7986.     (gnus-summary-search-group backward)
  7987.     (let ((group (or group (gnus-summary-search-group backward))))
  7988.       (set-buffer sumbuf)
  7989.       (gnus-summary-exit t)        ;Update all information.
  7990.       (if (null group)
  7991.       (gnus-summary-exit-no-update t)
  7992.     (gnus-group-jump-to-group ingroup)
  7993.     (setq group (gnus-summary-search-group backward))
  7994.     (gnus-message 5 "Selecting %s..." group)
  7995.     (set-buffer gnus-group-buffer)
  7996.     ;; We are now in group mode buffer.
  7997.     ;; Make sure group mode buffer point is on GROUP.
  7998.     (gnus-group-jump-to-group group)
  7999.     (if (not (eq gnus-auto-select-next 'quietly))
  8000.         (progn
  8001.           (gnus-summary-read-group group nil no-article sumbuf)
  8002.           (and (string= gnus-newsgroup-name ingroup)
  8003.            (bufferp sumbuf) (buffer-name sumbuf)
  8004.            (progn
  8005.              (set-buffer (setq gnus-summary-buffer sumbuf))
  8006.              (gnus-summary-exit-no-update t))))
  8007.       (let ((prevgroup group))
  8008.         (gnus-group-jump-to-group ingroup)
  8009.         (setq group (gnus-summary-search-group backward))
  8010.         (gnus-summary-read-group group nil no-article sumbuf)
  8011.         (while (and (string= gnus-newsgroup-name ingroup)
  8012.             (bufferp sumbuf) 
  8013.             (buffer-name sumbuf)
  8014.             (not (string= prevgroup (gnus-group-group-name))))
  8015.           (set-buffer gnus-group-buffer)
  8016.           (gnus-summary-read-group 
  8017.            (setq prevgroup (gnus-group-group-name)) 
  8018.            nil no-article sumbuf))
  8019.         (and (string= prevgroup (gnus-group-group-name))
  8020.          ;; We have reached the final group in the group
  8021.          ;; buffer.
  8022.          (progn
  8023.            (if (buffer-name sumbuf)
  8024.                (progn
  8025.              (set-buffer sumbuf)
  8026.              (gnus-summary-exit)))))))))))
  8027.  
  8028. (defun gnus-summary-prev-group (&optional no-article)
  8029.   "Exit current newsgroup and then select previous unread newsgroup.
  8030. If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
  8031.   (interactive "P")
  8032.   (gnus-summary-next-group no-article nil t))
  8033.  
  8034. ;; Walking around summary lines.
  8035.  
  8036. (defun gnus-summary-first-subject (&optional unread)
  8037.   "Go to the first unread subject.
  8038. If UNREAD is non-nil, go to the first unread article.
  8039. Returns nil if there are no unread articles."
  8040.   (interactive "P")
  8041.   (prog1
  8042.       (cond ((not unread)
  8043.          (goto-char (point-min)))
  8044.         ((gnus-goto-char 
  8045.           (text-property-any 
  8046.            (point-min) (point-max) 'gnus-mark gnus-unread-mark))
  8047.          t)
  8048.         (t 
  8049.          ;; There are no unread articles.
  8050.          (gnus-message 3 "No more unread articles")
  8051.          nil))
  8052.     (gnus-summary-position-cursor)))
  8053.  
  8054. (defun gnus-summary-next-subject (n &optional unread dont-display)
  8055.   "Go to next N'th summary line.
  8056. If N is negative, go to the previous N'th subject line.
  8057. If UNREAD is non-nil, only unread articles are selected.
  8058. The difference between N and the actual number of steps taken is
  8059. returned."
  8060.   (interactive "p")
  8061.   (let ((backward (< n 0))
  8062.     (n (abs n)))
  8063.     (while (and (> n 0)
  8064.         (gnus-summary-search-forward unread nil backward))
  8065.       (setq n (1- n)))
  8066.     (if (/= 0 n) (gnus-message 7 "No more%s articles"
  8067.                    (if unread " unread" "")))
  8068.     (or dont-display
  8069.     (progn
  8070.       (gnus-summary-recenter)
  8071.       (gnus-summary-position-cursor)))
  8072.     n))
  8073.  
  8074. (defun gnus-summary-next-unread-subject (n)
  8075.   "Go to next N'th unread summary line."
  8076.   (interactive "p")
  8077.   (gnus-summary-next-subject n t))
  8078.  
  8079. (defun gnus-summary-prev-subject (n &optional unread)
  8080.   "Go to previous N'th summary line.
  8081. If optional argument UNREAD is non-nil, only unread article is selected."
  8082.   (interactive "p")
  8083.   (gnus-summary-next-subject (- n) unread))
  8084.  
  8085. (defun gnus-summary-prev-unread-subject (n)
  8086.   "Go to previous N'th unread summary line."
  8087.   (interactive "p")
  8088.   (gnus-summary-next-subject (- n) t))
  8089.  
  8090. (defun gnus-summary-goto-subject (article)
  8091.   "Go the subject line of ARTICLE."
  8092.   (interactive
  8093.    (list
  8094.     (string-to-int
  8095.      (completing-read "Article number: "
  8096.               (mapcar
  8097.                (lambda (headers)
  8098.              (list
  8099.               (int-to-string (mail-header-number headers))))
  8100.                gnus-newsgroup-headers)
  8101.               nil 'require-match))))
  8102.   (or article (error "No article number"))
  8103.   (let ((b (point)))
  8104.     (if (not (gnus-goto-char (text-property-any (point-min) (point-max)
  8105.                         'gnus-number article)))
  8106.     ()
  8107.       (gnus-summary-show-thread)
  8108.       ;; Skip dummy articles. 
  8109.       (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
  8110.       (forward-line 1))
  8111.       (prog1
  8112.       (if (not (eobp))
  8113.           article
  8114.         (goto-char b)
  8115.         nil)
  8116.     (gnus-summary-position-cursor)))))
  8117.  
  8118. ;; Walking around summary lines with displaying articles.
  8119.  
  8120. (defun gnus-summary-expand-window (&optional arg)
  8121.   "Make the summary buffer take up the entire Emacs frame.
  8122. Given a prefix, will force an `article' buffer configuration."
  8123.   (interactive "P")
  8124.   (gnus-set-global-variables)
  8125.   (if arg
  8126.       (gnus-configure-windows 'article 'force)
  8127.     (gnus-configure-windows 'summary 'force)))
  8128.  
  8129. (defun gnus-summary-display-article (article &optional all-header)
  8130.   "Display ARTICLE in article buffer."
  8131.   (gnus-set-global-variables)
  8132.   (if (null article)
  8133.       nil
  8134.     (prog1
  8135.     (gnus-article-prepare article all-header)
  8136.       (gnus-summary-show-thread)
  8137.       (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
  8138.       (progn
  8139.         (forward-line 1)
  8140.         (gnus-summary-position-cursor)))
  8141.       (run-hooks 'gnus-select-article-hook)
  8142.       (gnus-summary-recenter)
  8143.       (gnus-summary-goto-subject article)
  8144.       ;; Successfully display article.
  8145.       (gnus-summary-update-line)
  8146.       (gnus-article-set-window-start 
  8147.        (cdr (assq article gnus-newsgroup-bookmarks)))
  8148.       t)))
  8149.  
  8150. (defun gnus-summary-select-article (&optional all-headers force pseudo article)
  8151.   "Select the current article.
  8152. If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
  8153. non-nil, the article will be re-fetched even if it already present in
  8154. the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
  8155. be displayed."
  8156.   (and (not pseudo) (gnus-summary-pseudo-article)
  8157.        (error "This is a pseudo-article."))
  8158.   (let ((article (or article (gnus-summary-article-number)))
  8159.     (all-headers (not (not all-headers))) ;Must be T or NIL.
  8160.     did) 
  8161.     (prog1
  8162.     (save-excursion
  8163.       (set-buffer gnus-summary-buffer)
  8164.       (if (or (null gnus-current-article)
  8165.           (null gnus-article-current)
  8166.           (null (get-buffer gnus-article-buffer))
  8167.           (not (eq article (cdr gnus-article-current)))
  8168.           (not (equal (car gnus-article-current) gnus-newsgroup-name))
  8169.           force)
  8170.           ;; The requested article is different from the current article.
  8171.           (progn
  8172.         (gnus-summary-display-article article all-headers)
  8173.         (setq did article))
  8174.         (if (or all-headers gnus-show-all-headers) 
  8175.         (gnus-article-show-all-headers))
  8176.         nil))
  8177.       (if did 
  8178.       (gnus-article-set-window-start 
  8179.        (cdr (assq article gnus-newsgroup-bookmarks)))))))
  8180.  
  8181. (defun gnus-summary-set-current-mark (&optional current-mark)
  8182.   "Obsolete function."
  8183.   nil)
  8184.  
  8185. (defun gnus-summary-next-article (&optional unread subject backward)
  8186.   "Select the next article.
  8187. If UNREAD, only unread articles are selected.
  8188. If SUBJECT, only articles with SUBJECT are selected.
  8189. If BACKWARD, the previous article is selected instead of the next."
  8190.   (interactive "P")
  8191.   (gnus-set-global-variables)
  8192.   (let (header)
  8193.     (cond
  8194.      ;; Is there such an article?
  8195.      ((and (gnus-summary-search-forward unread subject backward)
  8196.        (or (gnus-summary-display-article (gnus-summary-article-number))
  8197.            (eq (gnus-summary-article-mark) gnus-canceled-mark)))
  8198.       (gnus-summary-position-cursor))
  8199.      ;; If not, we try the first unread, if that is wanted.
  8200.      ((and subject
  8201.        gnus-auto-select-same
  8202.        (or (gnus-summary-first-unread-article)
  8203.            (eq (gnus-summary-article-mark) gnus-canceled-mark)))
  8204.       (gnus-summary-position-cursor)
  8205.       (gnus-message 6 "Wrapped"))
  8206.      ;; Try to get next/previous article not displayed in this group.
  8207.      ((and gnus-auto-extend-newsgroup
  8208.        (not unread) (not subject)
  8209.        (setq header (gnus-more-header-forward backward)))
  8210.       (gnus-extend-newsgroup header backward)
  8211.       (let ((buffer-read-only nil))
  8212.     (goto-char (if backward (point-min) (point-max)))
  8213.     (gnus-summary-prepare-threads (list header)))
  8214.       (gnus-summary-goto-article (if backward gnus-newsgroup-begin
  8215.                    gnus-newsgroup-end)))
  8216.      ;; Go to next/previous group.
  8217.      (t
  8218.       (or (gnus-ephemeral-group-p gnus-newsgroup-name)
  8219.       (gnus-summary-jump-to-group gnus-newsgroup-name))
  8220.       (let ((cmd last-command-char)
  8221.         (group 
  8222.          (if (eq gnus-keep-same-level 'best) 
  8223.          (gnus-summary-best-group gnus-newsgroup-name)
  8224.            (gnus-summary-search-group backward gnus-keep-same-level))))
  8225.     ;; For some reason, the group window gets selected. We change
  8226.     ;; it back.  
  8227.     (select-window (get-buffer-window (current-buffer)))
  8228.     ;; Keep just the event type of CMD.
  8229.                     ;(and (listp cmd) (setq cmd (car cmd)))
  8230.     ;; Select next unread newsgroup automagically.
  8231.     (cond 
  8232.      ((not gnus-auto-select-next)
  8233.       (gnus-message 7 "No more%s articles" (if unread " unread" "")))
  8234.      ((eq gnus-auto-select-next 'quietly)
  8235.       ;; Select quietly.
  8236.       (if (gnus-ephemeral-group-p gnus-newsgroup-name)
  8237.           (gnus-summary-exit)
  8238.         (gnus-message 7 "No more%s articles (%s)..."
  8239.               (if unread " unread" "") 
  8240.               (if group (concat "selecting " group)
  8241.                 "exiting"))
  8242.         (gnus-summary-next-group nil group backward)))
  8243.      (t
  8244.       (let ((keystrokes '(?\C-n ?\C-p))
  8245.         key)
  8246.         (while (or (null key) (memq key keystrokes))
  8247.           (gnus-message 
  8248.            7 "No more%s articles%s" (if unread " unread" "")
  8249.            (if (and group 
  8250.             (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
  8251.            (format " (Type %s for %s [%s])"
  8252.                (single-key-description cmd) group
  8253.                (car (gnus-gethash group gnus-newsrc-hashtb)))
  8254.          (format " (Type %s to exit %s)"
  8255.              (single-key-description cmd)
  8256.              gnus-newsgroup-name)))
  8257.           ;; Confirm auto selection.
  8258.           (let* ((event (read-char)))
  8259.         (setq key (if (listp event) (car event) event))
  8260.         (if (memq key keystrokes)
  8261.             (let ((obuf (current-buffer)))
  8262.               (switch-to-buffer gnus-group-buffer)
  8263.               (and group
  8264.                (gnus-group-jump-to-group group))
  8265.               (condition-case ()
  8266.               (execute-kbd-macro (char-to-string key))
  8267.             (error (ding) nil))
  8268.               (setq group (gnus-group-group-name))
  8269.               (switch-to-buffer obuf)))))
  8270.         (if (equal key cmd)
  8271.         (if (or (not group)
  8272.             (gnus-ephemeral-group-p gnus-newsgroup-name))
  8273.             (gnus-summary-exit)
  8274.           (gnus-summary-next-group nil group backward))
  8275.           (execute-kbd-macro (char-to-string key)))))))))))
  8276.  
  8277. (defun gnus-summary-next-unread-article ()
  8278.   "Select unread article after current one."
  8279.   (interactive)
  8280.   (gnus-summary-next-article t (and gnus-auto-select-same
  8281.                     (gnus-summary-subject-string))))
  8282.  
  8283. (defun gnus-summary-prev-article (&optional unread subject)
  8284.   "Select the article after the current one.
  8285. If UNREAD is non-nil, only unread articles are selected."
  8286.   (interactive "P")
  8287.   (gnus-summary-next-article unread subject t))
  8288.  
  8289. (defun gnus-summary-prev-unread-article ()
  8290.   "Select unred article before current one."
  8291.   (interactive)
  8292.   (gnus-summary-prev-article t (and gnus-auto-select-same
  8293.                     (gnus-summary-subject-string))))
  8294.  
  8295. (defun gnus-summary-next-page (&optional lines circular)
  8296.   "Show next page of selected article.
  8297. If end of article, select next article.
  8298. Argument LINES specifies lines to be scrolled up.
  8299. If CIRCULAR is non-nil, go to the start of the article instead of 
  8300. instead of selecting the next article when reaching the end of the
  8301. current article." 
  8302.   (interactive "P")
  8303.   (setq gnus-summary-buffer (current-buffer))
  8304.   (gnus-set-global-variables)
  8305.   (let ((article (gnus-summary-article-number))
  8306.     (endp nil))
  8307.     (gnus-configure-windows 'article)
  8308.     (if (or (null gnus-current-article)
  8309.         (null gnus-article-current)
  8310.         (/= article (cdr gnus-article-current))
  8311.         (not (equal (car gnus-article-current) gnus-newsgroup-name)))
  8312.     ;; Selected subject is different from current article's.
  8313.     (gnus-summary-display-article article)
  8314.       (gnus-eval-in-buffer-window
  8315.        gnus-article-buffer
  8316.        (setq endp (gnus-article-next-page lines)))
  8317.       (if endp
  8318.        (cond (circular
  8319.           (gnus-summary-beginning-of-article))
  8320.          (lines
  8321.           (gnus-message 3 "End of message"))
  8322.          ((null lines)
  8323.           (gnus-summary-next-unread-article)))))
  8324.     (gnus-summary-recenter)
  8325.     (gnus-summary-position-cursor)))
  8326.  
  8327. (defun gnus-summary-prev-page (&optional lines)
  8328.   "Show previous page of selected article.
  8329. Argument LINES specifies lines to be scrolled down."
  8330.   (interactive "P")
  8331.   (gnus-set-global-variables)
  8332.   (let ((article (gnus-summary-article-number)))
  8333.     (gnus-configure-windows 'article)
  8334.     (if (or (null gnus-current-article)
  8335.         (null gnus-article-current)
  8336.         (/= article (cdr gnus-article-current))
  8337.         (not (equal (car gnus-article-current) gnus-newsgroup-name)))
  8338.     ;; Selected subject is different from current article's.
  8339.     (gnus-summary-display-article article)
  8340.       (gnus-summary-recenter)
  8341.       (gnus-eval-in-buffer-window gnus-article-buffer
  8342.                   (gnus-article-prev-page lines))))
  8343.   (gnus-summary-position-cursor))
  8344.  
  8345. (defun gnus-summary-scroll-up (lines)
  8346.   "Scroll up (or down) one line current article.
  8347. Argument LINES specifies lines to be scrolled up (or down if negative)."
  8348.   (interactive "p")
  8349.   (gnus-set-global-variables)
  8350.   (gnus-configure-windows 'article)
  8351.   (or (gnus-summary-select-article nil nil 'pseudo)
  8352.       (gnus-eval-in-buffer-window 
  8353.        gnus-article-buffer
  8354.        (cond ((> lines 0)
  8355.           (if (gnus-article-next-page lines)
  8356.           (gnus-message 3 "End of message")))
  8357.          ((< lines 0)
  8358.           (gnus-article-prev-page (- lines))))))
  8359.   (gnus-summary-recenter)
  8360.   (gnus-summary-position-cursor))
  8361.  
  8362. (defun gnus-summary-next-same-subject ()
  8363.   "Select next article which has the same subject as current one."
  8364.   (interactive)
  8365.   (gnus-set-global-variables)
  8366.   (gnus-summary-next-article nil (gnus-summary-subject-string)))
  8367.  
  8368. (defun gnus-summary-prev-same-subject ()
  8369.   "Select previous article which has the same subject as current one."
  8370.   (interactive)
  8371.   (gnus-set-global-variables)
  8372.   (gnus-summary-prev-article nil (gnus-summary-subject-string)))
  8373.  
  8374. (defun gnus-summary-next-unread-same-subject ()
  8375.   "Select next unread article which has the same subject as current one."
  8376.   (interactive)
  8377.   (gnus-set-global-variables)
  8378.   (gnus-summary-next-article t (gnus-summary-subject-string)))
  8379.  
  8380. (defun gnus-summary-prev-unread-same-subject ()
  8381.   "Select previous unread article which has the same subject as current one."
  8382.   (interactive)
  8383.   (gnus-set-global-variables)
  8384.   (gnus-summary-prev-article t (gnus-summary-subject-string)))
  8385.  
  8386. (defun gnus-summary-first-unread-article ()
  8387.   "Select the first unread article. 
  8388. Return nil if there are no unread articles."
  8389.   (interactive)
  8390.   (gnus-set-global-variables)
  8391.   (prog1
  8392.       (if (gnus-summary-first-subject t)
  8393.       (progn
  8394.         (gnus-summary-show-thread)
  8395.         (gnus-summary-first-subject t)
  8396.         (gnus-summary-display-article (gnus-summary-article-number))))
  8397.     (gnus-summary-position-cursor)))
  8398.  
  8399. (defun gnus-summary-best-unread-article ()
  8400.   "Select the unread article with the highest score."
  8401.   (interactive)
  8402.   (gnus-set-global-variables)
  8403.   (let ((best -1000000)
  8404.     article score)
  8405.     (save-excursion
  8406.       (or (gnus-summary-first-subject t)
  8407.       (error "No unread articles"))
  8408.       (while 
  8409.       (and
  8410.        (progn
  8411.          (and (> (setq score (gnus-summary-article-score)) best)
  8412.           (setq best score
  8413.             article (gnus-summary-article-number)))
  8414.          t)
  8415.        (gnus-summary-search-subject nil t))))
  8416.     (if (not article)
  8417.     (error "No unread articles")
  8418.       (gnus-summary-goto-article article))
  8419.     (gnus-summary-position-cursor)))
  8420.  
  8421. (defun gnus-summary-goto-article (article &optional all-headers)
  8422.   "Fetch ARTICLE and display it if it exists.
  8423. If ALL-HEADERS is non-nil, no header lines are hidden."
  8424.   (interactive
  8425.    (list
  8426.     (string-to-int
  8427.      (completing-read 
  8428.       "Article number: "
  8429.       (mapcar (lambda (headers) 
  8430.         (list (int-to-string (mail-header-number headers))))
  8431.           gnus-newsgroup-headers) 
  8432.       nil 'require-match))))
  8433.   (prog1
  8434.       (and (gnus-summary-goto-subject article)
  8435.        (gnus-summary-display-article article all-headers))
  8436.     (gnus-summary-position-cursor)))
  8437.  
  8438. (defun gnus-summary-goto-last-article ()
  8439.   "Go to the previously read article."
  8440.   (interactive)
  8441.   (prog1
  8442.       (and gnus-last-article
  8443.        (gnus-summary-goto-article gnus-last-article))
  8444.     (gnus-summary-position-cursor)))
  8445.  
  8446. (defun gnus-summary-pop-article (number)
  8447.   "Pop one article off the history and go to the previous.
  8448. NUMBER articles will be popped off."
  8449.   (interactive "p")
  8450.   (let (to)
  8451.     (setq gnus-newsgroup-history
  8452.       (cdr (setq to (nthcdr number gnus-newsgroup-history))))
  8453.     (if to
  8454.     (gnus-summary-goto-article (car to))
  8455.       (error "Article history empty")))
  8456.   (gnus-summary-position-cursor))
  8457.  
  8458. ;; Summary article oriented commands
  8459.  
  8460. (defun gnus-summary-refer-parent-article (n)
  8461.   "Refer parent article N times.
  8462. The difference between N and the number of articles fetched is returned."
  8463.   (interactive "p")
  8464.   (gnus-set-global-variables)
  8465.   (while 
  8466.       (and 
  8467.        (> n 0)
  8468.        (let ((ref (mail-header-references (gnus-get-header-by-num
  8469.                        (gnus-summary-article-number)))))
  8470.      (if (and ref (not (equal ref ""))
  8471.           (string-match "<[^<>]*>[ \t]*$" ref))
  8472.          (gnus-summary-refer-article 
  8473.           (substring ref (match-beginning 0) (match-end 0)))
  8474.        (gnus-message 1 "No references in article %d"
  8475.              (gnus-summary-article-number))
  8476.        nil)))
  8477.     (setq n (1- n)))
  8478.   (gnus-summary-position-cursor)
  8479.   n)
  8480.     
  8481. (defun gnus-summary-refer-article (message-id)
  8482.   "Refer article specified by MESSAGE-ID.
  8483. NOTE: This command only works with newsgroups that use real or simulated NNTP."
  8484.   (interactive "sMessage-ID: ")
  8485.   (if (or (not (stringp message-id))
  8486.       (zerop (length message-id)))
  8487.       ()
  8488.     ;; Construct the correct Message-ID if necessary.
  8489.     ;; Suggested by tale@pawl.rpi.edu.
  8490.     (or (string-match "^<" message-id)
  8491.     (setq message-id (concat "<" message-id)))
  8492.     (or (string-match ">$" message-id)
  8493.     (setq message-id (concat message-id ">")))
  8494.     (let ((header (car (gnus-gethash (downcase message-id)
  8495.                      gnus-newsgroup-dependencies))))
  8496.       (if header
  8497.       (or (gnus-summary-goto-article (mail-header-number header))
  8498.           ;; The header has been read, but the article had been
  8499.           ;; expunged, so we insert it again.
  8500.           (progn
  8501.         (gnus-summary-insert-line
  8502.          nil header 0 nil gnus-read-mark nil nil
  8503.          (mail-header-subject header))
  8504.         (forward-line -1)
  8505.         (mail-header-number header)))
  8506.     (let ((gnus-override-method gnus-refer-article-method)
  8507.           (gnus-ancient-mark gnus-read-mark)
  8508.           (tmp-point (window-start
  8509.               (get-buffer-window gnus-article-buffer)))
  8510.           number tmp-buf)
  8511.       (and gnus-refer-article-method
  8512.            (gnus-check-server gnus-refer-article-method))
  8513.       ;; Save the old article buffer.
  8514.       (save-excursion
  8515.         (set-buffer (gnus-article-setup-buffer))
  8516.         (gnus-kill-buffer " *temp Article*")
  8517.         (setq tmp-buf (rename-buffer " *temp Article*")))
  8518.       (prog1
  8519.           (if (gnus-article-prepare 
  8520.            message-id nil (gnus-read-header message-id))
  8521.           (progn
  8522.             (setq number (mail-header-number gnus-current-headers))
  8523.             (gnus-rebuild-thread message-id)
  8524.             (gnus-summary-goto-subject number)
  8525.             (if (null gnus-use-full-window)
  8526.             (progn
  8527.               (delete-windows-on tmp-buf)
  8528.               (gnus-configure-windows 'article 'force)))
  8529.             (gnus-summary-recenter)
  8530.             (gnus-article-set-window-start 
  8531.              (cdr (assq number gnus-newsgroup-bookmarks)))
  8532.             (and gnus-visual
  8533.              (run-hooks 'gnus-visual-mark-article-hook))
  8534.             message-id)
  8535.         ;; We restore the old article buffer.
  8536.         (save-excursion
  8537.           (kill-buffer gnus-article-buffer)
  8538.           (set-buffer tmp-buf)
  8539.           (rename-buffer gnus-article-buffer)
  8540.           (let ((buffer-read-only nil))
  8541.             (and tmp-point
  8542.              (set-window-start (get-buffer-window (current-buffer))
  8543.                        tmp-point)))))))))))
  8544.  
  8545. (defun gnus-summary-enter-digest-group ()
  8546.   "Enter a digest group based on the current article."
  8547.   (interactive)
  8548.   (gnus-set-global-variables)
  8549.   (gnus-summary-select-article)
  8550.   ;; We do not want a narrowed article.
  8551.   (gnus-summary-stop-page-breaking)
  8552.   (let ((name (format "%s-%d" 
  8553.               (gnus-group-prefixed-name 
  8554.                gnus-newsgroup-name (list 'nndoc "")) 
  8555.               gnus-current-article))
  8556.     (ogroup gnus-newsgroup-name)
  8557.     (buf (current-buffer)))
  8558.     (if (gnus-group-read-ephemeral-group 
  8559.      name (list 'nndoc name
  8560.             (list 'nndoc-address (get-buffer gnus-article-buffer))
  8561.             '(nndoc-article-type digest))
  8562.      t)
  8563.     (setcdr (nthcdr 4 (nth 2 (gnus-gethash name gnus-newsrc-hashtb)))
  8564.         (list (list (cons 'to-group ogroup))))
  8565.       (switch-to-buffer buf)
  8566.       (gnus-set-global-variables)
  8567.       (gnus-configure-windows 'summary)
  8568.       (gnus-message 3 "Article not a digest?"))))
  8569.  
  8570. (defun gnus-summary-isearch-article ()
  8571.   "Do incremental search forward on current article."
  8572.   (interactive)
  8573.   (gnus-set-global-variables)
  8574.   (gnus-summary-select-article)
  8575.   (gnus-eval-in-buffer-window 
  8576.    gnus-article-buffer (isearch-forward)))
  8577.  
  8578. (defun gnus-summary-search-article-forward (regexp &optional backward)
  8579.   "Search for an article containing REGEXP forward.
  8580. If BACKWARD, search backward instead."
  8581.   (interactive
  8582.    (list (read-string
  8583.       (format "Search article %s (regexp%s): "
  8584.           (if current-prefix-arg "backward" "forward")
  8585.           (if gnus-last-search-regexp
  8586.               (concat ", default " gnus-last-search-regexp)
  8587.             "")))
  8588.      current-prefix-arg))
  8589.   (gnus-set-global-variables)
  8590.   (if (string-equal regexp "")
  8591.       (setq regexp (or gnus-last-search-regexp ""))
  8592.     (setq gnus-last-search-regexp regexp))
  8593.   (if (gnus-summary-search-article regexp backward)
  8594.       (gnus-article-set-window-start 
  8595.        (cdr (assq (gnus-summary-article-number) gnus-newsgroup-bookmarks)))
  8596.     (error "Search failed: \"%s\"" regexp)))
  8597.  
  8598. (defun gnus-summary-search-article-backward (regexp)
  8599.   "Search for an article containing REGEXP backward."
  8600.   (interactive
  8601.    (list (read-string
  8602.       (format "Search article backward (regexp%s): "
  8603.           (if gnus-last-search-regexp
  8604.               (concat ", default " gnus-last-search-regexp)
  8605.             "")))))
  8606.   (gnus-summary-search-article-forward regexp 'backward))
  8607.  
  8608. (defun gnus-summary-search-article (regexp &optional backward)
  8609.   "Search for an article containing REGEXP.
  8610. Optional argument BACKWARD means do search for backward.
  8611. gnus-select-article-hook is not called during the search."
  8612.   (let ((gnus-select-article-hook nil)    ;Disable hook.
  8613.     (gnus-mark-article-hook nil)    ;Inhibit marking as read.
  8614.     (re-search
  8615.      (if backward
  8616.          (function re-search-backward) (function re-search-forward)))
  8617.     (found nil)
  8618.     (last nil))
  8619.     ;; Hidden thread subtrees must be searched for ,too.
  8620.     (gnus-summary-show-all-threads)
  8621.     (if (eobp) (forward-line -1))
  8622.     ;; First of all, search current article.
  8623.     ;; We don't want to read article again from NNTP server nor reset
  8624.     ;; current point.
  8625.     (gnus-summary-select-article)
  8626.     (gnus-message 9 "Searching article: %d..." gnus-current-article)
  8627.     (setq last gnus-current-article)
  8628.     (gnus-eval-in-buffer-window
  8629.      gnus-article-buffer
  8630.      (save-restriction
  8631.        (widen)
  8632.        ;; Begin search from current point.
  8633.        (setq found (funcall re-search regexp nil t))))
  8634.     ;; Then search next articles.
  8635.     (while (and (not found)
  8636.         (gnus-summary-display-article 
  8637.          (gnus-summary-search-subject backward nil nil)))
  8638.       (gnus-message 9 "Searching article: %d..." gnus-current-article)
  8639.       (gnus-eval-in-buffer-window
  8640.        gnus-article-buffer
  8641.        (save-restriction
  8642.      (widen)
  8643.      (goto-char (if backward (point-max) (point-min)))
  8644.      (setq found (funcall re-search regexp nil t)))))
  8645.     (message "")
  8646.     ;; Adjust article pointer.
  8647.     (or (eq last gnus-current-article)
  8648.     (setq gnus-last-article last))
  8649.     ;; Return T if found such article.
  8650.     found))
  8651.  
  8652. (defun gnus-summary-execute-command (header regexp command &optional backward)
  8653.   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
  8654. If HEADER is an empty string (or nil), the match is done on the entire
  8655. article. If BACKWARD (the prefix) is non-nil, search backward instead."
  8656.   (interactive
  8657.    (list (let ((completion-ignore-case t))
  8658.        (completing-read 
  8659.         "Header name: "
  8660.         (mapcar (lambda (string) (list string))
  8661.             '("Number" "Subject" "From" "Lines" "Date"
  8662.               "Message-ID" "Xref" "References"))
  8663.         nil 'require-match))
  8664.      (read-string "Regexp: ")
  8665.      (read-key-sequence "Command: ")
  8666.      current-prefix-arg))
  8667.   (gnus-set-global-variables)
  8668.   ;; Hidden thread subtrees must be searched as well.
  8669.   (gnus-summary-show-all-threads)
  8670.   ;; We don't want to change current point nor window configuration.
  8671.   (save-excursion
  8672.     (save-window-excursion
  8673.       (gnus-message 6 "Executing %s..." (key-description command))
  8674.       ;; We'd like to execute COMMAND interactively so as to give arguments.
  8675.       (gnus-execute header regexp
  8676.             (` (lambda ()
  8677.              (call-interactively '(, (key-binding command)))))
  8678.             backward)
  8679.       (gnus-message 6 "Executing %s...done" (key-description command)))))
  8680.  
  8681. (defun gnus-summary-beginning-of-article ()
  8682.   "Scroll the article back to the beginning."
  8683.   (interactive)
  8684.   (gnus-set-global-variables)
  8685.   (gnus-summary-select-article)
  8686.   (gnus-configure-windows 'article)
  8687.   (gnus-eval-in-buffer-window
  8688.    gnus-article-buffer
  8689.    (widen)
  8690.    (goto-char (point-min))
  8691.    (and gnus-break-pages (gnus-narrow-to-page))))
  8692.  
  8693. (defun gnus-summary-end-of-article ()
  8694.   "Scroll to the end of the article."
  8695.   (interactive)
  8696.   (gnus-set-global-variables)
  8697.   (gnus-summary-select-article)
  8698.   (gnus-configure-windows 'article)
  8699.   (gnus-eval-in-buffer-window 
  8700.    gnus-article-buffer
  8701.    (widen)
  8702.    (goto-char (point-max))
  8703.    (recenter -3)
  8704.    (and gnus-break-pages (gnus-narrow-to-page))))
  8705.  
  8706. (defun gnus-summary-show-article ()
  8707.   "Force re-fetching of the current article."
  8708.   (interactive)
  8709.   (gnus-set-global-variables)
  8710.   (gnus-summary-select-article nil 'force)
  8711.   (gnus-configure-windows 'article)
  8712.   (gnus-summary-position-cursor))
  8713.  
  8714. (defun gnus-summary-verbose-headers (&optional arg)
  8715.   "Toggle permanent full header display.
  8716. If ARG is a positive number, turn header display on.
  8717. If ARG is a negative number, turn header display off."
  8718.   (interactive "P")
  8719.   (gnus-set-global-variables)
  8720.   (gnus-summary-toggle-header arg)
  8721.   (setq gnus-show-all-headers
  8722.     (cond ((or (not (numberp arg))
  8723.            (zerop arg))
  8724.            (not gnus-show-all-headers))
  8725.           ((natnump arg)
  8726.            t))))
  8727.  
  8728. (defun gnus-summary-toggle-header (&optional arg)
  8729.   "Show the headers if they are hidden, or hide them if they are shown.
  8730. If ARG is a positive number, show the entire header.
  8731. If ARG is a negative number, hide the unwanted header lines."
  8732.   (interactive "P")
  8733.   (gnus-set-global-variables)
  8734.   (save-excursion
  8735.     (set-buffer gnus-article-buffer)
  8736.     (let ((buffer-read-only nil))
  8737.       (if (numberp arg) 
  8738.       (if (> arg 0) (remove-text-properties (point-min) (point-max) 
  8739.                         gnus-hidden-properties)
  8740.         (if (< arg 0) (run-hooks 'gnus-article-display-hook)))
  8741.     (if (text-property-any (point-min) (point-max) 'invisible t)
  8742.         (remove-text-properties 
  8743.          (point-min) (point-max) gnus-hidden-properties)
  8744.       ;; We hide the headers. This song and dance act below is
  8745.       ;; done because `gnus-have-all-headers' is buffer-local to
  8746.       ;; the summary buffer, and we only want to temporarily
  8747.       ;; change it in that buffer. Ugh.
  8748.       (let ((have gnus-have-all-headers))
  8749.         (save-excursion
  8750.           (set-buffer gnus-summary-buffer)
  8751.           (setq gnus-have-all-headers nil)
  8752.           (save-excursion
  8753.         (set-buffer gnus-article-buffer)
  8754.         (run-hooks 'gnus-article-display-hook))
  8755.           (setq gnus-have-all-headers have)))))
  8756.       (set-window-point (get-buffer-window (current-buffer)) (point-min)))))
  8757.  
  8758. (defun gnus-summary-show-all-headers ()
  8759.   "Make all header lines visible."
  8760.   (interactive)
  8761.   (gnus-set-global-variables)
  8762.   (gnus-article-show-all-headers))
  8763.  
  8764. (defun gnus-summary-toggle-mime (&optional arg)
  8765.   "Toggle MIME processing.
  8766. If ARG is a positive number, turn MIME processing on."
  8767.   (interactive "P")
  8768.   (gnus-set-global-variables)
  8769.   (setq gnus-show-mime
  8770.     (if (null arg) (not gnus-show-mime)
  8771.       (> (prefix-numeric-value arg) 0)))
  8772.   (gnus-summary-select-article t 'force))
  8773.  
  8774. (defun gnus-summary-caesar-message (&optional arg)
  8775.   "Caesar rotate the current article by 13.
  8776. The numerical prefix specifies how manu places to rotate each letter
  8777. forward."
  8778.   (interactive "P")
  8779.   (gnus-set-global-variables)
  8780.   (gnus-summary-select-article)
  8781.   (let ((mail-header-separator ""))
  8782.     (gnus-eval-in-buffer-window 
  8783.      gnus-article-buffer
  8784.      (save-restriction
  8785.        (widen)
  8786.        (let ((start (window-start)))
  8787.      (news-caesar-buffer-body arg)
  8788.      (set-window-start (get-buffer-window (current-buffer)) start))))))
  8789.  
  8790. (defun gnus-summary-stop-page-breaking ()
  8791.   "Stop page breaking in the current article."
  8792.   (interactive)
  8793.   (gnus-set-global-variables)
  8794.   (gnus-summary-select-article)
  8795.   (gnus-eval-in-buffer-window gnus-article-buffer (widen)))
  8796.  
  8797. ;; Suggested by Brian Edmonds <bedmonds@prodigy.bc.ca>.
  8798.  
  8799. (defun gnus-summary-move-article (&optional n to-newsgroup select-method)
  8800.   "Move the current article to a different newsgroup.
  8801. If N is a positive number, move the N next articles.
  8802. If N is a negative number, move the N previous articles.
  8803. If N is nil and any articles have been marked with the process mark,
  8804. move those articles instead.
  8805. If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. 
  8806. If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
  8807. re-spool using this method.
  8808. For this function to work, both the current newsgroup and the
  8809. newsgroup that you want to move to have to support the `request-move'
  8810. and `request-accept' functions. (Ie. mail newsgroups at present.)"
  8811.   (interactive "P")
  8812.   (gnus-set-global-variables)
  8813.   (or (gnus-check-backend-function 'request-move-article gnus-newsgroup-name)
  8814.       (error "The current newsgroup does not support article moving"))
  8815.   (let ((articles (gnus-summary-work-articles n))
  8816.     (prefix (gnus-group-real-prefix gnus-newsgroup-name))
  8817.     art-group to-method sel-met)
  8818.     (if (and (not to-newsgroup) (not select-method))
  8819.     (setq to-newsgroup
  8820.           (completing-read 
  8821.            (format "Where do you want to move %s? %s"
  8822.                (if (> (length articles) 1)
  8823.                (format "these %d articles" (length articles))
  8824.              "this article")
  8825.                (if gnus-current-move-group
  8826.                (format "(%s default) " gnus-current-move-group)
  8827.              ""))
  8828.            gnus-active-hashtb nil nil prefix)))
  8829.     (if to-newsgroup
  8830.         (progn
  8831.           (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
  8832.               (setq to-newsgroup (or gnus-current-move-group "")))
  8833.           (or (gnus-gethash to-newsgroup gnus-active-hashtb)
  8834.           (gnus-activate-group to-newsgroup)
  8835.               (error "No such group: %s" to-newsgroup))
  8836.           (setq gnus-current-move-group to-newsgroup)))
  8837.     (setq to-method (if select-method (list select-method "")
  8838.               (gnus-find-method-for-group to-newsgroup)))
  8839.     (or (gnus-check-backend-function 'request-accept-article (car to-method))
  8840.     (error "%s does not support article copying" (car to-method)))
  8841.     (or (gnus-check-server to-method)
  8842.     (error "Can't open server %s" (car to-method)))
  8843.     (gnus-message 6 "Moving to %s: %s..." 
  8844.           (or select-method to-newsgroup) articles)
  8845.     (while articles
  8846.       (if (setq art-group
  8847.         (gnus-request-move-article 
  8848.          (car articles)        ; Article to move
  8849.          gnus-newsgroup-name    ; From newsgroup
  8850.          (nth 1 (gnus-find-method-for-group 
  8851.              gnus-newsgroup-name)) ; Server
  8852.          (list 'gnus-request-accept-article 
  8853.                (if select-method
  8854.                (list 'quote select-method)
  8855.              to-newsgroup)
  8856.                (not (cdr articles))) ; Accept form
  8857.          (not (cdr articles))))    ; Only save nov last time
  8858.       (let* ((buffer-read-only nil)
  8859.          (entry 
  8860.           (or
  8861.            (gnus-gethash (car art-group) gnus-newsrc-hashtb)
  8862.            (gnus-gethash 
  8863.             (gnus-group-prefixed-name 
  8864.              (car art-group) 
  8865.              (if select-method (list select-method "")
  8866.                (gnus-find-method-for-group to-newsgroup)))
  8867.             gnus-newsrc-hashtb)))
  8868.          (info (nth 2 entry))
  8869.          (article (car articles)))
  8870.         (gnus-summary-goto-subject article)
  8871.         (beginning-of-line)
  8872.         (delete-region (point) (progn (forward-line 1) (point)))
  8873.         ;; Update the group that has been moved to.
  8874.         (if (not info)
  8875.         ()            ; This group does not exist yet.
  8876.           (if (not (memq article gnus-newsgroup-unreads))
  8877.           (setcar (cdr (cdr info))
  8878.               (gnus-add-to-range (nth 2 info) 
  8879.                          (list (cdr art-group)))))
  8880.           ;; Copy any marks over to the new group.
  8881.           (let ((marks '((tick . gnus-newsgroup-marked)
  8882.                  (dormant . gnus-newsgroup-dormant)
  8883.                  (expire . gnus-newsgroup-expirable)
  8884.                  (bookmark . gnus-newsgroup-bookmarks)
  8885.                  (reply . gnus-newsgroup-replied)))
  8886.             (to-article (cdr art-group)))
  8887.         (while marks
  8888.           (if (memq article (symbol-value (cdr (car marks))))
  8889.               (gnus-add-marked-articles 
  8890.                (car info) (car (car marks)) (list to-article) info))
  8891.           (setq marks (cdr marks)))))
  8892.         ;; Update marks.
  8893.         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
  8894.         (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
  8895.         (setq gnus-newsgroup-dormant
  8896.           (delq article gnus-newsgroup-dormant))
  8897.         (setq gnus-newsgroup-reads
  8898.           (cons (cons article gnus-canceled-mark)
  8899.             gnus-newsgroup-reads)))
  8900.     (gnus-message 1 "Couldn't move article %s" (car articles)))
  8901.       (gnus-summary-remove-process-mark (car articles))
  8902.       (setq articles (cdr articles)))
  8903.     (gnus-set-mode-line 'summary)))
  8904.  
  8905. (defun gnus-summary-respool-article (&optional n respool-method)
  8906.   "Respool the current article.
  8907. The article will be squeezed through the mail spooling process again,
  8908. which means that it will be put in some mail newsgroup or other
  8909. depending on `nnmail-split-methods'.
  8910. If N is a positive number, respool the N next articles.
  8911. If N is a negative number, respool the N previous articles.
  8912. If N is nil and any articles have been marked with the process mark,
  8913. respool those articles instead.
  8914.  
  8915. Respooling can be done both from mail groups and \"real\" newsgroups.
  8916. In the former case, the articles in question will be moved from the
  8917. current group into whatever groups they are destined to.  In the
  8918. latter case, they will be copied into the relevant groups."
  8919.   (interactive "P")
  8920.   (gnus-set-global-variables)
  8921.   (let ((respool-methods (gnus-methods-using 'respool))
  8922.     (methname 
  8923.      (symbol-name (car (gnus-find-method-for-group gnus-newsgroup-name)))))
  8924.     (or respool-method
  8925.     (setq respool-method
  8926.           (completing-read
  8927.            "What method do you want to use when respooling? "
  8928.            respool-methods nil t methname)))
  8929.     (or (string= respool-method "")
  8930.     (if (assoc (symbol-name
  8931.             (car (gnus-find-method-for-group gnus-newsgroup-name)))
  8932.            respool-methods)
  8933.         (gnus-summary-move-article n nil (intern respool-method))
  8934.       (gnus-summary-copy-article n nil (intern respool-method))))))
  8935.  
  8936. ;; Suggested by gregj@unidata.com (Gregory J. Grubbs).
  8937. (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
  8938.   "Move the current article to a different newsgroup.
  8939. If N is a positive number, move the N next articles.
  8940. If N is a negative number, move the N previous articles.
  8941. If N is nil and any articles have been marked with the process mark,
  8942. move those articles instead.
  8943. If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. 
  8944. If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
  8945. re-spool using this method.
  8946. For this function to work, the newsgroup that you want to move to have
  8947. to support the `request-move' and `request-accept'
  8948. functions. (Ie. mail newsgroups at present.)"
  8949.   (interactive "P")
  8950.   (gnus-set-global-variables)
  8951.   (let ((articles (gnus-summary-work-articles n))
  8952.     (copy-buf (get-buffer-create "*copy work*"))
  8953.     (prefix (gnus-group-real-prefix gnus-newsgroup-name))
  8954.     art-group to-method)
  8955.     (buffer-disable-undo copy-buf)
  8956.     (if (and (not to-newsgroup) (not select-method))
  8957.     (setq to-newsgroup
  8958.           (completing-read 
  8959.            (format "Where do you want to copy %s? %s"
  8960.                (if (> (length articles) 1)
  8961.                (format "these %d articles" (length articles))
  8962.              "this article")
  8963.                (if gnus-current-move-group
  8964.                (format "(%s default) " gnus-current-move-group)
  8965.              ""))
  8966.            gnus-active-hashtb nil nil prefix)))
  8967.     (if to-newsgroup
  8968.         (progn
  8969.           (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
  8970.               (setq to-newsgroup (or gnus-current-move-group "")))
  8971.           (or (gnus-gethash to-newsgroup gnus-active-hashtb)
  8972.           (gnus-activate-group to-newsgroup)
  8973.               (error "No such group: %s" to-newsgroup))
  8974.           (setq gnus-current-move-group to-newsgroup)))
  8975.     (setq to-method (if select-method (list select-method "")
  8976.               (gnus-find-method-for-group to-newsgroup)))
  8977.     (or (gnus-check-backend-function 'request-accept-article (car to-method))
  8978.     (error "%s does not support article copying" (car to-method)))
  8979.     (or (gnus-check-server to-method)
  8980.     (error "Can't open server %s" (car to-method)))
  8981.     (while articles
  8982.       (gnus-message 6 "Copying to %s: %s..." 
  8983.             (or select-method to-newsgroup) articles)
  8984.       (if (setq art-group
  8985.         (save-excursion
  8986.           (set-buffer copy-buf)
  8987.           (gnus-request-article-this-buffer
  8988.            (car articles) gnus-newsgroup-name)
  8989.           (gnus-request-accept-article
  8990.            (if select-method (list 'quote select-method) to-newsgroup)
  8991.            (not (cdr articles)))))
  8992.       (let* ((entry 
  8993.           (or
  8994.            (gnus-gethash (car art-group) gnus-newsrc-hashtb)
  8995.            (gnus-gethash 
  8996.             (gnus-group-prefixed-name 
  8997.              (car art-group) 
  8998.              (if select-method (list select-method "")
  8999.                (gnus-find-method-for-group to-newsgroup)))
  9000.             gnus-newsrc-hashtb)))
  9001.          (info (nth 2 entry))
  9002.          (article (car articles)))
  9003.         ;; We copy the info over to the new group.
  9004.         (if (not info)
  9005.         ()            ; This group does not exist (yet).
  9006.           (if (not (memq article gnus-newsgroup-unreads))
  9007.           (setcar (cdr (cdr info))
  9008.               (gnus-add-to-range (nth 2 info) 
  9009.                          (list (cdr art-group)))))
  9010.           ;; Copy any marks over to the new group.
  9011.           (let ((marks '((tick . gnus-newsgroup-marked)
  9012.                  (dormant . gnus-newsgroup-dormant)
  9013.                  (expire . gnus-newsgroup-expirable)
  9014.                  (bookmark . gnus-newsgroup-bookmarks)
  9015.                  (reply . gnus-newsgroup-replied)))
  9016.             (to-article (cdr art-group)))
  9017.         (while marks
  9018.           (if (memq article (symbol-value (cdr (car marks))))
  9019.               (gnus-add-marked-articles 
  9020.                (car info) (car (car marks)) (list to-article) info))
  9021.           (setq marks (cdr marks))))))
  9022.     (gnus-message 1 "Couldn't copy article %s" (car articles)))
  9023.       (gnus-summary-remove-process-mark (car articles))
  9024.       (setq articles (cdr articles)))
  9025.     (kill-buffer copy-buf)))
  9026.  
  9027. (defun gnus-summary-import-article (file)
  9028.   "Import a random file into a mail newsgroup."
  9029.   (interactive "fImport file: ")
  9030.   (let ((group gnus-newsgroup-name)
  9031.     atts)
  9032.     (or (gnus-check-backend-function 'request-accept-article group)
  9033.     (error "%s does not support article importing" group))
  9034.     (or (file-readable-p file)
  9035.     (not (file-regular-p file))
  9036.     (error "Can't read %s" file))
  9037.     (save-excursion
  9038.       (set-buffer (get-buffer-create " *import file*"))
  9039.       (buffer-disable-undo (current-buffer))
  9040.       (erase-buffer)
  9041.       (insert-file-contents file)
  9042.       (goto-char (point-min))
  9043.       (if (nnheader-article-p)
  9044.       ()
  9045.     (setq atts (file-attributes file))
  9046.     (insert "From: " (read-string "From: ") "\n"
  9047.         "Subject: " (read-string "Subject: ") "\n"
  9048.         "Date: " (current-time-string (nth 5 atts)) "\n"
  9049.         "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
  9050.       (gnus-request-accept-article group t)
  9051.       (kill-buffer (current-buffer)))))
  9052.  
  9053. (defun gnus-summary-expire-articles ()
  9054.   "Expire all articles that are marked as expirable in the current group."
  9055.   (interactive)
  9056.   (if (not (gnus-check-backend-function 
  9057.         'request-expire-articles gnus-newsgroup-name))
  9058.       ()
  9059.     (let* ((info (nth 2 (gnus-gethash gnus-newsgroup-name 
  9060.                       gnus-newsrc-hashtb)))
  9061.        (total (memq 'total-expire (nth 5 info)))
  9062.        (expirable (if total
  9063.               (gnus-list-of-read-articles gnus-newsgroup-name)
  9064.             (setq gnus-newsgroup-expirable
  9065.                   (sort gnus-newsgroup-expirable '<))))
  9066.        es)
  9067.       (if (not expirable)
  9068.       ()
  9069.     (gnus-message 6 "Expiring articles...")
  9070.     ;; The list of articles that weren't expired is returned.
  9071.     (setq es (gnus-request-expire-articles expirable gnus-newsgroup-name))
  9072.     (or total (setq gnus-newsgroup-expirable es))
  9073.     ;; We go through the old list of expirable, and mark all
  9074.     ;; really expired articles as nonexistent.
  9075.     (or (eq es expirable)        ;If nothing was expired, we don't mark.
  9076.         (let ((gnus-use-cache nil))
  9077.           (while expirable
  9078.         (or (memq (car expirable) es)
  9079.             (gnus-summary-mark-article
  9080.              (car expirable) gnus-canceled-mark))
  9081.         (setq expirable (cdr expirable)))))
  9082.     (gnus-message 6 "Expiring articles...done")))))
  9083.  
  9084. (defun gnus-summary-expire-articles-now ()
  9085.   "Expunge all expirable articles in the current group.
  9086. This means that *all* articles that are marked as expirable will be
  9087. deleted forever, right now."
  9088.   (interactive)
  9089.   (or gnus-expert-user
  9090.       (gnus-y-or-n-p
  9091.        "Are you really, really, really sure you want to expunge? ")
  9092.       (error "Phew!"))
  9093.   (let ((nnmail-expiry-wait -1)
  9094.     (nnmail-expiry-wait-function nil))
  9095.     (gnus-summary-expire-articles)))
  9096.  
  9097. ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
  9098. (defun gnus-summary-delete-article (&optional n)
  9099.   "Delete the N next (mail) articles.
  9100. This command actually deletes articles. This is not a marking
  9101. command. The article will disappear forever from you life, never to
  9102. return. 
  9103. If N is negative, delete backwards.
  9104. If N is nil and articles have been marked with the process mark,
  9105. delete these instead."
  9106.   (interactive "P")
  9107.   (or (gnus-check-backend-function 'request-expire-articles 
  9108.                    gnus-newsgroup-name)
  9109.       (error "The current newsgroup does not support article deletion."))
  9110.   ;; Compute the list of articles to delete.
  9111.   (let ((articles (gnus-summary-work-articles n))
  9112.     not-deleted)
  9113.     (if (and gnus-novice-user
  9114.          (not (gnus-y-or-n-p 
  9115.            (format "Do you really want to delete %s forever? "
  9116.                (if (> (length articles) 1) "these articles"
  9117.                  "this article")))))
  9118.     ()
  9119.       ;; Delete the articles.
  9120.       (setq not-deleted (gnus-request-expire-articles 
  9121.              articles gnus-newsgroup-name 'force))
  9122.       (while articles
  9123.     (gnus-summary-remove-process-mark (car articles))    
  9124.     ;; The backend might not have been able to delete the article
  9125.     ;; after all.  
  9126.     (or (memq (car articles) not-deleted)
  9127.         (gnus-summary-mark-article (car articles) gnus-canceled-mark))
  9128.     (setq articles (cdr articles))))
  9129.     (gnus-summary-position-cursor)
  9130.     (gnus-set-mode-line 'summary)
  9131.     not-deleted))
  9132.  
  9133. (defun gnus-summary-edit-article (&optional force)
  9134.   "Enter into a buffer and edit the current article.
  9135. This will have permanent effect only in mail groups.
  9136. If FORCE is non-nil, allow editing of articles even in read-only
  9137. groups."
  9138.   (interactive "P")
  9139.   (or force
  9140.       (not (gnus-group-read-only-p))
  9141.       (error "The current newsgroup does not support article editing."))
  9142.   (gnus-summary-select-article t)
  9143.   (gnus-configure-windows 'article)
  9144.   (select-window (get-buffer-window gnus-article-buffer))
  9145.   (gnus-message 6 "C-c C-c to end edits")
  9146.   (setq buffer-read-only nil)
  9147.   (text-mode)
  9148.   (use-local-map (copy-keymap (current-local-map)))
  9149.   (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
  9150.   (buffer-enable-undo)
  9151.   (widen)
  9152.   (goto-char (point-min))
  9153.   (search-forward "\n\n" nil t))
  9154.  
  9155. (defun gnus-summary-edit-article-done ()
  9156.   "Make edits to the current article permanent."
  9157.   (interactive)
  9158.   (if (gnus-group-read-only-p)
  9159.       (progn
  9160.     (gnus-summary-edit-article-postpone)
  9161.     (message "The current newsgroup does not support article editing.")
  9162.     (ding))
  9163.     (let ((buf (buffer-substring-no-properties (point-min) (point-max))))
  9164.       (erase-buffer)
  9165.       (insert buf)
  9166.       (if (not (gnus-request-replace-article 
  9167.         (cdr gnus-article-current) (car gnus-article-current) 
  9168.         (current-buffer)))
  9169.       (error "Couldn't replace article.")
  9170.     (gnus-article-mode)
  9171.     (use-local-map gnus-article-mode-map)
  9172.     (setq buffer-read-only t)
  9173.     (buffer-disable-undo (current-buffer))
  9174.     (gnus-configure-windows 'summary))
  9175.       (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))))
  9176.  
  9177. (defun gnus-summary-edit-article-postpone ()
  9178.   "Postpone changes to the current article."
  9179.   (interactive)
  9180.   (gnus-article-mode)
  9181.   (use-local-map gnus-article-mode-map)
  9182.   (setq buffer-read-only t)
  9183.   (buffer-disable-undo (current-buffer))
  9184.   (gnus-configure-windows 'summary)
  9185.   (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))
  9186.  
  9187. (defun gnus-summary-fancy-query ()
  9188.   "Query where the fancy respool algorithm would put this article."
  9189.   (interactive)
  9190.   (gnus-summary-select-article)
  9191.   (save-excursion
  9192.     (set-buffer gnus-article-buffer)
  9193.     (save-restriction
  9194.       (goto-char (point-min))
  9195.       (search-forward "\n\n")
  9196.       (narrow-to-region (point-min) (point))
  9197.       (pp-eval-expression (list 'quote (nnmail-split-fancy))))))
  9198.  
  9199. ;; Summary score commands.
  9200.  
  9201. ;; Suggested by boubaker@cenatls.cena.dgac.fr.
  9202.  
  9203. (defun gnus-summary-raise-score (n)
  9204.   "Raise the score of the current article by N."
  9205.   (interactive "p")
  9206.   (gnus-summary-set-score (+ (gnus-summary-article-score) n)))
  9207.  
  9208. (defun gnus-summary-set-score (n)
  9209.   "Set the score of the current article to N."
  9210.   (interactive "p")
  9211.   ;; Skip dummy header line.
  9212.   (save-excursion
  9213.     (gnus-summary-show-thread)
  9214.     (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
  9215.     (forward-line 1))
  9216.     (let ((buffer-read-only nil))
  9217.       ;; Set score.
  9218.       (gnus-summary-update-mark
  9219.        (if (= n (or gnus-summary-default-score 0)) ? 
  9220.      (if (< n (or gnus-summary-default-score 0)) 
  9221.          gnus-score-below-mark gnus-score-over-mark)) 'score))
  9222.     (let* ((article (gnus-summary-article-number))
  9223.        (score (assq article gnus-newsgroup-scored)))
  9224.       (if score (setcdr score n)
  9225.     (setq gnus-newsgroup-scored 
  9226.           (cons (cons article n) gnus-newsgroup-scored))))
  9227.     (gnus-summary-update-line)))
  9228.  
  9229. (defun gnus-summary-current-score ()
  9230.   "Return the score of the current article."
  9231.   (interactive)
  9232.   (message "%s" (gnus-summary-article-score)))
  9233.  
  9234. ;; Summary marking commands.
  9235.  
  9236. (defun gnus-summary-raise-same-subject-and-select (score)
  9237.   "Raise articles which has the same subject with SCORE and select the next."
  9238.   (interactive "p")
  9239.   (let ((subject (gnus-summary-subject-string)))
  9240.     (gnus-summary-raise-score score)
  9241.     (while (gnus-summary-search-subject nil nil subject)
  9242.       (gnus-summary-raise-score score))
  9243.     (gnus-summary-next-article t)))
  9244.  
  9245. (defun gnus-summary-raise-same-subject (score)
  9246.   "Raise articles which has the same subject with SCORE."
  9247.   (interactive "p")
  9248.   (let ((subject (gnus-summary-subject-string)))
  9249.     (gnus-summary-raise-score score)
  9250.     (while (gnus-summary-search-subject nil nil subject)
  9251.       (gnus-summary-raise-score score))
  9252.     (gnus-summary-next-subject 1 t)))
  9253.  
  9254. (defun gnus-score-default (level)
  9255.   (if level (prefix-numeric-value level) 
  9256.     gnus-score-interactive-default-score))
  9257.  
  9258. (defun gnus-summary-raise-thread (&optional score)
  9259.   "Raise the score of the articles in the current thread with SCORE."
  9260.   (interactive "P")
  9261.   (setq score (gnus-score-default score))
  9262.   (let (e)
  9263.     (save-excursion
  9264.       (let ((level (gnus-summary-thread-level)))
  9265.     (gnus-summary-raise-score score)
  9266.     (while (and (zerop (gnus-summary-next-subject 1 nil t))
  9267.             (> (gnus-summary-thread-level) level))
  9268.       (gnus-summary-raise-score score))
  9269.     (setq e (point))))
  9270.     (let ((gnus-summary-check-current t))
  9271.       (or (zerop (gnus-summary-next-subject 1 t))
  9272.       (goto-char e))))
  9273.   (gnus-summary-recenter)
  9274.   (gnus-summary-position-cursor)
  9275.   (gnus-set-mode-line 'summary))
  9276.  
  9277. (defun gnus-summary-lower-same-subject-and-select (score)
  9278.   "Raise articles which has the same subject with SCORE and select the next."
  9279.   (interactive "p")
  9280.   (gnus-summary-raise-same-subject-and-select (- score)))
  9281.  
  9282. (defun gnus-summary-lower-same-subject (score)
  9283.   "Raise articles which has the same subject with SCORE."
  9284.   (interactive "p")
  9285.   (gnus-summary-raise-same-subject (- score)))
  9286.  
  9287. (defun gnus-summary-lower-thread (&optional score)
  9288.   "Lower score of articles in the current thread with SCORE."
  9289.   (interactive "P")
  9290.   (gnus-summary-raise-thread (- (1- (gnus-score-default score)))))
  9291.  
  9292. (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
  9293.   "Mark articles which has the same subject as read, and then select the next.
  9294. If UNMARK is positive, remove any kind of mark.
  9295. If UNMARK is negative, tick articles."
  9296.   (interactive "P")
  9297.   (if unmark
  9298.       (setq unmark (prefix-numeric-value unmark)))
  9299.   (let ((count
  9300.      (gnus-summary-mark-same-subject
  9301.       (gnus-summary-subject-string) unmark)))
  9302.     ;; Select next unread article. If auto-select-same mode, should
  9303.     ;; select the first unread article.
  9304.     (gnus-summary-next-article t (and gnus-auto-select-same
  9305.                       (gnus-summary-subject-string)))
  9306.     (gnus-message 7 "%d article%s marked as %s"
  9307.           count (if (= count 1) " is" "s are")
  9308.           (if unmark "unread" "read"))))
  9309.  
  9310. (defun gnus-summary-kill-same-subject (&optional unmark)
  9311.   "Mark articles which has the same subject as read. 
  9312. If UNMARK is positive, remove any kind of mark.
  9313. If UNMARK is negative, tick articles."
  9314.   (interactive "P")
  9315.   (if unmark
  9316.       (setq unmark (prefix-numeric-value unmark)))
  9317.   (let ((count
  9318.      (gnus-summary-mark-same-subject
  9319.       (gnus-summary-subject-string) unmark)))
  9320.     ;; If marked as read, go to next unread subject.
  9321.     (if (null unmark)
  9322.     ;; Go to next unread subject.
  9323.     (gnus-summary-next-subject 1 t))
  9324.     (gnus-message 7 "%d articles are marked as %s"
  9325.           count (if unmark "unread" "read"))))
  9326.  
  9327. (defun gnus-summary-mark-same-subject (subject &optional unmark)
  9328.   "Mark articles with same SUBJECT as read, and return marked number.
  9329. If optional argument UNMARK is positive, remove any kinds of marks.
  9330. If optional argument UNMARK is negative, mark articles as unread instead."
  9331.   (let ((count 1))
  9332.     (save-excursion
  9333.       (cond 
  9334.        ((null unmark)            ; Mark as read.
  9335.     (while (and 
  9336.         (progn
  9337.           (gnus-summary-mark-article-as-read gnus-killed-mark)
  9338.           (gnus-summary-show-thread) t)
  9339.         (gnus-summary-search-forward nil subject))
  9340.       (setq count (1+ count))))
  9341.        ((> unmark 0)            ; Tick.
  9342.     (while (and
  9343.         (progn
  9344.           (gnus-summary-mark-article-as-unread gnus-ticked-mark)
  9345.           (gnus-summary-show-thread) t)
  9346.         (gnus-summary-search-forward nil subject))
  9347.       (setq count (1+ count))))
  9348.        (t                ; Mark as unread.
  9349.     (while (and
  9350.         (progn
  9351.           (gnus-summary-mark-article-as-unread gnus-unread-mark)
  9352.           (gnus-summary-show-thread) t)
  9353.         (gnus-summary-search-forward nil subject))
  9354.       (setq count (1+ count)))))
  9355.       (gnus-set-mode-line 'summary)
  9356.       ;; Return the number of marked articles.
  9357.       count)))
  9358.  
  9359. (defun gnus-summary-mark-as-processable (n &optional unmark)
  9360.   "Set the process mark on the next N articles.
  9361. If N is negative, mark backward instead.  If UNMARK is non-nil, remove
  9362. the process mark instead.  The difference between N and the actual
  9363. number of articles marked is returned."
  9364.   (interactive "p")
  9365.   (let ((backward (< n 0))
  9366.     (n (abs n)))
  9367.     (while (and 
  9368.         (> n 0)
  9369.         (if unmark
  9370.         (gnus-summary-remove-process-mark
  9371.          (gnus-summary-article-number))
  9372.           (gnus-summary-set-process-mark (gnus-summary-article-number)))
  9373.         (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
  9374.       (setq n (1- n)))
  9375.     (if (/= 0 n) (gnus-message 7 "No more articles"))
  9376.     (gnus-summary-recenter)
  9377.     (gnus-summary-position-cursor)
  9378.     n))
  9379.  
  9380. (defun gnus-summary-unmark-as-processable (n)
  9381.   "Remove the process mark from the next N articles.
  9382. If N is negative, mark backward instead.  The difference between N and
  9383. the actual number of articles marked is returned."
  9384.   (interactive "p")
  9385.   (gnus-summary-mark-as-processable n t))
  9386.  
  9387. (defun gnus-summary-unmark-all-processable ()
  9388.   "Remove the process mark from all articles."
  9389.   (interactive)
  9390.   (save-excursion
  9391.     (while gnus-newsgroup-processable
  9392.       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
  9393.   (gnus-summary-position-cursor))
  9394.  
  9395. (defun gnus-summary-mark-as-expirable (n)
  9396.   "Mark N articles forward as expirable.
  9397. If N is negative, mark backward instead. The difference between N and
  9398. the actual number of articles marked is returned."
  9399.   (interactive "p")
  9400.   (gnus-summary-mark-forward n gnus-expirable-mark))
  9401.  
  9402. (defun gnus-summary-mark-article-as-replied (article)
  9403.   "Mark ARTICLE replied and update the summary line."
  9404.   (setq gnus-newsgroup-replied (cons article gnus-newsgroup-replied))
  9405.   (let ((buffer-read-only nil))
  9406.     (if (gnus-summary-goto-subject article)
  9407.     (progn
  9408.       (gnus-summary-update-mark gnus-replied-mark 'replied)
  9409.       t))))
  9410.  
  9411. (defun gnus-summary-set-bookmark (article)
  9412.   "Set a bookmark in current article."
  9413.   (interactive (list (gnus-summary-article-number)))
  9414.   (if (or (not (get-buffer gnus-article-buffer))
  9415.       (not gnus-current-article)
  9416.       (not gnus-article-current)
  9417.       (not (equal gnus-newsgroup-name (car gnus-article-current))))
  9418.       (error "No current article selected"))
  9419.   ;; Remove old bookmark, if one exists.
  9420.   (let ((old (assq article gnus-newsgroup-bookmarks)))
  9421.     (if old (setq gnus-newsgroup-bookmarks 
  9422.           (delq old gnus-newsgroup-bookmarks))))
  9423.   ;; Set the new bookmark, which is on the form 
  9424.   ;; (article-number . line-number-in-body).
  9425.   (setq gnus-newsgroup-bookmarks 
  9426.     (cons 
  9427.      (cons article 
  9428.            (save-excursion
  9429.          (set-buffer gnus-article-buffer)
  9430.          (count-lines
  9431.           (min (point)
  9432.                (save-excursion
  9433.              (goto-char (point-min))
  9434.              (search-forward "\n\n" nil t)
  9435.              (point)))
  9436.           (point))))
  9437.      gnus-newsgroup-bookmarks))
  9438.   (gnus-message 6 "A bookmark has been added to the current article."))
  9439.  
  9440. (defun gnus-summary-remove-bookmark (article)
  9441.   "Remove the bookmark from the current article."
  9442.   (interactive (list (gnus-summary-article-number)))
  9443.   ;; Remove old bookmark, if one exists.
  9444.   (let ((old (assq article gnus-newsgroup-bookmarks)))
  9445.     (if old 
  9446.     (progn
  9447.       (setq gnus-newsgroup-bookmarks 
  9448.         (delq old gnus-newsgroup-bookmarks))
  9449.       (gnus-message 6 "Removed bookmark."))
  9450.       (gnus-message 6 "No bookmark in current article."))))
  9451.  
  9452. ;; Suggested by Daniel Quinlan <quinlan@best.com>.
  9453. (defun gnus-summary-mark-as-dormant (n)
  9454.   "Mark N articles forward as dormant.
  9455. If N is negative, mark backward instead.  The difference between N and
  9456. the actual number of articles marked is returned."
  9457.   (interactive "p")
  9458.   (gnus-summary-mark-forward n gnus-dormant-mark))
  9459.  
  9460. (defun gnus-summary-set-process-mark (article)
  9461.   "Set the process mark on ARTICLE and update the summary line."
  9462.   (setq gnus-newsgroup-processable 
  9463.     (cons article 
  9464.           (delq article gnus-newsgroup-processable)))
  9465.   (let ((buffer-read-only nil))
  9466.     (if (gnus-summary-goto-subject article)
  9467.     (progn
  9468.       (gnus-summary-show-thread)
  9469.       (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
  9470.            (forward-line 1))
  9471.       (gnus-summary-update-mark gnus-process-mark 'replied)
  9472.       t))))
  9473.  
  9474. (defun gnus-summary-remove-process-mark (article)
  9475.   "Remove the process mark from ARTICLE and update the summary line."
  9476.   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
  9477.   (let ((buffer-read-only nil))
  9478.     (if (gnus-summary-goto-subject article)
  9479.     (progn
  9480.       (gnus-summary-show-thread)
  9481.       (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
  9482.            (forward-line 1))
  9483.       (gnus-summary-update-mark ?  'replied)
  9484.       (if (memq article gnus-newsgroup-replied) 
  9485.           (gnus-summary-update-mark gnus-replied-mark 'replied))
  9486.       t))))
  9487.  
  9488. (defun gnus-summary-mark-forward (n &optional mark no-expire)
  9489.   "Mark N articles as read forwards.
  9490. If N is negative, mark backwards instead.
  9491. Mark with MARK. If MARK is ? , ?! or ??, articles will be
  9492. marked as unread. 
  9493. The difference between N and the actual number of articles marked is
  9494. returned."
  9495.   (interactive "p")
  9496.   (gnus-set-global-variables)
  9497.   (let ((backward (< n 0))
  9498.     (gnus-summary-goto-unread
  9499.      (and gnus-summary-goto-unread
  9500.           (not (memq mark (list gnus-unread-mark
  9501.                     gnus-ticked-mark gnus-dormant-mark)))))
  9502.     (n (abs n))
  9503.     (mark (or mark gnus-del-mark)))
  9504.     (while (and (> n 0)
  9505.         (gnus-summary-mark-article nil mark no-expire)
  9506.         (zerop (gnus-summary-next-subject 
  9507.             (if backward -1 1) gnus-summary-goto-unread t)))
  9508.       (setq n (1- n)))
  9509.     (if (/= 0 n) (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
  9510.     (gnus-summary-recenter)
  9511.     (gnus-summary-position-cursor)
  9512.     (gnus-set-mode-line 'summary)
  9513.     n))
  9514.  
  9515. (defun gnus-summary-mark-article-as-read (mark)
  9516.   "Mark the current article quickly as read with MARK."
  9517.   (let ((article (gnus-summary-article-number)))
  9518.     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
  9519.     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
  9520.     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
  9521.     (setq gnus-newsgroup-reads
  9522.       (cons (cons article mark) gnus-newsgroup-reads))
  9523.     ;; Possibly remove from cache, if that is used. 
  9524.     (and gnus-use-cache (gnus-cache-enter-remove-article article))
  9525.     (and gnus-newsgroup-auto-expire 
  9526.      (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
  9527.          (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
  9528.          (= mark gnus-read-mark))
  9529.      (progn
  9530.        (setq mark gnus-expirable-mark)
  9531.        (setq gnus-newsgroup-expirable 
  9532.          (cons article gnus-newsgroup-expirable))))
  9533.     (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
  9534.       (forward-line 1))
  9535.     ;; Fix the mark.
  9536.     (gnus-summary-update-mark mark 'unread)
  9537.     t))
  9538.  
  9539. (defun gnus-summary-mark-article-as-unread (mark)
  9540.   "Mark the current article quickly as unread with MARK."
  9541.   (let ((article (gnus-summary-article-number)))
  9542.     (or (memq article gnus-newsgroup-unreads)
  9543.     (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
  9544.     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
  9545.     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
  9546.     (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
  9547.     (setq gnus-newsgroup-reads
  9548.       (delq (assq article gnus-newsgroup-reads)
  9549.         gnus-newsgroup-reads))
  9550.     (if (= mark gnus-ticked-mark)
  9551.     (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
  9552.     (if (= mark gnus-dormant-mark)
  9553.     (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))
  9554.  
  9555.     ;; See whether the article is to be put in the cache.
  9556.     (and gnus-use-cache
  9557.      (vectorp (gnus-get-header-by-num article))
  9558.      (save-excursion
  9559.        (gnus-cache-possibly-enter-article 
  9560.         gnus-newsgroup-name article 
  9561.         (gnus-get-header-by-num article)
  9562.         (= mark gnus-ticked-mark)
  9563.         (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
  9564.  
  9565.     (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
  9566.       (forward-line 1))
  9567.     ;; Fix the mark.
  9568.     (gnus-summary-update-mark mark 'unread)
  9569.     t))
  9570.  
  9571. (defun gnus-summary-mark-article (&optional article mark no-expire)
  9572.   "Mark ARTICLE with MARK.  MARK can be any character.
  9573. Four MARK strings are reserved: `? ' (unread), `?!' (ticked), `??'
  9574. (dormant) and `?E' (expirable).
  9575. If MARK is nil, then the default character `?D' is used.
  9576. If ARTICLE is nil, then the article on the current line will be
  9577. marked." 
  9578.   (and (stringp mark)
  9579.        (setq mark (aref mark 0)))
  9580.   ;; If no mark is given, then we check auto-expiring.
  9581.   (and (not no-expire)
  9582.        gnus-newsgroup-auto-expire 
  9583.        (or (not mark)
  9584.        (and (numberp mark) 
  9585.         (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
  9586.             (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
  9587.             (= mark gnus-read-mark))))
  9588.        (setq mark gnus-expirable-mark))
  9589.   (let* ((mark (or mark gnus-del-mark))
  9590.      (article (or article (gnus-summary-article-number))))
  9591.     (or article (error "No article on current line"))
  9592.     (if (or (= mark gnus-unread-mark) 
  9593.         (= mark gnus-ticked-mark) 
  9594.         (= mark gnus-dormant-mark))
  9595.     (gnus-mark-article-as-unread article mark)
  9596.       (gnus-mark-article-as-read article mark))
  9597.  
  9598.     ;; See whether the article is to be put in the cache.
  9599.     (and gnus-use-cache
  9600.      (not (= mark gnus-canceled-mark))
  9601.      (vectorp (gnus-get-header-by-num article))
  9602.      (save-excursion
  9603.        (gnus-cache-possibly-enter-article 
  9604.         gnus-newsgroup-name article 
  9605.         (gnus-get-header-by-num article)
  9606.         (= mark gnus-ticked-mark)
  9607.         (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
  9608.  
  9609.     (if (gnus-summary-goto-subject article)
  9610.     (let ((buffer-read-only nil))
  9611.       (gnus-summary-show-thread)
  9612.       (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
  9613.            (forward-line 1))
  9614.       ;; Fix the mark.
  9615.       (gnus-summary-update-mark mark 'unread)
  9616.       t))))
  9617.  
  9618. (defun gnus-summary-update-mark (mark type)
  9619.   (beginning-of-line)
  9620.   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
  9621.     (buffer-read-only nil)
  9622.     plist)
  9623.     (if (not forward)
  9624.     ()
  9625.       (forward-char forward)
  9626.       (setq plist (text-properties-at (point)))
  9627.       (delete-char 1)
  9628.       (insert mark)
  9629.       (and plist (add-text-properties (1- (point)) (point) plist))
  9630.       (and (eq type 'unread)
  9631.        (progn
  9632.          (add-text-properties (1- (point)) (point) (list 'gnus-mark mark))
  9633.          (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
  9634.   
  9635. (defun gnus-mark-article-as-read (article &optional mark)
  9636.   "Enter ARTICLE in the pertinent lists and remove it from others."
  9637.   ;; Make the article expirable.
  9638.   (let ((mark (or mark gnus-del-mark)))
  9639.     (if (= mark gnus-expirable-mark)
  9640.     (setq gnus-newsgroup-expirable (cons article gnus-newsgroup-expirable))
  9641.       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
  9642.     ;; Remove from unread and marked lists.
  9643.     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
  9644.     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
  9645.     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
  9646.     (setq gnus-newsgroup-reads 
  9647.       (cons (cons article mark) gnus-newsgroup-reads))
  9648.     ;; Possibly remove from cache, if that is used. 
  9649.     (and gnus-use-cache (gnus-cache-enter-remove-article article))))
  9650.  
  9651. (defun gnus-mark-article-as-unread (article &optional mark)
  9652.   "Enter ARTICLE in the pertinent lists and remove it from others."
  9653.   (let ((mark (or mark gnus-ticked-mark)))
  9654.     ;; Add to unread list.
  9655.     (or (memq article gnus-newsgroup-unreads)
  9656.     (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
  9657.     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
  9658.     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
  9659.     (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
  9660.     (setq gnus-newsgroup-reads
  9661.       (delq (assq article gnus-newsgroup-reads)
  9662.         gnus-newsgroup-reads))
  9663.     (if (= mark gnus-ticked-mark)
  9664.     (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
  9665.     (if (= mark gnus-dormant-mark)
  9666.     (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))))
  9667.  
  9668. (defalias 'gnus-summary-mark-as-unread-forward 
  9669.   'gnus-summary-tick-article-forward)
  9670. (make-obsolete 'gnus-summary-mark-as-unread-forward 
  9671.            'gnus-summary-tick-article-forward)
  9672. (defun gnus-summary-tick-article-forward (n)
  9673.   "Tick N articles forwards.
  9674. If N is negative, tick backwards instead.
  9675. The difference between N and the number of articles ticked is returned."
  9676.   (interactive "p")
  9677.   (gnus-summary-mark-forward n gnus-ticked-mark))
  9678.  
  9679. (defalias 'gnus-summary-mark-as-unread-backward 
  9680.   'gnus-summary-tick-article-backward)
  9681. (make-obsolete 'gnus-summary-mark-as-unread-backward 
  9682.            'gnus-summary-tick-article-backward)
  9683. (defun gnus-summary-tick-article-backward (n)
  9684.   "Tick N articles backwards.
  9685. The difference between N and the number of articles ticked is returned."
  9686.   (interactive "p")
  9687.   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
  9688.  
  9689. (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
  9690. (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
  9691. (defun gnus-summary-tick-article (&optional article clear-mark)
  9692.   "Mark current article as unread.
  9693. Optional 1st argument ARTICLE specifies article number to be marked as unread.
  9694. Optional 2nd argument CLEAR-MARK remove any kinds of mark."
  9695.   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
  9696.                        gnus-ticked-mark)))
  9697.  
  9698. (defun gnus-summary-mark-as-read-forward (n)
  9699.   "Mark N articles as read forwards.
  9700. If N is negative, mark backwards instead.
  9701. The difference between N and the actual number of articles marked is
  9702. returned."
  9703.   (interactive "p")
  9704.   (gnus-summary-mark-forward n gnus-del-mark t))
  9705.  
  9706. (defun gnus-summary-mark-as-read-backward (n)
  9707.   "Mark the N articles as read backwards.
  9708. The difference between N and the actual number of articles marked is
  9709. returned."
  9710.   (interactive "p")
  9711.   (gnus-summary-mark-forward (- n) gnus-del-mark t))
  9712.  
  9713. (defun gnus-summary-mark-as-read (&optional article mark)
  9714.   "Mark current article as read.
  9715. ARTICLE specifies the article to be marked as read.
  9716. MARK specifies a string to be inserted at the beginning of the line."
  9717.   (gnus-summary-mark-article article mark))
  9718.  
  9719. (defun gnus-summary-clear-mark-forward (n)
  9720.   "Clear marks from N articles forward.
  9721. If N is negative, clear backward instead.
  9722. The difference between N and the number of marks cleared is returned."
  9723.   (interactive "p")
  9724.   (gnus-summary-mark-forward n gnus-unread-mark))
  9725.  
  9726. (defun gnus-summary-clear-mark-backward (n)
  9727.   "Clear marks from N articles backward.
  9728. The difference between N and the number of marks cleared is returned."
  9729.   (interactive "p")
  9730.   (gnus-summary-mark-forward (- n) gnus-unread-mark))
  9731.  
  9732. (defun gnus-summary-mark-unread-as-read ()
  9733.   "Intended to be used by `gnus-summary-mark-article-hook'."
  9734.   (or (memq gnus-current-article gnus-newsgroup-marked)
  9735.       (memq gnus-current-article gnus-newsgroup-dormant)
  9736.       (memq gnus-current-article gnus-newsgroup-expirable)
  9737.       (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
  9738.  
  9739. (defun gnus-summary-mark-region-as-read (point mark all)
  9740.   "Mark all unread articles between point and mark as read.
  9741. If given a prefix, mark all articles between point and mark as read,
  9742. even ticked and dormant ones."
  9743.   (interactive "r\nP")
  9744.   (save-excursion
  9745.     (goto-char point)
  9746.     (beginning-of-line)
  9747.     (while (and 
  9748.         (< (point) mark)
  9749.         (progn
  9750.           (and
  9751.            (or all
  9752.            (and
  9753.             (not (memq (gnus-summary-article-number)
  9754.                    gnus-newsgroup-marked))
  9755.             (not (memq (gnus-summary-article-number)
  9756.                    gnus-newsgroup-dormant))))
  9757.            (gnus-summary-mark-article
  9758.         (gnus-summary-article-number) gnus-del-mark))
  9759.           t)
  9760.         (zerop (forward-line 1))))))
  9761.  
  9762. ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
  9763. (defalias 'gnus-summary-delete-marked-as-read 
  9764.   'gnus-summary-remove-lines-marked-as-read)
  9765. (make-obsolete 'gnus-summary-delete-marked-as-read 
  9766.            'gnus-summary-remove-lines-marked-as-read)
  9767. (defun gnus-summary-remove-lines-marked-as-read ()
  9768.   "Remove lines that are marked as read."
  9769.   (interactive)
  9770.   (gnus-summary-remove-lines-marked-with 
  9771.    (concat (mapconcat
  9772.         (lambda (char) (char-to-string (symbol-value char)))
  9773.         '(gnus-del-mark gnus-read-mark gnus-ancient-mark
  9774.                 gnus-killed-mark gnus-kill-file-mark
  9775.                 gnus-low-score-mark gnus-expirable-mark
  9776.                 gnus-canceled-mark gnus-catchup-mark)
  9777.         ""))))
  9778.  
  9779. (defalias 'gnus-summary-delete-marked-with 
  9780.   'gnus-summary-remove-lines-marked-with)
  9781. (make-obsolete 'gnus-summary-delete-marked-with 
  9782.            'gnus-summary-remove-lines-marked-with)
  9783. ;; Rewrite by Daniel Quinlan <quinlan@best.com>.
  9784. (defun gnus-summary-remove-lines-marked-with (marks)
  9785.   "Remove lines that are marked with MARKS (e.g. \"DK\")."
  9786.   (interactive "sMarks: ")
  9787.   ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
  9788.   (gnus-set-global-variables)
  9789.   (let ((buffer-read-only nil)
  9790.     (orig-article 
  9791.      (let ((gnus-summary-check-current t))
  9792.        (gnus-summary-search-forward t)
  9793.        (gnus-summary-article-number)))
  9794.     (marks (concat "^[" marks "]")))
  9795.     (goto-char (point-min))
  9796.     (if gnus-newsgroup-adaptive
  9797.     (gnus-score-remove-lines-adaptive marks)
  9798.       (while (re-search-forward marks nil t)
  9799.     (gnus-delete-line)))
  9800.     ;; If we use dummy roots, we have to do an additional sweep over
  9801.     ;; the buffer.
  9802.     (if (not (eq gnus-summary-make-false-root 'dummy))
  9803.     ()
  9804.       (goto-char (point-min))
  9805.       (setq marks (concat "^[" (char-to-string gnus-dummy-mark) "]"))
  9806.       (while (re-search-forward marks nil t)
  9807.     (if (gnus-subject-equal
  9808.          (gnus-summary-subject-string)
  9809.          (progn
  9810.            (forward-line 1)
  9811.            (gnus-summary-subject-string)))
  9812.         ()
  9813.       (forward-line -1)
  9814.       (gnus-delete-line))))
  9815.     (or (zerop (buffer-size))
  9816.     (gnus-summary-goto-subject orig-article)
  9817.     (if (eobp)
  9818.         (gnus-summary-prev-subject 1)
  9819.       (gnus-summary-position-cursor)))))
  9820.  
  9821. (defun gnus-summary-expunge-below (&optional score)
  9822.   "Remove articles with score less than SCORE."
  9823.   (interactive "P")
  9824.   (gnus-set-global-variables)
  9825.   (setq score (if score
  9826.           (prefix-numeric-value score)
  9827.         (or gnus-summary-default-score 0)))
  9828.   (save-excursion
  9829.     (set-buffer gnus-summary-buffer)
  9830.     (goto-char (point-min))
  9831.     (let ((buffer-read-only nil)
  9832.       beg)
  9833.       (while (not (eobp))
  9834.     (if (< (gnus-summary-article-score) score)
  9835.         (progn
  9836.           (setq beg (point))
  9837.           (forward-line 1)
  9838.           (delete-region beg (point)))
  9839.       (forward-line 1)))
  9840.       ;; Adjust point.
  9841.       (or (zerop (buffer-size))
  9842.       (if (eobp)
  9843.           (gnus-summary-prev-subject 1)
  9844.         (gnus-summary-position-cursor))))))
  9845.  
  9846. (defun gnus-summary-mark-below (score mark)
  9847.   "Mark articles with score less than SCORE with MARK."
  9848.   (interactive "P\ncMark: ")
  9849.   (gnus-set-global-variables)
  9850.   (setq score (if score
  9851.           (prefix-numeric-value score)
  9852.         (or gnus-summary-default-score 0)))
  9853.   (save-excursion
  9854.     (set-buffer gnus-summary-buffer)
  9855.     (goto-char (point-min))
  9856.     (while (not (eobp))
  9857.       (and (< (gnus-summary-article-score) score)
  9858.        (gnus-summary-mark-article nil mark))
  9859.       (forward-line 1))))
  9860.  
  9861. (defun gnus-summary-kill-below (&optional score)
  9862.   "Mark articles with score below SCORE as read."
  9863.   (interactive "P")
  9864.   (gnus-set-global-variables)
  9865.   (gnus-summary-mark-below score gnus-killed-mark))
  9866.  
  9867. (defun gnus-summary-clear-above (&optional score)
  9868.   "Clear all marks from articles with score above SCORE."
  9869.   (interactive "P")
  9870.   (gnus-set-global-variables)
  9871.   (gnus-summary-mark-above score gnus-unread-mark))
  9872.  
  9873. (defun gnus-summary-tick-above (&optional score)
  9874.   "Tick all articles with score above SCORE."
  9875.   (interactive "P")
  9876.   (gnus-set-global-variables)
  9877.   (gnus-summary-mark-above score gnus-ticked-mark))
  9878.  
  9879. (defun gnus-summary-mark-above (score mark)
  9880.   "Mark articles with score over SCORE with MARK."
  9881.   (interactive "P\ncMark: ")
  9882.   (gnus-set-global-variables)
  9883.   (setq score (if score
  9884.           (prefix-numeric-value score)
  9885.         (or gnus-summary-default-score 0)))
  9886.   (save-excursion
  9887.     (set-buffer gnus-summary-buffer)
  9888.     (goto-char (point-min))
  9889.     (while (not (eobp))
  9890.       (if (> (gnus-summary-article-score) score)
  9891.       (progn
  9892.         (gnus-summary-mark-article nil mark)
  9893.         (forward-line 1))
  9894.     (forward-line 1)))))
  9895.  
  9896. ;; Suggested by Daniel Quinlan <quinlan@best.com>.  
  9897. (defun gnus-summary-show-all-expunged ()
  9898.   "Display all the hidden articles that were expunged for low scores."
  9899.   (interactive)
  9900.   (gnus-set-global-variables)
  9901.   (let ((buffer-read-only nil))
  9902.     (let ((scored gnus-newsgroup-scored)
  9903.       headers h)
  9904.       (while scored
  9905.     (or (gnus-summary-goto-subject (car (car scored)))
  9906.         (and (setq h (gnus-get-header-by-num (car (car scored))))
  9907.          (< (cdr (car scored)) gnus-summary-expunge-below)
  9908.          (setq headers (cons h headers))))
  9909.     (setq scored (cdr scored)))
  9910.       (or headers (error "No expunged articles hidden."))
  9911.       (goto-char (point-min))
  9912.       (save-excursion 
  9913.     (gnus-summary-update-lines 
  9914.      (point)
  9915.      (progn
  9916.        (gnus-summary-prepare-unthreaded (nreverse headers))
  9917.        (point)))))
  9918.     (goto-char (point-min))
  9919.     (gnus-summary-position-cursor)))
  9920.  
  9921. (defun gnus-summary-show-all-dormant ()
  9922.   "Display all the hidden articles that are marked as dormant."
  9923.   (interactive)
  9924.   (gnus-set-global-variables)
  9925.   (let ((buffer-read-only nil))
  9926.     (let ((dormant gnus-newsgroup-dormant)
  9927.       headers h)
  9928.       (while dormant
  9929.     (or (gnus-summary-goto-subject (car dormant))
  9930.         (and (setq h (gnus-get-header-by-num (car dormant)))
  9931.          (setq headers (cons h headers))))
  9932.     (setq dormant (cdr dormant)))
  9933.       (or headers (error "No dormant articles hidden."))
  9934.       (goto-char (point-min))
  9935.       (save-excursion 
  9936.     (gnus-summary-update-lines 
  9937.      (point)
  9938.      (progn
  9939.        (gnus-summary-prepare-unthreaded (nreverse headers))
  9940.        (point)))))
  9941.     (goto-char (point-min))
  9942.     (gnus-summary-position-cursor)))
  9943.  
  9944. (defun gnus-summary-hide-all-dormant ()
  9945.   "Hide all dormant articles."
  9946.   (interactive)
  9947.   (gnus-set-global-variables)
  9948.   (gnus-summary-remove-lines-marked-with (char-to-string gnus-dormant-mark))
  9949.   (gnus-summary-position-cursor))
  9950.  
  9951. (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
  9952.   "Mark all articles not marked as unread in this newsgroup as read.
  9953. If prefix argument ALL is non-nil, all articles are marked as read.
  9954. If QUIETLY is non-nil, no questions will be asked.
  9955. If TO-HERE is non-nil, it should be a point in the buffer. All
  9956. articles before this point will be marked as read.
  9957. The number of articles marked as read is returned."
  9958.   (interactive "P")
  9959.   (gnus-set-global-variables)
  9960.   (prog1
  9961.       (if (or quietly
  9962.           (not gnus-interactive-catchup) ;Without confirmation?
  9963.           gnus-expert-user
  9964.           (gnus-y-or-n-p
  9965.            (if all
  9966.            "Mark absolutely all articles as read? "
  9967.          "Mark all unread articles as read? ")))
  9968.       (if (and not-mark 
  9969.            (not gnus-newsgroup-adaptive)
  9970.            (not gnus-newsgroup-auto-expire))
  9971.           (progn
  9972.         (and all (setq gnus-newsgroup-marked nil
  9973.                    gnus-newsgroup-dormant nil))
  9974.         (setq gnus-newsgroup-unreads 
  9975.               (append gnus-newsgroup-marked gnus-newsgroup-dormant)))
  9976.         ;; We actually mark all articles as canceled, which we
  9977.         ;; have to do when using auto-expiry or adaptive scoring. 
  9978.         (gnus-summary-show-all-threads)
  9979.         (if (gnus-summary-first-subject (not all))
  9980.         (while (and 
  9981.             (if to-here (< (point) to-here) t)
  9982.             (gnus-summary-mark-article-as-read gnus-catchup-mark)
  9983.             (gnus-summary-search-subject nil (not all)))))
  9984.         (or to-here
  9985.         (setq gnus-newsgroup-unreads
  9986.               (append gnus-newsgroup-marked
  9987.                   gnus-newsgroup-dormant)))))
  9988.     (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
  9989.       (if (and (not to-here) (eq 'nnvirtual (car method)))
  9990.       (nnvirtual-catchup-group
  9991.        (gnus-group-real-name gnus-newsgroup-name) (nth 1 method) all)))
  9992.     (gnus-summary-position-cursor)))
  9993.  
  9994. (defun gnus-summary-catchup-to-here (&optional all)
  9995.   "Mark all unticked articles before the current one as read.
  9996. If ALL is non-nil, also mark ticked and dormant articles as read."
  9997.   (interactive "P")
  9998.   (gnus-set-global-variables)
  9999.   (save-excursion
  10000.     (and (zerop (forward-line -1))
  10001.      (progn
  10002.        (end-of-line)
  10003.        (gnus-summary-catchup all t (point))
  10004.        (gnus-set-mode-line 'summary))))
  10005.   (gnus-summary-position-cursor))
  10006.  
  10007. (defun gnus-summary-catchup-all (&optional quietly)
  10008.   "Mark all articles in this newsgroup as read."
  10009.   (interactive "P")
  10010.   (gnus-set-global-variables)
  10011.   (gnus-summary-catchup t quietly))
  10012.  
  10013. (defun gnus-summary-catchup-and-exit (&optional all quietly)
  10014.   "Mark all articles not marked as unread in this newsgroup as read, then exit.
  10015. If prefix argument ALL is non-nil, all articles are marked as read."
  10016.   (interactive "P")
  10017.   (gnus-set-global-variables)
  10018.   (gnus-summary-catchup all quietly nil 'fast)
  10019.   ;; Select next newsgroup or exit.
  10020.   (if (and (eq gnus-auto-select-next 'quietly)
  10021.        (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
  10022.       (gnus-summary-next-group nil)
  10023.     (gnus-summary-exit)))
  10024.  
  10025. (defun gnus-summary-catchup-all-and-exit (&optional quietly)
  10026.   "Mark all articles in this newsgroup as read, and then exit."
  10027.   (interactive "P")
  10028.   (gnus-set-global-variables)
  10029.   (gnus-summary-catchup-and-exit t quietly))
  10030.  
  10031. ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
  10032. (defun gnus-summary-catchup-and-goto-next-group (&optional all)
  10033.   "Mark all articles in this group as read and select the next group.
  10034. If given a prefix, mark all articles, unread as well as ticked, as
  10035. read." 
  10036.   (interactive "P")
  10037.   (gnus-set-global-variables)
  10038.   (gnus-summary-catchup all)
  10039.   (gnus-summary-next-group))
  10040.  
  10041. ;; Thread-based commands.
  10042.  
  10043. (defun gnus-summary-toggle-threads (&optional arg)
  10044.   "Toggle showing conversation threads.
  10045. If ARG is positive number, turn showing conversation threads on."
  10046.   (interactive "P")
  10047.   (gnus-set-global-variables)
  10048.   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
  10049.     (setq gnus-show-threads
  10050.       (if (null arg) (not gnus-show-threads)
  10051.         (> (prefix-numeric-value arg) 0)))
  10052.     (gnus-summary-prepare)
  10053.     (gnus-summary-goto-subject current)
  10054.     (gnus-summary-position-cursor)))
  10055.  
  10056. (defun gnus-summary-show-all-threads ()
  10057.   "Show all threads."
  10058.   (interactive)
  10059.   (gnus-set-global-variables)
  10060.   (save-excursion
  10061.     (let ((buffer-read-only nil))
  10062.       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
  10063.   (gnus-summary-position-cursor))
  10064.  
  10065. (defun gnus-summary-show-thread ()
  10066.   "Show thread subtrees.
  10067. Returns nil if no thread was there to be shown."
  10068.   (interactive)
  10069.   (gnus-set-global-variables)
  10070.   (let ((buffer-read-only nil)
  10071.     (orig (prog1 (point) (gnus-summary-hide-thread)))
  10072.     ;; first goto end then to beg, to have point at beg after let
  10073.     (end (progn (end-of-line) (point)))
  10074.     (beg (progn (beginning-of-line) (point))))
  10075.     (prog1
  10076.     ;; Any hidden lines here?
  10077.     (search-forward "\r" end t)
  10078.       (subst-char-in-region beg end ?\^M ?\n t)
  10079.       (goto-char orig)
  10080.       (gnus-summary-position-cursor))))
  10081.  
  10082. (defun gnus-summary-hide-all-threads ()
  10083.   "Hide all thread subtrees."
  10084.   (interactive)
  10085.   (gnus-set-global-variables)
  10086.   (save-excursion
  10087.     (goto-char (point-min))
  10088.     (gnus-summary-hide-thread)
  10089.     (while (and (not (eobp)) (zerop (forward-line 1)))
  10090.       (gnus-summary-hide-thread)))
  10091.   (gnus-summary-position-cursor))
  10092.  
  10093. (defun gnus-summary-hide-thread ()
  10094.   "Hide thread subtrees.
  10095. Returns nil if no threads were there to be hidden."
  10096.   (interactive)
  10097.   (gnus-set-global-variables)
  10098.   (let ((buffer-read-only nil)
  10099.     (start (point))
  10100.     (level (gnus-summary-thread-level))
  10101.     (end (point)))
  10102.     ;; Go forward until either the buffer ends or the subthread
  10103.     ;; ends. 
  10104.     (if (eobp)
  10105.     ()
  10106.       (while (and (zerop (forward-line 1))
  10107.           (> (gnus-summary-thread-level) level))
  10108.     (setq end (point)))
  10109.       (prog1
  10110.       (save-excursion
  10111.         (goto-char end)
  10112.         (search-backward "\n" start t))
  10113.     (subst-char-in-region start end ?\n ?\^M t)
  10114.     (forward-line -1)
  10115.     (gnus-summary-position-cursor)))))
  10116.  
  10117. (defun gnus-summary-go-to-next-thread (&optional previous)
  10118.   "Go to the same level (or less) next thread.
  10119. If PREVIOUS is non-nil, go to previous thread instead.
  10120. Return the article number moved to, or nil if moving was impossible."
  10121.   (let ((level (gnus-summary-thread-level))
  10122.     (article (gnus-summary-article-number)))
  10123.     (if previous 
  10124.     (while (and (zerop (forward-line -1))
  10125.             (> (gnus-summary-thread-level) level)))
  10126.       (while (and (save-excursion
  10127.             (forward-line 1)
  10128.             (not (eobp)))
  10129.           (zerop (forward-line 1))
  10130.           (> (gnus-summary-thread-level) level))))
  10131.     (gnus-summary-recenter)
  10132.     (gnus-summary-position-cursor)
  10133.     (let ((oart (gnus-summary-article-number)))
  10134.       (and (/= oart article) oart))))
  10135.  
  10136. (defun gnus-summary-next-thread (n)
  10137.   "Go to the same level next N'th thread.
  10138. If N is negative, search backward instead.
  10139. Returns the difference between N and the number of skips actually
  10140. done."
  10141.   (interactive "p")
  10142.   (gnus-set-global-variables)
  10143.   (let ((backward (< n 0))
  10144.     (n (abs n)))
  10145.     (while (and (> n 0)
  10146.         (gnus-summary-go-to-next-thread backward))
  10147.       (setq n (1- n)))
  10148.     (gnus-summary-position-cursor)
  10149.     (if (/= 0 n) (gnus-message 7 "No more threads"))
  10150.     n))
  10151.  
  10152. (defun gnus-summary-prev-thread (n)
  10153.   "Go to the same level previous N'th thread.
  10154. Returns the difference between N and the number of skips actually
  10155. done."
  10156.   (interactive "p")
  10157.   (gnus-set-global-variables)
  10158.   (gnus-summary-next-thread (- n)))
  10159.  
  10160. (defun gnus-summary-go-down-thread (&optional same)
  10161.   "Go down one level in the current thread.
  10162. If SAME is non-nil, also move to articles of the same level."
  10163.   (let ((level (gnus-summary-thread-level))
  10164.     (start (point)))
  10165.     (if (and (zerop (forward-line 1))
  10166.          (> (gnus-summary-thread-level) level))
  10167.     t
  10168.       (goto-char start)
  10169.       nil)))
  10170.  
  10171. (defun gnus-summary-go-up-thread ()
  10172.   "Go up one level in the current thread."
  10173.   (let ((level (gnus-summary-thread-level))
  10174.     (start (point)))
  10175.     (while (and (zerop (forward-line -1))
  10176.         (>= (gnus-summary-thread-level) level)))
  10177.     (if (>= (gnus-summary-thread-level) level)
  10178.     (progn
  10179.       (goto-char start)
  10180.       nil)
  10181.       t)))
  10182.  
  10183. (defun gnus-summary-down-thread (n)
  10184.   "Go down thread N steps.
  10185. If N is negative, go up instead.
  10186. Returns the difference between N and how many steps down that were
  10187. taken."
  10188.   (interactive "p")
  10189.   (gnus-set-global-variables)
  10190.   (let ((up (< n 0))
  10191.     (n (abs n)))
  10192.     (while (and (> n 0)
  10193.         (if up (gnus-summary-go-up-thread)
  10194.           (gnus-summary-go-down-thread)))
  10195.       (setq n (1- n)))
  10196.     (gnus-summary-position-cursor)
  10197.     (if (/= 0 n) (gnus-message 7 "Can't go further"))
  10198.     n))
  10199.  
  10200. (defun gnus-summary-up-thread (n)
  10201.   "Go up thread N steps.
  10202. If N is negative, go up instead.
  10203. Returns the difference between N and how many steps down that were
  10204. taken."
  10205.   (interactive "p")
  10206.   (gnus-set-global-variables)
  10207.   (gnus-summary-down-thread (- n)))
  10208.  
  10209. (defun gnus-summary-kill-thread (&optional unmark)
  10210.   "Mark articles under current thread as read.
  10211. If the prefix argument is positive, remove any kinds of marks.
  10212. If the prefix argument is negative, tick articles instead."
  10213.   (interactive "P")
  10214.   (gnus-set-global-variables)
  10215.   (if unmark
  10216.       (setq unmark (prefix-numeric-value unmark)))
  10217.   (let ((killing t)
  10218.     (level (gnus-summary-thread-level)))
  10219.     (save-excursion
  10220.       ;; Expand the thread.
  10221.       (gnus-summary-show-thread)
  10222.       (while killing
  10223.     ;; Mark the article...
  10224.     (cond ((null unmark) (gnus-summary-mark-article-as-read
  10225.                   gnus-killed-mark))
  10226.           ((> unmark 0) (gnus-summary-mark-article-as-unread 
  10227.                  gnus-unread-mark))
  10228.           (t (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
  10229.     ;; ...and go forward until either the buffer ends or the subtree
  10230.     ;; ends. 
  10231.     (if (not (and (zerop (forward-line 1))
  10232.               (> (gnus-summary-thread-level) level)))
  10233.         (setq killing nil))))
  10234.     ;; Hide killed subtrees.
  10235.     (and (null unmark)
  10236.      gnus-thread-hide-killed
  10237.      (gnus-summary-hide-thread))
  10238.     ;; If marked as read, go to next unread subject.
  10239.     (if (null unmark)
  10240.     ;; Go to next unread subject.
  10241.     (gnus-summary-next-subject 1 t)))
  10242.   (gnus-set-mode-line 'summary))
  10243.  
  10244. ;; Summary sorting commands
  10245.  
  10246. (defun gnus-summary-sort-by-number (&optional reverse)
  10247.   "Sort summary buffer by article number.
  10248. Argument REVERSE means reverse order."
  10249.   (interactive "P")
  10250.   (gnus-set-global-variables)
  10251.   (gnus-summary-sort 
  10252.    ;; `gnus-summary-article-number' is a macro, and `sort-subr' wants
  10253.    ;; a function, so we wrap it.
  10254.    (cons (lambda () (gnus-summary-article-number))
  10255.      'gnus-thread-sort-by-number) reverse))
  10256.  
  10257. (defun gnus-summary-sort-by-author (&optional reverse)
  10258.   "Sort summary buffer by author name alphabetically.
  10259. If case-fold-search is non-nil, case of letters is ignored.
  10260. Argument REVERSE means reverse order."
  10261.   (interactive "P")
  10262.   (gnus-set-global-variables)
  10263.   (gnus-summary-sort
  10264.    (cons
  10265.     (lambda ()
  10266.       (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
  10267.          extract)
  10268.     (if (not (vectorp header))
  10269.         ""
  10270.       (setq extract (funcall gnus-extract-address-components
  10271.                  (mail-header-from header)))
  10272.       (concat (or (car extract) (cdr extract))
  10273.           "\r" (int-to-string (mail-header-number header))
  10274.           "\r" (mail-header-subject header)))))
  10275.     'gnus-thread-sort-by-author)
  10276.    reverse))
  10277.  
  10278. (defun gnus-summary-sort-by-subject (&optional reverse)
  10279.   "Sort summary buffer by subject alphabetically. `Re:'s are ignored.
  10280. If case-fold-search is non-nil, case of letters is ignored.
  10281. Argument REVERSE means reverse order."
  10282.   (interactive "P")
  10283.   (gnus-set-global-variables)
  10284.   (gnus-summary-sort
  10285.    (cons
  10286.     (lambda ()
  10287.       (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
  10288.          extract)
  10289.     (if (not (vectorp header))
  10290.         ""
  10291.       (setq extract (funcall gnus-extract-address-components
  10292.                  (mail-header-from header)))
  10293.       (concat 
  10294.        (downcase (gnus-simplify-subject (gnus-summary-subject-string) t))
  10295.        "\r" (int-to-string (mail-header-number header))
  10296.        "\r" (or (car extract) (cdr extract))))))
  10297.     'gnus-thread-sort-by-subject)
  10298.    reverse))
  10299.  
  10300. (defun gnus-summary-sort-by-date (&optional reverse)
  10301.   "Sort summary buffer by date.
  10302. Argument REVERSE means reverse order."
  10303.   (interactive "P")
  10304.   (gnus-set-global-variables)
  10305.   (gnus-summary-sort
  10306.    (cons
  10307.     (lambda ()
  10308.       (gnus-sortable-date
  10309.        (mail-header-date 
  10310.     (gnus-get-header-by-num (gnus-summary-article-number)))))
  10311.     'gnus-thread-sort-by-date)
  10312.    reverse))
  10313.  
  10314. (defun gnus-summary-sort-by-score (&optional reverse)
  10315.   "Sort summary buffer by score.
  10316. Argument REVERSE means reverse order."
  10317.   (interactive "P")
  10318.   (gnus-set-global-variables)
  10319.   (gnus-summary-sort 
  10320.    (cons (lambda () (gnus-summary-article-score))
  10321.      'gnus-thread-sort-by-score)
  10322.    (not reverse)))
  10323.  
  10324. (defvar gnus-summary-already-sorted nil)
  10325. (defun gnus-summary-sort (predicate reverse)
  10326.   ;; Sort summary buffer by PREDICATE.  REVERSE means reverse order. 
  10327.   (if gnus-summary-already-sorted
  10328.       ()
  10329.     (let (buffer-read-only)
  10330.       (if (not gnus-show-threads)
  10331.       ;; We do untreaded sorting...
  10332.       (progn
  10333.         (goto-char (point-min))
  10334.         (sort-subr reverse 'forward-line 'end-of-line (car predicate)))
  10335.     ;; ... or we do threaded sorting.
  10336.     (let ((gnus-thread-sort-functions (list (cdr predicate)))
  10337.           (gnus-summary-prepare-hook nil)
  10338.           (gnus-summary-already-sorted nil))
  10339.       ;; We do that by simply regenerating the threads.
  10340.       (gnus-summary-prepare)
  10341.       (and gnus-show-threads
  10342.            gnus-thread-hide-subtree
  10343.            (gnus-summary-hide-all-threads))
  10344.       ;; If in async mode, we send some info to the backend.
  10345.       (and gnus-newsgroup-async
  10346.            (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
  10347.            (gnus-request-asynchronous 
  10348.         gnus-newsgroup-name
  10349.         (if (and gnus-asynchronous-article-function
  10350.              (fboundp gnus-asynchronous-article-function))
  10351.             (funcall gnus-asynchronous-article-function
  10352.                  gnus-newsgroup-threads)
  10353.           gnus-newsgroup-threads))))))))
  10354.  
  10355.   
  10356. (defun gnus-sortable-date (date)
  10357.   "Make sortable string by string-lessp from DATE.
  10358. Timezone package is used."
  10359.   (let* ((date (timezone-fix-time date nil nil)) ;[Y M D H M S]
  10360.      (year (aref date 0))
  10361.      (month (aref date 1))
  10362.      (day (aref date 2)))
  10363.     (timezone-make-sortable-date 
  10364.      year month day 
  10365.      (timezone-make-time-string
  10366.       (aref date 3) (aref date 4) (aref date 5)))))
  10367.  
  10368.  
  10369. ;; Summary saving commands.
  10370.  
  10371. (defun gnus-summary-save-article (&optional n)
  10372.   "Save the current article using the default saver function.
  10373. If N is a positive number, save the N next articles.
  10374. If N is a negative number, save the N previous articles.
  10375. If N is nil and any articles have been marked with the process mark,
  10376. save those articles instead.
  10377. The variable `gnus-default-article-saver' specifies the saver function."
  10378.   (interactive "P")
  10379.   (gnus-set-global-variables)
  10380.   (let ((articles (gnus-summary-work-articles n)))
  10381.     (while articles
  10382.       (let ((header (gnus-get-header-by-num (car articles))))
  10383.     (if (vectorp header)
  10384.         (progn
  10385.           (save-window-excursion
  10386.         (gnus-summary-select-article t nil nil (car articles)))
  10387.           (or gnus-save-all-headers
  10388.           (gnus-article-hide-headers t))
  10389.           ;; Remove any X-Gnus lines.
  10390.           (save-excursion
  10391.         (save-restriction
  10392.           (set-buffer gnus-article-buffer)
  10393.           (let ((buffer-read-only nil))
  10394.             (goto-char (point-min))
  10395.             (narrow-to-region (point) (or (search-forward "\n\n" nil t)
  10396.                           (point-max)))
  10397.             (while (re-search-forward "^X-Gnus" nil t)
  10398.               (beginning-of-line)
  10399.               (delete-region (point)
  10400.                      (progn (forward-line 1) (point))))
  10401.             (widen))))
  10402.           (save-window-excursion
  10403.         (if gnus-default-article-saver
  10404.             (funcall gnus-default-article-saver)
  10405.           (error "No default saver is defined."))))
  10406.       (if (assq 'name header)
  10407.           (gnus-copy-file (cdr (assq 'name header)))
  10408.         (gnus-message 1 "Article %d is unsavable" (car articles)))))
  10409.       (gnus-summary-remove-process-mark (car articles))
  10410.       (setq articles (cdr articles)))
  10411.     (gnus-summary-position-cursor)
  10412.     n))
  10413.  
  10414. (defun gnus-summary-pipe-output (&optional arg)
  10415.   "Pipe the current article to a subprocess.
  10416. If N is a positive number, pipe the N next articles.
  10417. If N is a negative number, pipe the N previous articles.
  10418. If N is nil and any articles have been marked with the process mark,
  10419. pipe those articles instead."
  10420.   (interactive "P")
  10421.   (gnus-set-global-variables)
  10422.   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
  10423.     (gnus-summary-save-article arg))
  10424.   (gnus-configure-windows 'pipe))
  10425.  
  10426. (defun gnus-summary-save-article-mail (&optional arg)
  10427.   "Append the current article to an mail file.
  10428. If N is a positive number, save the N next articles.
  10429. If N is a negative number, save the N previous articles.
  10430. If N is nil and any articles have been marked with the process mark,
  10431. save those articles instead."
  10432.   (interactive "P")
  10433.   (gnus-set-global-variables)
  10434.   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
  10435.     (gnus-summary-save-article arg)))
  10436.  
  10437. (defun gnus-summary-save-article-rmail (&optional arg)
  10438.   "Append the current article to an rmail file.
  10439. If N is a positive number, save the N next articles.
  10440. If N is a negative number, save the N previous articles.
  10441. If N is nil and any articles have been marked with the process mark,
  10442. save those articles instead."
  10443.   (interactive "P")
  10444.   (gnus-set-global-variables)
  10445.   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
  10446.     (gnus-summary-save-article arg)))
  10447.  
  10448. (defun gnus-summary-save-article-file (&optional arg)
  10449.   "Append the current article to a file.
  10450. If N is a positive number, save the N next articles.
  10451. If N is a negative number, save the N previous articles.
  10452. If N is nil and any articles have been marked with the process mark,
  10453. save those articles instead."
  10454.   (interactive "P")
  10455.   (gnus-set-global-variables)
  10456.   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
  10457.     (gnus-summary-save-article arg)))
  10458.  
  10459. (defun gnus-read-save-file-name (prompt default-name)
  10460.   (let ((methods gnus-split-methods)
  10461.     split-name)
  10462.     (if (not gnus-split-methods)
  10463.     ()
  10464.       (save-excursion
  10465.     (set-buffer gnus-article-buffer)
  10466.     (gnus-narrow-to-headers)
  10467.     (while methods
  10468.       (goto-char (point-min))
  10469.       (and (condition-case () 
  10470.            (re-search-forward (car (car methods)) nil t)
  10471.          (error nil))
  10472.            (setq split-name (cons (nth 1 (car methods)) split-name)))
  10473.       (setq methods (cdr methods)))
  10474.     (widen)))
  10475.     (cond ((null split-name)
  10476.        (read-file-name
  10477.         (concat prompt " (default "
  10478.             (file-name-nondirectory default-name) ") ")
  10479.         (file-name-directory default-name)
  10480.         default-name))
  10481.       ((= 1 (length split-name))
  10482.        (read-file-name
  10483.         (concat prompt " (default " (car split-name) ") ")
  10484.         gnus-article-save-directory
  10485.         (concat gnus-article-save-directory (car split-name))))
  10486.       (t
  10487.        (setq split-name (mapcar (lambda (el) (list el))
  10488.                     (nreverse split-name)))
  10489.        (let ((result (completing-read 
  10490.               (concat prompt " ")
  10491.               split-name nil nil)))
  10492.          (concat gnus-article-save-directory
  10493.              (if (string= result "")
  10494.              (car (car split-name))
  10495.                result)))))))
  10496.  
  10497. (defun gnus-summary-save-in-rmail (&optional filename)
  10498.   "Append this article to Rmail file.
  10499. Optional argument FILENAME specifies file name.
  10500. Directory to save to is default to `gnus-article-save-directory' which
  10501. is initialized from the SAVEDIR environment variable."
  10502.   (interactive)
  10503.   (gnus-set-global-variables)
  10504.   (let ((default-name
  10505.       (funcall gnus-rmail-save-name gnus-newsgroup-name
  10506.            gnus-current-headers gnus-newsgroup-last-rmail)))
  10507.     (or filename
  10508.     (setq filename (gnus-read-save-file-name 
  10509.             "Save in rmail file:" default-name)))
  10510.     (gnus-make-directory (file-name-directory filename))
  10511.     (gnus-eval-in-buffer-window 
  10512.      gnus-article-buffer
  10513.      (save-excursion
  10514.        (save-restriction
  10515.      (widen)
  10516.      (gnus-output-to-rmail filename))))
  10517.     ;; Remember the directory name to save articles
  10518.     (setq gnus-newsgroup-last-rmail filename)))
  10519.  
  10520. (defun gnus-summary-save-in-mail (&optional filename)
  10521.   "Append this article to Unix mail file.
  10522. Optional argument FILENAME specifies file name.
  10523. Directory to save to is default to `gnus-article-save-directory' which
  10524. is initialized from the SAVEDIR environment variable."
  10525.   (interactive)
  10526.   (gnus-set-global-variables)
  10527.   (let ((default-name
  10528.       (funcall gnus-mail-save-name gnus-newsgroup-name
  10529.            gnus-current-headers gnus-newsgroup-last-mail)))
  10530.     (or filename
  10531.     (setq filename (gnus-read-save-file-name 
  10532.             "Save in Unix mail file:" default-name)))
  10533.     (setq filename
  10534.       (expand-file-name filename
  10535.                 (and default-name
  10536.                  (file-name-directory default-name))))
  10537.     (gnus-make-directory (file-name-directory filename))
  10538.     (gnus-eval-in-buffer-window 
  10539.      gnus-article-buffer
  10540.      (save-excursion
  10541.        (save-restriction
  10542.      (widen)
  10543.      (if (and (file-readable-p filename) (mail-file-babyl-p filename))
  10544.          (gnus-output-to-rmail filename)
  10545.        (rmail-output filename 1 t t)))))
  10546.     ;; Remember the directory name to save articles.
  10547.     (setq gnus-newsgroup-last-mail filename)))
  10548.  
  10549. (defun gnus-summary-save-in-file (&optional filename)
  10550.   "Append this article to file.
  10551. Optional argument FILENAME specifies file name.
  10552. Directory to save to is default to `gnus-article-save-directory' which
  10553. is initialized from the SAVEDIR environment variable."
  10554.   (interactive)
  10555.   (gnus-set-global-variables)
  10556.   (let ((default-name
  10557.       (funcall gnus-file-save-name gnus-newsgroup-name
  10558.            gnus-current-headers gnus-newsgroup-last-file)))
  10559.     (or filename
  10560.     (setq filename (gnus-read-save-file-name 
  10561.             "Save in file:" default-name)))
  10562.     (gnus-make-directory (file-name-directory filename))
  10563.     (gnus-eval-in-buffer-window 
  10564.      gnus-article-buffer
  10565.      (save-excursion
  10566.        (save-restriction
  10567.      (widen)
  10568.      (gnus-output-to-file filename))))
  10569.     ;; Remember the directory name to save articles.
  10570.     (setq gnus-newsgroup-last-file filename)))
  10571.  
  10572. (defun gnus-summary-save-in-pipe (&optional command)
  10573.   "Pipe this article to subprocess."
  10574.   (interactive)
  10575.   (gnus-set-global-variables)
  10576.   (let ((command (read-string "Shell command on article: "
  10577.                   gnus-last-shell-command)))
  10578.     (if (string-equal command "")
  10579.     (setq command gnus-last-shell-command))
  10580.     (gnus-eval-in-buffer-window 
  10581.      gnus-article-buffer
  10582.      (save-restriction
  10583.        (widen)
  10584.        (shell-command-on-region (point-min) (point-max) command nil)))
  10585.     (setq gnus-last-shell-command command)))
  10586.  
  10587. ;; Summary extract commands
  10588.  
  10589. (defun gnus-summary-insert-pseudos (pslist &optional not-view)
  10590.   (let ((buffer-read-only nil)
  10591.     (article (gnus-summary-article-number))
  10592.     b)
  10593.     (or (gnus-summary-goto-subject article)
  10594.     (error (format "No such article: %d" article)))
  10595.     (gnus-summary-position-cursor)
  10596.     ;; If all commands are to be bunched up on one line, we collect
  10597.     ;; them here.  
  10598.     (if gnus-view-pseudos-separately
  10599.     ()
  10600.       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
  10601.         files action)
  10602.     (while ps
  10603.       (setq action (cdr (assq 'action (car ps))))
  10604.       (setq files (list (cdr (assq 'name (car ps)))))
  10605.       (while (and ps (cdr ps)
  10606.               (string= (or action "1")
  10607.                    (or (cdr (assq 'action (car (cdr ps)))) "2")))
  10608.         (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
  10609.         (setcdr ps (cdr (cdr ps))))
  10610.       (if (not files)
  10611.           ()
  10612.         (if (not (string-match "%s" action))
  10613.         (setq files (cons " " files)))
  10614.         (setq files (cons " " files))
  10615.         (and (assq 'execute (car ps))
  10616.          (setcdr (assq 'execute (car ps))
  10617.              (funcall (if (string-match "%s" action)
  10618.                       'format 'concat)
  10619.                   action 
  10620.                   (mapconcat (lambda (f) f) files " ")))))
  10621.       (setq ps (cdr ps)))))
  10622.     (if (and gnus-view-pseudos (not not-view))
  10623.     (while pslist
  10624.       (and (assq 'execute (car pslist))
  10625.            (gnus-execute-command (cdr (assq 'execute (car pslist)))
  10626.                      (eq gnus-view-pseudos 'not-confirm)))
  10627.       (setq pslist (cdr pslist)))
  10628.       (save-excursion
  10629.     (while pslist
  10630.       (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist)))
  10631.                      (gnus-summary-article-number)))
  10632.       (forward-line 1)
  10633.       (setq b (point))
  10634.       (insert "          " (file-name-nondirectory 
  10635.                 (cdr (assq 'name (car pslist))))
  10636.           ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
  10637.       (add-text-properties 
  10638.        b (1+ b) (list 'gnus-number gnus-reffed-article-number
  10639.               'gnus-mark gnus-unread-mark 
  10640.               'gnus-level 0
  10641.               'gnus-pseudo (car pslist)))
  10642.       (forward-line -1)
  10643.       (gnus-sethash (int-to-string gnus-reffed-article-number)
  10644.             (car pslist) gnus-newsgroup-headers-hashtb-by-number)
  10645.       (setq gnus-newsgroup-unreads
  10646.         (cons gnus-reffed-article-number gnus-newsgroup-unreads))
  10647.       (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
  10648.       (setq pslist (cdr pslist)))))))
  10649.  
  10650. (defun gnus-pseudos< (p1 p2)
  10651.   (let ((c1 (cdr (assq 'action p1)))
  10652.     (c2 (cdr (assq 'action p2))))
  10653.     (and c1 c2 (string< c1 c2))))
  10654.  
  10655. (defun gnus-request-pseudo-article (props)
  10656.   (cond ((assq 'execute props)
  10657.      (gnus-execute-command (cdr (assq 'execute props)))))
  10658.   (let ((gnus-current-article (gnus-summary-article-number)))
  10659.     (run-hooks 'gnus-mark-article-hook)))
  10660.  
  10661. (defun gnus-execute-command (command &optional automatic)
  10662.   (save-excursion
  10663.     (gnus-article-setup-buffer)
  10664.     (set-buffer gnus-article-buffer)
  10665.     (let ((command (if automatic command (read-string "Command: " command)))
  10666.       (buffer-read-only nil))
  10667.       (erase-buffer)
  10668.       (insert "$ " command "\n\n")
  10669.       (if gnus-view-pseudo-asynchronously
  10670.       (start-process "gnus-execute" nil "sh" "-c" command)
  10671.     (call-process "sh" nil t nil "-c" command)))))
  10672.  
  10673. (defun gnus-copy-file (file &optional to)
  10674.   "Copy FILE to TO."
  10675.   (interactive
  10676.    (list (read-file-name "Copy file: " default-directory)
  10677.      (read-file-name "Copy file to: " default-directory)))
  10678.   (gnus-set-global-variables)
  10679.   (or to (setq to (read-file-name "Copy file to: " default-directory)))
  10680.   (and (file-directory-p to) 
  10681.        (setq to (concat (file-name-as-directory to)
  10682.             (file-name-nondirectory file))))
  10683.   (copy-file file to))
  10684.  
  10685. ;; Summary kill commands.
  10686.  
  10687. (defun gnus-summary-edit-global-kill (article)
  10688.   "Edit the \"global\" kill file."
  10689.   (interactive (list (gnus-summary-article-number)))
  10690.   (gnus-set-global-variables)
  10691.   (gnus-group-edit-global-kill article))
  10692.  
  10693. (defun gnus-summary-edit-local-kill ()
  10694.   "Edit a local kill file applied to the current newsgroup."
  10695.   (interactive)
  10696.   (gnus-set-global-variables)
  10697.   (setq gnus-current-headers 
  10698.     (gnus-gethash 
  10699.      (int-to-string (gnus-summary-article-number))
  10700.      gnus-newsgroup-headers-hashtb-by-number))
  10701.   (gnus-set-global-variables)
  10702.   (gnus-group-edit-local-kill 
  10703.    (gnus-summary-article-number) gnus-newsgroup-name))
  10704.  
  10705.  
  10706. ;;;
  10707. ;;; Gnus article mode
  10708. ;;;
  10709.  
  10710. (put 'gnus-article-mode 'mode-class 'special)
  10711.  
  10712. (defvar gnus-bugaboo nil)
  10713.  
  10714. (if gnus-article-mode-map
  10715.     nil
  10716.   (setq gnus-article-mode-map (make-keymap))
  10717.   (suppress-keymap gnus-article-mode-map)
  10718.   (define-key gnus-article-mode-map " " 'gnus-article-next-page)
  10719.   (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page)
  10720.   (define-key gnus-article-mode-map "\C-c^" 'gnus-article-refer-article)
  10721.   (define-key gnus-article-mode-map "h" 'gnus-article-show-summary)
  10722.   (define-key gnus-article-mode-map "s" 'gnus-article-show-summary)
  10723.   (define-key gnus-article-mode-map "\C-c\C-m" 'gnus-article-mail)
  10724.   (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly)
  10725.   (define-key gnus-article-mode-map gnus-mouse-2 'gnus-article-push-button)
  10726.   (define-key gnus-article-mode-map "\r" 'gnus-article-press-button)
  10727.   (define-key gnus-article-mode-map "\t" 'gnus-article-next-button)
  10728.   (define-key gnus-article-mode-map "\C-c\C-b" 'gnus-bug)
  10729.   
  10730.   ;; Duplicate almost all summary keystrokes in the article mode map.
  10731.   (let ((commands 
  10732.      (list 
  10733.       "p" "N" "P" "\M-\C-n" "\M-\C-p"
  10734.       "\M-n" "\M-p" "." "," "\M-s" "\M-r" "<" ">" "j"
  10735.       "u" "!" "U" "d" "D" "E" "\M-u" "\M-U" "k" "\C-k" "\M-\C-k"
  10736.       "\M-\C-l" "e" "#" "\M-#" "\M-\C-t" "\M-\C-s" "\M-\C-h"
  10737.       "\M-\C-f" "\M-\C-b" "\M-\C-u" "\M-\C-d" "&" "\C-w"
  10738.       "\C-t" "?" "\C-c\M-\C-s" "\C-c\C-s\C-n" "\C-c\C-s\C-a"
  10739.       "\C-c\C-s\C-s" "\C-c\C-s\C-d" "\C-c\C-s\C-i" "\C-x\C-s"
  10740.       "\M-g" "w" "\C-c\C-r" "\M-t" "C"
  10741.       "o" "\C-o" "|" "\M-k" "\M-K" "V" "\C-c\C-d"
  10742.       "\C-c\C-i" "x" "X" "t" "g" "?" "l"
  10743.       "\C-c\C-v\C-v" "\C-d" "v" 
  10744. ;;      "Mt" "M!" "Md" "Mr"
  10745. ;;      "Mc" "M " "Me" "Mx" "M?" "Mb" "MB" "M#" "M\M-#" "M\M-r"
  10746. ;;      "M\M-\C-r" "MD" "M\M-D" "MS" "MC" "MH" "M\C-c" "Mk" "MK"
  10747. ;;      "Ms" "Mc" "Mu" "Mm" "Mk" "Gn" "Gp" "GN" "GP" "G\C-n" "G\C-p"
  10748. ;;      "G\M-n" "G\M-p" "Gf" "Gb" "Gg" "Gl" "Gp" "Tk" "Tl" "Ti" "TT"
  10749. ;;      "Ts" "TS" "Th" "TH" "Tn" "Tp" "Tu" "Td" "T#" "A " "An" "A\177" "Ap"
  10750. ;;      "A\r" "A<" "A>" "Ab" "Ae" "A^" "Ar" "Aw" "Ac" "Ag" "At" "Am"
  10751. ;;      "As" "Wh" "Ws" "Wc" "Wo" "Ww" "Wd" "Wq" "Wf" "Wt" "W\C-t"
  10752. ;;      "WT" "WA" "Wa" "WH" "WC" "WS" "Wb" "Hv" "Hf" "Hd" "Hh" "Hi"
  10753. ;;      "Be" "B\177" "Bm" "Br" "Bw" "Bc" "Bq" "Bi" "Oo" "Om" "Or"
  10754. ;;      "Of" "Oh" "Ov" "Op" "Vu" "V\C-s" "V\C-r" "Vr" "V&" "VT" "Ve"
  10755. ;;      "VD" "Vk" "VK" "Vsn" "Vsa" "Vss" "Vsd" "Vsi"
  10756.       )))
  10757.     (while (and gnus-bugaboo commands) ; disabled
  10758.       (define-key gnus-article-mode-map (car commands) 
  10759.     'gnus-article-summary-command)
  10760.       (setq commands (cdr commands))))
  10761.  
  10762.   (let ((commands (list "q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
  10763. ;;            "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP" 
  10764.              "=" "n"  "^" "\M-^")))
  10765.     (while (and gnus-bugaboo commands) ; disabled
  10766.       (define-key gnus-article-mode-map (car commands) 
  10767.     'gnus-article-summary-command-nosave)
  10768.       (setq commands (cdr commands)))))
  10769.  
  10770.  
  10771. (defun gnus-article-mode ()
  10772.   "Major mode for displaying an article.
  10773.  
  10774. All normal editing commands are switched off.
  10775.  
  10776. The following commands are available:
  10777.  
  10778. \\<gnus-article-mode-map>
  10779. \\[gnus-article-next-page]\t Scroll the article one page forwards
  10780. \\[gnus-article-prev-page]\t Scroll the article one page backwards
  10781. \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
  10782. \\[gnus-article-show-summary]\t Display the summary buffer
  10783. \\[gnus-article-mail]\t Send a reply to the address near point
  10784. \\[gnus-article-describe-briefly]\t Describe the current mode briefly
  10785. \\[gnus-info-find-node]\t Go to the Gnus info node"
  10786.   (interactive)
  10787.   (if gnus-visual (gnus-article-make-menu-bar))
  10788.   (kill-all-local-variables)
  10789.   (gnus-simplify-mode-line)
  10790.   (setq mode-name "Article")
  10791.   (setq major-mode 'gnus-article-mode)
  10792.   (make-local-variable 'minor-mode-alist)
  10793.   (or (assq 'gnus-show-mime minor-mode-alist)
  10794.       (setq minor-mode-alist
  10795.         (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
  10796.   (use-local-map gnus-article-mode-map)
  10797.   (make-local-variable 'page-delimiter)
  10798.   (setq page-delimiter gnus-page-delimiter)
  10799.   (buffer-disable-undo (current-buffer))
  10800.   (setq buffer-read-only t)        ;Disable modification
  10801.   (run-hooks 'gnus-article-mode-hook))
  10802.  
  10803. (defun gnus-article-setup-buffer ()
  10804.   "Initialize article mode buffer."
  10805.   ;; Returns the article buffer.
  10806.   (if (get-buffer gnus-article-buffer)
  10807.       (save-excursion
  10808.     (set-buffer gnus-article-buffer)
  10809.     (buffer-disable-undo (current-buffer))
  10810.     (setq buffer-read-only t)
  10811.     (gnus-add-current-to-buffer-list)
  10812.     (or (eq major-mode 'gnus-article-mode)
  10813.         (gnus-article-mode))
  10814.     (current-buffer))
  10815.     (save-excursion
  10816.       (set-buffer (get-buffer-create gnus-article-buffer))
  10817.       (gnus-add-current-to-buffer-list)
  10818.       (gnus-article-mode)
  10819.       (current-buffer))))
  10820.  
  10821. ;; Set article window start at LINE, where LINE is the number of lines
  10822. ;; from the head of the article.
  10823. (defun gnus-article-set-window-start (&optional line)
  10824.   (set-window-start 
  10825.    (get-buffer-window gnus-article-buffer)
  10826.    (save-excursion
  10827.      (set-buffer gnus-article-buffer)
  10828.      (goto-char (point-min))
  10829.      (if (not line)
  10830.      (point-min)
  10831.        (gnus-message 6 "Moved to bookmark")
  10832.        (search-forward "\n\n" nil t)
  10833.        (forward-line line)
  10834.        (point)))))
  10835.  
  10836. (defun gnus-request-article-this-buffer (article group)
  10837.   "Get an article and insert it into this buffer."
  10838.   (setq group (or group gnus-newsgroup-name))
  10839.  
  10840.   ;; Open server if it has closed.
  10841.   (gnus-check-server (gnus-find-method-for-group group))
  10842.  
  10843.   ;; Using `gnus-request-article' directly will insert the article into
  10844.   ;; `nntp-server-buffer' - so we'll save some time by not having to
  10845.   ;; copy it from the server buffer into the article buffer.
  10846.  
  10847.   ;; We only request an article by message-id when we do not have the
  10848.   ;; headers for it, so we'll have to get those.
  10849.   (and (stringp article) 
  10850.        (let ((gnus-override-method gnus-refer-article-method))
  10851.      (gnus-read-header article)))
  10852.  
  10853.   ;; If the article number is negative, that means that this article
  10854.   ;; doesn't belong in this newsgroup (possibly), so we find its
  10855.   ;; message-id and request it by id instead of number.
  10856.   (if (not (numberp article))
  10857.       ()
  10858.     (save-excursion
  10859.       (set-buffer gnus-summary-buffer)
  10860.       (let ((header (gnus-get-header-by-num article)))
  10861.     (if (< article 0)
  10862.         (if (vectorp header)
  10863.         ;; It's a real article.
  10864.         (setq article (mail-header-id header))
  10865.           ;; It is an extracted pseudo-article.
  10866.           (setq article 'pseudo)
  10867.           (gnus-request-pseudo-article header)))
  10868.  
  10869.     (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
  10870.       (if (not (eq (car method) 'nneething))
  10871.           ()
  10872.         (let ((dir (concat (file-name-as-directory (nth 1 method))
  10873.                    (mail-header-subject header))))
  10874.           (if (file-directory-p dir)
  10875.           (progn
  10876.             (setq article 'nneething)
  10877.             (gnus-group-enter-directory dir)))))))))
  10878.  
  10879.   ;; Check the cache.
  10880.   (if (and gnus-use-cache
  10881.        (numberp article)
  10882.        (gnus-cache-request-article article group))
  10883.       'article
  10884.     ;; Get the article and put into the article buffer.
  10885.     (if (or (stringp article) (numberp article))
  10886.     (progn
  10887.       (erase-buffer)
  10888.       ;; There may be some overlays that we have to kill...
  10889.       (insert "i")
  10890.       (let ((overlays (and (fboundp 'overlays-at)
  10891.                    (overlays-at (point-min)))))
  10892.         (while overlays
  10893.           (delete-overlay (car overlays))
  10894.           (setq overlays (cdr overlays))))
  10895.       (erase-buffer)      
  10896.       (let ((gnus-override-method 
  10897.          (and (stringp article) gnus-refer-article-method)))
  10898.         (and (gnus-request-article article group (current-buffer))
  10899.          'article)))
  10900.       article)))
  10901.  
  10902. (defun gnus-read-header (id)
  10903.   "Read the headers of article ID and enter them into the Gnus system."
  10904.   (let (header)
  10905.     (if (not (setq header 
  10906.            (car (if (let ((gnus-nov-is-evil t))
  10907.                   (gnus-retrieve-headers 
  10908.                    (list id) gnus-newsgroup-name))
  10909.                 (gnus-get-newsgroup-headers)))))
  10910.     nil
  10911.       (if (stringp id)
  10912.       (mail-header-set-number header gnus-reffed-article-number))
  10913.       (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers))
  10914.       (gnus-sethash (int-to-string (mail-header-number header)) header
  10915.             gnus-newsgroup-headers-hashtb-by-number)
  10916.       (if (stringp id)
  10917.       (setq gnus-reffed-article-number (1- gnus-reffed-article-number)))
  10918.       (setq gnus-current-headers header)
  10919.       header)))
  10920.  
  10921. (defun gnus-article-prepare (article &optional all-headers header)
  10922.   "Prepare ARTICLE in article mode buffer.
  10923. ARTICLE should either be an article number or a Message-ID.
  10924. If ARTICLE is an id, HEADER should be the article headers.
  10925. If ALL-HEADERS is non-nil, no headers are hidden."
  10926.   (save-excursion
  10927.     ;; Make sure we start in a summary buffer.
  10928.     (or (eq major-mode 'gnus-summary-mode)
  10929.     (set-buffer gnus-summary-buffer))
  10930.     (setq gnus-summary-buffer (current-buffer))
  10931.     ;; Make sure the connection to the server is alive.
  10932.     (or (gnus-server-opened (gnus-find-method-for-group gnus-newsgroup-name))
  10933.     (progn
  10934.       (gnus-check-server 
  10935.        (gnus-find-method-for-group gnus-newsgroup-name))
  10936.       (gnus-request-group gnus-newsgroup-name t)))
  10937.     (let* ((article (if header (mail-header-number header) article))
  10938.        (summary-buffer (current-buffer))
  10939.        (internal-hook gnus-article-internal-prepare-hook)
  10940.        (group gnus-newsgroup-name)
  10941.        result)
  10942.       (save-excursion
  10943.     (gnus-article-setup-buffer)
  10944.     (set-buffer gnus-article-buffer)
  10945.     (if (not (setq result (let ((buffer-read-only nil))
  10946.                 (gnus-request-article-this-buffer 
  10947.                  article group))))
  10948.         ;; There is no such article.
  10949.         (save-excursion
  10950.           (if (not (numberp article))
  10951.           ()
  10952.         (setq gnus-article-current 
  10953.               (cons gnus-newsgroup-name article))
  10954.         (set-buffer gnus-summary-buffer)
  10955.         (setq gnus-current-article article)
  10956.         (gnus-summary-mark-article article gnus-canceled-mark))
  10957.           (gnus-message 1 "No such article (may be canceled)")
  10958.           (ding)
  10959.           nil)
  10960.       (if (or (eq result 'pseudo) (eq result 'nneething))
  10961.           (progn
  10962.         (save-excursion
  10963.           (set-buffer summary-buffer)
  10964.           (setq gnus-last-article gnus-current-article
  10965.             gnus-newsgroup-history (cons gnus-current-article
  10966.                              gnus-newsgroup-history)
  10967.             gnus-current-article 0
  10968.             gnus-current-headers nil
  10969.             gnus-article-current nil)
  10970.           (if (eq result 'nneething)
  10971.               (gnus-configure-windows 'summary)
  10972.             (gnus-configure-windows 'article))
  10973.           (gnus-set-global-variables))
  10974.         (gnus-set-mode-line 'article))
  10975.         ;; The result from the `request' was an actual article -
  10976.         ;; or at least some text that is now displayed in the
  10977.         ;; article buffer.
  10978.         (if (and (numberp article)
  10979.              (not (eq article gnus-current-article)))
  10980.         ;; Seems like a new article has been selected.
  10981.         ;; `gnus-current-article' must be an article number.
  10982.         (save-excursion
  10983.           (set-buffer summary-buffer)
  10984.           (setq gnus-last-article gnus-current-article
  10985.             gnus-newsgroup-history (cons gnus-current-article
  10986.                              gnus-newsgroup-history)
  10987.             gnus-current-article article
  10988.             gnus-current-headers 
  10989.             (gnus-get-header-by-num gnus-current-article)
  10990.             gnus-article-current 
  10991.             (cons gnus-newsgroup-name gnus-current-article))
  10992.           (gnus-summary-show-thread)
  10993.           (run-hooks 'gnus-mark-article-hook)
  10994.           (gnus-set-mode-line 'summary)
  10995.           (and gnus-visual 
  10996.                (run-hooks 'gnus-visual-mark-article-hook))
  10997.           ;; Set the global newsgroup variables here.
  10998.           ;; Suggested by Jim Sisolak
  10999.           ;; <sisolak@trans4.neep.wisc.edu>.
  11000.           (gnus-set-global-variables)
  11001.           (setq gnus-have-all-headers 
  11002.             (or all-headers gnus-show-all-headers))
  11003.           (and gnus-use-cache 
  11004.                (vectorp (gnus-get-header-by-number article))
  11005.                (gnus-cache-possibly-enter-article
  11006.             group article
  11007.             (gnus-get-header-by-number article)
  11008.             (memq article gnus-newsgroup-marked)
  11009.             (memq article gnus-newsgroup-dormant)
  11010.             (memq article gnus-newsgroup-unreads)))))
  11011.         ;; Hooks for getting information from the article.
  11012.         ;; This hook must be called before being narrowed.
  11013.         (let (buffer-read-only)
  11014.           (run-hooks 'internal-hook)
  11015.           (run-hooks 'gnus-article-prepare-hook)
  11016.           ;; Decode MIME message.
  11017.           (if (and gnus-show-mime
  11018.                (or (not gnus-strict-mime)
  11019.                (gnus-fetch-field "Mime-Version")))
  11020.           (funcall gnus-show-mime-method))
  11021.           ;; Perform the article display hooks.
  11022.           (run-hooks 'gnus-article-display-hook))
  11023.         ;; Do page break.
  11024.         (goto-char (point-min))
  11025.         (and gnus-break-pages (gnus-narrow-to-page))
  11026.         (gnus-set-mode-line 'article)
  11027.         (gnus-configure-windows 'article)
  11028.         (goto-char (point-min))
  11029.         t))))))
  11030.  
  11031. (defun gnus-article-show-all-headers ()
  11032.   "Show all article headers in article mode buffer."
  11033.   (save-excursion 
  11034.     (gnus-article-setup-buffer)
  11035.     (set-buffer gnus-article-buffer)
  11036.     (let ((buffer-read-only nil))
  11037.       (remove-text-properties (point-min) (point-max) 
  11038.                   gnus-hidden-properties))))
  11039.  
  11040. (defun gnus-article-hide-headers-if-wanted ()
  11041.   "Hide unwanted headers if `gnus-have-all-headers' is nil.
  11042. Provided for backwards compatibility."
  11043.   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
  11044.       (gnus-article-hide-headers)))
  11045.  
  11046. (defun gnus-article-hide-headers (&optional delete)
  11047.   "Hide unwanted headers and possibly sort them as well."
  11048.   (interactive "P")
  11049.   (save-excursion
  11050.     (set-buffer gnus-article-buffer)
  11051.     (save-restriction
  11052.       (let ((sorted gnus-sorted-header-list)
  11053.         (buffer-read-only nil)
  11054.         want-list beg want-l)
  11055.     ;; First we narrow to just the headers.
  11056.     (widen)
  11057.     (goto-char (point-min))
  11058.     ;; Hide any "From " lines at the beginning of (mail) articles. 
  11059.     (while (looking-at "From ")
  11060.       (forward-line 1))
  11061.     (or (bobp) 
  11062.         (add-text-properties (point-min) (point) gnus-hidden-properties))
  11063.     ;; Then treat the rest of the header lines.
  11064.     (narrow-to-region 
  11065.      (point) 
  11066.      (progn (search-forward "\n\n" nil t) (forward-line -1) (point)))
  11067.     ;; Then we use the two regular expressions
  11068.     ;; `gnus-ignored-headers' and `gnus-visible-headers' to
  11069.     ;; select which header lines is to remain visible in the
  11070.     ;; article buffer.
  11071.     (goto-char (point-min))
  11072.     (while (re-search-forward "^[^ \t]*:" nil t)
  11073.       (beginning-of-line)
  11074.       ;; We add the headers we want to keep to a list and delete
  11075.       ;; them from the buffer.
  11076.       (if (or (and (stringp gnus-visible-headers)
  11077.                (looking-at gnus-visible-headers))
  11078.           (and (not (stringp gnus-visible-headers))
  11079.                (stringp gnus-ignored-headers)
  11080.                (not (looking-at gnus-ignored-headers))))
  11081.           (progn
  11082.         (setq beg (point))
  11083.         (forward-line 1)
  11084.         ;; Be sure to get multi-line headers...
  11085.         (re-search-forward "^[^ \t]*:" nil t)
  11086.         (beginning-of-line)
  11087.         (setq want-list 
  11088.               (cons (buffer-substring beg (point)) want-list))
  11089.         (delete-region beg (point))
  11090.         (goto-char beg))
  11091.         (forward-line 1)))
  11092.     ;; Next we perform the sorting by looking at
  11093.     ;; `gnus-sorted-header-list'. 
  11094.     (goto-char (point-min))
  11095.     (while (and sorted want-list)
  11096.       (setq want-l want-list)
  11097.       (while (and want-l
  11098.               (not (string-match (car sorted) (car want-l))))
  11099.         (setq want-l (cdr want-l)))
  11100.       (if want-l 
  11101.           (progn
  11102.         (insert (car want-l))
  11103.         (setq want-list (delq (car want-l) want-list))))
  11104.       (setq sorted (cdr sorted)))
  11105.     ;; Any headers that were not matched by the sorted list we
  11106.     ;; just tack on the end of the visible header list.
  11107.     (while want-list
  11108.       (insert (car want-list))
  11109.       (setq want-list (cdr want-list)))
  11110.     ;; And finally we make the unwanted headers invisible.
  11111.     (if delete
  11112.         (delete-region (point) (point-max))
  11113.       ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
  11114.       (add-text-properties (point) (point-max) gnus-hidden-properties))))))
  11115.  
  11116. ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
  11117. (defun gnus-article-treat-overstrike ()
  11118.   "Translate overstrikes into bold text."
  11119.   (interactive)
  11120.   (save-excursion
  11121.     (set-buffer gnus-article-buffer)
  11122.     (let ((buffer-read-only nil))
  11123.       (while (search-forward "\b" nil t)
  11124.     (let ((next (following-char))
  11125.           (previous (char-after (- (point) 2))))
  11126.       (cond ((eq next previous)
  11127.          (put-text-property (- (point) 2) (point)
  11128.                     'invisible t)
  11129.          (put-text-property (point) (1+ (point))
  11130.                     'face 'bold))
  11131.         ((eq next ?_)
  11132.          (put-text-property (1- (point)) (1+ (point))
  11133.                     'invisible t)
  11134.          (put-text-property (1- (point)) (point)
  11135.                     'face 'underline))
  11136.         ((eq previous ?_)
  11137.          (put-text-property (- (point) 2) (point)
  11138.                     'invisible t)
  11139.          (put-text-property (point) (1+ (point))
  11140.                     'face 'underline))))))))
  11141.  
  11142. (defun gnus-article-word-wrap ()
  11143.   "Format too long lines."
  11144.   (interactive)
  11145.   (save-excursion
  11146.     (set-buffer gnus-article-buffer)
  11147.     (let ((buffer-read-only nil))
  11148.       (goto-char (point-min))
  11149.       (search-forward "\n\n" nil t)
  11150.       (end-of-line 1)
  11151.       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
  11152.         (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
  11153.         (adaptive-fill-mode t))
  11154.     (while (not (eobp))
  11155.       (and (>= (current-column) (min fill-column (window-width)))
  11156.            (/= (preceding-char) ?:)
  11157.            (fill-paragraph nil))
  11158.       (end-of-line 2))))))
  11159.  
  11160. (defun gnus-article-remove-cr ()
  11161.   "Remove carriage returns from an article."
  11162.   (interactive)
  11163.   (save-excursion
  11164.     (set-buffer gnus-article-buffer)
  11165.     (let ((buffer-read-only nil))
  11166.       (goto-char (point-min))
  11167.       (while (search-forward "\r" nil t)
  11168.     (replace-match "" t t)))))
  11169.  
  11170. (defun gnus-article-display-x-face (&optional force)
  11171.   "Look for an X-Face header and display it if present."
  11172.   (interactive (list 'force))
  11173.   (save-excursion
  11174.     (set-buffer gnus-article-buffer)
  11175.     (let ((inhibit-point-motion-hooks t)
  11176.       (case-fold-search nil)
  11177.       from)
  11178.       (save-restriction
  11179.     (goto-char (point-min))
  11180.     (search-forward "\n\n")
  11181.     (narrow-to-region (point-min) (point))
  11182.     (goto-char (point-min))
  11183.     (setq from (mail-fetch-field "from"))
  11184.     (if (not (and gnus-article-x-face-command
  11185.               (or force
  11186.               (not gnus-article-x-face-too-ugly)
  11187.               (and gnus-article-x-face-too-ugly from
  11188.                    (not (string-match gnus-article-x-face-too-ugly
  11189.                           from))))
  11190.               (progn
  11191.             (goto-char (point-min))
  11192.             (re-search-forward "^X-Face: " nil t))))
  11193.         nil
  11194.       (let ((beg (point))
  11195.         (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
  11196.         (if (symbolp gnus-article-x-face-command)
  11197.         (and (or (fboundp gnus-article-x-face-command)
  11198.              (error "%s is not a function"
  11199.                 gnus-article-x-face-command))
  11200.              (funcall gnus-article-x-face-command beg end))
  11201.           (call-process-region beg end "sh" nil 0 nil
  11202.                    "-c" gnus-article-x-face-command))))))))
  11203.  
  11204. (defun gnus-article-de-quoted-unreadable (&optional force)
  11205.   "Do a naive translation of a quoted-printable-encoded article.
  11206. This is in no way, shape or form meant as a replacement for real MIME
  11207. processing, but is simply a stop-gap measure until MIME support is
  11208. written.
  11209. If FORCE, decode the article whether it is marked as quoted-printable
  11210. or not." 
  11211.   (interactive (list 'force))
  11212.   (save-excursion
  11213.     (set-buffer gnus-article-buffer)
  11214.     (let ((case-fold-search t)
  11215.       (buffer-read-only nil)
  11216.       (type (gnus-fetch-field "content-transfer-encoding")))
  11217.       (if (or force (and type (string-match "quoted-printable" type)))
  11218.       (progn
  11219.         (goto-char (point-min))
  11220.         (search-forward "\n\n" nil 'move)
  11221.         (gnus-mime-decode-quoted-printable (point) (point-max)))))))
  11222.  
  11223. (defun gnus-mime-decode-quoted-printable (from to)
  11224.   ;; Decode quoted-printable from region between FROM and TO.
  11225.   (save-excursion
  11226.     (goto-char from)
  11227.     (while (search-forward "=" to t)
  11228.       (cond ((eq (following-char) ?\n)
  11229.          (delete-char -1)
  11230.          (delete-char 1))
  11231.         ((looking-at "[0-9A-F][0-9A-F]")
  11232.          (delete-char -1)
  11233.          (insert (hexl-hex-string-to-integer
  11234.               (buffer-substring (point) (+ 2 (point)))))
  11235.          (delete-char 2))
  11236.         ((looking-at "=")
  11237.          (delete-char 1))
  11238.         ((gnus-message 3 "Malformed MIME quoted-printable message"))))))
  11239.  
  11240. (defvar gnus-article-time-units
  11241.   (list (cons 'year (* 365.25 24 60 60))
  11242.     (cons 'week (* 7 24 60 60))
  11243.     (cons 'day (* 24 60 60))
  11244.     (cons 'hour (* 60 60))
  11245.     (cons 'minute 60)
  11246.     (cons 'second 1)))
  11247.  
  11248. (defun gnus-article-date-ut (&optional type)
  11249.   "Convert DATE date to universal time in the current article.
  11250. If TYPE is `local', convert to local time; if it is `lapsed', output
  11251. how much time has lapsed since DATE."
  11252.   (interactive (list 'ut))
  11253.   (let ((date (mail-header-date (or gnus-current-headers 
  11254.                     (gnus-get-header-by-number
  11255.                      (gnus-summary-article-number))"")))
  11256.     (date-regexp "^Date: \\|^X-Sent: "))
  11257.     (if (or (not date)
  11258.         (string= date ""))
  11259.     ()
  11260.       (save-excursion
  11261.     (set-buffer gnus-article-buffer)
  11262.     (let ((buffer-read-only nil))
  11263.       (goto-char (point-min))
  11264.       (if (and (re-search-forward date-regexp nil t)
  11265.            (progn 
  11266.              (beginning-of-line)
  11267.              (looking-at date-regexp)))
  11268.           (delete-region (gnus-point-at-bol)
  11269.                  (progn (end-of-line) (1+ (point))))
  11270.         (goto-char (point-min))
  11271.         (goto-char (- (search-forward "\n\n") 2)))
  11272.       (insert
  11273.        (cond 
  11274.         ((eq type 'local)
  11275.          (concat "Date: " (condition-case ()
  11276.                   (timezone-make-date-arpa-standard date)
  11277.                 (error date))
  11278.              "\n"))
  11279.         ((eq type 'ut)
  11280.          (concat "Date: "
  11281.              (condition-case ()
  11282.              (timezone-make-date-arpa-standard date nil "UT")
  11283.                (error date))
  11284.              "\n"))
  11285.         ((eq type 'lapsed)
  11286.          ;; If the date is seriously mangled, the timezone
  11287.          ;; functions are liable to bug out, so we condition-case
  11288.          ;; the entire thing.  
  11289.          (let* ((real-sec (condition-case ()
  11290.                   (- (gnus-seconds-since-epoch 
  11291.                       (timezone-make-date-arpa-standard
  11292.                        (current-time-string) 
  11293.                        (current-time-zone) "UT"))
  11294.                      (gnus-seconds-since-epoch 
  11295.                       (timezone-make-date-arpa-standard 
  11296.                        date nil "UT")))
  11297.                 (error 0)))
  11298.             (sec (abs real-sec))
  11299.             num prev)
  11300.            (if (zerop sec)
  11301.            "X-Sent: Now\n"
  11302.          (concat
  11303.           "X-Sent: "
  11304.           (mapconcat 
  11305.            (lambda (unit)
  11306.              (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
  11307.              ""
  11308.                (setq sec (- sec (* num (cdr unit))))
  11309.                (prog1
  11310.                (concat (if prev ", " "") (int-to-string 
  11311.                               (floor num))
  11312.                    " " (symbol-name (car unit))
  11313.                    (if (> num 1) "s" ""))
  11314.              (setq prev t))))
  11315.            gnus-article-time-units "")
  11316.           (if (> real-sec 0)
  11317.               " ago\n"
  11318.             " in the future\n")))))
  11319.         (t
  11320.          (error "Unknown conversion type: %s" type)))))))))
  11321.  
  11322. (defun gnus-article-date-local ()
  11323.   "Convert the current article date to the local timezone."
  11324.   (interactive)
  11325.   (gnus-article-date-ut 'local))
  11326.  
  11327. (defun gnus-article-date-lapsed ()
  11328.   "Convert the current article date to time lapsed since it was sent."
  11329.   (interactive)
  11330.   (gnus-article-date-ut 'lapsed))
  11331.  
  11332. (defun gnus-article-maybe-highlight ()
  11333.   "Do some article highlighting if `gnus-visual' is non-nil."
  11334.   (if gnus-visual (gnus-article-highlight-some)))
  11335.  
  11336. ;; Article savers.
  11337.  
  11338. (defun gnus-output-to-rmail (file-name)
  11339.   "Append the current article to an Rmail file named FILE-NAME."
  11340.   (require 'rmail)
  11341.   ;; Most of these codes are borrowed from rmailout.el.
  11342.   (setq file-name (expand-file-name file-name))
  11343.   (setq rmail-default-rmail-file file-name)
  11344.   (let ((artbuf (current-buffer))
  11345.     (tmpbuf (get-buffer-create " *Gnus-output*")))
  11346.     (save-excursion
  11347.       (or (get-file-buffer file-name)
  11348.       (file-exists-p file-name)
  11349.       (if (gnus-yes-or-no-p
  11350.            (concat "\"" file-name "\" does not exist, create it? "))
  11351.           (let ((file-buffer (create-file-buffer file-name)))
  11352.         (save-excursion
  11353.           (set-buffer file-buffer)
  11354.           (rmail-insert-rmail-file-header)
  11355.           (let ((require-final-newline nil))
  11356.             (write-region (point-min) (point-max) file-name t 1)))
  11357.         (kill-buffer file-buffer))
  11358.         (error "Output file does not exist")))
  11359.       (set-buffer tmpbuf)
  11360.       (buffer-disable-undo (current-buffer))
  11361.       (erase-buffer)
  11362.       (insert-buffer-substring artbuf)
  11363.       (gnus-convert-article-to-rmail)
  11364.       ;; Decide whether to append to a file or to an Emacs buffer.
  11365.       (let ((outbuf (get-file-buffer file-name)))
  11366.     (if (not outbuf)
  11367.         (append-to-file (point-min) (point-max) file-name)
  11368.       ;; File has been visited, in buffer OUTBUF.
  11369.       (set-buffer outbuf)
  11370.       (let ((buffer-read-only nil)
  11371.         (msg (and (boundp 'rmail-current-message)
  11372.               (symbol-value 'rmail-current-message))))
  11373.         ;; If MSG is non-nil, buffer is in RMAIL mode.
  11374.         (if msg
  11375.         (progn (widen)
  11376.                (narrow-to-region (point-max) (point-max))))
  11377.         (insert-buffer-substring tmpbuf)
  11378.         (if msg
  11379.         (progn
  11380.           (goto-char (point-min))
  11381.           (widen)
  11382.           (search-backward "\^_")
  11383.           (narrow-to-region (point) (point-max))
  11384.           (goto-char (1+ (point-min)))
  11385.           (rmail-count-new-messages t)
  11386.           (rmail-show-message msg)))))))
  11387.     (kill-buffer tmpbuf)))
  11388.  
  11389. (defun gnus-output-to-file (file-name)
  11390.   "Append the current article to a file named FILE-NAME."
  11391.   (setq file-name (expand-file-name file-name))
  11392.   (let ((artbuf (current-buffer))
  11393.     (tmpbuf (get-buffer-create " *Gnus-output*")))
  11394.     (save-excursion
  11395.       (set-buffer tmpbuf)
  11396.       (buffer-disable-undo (current-buffer))
  11397.       (erase-buffer)
  11398.       (insert-buffer-substring artbuf)
  11399.       ;; Append newline at end of the buffer as separator, and then
  11400.       ;; save it to file.
  11401.       (goto-char (point-max))
  11402.       (insert "\n")
  11403.       (append-to-file (point-min) (point-max) file-name))
  11404.     (kill-buffer tmpbuf)))
  11405.  
  11406. (defun gnus-convert-article-to-rmail ()
  11407.   "Convert article in current buffer to Rmail message format."
  11408.   (let ((buffer-read-only nil))
  11409.     ;; Convert article directly into Babyl format.
  11410.     ;; Suggested by Rob Austein <sra@lcs.mit.edu>
  11411.     (goto-char (point-min))
  11412.     (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
  11413.     (while (search-forward "\n\^_" nil t) ;single char
  11414.       (replace-match "\n^_" t t))    ;2 chars: "^" and "_"
  11415.     (goto-char (point-max))
  11416.     (insert "\^_")))
  11417.  
  11418. (defun gnus-narrow-to-page (&optional arg)
  11419.   "Make text outside current page invisible except for page delimiter.
  11420. A numeric arg specifies to move forward or backward by that many pages,
  11421. thus showing a page other than the one point was originally in."
  11422.   (interactive "P")
  11423.   (setq arg (if arg (prefix-numeric-value arg) 0))
  11424.   (save-excursion
  11425.     (forward-page -1)            ;Beginning of current page.
  11426.     (widen)
  11427.     (if (> arg 0)
  11428.     (forward-page arg)
  11429.       (if (< arg 0)
  11430.       (forward-page (1- arg))))
  11431.     ;; Find the end of the page.
  11432.     (forward-page)
  11433.     ;; If we stopped due to end of buffer, stay there.
  11434.     ;; If we stopped after a page delimiter, put end of restriction
  11435.     ;; at the beginning of that line.
  11436.     ;; These are commented out.
  11437.     ;;    (if (save-excursion (beginning-of-line)
  11438.     ;;            (looking-at page-delimiter))
  11439.     ;;    (beginning-of-line))
  11440.     (narrow-to-region (point)
  11441.               (progn
  11442.             ;; Find the top of the page.
  11443.             (forward-page -1)
  11444.             ;; If we found beginning of buffer, stay there.
  11445.             ;; If extra text follows page delimiter on same line,
  11446.             ;; include it.
  11447.             ;; Otherwise, show text starting with following line.
  11448.             (if (and (eolp) (not (bobp)))
  11449.                 (forward-line 1))
  11450.             (point)))))
  11451.  
  11452. (defun gnus-gmt-to-local ()
  11453.   "Rewrite Date header described in GMT to local in current buffer.
  11454. Intended to be used with gnus-article-prepare-hook."
  11455.   (save-excursion
  11456.     (save-restriction
  11457.       (widen)
  11458.       (goto-char (point-min))
  11459.       (narrow-to-region (point-min)
  11460.             (progn (search-forward "\n\n" nil 'move) (point)))
  11461.       (goto-char (point-min))
  11462.       (if (re-search-forward "^Date:[ \t]\\(.*\\)$" nil t)
  11463.       (let ((buffer-read-only nil)
  11464.         (date (buffer-substring-no-properties
  11465.                (match-beginning 1) (match-end 1))))
  11466.         (delete-region (match-beginning 1) (match-end 1))
  11467.         (insert
  11468.          (timezone-make-date-arpa-standard 
  11469.           date nil (current-time-zone))))))))
  11470.  
  11471.  
  11472. ;; Article mode commands
  11473.  
  11474. (defun gnus-article-next-page (&optional lines)
  11475.   "Show next page of current article.
  11476. If end of article, return non-nil. Otherwise return nil.
  11477. Argument LINES specifies lines to be scrolled up."
  11478.   (interactive "P")
  11479.   (move-to-window-line -1)
  11480.   ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
  11481.   (if (save-excursion
  11482.     (end-of-line)
  11483.     (and (pos-visible-in-window-p)    ;Not continuation line.
  11484.          (eobp)))
  11485.       ;; Nothing in this page.
  11486.       (if (or (not gnus-break-pages)
  11487.           (save-excursion
  11488.         (save-restriction
  11489.           (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
  11490.       t                ;Nothing more.
  11491.     (gnus-narrow-to-page 1)        ;Go to next page.
  11492.     nil)
  11493.     ;; More in this page.
  11494.     (condition-case ()
  11495.     (scroll-up lines)
  11496.       (end-of-buffer
  11497.        ;; Long lines may cause an end-of-buffer error.
  11498.        (goto-char (point-max))))
  11499.     nil))
  11500.  
  11501. (defun gnus-article-prev-page (&optional lines)
  11502.   "Show previous page of current article.
  11503. Argument LINES specifies lines to be scrolled down."
  11504.   (interactive "P")
  11505.   (move-to-window-line 0)
  11506.   (if (and gnus-break-pages
  11507.        (bobp)
  11508.        (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
  11509.       (progn
  11510.     (gnus-narrow-to-page -1)    ;Go to previous page.
  11511.     (goto-char (point-max))
  11512.     (recenter -1))
  11513.     (scroll-down lines)))
  11514.  
  11515. (defun gnus-article-refer-article ()
  11516.   "Read article specified by message-id around point."
  11517.   (interactive)
  11518.   (search-forward ">" nil t)        ;Move point to end of "<....>".
  11519.   (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
  11520.       (let ((message-id
  11521.          (buffer-substring (match-beginning 1) (match-end 1))))
  11522.     (set-buffer gnus-summary-buffer)
  11523.     (gnus-summary-refer-article message-id))
  11524.     (error "No references around point")))
  11525.  
  11526. (defun gnus-article-show-summary ()
  11527.   "Reconfigure windows to show summary buffer."
  11528.   (interactive)
  11529.   (gnus-configure-windows 'article)
  11530.   (gnus-summary-goto-subject gnus-current-article))
  11531.  
  11532. (defun gnus-article-describe-briefly ()
  11533.   "Describe article mode commands briefly."
  11534.   (interactive)
  11535.   (gnus-message 6
  11536.         (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-next-page]:Next page  \\[gnus-article-prev-page]:Prev page  \\[gnus-article-show-summary]:Show summary  \\[gnus-info-find-node]:Run Info  \\[gnus-article-describe-briefly]:This help")))
  11537.  
  11538. (defun gnus-article-summary-command ()
  11539.   "Execute the last keystroke in the summary buffer."
  11540.   (interactive)
  11541.   (let ((obuf (current-buffer))
  11542.     (owin (current-window-configuration))
  11543.     func)
  11544.     (switch-to-buffer gnus-summary-buffer 'norecord)
  11545.     (setq func (lookup-key (current-local-map) (this-command-keys)))
  11546.     (call-interactively func)
  11547.     (set-buffer obuf)
  11548.     (set-window-configuration owin)
  11549.     (set-window-point (get-buffer-window (current-buffer)) (point))))
  11550.  
  11551. (defun gnus-article-summary-command-nosave ()
  11552.   "Execute the last keystroke in the summary buffer."
  11553.   (interactive)
  11554.   (let (func)
  11555.     (pop-to-buffer gnus-summary-buffer 'norecord)
  11556.     (setq func (lookup-key (current-local-map) (this-command-keys)))
  11557.     (call-interactively func)))
  11558.  
  11559.  
  11560. ;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti)
  11561.  
  11562. ;;;###autoload
  11563. (defalias 'gnus-batch-kill 'gnus-batch-score)
  11564. ;;;###autoload
  11565. (defun gnus-batch-score ()
  11566.   "Run batched scoring.
  11567. Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
  11568. Newsgroups is a list of strings in Bnews format.  If you want to score
  11569. the comp hierarchy, you'd say \"comp.all\". If you would not like to
  11570. score the alt hierarchy, you'd say \"!alt.all\"."
  11571.   (interactive)
  11572.   (let* ((yes-and-no
  11573.       (gnus-newsrc-parse-options
  11574.        (apply (function concat)
  11575.           (mapcar (lambda (g) (concat g " "))
  11576.               command-line-args-left))))
  11577.      (gnus-expert-user t)
  11578.      (nnmail-spool-file nil)
  11579.      (gnus-use-dribble-file nil)
  11580.      (yes (car yes-and-no))
  11581.      (no (cdr yes-and-no))
  11582.      group newsrc entry
  11583.      ;; Disable verbose message.
  11584.      gnus-novice-user gnus-large-newsgroup)
  11585.     ;; Eat all arguments.
  11586.     (setq command-line-args-left nil)
  11587.     ;; Start Gnus.
  11588.     (gnus)
  11589.     ;; Apply kills to specified newsgroups in command line arguments.
  11590.     (setq newsrc (cdr gnus-newsrc-alist))
  11591.     (while newsrc
  11592.       (setq group (car (car newsrc)))
  11593.       (setq entry (gnus-gethash group gnus-newsrc-hashtb))
  11594.       (if (and (<= (nth 1 (car newsrc)) gnus-level-subscribed)
  11595.            (and (car entry)
  11596.             (or (eq (car entry) t)
  11597.             (not (zerop (car entry)))))
  11598.            (if yes (string-match yes group) t)
  11599.            (or (null no) (not (string-match no group))))
  11600.       (progn
  11601.         (gnus-summary-read-group group nil t)
  11602.         (and (eq (current-buffer) (get-buffer gnus-summary-buffer))
  11603.          (gnus-summary-exit))))
  11604.       (setq newsrc (cdr newsrc)))
  11605.     ;; Exit Emacs.
  11606.     (switch-to-buffer gnus-group-buffer)
  11607.     (gnus-group-save-newsrc)))
  11608.  
  11609. (defun gnus-apply-kill-file ()
  11610.   "Apply a kill file to the current newsgroup.
  11611. Returns the number of articles marked as read."
  11612.   (if (or (file-exists-p (gnus-newsgroup-kill-file nil))
  11613.       (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
  11614.       (gnus-apply-kill-file-internal)
  11615.     0))
  11616.  
  11617. (defun gnus-kill-save-kill-buffer ()
  11618.   (save-excursion
  11619.     (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)))
  11620.       (if (get-file-buffer file)
  11621.       (progn
  11622.         (set-buffer (get-file-buffer file))
  11623.         (and (buffer-modified-p) (save-buffer))
  11624.         (kill-buffer (current-buffer)))))))
  11625.  
  11626. (defvar gnus-kill-file-name "KILL"
  11627.   "Suffix of the kill files.")
  11628.  
  11629. (defun gnus-newsgroup-kill-file (newsgroup)
  11630.   "Return the name of a kill file name for NEWSGROUP.
  11631. If NEWSGROUP is nil, return the global kill file name instead."
  11632.   (cond ((or (null newsgroup)
  11633.          (string-equal newsgroup ""))
  11634.      ;; The global KILL file is placed at top of the directory.
  11635.      (expand-file-name gnus-kill-file-name
  11636.                (or gnus-kill-files-directory "~/News")))
  11637.     ((gnus-use-long-file-name 'not-kill)
  11638.      ;; Append ".KILL" to newsgroup name.
  11639.      (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
  11640.                    "." gnus-kill-file-name)
  11641.                (or gnus-kill-files-directory "~/News")))
  11642.     (t
  11643.      ;; Place "KILL" under the hierarchical directory.
  11644.      (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
  11645.                    "/" gnus-kill-file-name)
  11646.                (or gnus-kill-files-directory "~/News")))))
  11647.  
  11648.  
  11649. ;;;
  11650. ;;; Dribble file
  11651. ;;;
  11652.  
  11653. (defvar gnus-dribble-ignore nil)
  11654. (defvar gnus-dribble-eval-file nil)
  11655.  
  11656. (defun gnus-dribble-file-name ()
  11657.   (concat gnus-current-startup-file "-dribble"))
  11658.  
  11659. (defun gnus-dribble-enter (string)
  11660.   (if (and (not gnus-dribble-ignore)
  11661.        gnus-dribble-buffer
  11662.        (buffer-name gnus-dribble-buffer))
  11663.       (let ((obuf (current-buffer)))
  11664.     (set-buffer gnus-dribble-buffer)
  11665.     (insert string "\n")
  11666.     (set-window-point (get-buffer-window (current-buffer)) (point-max))
  11667.     (set-buffer obuf))))
  11668.  
  11669. (defun gnus-dribble-read-file ()
  11670.   (let ((dribble-file (gnus-dribble-file-name)))
  11671.     (save-excursion 
  11672.       (set-buffer (setq gnus-dribble-buffer 
  11673.             (get-buffer-create 
  11674.              (file-name-nondirectory dribble-file))))
  11675.       (gnus-add-current-to-buffer-list)
  11676.       (erase-buffer)
  11677.       (set-visited-file-name dribble-file)
  11678.       (buffer-disable-undo (current-buffer))
  11679.       (bury-buffer (current-buffer))
  11680.       (set-buffer-modified-p nil)
  11681.       (let ((auto (make-auto-save-file-name))
  11682.         (gnus-dribble-ignore t))
  11683.     (if (or (file-exists-p auto) (file-exists-p dribble-file))
  11684.         (progn
  11685.           (if (file-newer-than-file-p auto dribble-file)
  11686.           (setq dribble-file auto))
  11687.           (insert-file-contents dribble-file)
  11688.           (if (not (zerop (buffer-size)))
  11689.           (set-buffer-modified-p t))
  11690.           (if (gnus-y-or-n-p 
  11691.            "Auto-save file exists. Do you want to read it? ")
  11692.           (setq gnus-dribble-eval-file t))))))))
  11693.  
  11694. (defun gnus-dribble-eval-file ()
  11695.   (if (not gnus-dribble-eval-file)
  11696.       ()
  11697.     (setq gnus-dribble-eval-file nil)
  11698.     (save-excursion
  11699.       (let ((gnus-dribble-ignore t))
  11700.     (set-buffer gnus-dribble-buffer)
  11701.     (eval-buffer (current-buffer))))))
  11702.  
  11703. (defun gnus-dribble-delete-file ()
  11704.   (if (file-exists-p (gnus-dribble-file-name))
  11705.       (delete-file (gnus-dribble-file-name)))
  11706.   (if gnus-dribble-buffer
  11707.       (save-excursion
  11708.     (set-buffer gnus-dribble-buffer)
  11709.     (let ((auto (make-auto-save-file-name)))
  11710.       (if (file-exists-p auto)
  11711.           (delete-file auto))
  11712.       (erase-buffer)
  11713.       (set-buffer-modified-p nil)))))
  11714.  
  11715. (defun gnus-dribble-save ()
  11716.   (if (and gnus-dribble-buffer
  11717.        (buffer-name gnus-dribble-buffer))
  11718.       (save-excursion
  11719.     (set-buffer gnus-dribble-buffer)
  11720.     (save-buffer))))
  11721.  
  11722. (defun gnus-dribble-clear ()
  11723.   (save-excursion
  11724.     (if (gnus-buffer-exists-p gnus-dribble-buffer)
  11725.     (progn
  11726.       (set-buffer gnus-dribble-buffer)
  11727.       (erase-buffer)
  11728.       (set-buffer-modified-p nil)
  11729.       (setq buffer-saved-size (buffer-size))))))
  11730.  
  11731. ;;;
  11732. ;;; Server Communication
  11733. ;;;
  11734.  
  11735. (defun gnus-start-news-server (&optional confirm)
  11736.   "Open a method for getting news.
  11737. If CONFIRM is non-nil, the user will be asked for an NNTP server."
  11738.   (let (how)
  11739.     (if gnus-current-select-method
  11740.     ;; Stream is already opened.
  11741.     nil
  11742.       ;; Open NNTP server.
  11743.       (if (null gnus-nntp-service) (setq gnus-nntp-server nil))
  11744.       (if confirm
  11745.       (progn
  11746.         ;; Read server name with completion.
  11747.         (setq gnus-nntp-server
  11748.           (completing-read "NNTP server: "
  11749.                    (mapcar (lambda (server) (list server))
  11750.                        (cons (list gnus-nntp-server)
  11751.                          gnus-secondary-servers))
  11752.                    nil nil gnus-nntp-server))))
  11753.  
  11754.       (if (and gnus-nntp-server 
  11755.            (stringp gnus-nntp-server)
  11756.            (not (string= gnus-nntp-server "")))
  11757.       (setq gnus-select-method
  11758.         (cond ((or (string= gnus-nntp-server "")
  11759.                (string= gnus-nntp-server "::"))
  11760.                (list 'nnspool (system-name)))
  11761.               ((string-match "^:" gnus-nntp-server)
  11762.                (list 'nnmh gnus-nntp-server 
  11763.                  (list 'nnmh-directory 
  11764.                    (file-name-as-directory
  11765.                     (expand-file-name
  11766.                      (concat "~/" (substring
  11767.                            gnus-nntp-server 1)))))
  11768.                  (list 'nnmh-get-new-mail nil)))
  11769.               (t
  11770.                (list 'nntp gnus-nntp-server)))))
  11771.  
  11772.       (setq how (car gnus-select-method))
  11773.       (cond ((eq how 'nnspool)
  11774.          (require 'nnspool)
  11775.          (gnus-message 5 "Looking up local news spool..."))
  11776.         ((eq how 'nnmh)
  11777.          (require 'nnmh)
  11778.          (gnus-message 5 "Looking up mh spool..."))
  11779.         (t
  11780.          (require 'nntp)))
  11781.       (setq gnus-current-select-method gnus-select-method)
  11782.       (run-hooks 'gnus-open-server-hook)
  11783.       (or 
  11784.        ;; gnus-open-server-hook might have opened it
  11785.        (gnus-server-opened gnus-select-method)  
  11786.        (gnus-open-server gnus-select-method)
  11787.        (gnus-y-or-n-p
  11788.     (format
  11789.      "%s open error: '%s'. Continue? "
  11790.      (nth 1 gnus-select-method)
  11791.      (gnus-status-message gnus-select-method)))
  11792.        (progn
  11793.      (gnus-message 1 "Couldn't open server on %s" 
  11794.                (nth 1 gnus-select-method))
  11795.      (ding)
  11796.      nil)))))
  11797.  
  11798. (defun gnus-check-server (&optional method)
  11799.   "If the news server is down, start it up again."
  11800.   (let ((method (if method method gnus-select-method)))
  11801.     (and (stringp method)
  11802.      (setq method (gnus-server-to-method method)))
  11803.     (if (gnus-server-opened method)
  11804.     ;; Stream is already opened.
  11805.     t
  11806.       ;; Open server.
  11807.       (gnus-message 5 "Opening server %s on %s..." (car method) (nth 1 method))
  11808.       (run-hooks 'gnus-open-server-hook)
  11809.       (prog1
  11810.       (gnus-open-server method)
  11811.     (message "")))))
  11812.  
  11813. (defun gnus-nntp-message (&optional message)
  11814.   "Check the status of the NNTP server.
  11815. If the status of the server is clear and MESSAGE is non-nil, MESSAGE
  11816. is returned insted of the status string."
  11817.   (let ((status (gnus-status-message (gnus-find-method-for-group 
  11818.                       gnus-newsgroup-name)))
  11819.     (message (or message "")))
  11820.     (if (and (stringp status) (> (length status) 0))
  11821.     status message)))
  11822.  
  11823. (defun gnus-get-function (method function)
  11824.   (and (stringp method)
  11825.        (setq method (gnus-server-to-method method)))
  11826.   (let ((func (intern (format "%s-%s" (car method) function))))
  11827.     (if (not (fboundp func)) 
  11828.     (progn
  11829.       (require (car method))
  11830.       (if (not (fboundp func)) 
  11831.           (error "No such function: %s" func))))
  11832.     func))
  11833.  
  11834. ;;; Interface functions to the backends.
  11835.  
  11836. (defun gnus-open-server (method)
  11837.   (funcall (gnus-get-function method 'open-server)
  11838.        (nth 1 method) (nthcdr 2 method)))
  11839.  
  11840. (defun gnus-close-server (method)
  11841.   (funcall (gnus-get-function method 'close-server) (nth 1 method)))
  11842.  
  11843. (defun gnus-request-list (method)
  11844.   (funcall (gnus-get-function method 'request-list) (nth 1 method)))
  11845.  
  11846. (defun gnus-request-list-newsgroups (method)
  11847.   (funcall (gnus-get-function method 'request-list-newsgroups) (nth 1 method)))
  11848.  
  11849. (defun gnus-request-newgroups (date method)
  11850.   (funcall (gnus-get-function method 'request-newgroups) 
  11851.        date (nth 1 method)))
  11852.  
  11853. (defun gnus-server-opened (method)
  11854.   (funcall (gnus-get-function method 'server-opened) (nth 1 method)))
  11855.  
  11856. (defun gnus-status-message (method)
  11857.   (let ((method (if (stringp method) (gnus-find-method-for-group method)
  11858.           method)))
  11859.     (funcall (gnus-get-function method 'status-message) (nth 1 method))))
  11860.  
  11861. (defun gnus-request-group (group &optional dont-check)
  11862.   (let ((method (gnus-find-method-for-group group)))
  11863.     (funcall (gnus-get-function method 'request-group) 
  11864.          (gnus-group-real-name group) (nth 1 method) dont-check)))
  11865.  
  11866. (defun gnus-request-asynchronous (group &optional articles)
  11867.   (let ((method (gnus-find-method-for-group group)))
  11868.     (funcall (gnus-get-function method 'request-asynchronous) 
  11869.          (gnus-group-real-name group) (nth 1 method) articles)))
  11870.  
  11871. (defun gnus-list-active-group (group)
  11872.   (let ((method (gnus-find-method-for-group group))
  11873.     (func 'list-active-group))
  11874.     (and (gnus-check-backend-function func group)
  11875.      (funcall (gnus-get-function method func) 
  11876.           (gnus-group-real-name group) (nth 1 method)))))
  11877.  
  11878. (defun gnus-request-group-description (group)
  11879.   (let ((method (gnus-find-method-for-group group))
  11880.     (func 'request-group-description))
  11881.     (and (gnus-check-backend-function func group)
  11882.      (funcall (gnus-get-function method func) 
  11883.           (gnus-group-real-name group) (nth 1 method)))))
  11884.  
  11885. (defun gnus-close-group (group)
  11886.   (let ((method (gnus-find-method-for-group group)))
  11887.     (funcall (gnus-get-function method 'close-group) 
  11888.          (gnus-group-real-name group) (nth 1 method))))
  11889.  
  11890. (defun gnus-retrieve-headers (articles group)
  11891.   (let ((method (gnus-find-method-for-group group)))
  11892.     (if (and gnus-use-cache (numberp (car articles)))
  11893.     (gnus-cache-retrieve-headers articles group)
  11894.       (funcall (gnus-get-function method 'retrieve-headers) 
  11895.            articles (gnus-group-real-name group) (nth 1 method)))))
  11896.  
  11897. (defun gnus-retrieve-groups (groups method)
  11898.   (funcall (gnus-get-function method 'retrieve-groups) groups (nth 1 method)))
  11899.  
  11900. (defun gnus-request-article (article group &optional buffer)
  11901.   (let ((method (gnus-find-method-for-group group)))
  11902.     (funcall (gnus-get-function method 'request-article) 
  11903.          article (gnus-group-real-name group) (nth 1 method) buffer)))
  11904.  
  11905. (defun gnus-request-head (article group)
  11906.   (let ((method (gnus-find-method-for-group group)))
  11907.     (funcall (gnus-get-function method 'request-head) 
  11908.          article (gnus-group-real-name group) (nth 1 method))))
  11909.  
  11910. (defun gnus-request-body (article group)
  11911.   (let ((method (gnus-find-method-for-group group)))
  11912.     (funcall (gnus-get-function method 'request-body) 
  11913.          article (gnus-group-real-name group) (nth 1 method))))
  11914.  
  11915. ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
  11916. (defun gnus-request-post-buffer (post group subject header artbuf
  11917.                       info follow-to respect-poster)
  11918.   (let* ((info (or info (and group (nth 2 (gnus-gethash 
  11919.                        group gnus-newsrc-hashtb)))))
  11920.      (method
  11921.       (if (and gnus-post-method
  11922.            ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
  11923.            (memq 'post (assoc
  11924.                 (format "%s" (car (gnus-find-method-for-group
  11925.                            gnus-newsgroup-name)))
  11926.                 gnus-valid-select-methods)))
  11927.           gnus-post-method
  11928.         (gnus-find-method-for-group gnus-newsgroup-name))))
  11929.     (or (gnus-check-server method)
  11930.     (error "Can't open server %s:%s" (car method) (nth 1 method)))
  11931.     (let ((mail-self-blind nil)
  11932.       (mail-archive-file-name nil))
  11933.       (funcall (gnus-get-function method 'request-post-buffer) 
  11934.            post group subject header artbuf info follow-to
  11935.            respect-poster))))
  11936.  
  11937. (defun gnus-request-post (method &optional force)
  11938.   (and (stringp method)
  11939.        (setq method (gnus-server-to-method method)))
  11940.   (and (not force) gnus-post-method
  11941.        (memq 'post (assoc (format "%s" (car method))
  11942.                gnus-valid-select-methods))
  11943.        (setq method gnus-post-method))
  11944.   (funcall (gnus-get-function method 'request-post) 
  11945.        (nth 1 method)))
  11946.  
  11947. (defun gnus-request-expire-articles (articles group &optional force)
  11948.   (let ((method (gnus-find-method-for-group group)))
  11949.     (funcall (gnus-get-function method 'request-expire-articles) 
  11950.          articles (gnus-group-real-name group) (nth 1 method)
  11951.          force)))
  11952.  
  11953. (defun gnus-request-move-article 
  11954.   (article group server accept-function &optional last)
  11955.   (let ((method (gnus-find-method-for-group group)))
  11956.     (funcall (gnus-get-function method 'request-move-article) 
  11957.          article (gnus-group-real-name group) 
  11958.          (nth 1 method) accept-function last)))
  11959.  
  11960. (defun gnus-request-accept-article (group &optional last)
  11961.   (goto-char (point-max))
  11962.   (or (bolp) (insert "\n"))
  11963.   (let ((func (if (symbolp group) group
  11964.         (car (gnus-find-method-for-group group)))))
  11965.     (funcall (intern (format "%s-request-accept-article" func))
  11966.          (if (stringp group) (gnus-group-real-name group) group)
  11967.          last)))
  11968.  
  11969. (defun gnus-request-replace-article (article group buffer)
  11970.   (let ((func (car (gnus-find-method-for-group group))))
  11971.     (funcall (intern (format "%s-request-replace-article" func))
  11972.          article (gnus-group-real-name group) buffer)))
  11973.  
  11974. (defun gnus-request-create-group (group)
  11975.   (let ((method (gnus-find-method-for-group group)))
  11976.     (funcall (gnus-get-function method 'request-create-group) 
  11977.          (gnus-group-real-name group) (nth 1 method))))
  11978.  
  11979. (defun gnus-member-of-valid (symbol group)
  11980.   (memq symbol (assoc
  11981.         (format "%s" (car (gnus-find-method-for-group group)))
  11982.         gnus-valid-select-methods)))
  11983.  
  11984. (defun gnus-secondary-method-p (method)
  11985.   (let ((methods gnus-secondary-select-methods)
  11986.     (gmethod (gnus-server-get-method nil method)))
  11987.     (while (and methods
  11988.         (not (equal (gnus-server-get-method nil (car methods)) 
  11989.                 gmethod)))
  11990.       (setq methods (cdr methods)))
  11991.     methods))
  11992.  
  11993. (defun gnus-find-method-for-group (group &optional info)
  11994.   (or gnus-override-method
  11995.       (and (not group)
  11996.        gnus-select-method)
  11997.       (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
  11998.         method)
  11999.     (if (or (not info)
  12000.         (not (setq method (nth 4 info))))
  12001.         (setq method gnus-select-method)
  12002.       (setq method
  12003.         (cond ((stringp method)
  12004.                (gnus-server-to-method method))
  12005.               ((stringp (car method))
  12006.                (gnus-server-extend-method group method))
  12007.               (t
  12008.                method))))
  12009.     (gnus-server-add-address method))))
  12010.  
  12011. (defun gnus-check-backend-function (func group)
  12012.   (let ((method (if (stringp group) (car (gnus-find-method-for-group group))
  12013.           group)))
  12014.     (fboundp (intern (format "%s-%s" method func)))))
  12015.  
  12016. (defun gnus-methods-using (method)
  12017.   (let ((valids gnus-valid-select-methods)
  12018.     outs)
  12019.     (while valids
  12020.       (if (memq method (car valids)) 
  12021.       (setq outs (cons (car valids) outs)))
  12022.       (setq valids (cdr valids)))
  12023.     outs))
  12024.  
  12025. ;;; 
  12026. ;;; Active & Newsrc File Handling
  12027. ;;;
  12028.  
  12029. ;; Newsrc related functions.
  12030. ;; Gnus internal format of gnus-newsrc-alist:
  12031. ;; (("alt.general" 3 (1 . 1))
  12032. ;;  ("alt.misc"    3 ((1 . 10) (12 . 15)))
  12033. ;;  ("alt.test"    7 (1 . 99) (45 57 93)) ...)
  12034. ;; The first item is the group name; the second is the subscription
  12035. ;; level; the third is either a range of a list of ranges of read
  12036. ;; articles, the optional fourth element is a list of marked articles,
  12037. ;; the optional fifth element is the select method.
  12038. ;;
  12039. ;; Gnus internal format of gnus-newsrc-hashtb:
  12040. ;; (95 ("alt.general" 3 (1 . 1)) ("alt.misc" 3 ((1 . 10) (12 . 15))) ...)
  12041. ;; This is the entry for "alt.misc". The first element is the number
  12042. ;; of unread articles in "alt.misc". The cdr of this entry is the
  12043. ;; element *before* "alt.misc" in gnus-newsrc-alist, which makes is
  12044. ;; trivial to remove or add new elements into gnus-newsrc-alist
  12045. ;; without scanning the entire list. So, to get the actual information
  12046. ;; of "alt.misc", you'd say something like 
  12047. ;; (nth 2 (gnus-gethash "alt.misc" gnus-newsrc-hashtb))
  12048. ;;
  12049. ;; Gnus internal format of gnus-active-hashtb:
  12050. ;; ((1 . 1))
  12051. ;;  (5 . 10))
  12052. ;;  (67 . 99)) ...)
  12053. ;; The only element in each entry in this hash table is a range of
  12054. ;; (possibly) available articles. (Articles in this range may have
  12055. ;; been expired or canceled.)
  12056. ;;
  12057. ;; Gnus internal format of gnus-killed-list and gnus-zombie-list:
  12058. ;; ("alt.misc" "alt.test" "alt.general" ...)
  12059.  
  12060. (defun gnus-setup-news (&optional rawfile level)
  12061.   "Setup news information.
  12062. If RAWFILE is non-nil, the .newsrc file will also be read.
  12063. If LEVEL is non-nil, the news will be set up at level LEVEL."
  12064.   (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
  12065.     ;; Clear some variables to re-initialize news information.
  12066.     (if init (setq gnus-newsrc-alist nil 
  12067.            gnus-active-hashtb nil))
  12068.  
  12069.     ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
  12070.     (if init (gnus-read-newsrc-file rawfile))
  12071.  
  12072.     ;; If we don't read the complete active file, we fill in the
  12073.     ;; hashtb here. 
  12074.     (if (or (null gnus-read-active-file)
  12075.         (eq gnus-read-active-file 'some))
  12076.     (gnus-update-active-hashtb-from-killed))
  12077.  
  12078.     ;; Read the active file and create `gnus-active-hashtb'.
  12079.     ;; If `gnus-read-active-file' is nil, then we just create an empty
  12080.     ;; hash table. The partial filling out of the hash table will be
  12081.     ;; done in `gnus-get-unread-articles'.
  12082.     (and gnus-read-active-file 
  12083.      (not level)
  12084.      (gnus-read-active-file))
  12085.  
  12086.     (or gnus-active-hashtb
  12087.     (setq gnus-active-hashtb (make-vector 4095 0)))
  12088.  
  12089.     ;; Possibly eval the dribble file.
  12090.     (and init gnus-use-dribble-file (gnus-dribble-eval-file))
  12091.  
  12092.     (gnus-update-format-specifications)
  12093.  
  12094.     ;; Find new newsgroups and treat them.
  12095.     (if (and init gnus-check-new-newsgroups gnus-read-active-file (not level)
  12096.          (gnus-check-server gnus-select-method))
  12097.     (gnus-find-new-newsgroups))
  12098.  
  12099.     ;; Find the number of unread articles in each non-dead group.
  12100.     (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
  12101.       (gnus-get-unread-articles (or level (1+ gnus-level-subscribed))))
  12102.  
  12103.     (if (and init gnus-check-bogus-newsgroups 
  12104.          gnus-read-active-file (not level)
  12105.          (gnus-server-opened gnus-select-method))
  12106.     (gnus-check-bogus-newsgroups))))
  12107.  
  12108. (defun gnus-find-new-newsgroups ()
  12109.   "Search for new newsgroups and add them.
  12110. Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
  12111. The `-n' option line from .newsrc is respected."
  12112.   (interactive)
  12113.   (or (gnus-check-first-time-used)
  12114.       (if (or (consp gnus-check-new-newsgroups)
  12115.           (eq gnus-check-new-newsgroups 'ask-server))
  12116.       (gnus-ask-server-for-new-groups)
  12117.     (let ((groups 0)
  12118.           group new-newsgroups)
  12119.       (gnus-message 5 "Looking for new newsgroups...")
  12120.       (or gnus-have-read-active-file (gnus-read-active-file))
  12121.       (setq gnus-newsrc-last-checked-date (current-time-string))
  12122.       (if (not gnus-killed-hashtb) (gnus-make-hashtable-from-killed))
  12123.       ;; Go though every newsgroup in `gnus-active-hashtb' and compare
  12124.       ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
  12125.       (mapatoms
  12126.        (lambda (sym)
  12127.          (if (or (null (setq group (symbol-name sym)))
  12128.              (null (symbol-value sym))
  12129.              (gnus-gethash group gnus-killed-hashtb)
  12130.              (gnus-gethash group gnus-newsrc-hashtb))
  12131.          ()
  12132.            (let ((do-sub (gnus-matches-options-n group)))
  12133.          (cond 
  12134.           ((eq do-sub 'subscribe)
  12135.            (setq groups (1+ groups))
  12136.            (gnus-sethash group group gnus-killed-hashtb)
  12137.            (funcall gnus-subscribe-options-newsgroup-method group))
  12138.           ((eq do-sub 'ignore)
  12139.            nil)
  12140.           (t
  12141.            (setq groups (1+ groups))
  12142.            (gnus-sethash group group gnus-killed-hashtb)
  12143.            (if gnus-subscribe-hierarchical-interactive
  12144.                (setq new-newsgroups (cons group new-newsgroups))
  12145.              (funcall gnus-subscribe-newsgroup-method group)))))))
  12146.        gnus-active-hashtb)
  12147.       (if new-newsgroups 
  12148.           (gnus-subscribe-hierarchical-interactive new-newsgroups))
  12149.       ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
  12150.       (if (> groups 0)
  12151.           (gnus-message 6 "%d new newsgroup%s arrived." 
  12152.                 groups (if (> groups 1) "s have" " has"))
  12153.         (gnus-message 6 "No new newsgroups."))))))
  12154.  
  12155. (defun gnus-matches-options-n (group)
  12156.   ;; Returns `subscribe' if the group is to be unconditionally
  12157.   ;; subscribed, `ignore' if it is to be ignored, and nil if there is
  12158.   ;; no match for the group.
  12159.  
  12160.   ;; First we check the two user variables.
  12161.   (cond
  12162.    ((and gnus-options-subscribe
  12163.      (string-match gnus-options-subscribe group))
  12164.     'subscribe)
  12165.    ((and gnus-options-not-subscribe
  12166.      (string-match gnus-options-not-subscribe group))
  12167.     'ignore)
  12168.    ;; Then we go through the list that was retrieved from the .newsrc
  12169.    ;; file.  This list has elements on the form 
  12170.    ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
  12171.    ;; is in the reverse order of the options line) is returned.
  12172.    (t
  12173.     (let ((regs gnus-newsrc-options-n))
  12174.       (while (and regs
  12175.           (not (string-match (car (car regs)) group)))
  12176.     (setq regs (cdr regs)))
  12177.       (and regs (cdr (car regs)))))))
  12178.  
  12179. (defun gnus-ask-server-for-new-groups ()
  12180.   (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
  12181.      (methods (cons gnus-select-method 
  12182.             (append
  12183.              (and (consp gnus-check-new-newsgroups)
  12184.                   gnus-check-new-newsgroups)
  12185.              gnus-secondary-select-methods)))
  12186.      (groups 0)
  12187.      (new-date (current-time-string))
  12188.      (hashtb (gnus-make-hashtable 100))
  12189.      group new-newsgroups got-new method)
  12190.     ;; Go through both primary and secondary select methods and
  12191.     ;; request new newsgroups.  
  12192.     (while methods
  12193.       (setq method (gnus-server-get-method nil (car methods)))
  12194.       (and (gnus-check-server method)
  12195.        (gnus-request-newgroups date method)
  12196.        (save-excursion
  12197.          (setq got-new t)
  12198.          (set-buffer nntp-server-buffer)
  12199.          ;; Enter all the new groups in a hashtable.
  12200.          (gnus-active-to-gnus-format method hashtb 'ignore)))
  12201.       (setq methods (cdr methods)))
  12202.     (and got-new (setq gnus-newsrc-last-checked-date new-date))
  12203.     ;; Now all new groups from all select methods are in `hashtb'.
  12204.     (mapatoms
  12205.      (lambda (group-sym)
  12206.        (setq group (symbol-name group-sym))
  12207.        (if (or (null group)
  12208.            (null (symbol-value group-sym))
  12209.            (gnus-gethash group gnus-newsrc-hashtb)
  12210.            (member group gnus-zombie-list)
  12211.            (member group gnus-killed-list))
  12212.        ;; The group is already known.
  12213.        ()
  12214.      (and (symbol-value group-sym)
  12215.           (gnus-sethash group (symbol-value group-sym) gnus-active-hashtb))
  12216.      (let ((do-sub (gnus-matches-options-n group)))
  12217.        (cond ((eq do-sub 'subscribe)
  12218.           (setq groups (1+ groups))
  12219.           (gnus-sethash group group gnus-killed-hashtb)
  12220.           (funcall 
  12221.            gnus-subscribe-options-newsgroup-method group))
  12222.          ((eq do-sub 'ignore)
  12223.           nil)
  12224.          (t
  12225.           (setq groups (1+ groups))
  12226.           (gnus-sethash group group gnus-killed-hashtb)
  12227.           (if gnus-subscribe-hierarchical-interactive
  12228.               (setq new-newsgroups (cons group new-newsgroups))
  12229.             (funcall gnus-subscribe-newsgroup-method group)))))))
  12230.      hashtb)
  12231.     (if new-newsgroups 
  12232.     (gnus-subscribe-hierarchical-interactive new-newsgroups))
  12233.     ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
  12234.     (if (> groups 0)
  12235.     (gnus-message 6 "%d new newsgroup%s arrived." 
  12236.               groups (if (> groups 1) "s have" " has")))
  12237.     got-new))
  12238.  
  12239. (defun gnus-check-first-time-used ()
  12240.   (if (or (> (length gnus-newsrc-alist) 1)
  12241.       (file-exists-p gnus-startup-file)
  12242.       (file-exists-p (concat gnus-startup-file ".el"))
  12243.       (file-exists-p (concat gnus-startup-file ".eld")))
  12244.       nil
  12245.     (gnus-message 6 "First time user; subscribing you to default groups")
  12246.     (or gnus-have-read-active-file (gnus-read-active-file))
  12247.     (setq gnus-newsrc-last-checked-date (current-time-string))
  12248.     (let ((groups gnus-default-subscribed-newsgroups)
  12249.       group)
  12250.       (if (eq groups t)
  12251.       nil
  12252.     (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
  12253.     (mapatoms
  12254.      (lambda (sym)
  12255.        (if (null (setq group (symbol-name sym)))
  12256.            ()
  12257.          (let ((do-sub (gnus-matches-options-n group)))
  12258.            (cond 
  12259.         ((eq do-sub 'subscribe)
  12260.          (gnus-sethash group group gnus-killed-hashtb)
  12261.          (funcall gnus-subscribe-options-newsgroup-method group))
  12262.         ((eq do-sub 'ignore)
  12263.          nil)
  12264.         (t
  12265.          (setq gnus-killed-list (cons group gnus-killed-list)))))))
  12266.      gnus-active-hashtb)
  12267.     (while groups
  12268.       (if (gnus-gethash (car groups) gnus-active-hashtb)
  12269.           (gnus-group-change-level 
  12270.            (car groups) gnus-level-default-subscribed gnus-level-killed))
  12271.       (setq groups (cdr groups)))
  12272.     (gnus-group-make-help-group)
  12273.     (and gnus-novice-user
  12274.          (gnus-message 7 "`A k' to list killed groups"))))))
  12275.  
  12276. (defun gnus-subscribe-group (group previous &optional method)
  12277.   (gnus-group-change-level 
  12278.    (if method
  12279.        (list t group gnus-level-default-subscribed nil nil method)
  12280.      group) 
  12281.    gnus-level-default-subscribed gnus-level-killed previous t))
  12282.  
  12283. ;; `gnus-group-change-level' is the fundamental function for changing
  12284. ;; subscription levels of newsgroups. This might mean just changing
  12285. ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
  12286. ;; again, which subscribes/unsubscribes a group, which is equally
  12287. ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
  12288. ;; from 8-9 to 1-7 means that you remove the group from the list of
  12289. ;; killed (or zombie) groups and add them to the (kinda) subscribed
  12290. ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
  12291. ;; which is trivial.
  12292. ;; ENTRY can either be a string (newsgroup name) or a list (if
  12293. ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
  12294. ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
  12295. ;; entries. 
  12296. ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
  12297. ;; PREVIOUS is the group (in hashtb entry format) to insert this group
  12298. ;; after. 
  12299. (defun gnus-group-change-level (entry level &optional oldlevel
  12300.                       previous fromkilled)
  12301.   (let (group info active num)
  12302.     ;; Glean what info we can from the arguments
  12303.     (if (consp entry)
  12304.     (if fromkilled (setq group (nth 1 entry))
  12305.       (setq group (car (nth 2 entry))))
  12306.       (setq group entry))
  12307.     (if (and (stringp entry)
  12308.          oldlevel 
  12309.          (< oldlevel gnus-level-zombie))
  12310.     (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
  12311.     (if (and (not oldlevel)
  12312.          (consp entry))
  12313.     (setq oldlevel (car (cdr (nth 2 entry)))))
  12314.     (if (stringp previous)
  12315.     (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
  12316.  
  12317.     (if (and (>= oldlevel gnus-level-zombie)
  12318.          (gnus-gethash group gnus-newsrc-hashtb))
  12319.     ;; We are trying to subscribe a group that is already
  12320.     ;; subscribed. 
  12321.     ()                ; Do nothing. 
  12322.  
  12323.       (or (gnus-ephemeral-group-p group)
  12324.       (gnus-dribble-enter
  12325.        (format "(gnus-group-change-level %S %S %S %S %S)" 
  12326.            group level oldlevel (car (nth 2 previous)) fromkilled)))
  12327.     
  12328.       ;; Then we remove the newgroup from any old structures, if needed.
  12329.       ;; If the group was killed, we remove it from the killed or zombie
  12330.       ;; list. If not, and it is in fact going to be killed, we remove
  12331.       ;; it from the newsrc hash table and assoc.
  12332.       (cond ((>= oldlevel gnus-level-zombie)
  12333.          (if (= oldlevel gnus-level-zombie)
  12334.          (setq gnus-zombie-list (delete group gnus-zombie-list))
  12335.            (setq gnus-killed-list (delete group gnus-killed-list))))
  12336.         (t
  12337.          (if (and (>= level gnus-level-zombie)
  12338.               entry)
  12339.          (progn
  12340.            (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
  12341.            (if (nth 3 entry)
  12342.                (setcdr (gnus-gethash (car (nth 3 entry))
  12343.                          gnus-newsrc-hashtb)
  12344.                    (cdr entry)))
  12345.            (setcdr (cdr entry) (cdr (cdr (cdr entry))))))))
  12346.  
  12347.       ;; Finally we enter (if needed) the list where it is supposed to
  12348.       ;; go, and change the subscription level. If it is to be killed,
  12349.       ;; we enter it into the killed or zombie list.
  12350.       (cond ((>= level gnus-level-zombie)
  12351.          ;; Remove from the hash table.
  12352.          (gnus-sethash group nil gnus-newsrc-hashtb)
  12353.          (or (gnus-group-foreign-p group)
  12354.          ;; We do not enter foreign groups into the list of dead
  12355.          ;; groups.  
  12356.          (if (= level gnus-level-zombie)
  12357.              (setq gnus-zombie-list (cons group gnus-zombie-list))
  12358.            (setq gnus-killed-list (cons group gnus-killed-list)))))
  12359.         (t
  12360.          ;; If the list is to be entered into the newsrc assoc, and
  12361.          ;; it was killed, we have to create an entry in the newsrc
  12362.          ;; hashtb format and fix the pointers in the newsrc assoc.
  12363.          (if (>= oldlevel gnus-level-zombie)
  12364.          (progn
  12365.            (if (listp entry)
  12366.                (progn
  12367.              (setq info (cdr entry))
  12368.              (setq num (car entry)))
  12369.              (setq active (gnus-gethash group gnus-active-hashtb))
  12370.              (setq num 
  12371.                (if active (- (1+ (cdr active)) (car active)) t))
  12372.              ;; Check whether the group is foreign. If so, the
  12373.              ;; foreign select method has to be entered into the
  12374.              ;; info. 
  12375.              (let ((method (gnus-group-method-name group)))
  12376.                (if (eq method gnus-select-method)
  12377.                (setq info (list group level nil))
  12378.              (setq info (list group level nil nil method)))))
  12379.            (or previous 
  12380.                (setq previous 
  12381.                  (let ((p gnus-newsrc-alist))
  12382.                    (while (cdr (cdr p))
  12383.                  (setq p (cdr p)))
  12384.                    p)))
  12385.            (setq entry (cons info (cdr (cdr previous))))
  12386.            (if (cdr previous)
  12387.                (progn
  12388.              (setcdr (cdr previous) entry)
  12389.              (gnus-sethash group (cons num (cdr previous)) 
  12390.                        gnus-newsrc-hashtb))
  12391.              (setcdr previous entry)
  12392.              (gnus-sethash group (cons num previous)
  12393.                    gnus-newsrc-hashtb))
  12394.            (if (cdr entry)
  12395.                (setcdr (gnus-gethash (car (car (cdr entry)))
  12396.                          gnus-newsrc-hashtb)
  12397.                    entry)))
  12398.            ;; It was alive, and it is going to stay alive, so we
  12399.            ;; just change the level and don't change any pointers or
  12400.            ;; hash table entries.
  12401.            (setcar (cdr (car (cdr (cdr entry)))) level)))))))
  12402.  
  12403. (defun gnus-kill-newsgroup (newsgroup)
  12404.   "Obsolete function. Kills a newsgroup."
  12405.   (gnus-group-change-level
  12406.    (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
  12407.  
  12408. (defun gnus-check-bogus-newsgroups (&optional confirm)
  12409.   "Remove bogus newsgroups.
  12410. If CONFIRM is non-nil, the user has to confirm the deletion of every
  12411. newsgroup." 
  12412.   (let ((newsrc (cdr gnus-newsrc-alist))
  12413.     bogus group entry)
  12414.     (gnus-message 5 "Checking bogus newsgroups...")
  12415.     (or gnus-have-read-active-file (gnus-read-active-file))
  12416.     ;; Find all bogus newsgroup that are subscribed.
  12417.     (while newsrc
  12418.       (setq group (car (car newsrc)))
  12419.       (if (or (gnus-gethash group gnus-active-hashtb) ; Active
  12420.           (nth 4 (car newsrc))    ; Foreign
  12421.           (and confirm
  12422.            (not (gnus-y-or-n-p
  12423.              (format "Remove bogus newsgroup: %s " group)))))
  12424.       ;; Don't remove.
  12425.       ()
  12426.     ;; Found a bogus newsgroup.
  12427.     (setq bogus (cons group bogus)))
  12428.       (setq newsrc (cdr newsrc)))
  12429.     ;; Remove all bogus subscribed groups by first killing them, and
  12430.     ;; then removing them from the list of killed groups.
  12431.     (while bogus
  12432.       (and (setq entry (gnus-gethash (car bogus) gnus-newsrc-hashtb))
  12433.        (progn
  12434.          (gnus-group-change-level entry gnus-level-killed)
  12435.          (setq gnus-killed-list (delete (car bogus) gnus-killed-list))))
  12436.       (setq bogus (cdr bogus)))
  12437.     ;; Then we remove all bogus groups from the list of killed and
  12438.     ;; zombie groups. They are are removed without confirmation.
  12439.     (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
  12440.       killed)
  12441.       (while dead-lists
  12442.     (setq killed (symbol-value (car dead-lists)))
  12443.     (while killed
  12444.       (setq group (car killed))
  12445.       (or (gnus-gethash group gnus-active-hashtb)
  12446.           ;; The group is bogus.
  12447.           (set (car dead-lists)
  12448.            (delete group (symbol-value (car dead-lists)))))
  12449.       (setq killed (cdr killed)))
  12450.     (setq dead-lists (cdr dead-lists))))
  12451.     (gnus-message 5 "Checking bogus newsgroups...done")))
  12452.  
  12453. (defun gnus-check-duplicate-killed-groups ()
  12454.   "Remove duplicates from the list of killed groups."
  12455.   (interactive)
  12456.   (let ((killed gnus-killed-list))
  12457.     (while killed
  12458.       (gnus-message 9 "%d" (length killed))
  12459.       (setcdr killed (delete (car killed) (cdr killed)))
  12460.       (setq killed (cdr killed)))))
  12461.  
  12462. ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
  12463. ;; and compute how many unread articles there are in each group.
  12464. (defun gnus-get-unread-articles (&optional level) 
  12465.   (let* ((newsrc (cdr gnus-newsrc-alist))
  12466.      (level (or level (1+ gnus-level-subscribed)))
  12467.      (foreign-level
  12468.       (min 
  12469.        (cond ((and gnus-activate-foreign-newsgroups 
  12470.                (not (numberp gnus-activate-foreign-newsgroups)))
  12471.           (1+ gnus-level-subscribed))
  12472.          ((numberp gnus-activate-foreign-newsgroups)
  12473.           gnus-activate-foreign-newsgroups)
  12474.          (t 0))
  12475.        level))
  12476.      info group active virtuals method)
  12477.     (gnus-message 5 "Checking new news...")
  12478.  
  12479.     (while newsrc
  12480.       (setq info (car newsrc)
  12481.         group (car info)
  12482.         active (gnus-gethash group gnus-active-hashtb))
  12483.  
  12484.       ;; Check newsgroups. If the user doesn't want to check them, or
  12485.       ;; they can't be checked (for instance, if the news server can't
  12486.       ;; be reached) we just set the number of unread articles in this
  12487.       ;; newsgroup to t. This means that Gnus thinks that there are
  12488.       ;; unread articles, but it has no idea how many.
  12489.       (if (and (setq method (nth 4 info))
  12490.            (not (gnus-server-equal gnus-select-method
  12491.                        (gnus-server-get-method nil method)))
  12492.            (not (gnus-secondary-method-p method)))
  12493.       ;; These groups are foreign. Check the level.
  12494.       (if (<= (nth 1 info) foreign-level)
  12495.           (if (eq (car (if (stringp method) 
  12496.                    (gnus-server-to-method method)
  12497.                  (nth 4 info))) 'nnvirtual)
  12498.           ;; We have to activate the virtual groups after all
  12499.           ;; the others, so we just pop them on a list for
  12500.           ;; now. 
  12501.           (setq virtuals (cons info virtuals))
  12502.         (and (setq active (gnus-activate-group (car info)))
  12503.              ;; Close the groups as we look at them!
  12504.              (gnus-close-group group))))
  12505.  
  12506.     ;; These groups are native or secondary. 
  12507.     (if (and (not gnus-read-active-file)
  12508.          (<= (nth 1 info) level))
  12509.         (progn
  12510.           (or gnus-read-active-file (gnus-check-server method))
  12511.           (setq active (gnus-activate-group (car info))))))
  12512.       
  12513.       (if active
  12514.       (gnus-get-unread-articles-in-group info active)
  12515.     ;; The group couldn't be reached, so we nix out the number of
  12516.     ;; unread articles and stuff.
  12517.     (gnus-sethash group nil gnus-active-hashtb)
  12518.     (setcar (gnus-gethash group gnus-newsrc-hashtb) t))
  12519.  
  12520.       (setq newsrc (cdr newsrc)))
  12521.  
  12522.     ;; Activate the virtual groups. This has to be done after all the
  12523.     ;; other groups. 
  12524.     ;; !!! If one virtual group contains another virtual group, even
  12525.     ;; doing it this way might cause problems.
  12526.     (while virtuals
  12527.       (and (setq active (gnus-activate-group (car (car virtuals))))
  12528.        (gnus-get-unread-articles-in-group (car virtuals) active))
  12529.       (setq virtuals (cdr virtuals)))
  12530.  
  12531.     (gnus-message 5 "Checking new news...done")))
  12532.  
  12533. ;; Create a hash table out of the newsrc alist. The `car's of the
  12534. ;; alist elements are used as keys.
  12535. (defun gnus-make-hashtable-from-newsrc-alist ()
  12536.   (let ((alist gnus-newsrc-alist)
  12537.     (ohashtb gnus-newsrc-hashtb)
  12538.     prev)
  12539.     (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
  12540.     (setq alist 
  12541.       (setq prev (setq gnus-newsrc-alist 
  12542.                (if (equal (car (car gnus-newsrc-alist))
  12543.                       "dummy.group")
  12544.                    gnus-newsrc-alist
  12545.                  (cons (list "dummy.group" 0 nil) alist)))))
  12546.     (while alist
  12547.       (gnus-sethash (car (car alist)) 
  12548.             (cons (and ohashtb (car (gnus-gethash 
  12549.                          (car (car alist)) ohashtb))) 
  12550.               prev) gnus-newsrc-hashtb)
  12551.       (setq prev alist
  12552.         alist (cdr alist)))))
  12553.  
  12554. (defun gnus-make-hashtable-from-killed ()
  12555.   "Create a hash table from the killed and zombie lists."
  12556.   (let ((lists '(gnus-killed-list gnus-zombie-list))
  12557.     list)
  12558.     (setq gnus-killed-hashtb 
  12559.       (gnus-make-hashtable 
  12560.        (+ (length gnus-killed-list) (length gnus-zombie-list))))
  12561.     (while lists
  12562.       (setq list (symbol-value (car lists)))
  12563.       (setq lists (cdr lists))
  12564.       (while list
  12565.     (gnus-sethash (car list) (car list) gnus-killed-hashtb)
  12566.     (setq list (cdr list))))))
  12567.  
  12568. (defun gnus-get-unread-articles-in-group (info active)
  12569.   (let* ((range (nth 2 info))
  12570.      (num 0)
  12571.      (marked (nth 3 info)))
  12572.     ;; If a cache is present, we may have to alter the active info.
  12573.     (and gnus-use-cache
  12574.      (gnus-cache-possibly-alter-active (car info) active))
  12575.     ;; Modify the list of read articles according to what articles 
  12576.     ;; are available; then tally the unread articles and add the
  12577.     ;; number to the group hash table entry.
  12578.     (cond 
  12579.      ((zerop (cdr active))
  12580.       (setq num 0))
  12581.      ((not range)
  12582.       (setq num (- (1+ (cdr active)) (car active))))
  12583.      ((not (listp (cdr range)))
  12584.       ;; Fix a single (num . num) range according to the
  12585.       ;; active hash table.
  12586.       ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
  12587.       (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
  12588.       (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
  12589.       ;; Compute number of unread articles.
  12590.       (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
  12591.      (t
  12592.       ;; The read list is a list of ranges. Fix them according to
  12593.       ;; the active hash table.
  12594.       ;; First peel off any elements that are below the lower
  12595.       ;; active limit. 
  12596.       (while (and (cdr range) 
  12597.           (>= (car active) 
  12598.               (or (and (atom (car (cdr range))) (car (cdr range)))
  12599.               (car (car (cdr range))))))
  12600.     (if (numberp (car range))
  12601.         (setcar range 
  12602.             (cons (car range) 
  12603.               (or (and (numberp (car (cdr range)))
  12604.                    (car (cdr range))) 
  12605.                   (cdr (car (cdr range))))))
  12606.       (setcdr (car range) 
  12607.           (or (and (numberp (nth 1 range)) (nth 1 range))
  12608.               (cdr (car (cdr range))))))
  12609.     (setcdr range (cdr (cdr range))))
  12610.       ;; Adjust the first element to be the same as the lower limit. 
  12611.       (if (and (not (atom (car range))) 
  12612.            (< (cdr (car range)) (car active)))
  12613.       (setcdr (car range) (1- (car active))))
  12614.       ;; Then we want to peel off any elements that are higher
  12615.       ;; than the upper active limit.  
  12616.       (let ((srange range))
  12617.     ;; Go past all legal elements.
  12618.     (while (and (cdr srange) 
  12619.             (<= (or (and (atom (car (cdr srange)))
  12620.                  (car (cdr srange)))
  12621.                 (car (car (cdr srange)))) (cdr active)))
  12622.       (setq srange (cdr srange)))
  12623.     (if (cdr srange)
  12624.         ;; Nuke all remaining illegal elements.
  12625.         (setcdr srange nil))
  12626.  
  12627.     ;; Adjust the final element.
  12628.     (if (and (not (atom (car srange)))
  12629.          (> (cdr (car srange)) (cdr active)))
  12630.         (setcdr (car srange) (cdr active))))
  12631.       ;; Compute the number of unread articles.
  12632.       (while range
  12633.     (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
  12634.                     (cdr (car range))))
  12635.                 (or (and (atom (car range)) (car range))
  12636.                 (car (car range))))))
  12637.     (setq range (cdr range)))
  12638.       (setq num (max 0 (- (cdr active) num)))))
  12639.     (and info
  12640.      (progn
  12641.        (and (assq 'tick marked)
  12642.         (inline (gnus-remove-illegal-marked-articles
  12643.              (assq 'tick marked) (nth 2 info))))
  12644.        (and (assq 'dormant marked)
  12645.         (inline (gnus-remove-illegal-marked-articles
  12646.              (assq 'dormant marked) (nth 2 info))))
  12647.        (setcar
  12648.         (gnus-gethash (car info) gnus-newsrc-hashtb) 
  12649.         (setq num (max 0 (- num (length (cdr (assq 'tick marked)))
  12650.                 (length (cdr (assq 'dormant marked)))))))))
  12651.     num))
  12652.  
  12653. (defun gnus-remove-illegal-marked-articles (marked ranges)
  12654.   (let ((m (cdr marked)))
  12655.     ;; Make sure that all ticked articles are a subset of the unread
  12656.     ;; articles. 
  12657.     (while m
  12658.       (if (gnus-member-of-range (car m) ranges)
  12659.       (setcdr marked (cdr m))
  12660.     (setq marked m))
  12661.       (setq m (cdr m)))))
  12662.  
  12663. (defun gnus-activate-group (group)
  12664.   ;; Check whether a group has been activated or not.
  12665.   (let ((method (gnus-find-method-for-group group))
  12666.     active)
  12667.     (and (gnus-check-server method)
  12668.      ;; We escape all bugs and quit here to make it possible to
  12669.      ;; continue if a group is so out-there that it reports bugs
  12670.      ;; and stuff.
  12671.      (condition-case ()
  12672.          (gnus-request-group group)
  12673.        (error nil)
  12674.        (quit nil))
  12675.      (save-excursion
  12676.        (set-buffer nntp-server-buffer)
  12677.        (goto-char (point-min))
  12678.        ;; Parse the result we got from `gnus-request-group'.
  12679.        (and (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
  12680.         (progn
  12681.           (goto-char (match-beginning 1))
  12682.           (gnus-sethash 
  12683.            group (setq active (cons (read (current-buffer))
  12684.                         (read (current-buffer))))
  12685.            gnus-active-hashtb))
  12686.         ;; Return the new active info.
  12687.         active)))))
  12688.  
  12689. (defun gnus-update-read-articles 
  12690.   (group unread unselected ticked &optional domarks replied expirable killed
  12691.      dormant bookmark score)
  12692.   "Update the list of read and ticked articles in GROUP using the
  12693. UNREAD and TICKED lists.
  12694. Note: UNSELECTED has to be sorted over `<'.
  12695. Returns whether the updating was successful."
  12696.   (let* ((active (or gnus-newsgroup-active 
  12697.              (gnus-gethash group gnus-active-hashtb)))
  12698.      (entry (gnus-gethash group gnus-newsrc-hashtb))
  12699.      (info (nth 2 entry))
  12700.      (marked (nth 3 info))
  12701.      (prev 1)
  12702.      (unread (sort (copy-sequence unread) (function <)))
  12703.      read)
  12704.     (if (or (not info) (not active))
  12705.     ;; There is no info on this group if it was, in fact,
  12706.     ;; killed. Gnus stores no information on killed groups, so
  12707.     ;; there's nothing to be done. 
  12708.     ;; One could store the information somewhere temporarily,
  12709.     ;; perhaps... Hmmm... 
  12710.     ()
  12711.       ;; Remove any negative articles numbers.
  12712.       (while (and unread (< (car unread) 0))
  12713.     (setq unread (cdr unread)))
  12714.       ;; Remove any expired article numbers
  12715.       (while (and unread (< (car unread) (car active)))
  12716.     (setq unread (cdr unread)))
  12717.       (while (and ticked (< (car ticked) (car active)))
  12718.     (setq ticked (cdr ticked)))
  12719.       (while (and dormant (< (car dormant) (car active)))
  12720.     (setq dormant (cdr dormant)))
  12721.       (setq unread (sort (append unselected unread) '<))
  12722.       ;; Weed out duplicates.
  12723.       (let ((un unread))
  12724.     (while (cdr un)
  12725.       (if (eq (car un) (car (cdr un)))
  12726.           (setcdr un (cdr (cdr un)))
  12727.         (setq un (cdr un)))))
  12728.       ;; Compute the ranges of read articles by looking at the list of
  12729.       ;; unread articles.  
  12730.       (while unread
  12731.     (if (/= (car unread) prev)
  12732.         (setq read (cons (if (= prev (1- (car unread))) prev
  12733.                    (cons prev (1- (car unread)))) read)))
  12734.     (setq prev (1+ (car unread)))
  12735.     (setq unread (cdr unread)))
  12736.       (if (<= prev (cdr active))
  12737.       (setq read (cons (cons prev (cdr active)) read)))
  12738.       ;; Enter this list into the group info.
  12739.       (setcar (cdr (cdr info)) 
  12740.           (if (> (length read) 1) (nreverse read) read))
  12741.       ;; Enter the list of ticked articles.
  12742.       (gnus-set-marked-articles 
  12743.        info ticked
  12744.        (if domarks replied (cdr (assq 'reply marked)))
  12745.        (if domarks expirable (cdr (assq 'expire marked)))
  12746.        (if domarks killed (cdr (assq 'killed marked)))
  12747.        (if domarks dormant (cdr (assq 'dormant marked)))
  12748.        (if domarks bookmark (cdr (assq 'bookmark marked)))
  12749.        (if domarks score (cdr (assq 'score marked))))
  12750.       ;; Set the number of unread articles in gnus-newsrc-hashtb.
  12751.       (gnus-get-unread-articles-in-group 
  12752.        info (gnus-gethash group gnus-active-hashtb))
  12753.       t)))
  12754.  
  12755. (defun gnus-make-articles-unread (group articles)
  12756.   "Mark ARTICLES in GROUP as unread."
  12757.   (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
  12758.               (gnus-gethash (gnus-group-real-name group)
  12759.                     gnus-newsrc-hashtb))))
  12760.      (ranges (nth 2 info))
  12761.      news)
  12762.     (while articles
  12763.       (and (gnus-member-of-range (car articles) ranges)
  12764.        (setq news (cons (car articles) news)))
  12765.       (setq articles (cdr articles)))
  12766.     (if (not news)
  12767.     ()
  12768.       (setcar (nthcdr 2 info)
  12769.           (gnus-remove-from-range (nth 2 info) (nreverse news)))
  12770.       (gnus-group-update-group group t))))
  12771.  
  12772. ;; Enter all dead groups into the hashtb.
  12773. (defun gnus-update-active-hashtb-from-killed ()
  12774.   (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
  12775.     (lists (list gnus-killed-list gnus-zombie-list))
  12776.     killed)
  12777.     (while lists
  12778.       (setq killed (car lists))
  12779.       (while killed
  12780.     (gnus-sethash (car killed) nil hashtb)
  12781.     (setq killed (cdr killed)))
  12782.       (setq lists (cdr lists)))))
  12783.  
  12784. ;; Get the active file(s) from the backend(s).
  12785. (defun gnus-read-active-file ()
  12786.   (gnus-group-set-mode-line)
  12787.   (let ((methods (if (gnus-check-server gnus-select-method)
  12788.              ;; The native server is available.
  12789.              (cons gnus-select-method gnus-secondary-select-methods)
  12790.            ;; The native server is down, so we just do the
  12791.            ;; secondary ones.   
  12792.            gnus-secondary-select-methods))
  12793.     list-type)
  12794.     (setq gnus-have-read-active-file nil)
  12795.     (save-excursion
  12796.       (set-buffer nntp-server-buffer)
  12797.       (while methods
  12798.     (let* ((method (gnus-server-get-method nil (car methods)))
  12799.            (where (nth 1 method))
  12800.            (mesg (format "Reading active file%s via %s..."
  12801.                  (if (and where (not (zerop (length where))))
  12802.                  (concat " from " where) "")
  12803.                  (car method))))
  12804.       (gnus-message 5 mesg)
  12805.       (if (not (gnus-check-server method))
  12806.           ()
  12807.         (cond 
  12808.          ((and (eq gnus-read-active-file 'some)
  12809.            (gnus-check-backend-function 'retrieve-groups (car method)))
  12810.           (let ((newsrc (cdr gnus-newsrc-alist))
  12811.             (gmethod (gnus-server-get-method nil method))
  12812.             groups)
  12813.         (while newsrc
  12814.           (and (gnus-server-equal 
  12815.             (gnus-find-method-for-group 
  12816.              (car (car newsrc)) (car newsrc))
  12817.             gmethod)
  12818.                (setq groups (cons (gnus-group-real-name 
  12819.                        (car (car newsrc))) groups)))
  12820.           (setq newsrc (cdr newsrc)))
  12821.         (gnus-check-server method)
  12822.         (setq list-type (gnus-retrieve-groups groups method))
  12823.         (cond 
  12824.          ((not list-type)
  12825.           (gnus-message 
  12826.            1 "Cannot read partial active file from %s server." 
  12827.            (car method))
  12828.           (ding)
  12829.           (sit-for 2))
  12830.          ((eq list-type 'active)
  12831.           (gnus-active-to-gnus-format method gnus-active-hashtb))
  12832.          (t
  12833.           (gnus-groups-to-gnus-format method gnus-active-hashtb)))))
  12834.          (t
  12835.           (if (not (gnus-request-list method))
  12836.           (progn
  12837.             (gnus-message 1 "Cannot read active file from %s server." 
  12838.                   (car method))
  12839.             (ding))
  12840.         (gnus-active-to-gnus-format method)
  12841.         ;; We mark this active file as read.
  12842.         (setq gnus-have-read-active-file
  12843.               (cons method gnus-have-read-active-file))
  12844.         (gnus-message 5 "%sdone" mesg))))))
  12845.     (setq methods (cdr methods))))))
  12846.  
  12847. ;; Read an active file and place the results in `gnus-active-hashtb'.
  12848. (defun gnus-active-to-gnus-format (method &optional hashtb ignore-errors)
  12849.   (let ((cur (current-buffer))
  12850.     (hashtb (or hashtb 
  12851.             (if (and gnus-active-hashtb 
  12852.                  (not (equal method gnus-select-method)))
  12853.             gnus-active-hashtb
  12854.               (setq gnus-active-hashtb
  12855.                 (if (equal method gnus-select-method)
  12856.                 (gnus-make-hashtable 
  12857.                  (count-lines (point-min) (point-max)))
  12858.                   (gnus-make-hashtable 4096))))))
  12859.     (flag-hashtb (gnus-make-hashtable 60)))
  12860.     ;; Delete unnecessary lines.
  12861.     (goto-char (point-min))
  12862.     (while (search-forward "\nto." nil t)
  12863.       (delete-region (1+ (match-beginning 0)) 
  12864.              (progn (forward-line 1) (point))))
  12865.     (or (string= gnus-ignored-newsgroups "")
  12866.     (progn
  12867.       (goto-char (point-min))
  12868.       (delete-matching-lines gnus-ignored-newsgroups)))
  12869.     ;; Make the group names readable as a lisp expression even if they
  12870.     ;; contain special characters.
  12871.     ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
  12872.     (goto-char (point-max))
  12873.     (while (re-search-backward "[][';?()#]" nil t)
  12874.       (insert ?\\))
  12875.     ;; If these are groups from a foreign select method, we insert the
  12876.     ;; group prefix in front of the group names. 
  12877.     (and method (not (gnus-server-equal
  12878.               (gnus-server-get-method nil method)
  12879.               (gnus-server-get-method nil gnus-select-method)))
  12880.      (let ((prefix (gnus-group-prefixed-name "" method)))
  12881.        (goto-char (point-min))
  12882.        (while (and (not (eobp))
  12883.                (progn (insert prefix)
  12884.                   (zerop (forward-line 1)))))))
  12885.     ;; Store the active file in a hash table.
  12886.     (goto-char (point-min))
  12887.     (if (string-match "%[oO]" gnus-group-line-format)
  12888.     ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
  12889.     ;; If we want information on moderated groups, we use this
  12890.     ;; loop...   
  12891.     (let* ((mod-hashtb (make-vector 7 0))
  12892.            (m (intern "m" mod-hashtb))
  12893.            group max min)
  12894.       (while (not (eobp))
  12895.         (condition-case nil
  12896.         (progn
  12897.           (narrow-to-region (point) (gnus-point-at-eol))
  12898.           (setq group (let ((obarray hashtb)) (read cur)))
  12899.           (if (and (numberp (setq max (read cur)))
  12900.                (numberp (setq min (read cur)))
  12901.                (progn 
  12902.                  (skip-chars-forward " \t")
  12903.                  (not
  12904.                   (or (= (following-char) ?=)
  12905.                   (= (following-char) ?x)
  12906.                   (= (following-char) ?j)))))
  12907.               (set group (cons min max))
  12908.             (set group nil))
  12909.           ;; Enter moderated groups into a list.
  12910.           (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
  12911.               (setq gnus-moderated-list 
  12912.                 (cons (symbol-name group) gnus-moderated-list))))
  12913.           (error 
  12914.            (and group
  12915.             (symbolp group)
  12916.             (set group nil))))
  12917.         (widen)
  12918.         (forward-line 1)))
  12919.       ;; And if we do not care about moderation, we use this loop,
  12920.       ;; which is faster.
  12921.       (let (group max min)
  12922.     (while (not (eobp))
  12923.       (condition-case ()
  12924.           (progn
  12925.         (narrow-to-region (point) (gnus-point-at-eol))
  12926.         ;; group gets set to a symbol interned in the hash table
  12927.         ;; (what a hack!!) - jwz
  12928.         (setq group (let ((obarray hashtb)) (read cur)))
  12929.         (if (and (numberp (setq max (read cur)))
  12930.              (numberp (setq min (read cur)))
  12931.              (progn 
  12932.                (skip-chars-forward " \t")
  12933.                (not
  12934.                 (or (= (following-char) ?=)
  12935.                 (= (following-char) ?x)
  12936.                 (= (following-char) ?j)))))
  12937.             (set group (cons min max))
  12938.           (set group nil)))
  12939.         (error 
  12940.          (progn 
  12941.            (and group
  12942.             (symbolp group)
  12943.             (set group nil))
  12944.            (or ignore-errors
  12945.            (gnus-message 3 "Warning - illegal active: %s"
  12946.                  (buffer-substring 
  12947.                   (gnus-point-at-bol) (gnus-point-at-eol)))))))
  12948.       (widen)
  12949.       (forward-line 1))))))
  12950.  
  12951. (defun gnus-groups-to-gnus-format (method &optional hashtb)
  12952.   ;; Parse a "groups" active file.
  12953.   (let ((cur (current-buffer))
  12954.     (hashtb (or hashtb 
  12955.             (if (and method gnus-active-hashtb)
  12956.             gnus-active-hashtb
  12957.               (setq gnus-active-hashtb
  12958.                 (gnus-make-hashtable 
  12959.                  (count-lines (point-min) (point-max)))))))
  12960.     (prefix (and method 
  12961.              (not (gnus-server-equal
  12962.                (gnus-server-get-method nil method)
  12963.                (gnus-server-get-method nil gnus-select-method)))
  12964.              (gnus-group-prefixed-name "" method))))
  12965.  
  12966.     (goto-char (point-min))
  12967.     ;; We split this into to separate loops, one with the prefix
  12968.     ;; and one without to speed the reading up somewhat.
  12969.     (if prefix
  12970.     (let (min max opoint group)
  12971.       (while (not (eobp))
  12972.         (condition-case ()
  12973.         (progn
  12974.           (read cur) (read cur)
  12975.           (setq min (read cur)
  12976.             max (read cur)
  12977.             opoint (point))
  12978.           (skip-chars-forward " \t")
  12979.           (insert prefix)
  12980.           (goto-char opoint)
  12981.           (set (let ((obarray hashtb)) (read cur)) 
  12982.                (cons min max)))
  12983.           (error (and group (symbolp group) (set group nil))))
  12984.         (forward-line 1)))
  12985.       (let (min max group)
  12986.     (while (not (eobp))
  12987.       (condition-case ()
  12988.           (if (= (following-char) ?2)
  12989.           (progn
  12990.             (read cur) (read cur)
  12991.             (setq min (read cur)
  12992.               max (read cur))
  12993.             (set (setq group (let ((obarray hashtb)) (read cur)))
  12994.              (cons min max))))
  12995.         (error (and group (symbolp group) (set group nil))))
  12996.       (forward-line 1))))))
  12997.  
  12998. (defun gnus-read-newsrc-file (&optional force)
  12999.   "Read startup file.
  13000. If FORCE is non-nil, the .newsrc file is read."
  13001.   ;; Reset variables that might be defined in the .newsrc.eld file.
  13002.   (let ((variables gnus-variable-list))
  13003.     (while variables
  13004.       (set (car variables) nil)
  13005.       (setq variables (cdr variables))))
  13006.   (let* ((newsrc-file gnus-current-startup-file)
  13007.      (quick-file (concat newsrc-file ".el")))
  13008.     (save-excursion
  13009.       ;; We always load the .newsrc.eld file. If always contains
  13010.       ;; much information that can not be gotten from the .newsrc
  13011.       ;; file (ticked articles, killed groups, foreign methods, etc.)
  13012.       (gnus-read-newsrc-el-file quick-file)
  13013.  
  13014.       (if (or force
  13015.           (and (file-newer-than-file-p newsrc-file quick-file)
  13016.            (file-newer-than-file-p newsrc-file 
  13017.                        (concat quick-file "d")))
  13018.           (not gnus-newsrc-alist))
  13019.       ;; We read the .newsrc file. Note that if there if a
  13020.       ;; .newsrc.eld file exists, it has already been read, and
  13021.       ;; the `gnus-newsrc-hashtb' has been created. While reading
  13022.       ;; the .newsrc file, Gnus will only use the information it
  13023.       ;; can find there for changing the data already read -
  13024.       ;; ie. reading the .newsrc file will not trash the data
  13025.       ;; already read (except for read articles).
  13026.       (save-excursion
  13027.         (gnus-message 5 "Reading %s..." newsrc-file)
  13028.         (set-buffer (find-file-noselect newsrc-file))
  13029.         (buffer-disable-undo (current-buffer))
  13030.         (gnus-newsrc-to-gnus-format)
  13031.         (kill-buffer (current-buffer))
  13032.         (gnus-message 5 "Reading %s...done" newsrc-file))))))
  13033.  
  13034. (defun gnus-read-newsrc-el-file (file)
  13035.   (let ((ding-file (concat file "d")))
  13036.     ;; We always, always read the .eld file.
  13037.     (gnus-message 5 "Reading %s..." ding-file)
  13038.     (let (gnus-newsrc-assoc)
  13039.       (condition-case nil
  13040.       (load ding-file t t t)
  13041.     (error nil))
  13042.       (and gnus-newsrc-assoc (setq gnus-newsrc-alist gnus-newsrc-assoc)))
  13043.     (let ((inhibit-quit t))
  13044.       (gnus-uncompress-newsrc-alist))
  13045.     (gnus-make-hashtable-from-newsrc-alist)
  13046.     (if (not (file-newer-than-file-p file ding-file))
  13047.     ()
  13048.       ;; Old format quick file
  13049.       (gnus-message 5 "Reading %s..." file)
  13050.       ;; The .el file is newer than the .eld file, so we read that one
  13051.       ;; as well. 
  13052.       (gnus-read-old-newsrc-el-file file))))
  13053.  
  13054. ;; Parse the old-style quick startup file
  13055. (defun gnus-read-old-newsrc-el-file (file)
  13056.   (let (newsrc killed marked group m)
  13057.     (prog1
  13058.     (let ((gnus-killed-assoc nil)
  13059.           gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
  13060.       (prog1
  13061.           (condition-case nil
  13062.           (load file t t t)
  13063.         (error nil))
  13064.         (setq newsrc gnus-newsrc-assoc
  13065.           killed gnus-killed-assoc
  13066.           marked gnus-marked-assoc)))
  13067.       (setq gnus-newsrc-alist nil)
  13068.       (while newsrc
  13069.     (setq group (car newsrc))
  13070.     (let ((info (nth 2 (gnus-gethash (car group) gnus-newsrc-hashtb))))
  13071.       (if info
  13072.           (progn
  13073.         (setcar (nthcdr 2 info) (cdr (cdr group)))
  13074.         (setcar (cdr info)
  13075.             (if (nth 1 group) gnus-level-default-subscribed 
  13076.               gnus-level-default-unsubscribed))
  13077.         (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
  13078.         (setq gnus-newsrc-alist
  13079.           (cons 
  13080.            (setq info
  13081.              (list (car group)
  13082.                    (if (nth 1 group) gnus-level-default-subscribed
  13083.                  gnus-level-default-unsubscribed) 
  13084.                    (cdr (cdr group))))
  13085.            gnus-newsrc-alist)))
  13086.       (if (setq m (assoc (car group) marked))
  13087.           (setcdr (cdr (cdr info))
  13088.               (cons (list (cons 'tick (cdr m))) nil))))
  13089.     (setq newsrc (cdr newsrc)))
  13090.       (setq newsrc killed)
  13091.       (while newsrc
  13092.     (setcar newsrc (car (car newsrc)))
  13093.     (setq newsrc (cdr newsrc)))
  13094.       (setq gnus-killed-list killed))
  13095.     ;; The .el file version of this variable does not begin with
  13096.     ;; "options", while the .eld version does, so we just add it if it
  13097.     ;; isn't there.
  13098.     (and
  13099.      gnus-newsrc-options 
  13100.      (progn
  13101.        (and (not (string-match "^ *options" gnus-newsrc-options))
  13102.         (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
  13103.        (and (not (string-match "\n$" gnus-newsrc-options))
  13104.         (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
  13105.        ;; Finally, if we read some options lines, we parse them.
  13106.        (or (string= gnus-newsrc-options "")
  13107.        (gnus-newsrc-parse-options gnus-newsrc-options))))
  13108.  
  13109.     (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
  13110.     (gnus-make-hashtable-from-newsrc-alist)))
  13111.       
  13112. (defun gnus-make-newsrc-file (file)
  13113.   "Make server dependent file name by catenating FILE and server host name."
  13114.   (let* ((file (expand-file-name file nil))
  13115.      (real-file (concat file "-" (nth 1 gnus-select-method))))
  13116.     (if (or (file-exists-p real-file)
  13117.         (file-exists-p (concat real-file ".el"))
  13118.         (file-exists-p (concat real-file ".eld")))
  13119.     real-file file)))
  13120.  
  13121. (defun gnus-uncompress-newsrc-alist ()
  13122.   ;; Uncompress all lists of marked articles in the newsrc assoc.
  13123.   (let ((newsrc gnus-newsrc-alist)
  13124.     marked)
  13125.     (while newsrc
  13126.       (if (not (setq marked (nth 3 (car newsrc))))
  13127.       ()
  13128.     (while marked
  13129.       (or (eq 'score (car (car marked)))
  13130.           (eq 'bookmark (car (car marked)))
  13131.           (eq 'killed (car (car marked)))
  13132.           (setcdr (car marked) (gnus-uncompress-range (cdr (car marked)))))
  13133.       (setq marked (cdr marked))))
  13134.       (setq newsrc (cdr newsrc)))))
  13135.  
  13136. (defun gnus-compress-newsrc-alist ()
  13137.   ;; Compress all lists of marked articles in the newsrc assoc.
  13138.   (let ((newsrc gnus-newsrc-alist)
  13139.     marked)
  13140.     (while newsrc
  13141.       (if (not (setq marked (nth 3 (car newsrc))))
  13142.       ()
  13143.     (while marked
  13144.       (or (eq 'score (car (car marked)))
  13145.           (eq 'bookmark (car (car marked)))
  13146.           (eq 'killed (car (car marked)))
  13147.           (setcdr (car marked) 
  13148.               (condition-case ()
  13149.               (gnus-compress-sequence 
  13150.                (sort (cdr (car marked)) '<) t)
  13151.             (error (cdr (car marked))))))
  13152.       (setq marked (cdr marked))))
  13153.       (setq newsrc (cdr newsrc)))))
  13154.  
  13155. (defun gnus-newsrc-to-gnus-format ()
  13156.   (setq gnus-newsrc-options "")
  13157.   (setq gnus-newsrc-options-n nil)
  13158.  
  13159.   (or gnus-active-hashtb
  13160.       (setq gnus-active-hashtb (make-vector 4095 0)))
  13161.   (let ((buf (current-buffer))
  13162.     (already-read (> (length gnus-newsrc-alist) 1))
  13163.     group subscribed options-symbol newsrc Options-symbol
  13164.     symbol reads num1)
  13165.     (goto-char (point-min))
  13166.     ;; We intern the symbol `options' in the active hashtb so that we
  13167.     ;; can `eq' against it later.
  13168.     (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
  13169.     (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
  13170.   
  13171.     (while (not (eobp))
  13172.       ;; We first read the first word on the line by narrowing and
  13173.       ;; then reading into `gnus-active-hashtb'.  Most groups will
  13174.       ;; already exist in that hashtb, so this will save some string
  13175.       ;; space.
  13176.       (narrow-to-region
  13177.        (point)
  13178.        (progn (skip-chars-forward "^ \t!:\n") (point)))
  13179.       (goto-char (point-min))
  13180.       (setq symbol 
  13181.         (and (/= (point-min) (point-max))
  13182.          (let ((obarray gnus-active-hashtb)) (read buf))))
  13183.       (widen)
  13184.       ;; Now, the symbol we have read is either `options' or a group
  13185.       ;; name.  If it is an options line, we just add it to a string. 
  13186.       (cond 
  13187.        ((or (eq symbol options-symbol)
  13188.         (eq symbol Options-symbol))
  13189.     (setq gnus-newsrc-options
  13190.           ;; This concating is quite inefficient, but since our
  13191.           ;; thorough studies show that approx 99.37% of all
  13192.           ;; .newsrc files only contain a single options line, we
  13193.           ;; don't give a damn, frankly, my dear.
  13194.           (concat gnus-newsrc-options
  13195.               (buffer-substring 
  13196.                (gnus-point-at-bol)
  13197.                ;; Options may continue on the next line.
  13198.                (or (and (re-search-forward "^[^ \t]" nil 'move)
  13199.                 (progn (beginning-of-line) (point)))
  13200.                (point)))))
  13201.     (forward-line -1))
  13202.        (symbol
  13203.     (or (boundp symbol) (set symbol nil))
  13204.     ;; It was a group name.
  13205.     (setq subscribed (= (following-char) ?:)
  13206.           group (symbol-name symbol)
  13207.           reads nil)
  13208.     (if (eolp)
  13209.         ;; If the line ends here, this is clearly a buggy line, so
  13210.         ;; we put point a the beginning of line and let the cond
  13211.         ;; below do the error handling.
  13212.         (beginning-of-line)
  13213.       ;; We skip to the beginning of the ranges.
  13214.       (skip-chars-forward "!: \t"))
  13215.     ;; We are now at the beginning of the list of read articles.
  13216.     ;; We read them range by range.
  13217.     (while
  13218.         (cond 
  13219.          ((looking-at "[0-9]+")
  13220.           ;; We narrow and read a number instead of buffer-substring/
  13221.           ;; string-to-int because it's faster. narrow/widen is
  13222.           ;; faster than save-restriction/narrow, and save-restriction
  13223.           ;; produces a garbage object.
  13224.           (setq num1 (progn
  13225.                (narrow-to-region (match-beginning 0) (match-end 0))
  13226.                (read buf)))
  13227.           (widen)
  13228.           ;; If the next character is a dash, then this is a range.
  13229.           (if (= (following-char) ?-)
  13230.           (progn
  13231.             ;; We read the upper bound of the range.
  13232.             (forward-char 1)
  13233.             (if (not (looking-at "[0-9]+"))
  13234.             ;; This is a buggy line, by we pretend that
  13235.             ;; it's kinda OK. Perhaps the user should be
  13236.             ;; dinged? 
  13237.             (setq reads (cons num1 reads))
  13238.               (setq reads 
  13239.                 (cons 
  13240.                  (cons num1
  13241.                    (progn
  13242.                      (narrow-to-region (match-beginning 0) 
  13243.                                (match-end 0))
  13244.                      (read buf)))
  13245.                  reads))
  13246.               (widen)))
  13247.         ;; It was just a simple number, so we add it to the
  13248.         ;; list of ranges.
  13249.         (setq reads (cons num1 reads)))
  13250.           ;; If the next char in ?\n, then we have reached the end
  13251.           ;; of the line and return nil.
  13252.           (/= (following-char) ?\n))
  13253.          ((= (following-char) ?\n)
  13254.           ;; End of line, so we end.
  13255.           nil)
  13256.          (t
  13257.           ;; Not numbers and not eol, so this might be a buggy
  13258.           ;; line... 
  13259.           (or (eobp)        
  13260.           ;; If it was eob instead of ?\n, we allow it.
  13261.           (progn
  13262.             ;; The line was buggy.
  13263.             (setq group nil)
  13264.             (gnus-message 3 "Mangled line: %s" 
  13265.                   (buffer-substring (gnus-point-at-bol) 
  13266.                             (gnus-point-at-eol)))
  13267.             (ding)
  13268.             (sit-for 1)))
  13269.           nil))
  13270.       ;; Skip past ", ". Spaces are illegal in these ranges, but
  13271.       ;; we allow them, because it's a common mistake to put a
  13272.       ;; space after the comma.
  13273.       (skip-chars-forward ", "))
  13274.  
  13275.     ;; We have already read .newsrc.eld, so we gently update the
  13276.     ;; data in the hash table with the information we have just
  13277.     ;; read. 
  13278.     (if (not group)
  13279.         ()
  13280.       (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
  13281.         level)
  13282.         (if info
  13283.         ;; There is an entry for this file in the alist.
  13284.         (progn
  13285.           (setcar (nthcdr 2 info) (nreverse reads))
  13286.           ;; We update the level very gently.  In fact, we
  13287.           ;; only change it if there's been a status change
  13288.           ;; from subscribed to unsubscribed, or vice versa.
  13289.           (setq level (nth 1 info))
  13290.           (cond ((and (<= level gnus-level-subscribed)
  13291.                   (not subscribed))
  13292.              (setq level (if reads
  13293.                      gnus-level-default-unsubscribed 
  13294.                        (1+ gnus-level-default-unsubscribed))))
  13295.             ((and (> level gnus-level-subscribed) subscribed)
  13296.              (setq level gnus-level-default-subscribed)))
  13297.           (setcar (cdr info) level))
  13298.           ;; This is a new group.
  13299.           (setq info (list group 
  13300.                    (if subscribed
  13301.                    gnus-level-default-subscribed 
  13302.                  (if reads
  13303.                      (1+ gnus-level-subscribed)
  13304.                    gnus-level-default-unsubscribed))
  13305.                    (nreverse reads))))
  13306.         (setq newsrc (cons info newsrc))))))
  13307.       (forward-line 1))
  13308.     
  13309.     (setq newsrc (nreverse newsrc))
  13310.  
  13311.     (if (not already-read)
  13312.     ()
  13313.       ;; We now have two newsrc lists - `newsrc', which is what we
  13314.       ;; have read from .newsrc, and `gnus-newsrc-alist', which is
  13315.       ;; what we've read from .newsrc.eld. We have to merge these
  13316.       ;; lists. We do this by "attaching" any (foreign) groups in the
  13317.       ;; gnus-newsrc-alist to the (native) group that precedes them. 
  13318.       (let ((rc (cdr gnus-newsrc-alist))
  13319.         (prev gnus-newsrc-alist)
  13320.         entry mentry)
  13321.     (while rc
  13322.       (or (null (nth 4 (car rc)))    ; It's a native group.
  13323.           (assoc (car (car rc)) newsrc) ; It's already in the alist.
  13324.           (if (setq entry (assoc (car (car prev)) newsrc))
  13325.           (setcdr (setq mentry (memq entry newsrc))
  13326.               (cons (car rc) (cdr mentry)))
  13327.         (setq newsrc (cons (car rc) newsrc))))
  13328.       (setq prev rc
  13329.         rc (cdr rc)))))
  13330.  
  13331.     (setq gnus-newsrc-alist newsrc)
  13332.     ;; We make the newsrc hashtb.
  13333.     (gnus-make-hashtable-from-newsrc-alist)
  13334.  
  13335.     ;; Finally, if we read some options lines, we parse them.
  13336.     (or (string= gnus-newsrc-options "")
  13337.     (gnus-newsrc-parse-options gnus-newsrc-options))))
  13338.  
  13339. ;; Parse options lines to find "options -n !all rec.all" and stuff.
  13340. ;; The return value will be a list on the form
  13341. ;; ((regexp1 . ignore)
  13342. ;;  (regexp2 . subscribe)...)
  13343. ;; When handling new newsgroups, groups that match a `ignore' regexp
  13344. ;; will be ignored, and groups that match a `subscribe' regexp will be
  13345. ;; subscribed. A line like
  13346. ;; options -n !all rec.all
  13347. ;; will lead to a list that looks like
  13348. ;; (("^rec\\..+" . subscribe) 
  13349. ;;  ("^.+" . ignore))
  13350. ;; So all "rec.*" groups will be subscribed, while all the other
  13351. ;; groups will be ignored. Note that "options -n !all rec.all" is very
  13352. ;; different from "options -n rec.all !all". 
  13353. (defun gnus-newsrc-parse-options (options)
  13354.   (let (out eol)
  13355.     (save-excursion
  13356.       (gnus-set-work-buffer)
  13357.       (insert (regexp-quote options))
  13358.       ;; First we treat all continuation lines.
  13359.       (goto-char (point-min))
  13360.       (while (re-search-forward "\n[ \t]+" nil t)
  13361.     (replace-match " " t t))
  13362.       ;; Then we transform all "all"s into ".+"s.
  13363.       (goto-char (point-min))
  13364.       (while (re-search-forward "\\ball\\b" nil t)
  13365.     (replace-match ".+" t t))
  13366.       (goto-char (point-min))
  13367.       ;; We remove all other options than the "-n" ones.
  13368.       (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
  13369.     (replace-match " ")
  13370.     (forward-char -1))
  13371.       (goto-char (point-min))
  13372.  
  13373.       ;; We are only interested in "options -n" lines - we
  13374.       ;; ignore the other option lines.
  13375.       (while (re-search-forward "[ \t]-n" nil t)
  13376.     (setq eol 
  13377.           (or (save-excursion
  13378.             (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
  13379.              (- (point) 2)))
  13380.           (gnus-point-at-eol)))
  13381.     ;; Search for all "words"...
  13382.     (while (re-search-forward "[^ \t,\n]+" eol t)
  13383.       (if (= (char-after (match-beginning 0)) ?!)
  13384.           ;; If the word begins with a bang (!), this is a "not"
  13385.           ;; spec. We put this spec (minus the bang) and the
  13386.           ;; symbol `ignore' into the list.
  13387.           (setq out (cons (cons (concat 
  13388.                      "^" (buffer-substring 
  13389.                       (1+ (match-beginning 0))
  13390.                       (match-end 0)))
  13391.                     'ignore) out))
  13392.         ;; There was no bang, so this is a "yes" spec.
  13393.         (setq out (cons (cons (concat 
  13394.                    "^" (buffer-substring (match-beginning 0)
  13395.                              (match-end 0)))
  13396.                   'subscribe) out)))))
  13397.     
  13398.       (setq gnus-newsrc-options-n out))))
  13399.  
  13400.            
  13401. (defun gnus-save-newsrc-file ()
  13402.   "Save .newsrc file."
  13403.   ;; Note: We cannot save .newsrc file if all newsgroups are removed
  13404.   ;; from the variable gnus-newsrc-alist.
  13405.   (and (or gnus-newsrc-alist gnus-killed-list)
  13406.        gnus-current-startup-file
  13407.        (progn
  13408.      (run-hooks 'gnus-save-newsrc-hook)
  13409.      (save-excursion
  13410.        (if (and gnus-use-dribble-file
  13411.             (or (not gnus-dribble-buffer)
  13412.             (not (buffer-name gnus-dribble-buffer))
  13413.             (zerop (save-excursion
  13414.                  (set-buffer gnus-dribble-buffer)
  13415.                  (buffer-size)))))
  13416.            (gnus-message 4 "(No changes need to be saved)")
  13417.          (if gnus-save-newsrc-file
  13418.          (progn
  13419.            (gnus-message 5 "Saving %s..." gnus-current-startup-file)
  13420.            ;; Make backup file of master newsrc.
  13421.            (gnus-gnus-to-newsrc-format)
  13422.            (gnus-message 5 "Saving %s...done"
  13423.                  gnus-current-startup-file)))
  13424.          ;; Quickly loadable .newsrc.
  13425.          (set-buffer (get-buffer-create " *Gnus-newsrc*"))
  13426.          (make-local-variable 'version-control)
  13427.          (setq version-control 'never)
  13428.          (setq buffer-file-name (concat gnus-current-startup-file ".eld"))
  13429.          (gnus-add-current-to-buffer-list)
  13430.          (buffer-disable-undo (current-buffer))
  13431.          (erase-buffer)
  13432.          (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
  13433.          (gnus-gnus-to-quick-newsrc-format)
  13434.          (save-buffer)
  13435.          (kill-buffer (current-buffer))
  13436.          (gnus-message 5 "Saving %s.eld...done" gnus-current-startup-file)
  13437.          (gnus-dribble-delete-file))))))
  13438.  
  13439. (defun gnus-gnus-to-quick-newsrc-format ()
  13440.   "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
  13441.   (insert ";; Gnus startup file.\n")
  13442.   (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
  13443.   (insert ";; to read .newsrc.\n")
  13444.   (insert "(setq gnus-newsrc-file-version "
  13445.       (prin1-to-string gnus-version) ")\n")
  13446.   (let ((variables gnus-variable-list)
  13447.     (inhibit-quit t)
  13448.     (gnus-newsrc-alist (cdr gnus-newsrc-alist))
  13449.     variable)
  13450.     ;; insert lisp expressions.
  13451.     (gnus-compress-newsrc-alist)
  13452.     (while variables
  13453.       (setq variable (car variables))
  13454.       (and (boundp variable)
  13455.        (symbol-value variable)
  13456.        (or gnus-save-killed-list (not (eq variable 'gnus-killed-list)))
  13457.        (insert "(setq " (symbol-name variable) " '"
  13458.            (prin1-to-string (symbol-value variable))
  13459.            ")\n"))
  13460.       (setq variables (cdr variables)))
  13461.     (gnus-uncompress-newsrc-alist)))
  13462.  
  13463.  
  13464. (defun gnus-gnus-to-newsrc-format ()
  13465.   ;; Generate and save the .newsrc file.
  13466.   (let ((newsrc (cdr gnus-newsrc-alist))
  13467.     info ranges range)
  13468.     (save-excursion
  13469.       (set-buffer (create-file-buffer gnus-current-startup-file))
  13470.       (setq buffer-file-name gnus-current-startup-file)
  13471.       (buffer-disable-undo (current-buffer))
  13472.       (erase-buffer)
  13473.       ;; Write options.
  13474.       (if gnus-newsrc-options (insert gnus-newsrc-options))
  13475.       ;; Write subscribed and unsubscribed.
  13476.       (while newsrc
  13477.     (setq info (car newsrc))
  13478.     (if (not (nth 4 info))        ;Don't write foreign groups to .newsrc.
  13479.         (progn
  13480.           (insert (car info) (if (> (nth 1 info) gnus-level-subscribed)
  13481.                      "!" ":"))
  13482.           (if (setq ranges (nth 2 info))
  13483.           (progn
  13484.             (insert " ")
  13485.             (if (not (listp (cdr ranges)))
  13486.             (if (= (car ranges) (cdr ranges))
  13487.                 (insert (int-to-string (car ranges)))
  13488.               (insert (int-to-string (car ranges)) "-" 
  13489.                   (int-to-string (cdr ranges))))
  13490.               (while ranges
  13491.             (setq range (car ranges)
  13492.                   ranges (cdr ranges))
  13493.             (if (or (atom range) (= (car range) (cdr range)))
  13494.                 (insert (int-to-string 
  13495.                      (or (and (atom range) range) 
  13496.                      (car range))))
  13497.               (insert (int-to-string (car range)) "-"
  13498.                   (int-to-string (cdr range))))
  13499.             (if ranges (insert ","))))))
  13500.           (insert "\n")))
  13501.     (setq newsrc (cdr newsrc)))
  13502.       (make-local-variable 'version-control)
  13503.       (setq version-control 'never)
  13504.       ;; It has been reported that sometime the modtime on the .newsrc
  13505.       ;; file seems to be off. We really do want to overwrite it, so
  13506.       ;; we clear the modtime here before saving. It's a bit odd,
  13507.       ;; though... 
  13508.       ;; sometimes the modtime clear isn't sufficient.  most brute force:
  13509.       ;; delete the silly thing entirely first.  but this fails to provide
  13510.       ;; such niceties as .newsrc~ creation.
  13511.       (if gnus-modtime-botch
  13512.       (delete-file gnus-startup-file)
  13513.     (clear-visited-file-modtime))
  13514.       (save-buffer)
  13515.       (kill-buffer (current-buffer)))))
  13516.  
  13517. (defun gnus-read-all-descriptions-files ()
  13518.   (let ((methods (cons gnus-select-method gnus-secondary-select-methods)))
  13519.     (while methods
  13520.       (gnus-read-descriptions-file (car methods))
  13521.       (setq methods (cdr methods)))
  13522.     t))
  13523.  
  13524. (defun gnus-read-descriptions-file (&optional method)
  13525.   (let ((method (or method gnus-select-method)))
  13526.     ;; We create the hashtable whether we manage to read the desc file
  13527.     ;; to avoid trying to re-read after a failed read.
  13528.     (or gnus-description-hashtb
  13529.     (setq gnus-description-hashtb 
  13530.           (gnus-make-hashtable (length gnus-active-hashtb))))
  13531.     ;; Mark this method's desc file as read.
  13532.     (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
  13533.           gnus-description-hashtb)
  13534.  
  13535.     (gnus-message 5 "Reading descriptions file via %s..." (car method))
  13536.     (cond 
  13537.      ((not (gnus-check-server method))
  13538.       (gnus-message 1 "Couldn't open server")
  13539.       nil)
  13540.      ((not (gnus-request-list-newsgroups method))
  13541.       (gnus-message 1 "Couldn't read newsgroups descriptions")
  13542.       nil)
  13543.      (t
  13544.       (let (group)
  13545.     (save-excursion
  13546.       (save-restriction
  13547.         (set-buffer nntp-server-buffer)
  13548.         (goto-char (point-min))
  13549.         (if (or (search-forward "\n.\n" nil t)
  13550.             (goto-char (point-max)))
  13551.         (progn
  13552.           (beginning-of-line)
  13553.           (narrow-to-region (point-min) (point))))
  13554.         (goto-char (point-min))
  13555.         (while (not (eobp))
  13556.           ;; If we get an error, we set group to 0, which is not a
  13557.           ;; symbol... 
  13558.           (setq group 
  13559.             (condition-case ()
  13560.             (let ((obarray gnus-description-hashtb))
  13561.               ;; Group is set to a symbol interned in this
  13562.               ;; hash table.
  13563.               (read nntp-server-buffer))
  13564.               (error 0)))
  13565.           (skip-chars-forward " \t")
  13566.           ;; ... which leads to this line being effectively ignored.
  13567.           (and (symbolp group)
  13568.            (set group (buffer-substring 
  13569.                    (point) (progn (end-of-line) (point)))))
  13570.           (forward-line 1))))
  13571.     (gnus-message 5 "Reading descriptions file...done")
  13572.     t)))))
  13573.  
  13574. (defun gnus-group-get-description (group)
  13575.   ;; Get the description of a group by sending XGTITLE to the server.
  13576.   (and (gnus-request-group-description group)
  13577.        (save-excursion
  13578.      (set-buffer nntp-server-buffer)
  13579.      (goto-char (point-min))
  13580.      (and (looking-at "[^ \t]+[ \t]+\\(.*\\)")
  13581.           (buffer-substring (match-beginning 1) (match-end 1))))))
  13582.  
  13583. ;;;
  13584. ;;; Server
  13585. ;;;
  13586.  
  13587. (defvar gnus-server-mode-hook nil
  13588.   "Hook run in `gnus-server-mode' buffers.")
  13589.  
  13590. (defconst gnus-server-line-format "     {%(%h:%w%)}\n"
  13591.   "Format of server lines.
  13592. It works along the same lines as a normal formatting string,
  13593. with some simple extensions.")
  13594.  
  13595. (defvar gnus-server-mode-line-format "Gnus  List of servers"
  13596.   "The format specification for the server mode line.")
  13597.  
  13598. (defconst gnus-server-line-format-alist
  13599.   (list (list ?h 'how ?s)
  13600.     (list ?n 'name ?s)
  13601.     (list ?w 'where ?s)
  13602.     ))
  13603.  
  13604. (defconst gnus-server-mode-line-format-alist 
  13605.   (list (list ?S 'news-server ?s)
  13606.     (list ?M 'news-method ?s)
  13607.     (list ?u 'user-defined ?s)))
  13608.  
  13609. (defvar gnus-server-line-format-spec nil)
  13610. (defvar gnus-server-mode-line-format-spec nil)
  13611. (defvar gnus-server-killed-servers nil)
  13612.  
  13613. (defvar gnus-server-mode-map nil)
  13614. (put 'gnus-server-mode 'mode-class 'special)
  13615.  
  13616. (if gnus-server-mode-map
  13617.     nil
  13618.   (setq gnus-server-mode-map (make-sparse-keymap))
  13619.   (suppress-keymap gnus-server-mode-map)
  13620.   (define-key gnus-server-mode-map " " 'gnus-server-read-server)
  13621.   (define-key gnus-server-mode-map "\r" 'gnus-server-read-server)
  13622.   (define-key gnus-server-mode-map gnus-mouse-2 'gnus-server-pick-server)
  13623.   (define-key gnus-server-mode-map "q" 'gnus-server-exit)
  13624.   (define-key gnus-server-mode-map "l" 'gnus-server-list-servers)
  13625.   (define-key gnus-server-mode-map "k" 'gnus-server-kill-server)
  13626.   (define-key gnus-server-mode-map "y" 'gnus-server-yank-server)
  13627.   (define-key gnus-server-mode-map "c" 'gnus-server-copy-server)
  13628.   (define-key gnus-server-mode-map "a" 'gnus-server-add-server)
  13629.   (define-key gnus-server-mode-map "e" 'gnus-server-edit-server))
  13630.  
  13631. (defun gnus-server-mode ()
  13632.   "Major mode for listing and editing servers.
  13633.  
  13634. All normal editing commands are switched off.
  13635. \\<gnus-server-mode-map>
  13636.  
  13637. For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]'). 
  13638.  
  13639. The following commands are available:
  13640.  
  13641. \\{gnus-server-mode-map}"
  13642.   (interactive)
  13643.   (if gnus-visual (gnus-server-make-menu-bar))
  13644.   (kill-all-local-variables)
  13645.   (gnus-simplify-mode-line)
  13646.   (setq major-mode 'gnus-server-mode)
  13647.   (setq mode-name "Server")
  13648.                     ;  (gnus-group-set-mode-line)
  13649.   (setq mode-line-process nil)
  13650.   (use-local-map gnus-server-mode-map)
  13651.   (buffer-disable-undo (current-buffer))
  13652.   (setq truncate-lines t)
  13653.   (setq buffer-read-only t)
  13654.   (run-hooks 'gnus-server-mode-hook))
  13655.  
  13656. (defun gnus-server-insert-server-line (sformat name method)
  13657.   (let* ((sformat (or sformat gnus-server-line-format-spec))
  13658.      (how (car method))
  13659.      (where (nth 1 method))
  13660.      b)
  13661.     (beginning-of-line)
  13662.     (setq b (point))
  13663.     ;; Insert the text.
  13664.     (insert (eval sformat))
  13665.     (add-text-properties b (1+ b) (list 'gnus-server (intern name)))))
  13666.  
  13667. (defun gnus-server-setup-buffer ()
  13668.   (if (get-buffer gnus-server-buffer)
  13669.       ()
  13670.     (save-excursion
  13671.       (set-buffer (get-buffer-create gnus-server-buffer))
  13672.       (gnus-server-mode)
  13673.       (and gnus-carpal (gnus-carpal-setup-buffer 'server)))))
  13674.  
  13675. (defun gnus-server-prepare ()
  13676.   (setq gnus-server-mode-line-format-spec 
  13677.     (gnus-parse-format gnus-server-mode-line-format 
  13678.                gnus-server-mode-line-format-alist))
  13679.   (setq gnus-server-line-format-spec 
  13680.     (gnus-parse-format gnus-server-line-format 
  13681.                gnus-server-line-format-alist))
  13682.   (let ((alist gnus-server-alist)
  13683.     (buffer-read-only nil))
  13684.     (erase-buffer)
  13685.     (while alist
  13686.       (gnus-server-insert-server-line nil (car (car alist)) (cdr (car alist)))
  13687.       (setq alist (cdr alist))))
  13688.   (goto-char (point-min))
  13689.   (gnus-server-position-cursor))
  13690.  
  13691. (defun gnus-server-server-name ()
  13692.   (let ((server (get-text-property (gnus-point-at-bol) 'gnus-server)))
  13693.     (and server (symbol-name server))))
  13694.  
  13695. (defalias 'gnus-server-position-cursor 'gnus-goto-colon)
  13696.  
  13697. (defconst gnus-server-edit-buffer "*Gnus edit server*")
  13698.  
  13699. (defun gnus-server-update-server (server)
  13700.   (save-excursion
  13701.     (set-buffer gnus-server-buffer)
  13702.     (let ((buffer-read-only nil)
  13703.       (info (cdr (assoc server gnus-server-alist))))
  13704.       (gnus-dribble-enter 
  13705.        (concat "(gnus-server-set-info \"" server "\" '"
  13706.            (prin1-to-string info) ")"))
  13707.       ;; Buffer may be narrowed.
  13708.       (save-restriction
  13709.     (widen)
  13710.     (if (gnus-server-goto-server server)
  13711.         (delete-region (progn (beginning-of-line) (point))
  13712.                (progn (forward-line 1) (point))))
  13713.     (let ((entry (assoc server gnus-server-alist)))
  13714.       (gnus-server-insert-server-line nil (car entry) (cdr entry))
  13715.       (gnus-server-position-cursor))))))
  13716.  
  13717. (defun gnus-server-set-info (server info)
  13718.   ;; Enter a select method into the virtual server alist.
  13719.   (gnus-dribble-enter 
  13720.    (concat "(gnus-server-set-info \"" server "\" '"
  13721.        (prin1-to-string info) ")"))
  13722.   (let* ((server (nth 1 info))
  13723.      (entry (assoc server gnus-server-alist)))
  13724.     (if entry (setcdr entry info)
  13725.       (setq gnus-server-alist
  13726.         (nconc gnus-server-alist (list (cons server info)))))))
  13727.  
  13728. (defun gnus-server-to-method (server)
  13729.   ;; Map virtual server names to select methods.
  13730.   (or (and (equal server "native") gnus-select-method)
  13731.       (cdr (assoc server gnus-server-alist))))
  13732.  
  13733. (defun gnus-server-extend-method (group method)
  13734.   ;; This function "extends" a virtual server.  If the server is
  13735.   ;; "hello", and the select method is ("hello" (my-var "something")) 
  13736.   ;; in the group "alt.alt", this will result in a new virtual server
  13737.   ;; called "helly+alt.alt".
  13738.   (let ((entry
  13739.      (gnus-copy-sequence 
  13740.       (if (equal (car method) "native") gnus-select-method
  13741.         (cdr (assoc (car method) gnus-server-alist))))))
  13742.     (setcar (cdr entry) (concat (nth 1 entry) "+" group))
  13743.     (nconc entry (cdr method))))
  13744.  
  13745. (defun gnus-server-get-method (group method)
  13746.   ;; Input either a server name, and extended server name, or a
  13747.   ;; select method, and return a select method. 
  13748.   (cond ((stringp method)
  13749.      (gnus-server-to-method method))
  13750.     ((and (stringp (car method)) group)
  13751.      (gnus-server-extend-method group method))
  13752.     (t
  13753.      (gnus-server-add-address method))))
  13754.  
  13755. (defun gnus-server-add-address (method)
  13756.   (let ((method-name (symbol-name (car method))))
  13757.     (if (and (memq 'address (assoc method-name gnus-valid-select-methods))
  13758.          (not (assq (intern (concat method-name "-address")) method)))
  13759.     (append method (list (list (intern (concat method-name "-address"))
  13760.                    (nth 1 method))))
  13761.       method)))
  13762.  
  13763. (defun gnus-server-equal (s1 s2)
  13764.   (or (equal s1 s2)
  13765.       (and (= (length s1) (length s2))
  13766.        (progn
  13767.          (while (and s1 (member (car s1) s2))
  13768.            (setq s1 (cdr s1)))
  13769.          (null s1)))))
  13770.  
  13771. ;;; Interactive server functions.
  13772.  
  13773. (defun gnus-server-kill-server (server)
  13774.   "Kill the server on the current line."
  13775.   (interactive (list (gnus-server-server-name)))
  13776.   (or (gnus-server-goto-server server)
  13777.       (if server (error "No such server: %s" server)
  13778.     (error "No server on the current line")))
  13779.   (gnus-dribble-enter "")
  13780.   (let ((buffer-read-only nil))
  13781.     (delete-region (progn (beginning-of-line) (point))
  13782.            (progn (forward-line 1) (point))))
  13783.   (setq gnus-server-killed-servers 
  13784.     (cons (assoc server gnus-server-alist) gnus-server-killed-servers))
  13785.   (setq gnus-server-alist (delq (car gnus-server-killed-servers)
  13786.                 gnus-server-alist))
  13787.   (gnus-server-position-cursor))
  13788.  
  13789. (defun gnus-server-yank-server ()
  13790.   "Yank the previously killed server."
  13791.   (interactive)
  13792.   (or gnus-server-killed-servers
  13793.       (error "No killed servers to be yanked"))
  13794.   (let ((alist gnus-server-alist)
  13795.     (server (gnus-server-server-name))
  13796.     (killed (car gnus-server-killed-servers)))
  13797.     (if (not server) 
  13798.     (setq gnus-server-alist (nconc gnus-server-alist (list killed)))
  13799.       (if (string= server (car (car gnus-server-alist)))
  13800.       (setq gnus-server-alist (cons killed gnus-server-alist))
  13801.     (while (and (cdr alist)
  13802.             (not (string= server (car (car (cdr alist))))))
  13803.       (setq alist (cdr alist)))
  13804.     (setcdr alist (cons killed (cdr alist)))))
  13805.     (gnus-server-update-server (car killed))
  13806.     (setq gnus-server-killed-servers (cdr gnus-server-killed-servers))
  13807.     (gnus-server-position-cursor)))
  13808.  
  13809. (defun gnus-server-exit ()
  13810.   "Return to the group buffer."
  13811.   (interactive)
  13812.   (kill-buffer (current-buffer))
  13813.   (switch-to-buffer gnus-group-buffer))
  13814.  
  13815. (defun gnus-server-list-servers ()
  13816.   "List all available servers."
  13817.   (interactive)
  13818.   (let ((cur (gnus-server-server-name)))
  13819.     (gnus-server-prepare)
  13820.     (if cur (gnus-server-goto-server cur)
  13821.       (goto-char (point-max))
  13822.       (forward-line -1))
  13823.     (gnus-server-position-cursor)))
  13824.  
  13825. (defun gnus-server-copy-server (from to)
  13826.   (interactive
  13827.    (list
  13828.     (or (gnus-server-server-name)
  13829.     (error "No server on the current line"))
  13830.     (read-string "Copy to: ")))
  13831.   (or from (error "No server on current line"))
  13832.   (or (and to (not (string= to ""))) (error "No name to copy to"))
  13833.   (and (assoc to gnus-server-alist) (error "%s already exists" to))
  13834.   (or (assoc from gnus-server-alist) 
  13835.       (error "%s: no such server" from))
  13836.   (let ((to-entry (gnus-copy-sequence (assoc from gnus-server-alist))))
  13837.     (setcar to-entry to)
  13838.     (setcar (nthcdr 2 to-entry) to)
  13839.     (setq gnus-server-killed-servers 
  13840.       (cons to-entry gnus-server-killed-servers))
  13841.     (gnus-server-yank-server)))
  13842.  
  13843. (defun gnus-server-add-server (how where)
  13844.   (interactive 
  13845.    (list (intern (completing-read "Server method: "
  13846.                   gnus-valid-select-methods nil t))
  13847.      (read-string "Server name: ")))
  13848.   (setq gnus-server-killed-servers 
  13849.     (cons (list where how where) gnus-server-killed-servers))
  13850.   (gnus-server-yank-server))
  13851.  
  13852. (defun gnus-server-goto-server (server)
  13853.   "Jump to a server line."
  13854.   (interactive
  13855.    (list (completing-read "Goto server: " gnus-server-alist nil t)))
  13856.   (let ((to (text-property-any (point-min) (point-max) 
  13857.                    'gnus-server (intern server))))
  13858.     (and to
  13859.      (progn
  13860.        (goto-char to) 
  13861.        (gnus-server-position-cursor)))))
  13862.  
  13863. (defun gnus-server-edit-server (server)
  13864.   "Edit the server on the current line."
  13865.   (interactive (list (gnus-server-server-name)))
  13866.   (or server
  13867.       (error "No server on current line"))
  13868.   (let ((winconf (current-window-configuration)))
  13869.     (get-buffer-create gnus-server-edit-buffer)
  13870.     (gnus-configure-windows 'edit-server)
  13871.     (gnus-add-current-to-buffer-list)
  13872.     (emacs-lisp-mode)
  13873.     (make-local-variable 'gnus-prev-winconf)
  13874.     (setq gnus-prev-winconf winconf)
  13875.     (use-local-map (copy-keymap (current-local-map)))
  13876.     (let ((done-func '(lambda () 
  13877.             "Exit editing mode and update the information."
  13878.             (interactive)
  13879.             (gnus-server-edit-server-done 'group))))
  13880.       (setcar (cdr (nth 4 done-func)) server)
  13881.       (local-set-key "\C-c\C-c" done-func))
  13882.     (erase-buffer)
  13883.     (insert ";; Type `C-c C-c' after you have edited the server.\n\n")
  13884.     (insert (pp-to-string (cdr (assoc server gnus-server-alist))))))
  13885.  
  13886. (defun gnus-server-edit-server-done (server)
  13887.   (interactive)
  13888.   (set-buffer (get-buffer-create gnus-server-edit-buffer))
  13889.   (goto-char (point-min))
  13890.   (let ((form (read (current-buffer)))
  13891.     (winconf gnus-prev-winconf))
  13892.     (gnus-server-set-info server form)
  13893.     (kill-buffer (current-buffer))
  13894.     (and winconf (set-window-configuration winconf))
  13895.     (set-buffer gnus-server-buffer)
  13896.     (gnus-server-update-server (gnus-server-server-name))
  13897.     (gnus-server-list-servers)
  13898.     (gnus-server-position-cursor)))
  13899.  
  13900. (defun gnus-server-read-server (server)
  13901.   "Browse a server."
  13902.   (interactive (list (gnus-server-server-name)))
  13903.   (gnus-browse-foreign-server (gnus-server-to-method server) (current-buffer)))
  13904.  
  13905. (defun gnus-mouse-pick-server (e)
  13906.   (interactive "e")
  13907.   (mouse-set-point e)
  13908.   (gnus-server-read-server (gnus-server-server-name)))
  13909.  
  13910. ;;;
  13911. ;;; entry points into gnus-score.el
  13912. ;;;
  13913.  
  13914. ;;; Finding score files. 
  13915.  
  13916. (defvar gnus-global-score-files nil
  13917.   "*List of global score files and directories.
  13918. Set this variable if you want to use people's score files.  One entry
  13919. for each score file or each score file directory.  Gnus will decide
  13920. by itself what score files are applicable to which group.
  13921.  
  13922. Say you want to use the single score file
  13923. \"/ftp.ifi.uio.no@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all
  13924. score files in the \"/ftp.some-where:/pub/score\" directory.
  13925.  
  13926.  (setq gnus-global-score-files
  13927.        '(\"/ftp.ifi.uio.no:/pub/larsi/ding/score/soc.motss.SCORE\"
  13928.          \"/ftp.some-where:/pub/score\"))")
  13929.  
  13930. (defun gnus-score-score-files (group)
  13931.   "Return a list of all possible score files."
  13932.   ;; Search and set any global score files.
  13933.   (and gnus-global-score-files 
  13934.        (or gnus-internal-global-score-files
  13935.        (gnus-score-search-global-directories gnus-global-score-files)))
  13936.   ;; Fix the kill-file dir variable.
  13937.   (setq gnus-kill-files-directory 
  13938.     (file-name-as-directory
  13939.      (or gnus-kill-files-directory "~/News/")))
  13940.   ;; If we can't read it, there are no score files.
  13941.   (if (not (file-exists-p (expand-file-name gnus-kill-files-directory)))
  13942.       (setq gnus-score-file-list nil)
  13943.     (if (gnus-use-long-file-name 'not-score)
  13944.     ;; We want long file names.
  13945.     (if (or (not gnus-score-file-list)
  13946.         (not (car gnus-score-file-list))
  13947.         (gnus-file-newer-than gnus-kill-files-directory
  13948.                       (car gnus-score-file-list)))
  13949.         (setq gnus-score-file-list 
  13950.           (cons (nth 5 (file-attributes gnus-kill-files-directory))
  13951.             (nreverse 
  13952.              (directory-files 
  13953.               gnus-kill-files-directory t 
  13954.               (gnus-score-file-regexp))))))
  13955.       ;; We do not use long file names, so we have to do some
  13956.       ;; directory traversing.  
  13957.       (let ((mdir (length (expand-file-name gnus-kill-files-directory)))
  13958.           (suffixes (list gnus-score-file-suffix gnus-adaptive-file-suffix))
  13959.          dir files suffix)
  13960.       (while suffixes
  13961.        (setq dir (expand-file-name
  13962.               (concat gnus-kill-files-directory
  13963.                   (gnus-replace-chars-in-string group ?. ?/))))
  13964.       (setq dir (gnus-replace-chars-in-string dir ?: ?/))
  13965.       (setq suffix (car suffixes)
  13966.         suffixes (cdr suffixes))
  13967.       (if (file-exists-p (concat dir "/" suffix))
  13968.           (setq files (cons (concat dir "/" suffix) files)))
  13969.       (while (>= (1+ (length dir)) mdir)
  13970.         (and (file-exists-p (concat dir "/all/" suffix))
  13971.          (setq files (cons (concat dir "/all/" suffix) files)))
  13972.         (string-match "/[^/]*$" dir)
  13973.         (setq dir (substring dir 0 (match-beginning 0)))))
  13974.     (setq gnus-score-file-list 
  13975.           (cons nil (nreverse files)))))
  13976.     (cdr gnus-score-file-list)))
  13977.  
  13978. (defun gnus-score-file-regexp ()
  13979.   (concat "\\(" gnus-score-file-suffix 
  13980.       "\\|" gnus-adaptive-file-suffix "\\)$"))
  13981.     
  13982. (defun gnus-score-find-bnews (group)
  13983.   "Return a list of score files for GROUP.
  13984. The score files are those files in the ~/News directory which matches
  13985. GROUP using BNews sys file syntax."
  13986.   (let* ((sfiles (append (gnus-score-score-files group)
  13987.              gnus-internal-global-score-files))
  13988.      (kill-dir (file-name-as-directory 
  13989.             (expand-file-name gnus-kill-files-directory)))
  13990.      (klen (length kill-dir))
  13991.      ofiles not-match regexp)
  13992.     (save-excursion
  13993.       (set-buffer (get-buffer-create "*gnus score files*"))
  13994.       (buffer-disable-undo (current-buffer))
  13995.       ;; Go through all score file names and create regexp with them
  13996.       ;; as the source.  
  13997.       (while sfiles
  13998.     (erase-buffer)
  13999.     (insert (car sfiles))
  14000.     (goto-char (point-min))
  14001.     ;; First remove the suffix itself.
  14002.     (re-search-forward (concat "." (gnus-score-file-regexp)))
  14003.     (replace-match "" t t) 
  14004.     (goto-char (point-min))
  14005.     (if (looking-at (regexp-quote kill-dir))
  14006.         ;; If the file name was just "SCORE", `klen' is one character
  14007.         ;; too much.
  14008.         (delete-char (min (1- (point-max)) klen))
  14009.       (goto-char (point-max))
  14010.       (search-backward "/")
  14011.       (delete-region (1+ (point)) (point-min)))
  14012.     ;; If short file names were used, we have to translate slashes.
  14013.     (goto-char (point-min))
  14014.     (while (re-search-forward "[/:]" nil t)
  14015.       (replace-match "." t t))
  14016.     ;; Kludge to get rid of "nntp+" problems.
  14017.     (goto-char (point-min))
  14018.     (and (looking-at "nn[a-z]+\\+")
  14019.          (progn
  14020.            (search-forward "+")
  14021.            (forward-char -1)
  14022.            (insert "\\")))
  14023.     ;; Translate ".all" to "[./].*";
  14024.     (while (search-forward ".all" nil t)
  14025.       (replace-match "[./:].*" t t))
  14026.     (goto-char (point-min))
  14027.     ;; Translate "all" to ".*".
  14028.     (while (search-forward "all" nil t)
  14029.       (replace-match ".*" t t))
  14030.     (goto-char (point-min))
  14031.     ;; Deal with "not."s.
  14032.     (if (looking-at "not.")
  14033.         (progn
  14034.           (setq not-match t)
  14035.           (setq regexp (buffer-substring 5 (point-max))))
  14036.       (setq regexp (buffer-substring 1 (point-max)))
  14037.       (setq not-match nil))
  14038.     ;; Finally - if this resulting regexp matches the group name,
  14039.     ;; we add this score file to the list of score files
  14040.     ;; applicable to this group.
  14041.     (if (or (and not-match
  14042.              (not (string-match regexp group)))
  14043.         (and (not not-match)
  14044.              (string-match regexp group)))
  14045.         (setq ofiles (cons (car sfiles) ofiles)))
  14046.     (setq sfiles (cdr sfiles)))
  14047.       (kill-buffer (current-buffer))
  14048.       ;; Slight kludge here - the last score file returned should be
  14049.       ;; the local score file, whether it exists or not. This is so
  14050.       ;; that any score commands the user enters will go to the right
  14051.       ;; file, and not end up in some global score file.
  14052.       (let ((localscore
  14053.          (expand-file-name
  14054.           (if (gnus-use-long-file-name 'not-score)
  14055.           (concat gnus-kill-files-directory group "." 
  14056.               gnus-score-file-suffix)
  14057.         (concat gnus-kill-files-directory
  14058.             (gnus-replace-chars-in-string group ?. ?/ ?: ?/)
  14059.             "/" gnus-score-file-suffix)))))
  14060.     ;; The local score file might already be there, but it's
  14061.     ;; supposed to be the very last file, so we delete it from the
  14062.     ;; list if it's already there, and add it to the head of the
  14063.     ;; list. 
  14064.     (setq ofiles (cons localscore (delete localscore ofiles))))
  14065.       (nreverse ofiles))))
  14066.  
  14067. (defun gnus-score-find-single (group)
  14068.   "Return list containing the score file for GROUP."
  14069.   (list (gnus-score-file-name group gnus-adaptive-file-suffix)
  14070.     (gnus-score-file-name group)))
  14071.  
  14072. (defun gnus-score-find-hierarchical (group)
  14073.   "Return list of score files for GROUP.
  14074. This includes the score file for the group and all its parents."
  14075.   (let ((all (copy-sequence '(nil)))
  14076.     (start 0))
  14077.     (while (string-match "\\." group (1+ start))
  14078.       (setq start (match-beginning 0))
  14079.       (setq all (cons (substring group 0 start) all)))
  14080.     (setq all (cons group all))
  14081.     (nconc
  14082.      (mapcar (lambda (newsgroup)
  14083.            (gnus-score-file-name newsgroup gnus-adaptive-file-suffix))
  14084.          (setq all (nreverse all)))
  14085.      (mapcar 'gnus-score-file-name all))))
  14086.  
  14087. (defvar gnus-score-file-alist-cache nil)
  14088.  
  14089. (defun gnus-score-find-alist (group)
  14090.   "Return list of score files for GROUP.
  14091. The list is determined from the variable gnus-score-file-alist."
  14092.   (let ((alist gnus-score-file-multiple-match-alist)
  14093.     score-files)
  14094.     ;; if this group has been seen before, return the cached entry
  14095.     (if (setq score-files (assoc group gnus-score-file-alist-cache))
  14096.     (cdr score-files)        ;ensures caching groups with no matches
  14097.       ;; handle the multiple match alist
  14098.       (while alist
  14099.     (and (string-match (car (car alist)) group)
  14100.          (setq score-files
  14101.            (nconc score-files (copy-sequence (cdr (car alist))))))
  14102.     (setq alist (cdr alist)))
  14103.       (setq alist gnus-score-file-single-match-alist)
  14104.       ;; handle the single match alist
  14105.       (while alist
  14106.     (and (string-match (car (car alist)) group)
  14107.          ;; progn used just in case ("regexp") has no files
  14108.          ;; and score-files is still nil. -sj
  14109.          ;; this can be construed as a "stop searching here" feature :>
  14110.          ;; and used to simplify regexps in the single-alist 
  14111.          (progn
  14112.            (setq score-files
  14113.              (nconc score-files (copy-sequence (cdr (car alist)))))
  14114.            (setq alist nil)))
  14115.     (setq alist (cdr alist)))
  14116.       ;; cache the score files
  14117.       (setq gnus-score-file-alist-cache
  14118.         (cons (cons group score-files) gnus-score-file-alist-cache))
  14119.       score-files)))
  14120.  
  14121.  
  14122. (defun gnus-possibly-score-headers (&optional trace)
  14123.   (let ((func gnus-score-find-score-files-function)
  14124.     score-files)
  14125.     (and func (not (listp func))
  14126.      (setq func (list func)))
  14127.     ;; Go through all the functions for finding score files (or actual
  14128.     ;; scores) and add them to a list.
  14129.     (setq score-files (gnus-score-find-alist gnus-newsgroup-name))
  14130.     (while func
  14131.       (and (symbolp (car func))
  14132.        (fboundp (car func))
  14133.        (setq score-files 
  14134.          (nconc score-files (funcall (car func) gnus-newsgroup-name))))
  14135.       (setq func (cdr func)))
  14136.     (if score-files (gnus-score-headers score-files trace))))
  14137.  
  14138. (defun gnus-score-file-name (newsgroup &optional suffix)
  14139.   "Return the name of a score file for NEWSGROUP."
  14140.   (let ((suffix (or suffix gnus-score-file-suffix)))
  14141.     (cond 
  14142.      ((or (null newsgroup)
  14143.       (string-equal newsgroup ""))
  14144.       ;; The global score file is placed at top of the directory.
  14145.       (expand-file-name 
  14146.        suffix (or gnus-kill-files-directory "~/News")))
  14147.      ((gnus-use-long-file-name 'not-score)
  14148.       ;; Append ".SCORE" to newsgroup name.
  14149.       (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
  14150.                 "." suffix)
  14151.             (or gnus-kill-files-directory "~/News")))
  14152.      (t
  14153.       ;; Place "SCORE" under the hierarchical directory.
  14154.       (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
  14155.                 "/" suffix)
  14156.             (or gnus-kill-files-directory "~/News"))))))
  14157.  
  14158. (defun gnus-score-search-global-directories (files)
  14159.   "Scan all global score directories for score files."
  14160.   ;; Set the variable `gnus-internal-global-score-files' to all
  14161.   ;; available global score files.
  14162.   (interactive (list gnus-global-score-files))
  14163.   (let (out)
  14164.     (while files
  14165.       (if (string-match "/$" (car files))
  14166.       (setq out (nconc (directory-files 
  14167.                 (car files) t
  14168.                 (concat (gnus-score-file-regexp) "$"))))
  14169.     (setq out (cons (car files) out)))
  14170.       (setq files (cdr files)))
  14171.     (setq gnus-internal-global-score-files out)))
  14172.  
  14173. ;; Allow redefinition of Gnus functions.
  14174.  
  14175. (gnus-ems-redefine)
  14176.  
  14177. (provide 'gnus)
  14178.  
  14179. ;;; gnus.el ends here
  14180.