home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / a2.0bemacs-src.lha / Emacs-19.25 / lisp / gnus.el < prev    next >
Encoding:
Text File  |  1994-05-27  |  246.2 KB  |  6,974 lines

  1. ;;; GNUS: an NNTP-based News Reader for GNU Emacs
  2. ;; Copyright (C) 1987,88,89,90,93,94 Free Software Foundation, Inc.
  3.  
  4. ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
  5. ;; Keywords: news
  6.  
  7. ;; This file is part of GNU Emacs.
  8.  
  9. ;; GNU Emacs is free software; you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ;; GNU General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  21. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. ;;; Commentary:
  24.  
  25. ;; How to Install GNUS:
  26. ;; (0) First of all, remove GNUS related OLD *.elc files (at least
  27. ;;     nntp.elc).
  28. ;; (1) Unshar gnus.el, gnuspost.el, gnusmail.el, gnusmisc.el, and
  29. ;;     nntp.el.
  30. ;; (2) byte-compile-file nntp.el, gnus.el, gnuspost.el, gnusmail.el,
  31. ;;     and gnusmisc.el.  If you have a local news spool,
  32. ;;     byte-compile-file nnspool.el, too.
  33. ;; (3) Define three environment variables in .login file as follows:
  34. ;;
  35. ;;     setenv    NNTPSERVER    flab
  36. ;;     setenv    DOMAINNAME    "stars.flab.Fujitsu.CO.JP"
  37. ;;     setenv    ORGANIZATION    "Fujitsu Laboratories Ltd., Kawasaki, Japan."
  38. ;;
  39. ;;     Or instead, define lisp variables in your .emacs, site-init.el,
  40. ;;     or default.el as follows:
  41. ;;
  42. ;;     (setq gnus-nntp-server "flab")
  43. ;;     (setq gnus-local-domain "stars.flab.Fujitsu.CO.JP")
  44. ;;     (setq gnus-local-organization "Fujitsu Laboratories Ltd., ...")
  45. ;;
  46. ;;     If the function (system-name) returns the full internet name,
  47. ;;     you don't have to define the domain.
  48. ;;
  49. ;; (4) You may have to define NNTP service name as number 119.
  50. ;;
  51. ;;     (setq gnus-nntp-service 119)
  52. ;;
  53. ;;     Or, if you'd like to use a local news spool directly in stead
  54. ;;     of NNTP, install nnspool.el and set the variable to nil as
  55. ;;     follows:
  56. ;;
  57. ;;     (setq gnus-nntp-service nil)
  58. ;;
  59. ;; (5) If you'd like to use the GENERICFROM feature like the Bnews,
  60. ;;     define the variable as follows:
  61. ;;
  62. ;;     (setq gnus-use-generic-from t)
  63. ;;
  64. ;; (6) Define autoload entries in .emacs file as follows:
  65. ;;
  66. ;;     (autoload 'gnus "gnus" "Read network news." t)
  67. ;;     (autoload 'gnus-post-news "gnuspost" "Post a news." t)
  68. ;;
  69. ;; (7) Read nntp.el if you have problems with NNTP or kanji handling.
  70. ;;
  71. ;; (8) Install mhspool.el, tcp.el, and tcp.c if it is necessary.
  72. ;;
  73. ;;     mhspool.el is a package for reading articles or mail in your
  74. ;;     private directory using GNUS.
  75. ;;
  76. ;;     tcp.el and tcp.c are necessary if and only if your Emacs does
  77. ;;     not have the function `open-network-stream' which is used for
  78. ;;     communicating with NNTP server inside Emacs.
  79. ;;
  80. ;; (9) Install an Info file generated from the texinfo manual gnus.texinfo.
  81. ;;
  82. ;;     If you are not allowed to create the Info file to the standard
  83. ;;     Info-directory, create it in your private directory and set the
  84. ;;     variable gnus-info-directory to that directory.
  85. ;;
  86. ;; For getting more information about GNUS, consult USENET newsgorup
  87. ;; gnu.emacs.gnus.
  88.  
  89. ;; TO DO:
  90. ;; (1) Incremental update of active info.
  91. ;; (2) Asynchronous transmission of large messages.
  92.  
  93. ;;; Code:
  94.  
  95. (provide 'gnus)
  96. (require 'nntp)
  97. (require 'mail-utils)
  98.  
  99. (defvar gnus-default-nntp-server nil
  100.   "*Specify default NNTP server.
  101. This variable should be defined in paths.el.")
  102.  
  103. (defvar gnus-nntp-server (or (getenv "NNTPSERVER") gnus-default-nntp-server)
  104.   "*The name of the host running NNTP server.
  105. If it is a string such as `:DIRECTORY', the user's private DIRECTORY
  106. is used as a news spool.
  107. Initialized from the NNTPSERVER environment variable.")
  108.  
  109. (defvar gnus-nntp-service "nntp"
  110.   "*NNTP service name (\"nntp\" or 119).
  111. Go to a local news spool if its value is nil.")
  112.  
  113. (defvar gnus-startup-file "~/.newsrc"
  114.   "*Your `.newsrc' file.  Use `.newsrc-SERVER' instead if exists.")
  115.  
  116. (defvar gnus-signature-file "~/.signature"
  117.   "*Your `.signature' file.  Use `.signature-DISTRIBUTION' instead if exists.")
  118.  
  119. (defvar gnus-use-cross-reference t
  120.   "*Specifies what to do with cross references (Xref: field).
  121. If nil, ignore cross references.  If t, mark articles as read in
  122. subscribed newsgroups.  Otherwise, if not nil nor t, mark articles as
  123. read in all newsgroups.")
  124.  
  125. (defvar gnus-use-followup-to t
  126.   "*Specifies what to do with Followup-To: field.
  127. If nil, ignore followup-to: field.  If t, use its value except for
  128. `poster'.  Otherwise, if not nil nor t, always use its value.")
  129.  
  130. (defvar gnus-large-newsgroup 50
  131.   "*The number of articles which indicates a large newsgroup.
  132. If the number of articles in a newsgroup is greater than the value,
  133. confirmation is required for selecting the newsgroup.")
  134.  
  135. (defvar gnus-author-copy (getenv "AUTHORCOPY")
  136.   "*File name saving a copy of an article posted using FCC: field.
  137. Initialized from the AUTHORCOPY environment variable.
  138.  
  139. Articles are saved using a function specified by the the variable
  140. `gnus-author-copy-saver' (`rmail-output' is default) if a file name is
  141. given.  Instead, if the first character of the name is `|', the
  142. contents of the article is piped out to the named program. It is
  143. possible to save an article in an MH folder as follows:
  144.  
  145. \(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")")
  146.  
  147. (defvar gnus-author-copy-saver (function rmail-output)
  148.   "*A function called with a file name to save an author copy to.
  149. The default function is `rmail-output' which saves in Unix mailbox format.")
  150.  
  151. (defvar gnus-use-long-file-name
  152.   (not (memq system-type '(usg-unix-v xenix)))
  153.   "*Non-nil means that a newsgroup name is used as a default file name
  154. to save articles to. If it's nil, the directory form of a newsgroup is
  155. used instead.")
  156.  
  157. (defvar gnus-article-save-directory (getenv "SAVEDIR")
  158.   "*A directory name to save articles to (default to ~/News).
  159. Initialized from the SAVEDIR environment variable.")
  160.  
  161. (defvar gnus-default-article-saver (function gnus-summary-save-in-rmail)
  162.   "*A function to save articles in your favorite format.
  163. The function must be interactively callable (in other words, it must
  164. be an Emacs command).
  165.  
  166. GNUS provides the following functions:
  167.     gnus-summary-save-in-rmail (in Rmail format)
  168.     gnus-summary-save-in-mail (in Unix mail format)
  169.     gnus-summary-save-in-folder (in an MH folder)
  170.     gnus-summary-save-in-file (in article format).")
  171.  
  172. (defvar gnus-rmail-save-name (function gnus-plain-save-name)
  173.   "*A function generating a file name to save articles in Rmail format.
  174. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
  175.  
  176. (defvar gnus-mail-save-name (function gnus-plain-save-name)
  177.   "*A function generating a file name to save articles in Unix mail format.
  178. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
  179.  
  180. (defvar gnus-folder-save-name (function gnus-folder-save-name)
  181.   "*A function generating a file name to save articles in MH folder.
  182. The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.")
  183.  
  184. (defvar gnus-file-save-name (function gnus-numeric-save-name)
  185.   "*A function generating a file name to save articles in article format.
  186. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
  187.  
  188. (defvar gnus-kill-file-name "KILL"
  189.   "*File name of a KILL file.")
  190.  
  191. (defvar gnus-novice-user t
  192.   "*Non-nil means that you are a novice to USENET.
  193. If non-nil, verbose messages may be displayed
  194. or your confirmations may be required.")
  195.  
  196. (defvar gnus-interactive-catchup t
  197.   "*Require your confirmation when catching up a newsgroup if non-nil.")
  198.  
  199. (defvar gnus-interactive-post t
  200.   "*Newsgroup, subject, and distribution will be asked for if non-nil.")
  201.  
  202. (defvar gnus-interactive-exit t
  203.   "*Require your confirmation when exiting GNUS if non-nil.")
  204.  
  205. (defvar gnus-user-login-name nil
  206.   "*The login name of the user.
  207. Got from the function `user-login-name' if undefined.")
  208.  
  209. (defvar gnus-user-full-name nil
  210.   "*The full name of the user.
  211. Got from the NAME environment variable if undefined.")
  212.  
  213. (defvar gnus-show-mime nil
  214.   "*Show MIME message if non-nil.")
  215.  
  216. (defvar gnus-show-threads t
  217.   "*Show conversation threads in Summary Mode if non-nil.")
  218.  
  219. (defvar gnus-thread-hide-subject t
  220.   "*Non-nil means hide subjects for thread subtrees.")
  221.  
  222. (defvar gnus-thread-hide-subtree nil
  223.   "*Non-nil means hide thread subtrees initially.
  224. If non-nil, you have to run the command `gnus-summary-show-thread' by
  225. hand or by using `gnus-select-article-hook' to show hidden threads.")
  226.  
  227. (defvar gnus-thread-hide-killed t
  228.   "*Non-nil means hide killed thread subtrees automatically.")
  229.  
  230. (defvar gnus-thread-ignore-subject nil
  231.   "*Don't take care of subject differences, but only references if non-nil.
  232. If it is non-nil, some commands work with subjects do not work properly.")
  233.  
  234. (defvar gnus-thread-indent-level 4
  235.   "*Indentation of thread subtrees.")
  236.  
  237. (defvar gnus-ignored-newsgroups "^to\\..*$"
  238.   "*A regexp to match uninteresting newsgroups in the active file.
  239. Any lines in the active file matching this regular expression are
  240. removed from the newsgroup list before anything else is done to it,
  241. thus making them effectively invisible.")
  242.  
  243. (defvar gnus-ignored-headers
  244.   "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:"
  245.   "*All random fields within the header of a message.")
  246.  
  247. (defvar gnus-required-headers
  248.   '(From Date Newsgroups Subject Message-ID Path Organization Distribution)
  249.   "*All required fields for articles you post.
  250. RFC977 and RFC1036 require From, Date, Newsgroups, Subject, Message-ID
  251. and Path fields.  Organization, Distribution and Lines are optional.
  252. If you want GNUS not to insert some field, remove it from the
  253. variable.")
  254.  
  255. (defvar gnus-show-all-headers nil
  256.   "*Show all headers of an article if non-nil.")
  257.  
  258. (defvar gnus-save-all-headers t
  259.   "*Save all headers of an article if non-nil.")
  260.  
  261. (defvar gnus-optional-headers (function gnus-optional-lines-and-from)
  262.   "*A function generating a optional string displayed in GNUS Summary
  263. mode buffer.  The function is called with an article HEADER. The
  264. result must be a string excluding `[' and `]'.")
  265.  
  266. (defvar gnus-auto-extend-newsgroup t
  267.   "*Extend visible articles to forward and backward if non-nil.")
  268.  
  269. (defvar gnus-auto-select-first t
  270.   "*Select the first unread article automagically if non-nil.
  271. If you want to prevent automatic selection of the first unread article
  272. in some newsgroups, set the variable to nil in `gnus-select-group-hook'
  273. or `gnus-apply-kill-hook'.")
  274.  
  275. (defvar gnus-auto-select-next t
  276.   "*Select the next newsgroup automagically if non-nil.
  277. If the value is t and the next newsgroup is empty, GNUS will exit
  278. Summary mode and go back to Group mode.  If the value is neither nil
  279. nor t, GNUS will select the following unread newsgroup.  Especially, if
  280. the value is the symbol `quietly', the next unread newsgroup will be
  281. selected without any confirmations.")
  282.  
  283. (defvar gnus-auto-select-same nil
  284.   "*Select the next article with the same subject automagically if non-nil.")
  285.  
  286. (defvar gnus-auto-center-summary t
  287.   "*Always center the current summary in GNUS Summary window if non-nil.")
  288.  
  289. (defvar gnus-auto-mail-to-author nil
  290.   "*Insert `To: author' of the article when following up if non-nil.
  291. Mail is sent using the function specified by the variable
  292. `gnus-mail-send-method'.")
  293.  
  294. (defvar gnus-break-pages t
  295.   "*Break an article into pages if non-nil.
  296. Page delimiter is specified by the variable `gnus-page-delimiter'.")
  297.  
  298. (defvar gnus-page-delimiter "^\^L"
  299.   "*Regexp describing line-beginnings that separate pages of news article.")
  300.  
  301. (defvar gnus-digest-show-summary t
  302.   "*Show a summary of undigestified messages if non-nil.")
  303.  
  304. (defvar gnus-digest-separator "^Subject:[ \t]"
  305.   "*Regexp that separates messages in a digest article.")
  306.  
  307. (defvar gnus-use-full-window t
  308.   "*Non-nil means to take up the entire screen of Emacs.")
  309.  
  310. (defvar gnus-window-configuration
  311.   '((summary (0 1 0))
  312.     (newsgroups   (1 0 0))
  313.     (article   (0 3 10)))
  314.   "*Specify window configurations for each action.
  315. The format of the variable is a list of (ACTION (G S A)), where G, S,
  316. and A are the relative height of Group, Summary, and Article windows,
  317. respectively.  ACTION is `summary', `newsgroups', or `article'.")
  318.  
  319. (defvar gnus-show-mime-method (function metamail-buffer)
  320.   "*Function to process a MIME message.
  321. The function is expected to process current buffer as a MIME message.")
  322.  
  323. (defvar gnus-mail-reply-method
  324.   (function gnus-mail-reply-using-mail)
  325.   "*Function to compose reply mail.
  326. The function `gnus-mail-reply-using-mail' uses usual sendmail mail
  327. program.  The function `gnus-mail-reply-using-mhe' uses the MH-E mail
  328. program.  You can use yet another program by customizing this variable.")
  329.  
  330. (defvar gnus-mail-forward-method
  331.   (function gnus-mail-forward-using-mail)
  332.   "*Function to forward current message to another user.
  333. The function `gnus-mail-reply-using-mail' uses usual sendmail mail
  334. program.  You can use yet another program by customizing this variable.")
  335.  
  336. (defvar gnus-mail-other-window-method
  337.   (function gnus-mail-other-window-using-mail)
  338.   "*Function to compose mail in other window.
  339. The function `gnus-mail-other-window-using-mail' uses the usual sendmail
  340. mail program.  The function `gnus-mail-other-window-using-mhe' uses the MH-E
  341. mail program.  You can use yet another program by customizing this variable.")
  342.  
  343. (defvar gnus-mail-send-method send-mail-function
  344.   "*Function to mail a message too which is being posted as an article.
  345. The message must have To: or Cc: field.  The default is copied from
  346. the variable `send-mail-function'.")
  347.  
  348. (defvar gnus-subscribe-newsgroup-method
  349.   (function gnus-subscribe-alphabetically)
  350.   "*Function called with a newsgroup name when new newsgroup is found.
  351. The function `gnus-subscribe-randomly' inserts a new newsgroup a the
  352. beginning of newsgroups.  The function `gnus-subscribe-alphabetically'
  353. inserts it in strict alphabetic order.  The function
  354. `gnus-subscribe-hierarchically' inserts it in hierarchical newsgroup
  355. order.  The function `gnus-subscribe-interactively' asks for your decision.")
  356.  
  357. (defvar gnus-group-mode-hook nil
  358.   "*A hook for GNUS Group Mode.")
  359.  
  360. (defvar gnus-summary-mode-hook nil
  361.   "*A hook for GNUS Summary Mode.")
  362.  
  363. (defvar gnus-article-mode-hook nil
  364.   "*A hook for GNUS Article Mode.")
  365.  
  366. (defvar gnus-kill-file-mode-hook nil
  367.   "*A hook for GNUS KILL File Mode.")
  368.  
  369. (defvar gnus-open-server-hook nil
  370.   "*A hook called just before opening connection to news server.")
  371.  
  372. (defvar gnus-startup-hook nil
  373.   "*A hook called at start up time.
  374. This hook is called after GNUS is connected to the NNTP server. So, it
  375. is possible to change the behavior of GNUS according to the selected
  376. NNTP server.")
  377.  
  378. (defvar gnus-group-prepare-hook nil
  379.   "*A hook called after newsgroup list is created in the Newsgroup buffer.
  380. If you want to modify the Newsgroup buffer, you can use this hook.")
  381.  
  382. (defvar gnus-summary-prepare-hook nil
  383.   "*A hook called after summary list is created in the Summary buffer.
  384. If you want to modify the Summary buffer, you can use this hook.")
  385.  
  386. (defvar gnus-article-prepare-hook nil
  387.   "*A hook called after an article is prepared in the Article buffer.
  388. If you want to run a special decoding program like nkf, use this hook.")
  389.  
  390. (defvar gnus-select-group-hook nil
  391.   "*A hook called when a newsgroup is selected.
  392. If you want to sort Summary buffer by date and then by subject, you
  393. can use the following hook:
  394.  
  395. \(setq gnus-select-group-hook
  396.       (list
  397.        (function
  398.     (lambda ()
  399.       ;; First of all, sort by date.
  400.       (gnus-keysort-headers
  401.        (function string-lessp)
  402.        (function
  403.         (lambda (a)
  404.           (gnus-sortable-date (gnus-header-date a)))))
  405.       ;; Then sort by subject string ignoring `Re:'.
  406.       ;; If case-fold-search is non-nil, case of letters is ignored.
  407.       (gnus-keysort-headers
  408.        (function string-lessp)
  409.        (function
  410.         (lambda (a)
  411.           (if case-fold-search
  412.           (downcase (gnus-simplify-subject (gnus-header-subject a) t))
  413.         (gnus-simplify-subject (gnus-header-subject a) t)))))
  414.       ))))
  415.  
  416. If you'd like to simplify subjects like the
  417. `gnus-summary-next-same-subject' command does, you can use the
  418. following hook:
  419.  
  420. \(setq gnus-select-group-hook
  421.       (list
  422.        (function
  423.     (lambda ()
  424.       (mapcar (function
  425.            (lambda (header)
  426.              (nntp-set-header-subject
  427.               header
  428.               (gnus-simplify-subject
  429.                (gnus-header-subject header) 're-only))))
  430.           gnus-newsgroup-headers)))))
  431.  
  432. In some newsgroups author name is meaningless. It is possible to
  433. prevent listing author names in GNUS Summary buffer as follows:
  434.  
  435. \(setq gnus-select-group-hook
  436.       (list
  437.        (function
  438.     (lambda ()
  439.       (cond ((string-equal \"comp.sources.unix\" gnus-newsgroup-name)
  440.          (setq gnus-optional-headers
  441.                (function gnus-optional-lines)))
  442.         (t
  443.          (setq gnus-optional-headers
  444.                (function gnus-optional-lines-and-from))))))))")
  445.  
  446. (defvar gnus-select-article-hook
  447.   '(gnus-summary-show-thread)
  448.   "*A hook called when an article is selected.
  449. The default hook shows conversation thread subtrees of the selected
  450. article automatically using `gnus-summary-show-thread'.
  451.  
  452. If you'd like to run RMAIL on a digest article automagically, you can
  453. use the following hook:
  454.  
  455. \(setq gnus-select-article-hook
  456.       (list
  457.        (function
  458.     (lambda ()
  459.       (gnus-summary-show-thread)
  460.       (cond ((string-equal \"comp.sys.sun\" gnus-newsgroup-name)
  461.          (gnus-summary-rmail-digest))
  462.         ((and (string-equal \"comp.text\" gnus-newsgroup-name)
  463.               (string-match \"^TeXhax Digest\"
  464.                     (gnus-header-subject gnus-current-headers)))
  465.          (gnus-summary-rmail-digest)
  466.          ))))))")
  467.  
  468. (defvar gnus-select-digest-hook
  469.   (list
  470.    (function
  471.     (lambda ()
  472.       ;; Reply-To: is required by `undigestify-rmail-message'.
  473.       (or (mail-position-on-field "Reply-to" t)
  474.       (progn
  475.         (mail-position-on-field "Reply-to")
  476.         (insert (gnus-fetch-field "From")))))))
  477.   "*A hook called when reading digest messages using Rmail.
  478. This hook can be used to modify incomplete digest articles as follows
  479. \(this is the default):
  480.  
  481. \(setq gnus-select-digest-hook
  482.       (list
  483.        (function
  484.     (lambda ()
  485.       ;; Reply-To: is required by `undigestify-rmail-message'.
  486.       (or (mail-position-on-field \"Reply-to\" t)
  487.           (progn
  488.         (mail-position-on-field \"Reply-to\")
  489.         (insert (gnus-fetch-field \"From\"))))))))")
  490.  
  491. (defvar gnus-rmail-digest-hook nil
  492.   "*A hook called when reading digest messages using Rmail.
  493. This hook is intended to customize Rmail mode for reading digest articles.")
  494.  
  495. (defvar gnus-apply-kill-hook '(gnus-apply-kill-file)
  496.   "*A hook called when a newsgroup is selected and summary list is prepared.
  497. This hook is intended to apply a KILL file to the selected newsgroup.
  498. The function `gnus-apply-kill-file' is called by default.
  499.  
  500. Since a general KILL file is too heavy to use only for a few
  501. newsgroups, I recommend you to use a lighter hook function. For
  502. example, if you'd like to apply a KILL file to articles which contains
  503. a string `rmgroup' in subject in newsgroup `control', you can use the
  504. following hook:
  505.  
  506. \(setq gnus-apply-kill-hook
  507.       (list
  508.        (function
  509.     (lambda ()
  510.       (cond ((string-match \"control\" gnus-newsgroup-name)
  511.          (gnus-kill \"Subject\" \"rmgroup\")
  512.          (gnus-expunge \"X\")))))))")
  513.  
  514. (defvar gnus-mark-article-hook
  515.   (list
  516.    (function
  517.     (lambda ()
  518.       (or (memq gnus-current-article gnus-newsgroup-marked)
  519.       (gnus-summary-mark-as-read gnus-current-article))
  520.       (gnus-summary-set-current-mark "+"))))
  521.   "*A hook called when an article is selected at the first time.
  522. The hook is intended to mark an article as read (or unread)
  523. automatically when it is selected.
  524.  
  525. If you'd like to mark as unread (-) instead, use the following hook:
  526.  
  527. \(setq gnus-mark-article-hook
  528.       (list
  529.        (function
  530.         (lambda ()
  531.       (gnus-summary-mark-as-unread gnus-current-article)
  532.       (gnus-summary-set-current-mark \"+\")))))")
  533.  
  534. (defvar gnus-prepare-article-hook (list (function gnus-inews-insert-signature))
  535.   "*A hook called after preparing body, but before preparing header fields.
  536. The default hook (`gnus-inews-insert-signature') inserts a signature
  537. file specified by the variable `gnus-signature-file'.")
  538.  
  539. (defvar gnus-inews-article-hook (list (function gnus-inews-do-fcc))
  540.   "*A hook called before finally posting an article.
  541. The default hook (`gnus-inews-do-fcc') does FCC processing (save article
  542. to a file).")
  543.  
  544. (defvar gnus-exit-group-hook nil
  545.   "*A hook called when exiting (not quitting) Summary mode.
  546. If your machine is so slow that exiting from Summary mode takes very
  547. long time, set the variable `gnus-use-cross-reference' to nil. This
  548. inhibits marking articles as read using cross-reference information.")
  549.  
  550. (defvar gnus-suspend-gnus-hook nil
  551.   "*A hook called when suspending (not exiting) GNUS.")
  552.  
  553. (defvar gnus-exit-gnus-hook nil
  554.   "*A hook called when exiting (not suspending) GNUS.")
  555.  
  556. (defvar gnus-save-newsrc-hook nil
  557.   "*A hook called when saving the newsrc file.
  558. This hook is called before saving the `.newsrc' file.")
  559.  
  560.  
  561. ;; Site dependent variables. You have to define these variables in
  562. ;;  site-init.el, default.el or your .emacs.
  563.  
  564. (defvar gnus-local-timezone nil
  565.   "*Local time zone.
  566. This value is used only if `current-time-zone' does not work in your Emacs.
  567. It specifies the GMT offset, i.e. a decimal integer
  568. of the form +-HHMM giving the hours and minutes ahead of (i.e. east of) GMT.
  569. For example, +0900 should be used in Japan, since it is 9 hours ahead of GMT.
  570.  
  571. For backwards compatibility, it may also be a string like \"JST\",
  572. but strings are obsolescent: you should use numeric offsets instead.")
  573.  
  574. (defvar gnus-local-domain nil
  575.   "*Local domain name without a host name like: \"stars.flab.Fujitsu.CO.JP\"
  576. The `DOMAINNAME' environment variable is used instead if defined.  If
  577. the function (system-name) returns the full internet name, there is no
  578. need to define the name.")
  579.  
  580. (defvar gnus-local-organization nil
  581.   "*Local organization like: \"Fujitsu Laboratories Ltd., Kawasaki, Japan.\"
  582. The `ORGANIZATION' environment variable is used instead if defined.")
  583.  
  584. (defvar gnus-local-distributions '("local" "world")
  585.   "*List of distributions.
  586. The first element in the list is used as default.  If distributions
  587. file is available, its content is also used.")
  588.  
  589. (defvar gnus-use-generic-from nil
  590.   "*If nil, prepend local host name to the defined domain in the From:
  591. field; if stringp, use this; if non-nil, strip of the local host name.")
  592.  
  593. (defvar gnus-use-generic-path nil
  594.   "*If nil, use the NNTP server name in the Path: field; if stringp,
  595. use this; if non-nil, use no host name (user name only)")
  596.  
  597. ;; Internal variables.
  598.  
  599. (defconst gnus-version "GNUS 4.1"
  600.   "Version numbers of this version of GNUS.")
  601.  
  602. (defconst gnus-emacs-version
  603.   (progn
  604.     (string-match "[0-9]*" emacs-version)
  605.     (string-to-int (substring emacs-version
  606.                   (match-beginning 0) (match-end 0))))
  607.   "Major version number of this emacs.")
  608.  
  609. (defvar gnus-info-nodes
  610.   '((gnus-group-mode        "(gnus)Newsgroup Commands")
  611.     (gnus-summary-mode        "(gnus)Summary Commands")
  612.     (gnus-article-mode        "(gnus)Article Commands")
  613.     (gnus-kill-file-mode    "(gnus)Kill File")
  614.     (gnus-browse-killed-mode    "(gnus)Maintaining Subscriptions"))
  615.   "Assoc list of major modes and related Info nodes.")
  616.  
  617. ;; Alist syntax is different from that of 3.14.3.
  618. (defvar gnus-access-methods
  619.   '((nntp
  620.      (gnus-retrieve-headers        nntp-retrieve-headers)
  621.      (gnus-open-server            nntp-open-server)
  622.      (gnus-close-server            nntp-close-server)
  623.      (gnus-server-opened        nntp-server-opened)
  624.      (gnus-status-message        nntp-status-message)
  625.      (gnus-request-article        nntp-request-article)
  626.      (gnus-request-group        nntp-request-group)
  627.      (gnus-request-list            nntp-request-list)
  628.      (gnus-request-list-newsgroups    nntp-request-list-newsgroups)
  629.      (gnus-request-list-distributions    nntp-request-list-distributions)
  630.      (gnus-request-post            nntp-request-post))
  631.     (nnspool
  632.      (gnus-retrieve-headers        nnspool-retrieve-headers)
  633.      (gnus-open-server            nnspool-open-server)
  634.      (gnus-close-server            nnspool-close-server)
  635.      (gnus-server-opened        nnspool-server-opened)
  636.      (gnus-status-message        nnspool-status-message)
  637.      (gnus-request-article        nnspool-request-article)
  638.      (gnus-request-group        nnspool-request-group)
  639.      (gnus-request-list            nnspool-request-list)
  640.      (gnus-request-list-newsgroups    nnspool-request-list-newsgroups)
  641.      (gnus-request-list-distributions    nnspool-request-list-distributions)
  642.      (gnus-request-post            nnspool-request-post))
  643.     (mhspool
  644.      (gnus-retrieve-headers        mhspool-retrieve-headers)
  645.      (gnus-open-server            mhspool-open-server)
  646.      (gnus-close-server            mhspool-close-server)
  647.      (gnus-server-opened        mhspool-server-opened)
  648.      (gnus-status-message        mhspool-status-message)
  649.      (gnus-request-article        mhspool-request-article)
  650.      (gnus-request-group        mhspool-request-group)
  651.      (gnus-request-list            mhspool-request-list)
  652.      (gnus-request-list-newsgroups    mhspool-request-list-newsgroups)
  653.      (gnus-request-list-distributions    mhspool-request-list-distributions)
  654.      (gnus-request-post            mhspool-request-post)))
  655.   "Access method for NNTP, nnspool, and mhspool.")
  656.  
  657. (defvar gnus-group-buffer "*Newsgroup*")
  658. (defvar gnus-summary-buffer "*Summary*")
  659. (defvar gnus-article-buffer "*Article*")
  660. (defvar gnus-digest-buffer "GNUS Digest")
  661. (defvar gnus-digest-summary-buffer "GNUS Digest-summary")
  662.  
  663. (defvar gnus-buffer-list
  664.   (list gnus-group-buffer gnus-summary-buffer gnus-article-buffer
  665.     gnus-digest-buffer gnus-digest-summary-buffer)
  666.   "GNUS buffer names which should be killed when exiting.")
  667.  
  668. (defvar gnus-variable-list
  669.   '(gnus-newsrc-options
  670.     gnus-newsrc-options-n-yes gnus-newsrc-options-n-no
  671.     gnus-newsrc-assoc gnus-killed-assoc gnus-marked-assoc)
  672.   "GNUS variables saved in the quick startup file.")
  673.  
  674. (defvar gnus-overload-functions
  675.   '((news-inews gnus-inews-news "rnewspost")
  676.     (caesar-region gnus-caesar-region "rnews"))
  677.   "Functions overloaded by gnus.
  678. It is a list of `(original overload &optional file)'.")
  679.  
  680. (defvar gnus-distribution-list nil)
  681.  
  682. (defvar gnus-newsrc-options nil
  683.   "Options line in the .newsrc file.")
  684.  
  685. (defvar gnus-newsrc-options-n-yes nil
  686.   "Regexp representing subscribed newsgroups.")
  687.  
  688. (defvar gnus-newsrc-options-n-no nil
  689.   "Regexp representing unsubscribed newsgroups.")
  690.  
  691. (defvar gnus-newsrc-assoc nil
  692.   "Assoc list of read articles.
  693. gnus-newsrc-hashtb should be kept so that both hold the same information.")
  694.  
  695. (defvar gnus-newsrc-hashtb nil
  696.   "Hashtable of gnus-newsrc-assoc.")
  697.  
  698. (defvar gnus-killed-assoc nil
  699.   "Assoc list of newsgroups removed from gnus-newsrc-assoc.
  700. gnus-killed-hashtb should be kept so that both hold the same information.")
  701.  
  702. (defvar gnus-killed-hashtb nil
  703.   "Hashtable of gnus-killed-assoc.")
  704.  
  705. (defvar gnus-marked-assoc nil
  706.   "Assoc list of articles marked as unread.
  707. gnus-marked-hashtb should be kept so that both hold the same information.")
  708.  
  709. (defvar gnus-marked-hashtb nil
  710.   "Hashtable of gnus-marked-assoc.")
  711.  
  712. (defvar gnus-unread-hashtb nil
  713.   "Hashtable of unread articles.")
  714.  
  715. (defvar gnus-active-hashtb nil
  716.   "Hashtable of active articles.")
  717.  
  718. (defvar gnus-octive-hashtb nil
  719.   "Hashtable of OLD active articles.")
  720.  
  721. (defvar gnus-current-startup-file nil
  722.   "Startup file for the current host.")
  723.  
  724. (defvar gnus-last-search-regexp nil
  725.   "Default regexp for article search command.")
  726.  
  727. (defvar gnus-last-shell-command nil
  728.   "Default shell command on article.")
  729.  
  730. (defvar gnus-have-all-newsgroups nil)
  731.  
  732. (defvar gnus-newsgroup-name nil)
  733. (defvar gnus-newsgroup-begin nil)
  734. (defvar gnus-newsgroup-end nil)
  735. (defvar gnus-newsgroup-last-rmail nil)
  736. (defvar gnus-newsgroup-last-mail nil)
  737. (defvar gnus-newsgroup-last-folder nil)
  738. (defvar gnus-newsgroup-last-file nil)
  739.  
  740. (defvar gnus-newsgroup-unreads nil
  741.   "List of unread articles in the current newsgroup.")
  742.  
  743. (defvar gnus-newsgroup-unselected nil
  744.   "List of unselected unread articles in the current newsgroup.")
  745.  
  746. (defvar gnus-newsgroup-marked nil
  747.   "List of marked articles in the current newsgroup (a subset of unread art).")
  748.  
  749. (defvar gnus-newsgroup-headers nil
  750.   "List of article headers in the current newsgroup.
  751. If the variable is modified (added or deleted), the function
  752. gnus-clear-hashtables-for-newsgroup-headers must be called to clear
  753. the hash tables.")
  754. (defvar gnus-newsgroup-headers-hashtb-by-id nil)
  755. (defvar gnus-newsgroup-headers-hashtb-by-number nil)
  756.  
  757. (defvar gnus-current-article nil)
  758. (defvar gnus-current-headers nil)
  759. (defvar gnus-current-history nil)
  760. (defvar gnus-have-all-headers nil "Must be either T or NIL.")
  761. (defvar gnus-last-article nil)
  762. (defvar gnus-current-kill-article nil)
  763.  
  764. ;; Save window configuration.
  765. (defvar gnus-winconf-kill-file nil)
  766.  
  767. (defvar gnus-group-mode-map nil)
  768. (defvar gnus-summary-mode-map nil)
  769. (defvar gnus-article-mode-map nil)
  770. (defvar gnus-kill-file-mode-map nil)
  771.  
  772. (defvar rmail-default-file (expand-file-name "~/XMBOX"))
  773. (defvar rmail-default-rmail-file (expand-file-name "~/XNEWS"))
  774.  
  775. ;; Define GNUS Subsystems.
  776. (autoload 'gnus-group-post-news "gnuspost"
  777.       "Post an article." t)
  778. (autoload 'gnus-summary-post-news "gnuspost"
  779.       "Post an article." t)
  780. (autoload 'gnus-summary-followup "gnuspost"
  781.       "Post a reply article." t)
  782. (autoload 'gnus-summary-followup-with-original "gnuspost"
  783.       "Post a reply article with original article." t)
  784. (autoload 'gnus-summary-cancel-article "gnuspost"
  785.       "Cancel an article you posted." t)
  786.  
  787. (autoload 'gnus-summary-reply "gnusmail"
  788.       "Reply mail to news author." t)
  789. (autoload 'gnus-summary-reply-with-original "gnusmail"
  790.       "Reply mail to news author with original article." t)
  791. (autoload 'gnus-summary-mail-forward "gnusmail"
  792.       "Forward the current message to another user." t)
  793. (autoload 'gnus-summary-mail-other-window "gnusmail"
  794.       "Compose mail in other window." t)
  795.  
  796. (autoload 'gnus-group-kill-group "gnusmisc"
  797.       "Kill newsgroup on current line." t)
  798. (autoload 'gnus-group-yank-group "gnusmisc"
  799.       "Yank the last killed newsgroup on current line." t)
  800. (autoload 'gnus-group-kill-region "gnusmisc"
  801.       "Kill newsgroups in current region." t)
  802. (autoload 'gnus-group-transpose-groups "gnusmisc"
  803.       "Exchange current newsgroup and previous newsgroup." t)
  804. (autoload 'gnus-list-killed-groups "gnusmisc"
  805.       "List the killed newsgroups." t)
  806. (autoload 'gnus-gmt-to-local "gnusmisc"
  807.       "Rewrite Date field in GMT to local in current buffer.")
  808.  
  809. (autoload 'metamail-buffer "metamail"
  810.       "Process current buffer through 'metamail'." t)
  811.  
  812. (autoload 'timezone-make-sortable-date "timezone")
  813. (autoload 'timezone-parse-date "timezone")
  814.  
  815. (autoload 'rmail-output "rmailout"
  816.       "Append this message to Unix mail file named FILE-NAME." t)
  817. (autoload 'mail-position-on-field "sendmail")
  818. (autoload 'mh-find-path "mh-e")
  819. (autoload 'mh-prompt-for-folder "mh-e")
  820.  
  821. (put 'gnus-group-mode 'mode-class 'special)
  822. (put 'gnus-summary-mode 'mode-class 'special)
  823. (put 'gnus-article-mode 'mode-class 'special)
  824.  
  825. (autoload 'gnus-uu-ctl-map "gnus-uu" nil nil 'keymap)
  826. (autoload 'gnus-uu-mark-article "gnus-uu" nil t)
  827.  
  828. ;;(put 'gnus-eval-in-buffer-window 'lisp-indent-hook 1)
  829.  
  830. (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
  831.   "Pop to BUFFER, evaluate FORMS, and then returns to original window."
  832.   (` (let ((GNUSStartBufferWindow (selected-window)))
  833.        (unwind-protect
  834.        (progn
  835.          (pop-to-buffer (, buffer))
  836.          (,@ forms))
  837.      (select-window GNUSStartBufferWindow)))))
  838.  
  839. (defmacro gnus-make-hashtable (&optional hashsize)
  840.   "Make a hash table (default and minimum size is 200).
  841. Optional argument HASHSIZE specifies the table size."
  842.   (` (make-vector (, (if hashsize (` (max (, hashsize) 200)) 200)) 0)))
  843.  
  844. (defmacro gnus-gethash (string hashtable)
  845.   "Get hash value of STRING in HASHTABLE."
  846.   ;;(` (symbol-value (abbrev-symbol (, string) (, hashtable))))
  847.   ;;(` (abbrev-expansion (, string) (, hashtable)))
  848.   (` (symbol-value (intern-soft (, string) (, hashtable)))))
  849.  
  850. (defmacro gnus-sethash (string value hashtable)
  851.   "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
  852.   ;; We cannot use define-abbrev since it only accepts string as value.
  853.   (` (set (intern (, string) (, hashtable)) (, value))))
  854.  
  855. ;; Note: Macros defined here are also defined in nntp.el. I don't like
  856. ;; to put them here, but many users got troubled with the old
  857. ;; definitions in nntp.elc. These codes are NNTP 3.10 version.
  858.  
  859. (defmacro nntp-header-number (header)
  860.   "Return article number in HEADER."
  861.   (` (aref (, header) 0)))
  862.  
  863. (defmacro nntp-set-header-number (header number)
  864.   "Set article number of HEADER to NUMBER."
  865.   (` (aset (, header) 0 (, number))))
  866.  
  867. (defmacro nntp-header-subject (header)
  868.   "Return subject string in HEADER."
  869.   (` (aref (, header) 1)))
  870.  
  871. (defmacro nntp-set-header-subject (header subject)
  872.   "Set article subject of HEADER to SUBJECT."
  873.   (` (aset (, header) 1 (, subject))))
  874.  
  875. (defmacro nntp-header-from (header)
  876.   "Return author string in HEADER."
  877.   (` (aref (, header) 2)))
  878.  
  879. (defmacro nntp-set-header-from (header from)
  880.   "Set article author of HEADER to FROM."
  881.   (` (aset (, header) 2 (, from))))
  882.  
  883. (defmacro nntp-header-xref (header)
  884.   "Return xref string in HEADER."
  885.   (` (aref (, header) 3)))
  886.  
  887. (defmacro nntp-set-header-xref (header xref)
  888.   "Set article xref of HEADER to xref."
  889.   (` (aset (, header) 3 (, xref))))
  890.  
  891. (defmacro nntp-header-lines (header)
  892.   "Return lines in HEADER."
  893.   (` (aref (, header) 4)))
  894.  
  895. (defmacro nntp-set-header-lines (header lines)
  896.   "Set article lines of HEADER to LINES."
  897.   (` (aset (, header) 4 (, lines))))
  898.  
  899. (defmacro nntp-header-date (header)
  900.   "Return date in HEADER."
  901.   (` (aref (, header) 5)))
  902.  
  903. (defmacro nntp-set-header-date (header date)
  904.   "Set article date of HEADER to DATE."
  905.   (` (aset (, header) 5 (, date))))
  906.  
  907. (defmacro nntp-header-id (header)
  908.   "Return Id in HEADER."
  909.   (` (aref (, header) 6)))
  910.  
  911. (defmacro nntp-set-header-id (header id)
  912.   "Set article Id of HEADER to ID."
  913.   (` (aset (, header) 6 (, id))))
  914.  
  915. (defmacro nntp-header-references (header)
  916.   "Return references in HEADER."
  917.   (` (aref (, header) 7)))
  918.  
  919. (defmacro nntp-set-header-references (header ref)
  920.   "Set article references of HEADER to REF."
  921.   (` (aset (, header) 7 (, ref))))
  922.  
  923.  
  924. ;;;
  925. ;;; GNUS Group Mode
  926. ;;;
  927.  
  928. (if gnus-group-mode-map
  929.     nil
  930.   (setq gnus-group-mode-map (make-keymap))
  931.   (suppress-keymap gnus-group-mode-map)
  932.   (define-key gnus-group-mode-map " " 'gnus-group-read-group)
  933.   (define-key gnus-group-mode-map "=" 'gnus-group-select-group)
  934.   (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group)
  935.   (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group)
  936.   (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group)
  937.   (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group)
  938.   (define-key gnus-group-mode-map "N" 'gnus-group-next-group)
  939.   (define-key gnus-group-mode-map "P" 'gnus-group-prev-group)
  940.   (define-key gnus-group-mode-map "\C-n" 'gnus-group-next-group)
  941.   (define-key gnus-group-mode-map "\C-p" 'gnus-group-prev-group)
  942.   (define-key gnus-group-mode-map [down] 'gnus-group-next-group)
  943.   (define-key gnus-group-mode-map [up] 'gnus-group-prev-group)
  944.   (define-key gnus-group-mode-map "\r" 'next-line)
  945.   ;;(define-key gnus-group-mode-map "/" 'isearch-forward)
  946.   (define-key gnus-group-mode-map "<" 'beginning-of-buffer)
  947.   (define-key gnus-group-mode-map ">" 'end-of-buffer)
  948.   (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group)
  949.   (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group)
  950.   (define-key gnus-group-mode-map "c" 'gnus-group-catchup)
  951.   (define-key gnus-group-mode-map "C" 'gnus-group-catchup-all)
  952.   (define-key gnus-group-mode-map "l" 'gnus-group-list-groups)
  953.   (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups)
  954.   (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news)
  955.   (define-key gnus-group-mode-map "R" 'gnus-group-restart)
  956.   (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups)
  957.   (define-key gnus-group-mode-map "r" 'gnus-group-restrict-groups)
  958.   (define-key gnus-group-mode-map "a" 'gnus-group-post-news)
  959.   (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill)
  960.   (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill)
  961.   (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group)
  962.   (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group)
  963.   (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region)
  964.   (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups)
  965.   (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-list-killed-groups)
  966.   (define-key gnus-group-mode-map "V" 'gnus-version)
  967.   ;;(define-key gnus-group-mode-map "x" 'gnus-group-force-update)
  968.   (define-key gnus-group-mode-map "s" 'gnus-group-force-update)
  969.   (define-key gnus-group-mode-map "z" 'gnus-group-suspend)
  970.   (define-key gnus-group-mode-map "q" 'gnus-group-exit)
  971.   (define-key gnus-group-mode-map "Q" 'gnus-group-quit)
  972.   (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly)
  973.   (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node))
  974.  
  975. (defun gnus-group-mode ()
  976.   "Major mode for reading network news.
  977. All normal editing commands are turned off.
  978. Instead, these commands are available:
  979.  
  980. SPC    Read articles in this newsgroup.
  981. =    Select this newsgroup.
  982. j    Move to the specified newsgroup.
  983. n    Move to the next unread newsgroup.
  984. p    Move to the previous unread newsgroup.
  985. C-n    Move to the next newsgroup.
  986. C-p    Move to the previous newsgroup.
  987. <    Move point to the beginning of this buffer.
  988. >    Move point to the end of this buffer.
  989. u    Unsubscribe from (subscribe to) this newsgroup.
  990. U    Unsubscribe from (subscribe to) the specified newsgroup.
  991. c    Mark all articles as read, preserving marked articles.
  992. C    Mark all articles in this newsgroup as read.
  993. l    Revert this buffer.
  994. L    List all newsgroups.
  995. g    Get new news.
  996. R    Force to read the raw .newsrc file and get new news.
  997. b    Check bogus newsgroups.
  998. r    Restrict visible newsgroups to the current region.
  999. a    Post a new article.
  1000. ESC k    Edit a local KILL file applied to this newsgroup.
  1001. ESC K    Edit a global KILL file applied to all newsgroups.
  1002. C-k    Kill this newsgroup.
  1003. C-y    Yank killed newsgroup here.
  1004. C-w    Kill newsgroups in current region (excluding current point).
  1005. C-x C-t    Exchange this newsgroup and previous newsgroup.
  1006. C-c C-l    list killed newsgroups.
  1007. s    Save .newsrc file.
  1008. z    Suspend reading news.
  1009. q    Quit reading news.
  1010. Q    Quit reading news without saving .newsrc file.
  1011. V    Show the version number of this GNUS.
  1012. ?    Describe Group Mode commands briefly.
  1013. C-h m    Describe Group Mode.
  1014. C-c C-i    Read Info about Group Mode.
  1015.  
  1016.   The name of the host running NNTP server is asked for if no default
  1017. host is specified. It is also possible to choose another NNTP server
  1018. even when the default server is defined by giving a prefix argument to
  1019. the command `\\[gnus]'.
  1020.  
  1021.   If an NNTP server is preceded by a colon such as `:Mail', the user's
  1022. private directory `~/Mail' is used as a news spool. This makes it
  1023. possible to read mail stored in MH folders or articles saved by GNUS.
  1024. File names of mail or articles must consist of only numeric
  1025. characters. Otherwise, they are ignored.
  1026.  
  1027.   If there is a file named `~/.newsrc-SERVER', it is used as the
  1028. startup file instead of standard one when talking to SERVER.  It is
  1029. possible to talk to many hosts by using different startup files for
  1030. each.
  1031.  
  1032.   Option `-n' of the options line in the startup file is recognized
  1033. properly the same as the Bnews system. For example, if the options
  1034. line is `options -n !talk talk.rumors', newsgroups under the `talk'
  1035. hierarchy except for `talk.rumors' are ignored while checking new
  1036. newsgroups.
  1037.  
  1038.   If there is a file named `~/.signature-DISTRIBUTION', it is used as
  1039. signature file instead of standard one when posting a news in
  1040. DISTRIBUTION.
  1041.  
  1042.   If an Info file generated from `gnus.texinfo' is installed, you can
  1043. read an appropriate Info node of the Info file according to the
  1044. current major mode of GNUS by \\[gnus-info-find-node].
  1045.  
  1046.   The variable `gnus-version', `nntp-version', `nnspool-version', and
  1047. `mhspool-version' have the version numbers of this version of gnus.el,
  1048. nntp.el, nnspool.el, and mhspoo.el, respectively.
  1049.  
  1050. User customizable variables:
  1051.  gnus-nntp-server
  1052.     Specifies the name of the host running the NNTP server. If its
  1053.     value is a string such as `:DIRECTORY', the user's private
  1054.     DIRECTORY is used as a news spool.  The variable is initialized
  1055.     from the NNTPSERVER environment variable.
  1056.  
  1057.  gnus-nntp-service
  1058.     Specifies a NNTP service name.  It is usually \"nntp\" or 119.
  1059.     Nil forces GNUS to use a local news spool if the variable
  1060.     `gnus-nntp-server' is set to the local host name.
  1061.  
  1062.  gnus-startup-file
  1063.     Specifies a startup file (.newsrc).  If there is a file named
  1064.     `.newsrc-SERVER', it's used instead when talking to SERVER.  I
  1065.     recommend you to use the server specific file, if you'd like to
  1066.     talk to many servers.  Especially if you'd like to read your
  1067.     private directory, the name of the file must be
  1068.     `.newsrc-:DIRECTORY'.
  1069.  
  1070.  gnus-signature-file
  1071.     Specifies a signature file (.signature).  If there is a file named
  1072.     `.signature-DISTRIBUTION', it's used instead when posting an
  1073.     article in DISTRIBUTION.  Set the variable to nil to prevent
  1074.     appending the file automatically.  If you use an NNTP inews which
  1075.     comes with the NNTP package, you may have to set the variable to
  1076.     nil.
  1077.  
  1078.  gnus-use-cross-reference
  1079.     Specifies what to do with cross references (Xref: field).  If it
  1080.     is nil, cross references are ignored.  If it is t, articles in
  1081.     subscribed newsgroups are only marked as read.  Otherwise, if it
  1082.     is not nil nor t, articles in all newsgroups are marked as read.
  1083.  
  1084.  gnus-use-followup-to
  1085.     Specifies what to do with followup-to: field.  If it is nil, its
  1086.     value is ignored.  If it is non-nil, its value is used as followup
  1087.     newsgroups.  Especially, if it is t and field value is `poster',
  1088.     your confirmation is required.
  1089.  
  1090.  gnus-author-copy
  1091.     Specifies a file name to save a copy of article you posted using
  1092.     FCC: field.  If the first character of the value is `|', the
  1093.     contents of the article is piped out to a program specified by the
  1094.     rest of the value.  The variable is initialized from the
  1095.     AUTHORCOPY environment variable.
  1096.  
  1097.  gnus-author-copy-saver
  1098.     Specifies a function to save an author copy.  The function is
  1099.     called with a file name.  The default function `rmail-output'
  1100.     saves in Unix mail format.
  1101.  
  1102.  gnus-kill-file-name
  1103.     Use specified file name as a KILL file (default to `KILL').
  1104.  
  1105.  gnus-novice-user
  1106.     Non-nil means that you are a novice to USENET.  If non-nil,
  1107.     verbose messages may be displayed or your confirmations may be
  1108.     required.
  1109.  
  1110.  gnus-interactive-post
  1111.     Non-nil means that newsgroup, subject and distribution are asked
  1112.     for interactively when posting a new article.
  1113.  
  1114.  gnus-use-full-window
  1115.     Non-nil means to take up the entire screen of Emacs.
  1116.  
  1117.  gnus-window-configuration
  1118.     Specifies the configuration of Group, Summary, and Article
  1119.     windows.  It is a list of (ACTION (G S A)), where G, S, and A are
  1120.     the relative height of Group, Summary, and Article windows,
  1121.     respectively.  ACTION is `summary', `newsgroups', or `article'.
  1122.  
  1123.  gnus-subscribe-newsgroup-method
  1124.     Specifies a function called with a newsgroup name when new
  1125.     newsgroup is found.  The default definition adds new newsgroup at
  1126.     the beginning of other newsgroups.
  1127.  
  1128.   And more and more.  Please refer to texinfo documentation.
  1129.  
  1130. Various hooks for customization:
  1131.  gnus-group-mode-hook
  1132.     Entry to this mode calls the value with no arguments, if that
  1133.     value is non-nil. This hook is called before GNUS is connected to
  1134.     the NNTP server. So, you can change or define the NNTP server in
  1135.     this hook.
  1136.  
  1137.  gnus-startup-hook
  1138.     Called with no arguments after the NNTP server is selected. It is
  1139.     possible to change the behavior of GNUS or initialize the
  1140.     variables according to the selected NNTP server.
  1141.  
  1142.  gnus-group-prepare-hook
  1143.     Called with no arguments after a newsgroup list is created in the
  1144.     Newsgroup buffer, if that value is non-nil.
  1145.  
  1146.  gnus-save-newsrc-hook
  1147.     Called with no arguments when saving newsrc file if that value is
  1148.     non-nil.
  1149.  
  1150.  gnus-prepare-article-hook
  1151.     Called with no arguments after preparing message body, but before
  1152.     preparing header fields which is automatically generated if that
  1153.     value is non-nil.  The default hook (gnus-inews-insert-signature)
  1154.     inserts a signature file.
  1155.  
  1156.  gnus-inews-article-hook
  1157.     Called with no arguments when posting an article if that value is
  1158.     non-nil.  This hook is called just before posting an article.  The
  1159.     default hook does FCC (save an article to the specified file).
  1160.  
  1161.  gnus-suspend-gnus-hook
  1162.     Called with no arguments when suspending (not exiting) GNUS, if
  1163.     that value is non-nil.
  1164.  
  1165.  gnus-exit-gnus-hook
  1166.     Called with no arguments when exiting (not suspending) GNUS, if
  1167.     that value is non-nil."
  1168.   (interactive)
  1169.   (kill-all-local-variables)
  1170.   ;; Gee.  Why don't you upgrade?
  1171.   (cond ((boundp 'mode-line-modified)
  1172.      (setq mode-line-modified "--- "))
  1173.     ((listp (default-value 'mode-line-format))
  1174.      (setq mode-line-format
  1175.            (cons "--- " (cdr (default-value 'mode-line-format)))))
  1176.     (t
  1177.      (setq mode-line-format
  1178.            "--- GNUS: List of Newsgroups  %[(%m)%]----%3p-%-")))
  1179.   (setq major-mode 'gnus-group-mode)
  1180.   (setq mode-name "Newsgroup")
  1181.   (setq mode-line-buffer-identification    "GNUS: List of Newsgroups")
  1182.   (setq mode-line-process nil)
  1183.   (use-local-map gnus-group-mode-map)
  1184.   (buffer-flush-undo (current-buffer))
  1185.   (setq buffer-read-only t)        ;Disable modification
  1186.   (run-hooks 'gnus-group-mode-hook))
  1187.  
  1188. ;;;###autoload
  1189. (defun gnus (&optional confirm)
  1190.   "Read network news.
  1191. If optional argument CONFIRM is non-nil, ask NNTP server."
  1192.   (interactive "P")
  1193.   (unwind-protect
  1194.       (progn
  1195.     (switch-to-buffer (get-buffer-create gnus-group-buffer))
  1196.     (gnus-group-mode)
  1197.     (gnus-start-news-server confirm))
  1198.     (if (not (gnus-server-opened))
  1199.     (gnus-group-quit)
  1200.       ;; NNTP server is successfully open. 
  1201.       (setq mode-line-process (format " {%s}" gnus-nntp-server))
  1202.       (let ((buffer-read-only nil))
  1203.     (erase-buffer)
  1204.     (gnus-group-startup-message)
  1205.     (sit-for 0))
  1206.       (run-hooks 'gnus-startup-hook)
  1207.       (gnus-setup-news)
  1208.       (if gnus-novice-user
  1209.       (gnus-group-describe-briefly)) ;Show brief help message.
  1210.       (gnus-group-list-groups nil)
  1211.       )))
  1212.  
  1213. (defun gnus-group-startup-message ()
  1214.   "Insert startup message in current buffer."
  1215.   ;; Insert the message.
  1216.   (insert
  1217.    (format "
  1218.                    %s
  1219.  
  1220.          NNTP-based News Reader for GNU Emacs
  1221.  
  1222.  
  1223. If you have any trouble with this software, please let me
  1224. know. I will fix your problems in the next release.
  1225.  
  1226. Comments, suggestions, and bug fixes are welcome.
  1227.  
  1228. Masanobu UMEDA
  1229. umerin@mse.kyutech.ac.jp" gnus-version))
  1230.   ;; And then hack it.
  1231.   ;; 57 is the longest line.
  1232.   (indent-rigidly (point-min) (point-max) (/ (max (- (window-width) 57) 0) 2))
  1233.   (goto-char (point-min))
  1234.   ;; +4 is fuzzy factor.
  1235.   (insert-char ?\n (/ (max (- (window-height) 18) 0) 2)))
  1236.  
  1237. (defun gnus-group-list-groups (show-all)
  1238.   "List newsgroups in the Newsgroup buffer.
  1239. If argument SHOW-ALL is non-nil, unsubscribed groups are also listed."
  1240.   (interactive "P")
  1241.   (let ((case-fold-search nil)
  1242.     (last-group            ;Current newsgroup.
  1243.      (gnus-group-group-name))
  1244.     (next-group            ;Next possible newsgroup.
  1245.      (progn
  1246.        (gnus-group-search-forward nil nil)
  1247.        (gnus-group-group-name)))
  1248.     (prev-group            ;Previous possible newsgroup.
  1249.      (progn
  1250.        (gnus-group-search-forward t nil)
  1251.        (gnus-group-group-name))))
  1252.     (set-buffer gnus-group-buffer)    ;May call from out of Group buffer
  1253.     (gnus-group-prepare show-all)
  1254.     (if (zerop (buffer-size))
  1255.     (message "No news is good news")
  1256.       ;; Go to last newsgroup if possible.  If cannot, try next and
  1257.       ;; previous.  If all fail, go to first unread newsgroup.
  1258.       (goto-char (point-min))
  1259.       (or (and last-group
  1260.            (re-search-forward (gnus-group-make-regexp last-group) nil t))
  1261.       (and next-group
  1262.            (re-search-forward (gnus-group-make-regexp next-group) nil t))
  1263.       (and prev-group
  1264.            (re-search-forward (gnus-group-make-regexp prev-group) nil t))
  1265.       (gnus-group-search-forward nil nil t))
  1266.       ;; Adjust cursor point.
  1267.       (beginning-of-line)
  1268.       (search-forward ":" nil t)
  1269.       )))
  1270.  
  1271. (defun gnus-group-prepare (&optional all)
  1272.   "Prepare list of newsgroups in current buffer.
  1273. If optional argument ALL is non-nil, unsubscribed groups are also listed."
  1274.   (let ((buffer-read-only nil)
  1275.     (newsrc gnus-newsrc-assoc)
  1276.     (group-info nil)
  1277.     (group-name nil)
  1278.     (unread-count 0)
  1279.     ;; This specifies the format of Group buffer.
  1280.     (cntl "%s%s%5d: %s\n"))
  1281.     (erase-buffer)
  1282.     ;; List newsgroups.
  1283.     (while newsrc
  1284.       (setq group-info (car newsrc))
  1285.       (setq group-name (car group-info))
  1286.       (setq unread-count (nth 1 (gnus-gethash group-name gnus-unread-hashtb)))
  1287.       (if (or all
  1288.           (and (nth 1 group-info)    ;Subscribed.
  1289.            (> unread-count 0)))    ;There are unread articles.
  1290.       ;; Yes, I can use gnus-group-prepare-line, but this is faster.
  1291.       (insert
  1292.        (format cntl
  1293.            ;; Subscribed or not.
  1294.            (if (nth 1 group-info) " " "U")
  1295.            ;; Has new news?
  1296.            (if (and (> unread-count 0)
  1297.                 (>= 0
  1298.                 (- unread-count
  1299.                    (length
  1300.                     (cdr (gnus-gethash group-name
  1301.                                gnus-marked-hashtb))))))
  1302.                "*" " ")
  1303.            ;; Number of unread articles.
  1304.            unread-count
  1305.            ;; Newsgroup name.
  1306.            group-name))
  1307.     )
  1308.       (setq newsrc (cdr newsrc))
  1309.       )
  1310.     (setq gnus-have-all-newsgroups all)
  1311.     (goto-char (point-min))
  1312.     (run-hooks 'gnus-group-prepare-hook)
  1313.     ))
  1314.  
  1315. (defun gnus-group-prepare-line (info)
  1316.   "Return a string for the Newsgroup buffer from INFO.
  1317. INFO is an element of gnus-newsrc-assoc or gnus-killed-assoc."
  1318.   (let* ((group-name (car info))
  1319.      (unread-count
  1320.       (or (nth 1 (gnus-gethash group-name gnus-unread-hashtb))
  1321.           ;; Not in hash table, so compute it now.
  1322.           (gnus-number-of-articles
  1323.            (gnus-difference-of-range
  1324.         (nth 2 (gnus-gethash group-name gnus-active-hashtb))
  1325.         (nthcdr 2 info)))))
  1326.      ;; This specifies the format of Group buffer.
  1327.      (cntl "%s%s%5d: %s\n"))
  1328.     (format cntl
  1329.         ;; Subscribed or not.
  1330.         (if (nth 1 info) " " "U")
  1331.         ;; Has new news?
  1332.         (if (and (> unread-count 0)
  1333.              (>= 0
  1334.              (- unread-count
  1335.                 (length
  1336.                  (cdr (gnus-gethash group-name
  1337.                         gnus-marked-hashtb))))))
  1338.         "*" " ")
  1339.         ;; Number of unread articles.
  1340.         unread-count
  1341.         ;; Newsgroup name.
  1342.         group-name
  1343.         )))
  1344.  
  1345. (defun gnus-group-update-group (group &optional visible-only)
  1346.   "Update newsgroup info of GROUP.
  1347. If optional argument VISIBLE-ONLY is non-nil, non displayed group is ignored."
  1348.   (let ((buffer-read-only nil)
  1349.     (case-fold-search nil)        ;appleIIgs vs. appleiigs
  1350.     (regexp (gnus-group-make-regexp group))
  1351.     (visible nil))
  1352.     ;; Buffer may be narrowed.
  1353.     (save-restriction
  1354.       (widen)
  1355.       ;; Search a line to modify.  If the buffer is large, the search
  1356.       ;; takes long time.  In most cases, current point is on the line
  1357.       ;; we are looking for.  So, first of all, check current line. 
  1358.       ;; And then if current point is in the first half, search from
  1359.       ;; the beginning.  Otherwise, search from the end.
  1360.       (if (cond ((progn
  1361.            (beginning-of-line)
  1362.            (looking-at regexp)))
  1363.         ((and (> (/ (buffer-size) 2) (point)) ;In the first half.
  1364.               (progn
  1365.             (goto-char (point-min))
  1366.             (re-search-forward regexp nil t))))
  1367.         ((progn
  1368.            (goto-char (point-max))
  1369.            (re-search-backward regexp nil t))))
  1370.       ;; GROUP is listed in current buffer. So, delete old line.
  1371.       (progn
  1372.         (setq visible t)
  1373.         (beginning-of-line)
  1374.         (delete-region (point) (progn (forward-line 1) (point)))
  1375.         )
  1376.     ;; No such line in the buffer, so insert it at the top.
  1377.     (goto-char (point-min)))
  1378.       (if (or visible (not visible-only))
  1379.       (progn
  1380.         (insert (gnus-group-prepare-line
  1381.              (gnus-gethash group gnus-newsrc-hashtb)))
  1382.         (forward-line -1)        ;Move point on that line.
  1383.         ))
  1384.       )))
  1385.  
  1386. (defun gnus-group-group-name ()
  1387.   "Get newsgroup name around point."
  1388.   (save-excursion
  1389.     (beginning-of-line)
  1390.     (if (looking-at "^.+:[ \t]+\\([^ \t\n]+\\)\\([ \t].*\\|$\\)")
  1391.     (buffer-substring (match-beginning 1) (match-end 1))
  1392.       )))
  1393.  
  1394. (defun gnus-group-make-regexp (newsgroup)
  1395.   "Return regexp that matches for a line of NEWSGROUP."
  1396.   (concat "^.+: " (regexp-quote newsgroup) "\\([ \t].*\\|$\\)"))
  1397.  
  1398. (defun gnus-group-search-forward (backward norest &optional heretoo)
  1399.   "Search for the next (or previous) newsgroup.
  1400. If 1st argument BACKWARD is non-nil, search backward instead.
  1401. If 2nd argument NOREST is non-nil, don't care about newsgroup property.
  1402. If optional argument HERETOO is non-nil, current line is searched for, too."
  1403.   (let ((case-fold-search nil)
  1404.     (func
  1405.      (if backward
  1406.          (function re-search-backward) (function re-search-forward)))
  1407.     (regexp
  1408.      (format "^%s[ \t]*\\(%s\\):"
  1409.          (if norest ".." " [ \t]")
  1410.          (if norest "[0-9]+" "[1-9][0-9]*")))
  1411.     (found nil))
  1412.     (if backward
  1413.     (if heretoo
  1414.         (end-of-line)
  1415.       (beginning-of-line))
  1416.       (if heretoo
  1417.       (beginning-of-line)
  1418.     (end-of-line)))
  1419.     (setq found (funcall func regexp nil t))
  1420.     ;; Adjust cursor point.
  1421.     (beginning-of-line)
  1422.     (search-forward ":" nil t)
  1423.     ;; Return T if found.
  1424.     found
  1425.     ))
  1426.  
  1427. ;; GNUS Group mode command
  1428.  
  1429. (defun gnus-group-read-group (all &optional no-article)
  1430.   "Read news in this newsgroup.
  1431. If argument ALL is non-nil, already read articles become readable.
  1432. If optional argument NO-ARTICLE is non-nil, no article body is displayed."
  1433.   (interactive "P")
  1434.   (let ((group (gnus-group-group-name))) ;Newsgroup name to read.
  1435.     (if group
  1436.     (gnus-summary-read-group
  1437.      group
  1438.      (or all
  1439.          ;;(not (nth 1 (gnus-gethash group gnus-newsrc-hashtb))) ;Unsubscribed
  1440.          (zerop
  1441.           (nth 1 (gnus-gethash group gnus-unread-hashtb))))    ;No unread
  1442.      no-article
  1443.      ))
  1444.     ))
  1445.  
  1446. (defun gnus-group-select-group (all)
  1447.   "Select this newsgroup.
  1448. No article is selected automatically.
  1449. If argument ALL is non-nil, already read articles become readable."
  1450.   (interactive "P")
  1451.   (gnus-group-read-group all t))
  1452.  
  1453. (defun gnus-group-jump-to-group (group)
  1454.   "Jump to newsgroup GROUP."
  1455.   (interactive
  1456.    (list (completing-read "Newsgroup: " gnus-newsrc-assoc nil 'require-match)))
  1457.   (let ((case-fold-search nil))
  1458.     (goto-char (point-min))
  1459.     (or (re-search-forward (gnus-group-make-regexp group) nil t)
  1460.     (if (gnus-gethash group gnus-newsrc-hashtb)
  1461.         ;; Add GROUP entry, then seach again.
  1462.         (gnus-group-update-group group)))
  1463.     ;; Adjust cursor point.
  1464.     (beginning-of-line)
  1465.     (search-forward ":" nil t)
  1466.     ))
  1467.  
  1468. (defun gnus-group-next-group (n)
  1469.   "Go to next N'th newsgroup."
  1470.   (interactive "p")
  1471.   (while (and (> n 1)
  1472.           (gnus-group-search-forward nil t))
  1473.     (setq n (1- n)))
  1474.   (or (gnus-group-search-forward nil t)
  1475.       (message "No more newsgroups")))
  1476.  
  1477. (defun gnus-group-next-unread-group (n)
  1478.   "Go to next N'th unread newsgroup."
  1479.   (interactive "p")
  1480.   (while (and (> n 1)
  1481.           (gnus-group-search-forward nil nil))
  1482.     (setq n (1- n)))
  1483.   (or (gnus-group-search-forward nil nil)
  1484.       (message "No more unread newsgroups")))
  1485.  
  1486. (defun gnus-group-prev-group (n)
  1487.   "Go to previous N'th newsgroup."
  1488.   (interactive "p")
  1489.   (while (and (> n 1)
  1490.           (gnus-group-search-forward t t))
  1491.     (setq n (1- n)))
  1492.   (or (gnus-group-search-forward t t)
  1493.       (message "No more newsgroups")))
  1494.  
  1495. (defun gnus-group-prev-unread-group (n)
  1496.   "Go to previous N'th unread newsgroup."
  1497.   (interactive "p")
  1498.   (while (and (> n 1)
  1499.           (gnus-group-search-forward t nil))          
  1500.     (setq n (1- n)))
  1501.   (or (gnus-group-search-forward t nil)
  1502.       (message "No more unread newsgroups")))
  1503.  
  1504. (defun gnus-group-catchup (all)
  1505.   "Mark all articles not marked as unread in current newsgroup as read.
  1506. If prefix argument ALL is non-nil, all articles are marked as read.
  1507. Cross references (Xref: field) of articles are ignored."
  1508.   (interactive "P")
  1509.   (let* ((group (gnus-group-group-name))
  1510.          (marked (if (not all)
  1511.              (cdr (gnus-gethash group gnus-marked-hashtb)))))
  1512.     (and group
  1513.      (or (not gnus-interactive-catchup) ;Without confirmation?
  1514.          (y-or-n-p
  1515.           (if all
  1516.           "Do you really want to mark everything as read? "
  1517.         "Delete all articles not marked as read? ")))
  1518.      (progn
  1519.        (message "")            ;Clear "Yes or No" question.
  1520.        ;; Any marked articles will be preserved.
  1521.        (gnus-update-unread-articles group marked marked)
  1522.        (gnus-group-update-group group)
  1523.        (gnus-group-next-group 1)))
  1524.     ))
  1525.  
  1526. (defun gnus-group-catchup-all ()
  1527.   "Mark all articles in current newsgroup as read.
  1528. Cross references (Xref: field) of articles are ignored."
  1529.   (interactive)
  1530.   (gnus-group-catchup t))
  1531.  
  1532. (defun gnus-group-unsubscribe-current-group ()
  1533.   "Toggle subscribe from/to unsubscribe current group."
  1534.   (interactive)
  1535.   (let ((group (gnus-group-group-name)))
  1536.     (if group
  1537.      (progn
  1538.        (gnus-group-unsubscribe-group group)
  1539.        (gnus-group-next-group 1))
  1540.       (message "No Newsgroup found to \(un\)subscribe"))))
  1541.  
  1542. (defun gnus-group-unsubscribe-group (group)
  1543.   "Toggle subscribe from/to unsubscribe GROUP.
  1544. New newsgroup is added to .newsrc automatically."
  1545.   (interactive
  1546.    (list (completing-read "Newsgroup: "
  1547.               gnus-active-hashtb nil 'require-match)))
  1548.   (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
  1549.     (cond ((not (null newsrc))
  1550.        ;; Toggle subscription flag.
  1551.        (setcar (nthcdr 1 newsrc) (not (nth 1 newsrc)))
  1552.        (gnus-update-newsrc-buffer group)
  1553.        (gnus-group-update-group group)
  1554.        ;; Adjust cursor point.
  1555.        (beginning-of-line)
  1556.        (search-forward ":" nil t))
  1557.       ((and (stringp group)
  1558.         (gnus-gethash group gnus-active-hashtb))
  1559.        ;; Add new newsgroup.
  1560.        (gnus-add-newsgroup group)
  1561.        (gnus-group-update-group group)
  1562.        ;; Adjust cursor point.
  1563.        (beginning-of-line)
  1564.        (search-forward ":" nil t))
  1565.       (t (error "No such newsgroup: %s" group)))
  1566.     ))
  1567.  
  1568. (defun gnus-group-list-all-groups ()
  1569.   "List all of newsgroups in the Newsgroup buffer."
  1570.   (interactive)
  1571.   (message "Listing all groups...")
  1572.   (gnus-group-list-groups t)
  1573.   (message "Listing all groups...done"))
  1574.  
  1575. (defun gnus-group-get-new-news ()
  1576.   "Get newly arrived articles. In fact, read the active file again."
  1577.   (interactive)
  1578.   (gnus-setup-news)
  1579.   (gnus-group-list-groups gnus-have-all-newsgroups))
  1580.  
  1581. (defun gnus-group-restart ()
  1582.   "Force GNUS to read the raw startup file."
  1583.   (interactive)
  1584.   (gnus-save-newsrc-file)
  1585.   (gnus-setup-news t)            ;Force to read the raw startup file.
  1586.   (gnus-group-list-groups gnus-have-all-newsgroups))
  1587.  
  1588. (defun gnus-group-check-bogus-groups ()
  1589.   "Check bogus newsgroups."
  1590.   (interactive)
  1591.   (gnus-check-bogus-newsgroups t)    ;Require confirmation.
  1592.   (gnus-group-list-groups gnus-have-all-newsgroups))
  1593.  
  1594. (defun gnus-group-restrict-groups (start end)
  1595.   "Restrict visible newsgroups to the current region (START and END).
  1596. Type \\[widen] to remove restriction."
  1597.   (interactive "r")
  1598.   (save-excursion
  1599.     (narrow-to-region (progn
  1600.             (goto-char start)
  1601.             (beginning-of-line)
  1602.             (point))
  1603.               (progn
  1604.             (goto-char end)
  1605.             (forward-line 1)
  1606.             (point))))
  1607.   (message (substitute-command-keys "Type \\[widen] to remove restriction")))
  1608.  
  1609. (defun gnus-group-edit-global-kill ()
  1610.   "Edit a global KILL file."
  1611.   (interactive)
  1612.   (setq gnus-current-kill-article nil)    ;No articles selected.
  1613.   (gnus-kill-file-edit-file nil)     ;Nil stands for global KILL file.
  1614.   (message
  1615.    (substitute-command-keys
  1616.     "Editing a global KILL file (Type \\[gnus-kill-file-exit] to exit)")))
  1617.  
  1618. (defun gnus-group-edit-local-kill ()
  1619.   "Edit a local KILL file."
  1620.   (interactive)
  1621.   (setq gnus-current-kill-article nil)    ;No articles selected.
  1622.   (gnus-kill-file-edit-file (gnus-group-group-name))
  1623.   (message
  1624.    (substitute-command-keys
  1625.     "Editing a local KILL file (Type \\[gnus-kill-file-exit] to exit)")))
  1626.  
  1627. (defun gnus-group-force-update ()
  1628.   "Update .newsrc file."
  1629.   (interactive)
  1630.   (gnus-save-newsrc-file))
  1631.  
  1632. (defun gnus-group-suspend ()
  1633.   "Suspend the current GNUS session.
  1634. In fact, cleanup buffers except for Group Mode buffer.
  1635. The hook gnus-suspend-gnus-hook is called before actually suspending."
  1636.   (interactive)
  1637.   (run-hooks 'gnus-suspend-gnus-hook)
  1638.   ;; Kill GNUS buffers except for Group Mode buffer.
  1639.   (let ((buffers gnus-buffer-list))
  1640.     (while buffers
  1641.       (and (not (eq (car buffers) gnus-group-buffer))
  1642.        (get-buffer (car buffers))
  1643.        (kill-buffer (car buffers)))
  1644.       (setq buffers (cdr buffers))
  1645.       ))
  1646.   (bury-buffer))
  1647.  
  1648. (defun gnus-group-exit ()
  1649.   "Quit reading news after updating .newsrc.
  1650. The hook gnus-exit-gnus-hook is called before actually quitting."
  1651.   (interactive)
  1652.   (if (or noninteractive        ;For gnus-batch-kill
  1653.       (zerop (buffer-size))        ;No news is good news.
  1654.       (not (gnus-server-opened))    ;NNTP connection closed.
  1655.       (not gnus-interactive-exit)    ;Without confirmation
  1656.       (y-or-n-p "Are you sure you want to quit reading news? "))
  1657.       (progn
  1658.     (message "")            ;Erase "Yes or No" question.
  1659.     (run-hooks 'gnus-exit-gnus-hook)
  1660.     (gnus-save-newsrc-file)
  1661.     (gnus-clear-system)
  1662.     (gnus-close-server))
  1663.     ))
  1664.  
  1665. (defun gnus-group-quit ()
  1666.   "Quit reading news without updating .newsrc.
  1667. The hook gnus-exit-gnus-hook is called before actually quitting."
  1668.   (interactive)
  1669.   (if (or noninteractive        ;For gnus-batch-kill
  1670.       (zerop (buffer-size))
  1671.       (not (gnus-server-opened))
  1672.       (yes-or-no-p
  1673.        (format "Quit reading news without saving %s? "
  1674.            (file-name-nondirectory gnus-current-startup-file))))
  1675.       (progn
  1676.     (message "")            ;Erase "Yes or No" question.
  1677.     (run-hooks 'gnus-exit-gnus-hook)
  1678.     (gnus-clear-system)
  1679.     (gnus-close-server))
  1680.     ))
  1681.  
  1682. (defun gnus-group-describe-briefly ()
  1683.   "Describe Group mode commands briefly."
  1684.   (interactive)
  1685.   (message
  1686.    (concat
  1687.     (substitute-command-keys "\\[gnus-group-read-group]:Select  ")
  1688.     (substitute-command-keys "\\[gnus-group-next-unread-group]:Forward  ")
  1689.     (substitute-command-keys "\\[gnus-group-prev-unread-group]:Backward  ")
  1690.     (substitute-command-keys "\\[gnus-group-exit]:Exit  ")
  1691.     (substitute-command-keys "\\[gnus-info-find-node]:Run Info  ")
  1692.     (substitute-command-keys "\\[gnus-group-describe-briefly]:This help")
  1693.     )))
  1694.  
  1695.  
  1696. ;;;
  1697. ;;; GNUS Summary Mode
  1698. ;;;
  1699.  
  1700. (if gnus-summary-mode-map
  1701.     nil
  1702.   (setq gnus-summary-mode-map (make-keymap))
  1703.   (suppress-keymap gnus-summary-mode-map)
  1704.   (define-key gnus-summary-mode-map "\C-c\C-v" 'gnus-uu-ctl-map)
  1705.   (define-key gnus-summary-mode-map "#" 'gnus-uu-mark-article)
  1706.   (define-key gnus-summary-mode-map " " 'gnus-summary-next-page)
  1707.   (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page)
  1708.   (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up)
  1709.   (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article)
  1710.   (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article)
  1711.   (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article)
  1712.   (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article)
  1713.   (define-key gnus-summary-mode-map "\e\C-n" 'gnus-summary-next-same-subject)
  1714.   (define-key gnus-summary-mode-map "\e\C-p" 'gnus-summary-prev-same-subject)
  1715.   ;;(define-key gnus-summary-mode-map "\e\C-n" 'gnus-summary-next-unread-same-subject)
  1716.   ;;(define-key gnus-summary-mode-map "\e\C-p" 'gnus-summary-prev-unread-same-subject)
  1717.   (define-key gnus-summary-mode-map "\C-c\C-n" 'gnus-summary-next-digest)
  1718.   (define-key gnus-summary-mode-map "\C-c\C-p" 'gnus-summary-prev-digest)
  1719.   (define-key gnus-summary-mode-map "\C-n" 'gnus-summary-next-subject)
  1720.   (define-key gnus-summary-mode-map "\C-p" 'gnus-summary-prev-subject)
  1721.   (define-key gnus-summary-mode-map [down] 'gnus-summary-next-subject)
  1722.   (define-key gnus-summary-mode-map [up] 'gnus-summary-prev-subject)
  1723.   (define-key gnus-summary-mode-map "\en" 'gnus-summary-next-unread-subject)
  1724.   (define-key gnus-summary-mode-map "\ep" 'gnus-summary-prev-unread-subject)
  1725.   ;;(define-key gnus-summary-mode-map "\C-cn" 'gnus-summary-next-group)
  1726.   ;;(define-key gnus-summary-mode-map "\C-cp" 'gnus-summary-prev-group)
  1727.   (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article)
  1728.   ;;(define-key gnus-summary-mode-map "/" 'isearch-forward)
  1729.   (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article)
  1730.   (define-key gnus-summary-mode-map "\es" 'gnus-summary-search-article-forward)
  1731.   ;;(define-key gnus-summary-mode-map "\eS" 'gnus-summary-search-article-backward)
  1732.   (define-key gnus-summary-mode-map "\er" 'gnus-summary-search-article-backward)
  1733.   (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article)
  1734.   (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article)
  1735.   (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-subject)
  1736.   ;;(define-key gnus-summary-mode-map "J" 'gnus-summary-goto-article)
  1737.   (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article)
  1738.   (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article)
  1739.   ;;(define-key gnus-summary-mode-map "\er" 'gnus-summary-refer-article)
  1740.   (define-key gnus-summary-mode-map "\e^" 'gnus-summary-refer-article)
  1741.   (define-key gnus-summary-mode-map "u" 'gnus-summary-mark-as-unread-forward)
  1742.   (define-key gnus-summary-mode-map "U" 'gnus-summary-mark-as-unread-backward)
  1743.   (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward)
  1744.   (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward)
  1745.   (define-key gnus-summary-mode-map "\eu" 'gnus-summary-clear-mark-forward)
  1746.   (define-key gnus-summary-mode-map "\eU" 'gnus-summary-clear-mark-backward)
  1747.   (define-key gnus-summary-mode-map "k" 'gnus-summary-kill-same-subject-and-select)
  1748.   (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject)
  1749.   (define-key gnus-summary-mode-map "\e\C-t" 'gnus-summary-toggle-threads)
  1750.   (define-key gnus-summary-mode-map "\e\C-s" 'gnus-summary-show-thread)
  1751.   (define-key gnus-summary-mode-map "\e\C-h" 'gnus-summary-hide-thread)
  1752.   (define-key gnus-summary-mode-map "\e\C-f" 'gnus-summary-next-thread)
  1753.   (define-key gnus-summary-mode-map "\e\C-b" 'gnus-summary-prev-thread)
  1754.   (define-key gnus-summary-mode-map "\e\C-u" 'gnus-summary-up-thread)
  1755.   (define-key gnus-summary-mode-map "\e\C-d" 'gnus-summary-down-thread)
  1756.   (define-key gnus-summary-mode-map "\e\C-k" 'gnus-summary-kill-thread)
  1757.   (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command)
  1758.   ;;(define-key gnus-summary-mode-map "c" 'gnus-summary-catchup)
  1759.   ;;(define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-all)
  1760.   (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit)
  1761.   ;;(define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-all-and-exit)
  1762.   (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation)
  1763.   (define-key gnus-summary-mode-map "x" 'gnus-summary-delete-marked-as-read)
  1764.   (define-key gnus-summary-mode-map "X" 'gnus-summary-delete-marked-with)
  1765.   (define-key gnus-summary-mode-map "\C-c\C-sn" 'gnus-summary-sort-by-number)
  1766.   (define-key gnus-summary-mode-map "\C-c\C-sa" 'gnus-summary-sort-by-author)
  1767.   (define-key gnus-summary-mode-map "\C-c\C-ss" 'gnus-summary-sort-by-subject)
  1768.   (define-key gnus-summary-mode-map "\C-c\C-sd" 'gnus-summary-sort-by-date)
  1769.   (define-key gnus-summary-mode-map "\C-c\C-s\C-n" 'gnus-summary-sort-by-number)
  1770.   (define-key gnus-summary-mode-map "\C-c\C-s\C-a" 'gnus-summary-sort-by-author)
  1771.   (define-key gnus-summary-mode-map "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject)
  1772.   (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date)
  1773.   (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window)
  1774.   ;;(define-key gnus-summary-mode-map "G" 'gnus-summary-reselect-current-group)
  1775.   (define-key gnus-summary-mode-map "\C-x\C-s" 'gnus-summary-reselect-current-group)
  1776.   (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking)
  1777.   (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message)
  1778.   (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article)
  1779.   (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header)
  1780.   ;;(define-key gnus-summary-mode-map "v" 'gnus-summary-show-all-headers)
  1781.   (define-key gnus-summary-mode-map "\et" 'gnus-summary-toggle-mime)
  1782.   (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-rmail-digest)
  1783.   (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news)
  1784.   (define-key gnus-summary-mode-map "f" 'gnus-summary-followup)
  1785.   (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original)
  1786.   (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article)
  1787.   (define-key gnus-summary-mode-map "r" 'gnus-summary-reply)
  1788.   (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original)
  1789.   (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward)
  1790.   (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window)
  1791.   (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article)
  1792.   (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-in-mail)
  1793.   (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output)
  1794.   (define-key gnus-summary-mode-map "\ek" 'gnus-summary-edit-local-kill)
  1795.   (define-key gnus-summary-mode-map "\eK" 'gnus-summary-edit-global-kill)
  1796.   (define-key gnus-summary-mode-map "V" 'gnus-version)
  1797.   (define-key gnus-summary-mode-map "q" 'gnus-summary-exit)
  1798.   (define-key gnus-summary-mode-map "Q" 'gnus-summary-quit)
  1799.   (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly)
  1800.   (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node))
  1801.  
  1802. (defun gnus-summary-mode ()
  1803.   "Major mode for reading articles in this newsgroup.
  1804. All normal editing commands are turned off.
  1805. Instead, these commands are available:
  1806.  
  1807. SPC    Scroll to the next page of the current article.  The next unread
  1808.     article is selected automatically at the end of the message.
  1809. DEL    Scroll to the previous page of the current article.
  1810. RET    Scroll up (or down) one line the current article.
  1811. n    Move to the next unread article.
  1812. p    Move to the previous unread article.
  1813. N    Move to the next article.
  1814. P    Move to the previous article.
  1815. ESC C-n    Move to the next article which has the same subject as the
  1816.     current article.
  1817. ESC C-p    Move to the previous article which has the same subject as the
  1818.     current article.
  1819. \\[gnus-summary-next-unread-same-subject]
  1820.     Move to the next unread article which has the same subject as the
  1821.     current article.
  1822. \\[gnus-summary-prev-unread-same-subject]
  1823.     Move to the previous unread article which has the same subject as
  1824.     the current article.
  1825. C-c C-n    Scroll to the next digested message of the current article.
  1826. C-c C-p    Scroll to the previous digested message of the current article.
  1827. C-n    Move to the next subject.
  1828. C-p    Move to the previous subject.
  1829. ESC n    Move to the next unread subject.
  1830. ESC p    Move to the previous unread subject.
  1831. \\[gnus-summary-next-group]
  1832.     Exit the current newsgroup and select the next unread newsgroup.
  1833. \\[gnus-summary-prev-group]
  1834.     Exit the current newsgroup and select the previous unread newsgroup.
  1835. .    Jump to the first unread article in the current newsgroup.
  1836. s    Do an incremental search forward on the current article.
  1837. ESC s    Search for an article containing a regexp forward.
  1838. ESC r    Search for an article containing a regexp backward.
  1839. <    Move point to the beginning of the current article.
  1840. >    Move point to the end of the current article.
  1841. j    Jump to the article specified by the numeric article ID.
  1842. l    Jump to the article you read last.
  1843. ^    Refer to parent of the current article.
  1844. ESC ^    Refer to the article specified by the Message-ID.
  1845. u    Mark the current article as unread, and go forward.
  1846. U    Mark the current article as unread, and go backward.
  1847. d    Mark the current article as read, and go forward.
  1848. D    Mark the current article as read, and go backward.
  1849. ESC u    Clear the current article's mark, and go forward.
  1850. ESC U    Clear the current article's mark, and go backward.
  1851. k    Mark articles which has the same subject as the current article as
  1852.     read, and then select the next unread article.
  1853. C-k    Mark articles which has the same subject as the current article as
  1854.     read.
  1855. ESC k    Edit a local KILL file applied to the current newsgroup.
  1856. ESC K    Edit a global KILL file applied to all newsgroups.
  1857. ESC C-t    Toggle showing conversation threads.
  1858. ESC C-s    Show thread subtrees.
  1859. ESC C-h    Hide thread subtrees.
  1860. \\[gnus-summary-show-all-threads]    Show all thread subtrees.
  1861. \\[gnus-summary-hide-all-threads]    Hide all thread subtrees.
  1862. ESC C-f    Go to the same level next thread.
  1863. ESC C-b    Go to the same level previous thread.
  1864. ESC C-d    Go downward current thread.
  1865. ESC C-u    Go upward current thread.
  1866. ESC C-k    Mark articles under current thread as read.
  1867. &    Execute a command for each article conditionally.
  1868. \\[gnus-summary-catchup]
  1869.     Mark all articles as read in the current newsgroup, preserving
  1870.     articles marked as unread.
  1871. \\[gnus-summary-catchup-all]
  1872.     Mark all articles as read in the current newsgroup.
  1873. \\[gnus-summary-catchup-and-exit]
  1874.     Catch up all articles not marked as unread, and then exit the
  1875.     current newsgroup.
  1876. \\[gnus-summary-catchup-all-and-exit]
  1877.     Catch up all articles, and then exit the current newsgroup.
  1878. C-t    Toggle truncations of subject lines.
  1879. x    Delete subject lines marked as read.
  1880. X    Delete subject lines with the specific marks.
  1881. C-c C-s C-n    Sort subjects by article number.
  1882. C-c C-s C-a    Sort subjects by article author.
  1883. C-c C-s C-s    Sort subjects alphabetically.
  1884. C-c C-s C-d    Sort subjects by date.
  1885. =    Expand Summary window to show headers full window.
  1886. C-x C-s    Reselect the current newsgroup. Prefix argument means to select all.
  1887. w    Stop page breaking by linefeed.
  1888. C-c C-r    Caesar rotates letters by 13/47 places.
  1889. g    Force to show the current article.
  1890. t    Show original article header if pruned header currently shown, or
  1891.     vice versa.
  1892. ESC-t    Toggle MIME processing.
  1893. C-d    Run RMAIL on the current digest article.
  1894. a    Post a new article.
  1895. f    Post a reply article.
  1896. F    Post a reply article with original article.
  1897. C    Cancel the current article.
  1898. r    Mail a message to the author.
  1899. R    Mail a message to the author with original author.
  1900. C-c C-f    Forward the current message to another user.
  1901. m    Mail a message in other window.
  1902. o    Save the current article in your favorite format.
  1903. C-o    Append the current article to a file in Unix mail format.
  1904. |    Pipe the contents of the current article to a subprocess.
  1905. q    Quit reading news in the current newsgroup.
  1906. Q    Quit reading news without recording unread articles information.
  1907. V    Show the version number of this GNUS.
  1908. ?    Describe Summary mode commands briefly.
  1909. C-h m    Describe Summary mode.
  1910. C-c C-i    Read Info about Summary mode.
  1911.  
  1912. User customizable variables:
  1913.  gnus-large-newsgroup
  1914.     The number of articles which indicates a large newsgroup. If the
  1915.     number of articles in a newsgroup is greater than the value, the
  1916.     number of articles to be selected is asked for. If the given value
  1917.     N is positive, the last N articles is selected. If N is negative,
  1918.     the first N articles are selected. An empty string means to select
  1919.     all articles.
  1920.  
  1921.  gnus-use-long-file-name
  1922.     Non-nil means that a newsgroup name is used as a default file name
  1923.     to save articles to. If it's nil, the directory form of a
  1924.     newsgroup is used instead.
  1925.  
  1926.  gnus-default-article-saver
  1927.     Specifies your favorite article saver which is interactively
  1928.     funcallable. Following functions are available:
  1929.  
  1930.     gnus-summary-save-in-rmail (in Rmail format)
  1931.     gnus-summary-save-in-mail (in Unix mail format)
  1932.     gnus-summary-save-in-folder (in MH folder)
  1933.     gnus-summary-save-in-file (in article format).
  1934.  
  1935.  gnus-rmail-save-name
  1936.  gnus-mail-save-name
  1937.  gnus-folder-save-name
  1938.  gnus-file-save-name
  1939.     Specifies a function generating a file name to save articles in
  1940.     specified format.  The function is called with NEWSGROUP, HEADERS,
  1941.     and optional LAST-FILE.  Access macros to the headers are defined
  1942.     as nntp-header-FIELD, and functions are defined as
  1943.     gnus-header-FIELD.
  1944.  
  1945.  gnus-article-save-directory
  1946.     Specifies a directory name to save articles to using the commands
  1947.     gnus-summary-save-in-rmail, gnus-summary-save-in-mail and
  1948.     gnus-summary-save-in-file. The variable is initialized from the
  1949.     SAVEDIR environment variable.
  1950.  
  1951.  gnus-show-all-headers
  1952.     Non-nil means that all headers of an article are shown.
  1953.  
  1954.  gnus-save-all-headers
  1955.     Non-nil means that all headers of an article are saved in a file.
  1956.  
  1957.  gnus-show-mime
  1958.     Non-nil means that show a MIME message.
  1959.  
  1960.  gnus-show-threads
  1961.     Non-nil means that conversation threads are shown in tree structure.
  1962.  
  1963.  gnus-thread-hide-subject
  1964.     Non-nil means that subjects for thread subtrees are hidden.
  1965.  
  1966.  gnus-thread-hide-subtree
  1967.     Non-nil means that thread subtrees are hidden initially.
  1968.  
  1969.  gnus-thread-hide-killed
  1970.     Non-nil means that killed thread subtrees are hidden automatically.
  1971.  
  1972.  gnus-thread-ignore-subject
  1973.     Non-nil means that subject differences are ignored in constructing
  1974.     thread trees.
  1975.  
  1976.  gnus-thread-indent-level
  1977.     Indentation of thread subtrees.
  1978.  
  1979.  gnus-optional-headers
  1980.     Specifies a function which generates an optional string displayed
  1981.     in the Summary buffer. The function is called with an article
  1982.     HEADERS.  The result must be a string excluding `[' and `]'.  The
  1983.     default function returns a string like NNN:AUTHOR, where NNN is
  1984.     the number of lines in an article and AUTHOR is the name of the
  1985.     author.
  1986.  
  1987.  gnus-auto-extend-newsgroup
  1988.     Non-nil means visible articles are extended to forward and
  1989.     backward automatically if possible.
  1990.  
  1991.  gnus-auto-select-first
  1992.     Non-nil means the first unread article is selected automagically
  1993.     when a newsgroup is selected normally (by gnus-group-read-group).
  1994.     If you'd like to prevent automatic selection of the first unread
  1995.     article in some newsgroups, set the variable to nil in
  1996.     gnus-select-group-hook or gnus-apply-kill-hook.
  1997.  
  1998.  gnus-auto-select-next
  1999.     Non-nil means the next newsgroup is selected automagically at the
  2000.     end of the newsgroup. If the value is t and the next newsgroup is
  2001.     empty (no unread articles), GNUS will exit Summary mode and go
  2002.     back to Group mode. If the value is neither nil nor t, GNUS won't
  2003.     exit Summary mode but select the following unread newsgroup.
  2004.     Especially, if the value is the symbol `quietly', the next unread
  2005.     newsgroup will be selected without any confirmations.
  2006.  
  2007.  gnus-auto-select-same
  2008.     Non-nil means an article with the same subject as the current
  2009.     article is selected automagically like `rn -S'.
  2010.  
  2011.  gnus-auto-center-summary
  2012.     Non-nil means the point of Summary Mode window is always kept
  2013.     centered.
  2014.  
  2015.  gnus-break-pages
  2016.     Non-nil means an article is broken into pages at page delimiters.
  2017.     This may not work with some versions of GNU Emacs earlier than
  2018.     version 18.50.
  2019.  
  2020.  gnus-page-delimiter
  2021.     Specifies a regexp describing line-beginnings that separate pages
  2022.     of news article.
  2023.  
  2024.  [gnus-more-message is obsolete.  overlay-arrow-string interfares
  2025.     with other subsystems, such as dbx mode.]
  2026.  
  2027.  gnus-digest-show-summary
  2028.     Non-nil means that a summary of digest messages is shown when
  2029.     reading a digest article using `gnus-summary-rmail-digest'
  2030.     command.
  2031.  
  2032.  gnus-digest-separator
  2033.     Specifies a regexp separating messages in a digest article.
  2034.  
  2035.  gnus-mail-reply-method
  2036.  gnus-mail-other-window-method
  2037.     Specifies a function to begin composing mail message using
  2038.     commands gnus-summary-reply and gnus-summary-mail-other-window.
  2039.     Functions gnus-mail-reply-using-mail and gnus-mail-reply-using-mhe
  2040.     are available for the value of gnus-mail-reply-method.  And
  2041.     functions gnus-mail-other-window-using-mail and
  2042.     gnus-mail-other-window-using-mhe are available for the value of
  2043.     gnus-mail-other-window-method.
  2044.  
  2045.  gnus-mail-send-method
  2046.     Specifies a function to mail a message too which is being posted
  2047.     as an article.  The message must have To: or Cc: field.  The value
  2048.     of the variable send-mail-function is the default function which
  2049.     uses sendmail mail program.
  2050.  
  2051. Various hooks for customization:
  2052.  gnus-summary-mode-hook
  2053.     Entry to this mode calls the value with no arguments, if that
  2054.     value is non-nil.
  2055.  
  2056.  gnus-select-group-hook
  2057.     Called with no arguments when newsgroup is selected, if that value
  2058.     is non-nil. It is possible to sort subjects in this hook. See the
  2059.     documentation of this variable for more information.
  2060.  
  2061.  gnus-summary-prepare-hook
  2062.     Called with no arguments after a summary list is created in the
  2063.     Summary buffer, if that value is non-nil. If you'd like to modify
  2064.     the buffer, you can use this hook.
  2065.  
  2066.  gnus-select-article-hook
  2067.     Called with no arguments when an article is selected, if that
  2068.     value is non-nil. See the documentation of this variable for more
  2069.     information.
  2070.  
  2071.  gnus-select-digest-hook
  2072.     Called with no arguments when reading digest messages using Rmail,
  2073.     if that value is non-nil. This hook can be used to modify an
  2074.     article so that Rmail can work with it. See the documentation of
  2075.     the variable for more information.
  2076.  
  2077.  gnus-rmail-digest-hook
  2078.     Called with no arguments when reading digest messages using Rmail,
  2079.     if that value is non-nil. This hook is intended to customize Rmail
  2080.     mode.
  2081.  
  2082.  gnus-apply-kill-hook
  2083.     Called with no arguments when a newsgroup is selected and the
  2084.     Summary buffer is prepared. This hook is intended to apply a KILL
  2085.     file to the selected newsgroup. The format of KILL file is
  2086.     completely different from that of version 3.8. You have to rewrite
  2087.     them in the new format. See the documentation of Kill file mode
  2088.     for more information.
  2089.  
  2090.  gnus-mark-article-hook
  2091.     Called with no arguments when an article is selected at the first
  2092.     time. The hook is intended to mark an article as read (or unread)
  2093.     automatically when it is selected.  See the documentation of the
  2094.     variable for more information.
  2095.  
  2096.  gnus-exit-group-hook
  2097.     Called with no arguments when exiting the current newsgroup, if
  2098.     that value is non-nil. If your machine is so slow that exiting
  2099.     from Summary mode takes very long time, inhibit marking articles
  2100.     as read using cross-references by setting the variable
  2101.     gnus-use-cross-reference to nil in this hook."
  2102.   (interactive)
  2103.   (kill-all-local-variables)
  2104.   ;; Gee.  Why don't you upgrade?
  2105.   (cond ((boundp 'mode-line-modified)
  2106.      (setq mode-line-modified "--- "))
  2107.     ((listp (default-value 'mode-line-format))
  2108.      (setq mode-line-format
  2109.            (cons "--- " (cdr (default-value 'mode-line-format))))))
  2110.   ;; To disable display-time facility.
  2111.   ;;(make-local-variable 'global-mode-string)
  2112.   ;;(setq global-mode-string nil)
  2113.   (setq major-mode 'gnus-summary-mode)
  2114.   (setq mode-name "Summary")
  2115.   ;;(setq mode-line-process '(" " gnus-newsgroup-name))
  2116.   (make-local-variable 'minor-mode-alist)
  2117.   (or (assq 'gnus-show-threads minor-mode-alist)
  2118.       (setq minor-mode-alist
  2119.         (cons (list 'gnus-show-threads " Thread") minor-mode-alist)))
  2120.   (gnus-summary-set-mode-line)
  2121.   (use-local-map gnus-summary-mode-map)
  2122.   (buffer-flush-undo (current-buffer))
  2123.   (setq buffer-read-only t)        ;Disable modification
  2124.   (setq truncate-lines t)        ;Stop line folding
  2125.   (setq selective-display t)
  2126.   (setq selective-display-ellipses t)    ;Display `...'
  2127.   ;;(setq case-fold-search t)
  2128.   (run-hooks 'gnus-summary-mode-hook))
  2129.  
  2130. (defun gnus-summary-setup-buffer ()
  2131.   "Initialize Summary buffer."
  2132.   (if (get-buffer gnus-summary-buffer)
  2133.       (set-buffer gnus-summary-buffer)
  2134.     (set-buffer (get-buffer-create gnus-summary-buffer))
  2135.     (gnus-summary-mode)
  2136.     ))
  2137.  
  2138. (defun gnus-summary-read-group (group &optional show-all no-article)
  2139.   "Start reading news in newsgroup GROUP.
  2140. If optional 1st argument SHOW-ALL is non-nil, already read articles are
  2141. also listed.
  2142. If optional 2nd argument NO-ARTICLE is non-nil, no article is selected
  2143. initially."
  2144.   (message "Retrieving newsgroup: %s..." group)
  2145.   (if (gnus-select-newsgroup group show-all)
  2146.       (progn
  2147.     ;; Don't switch-to-buffer to prevent displaying old contents
  2148.     ;;  of the buffer until new subjects list is created.
  2149.     ;; Suggested by Juha Heinanen <jh@tut.fi>
  2150.     (gnus-summary-setup-buffer)
  2151.     ;; You can change the order of subjects in this hook.
  2152.     (run-hooks 'gnus-select-group-hook)
  2153.     (gnus-summary-prepare)
  2154.     ;; Function `gnus-apply-kill-file' must be called in this hook.
  2155.     (run-hooks 'gnus-apply-kill-hook)
  2156.     (if (zerop (buffer-size))
  2157.         ;; This newsgroup is empty.
  2158.         (progn
  2159.           (gnus-summary-catchup-and-exit nil t) ;Without confirmations.
  2160.           (message "No unread news"))
  2161.       ;; Hide conversation thread subtrees.  We cannot do this in
  2162.       ;; gnus-summary-prepare-hook since kill processing may not
  2163.       ;; work with hidden articles.
  2164.       (and gnus-show-threads
  2165.            gnus-thread-hide-subtree
  2166.            (gnus-summary-hide-all-threads))
  2167.       ;; Show first unread article if requested.
  2168.       (goto-char (point-min))
  2169.       (if (and (not no-article)
  2170.            gnus-auto-select-first
  2171.            (gnus-summary-first-unread-article))
  2172.           ;; Window is configured automatically.
  2173.           ;; Current buffer may be changed as a result of hook
  2174.           ;; evaluation, especially by gnus-summary-rmail-digest
  2175.           ;; command, so we should adjust cursor point carefully.
  2176.           (if (eq (current-buffer) (get-buffer gnus-summary-buffer))
  2177.           (progn
  2178.             ;; Adjust cursor point.
  2179.             (beginning-of-line)
  2180.             (search-forward ":" nil t)))
  2181.         (gnus-configure-windows 'summary)
  2182.         (pop-to-buffer gnus-summary-buffer)
  2183.         (gnus-summary-set-mode-line)
  2184.         ;; I sometime get confused with the old Article buffer.
  2185.         (if (get-buffer gnus-article-buffer)
  2186.         (if (get-buffer-window gnus-article-buffer)
  2187.             (save-excursion
  2188.               (set-buffer gnus-article-buffer)
  2189.               (let ((buffer-read-only nil))
  2190.             (erase-buffer)))
  2191.           (kill-buffer gnus-article-buffer)))
  2192.         ;; Adjust cursor point.
  2193.         (beginning-of-line)
  2194.         (search-forward ":" nil t))
  2195.       ))
  2196.     ;; Cannot select newsgroup GROUP.
  2197.     (if (gnus-gethash group gnus-active-hashtb)
  2198.     (progn
  2199.       ;; If NNTP is used, nntp_access file may not be installed
  2200.       ;; properly.  Otherwise, may be active file problem.
  2201.       (ding)
  2202.       (message
  2203.        (gnus-nntp-message
  2204.         (format "Cannot select %s.  May be security or active file problem." group)))
  2205.       (sit-for 0))
  2206.       ;; Check bogus newsgroups.
  2207.       ;; We must be in Group Mode buffer.
  2208.       (gnus-group-check-bogus-groups))
  2209.     ))
  2210.  
  2211. (defun gnus-summary-prepare ()
  2212.   "Prepare summary list of current newsgroup in Summary buffer."
  2213.   (let ((buffer-read-only nil))
  2214.     ;; Note: The next codes are not actually used because the user who
  2215.     ;; want it can define them in gnus-select-group-hook.
  2216.     ;; Print verbose messages if too many articles are selected.
  2217.     ;;    (and (numberp gnus-large-newsgroup)
  2218.     ;;       (> (length gnus-newsgroup-headers) gnus-large-newsgroup)
  2219.     ;;       (message "Preparing headers..."))
  2220.     (erase-buffer)
  2221.     (gnus-summary-prepare-threads
  2222.      (if gnus-show-threads
  2223.      (gnus-make-threads gnus-newsgroup-headers)
  2224.        gnus-newsgroup-headers) 0)
  2225.     ;; Erase header retrieval message.
  2226.     (message "")
  2227.     ;; Call hooks for modifying Summary buffer.
  2228.     ;; Suggested by sven@tde.LTH.Se (Sven Mattisson).
  2229.     (goto-char (point-min))
  2230.     (run-hooks 'gnus-summary-prepare-hook)
  2231.     ))
  2232.  
  2233. ;; Basic ideas by Paul Dworkin <paul@media-lab.media.mit.edu>
  2234. ;; Subject bug fix by jbw@bigbird.bu.edu (Joe Wells)
  2235.  
  2236. (defun gnus-summary-prepare-threads (threads level &optional parent-subject)
  2237.   "Prepare Summary buffer from THREADS and indentation LEVEL.
  2238. THREADS is a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...]).'
  2239. Optional PARENT-SUBJECT specifies the subject of the parent."
  2240.   (let ((thread nil)
  2241.     (header nil)
  2242.     (number nil)
  2243.     (subject nil)
  2244.     (child-subject nil)
  2245.     (parent-subject (or parent-subject ""))
  2246.     ;; `M Indent NUM: [OPT] SUBJECT'
  2247.     (cntl (format "%%s %%s%%%dd: [%%s] %%s\n"
  2248.               (length (prin1-to-string gnus-newsgroup-end)))))
  2249.     (while threads
  2250.       (setq thread (car threads))
  2251.       (setq threads (cdr threads))
  2252.       ;; If thread is a cons, hierarchical threads is given.
  2253.       ;; Otherwise, thread itself is header.
  2254.       (if (consp thread)
  2255.       (setq header (car thread))
  2256.     (setq header thread))
  2257.       ;; Print valid header only.
  2258.       (if (vectorp header)        ;Depends on nntp.el.
  2259.       (progn
  2260.         (setq number (nntp-header-number header))
  2261.         (setq subject (nntp-header-subject header))
  2262.         (setq child-subject (gnus-simplify-subject subject 're-only))
  2263.         (insert
  2264.          (format cntl
  2265.              ;; Read or not.
  2266.              (cond ((memq number gnus-newsgroup-marked)  "-")
  2267.                ((memq number gnus-newsgroup-unreads) " ")
  2268.                (t "D"))
  2269.              ;; Thread level.
  2270.              (make-string (* level gnus-thread-indent-level) ? )
  2271.              ;; Article number.
  2272.              number
  2273.              ;; Optional headers.
  2274.              (or (and gnus-optional-headers
  2275.                   (funcall gnus-optional-headers header)) "")
  2276.              ;; Its subject string.
  2277.              (concat (if (or (zerop level)
  2278.                      (not gnus-thread-hide-subject)
  2279.                      ;; Subject is different from the parent.
  2280.                      (not (string-equal
  2281.                        parent-subject child-subject)))
  2282.                  nil
  2283.                    (make-string (window-width) ? ))
  2284.                  subject)
  2285.              ))
  2286.         ))
  2287.       ;; Print subthreads.
  2288.       (and (consp thread)
  2289.        (cdr thread)
  2290.        (gnus-summary-prepare-threads
  2291.         (cdr thread) (1+ level) child-subject))
  2292.       )))
  2293.  
  2294. ;;(defun gnus-summary-set-mode-line ()
  2295. ;;  "Set Summary mode line string."
  2296. ;;  ;; The value must be a string to escape %-constructs.
  2297. ;;  (let ((subject
  2298. ;;     (if gnus-current-headers
  2299. ;;         (nntp-header-subject gnus-current-headers) gnus-newsgroup-name)))
  2300. ;;    (setq mode-line-buffer-identification
  2301. ;;      (concat "GNUS: "
  2302. ;;          subject
  2303. ;;          ;; Enough spaces to pad subject to 17 positions.
  2304. ;;          (make-string (max 0 (- 17 (length subject))) ? ))))
  2305. ;;  (set-buffer-modified-p t))
  2306.  
  2307. ;; New implementation in gnus 3.14.3
  2308.  
  2309. (defun gnus-summary-set-mode-line ()
  2310.   "Set Summary mode line string.
  2311. If you don't like it, define your own gnus-summary-set-mode-line."
  2312.   (let ((unmarked
  2313.      (- (length gnus-newsgroup-unreads)
  2314.         (length (gnus-intersection
  2315.              gnus-newsgroup-unreads gnus-newsgroup-marked))))
  2316.     (unselected
  2317.      (- (length gnus-newsgroup-unselected)
  2318.         (length (gnus-intersection
  2319.              gnus-newsgroup-unselected gnus-newsgroup-marked)))))
  2320.     (setq mode-line-buffer-identification
  2321.       (list 17
  2322.         (format "GNUS: %s%s %s"
  2323.             gnus-newsgroup-name
  2324.             (if gnus-current-article
  2325.                 (format "/%d" gnus-current-article) "")
  2326.             ;; Basic ideas by tale@pawl.rpi.edu.
  2327.             (cond ((and (zerop unmarked)
  2328.                     (zerop unselected))
  2329.                    "")
  2330.                   ((zerop unselected)
  2331.                    (format "{%d more}" unmarked))
  2332.                   (t
  2333.                    (format "{%d(+%d) more}" unmarked unselected)))
  2334.             ))))
  2335.   (set-buffer-modified-p t))
  2336.  
  2337. ;; GNUS Summary mode command.
  2338.  
  2339. (defun gnus-summary-search-group (&optional backward)
  2340.   "Search for next unread newsgroup.
  2341. If optional argument BACKWARD is non-nil, search backward instead."
  2342.   (save-excursion
  2343.     (set-buffer gnus-group-buffer)
  2344.     (save-excursion
  2345.       ;; We don't want to alter current point of Group mode buffer.
  2346.       (if (gnus-group-search-forward backward nil)
  2347.       (gnus-group-group-name))
  2348.       )))
  2349.  
  2350. (defun gnus-summary-search-subject (backward unread subject)
  2351.   "Search for article forward.
  2352. If 1st argument BACKWARD is non-nil, search backward.
  2353. If 2nd argument UNREAD is non-nil, only unread article is selected.
  2354. If 3rd argument SUBJECT is non-nil, the article which has
  2355. the same subject will be searched for."
  2356.   (let ((func
  2357.      (if backward
  2358.          (function re-search-backward) (function re-search-forward)))
  2359.     (article nil)
  2360.     ;; We have to take care of hidden lines.
  2361.     (regexp 
  2362.      (format "^%s[ \t]+\\([0-9]+\\):.\\[[^]\r\n]*\\][ \t]+%s"
  2363.          ;;(if unread " " ".")
  2364.          (cond ((eq unread t) " ") (unread "[- ]") (t "."))
  2365.          (if subject
  2366.              (concat "\\([Rr][Ee]:[ \t]+\\)*"
  2367.                  (regexp-quote (gnus-simplify-subject subject))
  2368.                  ;; Ignore words in parentheses.
  2369.                  "\\([ \t]*([^\r\n]*)\\)*[ \t]*\\(\r\\|$\\)")
  2370.            "")
  2371.          )))
  2372.     (if backward
  2373.     (beginning-of-line)
  2374.       (end-of-line))
  2375.     (if (funcall func regexp nil t)
  2376.     (setq article
  2377.           (string-to-int
  2378.            (buffer-substring (match-beginning 1) (match-end 1)))))
  2379.     ;; Adjust cursor point.
  2380.     (beginning-of-line)
  2381.     (search-forward ":" nil t)
  2382.     ;; This is the result.
  2383.     article
  2384.     ))
  2385.  
  2386. (defun gnus-summary-search-forward (&optional unread subject)
  2387.   "Search for article forward.
  2388. If 1st optional argument UNREAD is non-nil, only unread article is selected.
  2389. If 2nd optional argument SUBJECT is non-nil, the article which has
  2390. the same subject will be searched for."
  2391.   (gnus-summary-search-subject nil unread subject))
  2392.  
  2393. (defun gnus-summary-search-backward (&optional unread subject)
  2394.   "Search for article backward.
  2395. If 1st optional argument UNREAD is non-nil, only unread article is selected.
  2396. If 2nd optional argument SUBJECT is non-nil, the article which has
  2397. the same subject will be searched for."
  2398.   (gnus-summary-search-subject t unread subject))
  2399.  
  2400. (defun gnus-summary-article-number ()
  2401.   "Article number around point. If nothing, return current number."
  2402.   (save-excursion
  2403.     (beginning-of-line)
  2404.     (if (looking-at ".[ \t]+\\([0-9]+\\):")
  2405.     (string-to-int
  2406.      (buffer-substring (match-beginning 1) (match-end 1)))
  2407.       ;; If search fail, return current article number.
  2408.       gnus-current-article
  2409.       )))
  2410.  
  2411. (defun gnus-summary-subject-string ()
  2412.   "Return current subject string or nil if nothing."
  2413.   (save-excursion
  2414.     ;; It is possible to implement this function using
  2415.     ;;  `gnus-summary-article-number' and `gnus-newsgroup-headers'.
  2416.     (beginning-of-line)
  2417.     ;; We have to take care of hidden lines.
  2418.     (if (looking-at ".[ \t]+[0-9]+:.\\[[^]\r\n]*\\][ \t]+\\([^\r\n]*\\)[\r\n]")
  2419.     (buffer-substring (match-beginning 1) (match-end 1)))
  2420.     ))
  2421.  
  2422. (defun gnus-summary-goto-subject (article)
  2423.   "Move point to ARTICLE's subject."
  2424.   (interactive
  2425.    (list
  2426.     (string-to-int
  2427.      (completing-read "Article number: "
  2428.               (mapcar
  2429.                (function
  2430.             (lambda (headers)
  2431.               (list
  2432.                (int-to-string (nntp-header-number headers)))))
  2433.                gnus-newsgroup-headers)
  2434.               nil 'require-match))))
  2435.   (let ((current (point)))
  2436.     (goto-char (point-min))
  2437.     (or (and article (re-search-forward (format "^.[ \t]+%d:" article) nil t))
  2438.     (progn (goto-char current) nil))
  2439.     ))
  2440.  
  2441. (defun gnus-summary-recenter ()
  2442.   "Center point in Summary window."
  2443.   ;; Scroll window so as to cursor comes center of Summary window
  2444.   ;;  only when article is displayed.
  2445.   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
  2446.   ;; Recenter only when requested.
  2447.   ;; Subbested by popovich@park.cs.columbia.edu
  2448.   (and gnus-auto-center-summary
  2449.        (get-buffer-window gnus-article-buffer)
  2450.        (< (/ (- (window-height) 1) 2)
  2451.       (count-lines (point) (point-max)))
  2452.        (recenter (/ (- (window-height) 2) 2))))
  2453.  
  2454. ;; Walking around Group mode buffer.
  2455.  
  2456. (defun gnus-summary-jump-to-group (newsgroup)
  2457.   "Move point to NEWSGROUP in Group mode buffer."
  2458.   ;; Keep update point of Group mode buffer if visible.
  2459.   (if (eq (current-buffer)
  2460.       (get-buffer gnus-group-buffer))
  2461.       (save-window-excursion
  2462.     ;; Take care of tree window mode.
  2463.     (if (get-buffer-window gnus-group-buffer)
  2464.         (pop-to-buffer gnus-group-buffer))
  2465.     (gnus-group-jump-to-group newsgroup))
  2466.     (save-excursion
  2467.       ;; Take care of tree window mode.
  2468.       (if (get-buffer-window gnus-group-buffer)
  2469.       (pop-to-buffer gnus-group-buffer)
  2470.     (set-buffer gnus-group-buffer))
  2471.       (gnus-group-jump-to-group newsgroup))))
  2472.  
  2473. (defun gnus-summary-next-group (no-article)
  2474.   "Exit current newsgroup and then select next unread newsgroup.
  2475. If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
  2476.   (interactive "P")
  2477.   ;; Make sure Group mode buffer point is on current newsgroup.
  2478.   (gnus-summary-jump-to-group gnus-newsgroup-name)
  2479.   (let ((group (gnus-summary-search-group)))
  2480.     (if (null group)
  2481.     (progn
  2482.       (message "Exiting %s..." gnus-newsgroup-name)  
  2483.       (gnus-summary-exit)
  2484.       (message ""))
  2485.       (message "Selecting %s..." group)
  2486.       (gnus-summary-exit t)        ;Exit Summary mode temporary.
  2487.       ;; We are now in Group mode buffer.
  2488.       ;; Make sure Group mode buffer point is on GROUP.
  2489.       (gnus-summary-jump-to-group group)
  2490.       (gnus-summary-read-group group nil no-article)
  2491.       (or (eq (current-buffer)
  2492.           (get-buffer gnus-summary-buffer))
  2493.       (eq gnus-auto-select-next t)
  2494.       ;; Expected newsgroup has nothing to read since the articles
  2495.       ;; are marked as read by cross-referencing. So, try next
  2496.       ;; newsgroup. (Make sure we are in Group mode buffer now.)
  2497.       (and (eq (current-buffer)
  2498.            (get-buffer gnus-group-buffer))
  2499.            (gnus-group-group-name)
  2500.            (gnus-summary-read-group
  2501.         (gnus-group-group-name) nil no-article))
  2502.       )
  2503.       )))
  2504.  
  2505. (defun gnus-summary-prev-group (no-article)
  2506.   "Exit current newsgroup and then select previous unread newsgroup.
  2507. If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
  2508.   (interactive "P")
  2509.   ;; Make sure Group mode buffer point is on current newsgroup.
  2510.   (gnus-summary-jump-to-group gnus-newsgroup-name)
  2511.   (let ((group (gnus-summary-search-group t)))
  2512.     (if (null group)
  2513.     (progn
  2514.       (message "Exiting %s..." gnus-newsgroup-name)  
  2515.       (gnus-summary-exit)
  2516.       (message ""))
  2517.       (message "Selecting %s..." group)
  2518.       (gnus-summary-exit t)        ;Exit Summary mode temporary.
  2519.       ;; We are now in Group mode buffer.
  2520.       ;; We have to adjust point of Group mode buffer because current
  2521.       ;; point is moved to next unread newsgroup by exiting.
  2522.       (gnus-summary-jump-to-group group)
  2523.       (gnus-summary-read-group group nil no-article)
  2524.       (or (eq (current-buffer)
  2525.           (get-buffer gnus-summary-buffer))
  2526.       (eq gnus-auto-select-next t)
  2527.       ;; Expected newsgroup has nothing to read since the articles
  2528.       ;; are marked as read by cross-referencing. So, try next
  2529.       ;; newsgroup. (Make sure we are in Group mode buffer now.)
  2530.       (and (eq (current-buffer)
  2531.            (get-buffer gnus-group-buffer))
  2532.            (gnus-summary-search-group t)
  2533.            (gnus-summary-read-group
  2534.         (gnus-summary-search-group t) nil no-article))
  2535.       )
  2536.       )))
  2537.  
  2538. ;; Walking around summary lines.
  2539.  
  2540. (defun gnus-summary-next-subject (n &optional unread)
  2541.   "Go to next N'th summary line.
  2542. If optional argument UNREAD is non-nil, only unread article is selected."
  2543.   (interactive "p")
  2544.   (while (and (> n 1)
  2545.           (gnus-summary-search-forward unread))
  2546.     (setq n (1- n)))
  2547.   (cond ((gnus-summary-search-forward unread)
  2548.      (gnus-summary-recenter))
  2549.     (unread
  2550.      (message "No more unread articles"))
  2551.     (t
  2552.      (message "No more articles"))
  2553.     ))
  2554.  
  2555. (defun gnus-summary-next-unread-subject (n)
  2556.   "Go to next N'th unread summary line."
  2557.   (interactive "p")
  2558.   (gnus-summary-next-subject n t))
  2559.  
  2560. (defun gnus-summary-prev-subject (n &optional unread)
  2561.   "Go to previous N'th summary line.
  2562. If optional argument UNREAD is non-nil, only unread article is selected."
  2563.   (interactive "p")
  2564.   (while (and (> n 1)
  2565.           (gnus-summary-search-backward unread))
  2566.     (setq n (1- n)))
  2567.   (cond ((gnus-summary-search-backward unread)
  2568.      (gnus-summary-recenter))
  2569.     (unread
  2570.      (message "No more unread articles"))
  2571.     (t
  2572.      (message "No more articles"))
  2573.     ))
  2574.  
  2575. (defun gnus-summary-prev-unread-subject (n)
  2576.   "Go to previous N'th unread summary line."
  2577.   (interactive "p")
  2578.   (gnus-summary-prev-subject n t))
  2579.  
  2580. ;; Walking around summary lines with displaying articles.
  2581.  
  2582. (defun gnus-summary-expand-window ()
  2583.   "Expand Summary window to show headers full window."
  2584.   (interactive)
  2585.   (gnus-configure-windows 'summary)
  2586.   (pop-to-buffer gnus-summary-buffer))
  2587.  
  2588. (defun gnus-summary-display-article (article &optional all-header)
  2589.   "Display ARTICLE in Article buffer."
  2590.   (if (null article)
  2591.       nil
  2592.     (gnus-configure-windows 'article)
  2593.     (pop-to-buffer gnus-summary-buffer)
  2594.     (gnus-article-prepare article all-header)
  2595.     (gnus-summary-recenter)
  2596.     (gnus-summary-set-mode-line)
  2597.     (run-hooks 'gnus-select-article-hook)
  2598.     ;; Successfully display article.
  2599.     t
  2600.     ))
  2601.  
  2602. (defun gnus-summary-select-article (&optional all-headers force)
  2603.   "Select the current article.
  2604. Optional first argument ALL-HEADERS is non-nil, show all header fields.
  2605. Optional second argument FORCE is nil, the article is only selected
  2606. again when current header does not match with ALL-HEADERS option."
  2607.   (let ((article (gnus-summary-article-number))
  2608.     (all-headers (not (not all-headers)))) ;Must be T or NIL.
  2609.     (if (or (null gnus-current-article)
  2610.         (/= article gnus-current-article)
  2611.         (and force (not (eq all-headers gnus-have-all-headers))))
  2612.     ;; The selected one is different from that of the current article.
  2613.     (gnus-summary-display-article article all-headers)
  2614.       (gnus-configure-windows 'article)
  2615.       (pop-to-buffer gnus-summary-buffer))
  2616.     ))
  2617.  
  2618. (defun gnus-summary-set-current-mark (&optional current-mark)
  2619.   "Put `+' at the current article.
  2620. Optional argument specifies CURRENT-MARK instead of `+'."
  2621.   (save-excursion
  2622.     (set-buffer gnus-summary-buffer)
  2623.     (let ((buffer-read-only nil))
  2624.       (goto-char (point-min))
  2625.       ;; First of all clear mark at last article.
  2626.       (if (re-search-forward "^.[ \t]+[0-9]+:[^ \t]" nil t)
  2627.       (progn
  2628.         (delete-char -1)
  2629.         (insert " ")
  2630.         (goto-char (point-min))))
  2631.       (if (re-search-forward (format "^.[ \t]+%d:" gnus-current-article) nil t)
  2632.       (progn
  2633.         (delete-char 1)
  2634.         (insert (or current-mark "+"))))
  2635.       )))
  2636.  
  2637. ;;(defun gnus-summary-next-article (unread &optional subject)
  2638. ;;  "Select article after current one.
  2639. ;;If argument UNREAD is non-nil, only unread article is selected."
  2640. ;;  (interactive "P")
  2641. ;;  (cond ((gnus-summary-display-article
  2642. ;;      (gnus-summary-search-forward unread subject)))
  2643. ;;    (unread
  2644. ;;     (message "No more unread articles"))
  2645. ;;    (t
  2646. ;;     (message "No more articles"))
  2647. ;;    ))
  2648.  
  2649. (defun gnus-summary-next-article (unread &optional subject)
  2650.   "Select article after current one.
  2651. If argument UNREAD is non-nil, only unread article is selected."
  2652.   (interactive "P")
  2653.   (let ((header nil))
  2654.     (cond ((gnus-summary-display-article
  2655.         (gnus-summary-search-forward unread subject)))
  2656.       ((and subject
  2657.         gnus-auto-select-same
  2658.         (gnus-set-difference gnus-newsgroup-unreads
  2659.                      gnus-newsgroup-marked)
  2660.         (memq this-command
  2661.               '(gnus-summary-next-unread-article
  2662.             gnus-summary-next-page
  2663.             gnus-summary-kill-same-subject-and-select
  2664.             ;;gnus-summary-next-article
  2665.             ;;gnus-summary-next-same-subject
  2666.             ;;gnus-summary-next-unread-same-subject
  2667.             )))
  2668.        ;; Wrap article pointer if there are unread articles.
  2669.        ;; Hook function, such as gnus-summary-rmail-digest, may
  2670.        ;; change current buffer, so need check.
  2671.        (let ((buffer (current-buffer))
  2672.          (last-point (point)))
  2673.          ;; No more articles with same subject, so jump to the first
  2674.          ;; unread article.
  2675.          (gnus-summary-first-unread-article)
  2676.          ;;(and (eq buffer (current-buffer))
  2677.          ;;    (= (point) last-point)
  2678.          ;;    ;; Ignore given SUBJECT, and try again.
  2679.          ;;    (gnus-summary-next-article unread nil))
  2680.          (and (eq buffer (current-buffer))
  2681.           (< (point) last-point)
  2682.           (message "Wrapped"))
  2683.          ))
  2684.       ((and gnus-auto-extend-newsgroup
  2685.         (not unread)        ;Not unread only
  2686.         (not subject)        ;Only if subject is not specified.
  2687.         (setq header (gnus-more-header-forward)))
  2688.        ;; Extend to next article if possible.
  2689.        ;; Basic ideas by himacdonald@watdragon.waterloo.edu
  2690.        (gnus-extend-newsgroup header nil)
  2691.        ;; Threads feature must be turned off.
  2692.        (let ((buffer-read-only nil))
  2693.          (goto-char (point-max))
  2694.          (gnus-summary-prepare-threads (list header) 0))
  2695.        (gnus-summary-goto-article gnus-newsgroup-end))
  2696.       (t
  2697.        ;; Select next newsgroup automatically if requested.
  2698.        (let ((cmd (string-to-char (this-command-keys)))
  2699.          (group (gnus-summary-search-group))
  2700.          (auto-select
  2701.           (and gnus-auto-select-next
  2702.                ;;(null (gnus-set-difference gnus-newsgroup-unreads
  2703.                ;;                gnus-newsgroup-marked))
  2704.                (memq this-command
  2705.                  '(gnus-summary-next-unread-article
  2706.                    gnus-summary-next-article
  2707.                    gnus-summary-next-page
  2708.                    gnus-summary-next-same-subject
  2709.                    gnus-summary-next-unread-same-subject
  2710.                    gnus-summary-kill-same-subject
  2711.                    gnus-summary-kill-same-subject-and-select
  2712.                    ))
  2713.                ;; Ignore characters typed ahead.
  2714.                (not (input-pending-p))
  2715.                )))
  2716.          (message "No more%s articles%s"
  2717.               (if unread " unread" "")
  2718.               (if (and auto-select
  2719.                    (not (eq gnus-auto-select-next 'quietly)))
  2720.               (if group
  2721.                   (format " (Type %s for %s [%d])"
  2722.                       (key-description (char-to-string cmd))
  2723.                       group
  2724.                       (nth 1 (gnus-gethash group
  2725.                                gnus-unread-hashtb)))
  2726.                 (format " (Type %s to exit %s)"
  2727.                     (key-description (char-to-string cmd))
  2728.                     gnus-newsgroup-name
  2729.                     ))
  2730.             ""))
  2731.          ;; Select next unread newsgroup automagically.
  2732.          (cond ((and auto-select
  2733.              (eq gnus-auto-select-next 'quietly))
  2734.             ;; Select quietly.
  2735.             (gnus-summary-next-group nil))
  2736.            (auto-select
  2737.             ;; Confirm auto selection.
  2738.             (let ((char (read-char)))
  2739.               (if (= char cmd)
  2740.               (gnus-summary-next-group nil)
  2741.             (setq unread-command-char char))))
  2742.            )
  2743.          ))
  2744.       )))
  2745.  
  2746. (defun gnus-summary-next-unread-article ()
  2747.   "Select unread article after current one."
  2748.   (interactive)
  2749.   (gnus-summary-next-article t (and gnus-auto-select-same
  2750.                     (gnus-summary-subject-string))))
  2751.  
  2752. (defun gnus-summary-prev-article (unread &optional subject)
  2753.   "Select article before current one.
  2754. If argument UNREAD is non-nil, only unread article is selected."
  2755.   (interactive "P")
  2756.   (let ((header nil))
  2757.     (cond ((gnus-summary-display-article
  2758.         (gnus-summary-search-backward unread subject)))
  2759.       ((and subject
  2760.         gnus-auto-select-same
  2761.         (gnus-set-difference gnus-newsgroup-unreads
  2762.                      gnus-newsgroup-marked)
  2763.         (memq this-command
  2764.               '(gnus-summary-prev-unread-article
  2765.             ;;gnus-summary-prev-page
  2766.             ;;gnus-summary-prev-article
  2767.             ;;gnus-summary-prev-same-subject
  2768.             ;;gnus-summary-prev-unread-same-subject
  2769.             )))
  2770.        ;; Ignore given SUBJECT, and try again.
  2771.        (gnus-summary-prev-article unread nil))
  2772.       (unread
  2773.        (message "No more unread articles"))
  2774.       ((and gnus-auto-extend-newsgroup
  2775.         (not subject)        ;Only if subject is not specified.
  2776.         (setq header (gnus-more-header-backward)))
  2777.        ;; Extend to previous article if possible.
  2778.        ;; Basic ideas by himacdonald@watdragon.waterloo.edu
  2779.        (gnus-extend-newsgroup header t)
  2780.        (let ((buffer-read-only nil))
  2781.          (goto-char (point-min))
  2782.          (gnus-summary-prepare-threads (list header) 0))
  2783.        (gnus-summary-goto-article gnus-newsgroup-begin))
  2784.       (t
  2785.        (message "No more articles"))
  2786.       )))
  2787.  
  2788. (defun gnus-summary-prev-unread-article ()
  2789.   "Select unred article before current one."
  2790.   (interactive)
  2791.   (gnus-summary-prev-article t (and gnus-auto-select-same
  2792.                     (gnus-summary-subject-string))))
  2793.  
  2794. (defun gnus-summary-next-page (lines)
  2795.   "Show next page of selected article.
  2796. If end of article, select next article.
  2797. Argument LINES specifies lines to be scrolled up."
  2798.   (interactive "P")
  2799.   (let ((article (gnus-summary-article-number))
  2800.     (endp nil))
  2801.     (if (or (null gnus-current-article)
  2802.         (/= article gnus-current-article))
  2803.     ;; Selected subject is different from current article's.
  2804.     (gnus-summary-display-article article)
  2805.       (gnus-configure-windows 'article)
  2806.       (pop-to-buffer gnus-summary-buffer)
  2807.       (gnus-eval-in-buffer-window gnus-article-buffer
  2808.     (setq endp (gnus-article-next-page lines)))
  2809.       (cond ((and endp lines)
  2810.          (message "End of message"))
  2811.         ((and endp (null lines))
  2812.          (gnus-summary-next-unread-article)))
  2813.       )))
  2814.  
  2815. (defun gnus-summary-prev-page (lines)
  2816.   "Show previous page of selected article.
  2817. Argument LINES specifies lines to be scrolled down."
  2818.   (interactive "P")
  2819.   (let ((article (gnus-summary-article-number)))
  2820.     (if (or (null gnus-current-article)
  2821.         (/= article gnus-current-article))
  2822.     ;; Selected subject is different from current article's.
  2823.     (gnus-summary-display-article article)
  2824.       (gnus-configure-windows 'article)
  2825.       (pop-to-buffer gnus-summary-buffer)
  2826.       (gnus-eval-in-buffer-window gnus-article-buffer
  2827.     (gnus-article-prev-page lines))
  2828.       )))
  2829.  
  2830. (defun gnus-summary-scroll-up (lines)
  2831.   "Scroll up (or down) one line current article.
  2832. Argument LINES specifies lines to be scrolled up (or down if negative)."
  2833.   (interactive "p")
  2834.   (gnus-summary-select-article)
  2835.   (gnus-eval-in-buffer-window gnus-article-buffer
  2836.     (cond ((> lines 0)
  2837.        (if (gnus-article-next-page lines)
  2838.            (message "End of message")))
  2839.       ((< lines 0)
  2840.        (gnus-article-prev-page (- 0 lines))))
  2841.     ))
  2842.  
  2843. (defun gnus-summary-next-same-subject ()
  2844.   "Select next article which has the same subject as current one."
  2845.   (interactive)
  2846.   (gnus-summary-next-article nil (gnus-summary-subject-string)))
  2847.  
  2848. (defun gnus-summary-prev-same-subject ()
  2849.   "Select previous article which has the same subject as current one."
  2850.   (interactive)
  2851.   (gnus-summary-prev-article nil (gnus-summary-subject-string)))
  2852.  
  2853. (defun gnus-summary-next-unread-same-subject ()
  2854.   "Select next unread article which has the same subject as current one."
  2855.   (interactive)
  2856.   (gnus-summary-next-article t (gnus-summary-subject-string)))
  2857.  
  2858. (defun gnus-summary-prev-unread-same-subject ()
  2859.   "Select previous unread article which has the same subject as current one."
  2860.   (interactive)
  2861.   (gnus-summary-prev-article t (gnus-summary-subject-string)))
  2862.  
  2863. (defun gnus-summary-refer-parent-article (child)
  2864.   "Refer parent article of current article.
  2865. If a prefix argument CHILD is non-nil, go back to the child article
  2866. using internally maintained articles history.
  2867. NOTE: This command may not work with nnspool.el."
  2868.   (interactive "P")
  2869.   (gnus-summary-select-article t t)    ;Request all headers.
  2870.   (let ((referenced-id nil))        ;Message-id of parent or child article.
  2871.     (if child
  2872.     ;; Go back to child article using history.
  2873.     (gnus-summary-refer-article nil)
  2874.       (gnus-eval-in-buffer-window gnus-article-buffer
  2875.     ;; Look for parent Message-ID.
  2876.     ;; We cannot use gnus-current-headers to get references
  2877.     ;; because we may be looking at parent or referred article.
  2878.     (let ((references (gnus-fetch-field "References")))
  2879.       ;; Get the last message-id in the references.
  2880.       (and references
  2881.            (string-match "\\(<[^<>]+>\\)[^>]*\\'" references)
  2882.            (setq referenced-id
  2883.              (substring references
  2884.                 (match-beginning 1) (match-end 1))))
  2885.       ))
  2886.       (if (stringp referenced-id)
  2887.       (gnus-summary-refer-article referenced-id)
  2888.     (error "No more parents"))
  2889.       )))
  2890.  
  2891. (defun gnus-summary-refer-article (message-id)
  2892.   "Refer article specified by MESSAGE-ID.
  2893. If the MESSAGE-ID is nil or an empty string, Message-ID is poped from
  2894. internally maintained articles history.
  2895. NOTE: This command may not work with nnspool.el nor mhspool.el."
  2896.   (interactive "sMessage-ID: ")
  2897.   ;; Make sure that this command depends on the fact that article
  2898.   ;; related information is not updated when an article is retrieved
  2899.   ;; by Message-ID.
  2900.   (gnus-summary-select-article t t)    ;Request all headers.
  2901.   (if (and (stringp message-id)
  2902.        (> (length message-id) 0))
  2903.       (gnus-eval-in-buffer-window gnus-article-buffer
  2904.     ;; Construct the correct Message-ID if necessary.
  2905.     ;; Suggested by tale@pawl.rpi.edu.
  2906.     (or (string-match "^<" message-id)
  2907.         (setq message-id (concat "<" message-id)))
  2908.     (or (string-match ">$" message-id)
  2909.         (setq message-id (concat message-id ">")))
  2910.     ;; Push current message-id on history.
  2911.     ;; We cannot use gnus-current-headers to get current
  2912.     ;; message-id because we may be looking at parent or referred
  2913.     ;; article.
  2914.     (let ((current (gnus-fetch-field "Message-ID")))
  2915.       (or (equal current message-id) ;Nothing to do.
  2916.           (equal current (car gnus-current-history))
  2917.           (setq gnus-current-history
  2918.             (cons current gnus-current-history)))
  2919.       ))
  2920.     ;; Pop message-id from history.
  2921.     (setq message-id (car gnus-current-history))
  2922.     (setq gnus-current-history (cdr gnus-current-history)))
  2923.   (if (stringp message-id)
  2924.       ;; Retrieve article by message-id.  This may not work with
  2925.       ;; nnspool nor mhspool.
  2926.       (gnus-article-prepare message-id t)
  2927.     (error "No such references"))
  2928.   )
  2929.  
  2930. (defun gnus-summary-next-digest (nth)
  2931.   "Move to head of NTH next digested message."
  2932.   (interactive "p")
  2933.   (gnus-summary-select-article)
  2934.   (gnus-eval-in-buffer-window gnus-article-buffer
  2935.     (gnus-article-next-digest (or nth 1))
  2936.     ))
  2937.  
  2938. (defun gnus-summary-prev-digest (nth)
  2939.   "Move to head of NTH previous digested message."
  2940.   (interactive "p")
  2941.   (gnus-summary-select-article)
  2942.   (gnus-eval-in-buffer-window gnus-article-buffer
  2943.     (gnus-article-prev-digest (or nth 1))
  2944.     ))
  2945.  
  2946. (defun gnus-summary-first-unread-article ()
  2947.   "Select first unread article. Return non-nil if successfully selected."
  2948.   (interactive)
  2949.   (let ((begin (point)))
  2950.     (goto-char (point-min))
  2951.     (if (re-search-forward "^ [ \t]+[0-9]+:" nil t)
  2952.     (gnus-summary-display-article (gnus-summary-article-number))
  2953.       ;; If there is no unread articles, stay there.
  2954.       (goto-char begin)
  2955.       ;;(gnus-summary-display-article (gnus-summary-article-number))
  2956.       (message "No more unread articles")
  2957.       nil
  2958.       )
  2959.     ))
  2960.  
  2961. (defun gnus-summary-isearch-article ()
  2962.   "Do incremental search forward on current article."
  2963.   (interactive)
  2964.   (gnus-summary-select-article)
  2965.   (gnus-eval-in-buffer-window gnus-article-buffer
  2966.                   (isearch-forward)))
  2967.  
  2968. (defun gnus-summary-search-article-forward (regexp)
  2969.   "Search for an article containing REGEXP forward.
  2970. gnus-select-article-hook is not called during the search."
  2971.   (interactive
  2972.    (list (read-string
  2973.       (concat "Search forward (regexp): "
  2974.           (if gnus-last-search-regexp
  2975.               (concat "(default " gnus-last-search-regexp ") "))))))
  2976.   (if (string-equal regexp "")
  2977.       (setq regexp (or gnus-last-search-regexp ""))
  2978.     (setq gnus-last-search-regexp regexp))
  2979.   (if (gnus-summary-search-article regexp nil)
  2980.       (gnus-eval-in-buffer-window gnus-article-buffer
  2981.     (recenter 0)
  2982.     ;;(sit-for 1)
  2983.     )
  2984.     (error "Search failed: \"%s\"" regexp)
  2985.     ))
  2986.  
  2987. (defun gnus-summary-search-article-backward (regexp)
  2988.   "Search for an article containing REGEXP backward.
  2989. gnus-select-article-hook is not called during the search."
  2990.   (interactive
  2991.    (list (read-string
  2992.       (concat "Search backward (regexp): "
  2993.           (if gnus-last-search-regexp
  2994.               (concat "(default " gnus-last-search-regexp ") "))))))
  2995.   (if (string-equal regexp "")
  2996.       (setq regexp (or gnus-last-search-regexp ""))
  2997.     (setq gnus-last-search-regexp regexp))
  2998.   (if (gnus-summary-search-article regexp t)
  2999.       (gnus-eval-in-buffer-window gnus-article-buffer
  3000.     (recenter 0)
  3001.     ;;(sit-for 1)
  3002.     )
  3003.     (error "Search failed: \"%s\"" regexp)
  3004.     ))
  3005.  
  3006. (defun gnus-summary-search-article (regexp &optional backward)
  3007.   "Search for an article containing REGEXP.
  3008. Optional argument BACKWARD means do search for backward.
  3009. gnus-select-article-hook is not called during the search."
  3010.   (let ((gnus-select-article-hook nil)    ;Disable hook.
  3011.     (gnus-mark-article-hook nil)    ;Inhibit marking as read.
  3012.     (re-search
  3013.      (if backward
  3014.          (function re-search-backward) (function re-search-forward)))
  3015.     (found nil)
  3016.     (last nil))
  3017.     ;; Hidden thread subtrees must be searched for ,too.
  3018.     (gnus-summary-show-all-threads)
  3019.     ;; First of all, search current article.
  3020.     ;; We don't want to read article again from NNTP server nor reset
  3021.     ;; current point.
  3022.     (gnus-summary-select-article)
  3023.     (message "Searching article: %d..." gnus-current-article)
  3024.     (setq last gnus-current-article)
  3025.     (gnus-eval-in-buffer-window gnus-article-buffer
  3026.       (save-restriction
  3027.     (widen)
  3028.     ;; Begin search from current point.
  3029.     (setq found (funcall re-search regexp nil t))))
  3030.     ;; Then search next articles.
  3031.     (while (and (not found)
  3032.         (gnus-summary-display-article 
  3033.          (gnus-summary-search-subject backward nil nil)))
  3034.       (message "Searching article: %d..." gnus-current-article)
  3035.       (gnus-eval-in-buffer-window gnus-article-buffer
  3036.     (save-restriction
  3037.       (widen)
  3038.       (goto-char (if backward (point-max) (point-min)))
  3039.       (setq found (funcall re-search regexp nil t)))
  3040.     ))
  3041.     (message "")
  3042.     ;; Adjust article pointer.
  3043.     (or (eq last gnus-current-article)
  3044.     (setq gnus-last-article last))
  3045.     ;; Return T if found such article.
  3046.     found
  3047.     ))
  3048.  
  3049. (defun gnus-summary-execute-command (field regexp command &optional backward)
  3050.   "If FIELD of article header matches REGEXP, execute a COMMAND string.
  3051. If FIELD is an empty string (or nil), entire article body is searched for.
  3052. If optional (prefix) argument BACKWARD is non-nil, do backward instead."
  3053.   (interactive
  3054.    (list (let ((completion-ignore-case t))
  3055.        (completing-read "Field name: "
  3056.                 '(("Number")("Subject")("From")
  3057.                   ("Lines")("Date")("Id")
  3058.                   ("Xref")("References"))
  3059.                 nil 'require-match))
  3060.      (read-string "Regexp: ")
  3061.      (read-key-sequence "Command: ")
  3062.      current-prefix-arg))
  3063.   ;; Hidden thread subtrees must be searched for ,too.
  3064.   (gnus-summary-show-all-threads)
  3065.   ;; We don't want to change current point nor window configuration.
  3066.   (save-excursion
  3067.     (save-window-excursion
  3068.       (message "Executing %s..." (key-description command))
  3069.       ;; We'd like to execute COMMAND interactively so as to give arguments.
  3070.       (gnus-execute field regexp
  3071.             (` (lambda ()
  3072.              (call-interactively '(, (key-binding command)))))
  3073.             backward)
  3074.       (message "Executing %s... done" (key-description command)))))
  3075.  
  3076. (defun gnus-summary-beginning-of-article ()
  3077.   "Go to beginning of article body"
  3078.   (interactive)
  3079.   (gnus-summary-select-article)
  3080.   (gnus-eval-in-buffer-window gnus-article-buffer
  3081.     (widen)
  3082.     (beginning-of-buffer)
  3083.     (if gnus-break-pages
  3084.     (gnus-narrow-to-page))
  3085.     ))
  3086.  
  3087. (defun gnus-summary-end-of-article ()
  3088.   "Go to end of article body"
  3089.   (interactive)
  3090.   (gnus-summary-select-article)
  3091.   (gnus-eval-in-buffer-window gnus-article-buffer
  3092.     (widen)
  3093.     (end-of-buffer)
  3094.     (if gnus-break-pages
  3095.     (gnus-narrow-to-page))
  3096.     ))
  3097.  
  3098. (defun gnus-summary-goto-article (article &optional all-headers)
  3099.   "Read ARTICLE if exists.
  3100. Optional argument ALL-HEADERS means all headers are shown."
  3101.   (interactive
  3102.    (list
  3103.     (string-to-int
  3104.      (completing-read "Article number: "
  3105.               (mapcar
  3106.                (function
  3107.             (lambda (headers)
  3108.               (list
  3109.                (int-to-string (nntp-header-number headers)))))
  3110.                gnus-newsgroup-headers)
  3111.               nil 'require-match))))
  3112.   (if (gnus-summary-goto-subject article)
  3113.       (gnus-summary-display-article article all-headers)))
  3114.  
  3115. (defun gnus-summary-goto-last-article ()
  3116.   "Go to last subject line."
  3117.   (interactive)
  3118.   (if gnus-last-article
  3119.       (gnus-summary-goto-article gnus-last-article)))
  3120.  
  3121. (defun gnus-summary-show-article ()
  3122.   "Force to show current article."
  3123.   (interactive)
  3124.   ;; The following is a trick to force to read the current article again.
  3125.   (setq gnus-have-all-headers (not gnus-have-all-headers))
  3126.   (gnus-summary-select-article (not gnus-have-all-headers) t))
  3127.  
  3128. (defun gnus-summary-toggle-header (arg)
  3129.   "Show original header if pruned header currently shown, or vice versa.
  3130. With arg, show original header iff arg is positive."
  3131.   (interactive "P")
  3132.   ;; Variable gnus-show-all-headers must be NIL to toggle really.
  3133.   (let ((gnus-show-all-headers nil)
  3134.     (all-headers
  3135.      (if (null arg) (not gnus-have-all-headers)
  3136.        (> (prefix-numeric-value arg) 0))))
  3137.     (gnus-summary-select-article all-headers t)))
  3138.  
  3139. (defun gnus-summary-show-all-headers ()
  3140.   "Show original article header."
  3141.   (interactive)
  3142.   (gnus-summary-select-article t t))
  3143.  
  3144. (defun gnus-summary-toggle-mime (arg)
  3145.   "Toggle MIME processing.
  3146. With arg, turn MIME processing on iff arg is positive."
  3147.   (interactive "P")
  3148.   (setq gnus-show-mime
  3149.     (if (null arg) (not gnus-show-mime)
  3150.       (> (prefix-numeric-value arg) 0)))
  3151.   ;; The following is a trick to force to read the current article again.
  3152.   (setq gnus-have-all-headers (not gnus-have-all-headers))
  3153.   (gnus-summary-select-article (not gnus-have-all-headers) t))
  3154.  
  3155. (defun gnus-summary-stop-page-breaking ()
  3156.   "Stop page breaking by linefeed temporary (Widen article buffer)."
  3157.   (interactive)
  3158.   (gnus-summary-select-article)
  3159.   (gnus-eval-in-buffer-window gnus-article-buffer
  3160.     (widen)
  3161.     ))
  3162.  
  3163. (defun gnus-summary-kill-same-subject-and-select (unmark)
  3164.   "Mark articles which has the same subject as read, and then select next.
  3165. If argument UNMARK is positive, remove any kinds of marks.
  3166. If argument UNMARK is negative, mark articles as unread instead."
  3167.   (interactive "P")
  3168.   (if unmark
  3169.       (setq unmark (prefix-numeric-value unmark)))
  3170.   (let ((count
  3171.      (gnus-summary-mark-same-subject
  3172.       (gnus-summary-subject-string) unmark)))
  3173.     ;; Select next unread article. If auto-select-same mode, should
  3174.     ;; select the first unread article.
  3175.     (gnus-summary-next-article t (and gnus-auto-select-same
  3176.                       (gnus-summary-subject-string)))
  3177.     (message "%d articles are marked as %s"
  3178.          count (if unmark "unread" "read"))
  3179.     ))
  3180.  
  3181. (defun gnus-summary-kill-same-subject (unmark)
  3182.   "Mark articles which has the same subject as read. 
  3183. If argument UNMARK is positive, remove any kinds of marks.
  3184. If argument UNMARK is negative, mark articles as unread instead."
  3185.   (interactive "P")
  3186.   (if unmark
  3187.       (setq unmark (prefix-numeric-value unmark)))
  3188.   (let ((count
  3189.      (gnus-summary-mark-same-subject
  3190.       (gnus-summary-subject-string) unmark)))
  3191.     ;; If marked as read, go to next unread subject.
  3192.     (if (null unmark)
  3193.     ;; Go to next unread subject.
  3194.     (gnus-summary-next-subject 1 t))
  3195.     (message "%d articles are marked as %s"
  3196.          count (if unmark "unread" "read"))
  3197.     ))
  3198.  
  3199. (defun gnus-summary-mark-same-subject (subject &optional unmark)
  3200.   "Mark articles with same SUBJECT as read, and return marked number.
  3201. If optional argument UNMARK is positive, remove any kinds of marks.
  3202. If optional argument UNMARK is negative, mark articles as unread instead."
  3203.   (let ((count 1))
  3204.     (save-excursion
  3205.       (cond ((null unmark)
  3206.          (gnus-summary-mark-as-read nil "K"))
  3207.         ((> unmark 0)
  3208.          (gnus-summary-mark-as-unread nil t))
  3209.         (t
  3210.          (gnus-summary-mark-as-unread)))
  3211.       (while (and subject
  3212.           (gnus-summary-search-forward nil subject))
  3213.     (cond ((null unmark)
  3214.            (gnus-summary-mark-as-read nil "K"))
  3215.           ((> unmark 0)
  3216.            (gnus-summary-mark-as-unread nil t))
  3217.           (t
  3218.            (gnus-summary-mark-as-unread)))
  3219.     (setq count (1+ count))
  3220.     ))
  3221.     ;; Hide killed thread subtrees.  Does not work properly always.
  3222.     ;;(and (null unmark)
  3223.     ;;     gnus-thread-hide-killed
  3224.     ;;       (gnus-summary-hide-thread))
  3225.     ;; Return number of articles marked as read.
  3226.     count
  3227.     ))
  3228.  
  3229. (defun gnus-summary-mark-as-unread-forward (count)
  3230.   "Mark current article as unread, and then go forward.
  3231. Argument COUNT specifies number of articles marked as unread."
  3232.   (interactive "p")
  3233.   (while (> count 0)
  3234.     (gnus-summary-mark-as-unread nil nil)
  3235.     (gnus-summary-next-subject 1 nil)
  3236.     (setq count (1- count))))
  3237.  
  3238. (defun gnus-summary-mark-as-unread-backward (count)
  3239.   "Mark current article as unread, and then go backward.
  3240. Argument COUNT specifies number of articles marked as unread."
  3241.   (interactive "p")
  3242.   (while (> count 0)
  3243.     (gnus-summary-mark-as-unread nil nil)
  3244.     (gnus-summary-prev-subject 1 nil)
  3245.     (setq count (1- count))))
  3246.  
  3247. (defun gnus-summary-mark-as-unread (&optional article clear-mark)
  3248.   "Mark current article as unread.
  3249. Optional 1st argument ARTICLE specifies article number to be marked as unread.
  3250. Optional 2nd argument CLEAR-MARK remove any kinds of mark."
  3251.   (save-excursion
  3252.     (set-buffer gnus-summary-buffer)
  3253.     ;; First of all, show hidden thread subtrees.
  3254.     (gnus-summary-show-thread)
  3255.     (let* ((buffer-read-only nil)
  3256.        (current (gnus-summary-article-number))
  3257.        (article (or article current)))
  3258.       (gnus-mark-article-as-unread article clear-mark)
  3259.       (if (or (eq article current)
  3260.           (gnus-summary-goto-subject article))
  3261.       (progn
  3262.         (beginning-of-line)
  3263.         (delete-char 1)
  3264.         (insert (if clear-mark " " "-"))))
  3265.       )))
  3266.  
  3267. (defun gnus-summary-mark-as-read-forward (count)
  3268.   "Mark current article as read, and then go forward.
  3269. Argument COUNT specifies number of articles marked as read"
  3270.   (interactive "p")
  3271.   (while (> count 0)
  3272.     (gnus-summary-mark-as-read)
  3273.     (gnus-summary-next-subject 1 'unread-only)
  3274.     (setq count (1- count))))
  3275.  
  3276. (defun gnus-summary-mark-as-read-backward (count)
  3277.   "Mark current article as read, and then go backward.
  3278. Argument COUNT specifies number of articles marked as read"
  3279.   (interactive "p")
  3280.   (while (> count 0)
  3281.     (gnus-summary-mark-as-read)
  3282.     (gnus-summary-prev-subject 1 'unread-only)
  3283.     (setq count (1- count))))
  3284.  
  3285. (defun gnus-summary-mark-as-read (&optional article mark)
  3286.   "Mark current article as read.
  3287. Optional 1st argument ARTICLE specifies article number to be marked as read.
  3288. Optional 2nd argument MARK specifies a string inserted at beginning of line.
  3289. Any kind of string (length 1) except for a space and `-' is ok."
  3290.   (save-excursion
  3291.     (set-buffer gnus-summary-buffer)
  3292.     ;; First of all, show hidden thread subtrees.
  3293.     (gnus-summary-show-thread)
  3294.     (let* ((buffer-read-only nil)
  3295.        (mark (or mark "D"))        ;Default mark is `D'.
  3296.        (current (gnus-summary-article-number))
  3297.        (article (or article current)))
  3298.       (gnus-mark-article-as-read article)
  3299.       (if (or (eq article current)
  3300.           (gnus-summary-goto-subject article))
  3301.       (progn
  3302.         (beginning-of-line)
  3303.         (delete-char 1)
  3304.         (insert mark)))
  3305.       )))
  3306.  
  3307. (defun gnus-summary-clear-mark-forward (count)
  3308.   "Remove current article's mark, and go forward.
  3309. Argument COUNT specifies number of articles unmarked"
  3310.   (interactive "p")
  3311.   (while (> count 0)
  3312.     (gnus-summary-mark-as-unread nil t)
  3313.     (gnus-summary-next-subject 1 nil)
  3314.     (setq count (1- count))))
  3315.  
  3316. (defun gnus-summary-clear-mark-backward (count)
  3317.   "Remove current article's mark, and go backward.
  3318. Argument COUNT specifies number of articles unmarked"
  3319.   (interactive "p")
  3320.   (while (> count 0)
  3321.     (gnus-summary-mark-as-unread nil t)
  3322.     (gnus-summary-prev-subject 1 nil)
  3323.     (setq count (1- count))))
  3324.  
  3325. (defun gnus-summary-delete-marked-as-read ()
  3326.   "Delete lines which is marked as read."
  3327.   (interactive)
  3328.   (if gnus-newsgroup-unreads
  3329.       (let ((buffer-read-only nil))
  3330.     (save-excursion
  3331.       (goto-char (point-min))
  3332.       (delete-non-matching-lines "^[- ]"))
  3333.     ;; Adjust point.
  3334.     (if (eobp)
  3335.         (gnus-summary-prev-subject 1)
  3336.       (beginning-of-line)
  3337.       (search-forward ":" nil t)))
  3338.     ;; It is not so good idea to make the buffer empty.
  3339.     (message "All articles are marked as read")
  3340.     ))
  3341.  
  3342. (defun gnus-summary-delete-marked-with (marks)
  3343.   "Delete lines which are marked with MARKS (e.g. \"DK\")."
  3344.   (interactive "sMarks: ")
  3345.   (let ((buffer-read-only nil))
  3346.     (save-excursion
  3347.       (goto-char (point-min))
  3348.       (delete-matching-lines (concat "^[" marks "]")))
  3349.     ;; Adjust point.
  3350.     (or (zerop (buffer-size))
  3351.     (if (eobp)
  3352.         (gnus-summary-prev-subject 1)
  3353.       (beginning-of-line)
  3354.       (search-forward ":" nil t)))
  3355.     ))
  3356.  
  3357. ;; Thread-based commands.
  3358.  
  3359. (defun gnus-summary-toggle-threads (arg)
  3360.   "Toggle showing conversation threads.
  3361. With arg, turn showing conversation threads on iff arg is positive."
  3362.   (interactive "P")
  3363.   (let ((current (gnus-summary-article-number)))
  3364.     (setq gnus-show-threads
  3365.       (if (null arg) (not gnus-show-threads)
  3366.         (> (prefix-numeric-value arg) 0)))
  3367.     (gnus-summary-prepare)
  3368.     (gnus-summary-goto-subject current)
  3369.     ))
  3370.  
  3371. (defun gnus-summary-show-all-threads ()
  3372.   "Show all thread subtrees."
  3373.   (interactive)
  3374.   (if gnus-show-threads
  3375.       (save-excursion
  3376.     (let ((buffer-read-only nil))
  3377.       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)
  3378.       ))))
  3379.  
  3380. (defun gnus-summary-show-thread ()
  3381.   "Show thread subtrees."
  3382.   (interactive)
  3383.   (if gnus-show-threads
  3384.       (save-excursion
  3385.     (let ((buffer-read-only nil))
  3386.       (subst-char-in-region (progn
  3387.                   (beginning-of-line) (point))
  3388.                 (progn
  3389.                   (end-of-line) (point))
  3390.                 ?\^M ?\n t)
  3391.       ))))
  3392.  
  3393. (defun gnus-summary-hide-all-threads ()
  3394.   "Hide all thread subtrees."
  3395.   (interactive)
  3396.   (if gnus-show-threads
  3397.       (save-excursion
  3398.     ;; Adjust cursor point.
  3399.     (goto-char (point-min))
  3400.     (search-forward ":" nil t)
  3401.     (let ((level (current-column)))
  3402.       (gnus-summary-hide-thread)
  3403.       (while (gnus-summary-search-forward)
  3404.         (and (>= level (current-column))
  3405.          (gnus-summary-hide-thread)))
  3406.       ))))
  3407.  
  3408. (defun gnus-summary-hide-thread ()
  3409.   "Hide thread subtrees."
  3410.   (interactive)
  3411.   (if gnus-show-threads
  3412.       (save-excursion
  3413.     ;; Adjust cursor point.
  3414.     (beginning-of-line)
  3415.     (search-forward ":" nil t)
  3416.     (let ((buffer-read-only nil)
  3417.           (init (point))
  3418.           (last (point))
  3419.           (level (current-column)))
  3420.       (while (and (gnus-summary-search-forward)
  3421.               (< level (current-column)))
  3422.         ;; Interested in lower levels.
  3423.         (if (< level (current-column))
  3424.         (progn
  3425.           (setq last (point))
  3426.           ))
  3427.         )
  3428.       (subst-char-in-region init last ?\n ?\^M t)
  3429.       ))))
  3430.  
  3431. (defun gnus-summary-next-thread (n)
  3432.   "Go to the same level next thread.
  3433. Argument N specifies the number of threads."
  3434.   (interactive "p")
  3435.   ;; Adjust cursor point.
  3436.   (beginning-of-line)
  3437.   (search-forward ":" nil t)
  3438.   (let ((init (point))
  3439.     (last (point))
  3440.     (level (current-column)))
  3441.     (while (and (> n 0)
  3442.         (gnus-summary-search-forward)
  3443.         (<= level (current-column)))
  3444.       ;; We have to skip lower levels.
  3445.       (if (= level (current-column))
  3446.       (progn
  3447.         (setq last (point))
  3448.         (setq n (1- n))
  3449.         ))
  3450.       )
  3451.     ;; Return non-nil if successfully move to the next.
  3452.     (prog1 (not (= init last))
  3453.       (goto-char last))
  3454.     ))
  3455.  
  3456. (defun gnus-summary-prev-thread (n)
  3457.   "Go to the same level previous thread.
  3458. Argument N specifies the number of threads."
  3459.   (interactive "p")
  3460.   ;; Adjust cursor point.
  3461.   (beginning-of-line)
  3462.   (search-forward ":" nil t)
  3463.   (let ((init (point))
  3464.     (last (point))
  3465.     (level (current-column)))
  3466.     (while (and (> n 0)
  3467.         (gnus-summary-search-backward)
  3468.         (<= level (current-column)))
  3469.       ;; We have to skip lower levels.
  3470.       (if (= level (current-column))
  3471.       (progn
  3472.         (setq last (point))
  3473.         (setq n (1- n))
  3474.         ))
  3475.       )
  3476.     ;; Return non-nil if successfully move to the previous.
  3477.     (prog1 (not (= init last))
  3478.       (goto-char last))
  3479.     ))
  3480.  
  3481. (defun gnus-summary-down-thread (d)
  3482.   "Go downward current thread.
  3483. Argument D specifies the depth goes down."
  3484.   (interactive "p")
  3485.   ;; Adjust cursor point.
  3486.   (beginning-of-line)
  3487.   (search-forward ":" nil t)
  3488.   (let ((last (point))
  3489.     (level (current-column)))
  3490.     (while (and (> d 0)
  3491.         (gnus-summary-search-forward)
  3492.         (<= level (current-column))) ;<= can be <.  Which do you like?
  3493.       ;; We have to skip the same levels.
  3494.       (if (< level (current-column))
  3495.       (progn
  3496.         (setq last (point))
  3497.         (setq level (current-column))
  3498.         (setq d (1- d))
  3499.         ))
  3500.       )
  3501.     (goto-char last)
  3502.     ))
  3503.  
  3504. (defun gnus-summary-up-thread (d)
  3505.   "Go upward current thread.
  3506. Argument D specifies the depth goes up."
  3507.   (interactive "p")
  3508.   ;; Adjust cursor point.
  3509.   (beginning-of-line)
  3510.   (search-forward ":" nil t)
  3511.   (let ((last (point))
  3512.     (level (current-column)))
  3513.     (while (and (> d 0)
  3514.         (gnus-summary-search-backward))
  3515.       ;; We have to skip the same levels.
  3516.       (if (> level (current-column))
  3517.       (progn
  3518.         (setq last (point))
  3519.         (setq level (current-column))
  3520.         (setq d (1- d))
  3521.         ))
  3522.       )
  3523.     (goto-char last)
  3524.     ))
  3525.  
  3526. (defun gnus-summary-kill-thread (unmark)
  3527.   "Mark articles under current thread as read.
  3528. If argument UNMARK is positive, remove any kinds of marks.
  3529. If argument UNMARK is negative, mark articles as unread instead."
  3530.   (interactive "P")
  3531.   (if unmark
  3532.       (setq unmark (prefix-numeric-value unmark)))
  3533.   ;; Adjust cursor point.
  3534.   (beginning-of-line)
  3535.   (search-forward ":" nil t)
  3536.   (save-excursion
  3537.     (let ((level (current-column)))
  3538.       ;; Mark current article.
  3539.       (cond ((null unmark)
  3540.          (gnus-summary-mark-as-read nil "K"))
  3541.         ((> unmark 0)
  3542.          (gnus-summary-mark-as-unread nil t))
  3543.         (t
  3544.          (gnus-summary-mark-as-unread))
  3545.         )
  3546.       ;; Mark following articles.
  3547.       (while (and (gnus-summary-search-forward)
  3548.           (< level (current-column)))
  3549.     (cond ((null unmark)
  3550.            (gnus-summary-mark-as-read nil "K"))
  3551.           ((> unmark 0)
  3552.            (gnus-summary-mark-as-unread nil t))
  3553.           (t
  3554.            (gnus-summary-mark-as-unread))
  3555.           ))
  3556.       ))
  3557.   ;; Hide killed subtrees.
  3558.   (and (null unmark)
  3559.        gnus-thread-hide-killed
  3560.        (gnus-summary-hide-thread))
  3561.   ;; If marked as read, go to next unread subject.
  3562.   (if (null unmark)
  3563.       ;; Go to next unread subject.
  3564.       (gnus-summary-next-subject 1 t))
  3565.   )
  3566.  
  3567. (defun gnus-summary-toggle-truncation (arg)
  3568.   "Toggle truncation of summary lines.
  3569. With arg, turn line truncation on iff arg is positive."
  3570.   (interactive "P")
  3571.   (setq truncate-lines
  3572.     (if (null arg) (not truncate-lines)
  3573.       (> (prefix-numeric-value arg) 0)))
  3574.   (redraw-display))
  3575.  
  3576. (defun gnus-summary-sort-by-number (reverse)
  3577.   "Sort Summary buffer by article number.
  3578. Argument REVERSE means reverse order."
  3579.   (interactive "P")
  3580.   (gnus-summary-keysort-summary
  3581.    (function <)
  3582.    (function
  3583.     (lambda (a)
  3584.       (nntp-header-number a)))
  3585.    reverse
  3586.    ))
  3587.  
  3588. (defun gnus-summary-sort-by-author (reverse)
  3589.   "Sort Summary buffer by author name alphabetically.
  3590. If case-fold-search is non-nil, case of letters is ignored.
  3591. Argument REVERSE means reverse order."
  3592.   (interactive "P")
  3593.   (gnus-summary-keysort-summary
  3594.    (function string-lessp)
  3595.    (function
  3596.     (lambda (a)
  3597.       (if case-fold-search
  3598.       (downcase (nntp-header-from a))
  3599.     (nntp-header-from a))))
  3600.    reverse
  3601.    ))
  3602.  
  3603. (defun gnus-summary-sort-by-subject (reverse)
  3604.   "Sort Summary buffer by subject alphabetically. `Re:'s are ignored.
  3605. If case-fold-search is non-nil, case of letters is ignored.
  3606. Argument REVERSE means reverse order."
  3607.   (interactive "P")
  3608.   (gnus-summary-keysort-summary
  3609.    (function string-lessp)
  3610.    (function
  3611.     (lambda (a)
  3612.       (if case-fold-search
  3613.       (downcase (gnus-simplify-subject (nntp-header-subject a) 're-only))
  3614.     (gnus-simplify-subject (nntp-header-subject a) 're-only))))
  3615.    reverse
  3616.    ))
  3617.  
  3618. (defun gnus-summary-sort-by-date (reverse)
  3619.   "Sort Summary buffer by date.
  3620. Argument REVERSE means reverse order."
  3621.   (interactive "P")
  3622.   (gnus-summary-keysort-summary
  3623.    (function string-lessp)
  3624.    (function
  3625.     (lambda (a)
  3626.       (gnus-sortable-date (nntp-header-date a))))
  3627.    reverse
  3628.    ))
  3629.  
  3630. (defun gnus-summary-keysort-summary (predicate key &optional reverse)
  3631.   "Sort Summary buffer by PREDICATE using a value passed by KEY.
  3632. Optional argument REVERSE means reverse order."
  3633.   (let ((current (gnus-summary-article-number)))
  3634.     (gnus-keysort-headers predicate key reverse)
  3635.     (gnus-summary-prepare)
  3636.     (gnus-summary-goto-subject current)
  3637.     ))
  3638.  
  3639. (defun gnus-summary-sort-summary (predicate &optional reverse)
  3640.   "Sort Summary buffer by PREDICATE.
  3641. Optional argument REVERSE means reverse order."
  3642.   (let ((current (gnus-summary-article-number)))
  3643.     (gnus-sort-headers predicate reverse)
  3644.     (gnus-summary-prepare)
  3645.     (gnus-summary-goto-subject current)
  3646.     ))
  3647.  
  3648. (defun gnus-summary-reselect-current-group (show-all)
  3649.   "Once exit and then reselect the current newsgroup.
  3650. Prefix argument SHOW-ALL means to select all articles."
  3651.   (interactive "P")
  3652.   (let ((current-subject (gnus-summary-article-number)))
  3653.     (gnus-summary-exit t)
  3654.     ;; We have to adjust the point of Group mode buffer because the
  3655.     ;; current point was moved to the next unread newsgroup by
  3656.     ;; exiting.
  3657.     (gnus-summary-jump-to-group gnus-newsgroup-name)
  3658.     (gnus-group-read-group show-all t)
  3659.     (gnus-summary-goto-subject current-subject)
  3660.     ))
  3661.  
  3662. (defun gnus-summary-caesar-message (rotnum)
  3663.   "Caesar rotates all letters of current message by 13/47 places.
  3664. With prefix arg, specifies the number of places to rotate each letter forward.
  3665. Caesar rotates Japanese letters by 47 places in any case."
  3666.   (interactive "P")
  3667.   (gnus-summary-select-article)
  3668.   (gnus-overload-functions)
  3669.   (gnus-eval-in-buffer-window gnus-article-buffer
  3670.     (save-restriction
  3671.       (widen)
  3672.       ;; We don't want to jump to the beginning of the message.
  3673.       ;; `save-excursion' does not do its job.
  3674.       (move-to-window-line 0)
  3675.       (let ((last (point)))
  3676.     (news-caesar-buffer-body rotnum)
  3677.     (goto-char last)
  3678.     (recenter 0)
  3679.     ))
  3680.     ))
  3681.  
  3682. (defun gnus-summary-rmail-digest ()
  3683.   "Run RMAIL on current digest article.
  3684. gnus-select-digest-hook will be called with no arguments, if that
  3685. value is non-nil. It is possible to modify the article so that Rmail
  3686. can work with it.
  3687. gnus-rmail-digest-hook will be called with no arguments, if that value
  3688. is non-nil. The hook is intended to customize Rmail mode."
  3689.   (interactive)
  3690.   (gnus-summary-select-article)
  3691.   (require 'rmail)
  3692.   (let ((artbuf gnus-article-buffer)
  3693.     (digbuf (get-buffer-create gnus-digest-buffer))
  3694.     (mail-header-separator ""))
  3695.     (set-buffer digbuf)
  3696.     (buffer-flush-undo (current-buffer))
  3697.     (setq buffer-read-only nil)
  3698.     (erase-buffer)
  3699.     (insert-buffer-substring artbuf)
  3700.     (run-hooks 'gnus-select-digest-hook)
  3701.     (gnus-convert-article-to-rmail)
  3702.     (goto-char (point-min))
  3703.     ;; Rmail initializations.
  3704.     (rmail-insert-rmail-file-header)
  3705.     (rmail-mode)
  3706.     (rmail-set-message-counters)
  3707.     (rmail-show-message)
  3708.     (condition-case ()
  3709.     (progn
  3710.       (undigestify-rmail-message)
  3711.       (rmail-expunge)        ;Delete original message.
  3712.       ;; File name is meaningless but `save-buffer' requires it.
  3713.       (setq buffer-file-name "GNUS Digest")
  3714.       (setq mode-line-buffer-identification
  3715.         (concat "Digest: "
  3716.             (nntp-header-subject gnus-current-headers)))
  3717.       ;; There is no need to write this buffer to a file.
  3718.       (make-local-variable 'write-file-hooks)
  3719.       (setq write-file-hooks
  3720.         (list (function
  3721.                (lambda ()
  3722.              (set-buffer-modified-p nil)
  3723.              (message "(No changes need to be saved)")
  3724.              'no-need-to-write-this-buffer))))
  3725.       ;; Default file name saving digest messages.
  3726.       (setq rmail-default-rmail-file
  3727.         (funcall gnus-rmail-save-name
  3728.              gnus-newsgroup-name
  3729.              gnus-current-headers
  3730.              gnus-newsgroup-last-rmail
  3731.              ))
  3732.       (setq rmail-default-file
  3733.         (funcall gnus-mail-save-name
  3734.              gnus-newsgroup-name
  3735.              gnus-current-headers
  3736.              gnus-newsgroup-last-mail
  3737.              ))
  3738.       ;; Prevent generating new buffer named ***<N> each time.
  3739.       (setq rmail-summary-buffer
  3740.         (get-buffer-create gnus-digest-summary-buffer))
  3741.       (run-hooks 'gnus-rmail-digest-hook)
  3742.       ;; Take all windows safely.
  3743.       (gnus-configure-windows '(1 0 0))
  3744.       (pop-to-buffer gnus-group-buffer)
  3745.       ;; Use Summary Article windows for Digest summary and
  3746.       ;; Digest buffers.
  3747.       (if gnus-digest-show-summary
  3748.           (let ((gnus-summary-buffer gnus-digest-summary-buffer)
  3749.             (gnus-article-buffer gnus-digest-buffer))
  3750.         (gnus-configure-windows 'article)
  3751.         (pop-to-buffer gnus-digest-buffer)
  3752.         (rmail-summary)
  3753.         (pop-to-buffer gnus-digest-summary-buffer)
  3754.         (message (substitute-command-keys
  3755.               "Type \\[rmail-summary-quit] to return to GNUS")))
  3756.         (let ((gnus-summary-buffer gnus-digest-buffer))
  3757.           (gnus-configure-windows 'summary)
  3758.           (pop-to-buffer gnus-digest-buffer)
  3759.           (message (substitute-command-keys
  3760.             "Type \\[rmail-quit] to return to GNUS")))
  3761.         )
  3762.       ;; Move the buffers to the end of buffer list.
  3763.       (bury-buffer gnus-article-buffer)
  3764.       (bury-buffer gnus-group-buffer)
  3765.       (bury-buffer gnus-digest-summary-buffer)
  3766.       (bury-buffer gnus-digest-buffer))
  3767.       (error (set-buffer-modified-p nil)
  3768.          (kill-buffer digbuf)
  3769.          ;; This command should not signal an error because the
  3770.          ;; command is called from hooks.
  3771.          (ding) (message "Article is not a digest")))
  3772.     ))
  3773.  
  3774. (defun gnus-summary-save-article ()
  3775.   "Save this article using default saver function.
  3776. The variable `gnus-default-article-saver' specifies the saver function."
  3777.   (interactive)
  3778.   (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers)
  3779.   (if gnus-default-article-saver
  3780.       (call-interactively gnus-default-article-saver)
  3781.     (error "No default saver is defined.")))
  3782.  
  3783. (defun gnus-summary-save-in-rmail (&optional filename)
  3784.   "Append this article to Rmail file.
  3785. Optional argument FILENAME specifies file name.
  3786. Directory to save to is default to `gnus-article-save-directory' which
  3787. is initialized from the SAVEDIR environment variable."
  3788.   (interactive)
  3789.   (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers)
  3790.   (gnus-eval-in-buffer-window gnus-article-buffer
  3791.     (save-excursion
  3792.       (save-restriction
  3793.     (widen)
  3794.     (let ((default-name
  3795.         (funcall gnus-rmail-save-name
  3796.              gnus-newsgroup-name
  3797.              gnus-current-headers
  3798.              gnus-newsgroup-last-rmail
  3799.              )))
  3800.       (or filename
  3801.           (setq filename
  3802.             (read-file-name
  3803.              (concat "Save article in Rmail file: (default "
  3804.                  (file-name-nondirectory default-name)
  3805.                  ") ")
  3806.              (file-name-directory default-name)
  3807.              default-name)))
  3808.       (gnus-make-directory (file-name-directory filename))
  3809.       (gnus-output-to-rmail filename)
  3810.       ;; Remember the directory name to save articles.
  3811.       (setq gnus-newsgroup-last-rmail filename)
  3812.       )))
  3813.     ))
  3814.  
  3815. (defun gnus-summary-save-in-mail (&optional filename)
  3816.   "Append this article to Unix mail file.
  3817. Optional argument FILENAME specifies file name.
  3818. Directory to save to is default to `gnus-article-save-directory' which
  3819. is initialized from the SAVEDIR environment variable."
  3820.   (interactive)
  3821.   (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers)
  3822.   (gnus-eval-in-buffer-window gnus-article-buffer
  3823.     (save-excursion
  3824.       (save-restriction
  3825.     (widen)
  3826.     (let ((default-name
  3827.         (funcall gnus-mail-save-name
  3828.              gnus-newsgroup-name
  3829.              gnus-current-headers
  3830.              gnus-newsgroup-last-mail
  3831.              )))
  3832.       (or filename
  3833.           (setq filename
  3834.             (read-file-name
  3835.              (concat "Save article in Unix mail file: (default "
  3836.                  (file-name-nondirectory default-name)
  3837.                  ") ")
  3838.              (file-name-directory default-name)
  3839.              default-name)))
  3840.       (setq filename
  3841.         (expand-file-name filename
  3842.                   (and default-name
  3843.                        (file-name-directory default-name))))
  3844.       (gnus-make-directory (file-name-directory filename))
  3845.       (if (and (file-readable-p filename) (rmail-file-p filename))
  3846.           (gnus-output-to-rmail filename)
  3847.         (rmail-output filename 1 t t))
  3848.       ;; Remember the directory name to save articles.
  3849.       (setq gnus-newsgroup-last-mail filename)
  3850.       )))
  3851.     ))
  3852.  
  3853. (defun gnus-summary-save-in-file (&optional filename)
  3854.   "Append this article to file.
  3855. Optional argument FILENAME specifies file name.
  3856. Directory to save to is default to `gnus-article-save-directory' which
  3857. is initialized from the SAVEDIR environment variable."
  3858.   (interactive)
  3859.   (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers)
  3860.   (gnus-eval-in-buffer-window gnus-article-buffer
  3861.     (save-excursion
  3862.       (save-restriction
  3863.     (widen)
  3864.     (let ((default-name
  3865.         (funcall gnus-file-save-name
  3866.              gnus-newsgroup-name
  3867.              gnus-current-headers
  3868.              gnus-newsgroup-last-file
  3869.              )))
  3870.       (or filename
  3871.           (setq filename
  3872.             (read-file-name
  3873.              (concat "Save article in file: (default "
  3874.                  (file-name-nondirectory default-name)
  3875.                  ") ")
  3876.              (file-name-directory default-name)
  3877.              default-name)))
  3878.       (gnus-make-directory (file-name-directory filename))
  3879.       (gnus-output-to-file filename)
  3880.       ;; Remember the directory name to save articles.
  3881.       (setq gnus-newsgroup-last-file filename)
  3882.       )))
  3883.     ))
  3884.  
  3885. (defun gnus-summary-save-in-folder (&optional folder)
  3886.   "Save this article to MH folder (using `rcvstore' in MH library).
  3887. Optional argument FOLDER specifies folder name."
  3888.   (interactive)
  3889.   (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers)
  3890.   (gnus-eval-in-buffer-window gnus-article-buffer
  3891.     (save-restriction
  3892.       (widen)
  3893.       ;; Thanks to yuki@flab.Fujitsu.JUNET and ohm@kaba.junet.
  3894.       (mh-find-path)
  3895.       (let ((folder
  3896.          (or folder
  3897.          (mh-prompt-for-folder "Save article in"
  3898.                        (funcall gnus-folder-save-name
  3899.                         gnus-newsgroup-name
  3900.                         gnus-current-headers
  3901.                         gnus-newsgroup-last-folder
  3902.                         )
  3903.                        t
  3904.                        )))
  3905.         (errbuf (get-buffer-create " *GNUS rcvstore*")))
  3906.     (unwind-protect
  3907.         (call-process-region (point-min) (point-max)
  3908.                  (expand-file-name "rcvstore" mh-lib)
  3909.                  nil errbuf nil folder)
  3910.       (set-buffer errbuf)
  3911.       (if (zerop (buffer-size))
  3912.           (message "Article saved in folder: %s" folder)
  3913.         (message "%s" (buffer-string)))
  3914.       (kill-buffer errbuf)
  3915.       (setq gnus-newsgroup-last-folder folder))
  3916.     ))
  3917.     ))
  3918.  
  3919. (defun gnus-summary-pipe-output ()
  3920.   "Pipe this article to subprocess."
  3921.   (interactive)
  3922.   ;; Ignore `gnus-save-all-headers' since this is not save command.
  3923.   ;;(gnus-summary-select-article)
  3924.   ;; Huuum.  Is this right?
  3925.   (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers)
  3926.   (gnus-eval-in-buffer-window gnus-article-buffer
  3927.     (save-restriction
  3928.       (widen)
  3929.       (let ((command (read-string "Shell command on article: "
  3930.                   gnus-last-shell-command)))
  3931.     (if (string-equal command "")
  3932.         (setq command gnus-last-shell-command))
  3933.     (shell-command-on-region (point-min) (point-max) command nil)
  3934.     (setq gnus-last-shell-command command)
  3935.     ))
  3936.     ))
  3937.  
  3938. (defun gnus-summary-catchup (all &optional quietly)
  3939.   "Mark all articles not marked as unread in this newsgroup as read.
  3940. If prefix argument ALL is non-nil, all articles are marked as read."
  3941.   (interactive "P")
  3942.   (if (or quietly
  3943.       (not gnus-interactive-catchup) ;Without confirmation?
  3944.       (y-or-n-p
  3945.        (if all
  3946.            "Do you really want to mark everything as read? "
  3947.          "Delete all articles not marked as unread? ")))
  3948.       (let ((unmarked
  3949.          (gnus-set-difference gnus-newsgroup-unreads
  3950.                   (if (not all) gnus-newsgroup-marked))))
  3951.         (message "")            ;Erase "Yes or No" question.
  3952.     ;; Hidden thread subtrees must be searched for ,too.
  3953.     (gnus-summary-show-all-threads)
  3954.     (while unmarked
  3955.           (gnus-summary-mark-as-read (car unmarked) "C")
  3956.       (setq unmarked (cdr unmarked))
  3957.       ))
  3958.     ))
  3959.  
  3960. (defun gnus-summary-catchup-all (&optional quietly)
  3961.   "Mark all articles in this newsgroup as read."
  3962.   (interactive)
  3963.   (gnus-summary-catchup t quietly))
  3964.  
  3965. (defun gnus-summary-catchup-and-exit (all &optional quietly)
  3966.   "Mark all articles not marked as unread in this newsgroup as read, then exit.
  3967. If prefix argument ALL is non-nil, all articles are marked as read."
  3968.   (interactive "P")
  3969.   (if (or quietly
  3970.       (not gnus-interactive-catchup) ;Without confirmation?
  3971.       (y-or-n-p
  3972.        (if all
  3973.            "Do you really want to mark everything as read? "
  3974.          "Delete all articles not marked as unread? ")))
  3975.       (let ((unmarked
  3976.              (gnus-set-difference gnus-newsgroup-unreads
  3977.                                   (if (not all) gnus-newsgroup-marked))))
  3978.         (message "")            ;Erase "Yes or No" question.
  3979.     (while unmarked
  3980.           (gnus-mark-article-as-read (car unmarked))
  3981.       (setq unmarked (cdr unmarked)))
  3982.     ;; Select next newsgroup or exit.
  3983.     (cond ((eq gnus-auto-select-next 'quietly)
  3984.            ;; Select next newsgroup quietly.
  3985.            (gnus-summary-next-group nil))
  3986.           (t
  3987.            (gnus-summary-exit)))
  3988.     )))
  3989.  
  3990. (defun gnus-summary-catchup-all-and-exit (&optional quietly)
  3991.   "Mark all articles in this newsgroup as read, and then exit."
  3992.   (interactive)
  3993.   (gnus-summary-catchup-and-exit t quietly))
  3994.  
  3995. (defun gnus-summary-edit-global-kill ()
  3996.   "Edit a global KILL file."
  3997.   (interactive)
  3998.   (setq gnus-current-kill-article (gnus-summary-article-number))
  3999.   (gnus-kill-file-edit-file nil)    ;Nil stands for global KILL file.
  4000.   (message
  4001.    (substitute-command-keys
  4002.     "Editing a global KILL file (Type \\[gnus-kill-file-exit] to exit)")))
  4003.  
  4004. (defun gnus-summary-edit-local-kill ()
  4005.   "Edit a local KILL file applied to the current newsgroup."
  4006.   (interactive)
  4007.   (setq gnus-current-kill-article (gnus-summary-article-number))
  4008.   (gnus-kill-file-edit-file gnus-newsgroup-name)
  4009.   (message
  4010.    (substitute-command-keys
  4011.     "Editing a local KILL file (Type \\[gnus-kill-file-exit] to exit)")))
  4012.  
  4013. (defun gnus-summary-exit (&optional temporary)
  4014.   "Exit reading current newsgroup, and then return to group selection mode.
  4015. gnus-exit-group-hook is called with no arguments if that value is non-nil."
  4016.   (interactive)
  4017.   (let ((updated nil)
  4018.     (gnus-newsgroup-headers gnus-newsgroup-headers)
  4019.     (gnus-newsgroup-unreads gnus-newsgroup-unreads)
  4020.     (gnus-newsgroup-unselected gnus-newsgroup-unselected)
  4021.     (gnus-newsgroup-marked gnus-newsgroup-marked))
  4022.     ;; Important internal variables are saved, so we can reenter
  4023.     ;; Summary buffer even if hook changes them.
  4024.     (run-hooks 'gnus-exit-group-hook)
  4025.     (gnus-update-unread-articles gnus-newsgroup-name
  4026.                  (append gnus-newsgroup-unselected
  4027.                      gnus-newsgroup-unreads)
  4028.                  gnus-newsgroup-marked)
  4029.     ;; T means ignore unsubscribed newsgroups.
  4030.     (if gnus-use-cross-reference
  4031.     (setq updated
  4032.           (gnus-mark-as-read-by-xref gnus-newsgroup-name
  4033.                      gnus-newsgroup-headers
  4034.                      gnus-newsgroup-unreads
  4035.                      (eq gnus-use-cross-reference t)
  4036.                      )))
  4037.     ;; Do not switch windows but change the buffer to work.
  4038.     (set-buffer gnus-group-buffer)
  4039.     ;; Update cross referenced group info.
  4040.     (while updated
  4041.       (gnus-group-update-group (car updated) t) ;Ignore invisible group.
  4042.       (setq updated (cdr updated)))
  4043.     (gnus-group-update-group gnus-newsgroup-name))
  4044.   ;; Make sure where I was, and go to next newsgroup.
  4045.   (gnus-group-jump-to-group gnus-newsgroup-name)
  4046.   (gnus-group-next-unread-group 1)
  4047.   (if temporary
  4048.       ;; If exiting temporary, caller should adjust Group mode
  4049.       ;; buffer point by itself.
  4050.       nil                ;Nothing to do.
  4051.     ;; Return to Group mode buffer.
  4052.     (if (get-buffer gnus-summary-buffer)
  4053.     (bury-buffer gnus-summary-buffer))
  4054.     (if (get-buffer gnus-article-buffer)
  4055.     (bury-buffer gnus-article-buffer))
  4056.     (gnus-configure-windows 'newsgroups)
  4057.     (pop-to-buffer gnus-group-buffer)))
  4058.  
  4059. (defun gnus-summary-quit ()
  4060.   "Quit reading current newsgroup without updating read article info."
  4061.   (interactive)
  4062.   (if (y-or-n-p "Do you really wanna quit reading this group? ")
  4063.       (progn
  4064.     (message "")            ;Erase "Yes or No" question.
  4065.     ;; Return to Group selection mode.
  4066.     (if (get-buffer gnus-summary-buffer)
  4067.         (bury-buffer gnus-summary-buffer))
  4068.     (if (get-buffer gnus-article-buffer)
  4069.         (bury-buffer gnus-article-buffer))
  4070.     (gnus-configure-windows 'newsgroups)
  4071.     (pop-to-buffer gnus-group-buffer)
  4072.     (gnus-group-jump-to-group gnus-newsgroup-name) ;Make sure where I was.
  4073.     (gnus-group-next-group 1)    ;(gnus-group-next-unread-group 1)
  4074.     )))
  4075.  
  4076. (defun gnus-summary-describe-briefly ()
  4077.   "Describe Summary mode commands briefly."
  4078.   (interactive)
  4079.   (message
  4080.    (concat
  4081.     (substitute-command-keys "\\[gnus-summary-next-page]:Select  ")
  4082.     (substitute-command-keys "\\[gnus-summary-next-unread-article]:Forward  ")
  4083.     (substitute-command-keys "\\[gnus-summary-prev-unread-article]:Backward  ")
  4084.     (substitute-command-keys "\\[gnus-summary-exit]:Exit  ")
  4085.     (substitute-command-keys "\\[gnus-info-find-node]:Run Info  ")
  4086.     (substitute-command-keys "\\[gnus-summary-describe-briefly]:This help")
  4087.     )))
  4088.  
  4089.  
  4090. ;;;
  4091. ;;; GNUS Article Mode
  4092. ;;;
  4093.  
  4094. (if gnus-article-mode-map
  4095.     nil
  4096.   (setq gnus-article-mode-map (make-keymap))
  4097.   (suppress-keymap gnus-article-mode-map)
  4098.   (define-key gnus-article-mode-map " " 'gnus-article-next-page)
  4099.   (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page)
  4100.   (define-key gnus-article-mode-map "r" 'gnus-article-refer-article)
  4101.   (define-key gnus-article-mode-map "o" 'gnus-article-pop-article)
  4102.   (define-key gnus-article-mode-map "h" 'gnus-article-show-summary)
  4103.   (define-key gnus-article-mode-map "s" 'gnus-article-show-summary)
  4104.   (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly)
  4105.   (define-key gnus-article-mode-map "\C-c\C-i" 'gnus-info-find-node))
  4106.  
  4107. (defun gnus-article-mode ()
  4108.   "Major mode for browsing through an article.
  4109. All normal editing commands are turned off.
  4110. Instead, these commands are available:
  4111. \\{gnus-article-mode-map}
  4112.  
  4113. Various hooks for customization:
  4114.  gnus-article-mode-hook
  4115.     Entry to this mode calls the value with no arguments, if that
  4116.     value is non-nil.
  4117.  
  4118.  gnus-article-prepare-hook
  4119.     Called with no arguments after an article is prepared for reading,
  4120.     if that value is non-nil."
  4121.   (interactive)
  4122.   (kill-all-local-variables)
  4123.   ;; Gee.  Why don't you upgrade?
  4124.   (cond ((boundp 'mode-line-modified)
  4125.      (setq mode-line-modified "--- "))
  4126.     ((listp (default-value 'mode-line-format))
  4127.      (setq mode-line-format
  4128.            (cons "--- " (cdr (default-value 'mode-line-format))))))
  4129.   ;; To disable display-time facility.
  4130.   ;;(make-local-variable 'global-mode-string)
  4131.   ;;(setq global-mode-string nil)
  4132.   (setq major-mode 'gnus-article-mode)
  4133.   (setq mode-name "Article")
  4134.   (make-local-variable 'minor-mode-alist)
  4135.   (or (assq 'gnus-show-mime minor-mode-alist)
  4136.       (setq minor-mode-alist
  4137.         (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
  4138.   (gnus-article-set-mode-line)
  4139.   (use-local-map gnus-article-mode-map)
  4140.   (make-local-variable 'page-delimiter)
  4141.   (setq page-delimiter gnus-page-delimiter)
  4142.   (make-local-variable 'mail-header-separator)
  4143.   (setq mail-header-separator "")    ;For caesar function.
  4144.   (buffer-flush-undo (current-buffer))
  4145.   (setq buffer-read-only t)        ;Disable modification
  4146.   (run-hooks 'gnus-article-mode-hook))
  4147.  
  4148. (defun gnus-article-setup-buffer ()
  4149.   "Initialize Article mode buffer."
  4150.   (or (get-buffer gnus-article-buffer)
  4151.       (save-excursion
  4152.     (set-buffer (get-buffer-create gnus-article-buffer))
  4153.     (gnus-article-mode))
  4154.       ))
  4155.  
  4156. (defun gnus-article-prepare (article &optional all-headers)
  4157.   "Prepare ARTICLE in Article mode buffer.
  4158. ARTICLE can be either a article number or Message-ID.
  4159. If optional argument ALL-HEADERS is non-nil, all headers are inserted."
  4160.   ;; Make sure a connection to NNTP server is alive.
  4161.   (if (not (gnus-server-opened))
  4162.       (progn
  4163.     (gnus-start-news-server)
  4164.     (gnus-request-group gnus-newsgroup-name)))
  4165.   (save-excursion
  4166.     (set-buffer gnus-article-buffer)
  4167.     (let ((buffer-read-only nil))
  4168.       (erase-buffer)
  4169.       ;; mhspool does not work with Message-ID.  So, let's translate
  4170.       ;; it into an article number as possible as can.  This may help
  4171.       ;; nnspool too.
  4172.       ;; Note: this conversion must be done here since if the article
  4173.       ;; is specified by number or message-id has a different meaning
  4174.       ;; in the following.
  4175.       (if (let* ((header
  4176.           (and (stringp article)
  4177.                (gnus-get-header-by-id article)))
  4178.          (article
  4179.           (if header
  4180.               (nntp-header-number header) article)))
  4181.         (gnus-request-article article))
  4182.       (progn
  4183.         ;; Prepare article buffer
  4184.         (insert-buffer-substring nntp-server-buffer)
  4185.         ;; gnus-have-all-headers must be either T or NIL.
  4186.         (setq gnus-have-all-headers
  4187.           (not (not (or all-headers gnus-show-all-headers))))
  4188.         (if (and (numberp article)
  4189.              (not (eq article gnus-current-article)))
  4190.         ;; Seems me that a new article has been selected.
  4191.         (progn
  4192.           ;; gnus-current-article must be an article number.
  4193.           (setq gnus-last-article gnus-current-article)
  4194.           (setq gnus-current-article article)
  4195. ;;          (setq gnus-current-headers
  4196. ;;            (gnus-find-header-by-number gnus-newsgroup-headers
  4197. ;;                            gnus-current-article))
  4198.           (setq gnus-current-headers
  4199.             (gnus-get-header-by-number gnus-current-article))
  4200.           (run-hooks 'gnus-mark-article-hook)
  4201.           ))
  4202.         ;; Clear article history only when the article is
  4203.         ;; retrieved by the article number.
  4204.         (if (numberp article)
  4205.         (setq gnus-current-history nil))
  4206.         ;; Hooks for modifying contents of the article.  This hook
  4207.         ;; must be called before being narrowed.
  4208.         (run-hooks 'gnus-article-prepare-hook)
  4209.         ;; Decode MIME message.
  4210.         (if (and gnus-show-mime
  4211.              (gnus-fetch-field "Mime-Version"))
  4212.         (funcall gnus-show-mime-method))
  4213.         ;; Delete unnecessary headers.
  4214.         (or gnus-have-all-headers
  4215.         (gnus-article-delete-headers))
  4216.         ;; Do page break.
  4217.         (goto-char (point-min))
  4218.         (if gnus-break-pages
  4219.         (gnus-narrow-to-page))
  4220.         ;; Next function must be called after setting
  4221.         ;;  `gnus-current-article' variable and narrowed to page.
  4222.         (gnus-article-set-mode-line)
  4223.         )
  4224.     ;; There is no such article.
  4225.     (if (numberp article)
  4226.         (gnus-summary-mark-as-read article))
  4227.     (ding) (message "No such article (may be canceled)"))
  4228.       )))
  4229.  
  4230. (defun gnus-article-show-all-headers ()
  4231.   "Show all article headers in Article mode buffer."
  4232.   (or gnus-have-all-headers
  4233.       (gnus-article-prepare gnus-current-article t)))
  4234.  
  4235. ;;(defun gnus-article-set-mode-line ()
  4236. ;;  "Set Article mode line string."
  4237. ;;  (setq mode-line-buffer-identification
  4238. ;;    (list 17
  4239. ;;          (format "GNUS: %s {%d-%d} %d"
  4240. ;;              gnus-newsgroup-name
  4241. ;;              gnus-newsgroup-begin
  4242. ;;              gnus-newsgroup-end
  4243. ;;              gnus-current-article
  4244. ;;                    )))
  4245. ;;  (set-buffer-modified-p t))
  4246.  
  4247. ;;(defun gnus-article-set-mode-line ()
  4248. ;;  "Set Article mode line string."
  4249. ;;  (let ((unmarked
  4250. ;;     (- (length gnus-newsgroup-unreads)
  4251. ;;        (length (gnus-intersection
  4252. ;;             gnus-newsgroup-unreads gnus-newsgroup-marked))))
  4253. ;;    (unselected
  4254. ;;     (- (length gnus-newsgroup-unselected)
  4255. ;;        (length (gnus-intersection
  4256. ;;             gnus-newsgroup-unselected gnus-newsgroup-marked)))))
  4257. ;;    (setq mode-line-buffer-identification
  4258. ;;      (list 17
  4259. ;;        (format "GNUS: %s{%d} %s"
  4260. ;;            gnus-newsgroup-name
  4261. ;;            gnus-current-article
  4262. ;;            ;; This is proposed by tale@pawl.rpi.edu.
  4263. ;;            (cond ((and (zerop unmarked)
  4264. ;;                    (zerop unselected))
  4265. ;;                   "      ")
  4266. ;;                  ((zerop unselected)
  4267. ;;                   (format "%d more" unmarked))
  4268. ;;                  (t
  4269. ;;                   (format "%d(+%d) more" unmarked unselected)))
  4270. ;;            ))))
  4271. ;;  (set-buffer-modified-p t))
  4272.  
  4273. ;; New implementation in gnus 3.14.3
  4274.  
  4275. (defun gnus-article-set-mode-line ()
  4276.   "Set Article mode line string.
  4277. If you don't like it, define your own gnus-article-set-mode-line."
  4278.   (let ((maxlen 15)            ;Maximum subject length
  4279.     (subject
  4280.      (if gnus-current-headers
  4281.          (nntp-header-subject gnus-current-headers) "")))
  4282.     ;; The value must be a string to escape %-constructs because of subject.
  4283.     (setq mode-line-buffer-identification
  4284.       (format "GNUS: %s%s %s%s%s"
  4285.           gnus-newsgroup-name
  4286.           (if gnus-current-article
  4287.               (format "/%d" gnus-current-article) "")
  4288.           (substring subject 0 (min (length subject) maxlen))
  4289.           (if (> (length subject) maxlen) "..." "")
  4290.           (make-string (max 0 (- 17 (length subject))) ? )
  4291.           )))
  4292.   (set-buffer-modified-p t))
  4293.  
  4294. (defun gnus-article-delete-headers ()
  4295.   "Delete unnecessary headers."
  4296.   (save-excursion
  4297.     (save-restriction
  4298.       (goto-char (point-min))
  4299.       (narrow-to-region (point-min)
  4300.             (progn (search-forward "\n\n" nil 'move) (point)))
  4301.       (goto-char (point-min))
  4302.       (and (stringp gnus-ignored-headers)
  4303.        (while (re-search-forward gnus-ignored-headers nil t)
  4304.          (beginning-of-line)
  4305.          (delete-region (point)
  4306.                 (progn (re-search-forward "\n[^ \t]")
  4307.                    (forward-char -1)
  4308.                    (point)))))
  4309.       )))
  4310.  
  4311. ;; Working on article's buffer
  4312.  
  4313. (defun gnus-article-next-page (lines)
  4314.   "Show next page of current article.
  4315. If end of article, return non-nil. Otherwise return nil.
  4316. Argument LINES specifies lines to be scrolled up."
  4317.   (interactive "P")
  4318.   (move-to-window-line -1)
  4319.   ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
  4320.   (if (save-excursion
  4321.     (end-of-line)
  4322.     (and (pos-visible-in-window-p)    ;Not continuation line.
  4323.          (eobp)))
  4324.       ;; Nothing in this page.
  4325.       (if (or (not gnus-break-pages)
  4326.           (save-excursion
  4327.         (save-restriction
  4328.           (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
  4329.       t                ;Nothing more.
  4330.     (gnus-narrow-to-page 1)        ;Go to next page.
  4331.     nil
  4332.     )
  4333.     ;; More in this page.
  4334.     (condition-case ()
  4335.     (scroll-up lines)
  4336.       (end-of-buffer
  4337.        ;; Long lines may cause an end-of-buffer error.
  4338.        (goto-char (point-max))))
  4339.     nil
  4340.     ))
  4341.  
  4342. (defun gnus-article-prev-page (lines)
  4343.   "Show previous page of current article.
  4344. Argument LINES specifies lines to be scrolled down."
  4345.   (interactive "P")
  4346.   (move-to-window-line 0)
  4347.   (if (and gnus-break-pages
  4348.        (bobp)
  4349.        (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
  4350.       (progn
  4351.     (gnus-narrow-to-page -1) ;Go to previous page.
  4352.     (goto-char (point-max))
  4353.     (recenter -1))
  4354.     (scroll-down lines)))
  4355.  
  4356. (defun gnus-article-next-digest (nth)
  4357.   "Move to head of NTH next digested message.
  4358. Set mark at end of digested message."
  4359.   ;; Stop page breaking in digest mode.
  4360.   (widen)
  4361.   (end-of-line)
  4362.   ;; Skip NTH - 1 digest.
  4363.   ;; Suggested by Khalid Sattar <admin@cs.exeter.ac.uk>.
  4364.   ;; Digest separator is customizable.
  4365.   ;; Suggested by Skip Montanaro <montanaro@sprite.crd.ge.com>.
  4366.   (while (and (> nth 1)
  4367.           (re-search-forward gnus-digest-separator nil 'move))
  4368.     (setq nth (1- nth)))
  4369.   (if (re-search-forward gnus-digest-separator nil t)
  4370.       (let ((begin (point)))
  4371.     ;; Search for end of this message.
  4372.     (end-of-line)
  4373.     (if (re-search-forward gnus-digest-separator nil t)
  4374.         (progn
  4375.           (search-backward "\n\n")    ;This may be incorrect.
  4376.           (forward-line 1))
  4377.       (goto-char (point-max)))
  4378.     (push-mark)            ;Set mark at end of digested message.
  4379.     (goto-char begin)
  4380.     (beginning-of-line)
  4381.     ;; Show From: and Subject: fields.
  4382.     (recenter 1))
  4383.     (message "End of message")
  4384.     ))
  4385.  
  4386. (defun gnus-article-prev-digest (nth)
  4387.   "Move to head of NTH previous digested message."
  4388.   ;; Stop page breaking in digest mode.
  4389.   (widen)
  4390.   (beginning-of-line)
  4391.   ;; Skip NTH - 1 digest.
  4392.   ;; Suggested by Khalid Sattar <admin@cs.exeter.ac.uk>.
  4393.   ;; Digest separator is customizable.
  4394.   ;; Suggested by Skip Montanaro <montanaro@sprite.crd.ge.com>.
  4395.   (while (and (> nth 1)
  4396.           (re-search-backward gnus-digest-separator nil 'move))
  4397.     (setq nth (1- nth)))
  4398.   (if (re-search-backward gnus-digest-separator nil t)
  4399.       (let ((begin (point)))
  4400.     ;; Search for end of this message.
  4401.     (end-of-line)
  4402.     (if (re-search-forward gnus-digest-separator nil t)
  4403.         (progn
  4404.           (search-backward "\n\n")    ;This may be incorrect.
  4405.           (forward-line 1))
  4406.       (goto-char (point-max)))
  4407.     (push-mark)            ;Set mark at end of digested message.
  4408.     (goto-char begin)
  4409.     ;; Show From: and Subject: fields.
  4410.     (recenter 1))
  4411.     (goto-char (point-min))
  4412.     (message "Top of message")
  4413.     ))
  4414.  
  4415. (defun gnus-article-refer-article ()
  4416.   "Read article specified by message-id around point."
  4417.   (interactive)
  4418.   (save-window-excursion
  4419.     (save-excursion
  4420.       (re-search-forward ">" nil t)    ;Move point to end of "<....>".
  4421.       (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
  4422.       (let ((message-id
  4423.          (buffer-substring (match-beginning 1) (match-end 1))))
  4424.         (set-buffer gnus-summary-buffer)
  4425.         (gnus-summary-refer-article message-id))
  4426.     (error "No references around point"))
  4427.       )))
  4428.  
  4429. (defun gnus-article-pop-article ()
  4430.   "Pop up article history."
  4431.   (interactive)
  4432.   (save-window-excursion
  4433.     (set-buffer gnus-summary-buffer)
  4434.     (gnus-summary-refer-article nil)))
  4435.  
  4436. (defun gnus-article-show-summary ()
  4437.   "Reconfigure windows to show Summary buffer."
  4438.   (interactive)
  4439.   (gnus-configure-windows 'article)
  4440.   (pop-to-buffer gnus-summary-buffer)
  4441.   (gnus-summary-goto-subject gnus-current-article))
  4442.  
  4443. (defun gnus-article-describe-briefly ()
  4444.   "Describe Article mode commands briefly."
  4445.   (interactive)
  4446.   (message
  4447.    (concat
  4448.     (substitute-command-keys "\\[gnus-article-next-page]:Next page  ")
  4449.     (substitute-command-keys "\\[gnus-article-prev-page]:Prev page  ")
  4450.     (substitute-command-keys "\\[gnus-article-show-summary]:Show Summary  ")
  4451.     (substitute-command-keys "\\[gnus-info-find-node]:Run Info  ")
  4452.     (substitute-command-keys "\\[gnus-article-describe-briefly]:This help")
  4453.     )))
  4454.  
  4455.  
  4456. ;;;
  4457. ;;; GNUS KILL-File Mode
  4458. ;;;
  4459.  
  4460. (if gnus-kill-file-mode-map
  4461.     nil
  4462.   (setq gnus-kill-file-mode-map (copy-keymap emacs-lisp-mode-map))
  4463.   (define-key gnus-kill-file-mode-map "\C-c\C-k\C-s" 'gnus-kill-file-kill-by-subject)
  4464.   (define-key gnus-kill-file-mode-map "\C-c\C-k\C-a" 'gnus-kill-file-kill-by-author)
  4465.   (define-key gnus-kill-file-mode-map "\C-c\C-a" 'gnus-kill-file-apply-buffer)
  4466.   (define-key gnus-kill-file-mode-map "\C-c\C-e" 'gnus-kill-file-apply-last-sexp)
  4467.   (define-key gnus-kill-file-mode-map "\C-c\C-c" 'gnus-kill-file-exit)
  4468.   (define-key gnus-kill-file-mode-map "\C-c\C-i" 'gnus-info-find-node))
  4469.  
  4470. (defun gnus-kill-file-mode ()
  4471.   "Major mode for editing KILL file.
  4472.  
  4473. In addition to Emacs-Lisp Mode, the following commands are available:
  4474.  
  4475. \\[gnus-kill-file-kill-by-subject]    Insert KILL command for current subject.
  4476. \\[gnus-kill-file-kill-by-author]    Insert KILL command for current author.
  4477. \\[gnus-kill-file-apply-buffer]    Apply current buffer to selected newsgroup.
  4478. \\[gnus-kill-file-apply-last-sexp]    Apply sexp before point to selected newsgroup.
  4479. \\[gnus-kill-file-exit]    Save file and exit editing KILL file.
  4480. \\[gnus-info-find-node]    Read Info about KILL file.
  4481.  
  4482.   A KILL file contains lisp expressions to be applied to a selected
  4483. newsgroup. The purpose is to mark articles as read on the basis of
  4484. some set of regexps. A global KILL file is applied to every newsgroup,
  4485. and a local KILL file is applied to a specified newsgroup. Since a
  4486. global KILL file is applied to every newsgroup, for better performance
  4487. use a local one.
  4488.  
  4489.   A KILL file can contain any kind of Emacs lisp expressions expected
  4490. to be evaluated in the Summary buffer. Writing lisp programs for this
  4491. purpose is not so easy because the internal working of GNUS must be
  4492. well-known. For this reason, GNUS provides a general function which
  4493. does this easily for non-Lisp programmers.
  4494.  
  4495.   The `gnus-kill' function executes commands available in Summary Mode
  4496. by their key sequences. `gnus-kill' should be called with FIELD,
  4497. REGEXP and optional COMMAND and ALL. FIELD is a string representing
  4498. the header field or an empty string. If FIELD is an empty string, the
  4499. entire article body is searched for. REGEXP is a string which is
  4500. compared with FIELD value. COMMAND is a string representing a valid
  4501. key sequence in Summary Mode or Lisp expression. COMMAND is default to
  4502. '(gnus-summary-mark-as-read nil \"X\"). Make sure that COMMAND is
  4503. executed in the Summary buffer.  If the second optional argument ALL
  4504. is non-nil, the COMMAND is applied to articles which are already
  4505. marked as read or unread.  Articles which are marked are skipped over
  4506. by default.
  4507.  
  4508.   For example, if you want to mark articles of which subjects contain
  4509. the string `AI' as read, a possible KILL file may look like:
  4510.  
  4511.     (gnus-kill \"Subject\" \"AI\")
  4512.  
  4513.   If you want to mark articles with `D' instead of `X', you can use
  4514. the following expression:
  4515.  
  4516.     (gnus-kill \"Subject\" \"AI\" \"d\")
  4517.  
  4518. In this example it is assumed that the command
  4519. `gnus-summary-mark-as-read-forward' is assigned to `d' in Summary Mode.
  4520.  
  4521.   It is possible to delete unnecessary headers which are marked with
  4522. `X' in a KILL file as follows:
  4523.  
  4524.     (gnus-expunge \"X\")
  4525.  
  4526.   If the Summary buffer is empty after applying KILL files, GNUS will
  4527. exit the selected newsgroup normally.  If headers which are marked
  4528. with `D' are deleted in a KILL file, it is impossible to read articles
  4529. which are marked as read in the previous GNUS sessions.  Marks other
  4530. than `D' should be used for articles which should really be deleted.
  4531.  
  4532. Entry to this mode calls emacs-lisp-mode-hook and
  4533. gnus-kill-file-mode-hook with no arguments, if that value is non-nil."
  4534.   (interactive)
  4535.   (kill-all-local-variables)
  4536.   (use-local-map gnus-kill-file-mode-map)
  4537.   (set-syntax-table emacs-lisp-mode-syntax-table)
  4538.   (setq major-mode 'gnus-kill-file-mode)
  4539.   (setq mode-name "KILL-File")
  4540.   (lisp-mode-variables nil)
  4541.   (run-hooks 'emacs-lisp-mode-hook 'gnus-kill-file-mode-hook))
  4542.  
  4543. (defun gnus-kill-file-edit-file (newsgroup)
  4544.   "Begin editing a KILL file of NEWSGROUP.
  4545. If NEWSGROUP is nil, the global KILL file is selected."
  4546.   (interactive "sNewsgroup: ")
  4547.   (let ((file (gnus-newsgroup-kill-file newsgroup)))
  4548.     (gnus-make-directory (file-name-directory file))
  4549.     ;; Save current window configuration if this is first invocation.
  4550.     (or (and (get-file-buffer file)
  4551.          (get-buffer-window (get-file-buffer file)))
  4552.     (setq gnus-winconf-kill-file (current-window-configuration)))
  4553.     ;; Hack windows.
  4554.     (let ((buffer (find-file-noselect file)))
  4555.       (cond ((get-buffer-window buffer)
  4556.          (pop-to-buffer buffer))
  4557.         ((eq major-mode 'gnus-group-mode)
  4558.          (gnus-configure-windows '(1 0 0)) ;Take all windows.
  4559.          (pop-to-buffer gnus-group-buffer)
  4560.          (let ((gnus-summary-buffer buffer))
  4561.            (gnus-configure-windows '(1 1 0)) ;Split into two.
  4562.            (pop-to-buffer buffer)))
  4563.         ((eq major-mode 'gnus-summary-mode)
  4564.          (gnus-configure-windows 'article)
  4565.          (pop-to-buffer gnus-article-buffer)
  4566.          (bury-buffer gnus-article-buffer)
  4567.          (switch-to-buffer buffer))
  4568.         (t                ;No good rules.
  4569.          (find-file-other-window file))
  4570.         ))
  4571.     (gnus-kill-file-mode)
  4572.     ))
  4573.  
  4574. (defun gnus-kill-file-kill-by-subject ()
  4575.   "Insert KILL command for current subject."
  4576.   (interactive)
  4577.   (insert
  4578.    (format "(gnus-kill \"Subject\" %s)\n"
  4579.        (prin1-to-string
  4580.         (if gnus-current-kill-article
  4581.         (regexp-quote
  4582.          (nntp-header-subject
  4583.           ;; No need to speed up this command.
  4584.           ;;(gnus-get-header-by-number gnus-current-kill-article)
  4585.           (gnus-find-header-by-number gnus-newsgroup-headers
  4586.                           gnus-current-kill-article)))
  4587.           "")))))
  4588.  
  4589. (defun gnus-kill-file-kill-by-author ()
  4590.   "Insert KILL command for current author."
  4591.   (interactive)
  4592.   (insert
  4593.    (format "(gnus-kill \"From\" %s)\n"
  4594.        (prin1-to-string
  4595.         (if gnus-current-kill-article
  4596.         (regexp-quote
  4597.          (nntp-header-from
  4598.           ;; No need to speed up this command.
  4599.           ;;(gnus-get-header-by-number gnus-current-kill-article)
  4600.           (gnus-find-header-by-number gnus-newsgroup-headers
  4601.                           gnus-current-kill-article)))
  4602.           "")))))
  4603.  
  4604. (defun gnus-kill-file-apply-buffer ()
  4605.   "Apply current buffer to current newsgroup."
  4606.   (interactive)
  4607.   (if (and gnus-current-kill-article
  4608.        (get-buffer gnus-summary-buffer))
  4609.       ;; Assume newsgroup is selected.
  4610.       (let ((string (concat "(progn \n" (buffer-string) "\n)" )))
  4611.     (save-excursion
  4612.       (save-window-excursion
  4613.         (pop-to-buffer gnus-summary-buffer)
  4614.         (eval (car (read-from-string string))))))
  4615.     (ding) (message "No newsgroup is selected.")))
  4616.  
  4617. (defun gnus-kill-file-apply-last-sexp ()
  4618.   "Apply sexp before point in current buffer to current newsgroup."
  4619.   (interactive)
  4620.   (if (and gnus-current-kill-article
  4621.        (get-buffer gnus-summary-buffer))
  4622.       ;; Assume newsgroup is selected.
  4623.       (let ((string
  4624.          (buffer-substring
  4625.           (save-excursion (forward-sexp -1) (point)) (point))))
  4626.     (save-excursion
  4627.       (save-window-excursion
  4628.         (pop-to-buffer gnus-summary-buffer)
  4629.         (eval (car (read-from-string string))))))
  4630.     (ding) (message "No newsgroup is selected.")))
  4631.  
  4632. (defun gnus-kill-file-exit ()
  4633.   "Save a KILL file, then return to the previous buffer."
  4634.   (interactive)
  4635.   (save-buffer)
  4636.   (let ((killbuf (current-buffer)))
  4637.     ;; We don't want to return to Article buffer.
  4638.     (and (get-buffer gnus-article-buffer)
  4639.      (bury-buffer (get-buffer gnus-article-buffer)))
  4640.     ;; Delete the KILL file windows.
  4641.     (delete-windows-on killbuf)
  4642.     ;; Restore last window configuration if available.
  4643.     (and gnus-winconf-kill-file
  4644.      (set-window-configuration gnus-winconf-kill-file))
  4645.     (setq gnus-winconf-kill-file nil)
  4646.     ;; Kill the KILL file buffer.  Suggested by tale@pawl.rpi.edu.
  4647.     (kill-buffer killbuf)))
  4648.  
  4649.  
  4650. ;;;
  4651. ;;; Utility functions
  4652. ;;;
  4653.  
  4654. ;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti)
  4655.  
  4656. (defun gnus-batch-kill ()
  4657.   "Run batched KILL.
  4658. Usage: emacs -batch -l gnus -f gnus-batch-kill NEWSGROUP ..."
  4659.   (if (not noninteractive)
  4660.       (error "gnus-batch-kill is to be used only with -batch"))
  4661.   (let* ((group nil)
  4662.      (subscribed nil)
  4663.      (newsrc nil)
  4664.      (yes-and-no
  4665.       (gnus-parse-n-options
  4666.        (apply (function concat)
  4667.           (mapcar (function (lambda (g) (concat g " ")))
  4668.               command-line-args-left))))
  4669.      (yes (car yes-and-no))
  4670.      (no  (cdr yes-and-no))
  4671.      ;; Disable verbose message.
  4672.      (gnus-novice-user nil)
  4673.      (gnus-large-newsgroup nil)
  4674.      (nntp-large-newsgroup nil))
  4675.     ;; Eat all arguments.
  4676.     (setq command-line-args-left nil)
  4677.     ;; Startup GNUS.
  4678.     (gnus)
  4679.     ;; Apply kills to specified newsgroups in command line arguments.
  4680.     (setq newsrc (copy-sequence gnus-newsrc-assoc))
  4681.     (while newsrc
  4682.       (setq group (car (car newsrc)))
  4683.       (setq subscribed (nth 1 (car newsrc)))
  4684.       (setq newsrc (cdr newsrc))
  4685.       (if (and subscribed
  4686.            (not (zerop (nth 1 (gnus-gethash group gnus-unread-hashtb))))
  4687.            (if yes
  4688.            (string-match yes group) t)
  4689.            (or (null no)
  4690.            (not (string-match no group))))
  4691.       (progn
  4692.         (gnus-summary-read-group group nil t)
  4693.         (if (eq (current-buffer) (get-buffer gnus-summary-buffer))
  4694.         (gnus-summary-exit t))
  4695.         ))
  4696.       )
  4697.     ;; Finally, exit Emacs.
  4698.     (set-buffer gnus-group-buffer)
  4699.     (gnus-group-exit)
  4700.     ))
  4701.  
  4702. ;; For saving articles
  4703.  
  4704. (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
  4705.   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  4706. If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
  4707. Otherwise, it is like ~/News/news/group/num."
  4708.   (let ((default
  4709.       (expand-file-name
  4710.        (concat (if gnus-use-long-file-name
  4711.                (gnus-capitalize-newsgroup newsgroup)
  4712.              (gnus-newsgroup-directory-form newsgroup))
  4713.            "/" (int-to-string (nntp-header-number headers)))
  4714.        (or gnus-article-save-directory "~/News"))))
  4715.     (if (and last-file
  4716.          (string-equal (file-name-directory default)
  4717.                (file-name-directory last-file))
  4718.          (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  4719.     default
  4720.       (or last-file default))))
  4721.  
  4722. (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
  4723.   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  4724. If variable `gnus-use-long-file-name' is nil, it is ~/News/news.group/num.
  4725. Otherwise, it is like ~/News/news/group/num."
  4726.   (let ((default
  4727.       (expand-file-name
  4728.        (concat (if gnus-use-long-file-name
  4729.                newsgroup
  4730.              (gnus-newsgroup-directory-form newsgroup))
  4731.            "/" (int-to-string (nntp-header-number headers)))
  4732.        (or gnus-article-save-directory "~/News"))))
  4733.     (if (and last-file
  4734.          (string-equal (file-name-directory default)
  4735.                (file-name-directory last-file))
  4736.          (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  4737.     default
  4738.       (or last-file default))))
  4739.  
  4740. (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
  4741.   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  4742. If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group.
  4743. Otherwise, it is like ~/News/news/group/news."
  4744.   (or last-file
  4745.       (expand-file-name
  4746.        (if gnus-use-long-file-name
  4747.        (gnus-capitalize-newsgroup newsgroup)
  4748.      (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
  4749.        (or gnus-article-save-directory "~/News"))))
  4750.  
  4751. (defun gnus-plain-save-name (newsgroup headers &optional last-file)
  4752.   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  4753. If variable `gnus-use-long-file-name' is nil, it is ~/News/news.group.
  4754. Otherwise, it is like ~/News/news/group/news."
  4755.   (or last-file
  4756.       (expand-file-name
  4757.        (if gnus-use-long-file-name
  4758.        newsgroup
  4759.      (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
  4760.        (or gnus-article-save-directory "~/News"))))
  4761.  
  4762. (defun gnus-Folder-save-name (newsgroup headers &optional last-folder)
  4763.   "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
  4764. If variable `gnus-use-long-file-name' is nil, it is +News.group.
  4765. Otherwise, it is like +news/group."
  4766.   (or last-folder
  4767.       (concat "+"
  4768.           (if gnus-use-long-file-name
  4769.           (gnus-capitalize-newsgroup newsgroup)
  4770.         (gnus-newsgroup-directory-form newsgroup)))))
  4771.  
  4772. (defun gnus-folder-save-name (newsgroup headers &optional last-folder)
  4773.   "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
  4774. If variable `gnus-use-long-file-name' is nil, it is +news.group.
  4775. Otherwise, it is like +news/group."
  4776.   (or last-folder
  4777.       (concat "+"
  4778.           (if gnus-use-long-file-name
  4779.           newsgroup
  4780.         (gnus-newsgroup-directory-form newsgroup)))))
  4781.  
  4782. ;; For KILL files
  4783.  
  4784. (defun gnus-apply-kill-file ()
  4785.   "Apply KILL file to the current newsgroup."
  4786.   ;; Apply the global KILL file.
  4787.   (load (gnus-newsgroup-kill-file nil) t nil t)
  4788.   ;; And then apply the local KILL file.
  4789.   (load (gnus-newsgroup-kill-file gnus-newsgroup-name) t nil t))
  4790.  
  4791. (defun gnus-Newsgroup-kill-file (newsgroup)
  4792.   "Return the name of a KILL file of NEWSGROUP.
  4793. If NEWSGROUP is nil, return the global KILL file instead."
  4794.   (cond ((or (null newsgroup)
  4795.          (string-equal newsgroup ""))
  4796.      ;; The global KILL file is placed at top of the directory.
  4797.      (expand-file-name gnus-kill-file-name
  4798.                (or gnus-article-save-directory "~/News")))
  4799.     (gnus-use-long-file-name
  4800.      ;; Append ".KILL" to capitalized newsgroup name.
  4801.      (expand-file-name (concat (gnus-capitalize-newsgroup newsgroup)
  4802.                    "." gnus-kill-file-name)
  4803.                (or gnus-article-save-directory "~/News")))
  4804.     (t
  4805.      ;; Place "KILL" under the hierarchical directory.
  4806.      (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
  4807.                    "/" gnus-kill-file-name)
  4808.                (or gnus-article-save-directory "~/News")))
  4809.     ))
  4810.  
  4811. (defun gnus-newsgroup-kill-file (newsgroup)
  4812.   "Return the name of a KILL file of NEWSGROUP.
  4813. If NEWSGROUP is nil, return the global KILL file instead."
  4814.   (cond ((or (null newsgroup)
  4815.          (string-equal newsgroup ""))
  4816.      ;; The global KILL file is placed at top of the directory.
  4817.      (expand-file-name gnus-kill-file-name
  4818.                (or gnus-article-save-directory "~/News")))
  4819.     (gnus-use-long-file-name
  4820.      ;; Append ".KILL" to newsgroup name.
  4821.      (expand-file-name (concat newsgroup "." gnus-kill-file-name)
  4822.                (or gnus-article-save-directory "~/News")))
  4823.     (t
  4824.      ;; Place "KILL" under the hierarchical directory.
  4825.      (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
  4826.                    "/" gnus-kill-file-name)
  4827.                (or gnus-article-save-directory "~/News")))
  4828.     ))
  4829.  
  4830. ;; For subscribing new newsgroup
  4831.  
  4832. (defun gnus-subscribe-randomly (newsgroup)
  4833.   "Subscribe new NEWSGROUP and insert it at the beginning of newsgroups."
  4834.   (gnus-subscribe-newsgroup newsgroup
  4835.                 (car (car gnus-newsrc-assoc))))
  4836.  
  4837. (defun gnus-subscribe-alphabetically (newgroup)
  4838.   "Subscribe new NEWSGROUP and insert it in strict alphabetic order."
  4839.   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
  4840.   (let ((groups gnus-newsrc-assoc)
  4841.     (before nil))
  4842.     (while (and (not before) groups)
  4843.       (if (string< newgroup (car (car groups)))
  4844.       (setq before (car (car groups)))
  4845.     (setq groups (cdr groups))))
  4846.     (gnus-subscribe-newsgroup newgroup before)
  4847.     ))
  4848.  
  4849. (defun gnus-subscribe-hierarchically (newgroup)
  4850.   "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
  4851.   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
  4852.   (save-excursion
  4853.     (set-buffer (find-file-noselect gnus-current-startup-file))
  4854.     (let ((groupkey newgroup)
  4855.       (before nil))
  4856.       (while (and (not before) groupkey)
  4857.     (goto-char (point-min))
  4858.     (let ((groupkey-re
  4859.            (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
  4860.       (while (and (re-search-forward groupkey-re nil t)
  4861.               (progn
  4862.             (setq before (buffer-substring
  4863.                       (match-beginning 1) (match-end 1)))
  4864.             (string< before newgroup)))
  4865.         ))
  4866.     ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
  4867.     (setq groupkey
  4868.           (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
  4869.           (substring groupkey (match-beginning 1) (match-end 1)))))
  4870.       (gnus-subscribe-newsgroup newgroup before)
  4871.       )))
  4872.  
  4873. (defun gnus-subscribe-interactively (newsgroup)
  4874.   "Subscribe new NEWSGROUP interactively.
  4875. It is inserted in hierarchical newsgroup order if subscribed.
  4876. Unless, it is killed."
  4877.   (if (y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup))
  4878.       (gnus-subscribe-hierarchically newsgroup)
  4879.     ;; Save in kill-ring
  4880.     (gnus-subscribe-newsgroup newsgroup)
  4881.     (gnus-kill-newsgroup newsgroup)))
  4882.  
  4883. (defun gnus-subscribe-newsgroup (newsgroup &optional next)
  4884.   "Subscribe new NEWSGROUP.
  4885. If optional argument NEXT is non-nil, it is inserted before NEXT."
  4886.   (gnus-insert-newsgroup (list newsgroup t) next)
  4887.   (message "Subscribe newsgroup: %s" newsgroup))
  4888.  
  4889. ;; For directories
  4890.  
  4891. (defun gnus-newsgroup-directory-form (newsgroup)
  4892.   "Make hierarchical directory name from NEWSGROUP name."
  4893.   (let ((newsgroup (substring newsgroup 0)) ;Copy string.
  4894.     (len (length newsgroup))
  4895.     (idx 0))
  4896.     ;; Replace all occurrences of `.' with `/'.
  4897.     (while (< idx len)
  4898.       (if (= (aref newsgroup idx) ?.)
  4899.       (aset newsgroup idx ?/))
  4900.       (setq idx (1+ idx)))
  4901.     newsgroup
  4902.     ))
  4903.  
  4904. (defun gnus-make-directory (directory)
  4905.   "Make DIRECTORY recursively."
  4906.   (let ((directory (expand-file-name directory default-directory)))
  4907.     (or (file-exists-p directory)
  4908.     (gnus-make-directory-1 "" directory))
  4909.     ))
  4910.  
  4911. (defun gnus-make-directory-1 (head tail)
  4912.   (cond ((string-match "^/\\([^/]+\\)" tail)
  4913.      ;; ange-ftp interferes with calling match-* after
  4914.      ;; calling file-name-as-directory.
  4915.      (let ((beg (match-beginning 1))
  4916.            (end (match-end 1)))
  4917.        (setq head (concat (file-name-as-directory head)
  4918.                   (substring tail beg end)))
  4919.        (or (file-exists-p head)
  4920.            (call-process "mkdir" nil nil nil head))
  4921.        (gnus-make-directory-1 head (substring tail end))))
  4922.     ((string-equal tail "") t)
  4923.     ))
  4924.  
  4925. (defun gnus-capitalize-newsgroup (newsgroup)
  4926.   "Capitalize NEWSGROUP name with treating '.' and '-' as part of words."
  4927.   ;; Suggested by "Jonathan I. Kamens" <jik@pit-manager.MIT.EDU>.
  4928.   (let ((current-syntax-table (syntax-table)))
  4929.     (unwind-protect
  4930.     (progn
  4931.       (set-syntax-table (copy-syntax-table current-syntax-table))
  4932.       (modify-syntax-entry ?- "w")
  4933.       (modify-syntax-entry ?. "w")
  4934.       (capitalize newsgroup))
  4935.       (set-syntax-table current-syntax-table))))
  4936.  
  4937. (defun gnus-simplify-subject (subject &optional re-only)
  4938.   "Remove `Re:' and words in parentheses.
  4939. If optional argument RE-ONLY is non-nil, strip `Re:' only."
  4940.   (let ((case-fold-search t))        ;Ignore case.
  4941.     ;; Remove `Re:' and `Re^N:'.
  4942.     (if (string-match "\\`\\(re\\(\\^[0-9]+\\)?:[ \t]+\\)+" subject)
  4943.     (setq subject (substring subject (match-end 0))))
  4944.     ;; Remove words in parentheses from end.
  4945.     (or re-only
  4946.     (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
  4947.       (setq subject (substring subject 0 (match-beginning 0)))))
  4948.     ;; Return subject string.
  4949.     subject
  4950.     ))
  4951.  
  4952. (defun gnus-optional-lines-and-from (header)
  4953.   "Return a string like `NNN:AUTHOR' from HEADER."
  4954.   (let ((name-length (length "umerin@photon")))
  4955.     (substring (format "%3d:%s"
  4956.                ;; Lines of the article.
  4957.                ;; Suggested by dana@bellcore.com.
  4958.                (nntp-header-lines header)
  4959.                ;; Its author.
  4960.                (concat (mail-strip-quoted-names
  4961.                 (nntp-header-from header))
  4962.                    (make-string name-length ? )))
  4963.            ;; 4 stands for length of `NNN:'.
  4964.            0 (+ 4 name-length))))
  4965.  
  4966. (defun gnus-optional-lines (header)
  4967.   "Return a string like `NNN' from HEADER."
  4968.   (format "%4d" (nntp-header-lines header)))
  4969.  
  4970. ;; Basic ideas by flee@cs.psu.edu (Felix Lee)
  4971.  
  4972. (defun gnus-keysort-headers (predicate key &optional reverse)
  4973.   "Sort current headers by PREDICATE using a value passed by KEY safely.
  4974. *Safely* means C-g quitting is disabled during sort.
  4975. Optional argument REVERSE means reverse order."
  4976.   (let ((inhibit-quit t))
  4977.     (setq gnus-newsgroup-headers
  4978.       (if reverse
  4979.           (nreverse
  4980.            (gnus-keysort (nreverse gnus-newsgroup-headers) predicate key))
  4981.         (gnus-keysort gnus-newsgroup-headers predicate key)))
  4982.     ;; Make sure we don't have to call
  4983.     ;; gnus-clear-hashtables-for-newsgroup-headers to clear hash
  4984.     ;; tables for the variable gnus-newsgroup-headers since no new
  4985.     ;; entry is added to nor deleted from the variable.
  4986.     ))
  4987.  
  4988. (defun gnus-keysort (list predicate key)
  4989.   "Sort LIST by PREDICATE using a value passed by KEY."
  4990.   (mapcar (function cdr)
  4991.       (sort (mapcar (function (lambda (a) (cons (funcall key a) a))) list)
  4992.         (function (lambda (a b)
  4993.                 (funcall predicate (car a) (car b)))))))
  4994.  
  4995. (defun gnus-sort-headers (predicate &optional reverse)
  4996.   "Sort current headers by PREDICATE safely.
  4997. *Safely* means C-g quitting is disabled during sort.
  4998. Optional argument REVERSE means reverse order."
  4999.   (let ((inhibit-quit t))
  5000.     (setq gnus-newsgroup-headers
  5001.       (if reverse
  5002.           (nreverse (sort (nreverse gnus-newsgroup-headers) predicate))
  5003.         (sort gnus-newsgroup-headers predicate)))
  5004.     ;; Make sure we don't have to call
  5005.     ;; gnus-clear-hashtables-for-newsgroup-headers to clear hash
  5006.     ;; tables for the variable gnus-newsgroup-headers since no new
  5007.     ;; entry is added to nor deleted from the variable.
  5008.     ))
  5009.  
  5010. (defun gnus-string-lessp (a b)
  5011.   "Return T if first arg string is less than second in lexicographic order.
  5012. If case-fold-search is non-nil, case of letters is ignored."
  5013.   (if case-fold-search
  5014.       (string-lessp (downcase a) (downcase b))
  5015.     (string-lessp a b)))
  5016.  
  5017. (defun gnus-date-lessp (date1 date2)
  5018.   "Return T if DATE1 is earlyer than DATE2."
  5019.   (string-lessp (gnus-sortable-date date1)
  5020.         (gnus-sortable-date date2)))
  5021.  
  5022. (defun gnus-sortable-date (date)
  5023.   "Make sortable string by string-lessp from DATE.
  5024. Timezone package is used."
  5025.   (let* ((date   (timezone-parse-date date)) ;[Y M D T]
  5026.      (year   (string-to-int (aref date 0)))
  5027.      (month  (string-to-int (aref date 1)))
  5028.      (day    (string-to-int (aref date 2)))
  5029.      (time   (aref date 3)))    ;HH:MM:SS
  5030.     ;; Timezone package is used.  But, we don't have to care about
  5031.     ;; the timezone since article's timezones are always GMT.
  5032.     (timezone-make-sortable-date year month day time)
  5033.     ))
  5034.  
  5035. ;;(defun gnus-sortable-date (date)
  5036. ;;  "Make sortable string by string-lessp from DATE."
  5037. ;;  (let ((month '(("JAN" . " 1")("FEB" . " 2")("MAR" . " 3")
  5038. ;;         ("APR" . " 4")("MAY" . " 5")("JUN" . " 6")
  5039. ;;         ("JUL" . " 7")("AUG" . " 8")("SEP" . " 9")
  5040. ;;         ("OCT" . "10")("NOV" . "11")("DEC" . "12")))
  5041. ;;    (date (or date "")))
  5042. ;;    ;; Can understand the following styles:
  5043. ;;    ;; (1) 14 Apr 89 03:20:12 GMT
  5044. ;;    ;; (2) Fri, 17 Mar 89 4:01:33 GMT
  5045. ;;    (if (string-match
  5046. ;;     "\\([0-9]+\\) \\([^ ,]+\\) \\([0-9]+\\) \\([0-9:]+\\)" date)
  5047. ;;    (concat
  5048. ;;     ;; Year
  5049. ;;     (substring date (match-beginning 3) (match-end 3))
  5050. ;;     ;; Month
  5051. ;;     (cdr
  5052. ;;      (assoc
  5053. ;;       (upcase (substring date (match-beginning 2) (match-end 2))) month))
  5054. ;;     ;; Day
  5055. ;;     (format "%2d" (string-to-int
  5056. ;;            (substring date
  5057. ;;                   (match-beginning 1) (match-end 1))))
  5058. ;;     ;; Time
  5059. ;;     (substring date (match-beginning 4) (match-end 4)))
  5060. ;;      ;; Cannot understand DATE string.
  5061. ;;      date
  5062. ;;      )
  5063. ;;    ))
  5064.  
  5065. (defun gnus-fetch-field (field)
  5066.   "Return the value of the header FIELD of current article."
  5067.   (save-excursion
  5068.     (save-restriction
  5069.       (widen)
  5070.       (goto-char (point-min))
  5071.       (narrow-to-region (point-min)
  5072.             (progn (search-forward "\n\n" nil 'move) (point)))
  5073.       (mail-fetch-field field))))
  5074.  
  5075. (fset 'gnus-expunge 'gnus-summary-delete-marked-with)
  5076.  
  5077. (defun gnus-kill (field regexp &optional command all)
  5078.   "If FIELD of an article matches REGEXP, execute COMMAND.
  5079. Optional 1st argument COMMAND is default to
  5080.     (gnus-summary-mark-as-read nil \"X\").
  5081. If optional 2nd argument ALL is non-nil, articles marked are also applied to.
  5082. If FIELD is an empty string (or nil), entire article body is searched for.
  5083. COMMAND must be a lisp expression or a string representing a key sequence."
  5084.   ;; We don't want to change current point nor window configuration.
  5085.   (save-excursion
  5086.     (save-window-excursion
  5087.       ;; Selected window must be Summary buffer to execute keyboard
  5088.       ;; macros correctly. See command_loop_1.
  5089.       (switch-to-buffer gnus-summary-buffer 'norecord)
  5090.       (goto-char (point-min))        ;From the beginning.
  5091.       (if (null command)
  5092.       (setq command '(gnus-summary-mark-as-read nil "X")))
  5093.       (gnus-execute field regexp command nil (not all))
  5094.       )))
  5095.  
  5096. (defun gnus-execute (field regexp form &optional backward ignore-marked)
  5097.   "If FIELD of article header matches REGEXP, execute lisp FORM (or a string).
  5098. If FIELD is an empty string (or nil), entire article body is searched for.
  5099. If optional 1st argument BACKWARD is non-nil, do backward instead.
  5100. If optional 2nd argument IGNORE-MARKED is non-nil, articles which are
  5101. marked as read or unread are ignored."
  5102.   (let ((function nil)
  5103.     (header nil)
  5104.     (article nil))
  5105.     (if (string-equal field "")
  5106.     (setq field nil))
  5107.     (if (null field)
  5108.     nil
  5109.       (or (stringp field)
  5110.       (setq field (symbol-name field)))
  5111.       ;; Get access function of header filed.
  5112.       (setq function (intern-soft (concat "gnus-header-" (downcase field))))
  5113.       (if (and function (fboundp function))
  5114.       (setq function (symbol-function function))
  5115.     (error "Unknown header field: \"%s\"" field)))
  5116.     ;; Make FORM funcallable.
  5117.     (if (and (listp form) (not (eq (car form) 'lambda)))
  5118.     (setq form (list 'lambda nil form)))
  5119.     ;; Starting from the current article.
  5120.     (or (and ignore-marked
  5121.          ;; Articles marked as read and unread should be ignored.
  5122.          (setq article (gnus-summary-article-number))
  5123.          (or (not (memq article gnus-newsgroup-unreads)) ;Marked as read.
  5124.          (memq article gnus-newsgroup-marked) ;Marked as unread.
  5125.          ))
  5126.     (gnus-execute-1 function regexp form))
  5127.     (while (gnus-summary-search-subject backward ignore-marked nil)
  5128.       (gnus-execute-1 function regexp form))
  5129.     ))
  5130.  
  5131. (defun gnus-execute-1 (function regexp form)
  5132.   (save-excursion
  5133.     ;; The point of Summary buffer must be saved during execution.
  5134.     (let ((article (gnus-summary-article-number)))
  5135.       (if (null article)
  5136.       nil                ;Nothing to do.
  5137.     (if function
  5138.         ;; Compare with header field.
  5139.         (let (;;(header (gnus-find-header-by-number
  5140.           ;;        gnus-newsgroup-headers article))
  5141.           (header (gnus-get-header-by-number article))
  5142.           (value nil))
  5143.           (and header
  5144.            (progn
  5145.              (setq value (funcall function header))
  5146.              ;; Number (Lines:) or symbol must be converted to string.
  5147.              (or (stringp value)
  5148.              (setq value (prin1-to-string value)))
  5149.              (string-match regexp value))
  5150.            (if (stringp form)    ;Keyboard macro.
  5151.                (execute-kbd-macro form)
  5152.              (funcall form))))
  5153.       ;; Search article body.
  5154.       (let ((gnus-current-article nil) ;Save article pointer.
  5155.         (gnus-last-article nil)
  5156.         (gnus-break-pages nil)    ;No need to break pages.
  5157.         (gnus-mark-article-hook nil)) ;Inhibit marking as read.
  5158.         (message "Searching for article: %d..." article)
  5159.         (gnus-article-setup-buffer)
  5160.         (gnus-article-prepare article t)
  5161.         (if (save-excursion
  5162.           (set-buffer gnus-article-buffer)
  5163.           (goto-char (point-min))
  5164.           (re-search-forward regexp nil t))
  5165.         (if (stringp form)    ;Keyboard macro.
  5166.             (execute-kbd-macro form)
  5167.           (funcall form))))
  5168.       ))
  5169.       )))
  5170.  
  5171. ;;; caesar-region written by phr@prep.ai.mit.edu  Nov 86
  5172. ;;; modified by tower@prep Nov 86
  5173. ;;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47.
  5174.  
  5175. (defun gnus-caesar-region (&optional n)
  5176.   "Caesar rotation of region by N, default 13, for decrypting netnews.
  5177. ROT47 will be performed for Japanese text in any case."
  5178.   (interactive (if current-prefix-arg    ; Was there a prefix arg?
  5179.            (list (prefix-numeric-value current-prefix-arg))
  5180.          (list nil)))
  5181.   (cond ((not (numberp n)) (setq n 13))
  5182.     (t (setq n (mod n 26))))    ;canonicalize N
  5183.   (if (not (zerop n))        ; no action needed for a rot of 0
  5184.       (progn
  5185.     (if (or (not (boundp 'caesar-translate-table))
  5186.         (/= (aref caesar-translate-table ?a) (+ ?a n)))
  5187.         (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
  5188.           (message "Building caesar-translate-table...")
  5189.           (setq caesar-translate-table (make-vector 256 0))
  5190.           (while (< i 256)
  5191.         (aset caesar-translate-table i i)
  5192.         (setq i (1+ i)))
  5193.           (setq lower (concat lower lower) upper (upcase lower) i 0)
  5194.           (while (< i 26)
  5195.         (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
  5196.         (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
  5197.         (setq i (1+ i)))
  5198.           ;; ROT47 for Japanese text.
  5199.           ;; Thanks to ichikawa@flab.fujitsu.junet.
  5200.           (setq i 161)
  5201.           (let ((t1 (logior ?O 128))
  5202.             (t2 (logior ?! 128))
  5203.             (t3 (logior ?~ 128)))
  5204.         (while (< i 256)
  5205.           (aset caesar-translate-table i
  5206.             (let ((v (aref caesar-translate-table i)))
  5207.               (if (<= v t1) (if (< v t2) v (+ v 47))
  5208.                 (if (<= v t3) (- v 47) v))))
  5209.           (setq i (1+ i))))
  5210.           (message "Building caesar-translate-table... done")))
  5211.     (let ((from (region-beginning))
  5212.           (to (region-end))
  5213.           (i 0) str len)
  5214.       (setq str (buffer-substring from to))
  5215.       (setq len (length str))
  5216.       (while (< i len)
  5217.         (aset str i (aref caesar-translate-table (aref str i)))
  5218.         (setq i (1+ i)))
  5219.       (goto-char from)
  5220.       (delete-region from to)
  5221.       (insert str)))))
  5222.  
  5223. ;; Functions accessing headers.
  5224. ;; Functions are more convenient than macros in some case.
  5225.  
  5226. (defun gnus-header-number (header)
  5227.   "Return article number in HEADER."
  5228.   (nntp-header-number header))
  5229.  
  5230. (defun gnus-header-subject (header)
  5231.   "Return subject string in HEADER."
  5232.   (nntp-header-subject header))
  5233.  
  5234. (defun gnus-header-from (header)
  5235.   "Return author string in HEADER."
  5236.   (nntp-header-from header))
  5237.  
  5238. (defun gnus-header-xref (header)
  5239.   "Return xref string in HEADER."
  5240.   (nntp-header-xref header))
  5241.  
  5242. (defun gnus-header-lines (header)
  5243.   "Return lines in HEADER."
  5244.   (nntp-header-lines header))
  5245.  
  5246. (defun gnus-header-date (header)
  5247.   "Return date in HEADER."
  5248.   (nntp-header-date header))
  5249.  
  5250. (defun gnus-header-id (header)
  5251.   "Return Id in HEADER."
  5252.   (nntp-header-id header))
  5253.  
  5254. (defun gnus-header-references (header)
  5255.   "Return references in HEADER."
  5256.   (nntp-header-references header))
  5257.  
  5258.  
  5259. ;;;
  5260. ;;; Article savers.
  5261. ;;;
  5262.  
  5263. (defun gnus-output-to-rmail (file-name)
  5264.   "Append the current article to an Rmail file named FILE-NAME."
  5265.   (require 'rmail)
  5266.   ;; Most of these codes are borrowed from rmailout.el.
  5267.   (setq file-name (expand-file-name file-name))
  5268.   (setq rmail-default-rmail-file file-name)
  5269.   (let ((artbuf (current-buffer))
  5270.     (tmpbuf (get-buffer-create " *GNUS-output*")))
  5271.     (save-excursion
  5272.       (or (get-file-buffer file-name)
  5273.       (file-exists-p file-name)
  5274.       (if (yes-or-no-p
  5275.            (concat "\"" file-name "\" does not exist, create it? "))
  5276.           (let ((file-buffer (create-file-buffer file-name)))
  5277.         (save-excursion
  5278.           (set-buffer file-buffer)
  5279.           (rmail-insert-rmail-file-header)
  5280.           (let ((require-final-newline nil))
  5281.             (write-region (point-min) (point-max) file-name t 1)))
  5282.         (kill-buffer file-buffer))
  5283.         (error "Output file does not exist")))
  5284.       (set-buffer tmpbuf)
  5285.       (buffer-flush-undo (current-buffer))
  5286.       (erase-buffer)
  5287.       (insert-buffer-substring artbuf)
  5288.       (gnus-convert-article-to-rmail)
  5289.       ;; Decide whether to append to a file or to an Emacs buffer.
  5290.       (let ((outbuf (get-file-buffer file-name)))
  5291.     (if (not outbuf)
  5292.         (append-to-file (point-min) (point-max) file-name)
  5293.       ;; File has been visited, in buffer OUTBUF.
  5294.       (set-buffer outbuf)
  5295.       (let ((buffer-read-only nil)
  5296.         (msg (and (boundp 'rmail-current-message)
  5297.               rmail-current-message)))
  5298.         ;; If MSG is non-nil, buffer is in RMAIL mode.
  5299.         (if msg
  5300.         (progn (widen)
  5301.                (narrow-to-region (point-max) (point-max))))
  5302.         (insert-buffer-substring tmpbuf)
  5303.         (if msg
  5304.         (progn
  5305.           (goto-char (point-min))
  5306.           (widen)
  5307.           (search-backward "\^_")
  5308.           (narrow-to-region (point) (point-max))
  5309.           (goto-char (1+ (point-min)))
  5310.           (rmail-count-new-messages t)
  5311.           (rmail-show-message msg))))))
  5312.       )
  5313.     (kill-buffer tmpbuf)
  5314.     ))
  5315.  
  5316. (defun gnus-output-to-file (file-name)
  5317.   "Append the current article to a file named FILE-NAME."
  5318.   (setq file-name (expand-file-name file-name))
  5319.   (let ((artbuf (current-buffer))
  5320.     (tmpbuf (get-buffer-create " *GNUS-output*")))
  5321.     (save-excursion
  5322.       (set-buffer tmpbuf)
  5323.       (buffer-flush-undo (current-buffer))
  5324.       (erase-buffer)
  5325.       (insert-buffer-substring artbuf)
  5326.       ;; Append newline at end of the buffer as separator, and then
  5327.       ;; save it to file.
  5328.       (goto-char (point-max))
  5329.       (insert "\n")
  5330.       (append-to-file (point-min) (point-max) file-name))
  5331.     (kill-buffer tmpbuf)
  5332.     ))
  5333.  
  5334. (defun gnus-convert-article-to-rmail ()
  5335.   "Convert article in current buffer to Rmail message format."
  5336.   (let ((buffer-read-only nil))
  5337.     ;; Convert article directly into Babyl format.
  5338.     ;; Suggested by Rob Austein <sra@lcs.mit.edu>
  5339.     (goto-char (point-min))
  5340.     (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
  5341.     (while (search-forward "\n\^_" nil t) ;single char
  5342.       (replace-match "\n^_"))        ;2 chars: "^" and "_"
  5343.     (goto-char (point-max))
  5344.     (insert "\^_")))
  5345.  
  5346. ;;(defun gnus-convert-article-to-rmail ()
  5347. ;;  "Convert article in current buffer to Rmail message format."
  5348. ;;  (let ((buffer-read-only nil))
  5349. ;;    ;; Insert special header of Unix mail.
  5350. ;;    (goto-char (point-min))
  5351. ;;    (insert "From "
  5352. ;;        (or (mail-strip-quoted-names (mail-fetch-field "from"))
  5353. ;;        "unknown")
  5354. ;;        " " (current-time-string) "\n")
  5355. ;;    ;; Stop quoting `From' since this seems unnecessary in most cases.
  5356. ;;    ;; ``Quote'' "\nFrom " as "\n>From "
  5357. ;;    ;;(while (search-forward "\nFrom " nil t)
  5358. ;;    ;;  (forward-char -5)
  5359. ;;    ;;  (insert ?>))
  5360. ;;    ;; Convert article to babyl format.
  5361. ;;    (rmail-convert-to-babyl-format)
  5362. ;;    ))
  5363.  
  5364.  
  5365. ;;;
  5366. ;;; Internal functions.
  5367. ;;;
  5368.  
  5369. (defun gnus-start-news-server (&optional confirm)
  5370.   "Open network stream to remote NNTP server.
  5371. If optional argument CONFIRM is non-nil, ask you host that NNTP server
  5372. is running even if it is defined.
  5373. Run gnus-open-server-hook just before opening news server."
  5374.   (if (gnus-server-opened)
  5375.       ;; Stream is already opened.
  5376.       nil
  5377.     ;; Open NNTP server.
  5378.     (if (or confirm
  5379.         (null gnus-nntp-server))
  5380.     ;; If someone has set the service to nil, then this should always
  5381.     ;; be the local host.
  5382.     (if gnus-nntp-service
  5383.         (if (and (boundp 'gnus-secondary-servers) gnus-secondary-servers)
  5384.         ;; Read server name with completion.
  5385.         (setq gnus-nntp-server
  5386.               (completing-read "NNTP server: "
  5387.                        (cons (list gnus-nntp-server)
  5388.                          gnus-secondary-servers)
  5389.                        nil nil gnus-nntp-server))
  5390.           (setq gnus-nntp-server
  5391.             (read-string "NNTP server: " gnus-nntp-server)))
  5392.       (setq gnus-nntp-server "")))
  5393.     ;; If no server name is given, local host is assumed.
  5394.     (if (or (string-equal gnus-nntp-server "")
  5395.         (string-equal gnus-nntp-server "::")) ;RMS preference.
  5396.     (setq gnus-nntp-server (system-name)))
  5397.     ;; gnus-nntp-server must be either (system-name), ':DIRECTORY', or
  5398.     ;; nntp server name.  I mean '::' cannot be a value of
  5399.     ;; gnus-nntp-server.
  5400.     (cond ((and (null gnus-nntp-service)
  5401.         (string-equal gnus-nntp-server (system-name)))
  5402.        (require 'nnspool)
  5403.        (gnus-define-access-method 'nnspool)
  5404.        (message "Looking up local news spool..."))
  5405.       ((string-match ":" gnus-nntp-server)
  5406.        ;; :DIRECTORY
  5407.        (require 'mhspool)
  5408.        (gnus-define-access-method 'mhspool)
  5409.        (message "Looking up private directory..."))
  5410.       (t
  5411.        (gnus-define-access-method 'nntp)
  5412.        (message "Connecting to NNTP server on %s..." gnus-nntp-server)))
  5413.     (run-hooks 'gnus-open-server-hook)
  5414.     (cond ((gnus-server-opened)        ;Maybe opened in gnus-open-server-hook.
  5415.        (message ""))
  5416.       ((gnus-open-server gnus-nntp-server gnus-nntp-service)
  5417.        (message ""))
  5418.       (t
  5419.        (error
  5420.         (gnus-nntp-message
  5421.          (format "Cannot open NNTP server on %s" gnus-nntp-server)))))
  5422.     ))
  5423.  
  5424. ;; Dummy functions used only once. Should return nil.
  5425. (defun gnus-server-opened () nil)
  5426. (defun gnus-close-server () nil)
  5427.  
  5428. (defun gnus-nntp-message (&optional message)
  5429.   "Return a message returned from NNTP server.
  5430. If no message is available and optional MESSAGE is given, return it."
  5431.   (let ((status (gnus-status-message))
  5432.     (message (or message "")))
  5433.     (if (and (stringp status)
  5434.          (> (length status) 0))
  5435.     status message)))
  5436.  
  5437. (defun gnus-define-access-method (method &optional access-methods)
  5438.   "Define access functions for the access METHOD.
  5439. Methods definition is taken from optional argument ACCESS-METHODS or
  5440. the variable gnus-access-methods."
  5441.   (let ((bindings
  5442.      (cdr (assoc method (or access-methods gnus-access-methods)))))
  5443.     (if (null bindings)
  5444.     (error "Unknown access method: %s" method)
  5445.       ;; Should not use symbol-function here since overload does not work.
  5446.       (while bindings
  5447.     ;; Alist syntax is different from that of 3.14.3.
  5448.     (fset (car (car bindings)) (car (cdr (car bindings))))
  5449.     (setq bindings (cdr bindings)))
  5450.       )))
  5451.  
  5452. (defun gnus-select-newsgroup (group &optional show-all)
  5453.   "Select newsgroup GROUP.
  5454. If optional argument SHOW-ALL is non-nil, all of articles in the group
  5455. are selected."
  5456.   ;; Make sure a connection to NNTP server is alive.
  5457.   (gnus-start-news-server)
  5458.   (if (gnus-request-group group)
  5459.       (let ((articles nil))
  5460.     (setq gnus-newsgroup-name group)
  5461.     (setq gnus-newsgroup-unreads
  5462.           (gnus-uncompress-sequence
  5463.            (nthcdr 2 (gnus-gethash group gnus-unread-hashtb))))
  5464.     (cond (show-all
  5465.            ;; Select all active articles.
  5466.            (setq articles
  5467.              (gnus-uncompress-sequence
  5468.               (nthcdr 2 (gnus-gethash group gnus-active-hashtb)))))
  5469.           (t
  5470.            ;; Select unread articles only.
  5471.            (setq articles gnus-newsgroup-unreads)))
  5472.     ;; Require confirmation if selecting large newsgroup.
  5473.     (setq gnus-newsgroup-unselected nil)
  5474.     (if (not (numberp gnus-large-newsgroup))
  5475.         nil
  5476.       (let ((selected nil)
  5477.         (number (length articles)))
  5478.         (if (> number gnus-large-newsgroup)
  5479.         (progn
  5480.           (condition-case ()
  5481.               (let ((input
  5482.                  (read-string
  5483.                   (format
  5484.                    "How many articles from %s (default %d): "
  5485.                    gnus-newsgroup-name number))))
  5486.             (setq selected
  5487.                   (if (string-equal input "")
  5488.                   number (string-to-int input))))
  5489.             (quit
  5490.              (setq selected 0)))
  5491.           (cond ((and (> selected 0)
  5492.                   (< selected number))
  5493.              ;; Select last N articles.
  5494.              (setq articles (nthcdr (- number selected) articles)))
  5495.             ((and (< selected 0)
  5496.                   (< (- 0 selected) number))
  5497.              ;; Select first N articles.
  5498.              (setq selected (- 0 selected))
  5499.              (setq articles (copy-sequence articles))
  5500.              (setcdr (nthcdr (1- selected) articles) nil))
  5501.             ((zerop selected)
  5502.              (setq articles nil))
  5503.             ;; Otherwise select all.
  5504.             )
  5505.           ;; Get unselected unread articles.
  5506.           (setq gnus-newsgroup-unselected
  5507.             (gnus-set-difference gnus-newsgroup-unreads articles))
  5508.           ))
  5509.         ))
  5510.     ;; Get headers list.
  5511.     (setq gnus-newsgroup-headers (gnus-retrieve-headers articles))
  5512.     ;; UNREADS may contain expired articles, so we have to remove
  5513.     ;;  them from the list.
  5514.     (setq gnus-newsgroup-unreads
  5515.           (gnus-intersection gnus-newsgroup-unreads
  5516.                  (mapcar
  5517.                   (function
  5518.                    (lambda (header)
  5519.                      (nntp-header-number header)))
  5520.                   gnus-newsgroup-headers)))
  5521.     ;; Marked article must be a subset of unread articles.
  5522.     (setq gnus-newsgroup-marked
  5523.           (gnus-intersection (append gnus-newsgroup-unselected
  5524.                      gnus-newsgroup-unreads)
  5525.                  (cdr
  5526.                   (gnus-gethash group gnus-marked-hashtb))))
  5527.     ;; First and last article in this newsgroup.
  5528.     (setq gnus-newsgroup-begin
  5529.           (if gnus-newsgroup-headers
  5530.           (nntp-header-number (car gnus-newsgroup-headers))
  5531.         0
  5532.         ))
  5533.     (setq gnus-newsgroup-end
  5534.           (if gnus-newsgroup-headers
  5535.           (nntp-header-number
  5536.            (gnus-last-element gnus-newsgroup-headers))
  5537.         0
  5538.         ))
  5539.     ;; File name that an article was saved last.
  5540.     (setq gnus-newsgroup-last-rmail nil)
  5541.     (setq gnus-newsgroup-last-mail nil)
  5542.     (setq gnus-newsgroup-last-folder nil)
  5543.     (setq gnus-newsgroup-last-file nil)
  5544.     ;; Reset article pointer etc.
  5545.     (setq gnus-current-article nil)
  5546.     (setq gnus-current-headers nil)
  5547.     (setq gnus-current-history nil)
  5548.     (setq gnus-have-all-headers nil)
  5549.     (setq gnus-last-article nil)
  5550.     ;; Clear old hash tables for the variable gnus-newsgroup-headers.
  5551.     (gnus-clear-hashtables-for-newsgroup-headers)
  5552.     ;; GROUP is successfully selected.
  5553.     t
  5554.     )
  5555.     ))
  5556.  
  5557. ;; Hacking for making header search much faster.
  5558.  
  5559. (defun gnus-get-header-by-number (number)
  5560.   "Return a header specified by a NUMBER.
  5561. If the variable gnus-newsgroup-headers is updated, the hashed table
  5562. gnus-newsgroup-headers-hashtb-by-number must be set to nil to indicate
  5563. rehash is necessary."
  5564.   (or gnus-newsgroup-headers-hashtb-by-number
  5565.       (gnus-make-headers-hashtable-by-number))
  5566.   (gnus-gethash (int-to-string number)
  5567.         gnus-newsgroup-headers-hashtb-by-number))
  5568.  
  5569. (defun gnus-get-header-by-id (id)
  5570.   "Return a header specified by an ID.
  5571. If the variable gnus-newsgroup-headers is updated, the hashed table
  5572. gnus-newsgroup-headers-hashtb-by-id must be set to nil to indicate
  5573. rehash is necessary."
  5574.   (or gnus-newsgroup-headers-hashtb-by-id
  5575.       (gnus-make-headers-hashtable-by-id))
  5576.   (and (stringp id)
  5577.        (gnus-gethash id gnus-newsgroup-headers-hashtb-by-id)))
  5578.  
  5579. (defun gnus-make-headers-hashtable-by-number ()
  5580.   "Make hashtable for the variable gnus-newsgroup-headers by number."
  5581.   (let ((header nil)
  5582.     (headers gnus-newsgroup-headers))
  5583.     (setq gnus-newsgroup-headers-hashtb-by-number
  5584.       (gnus-make-hashtable (length headers)))
  5585.     (while headers
  5586.       (setq header (car headers))
  5587.       (gnus-sethash (int-to-string (nntp-header-number header))
  5588.             header gnus-newsgroup-headers-hashtb-by-number)
  5589.       (setq headers (cdr headers))
  5590.       )))
  5591.  
  5592. (defun gnus-make-headers-hashtable-by-id ()
  5593.   "Make hashtable for the variable gnus-newsgroup-headers by id."
  5594.   (let ((header nil)
  5595.     (headers gnus-newsgroup-headers))
  5596.     (setq gnus-newsgroup-headers-hashtb-by-id
  5597.       (gnus-make-hashtable (length headers)))
  5598.     (while headers
  5599.       (setq header (car headers))
  5600.       (gnus-sethash (nntp-header-id header)
  5601.             header gnus-newsgroup-headers-hashtb-by-id)
  5602.       (setq headers (cdr headers))
  5603.       )))
  5604.  
  5605. (defun gnus-clear-hashtables-for-newsgroup-headers ()
  5606.   "Clear hash tables created for the variable gnus-newsgroup-headers."
  5607.   (setq gnus-newsgroup-headers-hashtb-by-id nil)
  5608.   (setq gnus-newsgroup-headers-hashtb-by-number nil))
  5609.  
  5610. (defun gnus-more-header-backward ()
  5611.   "Find new header backward."
  5612.   (let ((first
  5613.      (car (nth 2 (gnus-gethash gnus-newsgroup-name gnus-active-hashtb))))
  5614.     (artnum gnus-newsgroup-begin)
  5615.     (header nil))
  5616.     (while (and (not header)
  5617.         (> artnum first))
  5618.       (setq artnum (1- artnum))
  5619.       (setq header (car (gnus-retrieve-headers (list artnum)))))
  5620.     header
  5621.     ))
  5622.  
  5623. (defun gnus-more-header-forward ()
  5624.   "Find new header forward."
  5625.   (let ((last
  5626.      (cdr (nth 2 (gnus-gethash gnus-newsgroup-name gnus-active-hashtb))))
  5627.     (artnum gnus-newsgroup-end)
  5628.     (header nil))
  5629.     (while (and (not header)
  5630.         (< artnum last))
  5631.       (setq artnum (1+ artnum))
  5632.       (setq header (car (gnus-retrieve-headers (list artnum)))))
  5633.     header
  5634.     ))
  5635.  
  5636. (defun gnus-extend-newsgroup (header &optional backward)
  5637.   "Extend newsgroup selection with HEADER.
  5638. Optional argument BACKWARD means extend toward backward."
  5639.   (if header
  5640.       (let ((artnum (nntp-header-number header)))
  5641.     (setq gnus-newsgroup-headers
  5642.           (if backward
  5643.           (cons header gnus-newsgroup-headers)
  5644.         (append gnus-newsgroup-headers (list header))))
  5645.     ;; Clear current hash tables for the variable gnus-newsgroup-headers.
  5646.     (gnus-clear-hashtables-for-newsgroup-headers)
  5647.     ;; We have to update unreads and unselected, but don't have to
  5648.     ;; care about gnus-newsgroup-marked.
  5649.     (if (memq artnum gnus-newsgroup-unselected)
  5650.         (setq gnus-newsgroup-unreads
  5651.           (cons artnum gnus-newsgroup-unreads)))
  5652.     (setq gnus-newsgroup-unselected
  5653.           (delq artnum gnus-newsgroup-unselected))
  5654.     (setq gnus-newsgroup-begin (min gnus-newsgroup-begin artnum))
  5655.     (setq gnus-newsgroup-end (max gnus-newsgroup-end artnum))
  5656.     )))
  5657.  
  5658. (defun gnus-mark-article-as-read (article)
  5659.   "Remember that ARTICLE is marked as read."
  5660.   ;; Remove from unread and marked list.
  5661.   (setq gnus-newsgroup-unreads
  5662.     (delq article gnus-newsgroup-unreads))
  5663.   (setq gnus-newsgroup-marked
  5664.     (delq article gnus-newsgroup-marked)))
  5665.  
  5666. (defun gnus-mark-article-as-unread (article &optional clear-mark)
  5667.   "Remember that ARTICLE is marked as unread.
  5668. Optional argument CLEAR-MARK means ARTICLE should not be remembered
  5669. that it was marked as read once."
  5670.   ;; Add to unread list.
  5671.   (or (memq article gnus-newsgroup-unreads)
  5672.       (setq gnus-newsgroup-unreads
  5673.         (cons article gnus-newsgroup-unreads)))
  5674.   ;; If CLEAR-MARK is non-nil, the article must be removed from marked
  5675.   ;; list.  Otherwise, it must be added to the list.
  5676.   (if clear-mark
  5677.       (setq gnus-newsgroup-marked
  5678.         (delq article gnus-newsgroup-marked))
  5679.     (or (memq article gnus-newsgroup-marked)
  5680.     (setq gnus-newsgroup-marked
  5681.           (cons article gnus-newsgroup-marked)))))
  5682.  
  5683. (defun gnus-clear-system ()
  5684.   "Clear all variables and buffer."
  5685.   ;; Clear GNUS variables.
  5686.   (let ((variables gnus-variable-list))
  5687.     (while variables
  5688.       (set (car variables) nil)
  5689.       (setq variables (cdr variables))))
  5690.   ;; Clear other internal variables.
  5691.   (setq gnus-newsrc-hashtb nil)
  5692.   (setq gnus-marked-hashtb nil)
  5693.   (setq gnus-killed-hashtb nil)
  5694.   (setq gnus-active-hashtb nil)
  5695.   (setq gnus-octive-hashtb nil)
  5696.   (setq gnus-unread-hashtb nil)
  5697.   (setq gnus-newsgroup-headers nil)
  5698.   (setq gnus-newsgroup-headers-hashtb-by-id nil)
  5699.   (setq gnus-newsgroup-headers-hashtb-by-number nil)
  5700.   ;; Kill the startup file.
  5701.   (and gnus-current-startup-file
  5702.        (get-file-buffer gnus-current-startup-file)
  5703.        (kill-buffer (get-file-buffer gnus-current-startup-file)))
  5704.   (setq gnus-current-startup-file nil)
  5705.   ;; Kill GNUS buffers.
  5706.   (let ((buffers gnus-buffer-list))
  5707.     (while buffers
  5708.       (if (get-buffer (car buffers))
  5709.       (kill-buffer (car buffers)))
  5710.       (setq buffers (cdr buffers))
  5711.       )))
  5712.  
  5713. (defun gnus-configure-windows (action)
  5714.   "Configure GNUS windows according to the next ACTION.
  5715. The ACTION is either a symbol, such as `summary', or a
  5716. configuration list such as `(1 1 2)'.  If ACTION is not a list,
  5717. configuration list is got from the variable gnus-window-configuration."
  5718.   (let* ((windows
  5719.       (if (listp action)
  5720.           action (car (cdr (assq action gnus-window-configuration)))))
  5721.      (grpwin (get-buffer-window gnus-group-buffer))
  5722.      (subwin (get-buffer-window gnus-summary-buffer))
  5723.      (artwin (get-buffer-window gnus-article-buffer))
  5724.      (winsum nil)
  5725.      (height nil)
  5726.      (grpheight 0)
  5727.      (subheight 0)
  5728.      (artheight 0))
  5729.     (if (or (null windows)        ;No configuration is specified.
  5730.         (and (eq (null grpwin)
  5731.              (zerop (nth 0 windows)))
  5732.          (eq (null subwin)
  5733.              (zerop (nth 1 windows)))
  5734.          (eq (null artwin)
  5735.              (zerop (nth 2 windows)))))
  5736.     ;; No need to change window configuration.
  5737.     nil
  5738.       (select-window (or grpwin subwin artwin (selected-window)))
  5739.       ;; First of all, compute the height of each window.
  5740.       (cond (gnus-use-full-window
  5741.          ;; Take up the entire screen.
  5742.          (delete-other-windows)
  5743.          (setq height (window-height (selected-window))))
  5744.         (t
  5745.          (setq height (+ (if grpwin (window-height grpwin) 0)
  5746.                  (if subwin (window-height subwin) 0)
  5747.                  (if artwin (window-height artwin) 0)))))
  5748.       ;; The Newsgroup buffer exits always. So, use it to extend the
  5749.       ;; Group window so as to get enough window space.
  5750.       (switch-to-buffer gnus-group-buffer 'norecord)
  5751.       (and (get-buffer gnus-summary-buffer)
  5752.        (delete-windows-on gnus-summary-buffer))
  5753.       (and (get-buffer gnus-article-buffer)
  5754.        (delete-windows-on gnus-article-buffer))
  5755.       ;; Compute expected window height.
  5756.       (setq winsum (apply (function +) windows))
  5757.       (if (not (zerop (nth 0 windows)))
  5758.       (setq grpheight (max window-min-height
  5759.                    (/ (* height (nth 0 windows)) winsum))))
  5760.       (if (not (zerop (nth 1 windows)))
  5761.       (setq subheight (max window-min-height
  5762.                    (/ (* height (nth 1 windows)) winsum))))
  5763.       (if (not (zerop (nth 2 windows)))
  5764.       (setq artheight (max window-min-height
  5765.                    (/ (* height (nth 2 windows)) winsum))))
  5766.       (setq height (+ grpheight subheight artheight))
  5767.       (enlarge-window (max 0 (- height (window-height (selected-window)))))
  5768.       ;; Then split the window.
  5769.       (and (not (zerop artheight))
  5770.        (or (not (zerop grpheight))
  5771.            (not (zerop subheight)))
  5772.        (split-window-vertically (+ grpheight subheight)))
  5773.       (and (not (zerop grpheight))
  5774.        (not (zerop subheight))
  5775.        (split-window-vertically grpheight))
  5776.       ;; Then select buffers in each window.
  5777.       (and (not (zerop grpheight))
  5778.        (progn
  5779.          (switch-to-buffer gnus-group-buffer 'norecord)
  5780.          (other-window 1)))
  5781.       (and (not (zerop subheight))
  5782.        (progn
  5783.          (switch-to-buffer gnus-summary-buffer 'norecord)
  5784.          (other-window 1)))
  5785.       (and (not (zerop artheight))
  5786.        (progn
  5787.          ;; If Article buffer does not exist, it will be created
  5788.          ;; and initialized.
  5789.          (gnus-article-setup-buffer)
  5790.          (switch-to-buffer gnus-article-buffer 'norecord)))
  5791.       )
  5792.     ))
  5793.  
  5794. (defun gnus-find-header-by-number (headers number)
  5795.   "Return a header which is a element of HEADERS and has NUMBER."
  5796.   (let ((found nil))
  5797.     (while (and headers (not found))
  5798.       ;; We cannot use `=' to accept non-numeric NUMBER.
  5799.       (if (eq number (nntp-header-number (car headers)))
  5800.       (setq found (car headers)))
  5801.       (setq headers (cdr headers)))
  5802.     found
  5803.     ))
  5804.  
  5805. (defun gnus-find-header-by-id (headers id)
  5806.   "Return a header which is a element of HEADERS and has Message-ID."
  5807.   (let ((found nil))
  5808.     (while (and headers (not found))
  5809.       (if (string-equal id (nntp-header-id (car headers)))
  5810.       (setq found (car headers)))
  5811.       (setq headers (cdr headers)))
  5812.     found
  5813.     ))
  5814.  
  5815. (defun gnus-version ()
  5816.   "Version numbers of this version of GNUS."
  5817.   (interactive)
  5818.   (cond ((and (boundp 'mhspool-version) (boundp 'nnspool-version))
  5819.      (message "%s; %s; %s; %s"
  5820.           gnus-version nntp-version nnspool-version mhspool-version))
  5821.     ((boundp 'mhspool-version)
  5822.      (message "%s; %s; %s"
  5823.           gnus-version nntp-version mhspool-version))
  5824.     ((boundp 'nnspool-version)
  5825.      (message "%s; %s; %s"
  5826.           gnus-version nntp-version nnspool-version))
  5827.     (t
  5828.      (message "%s; %s" gnus-version nntp-version))))
  5829.  
  5830. (defun gnus-info-find-node ()
  5831.   "Find Info documentation of GNUS."
  5832.   (interactive)
  5833.   (require 'info)
  5834.   ;; Enlarge info window if needed.
  5835.   (cond ((eq major-mode 'gnus-group-mode)
  5836.      (gnus-configure-windows '(1 0 0)) ;Take all windows.
  5837.      (pop-to-buffer gnus-group-buffer))
  5838.     ((eq major-mode 'gnus-summary-mode)
  5839.      (gnus-configure-windows '(0 1 0)) ;Take all windows.
  5840.      (pop-to-buffer gnus-summary-buffer)))
  5841.   (Info-goto-node (car (cdr (assq major-mode gnus-info-nodes)))))
  5842.  
  5843. (defun gnus-overload-functions (&optional overloads)
  5844.   "Overload functions specified by optional argument OVERLOADS.
  5845. If nothing is specified, use the variable gnus-overload-functions."
  5846.   (let ((defs nil)
  5847.     (overloads (or overloads gnus-overload-functions)))
  5848.     (while overloads
  5849.       (setq defs (car overloads))
  5850.       (setq overloads (cdr overloads))
  5851.       ;; Load file before overloading function if necessary.  Make
  5852.       ;; sure we cannot use `require' always.
  5853.       (and (not (fboundp (car defs)))
  5854.        (car (cdr (cdr defs)))
  5855.        (load (car (cdr (cdr defs))) nil 'nomessage))
  5856.       (fset (car defs) (car (cdr defs)))
  5857.       )))
  5858.  
  5859. (defun gnus-make-threads (newsgroup-headers)
  5860.   "Make conversation threads tree from NEWSGROUP-HEADERS."
  5861.   (let ((headers newsgroup-headers)
  5862.     (refer nil)
  5863.     (h nil)
  5864.     (d nil)
  5865.     (roots nil)
  5866.     (dependencies nil))
  5867.     ;; Make message dependency alist.
  5868.     (while headers
  5869.       (setq h (car headers))
  5870.       (setq headers (cdr headers))
  5871.       ;; Ignore invalid headers.
  5872.       (if (vectorp h)            ;Depends on nntp.el.
  5873.       (progn
  5874.         ;; Ignore broken references, e.g "<123@a.b.c".
  5875.         (setq refer (nntp-header-references h))
  5876.         (setq d (and refer
  5877.              (string-match "\\(<[^<>]+>\\)[^>]*$" refer)
  5878. ;;             (gnus-find-header-by-id
  5879. ;;              newsgroup-headers
  5880. ;;              (substring refer (match-beginning 1) (match-end 1)))
  5881.              ;; In fact if the variable newsgroup-headers
  5882.              ;; is not 'equal' to the variable
  5883.              ;; gnus-newsgroup-headers, the following
  5884.              ;; function call may return bogus value.
  5885.              (gnus-get-header-by-id
  5886.               (substring refer (match-beginning 1) (match-end 1)))
  5887.              ))
  5888.         ;; Check subject equality.
  5889.         (or gnus-thread-ignore-subject
  5890.         (null d)
  5891.         (string-equal (gnus-simplify-subject
  5892.                    (nntp-header-subject h) 're)
  5893.                   (gnus-simplify-subject
  5894.                    (nntp-header-subject d) 're))
  5895.         ;; H should be a thread root.
  5896.         (setq d nil))
  5897.         ;; H depends on D.
  5898.         (setq dependencies
  5899.           (cons (cons h d) dependencies))
  5900.         ;; H is a thread root.
  5901.         (if (null d)
  5902.         (setq roots (cons h roots)))
  5903.         ))
  5904.       )
  5905.     ;; Make complete threads from the roots.
  5906.     ;; Note: dependencies are in reverse order, but
  5907.     ;; gnus-make-threads-1 processes it in reverse order again.  So,
  5908.     ;; we don't have to worry about it.
  5909.     (mapcar
  5910.      (function
  5911.       (lambda (root)
  5912.     (gnus-make-threads-1 root dependencies))) (nreverse roots))
  5913.     ))
  5914.  
  5915. (defun gnus-make-threads-1 (parent dependencies)
  5916.   (let ((children nil)
  5917.     (d nil)
  5918.     (depends dependencies))
  5919.     ;; Find children.
  5920.     (while depends
  5921.       (setq d (car depends))
  5922.       (setq depends (cdr depends))
  5923.       (and (cdr d)
  5924.        (eq (nntp-header-id parent) (nntp-header-id (cdr d)))
  5925.        (setq children (cons (car d) children))))
  5926.     ;; Go down.
  5927.     (cons parent
  5928.       (mapcar
  5929.        (function
  5930.         (lambda (child)
  5931.           (gnus-make-threads-1 child dependencies))) children))
  5932.     ))
  5933.  
  5934. (defun gnus-narrow-to-page (&optional arg)
  5935.   "Make text outside current page invisible except for page delimiter.
  5936. A numeric arg specifies to move forward or backward by that many pages,
  5937. thus showing a page other than the one point was originally in."
  5938.   (interactive "P")
  5939.   (setq arg (if arg (prefix-numeric-value arg) 0))
  5940.   (save-excursion
  5941.     (forward-page -1)            ;Beginning of current page.
  5942.     (widen)
  5943.     (if (> arg 0)
  5944.     (forward-page arg)
  5945.       (if (< arg 0)
  5946.       (forward-page (1- arg))))
  5947.     ;; Find the end of the page.
  5948.     (forward-page)
  5949.     ;; If we stopped due to end of buffer, stay there.
  5950.     ;; If we stopped after a page delimiter, put end of restriction
  5951.     ;; at the beginning of that line.
  5952.     ;; These are commented out.
  5953.     ;;    (if (save-excursion (beginning-of-line)
  5954.     ;;            (looking-at page-delimiter))
  5955.     ;;    (beginning-of-line))
  5956.     (narrow-to-region (point)
  5957.               (progn
  5958.             ;; Find the top of the page.
  5959.             (forward-page -1)
  5960.             ;; If we found beginning of buffer, stay there.
  5961.             ;; If extra text follows page delimiter on same line,
  5962.             ;; include it.
  5963.             ;; Otherwise, show text starting with following line.
  5964.             (if (and (eolp) (not (bobp)))
  5965.                 (forward-line 1))
  5966.             (point)))
  5967.     ))
  5968.  
  5969. ;; Create hash table for alist, such as gnus-newsrc-assoc,
  5970. ;; gnus-killed-assoc, and gnus-marked-assoc.
  5971.  
  5972. (defun gnus-make-hashtable-from-alist (alist &optional hashsize)
  5973.   "Return hash table for ALIST.
  5974. Optional argument HASHSIZE specifies the hashtable size.
  5975. Hash key is a car of alist element, which must be a string."
  5976.   (let ((hashtb (gnus-make-hashtable (or hashsize (length alist)))))
  5977.     (while alist
  5978.       (gnus-sethash (car (car alist))    ;Newsgroup name
  5979.             (car alist)        ;Alist element
  5980.             hashtb)
  5981.       (setq alist (cdr alist)))
  5982.     hashtb
  5983.     ))
  5984.  
  5985. (defun gnus-last-element (list)
  5986.   "Return last element of LIST."
  5987.   (let ((last nil))
  5988.     (while list
  5989.       (if (null (cdr list))
  5990.       (setq last (car list)))
  5991.       (setq list (cdr list)))
  5992.     last
  5993.     ))
  5994.  
  5995. (defun gnus-set-difference (list1 list2)
  5996.   "Return a list of elements of LIST1 that do not appear in LIST2."
  5997.   (let ((list1 (copy-sequence list1)))
  5998.     (while list2
  5999.       (setq list1 (delq (car list2) list1))
  6000.       (setq list2 (cdr list2)))
  6001.     list1
  6002.     ))
  6003.  
  6004. (defun gnus-intersection (list1 list2)
  6005.   "Return a list of elements that appear in both LIST1 and LIST2."
  6006.   (let ((result nil))
  6007.     (while list2
  6008.       (if (memq (car list2) list1)
  6009.       (setq result (cons (car list2) result)))
  6010.       (setq list2 (cdr list2)))
  6011.     result
  6012.     ))
  6013.  
  6014.  
  6015. ;;;
  6016. ;;; Get information about active articles, already read articles, and
  6017. ;;;  still unread articles.
  6018. ;;;
  6019.  
  6020. ;; GNUS internal format of gnus-newsrc-assoc and gnus-killed-assoc:
  6021. ;; (("general" t (1 . 1))
  6022. ;;  ("misc"    t (1 . 10) (12 . 15))
  6023. ;;  ("test"  nil (1 . 99)) ...)
  6024. ;; GNUS internal format of gnus-marked-assoc:
  6025. ;; (("general" 1 2 3)
  6026. ;;  ("misc" 2) ...)
  6027. ;; GNUS internal format of gnus-active-hashtb:
  6028. ;; (("general" t (1 . 1))
  6029. ;;  ("misc"    t (1 . 10))
  6030. ;;  ("test"  nil (1 . 99)) ...)
  6031. ;; GNUS internal format of gnus-unread-hashtb:
  6032. ;; (("general" 1 (1 . 1))
  6033. ;;  ("misc"   14 (1 . 10) (12 . 15))
  6034. ;;  ("test"   99 (1 . 99)) ...)
  6035.  
  6036. (defun gnus-setup-news (&optional rawfile)
  6037.   "Setup news information.
  6038. If optional argument RAWFILE is non-nil, force to read raw startup file."
  6039.   (let ((init (not (and gnus-newsrc-assoc
  6040.             gnus-active-hashtb
  6041.             gnus-unread-hashtb
  6042.             (not rawfile)
  6043.             ))))
  6044.     ;; We have to clear some variables to re-initialize news info.
  6045.     (if init
  6046.     (setq gnus-newsrc-assoc nil
  6047.           gnus-active-hashtb nil
  6048.           gnus-unread-hashtb nil))
  6049.     (gnus-read-active-file)
  6050.     ;; Initialize only once.
  6051.     (if init
  6052.     (progn
  6053.       ;; Get distributions only once.
  6054.       (gnus-read-distributions-file)
  6055.       ;; newsrc file must be read after reading active file since
  6056.       ;; its size is used to guess the size of gnus-newsrc-hashtb.
  6057.       (gnus-read-newsrc-file rawfile)
  6058.       ))
  6059.     (gnus-expire-marked-articles)
  6060.     (gnus-get-unread-articles)
  6061.     ;; Check new newsgroups and subscribe them.
  6062.     (if init
  6063.     (let ((new-newsgroups (gnus-find-new-newsgroups)))
  6064.       (while new-newsgroups
  6065.         (funcall gnus-subscribe-newsgroup-method (car new-newsgroups))
  6066.         (setq new-newsgroups (cdr new-newsgroups))
  6067.         )))
  6068.     ))
  6069.  
  6070. (defun gnus-add-newsgroup (newsgroup)
  6071.   "Subscribe new NEWSGROUP safely and put it at top."
  6072.   (and (null (gnus-gethash newsgroup gnus-newsrc-hashtb)) ;Really new?
  6073.        (gnus-gethash newsgroup gnus-active-hashtb) ;Really exist?
  6074.        (gnus-insert-newsgroup (or (gnus-gethash newsgroup gnus-killed-hashtb)
  6075.                   (list newsgroup t))
  6076.                   (car (car gnus-newsrc-assoc)))))
  6077.  
  6078. (defun gnus-find-new-newsgroups ()
  6079.   "Looking for new newsgroups and return names.
  6080. `-n' option of options line in .newsrc file is recognized."
  6081.   (let ((group nil)
  6082.     (new-newsgroups nil))
  6083.     (mapatoms
  6084.      (function
  6085.       (lambda (sym)
  6086.     (setq group (symbol-name sym))
  6087.     ;; Taking account of `-n' option.
  6088.     (and (or (null gnus-newsrc-options-n-no)
  6089.          (not (string-match gnus-newsrc-options-n-no group))
  6090.          (and gnus-newsrc-options-n-yes
  6091.               (string-match gnus-newsrc-options-n-yes group)))
  6092.          (null (gnus-gethash group gnus-killed-hashtb)) ;Ignore killed.
  6093.          (null (gnus-gethash group gnus-newsrc-hashtb)) ;Really new.
  6094.          ;; Find new newsgroup.
  6095.          (setq new-newsgroups
  6096.            (cons group new-newsgroups)))
  6097.     ))
  6098.      gnus-active-hashtb)
  6099.     ;; Return new newsgroups.
  6100.     new-newsgroups
  6101.     ))
  6102.  
  6103. (defun gnus-kill-newsgroup (group)
  6104.   "Kill GROUP from gnus-newsrc-assoc, .newsrc and gnus-unread-hashtb."
  6105.   (let ((info (gnus-gethash group gnus-newsrc-hashtb)))
  6106.     (if (null info)
  6107.     nil
  6108.       ;; Delete from gnus-newsrc-assoc and gnus-newsrc-hashtb.
  6109.       (setq gnus-newsrc-assoc (delq info gnus-newsrc-assoc))
  6110.       (gnus-sethash group nil gnus-newsrc-hashtb)
  6111.       ;; Add to gnus-killed-assoc and gnus-killed-hashtb.
  6112.       (setq gnus-killed-assoc
  6113.         (cons info
  6114.           (delq (gnus-gethash group gnus-killed-hashtb)
  6115.             gnus-killed-assoc)))
  6116.       (gnus-sethash group info gnus-killed-hashtb)
  6117.       ;; Clear unread hashtable.
  6118.       ;; Thanks cwitty@csli.Stanford.EDU (Carl Witty).
  6119.       (gnus-sethash group nil gnus-unread-hashtb)
  6120.       ;; Then delete from .newsrc
  6121.       (gnus-update-newsrc-buffer group 'delete)
  6122.       ;; Return the deleted newsrc entry.
  6123.       info
  6124.       )))
  6125.  
  6126. (defun gnus-insert-newsgroup (info &optional next)
  6127.   "Insert newsrc INFO entry before NEXT.
  6128. If optional argument NEXT is nil, appended to the last."
  6129.   (if (null info)
  6130.       (error "Invalid argument: %s" info))
  6131.   (let* ((group (car info))        ;Newsgroup name.
  6132.      (range
  6133.       (gnus-difference-of-range
  6134.        (nth 2 (gnus-gethash group gnus-active-hashtb)) (nthcdr 2 info))))
  6135.     ;; Check duplication.
  6136.     (if (gnus-gethash group gnus-newsrc-hashtb)
  6137.     (error "Duplicated: %s" group))
  6138.     ;; Insert to gnus-newsrc-assoc and gnus-newsrc-hashtb.
  6139.     (if (string-equal next (car (car gnus-newsrc-assoc)))
  6140.     (setq gnus-newsrc-assoc
  6141.           (cons info gnus-newsrc-assoc))
  6142.       (let ((found nil)
  6143.         (rest (cdr gnus-newsrc-assoc))
  6144.         (tail gnus-newsrc-assoc))
  6145.     ;; Seach insertion point.
  6146.     (while (and (not found) rest)
  6147.       (if (string-equal next (car (car rest)))
  6148.           (setq found t)
  6149.         (setq rest (cdr rest))
  6150.         (setq tail (cdr tail))
  6151.         ))
  6152.     ;; Find it.
  6153.     (if (consp tail)
  6154.         (setcdr tail (cons info rest))
  6155.       ;; gnus-newsrc-assoc must be nil.
  6156.       (setq gnus-newsrc-assoc
  6157.         (append gnus-newsrc-assoc (cons info rest))))
  6158.     ))
  6159.     (gnus-sethash group info gnus-newsrc-hashtb)
  6160.     ;; Delete from gnus-killed-assoc and gnus-killed-hashtb.
  6161.     (setq gnus-killed-assoc
  6162.       (delq (gnus-gethash group gnus-killed-hashtb) gnus-killed-assoc))
  6163.     (gnus-sethash group nil gnus-killed-hashtb)
  6164.     ;; Then insert to .newsrc.
  6165.     (gnus-update-newsrc-buffer group nil next)
  6166.     ;; Add to gnus-unread-hashtb.
  6167.     (gnus-sethash group
  6168.           (cons group        ;Newsgroup name.
  6169.             (cons (gnus-number-of-articles range) range))
  6170.           gnus-unread-hashtb)
  6171.     ))
  6172.  
  6173. (defun gnus-check-killed-newsgroups ()
  6174.   "Check consistency between gnus-newsrc-assoc and gnus-killed-assoc.
  6175. gnus-killed-hashtb is also updated."
  6176.   (let ((group nil)
  6177.     (new-killed nil)
  6178.     (old-killed gnus-killed-assoc))
  6179.     (while old-killed
  6180.       (setq group (car (car old-killed)))
  6181.       (and (or (null gnus-newsrc-options-n-no)
  6182.            (not (string-match gnus-newsrc-options-n-no group))
  6183.            (and gnus-newsrc-options-n-yes
  6184.             (string-match gnus-newsrc-options-n-yes group)))
  6185.        (null (gnus-gethash group gnus-newsrc-hashtb)) ;No duplication.
  6186.        ;; Subscribed in options line and not in gnus-newsrc-assoc.
  6187.        (setq new-killed
  6188.          (cons (car old-killed) new-killed)))
  6189.       (setq old-killed (cdr old-killed))
  6190.       )
  6191.     (setq gnus-killed-assoc (nreverse new-killed))
  6192.     (setq gnus-killed-hashtb
  6193.       (gnus-make-hashtable-from-alist gnus-killed-assoc))
  6194.     ))
  6195.  
  6196. (defun gnus-check-bogus-newsgroups (&optional confirm)
  6197.   "Delete bogus newsgroups.
  6198. If optional argument CONFIRM is non-nil, confirm deletion of newsgroups."
  6199.   (let ((group nil)            ;Newsgroup name temporary used.
  6200.     (old-newsrc gnus-newsrc-assoc)
  6201.     (new-newsrc nil)
  6202.     (bogus nil)            ;List of bogus newsgroups.
  6203.     (old-killed gnus-killed-assoc)
  6204.     (new-killed nil)
  6205.     (old-marked gnus-marked-assoc)
  6206.     (new-marked nil))
  6207.     (message "Checking bogus newsgroups...")
  6208.     ;; Update gnus-newsrc-assoc and gnus-newsrc-hashtb.
  6209.     (while old-newsrc
  6210.       (setq group (car (car old-newsrc)))
  6211.       (if (or (gnus-gethash group gnus-active-hashtb)
  6212.           (and confirm
  6213.            (not (y-or-n-p
  6214.              (format "Delete bogus newsgroup: %s " group)))))
  6215.       ;; Active newsgroup.
  6216.       (setq new-newsrc (cons (car old-newsrc) new-newsrc))
  6217.     ;; Found a bogus newsgroup.
  6218.     (setq bogus (cons group bogus)))
  6219.       (setq old-newsrc (cdr old-newsrc))
  6220.       )
  6221.     (setq gnus-newsrc-assoc (nreverse new-newsrc))
  6222.     (setq gnus-newsrc-hashtb
  6223.       (gnus-make-hashtable-from-alist gnus-newsrc-assoc))
  6224.     ;; Update gnus-killed-assoc and gnus-killed-hashtb.
  6225.     ;; The killed newsgroups are deleted without any confirmations.
  6226.     (while old-killed
  6227.       (setq group (car (car old-killed)))
  6228.       (and (gnus-gethash group gnus-active-hashtb)
  6229.        (null (gnus-gethash group gnus-newsrc-hashtb))
  6230.        ;; Active and really killed newsgroup.
  6231.        (setq new-killed (cons (car old-killed) new-killed)))
  6232.       (setq old-killed (cdr old-killed))
  6233.       )
  6234.     (setq gnus-killed-assoc (nreverse new-killed))
  6235.     (setq gnus-killed-hashtb
  6236.       (gnus-make-hashtable-from-alist gnus-killed-assoc))
  6237.     ;; Remove BOGUS from .newsrc file.
  6238.     (while bogus
  6239.       (gnus-update-newsrc-buffer (car bogus) 'delete)
  6240.       (setq bogus (cdr bogus)))
  6241.     ;; Update gnus-marked-assoc and gnus-marked-hashtb.
  6242.     (while old-marked
  6243.       (setq group (car (car old-marked)))
  6244.       (if (and (cdr (car old-marked))    ;Non-empty?
  6245.            (gnus-gethash group gnus-newsrc-hashtb))    ;Not bogus?
  6246.       (setq new-marked (cons (car old-marked) new-marked)))
  6247.       (setq old-marked (cdr old-marked)))
  6248.     (setq gnus-marked-assoc new-marked)
  6249.     (setq gnus-marked-hashtb
  6250.       (gnus-make-hashtable-from-alist gnus-marked-assoc))
  6251.     (message "Checking bogus newsgroups... done")
  6252.     ))
  6253.  
  6254. (defun gnus-get-unread-articles ()
  6255.   "Compute diffs between active and read articles."
  6256.   (let ((read gnus-newsrc-assoc)
  6257.     (group-info nil)
  6258.     (group-name nil)
  6259.     (active nil)
  6260.     (range nil))
  6261.     (message "Checking new news...")
  6262.     (or gnus-unread-hashtb
  6263.     (setq gnus-unread-hashtb
  6264.           (gnus-make-hashtable (length gnus-active-hashtb))))
  6265.     (while read
  6266.       (setq group-info (car read))    ;About one newsgroup
  6267.       (setq group-name (car group-info))
  6268.       (setq active (nth 2 (gnus-gethash group-name gnus-active-hashtb)))
  6269.       (if (and gnus-octive-hashtb
  6270.            ;; Is nothing changed?
  6271.            (equal active
  6272.               (nth 2 (gnus-gethash group-name gnus-octive-hashtb)))
  6273.            ;; Is this newsgroup in the unread hash table?
  6274.            (gnus-gethash group-name gnus-unread-hashtb)
  6275.            )
  6276.       nil                ;Nothing to do.
  6277.     (setq range (gnus-difference-of-range active (nthcdr 2 group-info)))
  6278.     (gnus-sethash group-name
  6279.               (cons group-name    ;Group name
  6280.                 (cons (gnus-number-of-articles range)
  6281.                   range)) ;Range of unread articles
  6282.               gnus-unread-hashtb)
  6283.     )
  6284.       (setq read (cdr read))
  6285.       )
  6286.     (message "Checking new news... done")
  6287.     ))
  6288.  
  6289. (defun gnus-expire-marked-articles ()
  6290.   "Check expired article which is marked as unread."
  6291.   (let ((marked-assoc gnus-marked-assoc)
  6292.     (updated-assoc nil)
  6293.     (marked nil)            ;Current marked info.
  6294.     (articles nil)            ;List of marked articles.
  6295.     (updated nil)            ;List of real marked.
  6296.     (begin nil))
  6297.     (while marked-assoc
  6298.       (setq marked (car marked-assoc))
  6299.       (setq articles (cdr marked))
  6300.       (setq updated nil)
  6301.       (setq begin
  6302.         (car (nth 2 (gnus-gethash (car marked) gnus-active-hashtb))))
  6303.       (while (and begin articles)
  6304.     (if (>= (car articles) begin)
  6305.         ;; This article is still active.
  6306.         (setq updated (cons (car articles) updated)))
  6307.     (setq articles (cdr articles)))
  6308.       (if updated
  6309.       (setq updated-assoc
  6310.         (cons (cons (car marked) updated) updated-assoc)))
  6311.       (setq marked-assoc (cdr marked-assoc)))
  6312.     (setq gnus-marked-assoc updated-assoc)
  6313.     (setq gnus-marked-hashtb
  6314.       (gnus-make-hashtable-from-alist gnus-marked-assoc))
  6315.     ))
  6316.  
  6317. (defun gnus-mark-as-read-by-xref
  6318.   (group headers unreads &optional subscribed-only)
  6319.   "Mark articles as read using cross references and return updated newsgroups.
  6320. Arguments are GROUP, HEADERS, UNREADS, and optional SUBSCRIBED-ONLY."
  6321.   (let ((xref-list nil)
  6322.     (header nil)
  6323.     (xrefs nil)            ;One Xref: field info.
  6324.     (xref nil)            ;(NEWSGROUP . ARTICLE)
  6325.     (gname nil)            ;Newsgroup name
  6326.     (article nil))            ;Article number
  6327.     (while headers
  6328.       (setq header (car headers))
  6329.       (if (memq (nntp-header-number header) unreads)
  6330.       ;; This article is not yet marked as read.
  6331.       nil
  6332.     (setq xrefs (gnus-parse-xref-field (nntp-header-xref header)))
  6333.     ;; For each cross reference info. in one Xref: field.
  6334.     (while xrefs
  6335.       (setq xref (car xrefs))
  6336.       (setq gname (car xref))    ;Newsgroup name
  6337.       (setq article (cdr xref))    ;Article number
  6338.       (or (string-equal group gname) ;Ignore current newsgroup.
  6339.           ;; Ignore unsubscribed newsgroup if requested.
  6340.           (and subscribed-only
  6341.            (not (nth 1 (gnus-gethash gname gnus-newsrc-hashtb))))
  6342.           ;; Ignore article marked as unread.
  6343.           (memq article (cdr (gnus-gethash gname gnus-marked-hashtb)))
  6344.           (let ((group-xref (assoc gname xref-list)))
  6345.         (if group-xref
  6346.             (if (memq article (cdr group-xref))
  6347.             nil        ;Alread marked.
  6348.               (setcdr group-xref (cons article (cdr group-xref))))
  6349.           ;; Create new assoc entry for GROUP.
  6350.           (setq xref-list (cons (list gname article) xref-list)))
  6351.         ))
  6352.       (setq xrefs (cdr xrefs))
  6353.       ))
  6354.       (setq headers (cdr headers)))
  6355.     ;; Mark cross referenced articles as read.
  6356.     (gnus-mark-xrefed-as-read xref-list)
  6357.     ;;(message "%s %s" (prin1-to-string unreads) (prin1-to-string xref-list))
  6358.     ;; Return list of updated group name.
  6359.     (mapcar (function car) xref-list)
  6360.     ))
  6361.  
  6362. (defun gnus-parse-xref-field (xref-value)
  6363.   "Parse Xref: field value, and return list of `(group . article-id)'."
  6364.   (let ((xref-list nil)
  6365.     (xref-value (or xref-value "")))
  6366.     ;; Remove server host name.
  6367.     (if (string-match "^[ \t]*[^ \t,]+[ \t,]+\\(.*\\)$" xref-value)
  6368.     (setq xref-value (substring xref-value (match-beginning 1)))
  6369.       (setq xref-value nil))
  6370.     ;; Process each xref info.
  6371.     (while xref-value
  6372.       (if (string-match
  6373.        "^[ \t,]*\\([^ \t,]+\\):\\([0-9]+\\)[^0-9]*" xref-value)
  6374.       (progn
  6375.         (setq xref-list
  6376.           (cons
  6377.            (cons
  6378.             ;; Group name
  6379.             (substring xref-value (match-beginning 1) (match-end 1))
  6380.             ;; Article-ID
  6381.             (string-to-int
  6382.              (substring xref-value (match-beginning 2) (match-end 2))))
  6383.            xref-list))
  6384.         (setq xref-value (substring xref-value (match-end 2))))
  6385.     (setq xref-value nil)))
  6386.     ;; Return alist.
  6387.     xref-list
  6388.     ))
  6389.  
  6390. (defun gnus-mark-xrefed-as-read (xrefs)
  6391.   "Update unread article information using XREFS alist."
  6392.   (let ((group nil)
  6393.     (idlist nil)
  6394.     (unread nil))
  6395.     (while xrefs
  6396.       (setq group (car (car xrefs)))
  6397.       (setq idlist (cdr (car xrefs)))
  6398.       (setq unread (gnus-uncompress-sequence
  6399.             (nthcdr 2 (gnus-gethash group gnus-unread-hashtb))))
  6400.       (while idlist
  6401.     (setq unread (delq (car idlist) unread))
  6402.     (setq idlist (cdr idlist)))
  6403.       (gnus-update-unread-articles group unread 'ignore)
  6404.       (setq xrefs (cdr xrefs))
  6405.       )))
  6406.  
  6407. (defun gnus-update-unread-articles (group unread-list marked-list)
  6408.   "Update unread articles of GROUP using UNREAD-LIST and MARKED-LIST."
  6409.   (let ((active (nth 2 (gnus-gethash group gnus-active-hashtb)))
  6410.     (unread (gnus-gethash group gnus-unread-hashtb)))
  6411.     (if (or (null active) (null unread))
  6412.     ;; Ignore unknown newsgroup.
  6413.     nil
  6414.       ;; Update gnus-unread-hashtb.
  6415.       (if unread-list
  6416.       (setcdr (cdr unread)
  6417.           (gnus-compress-sequence unread-list))
  6418.     ;; All of the articles are read.
  6419.     (setcdr (cdr unread) '((0 . 0))))
  6420.       ;; Number of unread articles.
  6421.       (setcar (cdr unread)
  6422.           (gnus-number-of-articles (nthcdr 2 unread)))
  6423.       ;; Update gnus-newsrc-assoc.
  6424.       (if (> (car active) 0)
  6425.       ;; Articles from 1 to N are not active.
  6426.       (setq active (cons 1 (cdr active))))
  6427.       (setcdr (cdr (gnus-gethash group gnus-newsrc-hashtb))
  6428.           (gnus-difference-of-range active (nthcdr 2 unread)))
  6429.       ;; Update .newsrc buffer.
  6430.       (gnus-update-newsrc-buffer group)
  6431.       ;; Update gnus-marked-assoc.
  6432.       (if (listp marked-list)        ;Includes NIL.
  6433.       (let ((marked (gnus-gethash group gnus-marked-hashtb)))
  6434.         (cond (marked        ;There is an entry.
  6435.            (setcdr marked marked-list))
  6436.           (marked-list        ;Non-NIL.
  6437.            (let ((info (cons group marked-list)))
  6438.              ;; hashtb must share the same cons cell.
  6439.              (setq gnus-marked-assoc
  6440.                (cons info gnus-marked-assoc))
  6441.              (gnus-sethash group info gnus-marked-hashtb)
  6442.              ))
  6443.           )))
  6444.       )))
  6445.  
  6446. (defun gnus-read-active-file ()
  6447.   "Get active file from NNTP server."
  6448.   ;; Make sure a connection to NNTP server is alive.
  6449.   (gnus-start-news-server)
  6450.   (message "Reading active file...")
  6451.   (if (gnus-request-list)        ;Get active file from server
  6452.       (save-excursion
  6453.     (set-buffer nntp-server-buffer)
  6454.     (gnus-active-to-gnus-format)
  6455.     (message "Reading active file... done"))
  6456.     (error "Cannot read active file from NNTP server.")))
  6457.  
  6458. (defun gnus-active-to-gnus-format ()
  6459.   "Convert active file format to internal format.
  6460. Lines matching gnus-ignored-newsgroups are ignored."
  6461.   ;; Delete unnecessary lines.
  6462.   (goto-char (point-min))
  6463.   ;;(delete-matching-lines "^to\\..*$")
  6464.   (delete-matching-lines gnus-ignored-newsgroups)
  6465.   ;; Save OLD active info.
  6466.   (setq gnus-octive-hashtb gnus-active-hashtb)
  6467.   ;; Make large enough hash table.
  6468.   (setq gnus-active-hashtb
  6469.     (gnus-make-hashtable (count-lines (point-min) (point-max))))
  6470.   ;; Store active file in hashtable.
  6471.   (goto-char (point-min))
  6472.   (while
  6473.       (re-search-forward
  6474.        "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([ymn]\\).*$"
  6475.        nil t)
  6476.     (gnus-sethash
  6477.      (buffer-substring (match-beginning 1) (match-end 1))
  6478.      (list (buffer-substring (match-beginning 1) (match-end 1))
  6479.        (string-equal
  6480.         "y" (buffer-substring (match-beginning 4) (match-end 4)))
  6481.        (cons (string-to-int
  6482.           (buffer-substring (match-beginning 3) (match-end 3)))
  6483.          (string-to-int
  6484.           (buffer-substring (match-beginning 2) (match-end 2)))))
  6485.      gnus-active-hashtb)
  6486.     ))
  6487.  
  6488. (defun gnus-read-newsrc-file (&optional rawfile)
  6489.   "Read startup FILE.
  6490. If optional argument RAWFILE is non-nil, the raw startup file is read."
  6491.   (setq gnus-current-startup-file (gnus-make-newsrc-file gnus-startup-file))
  6492.   ;; Reset variables which may be included in the quick startup file.
  6493.   (let ((variables gnus-variable-list))
  6494.     (while variables
  6495.       (set (car variables) nil)
  6496.       (setq variables (cdr variables))))
  6497.   (let* ((newsrc-file gnus-current-startup-file)
  6498.      (quick-file (concat newsrc-file ".el"))
  6499.      (quick-loaded nil))
  6500.     (save-excursion
  6501.       ;; Prepare .newsrc buffer.
  6502.       (set-buffer (find-file-noselect newsrc-file))
  6503.       ;; It is not so good idea turning off undo.
  6504.       ;;(buffer-flush-undo (current-buffer))
  6505.       ;; Load quick .newsrc to restore gnus-marked-assoc and
  6506.       ;; gnus-killed-assoc even if gnus-newsrc-assoc is out of date.
  6507.       (condition-case nil
  6508.       (progn
  6509.         (setq quick-loaded (load quick-file t t t))
  6510.         ;; Recreate hashtables.
  6511.         (setq gnus-killed-hashtb
  6512.           (gnus-make-hashtable-from-alist gnus-killed-assoc))
  6513.         (setq gnus-marked-hashtb
  6514.           (gnus-make-hashtable-from-alist gnus-marked-assoc))
  6515.         )
  6516.     (error nil))
  6517.       (cond ((and (not rawfile)        ;Not forced to read the raw file.
  6518.           ;; .newsrc.el is newer than .newsrc.
  6519.           ;; Do it this way in case timestamps are identical
  6520.           ;; (on fast machines/disks).
  6521.           (not (file-newer-than-file-p newsrc-file quick-file))
  6522.           quick-loaded
  6523.           gnus-newsrc-assoc    ;Really loaded?
  6524.           )
  6525.          ;; We don't have to read the raw startup file.
  6526.          ;; gnus-newsrc-assoc may be defined in the quick startup file.
  6527.          ;; So, we have to define the hashtable here.
  6528.          (setq gnus-newsrc-hashtb
  6529.            (gnus-make-hashtable-from-alist gnus-newsrc-assoc)))
  6530.         (t
  6531.          ;; Since .newsrc file is newer than quick file, read it.
  6532.          (message "Reading %s..." newsrc-file)
  6533.          (gnus-newsrc-to-gnus-format)
  6534.          (gnus-check-killed-newsgroups)
  6535.          (message "Reading %s... Done" newsrc-file)))
  6536.       )))
  6537.  
  6538. (defun gnus-make-newsrc-file (file)
  6539.   "Make server dependent file name by catenating FILE and server host name."
  6540.   (let* ((file (expand-file-name file nil))
  6541.      (real-file (concat file "-" gnus-nntp-server)))
  6542.     (if (file-exists-p real-file)
  6543.     real-file file)
  6544.     ))
  6545.  
  6546. (defun gnus-newsrc-to-gnus-format ()
  6547.   "Parse current buffer as .newsrc file."
  6548.   (let ((newsgroup nil)
  6549.     (subscribe nil)
  6550.     (ranges nil)
  6551.     (subrange nil)
  6552.     (read-list nil))
  6553.     ;; We have to re-initialize these variable (except for
  6554.     ;; gnus-marked-assoc and gnus-killed-assoc) because quick startup
  6555.     ;; file may contain bogus values.
  6556.     (setq gnus-newsrc-options nil)
  6557.     (setq gnus-newsrc-options-n-yes nil)
  6558.     (setq gnus-newsrc-options-n-no nil)
  6559.     (setq gnus-newsrc-assoc nil)
  6560.     ;; Make large enough hash table.
  6561.     (setq gnus-newsrc-hashtb
  6562.       (gnus-make-hashtable
  6563.        (max (length gnus-active-hashtb)
  6564.         (count-lines (point-min) (point-max)))))
  6565.     ;; Save options line to variable.
  6566.     ;; Lines beginning with white spaces are treated as continuation
  6567.     ;; line.  Refer man page of newsrc(5).
  6568.     (goto-char (point-min))
  6569.     (if (re-search-forward
  6570.      "^[ \t]*options[ \t]*\\(.*\\(\n[ \t]+.*\\)*\\)[ \t]*$" nil t)
  6571.     (progn
  6572.       ;; Save entire options line.
  6573.       (setq gnus-newsrc-options
  6574.         (buffer-substring (match-beginning 1) (match-end 1)))
  6575.       ;; Compile "-n" option.
  6576.       (if (string-match "\\(^\\|[ \t\n]\\)-n" gnus-newsrc-options)
  6577.           (let ((yes-and-no
  6578.              (gnus-parse-n-options
  6579.               (substring gnus-newsrc-options (match-end 0)))))
  6580.         (setq gnus-newsrc-options-n-yes (car yes-and-no))
  6581.         (setq gnus-newsrc-options-n-no  (cdr yes-and-no))
  6582.         ))
  6583.       ))
  6584.     ;; Parse body of .newsrc file
  6585.     ;; Options line continuation lines must be also considered here.
  6586.     ;; Before supporting continuation lines, " newsgroup ! 1-5" was
  6587.     ;; okay, but now it is invalid.  It should be "newsgroup! 1-5".
  6588.     (goto-char (point-min))
  6589.     ;; Due to overflows in regex.c, change the following regexp:
  6590.     ;; "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(.*\\)$"
  6591.     ;; Suggested by composer@bucsf.bu.edu (Jeff Kellem)
  6592.     ;; but no longer viable because of extensive backtracking in Emacs 19:
  6593.     ;; "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(\\(...\\)*.*\\)$"
  6594.     ;; but, the following causes trouble on some case:
  6595.     ;; "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(\\|[^ \t\n].*\\)$"
  6596.     (while (re-search-forward
  6597.         (if (= gnus-emacs-version 18)
  6598.         "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(\\(...\\)*.*\\)$"
  6599.           "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(.*\\)$")
  6600.         nil t)
  6601.       (setq newsgroup (buffer-substring (match-beginning 1) (match-end 1)))
  6602.       ;; Check duplications of newsgroups.
  6603.       ;; Note: Checking the duplications takes very long time.
  6604.       (if (gnus-gethash newsgroup gnus-newsrc-hashtb)
  6605.       (message "Ignore duplicated newsgroup: %s" newsgroup)
  6606.     (setq subscribe
  6607.           (string-equal
  6608.            ":" (buffer-substring (match-beginning 2) (match-end 2))))
  6609.     (setq ranges (buffer-substring (match-beginning 3) (match-end 3)))
  6610.     (setq read-list nil)
  6611.     (while (string-match "^[, \t]*\\([0-9-]+\\)" ranges)
  6612.       (setq subrange (substring ranges (match-beginning 1) (match-end 1)))
  6613.       (setq ranges (substring ranges (match-end 1)))
  6614.       (cond ((string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" subrange)
  6615.          (setq read-list
  6616.                (cons
  6617.             (cons (string-to-int
  6618.                    (substring subrange
  6619.                       (match-beginning 1) (match-end 1)))
  6620.                   (string-to-int
  6621.                    (substring subrange
  6622.                       (match-beginning 2) (match-end 2))))
  6623.             read-list)))
  6624.         ((string-match "^[0-9]+$" subrange)
  6625.          (setq read-list
  6626.                (cons (cons (string-to-int subrange)
  6627.                    (string-to-int subrange))
  6628.                  read-list)))
  6629.         (t
  6630.          (ding) (message "Ignoring bogus lines of %s" newsgroup)
  6631.          (sit-for 0))
  6632.         ))
  6633.     (setq gnus-newsrc-assoc
  6634.           (cons (cons newsgroup (cons subscribe (nreverse read-list)))
  6635.             gnus-newsrc-assoc))
  6636.     ;; Update gnus-newsrc-hashtb one by one.
  6637.     (gnus-sethash newsgroup (car gnus-newsrc-assoc) gnus-newsrc-hashtb)
  6638.     ))
  6639.     (setq gnus-newsrc-assoc (nreverse gnus-newsrc-assoc))
  6640.     ))
  6641.  
  6642. (defun gnus-parse-n-options (options)
  6643.   "Parse -n NEWSGROUPS options and return a cons of YES and NO regexps."
  6644.   (let ((yes nil)
  6645.     (no nil)
  6646.     (yes-or-no nil)            ;`!' or not.
  6647.     (newsgroup nil))
  6648.     ;; Parse each newsgroup description such as "comp.all".  Commas
  6649.     ;; and white spaces can be a newsgroup separator.
  6650.     (while
  6651.     (string-match "^[ \t\n,]*\\(!?\\)\\([^- \t\n,][^ \t\n,]*\\)" options)
  6652.       (setq yes-or-no
  6653.         (substring options (match-beginning 1) (match-end 1)))
  6654.       (setq newsgroup
  6655.         (regexp-quote
  6656.          (substring options
  6657.             (match-beginning 2) (match-end 2))))
  6658.       (setq options (substring options (match-end 2)))
  6659.       ;; Rewrite "all" to ".+" not ".*".  ".+" requires at least one
  6660.       ;; character.
  6661.       (while (string-match "\\(^\\|\\\\[.]\\)all\\(\\\\[.]\\|$\\)" newsgroup)
  6662.     (setq newsgroup
  6663.           (concat (substring newsgroup 0 (match-end 1))
  6664.               ".+"
  6665.               (substring newsgroup (match-beginning 2)))))
  6666.       ;; It is yes or no.
  6667.       (cond ((string-equal yes-or-no "!")
  6668.          (setq no (cons newsgroup no)))
  6669.         ((string-equal newsgroup ".+")) ;Ignore `all'.
  6670.         (t
  6671.          (setq yes (cons newsgroup yes))))
  6672.       )
  6673.     ;; Make a cons of regexps from parsing result.
  6674.     ;; We have to append \(\.\|$\) to prevent matching substring of
  6675.     ;; newsgroup.  For example, "jp.net" should not match with
  6676.     ;; "jp.network".
  6677.     ;; Fixes for large regexp problems are from yonezu@nak.math.keio.ac.jp.
  6678.     (cons (if yes
  6679.           (concat "^\\("
  6680.               (apply (function concat)
  6681.                  (mapcar
  6682.                   (function
  6683.                    (lambda (newsgroup)
  6684.                  (concat newsgroup "\\|")))
  6685.                   (cdr yes)))
  6686.               (car yes) "\\)\\(\\.\\|$\\)"))
  6687.       (if no
  6688.           (concat "^\\("
  6689.               (apply (function concat)
  6690.                  (mapcar
  6691.                   (function
  6692.                    (lambda (newsgroup)
  6693.                  (concat newsgroup "\\|")))
  6694.                   (cdr no)))
  6695.               (car no) "\\)\\(\\.\\|$\\)")))
  6696.     ))
  6697.  
  6698. (defun gnus-save-newsrc-file ()
  6699.   "Save to .newsrc FILE."
  6700.   ;; Note: We cannot save .newsrc file if all newsgroups are removed
  6701.   ;; from the variable gnus-newsrc-assoc.
  6702.   (and (or gnus-newsrc-assoc gnus-killed-assoc)
  6703.        gnus-current-startup-file
  6704.        (save-excursion
  6705.      ;; A buffer containing .newsrc file may be deleted.
  6706.      (set-buffer (find-file-noselect gnus-current-startup-file))
  6707.      (if (not (buffer-modified-p))
  6708.          (message "(No changes need to be saved)")
  6709.        (message "Saving %s..." gnus-current-startup-file)
  6710.        (let ((make-backup-files t)
  6711.          (version-control nil)
  6712.          (require-final-newline t)) ;Don't ask even if requested.
  6713.          ;; Make backup file of master newsrc.
  6714.          ;; You can stop or change version control of backup file.
  6715.          ;; Suggested by jason@violet.berkeley.edu.
  6716.          (run-hooks 'gnus-save-newsrc-hook)
  6717.          (save-buffer))
  6718.        ;; Quickly loadable .newsrc.
  6719.        (set-buffer (get-buffer-create " *GNUS-newsrc*"))
  6720.        (buffer-flush-undo (current-buffer))
  6721.        (erase-buffer)
  6722.        (gnus-gnus-to-quick-newsrc-format)
  6723.        (let ((make-backup-files nil)
  6724.          (version-control nil)
  6725.          (require-final-newline t)) ;Don't ask even if requested.
  6726.          (write-file (concat gnus-current-startup-file ".el")))
  6727.        (kill-buffer (current-buffer))
  6728.        (message "Saving %s... Done" gnus-current-startup-file)
  6729.        ))
  6730.     ))
  6731.  
  6732. (defun gnus-update-newsrc-buffer (group &optional delete next)
  6733.   "Incrementally update .newsrc buffer about GROUP.
  6734. If optional 1st argument DELETE is non-nil, delete the group.
  6735. If optional 2nd argument NEXT is non-nil, inserted before it."
  6736.   (save-excursion
  6737.     ;; Taking account of the killed startup file.
  6738.     ;; Suggested by tale@pawl.rpi.edu.
  6739.     (set-buffer (or (get-file-buffer gnus-current-startup-file)
  6740.             (find-file-noselect gnus-current-startup-file)))
  6741.     ;; Options line continuation lines must be also considered here.
  6742.     ;; Before supporting continuation lines, " newsgroup ! 1-5" was
  6743.     ;; okay, but now it is invalid.  It should be "newsgroup! 1-5".
  6744.     (let ((deleted nil)
  6745.       (case-fold-search nil)    ;Should NOT ignore case.
  6746.       (buffer-read-only nil))    ;May be not modifiable.
  6747.       ;; Delete ALL entries which match for GROUP.
  6748.       (goto-char (point-min))
  6749.       (while (re-search-forward
  6750.           (concat "^" (regexp-quote group) "[:!]") nil t)
  6751.     (beginning-of-line)
  6752.     (delete-region (point) (progn (forward-line 1) (point)))
  6753.     (setq deleted t)        ;Old entry is deleted.
  6754.     )
  6755.       (if delete
  6756.       nil
  6757.     ;; Insert group entry.
  6758.     (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
  6759.       (if (null newsrc)
  6760.           nil
  6761.         ;; Find insertion point.
  6762.         (cond (deleted nil)        ;Insert here.
  6763.           ((and (stringp next)
  6764.             (progn
  6765.               (goto-char (point-min))
  6766.               (re-search-forward
  6767.                (concat "^" (regexp-quote next) "[:!]") nil t)))
  6768.            (beginning-of-line))
  6769.           (t
  6770.            (goto-char (point-max))
  6771.            (or (bolp)
  6772.                (insert "\n"))))
  6773.         ;; Insert after options line.
  6774.         (if (looking-at "^[ \t]*options\\([ \t]\\|$\\)")
  6775.         (progn
  6776.           (forward-line 1)
  6777.           ;; Skip continuation lines.
  6778.           (while (and (not (eobp))
  6779.                   (looking-at "^[ \t]+"))
  6780.             (forward-line 1))))
  6781.         (insert group        ;Group name
  6782.             (if (nth 1 newsrc) ": " "! ")) ;Subscribed?
  6783.         (gnus-ranges-to-newsrc-format (nthcdr 2 newsrc)) ;Read articles
  6784.         (insert "\n")
  6785.         )))
  6786.       )))
  6787.  
  6788. (defun gnus-gnus-to-quick-newsrc-format ()
  6789.   "Insert GNUS variables such as gnus-newsrc-assoc in lisp format."
  6790.   (insert ";; GNUS internal format of .newsrc.\n")
  6791.   (insert ";; Touch .newsrc instead if you think to remove this file.\n")
  6792.   (let ((variable nil)
  6793.     (variables gnus-variable-list)
  6794.     ;; Temporary rebind to make changes
  6795.     ;; gnus-check-killed-newsgroups in invisible.
  6796.     (gnus-killed-assoc gnus-killed-assoc)
  6797.     (gnus-killed-hashtb gnus-killed-hashtb))
  6798.     ;; Remove duplicated or unsubscribed newsgroups in
  6799.     ;; gnus-killed-assoc (and gnus-killed-hashtb).
  6800.     (gnus-check-killed-newsgroups)
  6801.     ;; Then, insert lisp expressions.
  6802.     (while variables
  6803.       (setq variable (car variables))
  6804.       (and (boundp variable)
  6805.        (symbol-value variable)
  6806.        (insert "(setq " (symbol-name variable) " '"
  6807.            (prin1-to-string (symbol-value variable))
  6808.            ")\n"))
  6809.       (setq variables (cdr variables)))
  6810.     ))
  6811.  
  6812. (defun gnus-ranges-to-newsrc-format (ranges)
  6813.   "Insert ranges of read articles."
  6814.   (let ((range nil))            ;Range is a pair of BEGIN and END.
  6815.     (while ranges
  6816.       (setq range (car ranges))
  6817.       (setq ranges (cdr ranges))
  6818.       (cond ((= (car range) (cdr range))
  6819.          (if (= (car range) 0)
  6820.          (setq ranges nil)    ;No unread articles.
  6821.            (insert (int-to-string (car range)))
  6822.            (if ranges (insert ","))
  6823.            ))
  6824.         (t
  6825.          (insert (int-to-string (car range))
  6826.              "-"
  6827.              (int-to-string (cdr range)))
  6828.          (if ranges (insert ","))
  6829.          ))
  6830.       )))
  6831.  
  6832. (defun gnus-compress-sequence (numbers)
  6833.   "Convert list of sorted numbers to ranges."
  6834.   (let* ((numbers (sort (copy-sequence numbers) (function <)))
  6835.      (first (car numbers))
  6836.      (last (car numbers))
  6837.      (result nil))
  6838.     (while numbers
  6839.       (cond ((= last (car numbers)) nil) ;Omit duplicated number
  6840.         ((= (1+ last) (car numbers)) ;Still in sequence
  6841.          (setq last (car numbers)))
  6842.         (t                ;End of one sequence
  6843.          (setq result (cons (cons first last) result))
  6844.          (setq first (car numbers))
  6845.          (setq last  (car numbers)))
  6846.         )
  6847.       (setq numbers (cdr numbers))
  6848.       )
  6849.     (nreverse (cons (cons first last) result))
  6850.     ))
  6851.  
  6852. (defun gnus-uncompress-sequence (ranges)
  6853.   "Expand compressed format of sequence."
  6854.   (let ((first nil)
  6855.     (last  nil)
  6856.     (result nil))
  6857.     (while ranges
  6858.       (setq first (car (car ranges)))
  6859.       (setq last  (cdr (car ranges)))
  6860.       (while (< first last)
  6861.     (setq result (cons first result))
  6862.     (setq first (1+ first)))
  6863.       (setq result (cons first result))
  6864.       (setq ranges (cdr ranges))
  6865.       )
  6866.     (nreverse result)
  6867.     ))
  6868.  
  6869. (defun gnus-number-of-articles (range)
  6870.   "Compute number of articles from RANGE `((beg1 . end1) (beg2 . end2) ...)'."
  6871.   (let ((count 0))
  6872.     (while range
  6873.       (if (/= (cdr (car range)) 0)
  6874.       ;; If end1 is 0, it must be skipped. Usually no articles in
  6875.       ;;  this group.
  6876.       (setq count (+ count 1 (- (cdr (car range)) (car (car range))))))
  6877.       (setq range (cdr range))
  6878.       )
  6879.     count                ;Result
  6880.     ))
  6881.  
  6882. (defun gnus-difference-of-range (src obj)
  6883.   "Compute (SRC - OBJ) on range.
  6884. Range of SRC is expressed as `(beg . end)'.
  6885. Range of OBJ is expressed as `((beg1 . end1) (beg2 . end2) ...)."
  6886.   (let ((beg (car src))
  6887.     (end (cdr src))
  6888.     (range nil))            ;This is result.
  6889.     ;; Src may be nil.
  6890.     (while (and src obj)
  6891.       (let ((beg1 (car (car obj)))
  6892.         (end1 (cdr (car obj))))
  6893.     (cond ((> beg end)
  6894.            (setq obj nil))        ;Terminate loop
  6895.           ((< beg beg1)
  6896.            (setq range (cons (cons beg (min (1- beg1) end)) range))
  6897.            (setq beg (1+ end1)))
  6898.           ((>= beg beg1)
  6899.            (setq beg (max beg (1+ end1))))
  6900.           )
  6901.     (setq obj (cdr obj))        ;Next OBJ
  6902.     ))
  6903.     ;; Src may be nil.
  6904.     (if (and src (<= beg end))
  6905.     (setq range (cons (cons beg end) range)))
  6906.     ;; Result
  6907.     (if range
  6908.     (nreverse range)
  6909.       (list (cons 0 0)))
  6910.     ))
  6911.  
  6912. (defun gnus-read-distributions-file ()
  6913.   "Get distributions file from NNTP server (NNTP2 functionality)."
  6914.   ;; Make sure a connection to NNTP server is alive.
  6915.   (gnus-start-news-server)
  6916.   (message "Reading distributions file...")
  6917.   (setq gnus-distribution-list nil)
  6918.   (if (gnus-request-list-distributions)
  6919.       (save-excursion
  6920.     (set-buffer nntp-server-buffer)
  6921.     (gnus-distributions-to-gnus-format)
  6922.     (message "Reading distributions file... done"))
  6923.     ;; It's not a fatal error.
  6924.     ;;(error "Cannot read distributions file from NNTP server.")
  6925.     )
  6926.   ;; Merge with user supplied default distributions.
  6927.   (let ((defaults (reverse gnus-local-distributions))
  6928.     (dist nil))
  6929.     (while defaults
  6930.       (setq dist (assoc (car defaults) gnus-distribution-list))
  6931.       (if dist
  6932.       (setq gnus-distribution-list
  6933.         (delq dist gnus-distribution-list)))
  6934.       (setq gnus-distribution-list
  6935.         (cons (list (car defaults)) gnus-distribution-list))
  6936.       (setq defaults (cdr defaults))
  6937.       )))
  6938.  
  6939. (defun gnus-distributions-to-gnus-format ()
  6940.   "Convert distributions file format to internal format."
  6941.   (setq gnus-distribution-list nil)
  6942.   (goto-char (point-min))
  6943.   (while (re-search-forward "^\\([^ \t\n]+\\).*$" nil t)
  6944.     (setq gnus-distribution-list
  6945.       (cons (list (buffer-substring (match-beginning 1) (match-end 1)))
  6946.         gnus-distribution-list)))
  6947.   (setq gnus-distribution-list
  6948.     (nreverse gnus-distribution-list)))
  6949.  
  6950. ;; Some older version of GNU Emacs does not support function
  6951. ;; `file-newer-than-file-p'.
  6952.  
  6953. (or (fboundp 'file-newer-than-file-p)
  6954.     (defun file-newer-than-file-p (file1 file2)
  6955.       "Return t if file FILE1 is newer than file FILE2.
  6956. If FILE1 does not exist, the answer is nil;
  6957. otherwise, if FILE2 does not exist, the answer is t."
  6958.       (let ((mod1 (nth 5 (file-attributes file1)))
  6959.         (mod2 (nth 5 (file-attributes file2))))
  6960.     (cond ((not (file-exists-p file1)) nil)
  6961.           ((not (file-exists-p file2)) t)
  6962.           ((and mod2 mod1)
  6963.            (or (< (car mod2) (car mod1))
  6964.            (and (= (car mod2) (car mod1))
  6965.             (<= (nth 1 mod2) (nth 1 mod1)))))
  6966.           ))))
  6967.  
  6968.  
  6969. ;;Local variables:
  6970. ;;eval: (put 'gnus-eval-in-buffer-window 'lisp-indent-hook 1)
  6971. ;;end:
  6972.  
  6973. ;;; gnus.el ends here
  6974.