home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / rnews+.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  53.4 KB  |  1,493 lines

  1. ;From ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!uunet!cimshop!rhess Fri Apr 20 15:00:37 EDT 1990
  2. ;Article 1544 of gnu.emacs:
  3. ;Path: ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!uunet!cimshop!rhess
  4. ;From: cimshop!rhess@uunet.UU.NET (Richard L. Hess)
  5. ;Newsgroups: gnu.emacs
  6. ;Subject: Re: Improvements to rnews
  7. ;Message-ID: <CIMSHOP!RHESS.90Apr20070758@uunet.UU.NET>
  8. ;Date: 20 Apr 90 14:07:58 GMT
  9. ;References: <9004191134.AA03316@aeneas.MIT.EDU>
  10. ;Sender: rhess@cimshop.UUCP
  11. ;Distribution: gnu
  12. ;Organization: Consilium Inc., Mountain View, California.
  13. ;Lines: 1477
  14. ;In-reply-to: jpff%maths.bath.ac.uk@NSFNET-RELAY.AC.UK's message of 19 Apr 90 11:25:33 GMT
  15. ;
  16. ;
  17. ;Here's an "enhanced" version of rnews which I was working on during the early
  18. ;part of '89.  It fixes some rnews bugs and provides a summary mechanism.  Hope
  19. ;this helps.
  20. ;
  21. ;Dick...
  22. ;
  23. ;ps.    I was using this as my primary newsreader until I got hooked on gnus,
  24. ;    I haven't touched rnews since June or July of '89.   ;-)
  25.  
  26. ;;; USENET news reader for gnu emacs
  27. ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
  28. ;
  29. ; [enhanced rnews]:
  30. ;------------------------------------------------------------------------------
  31. ; WHO:   Richard Hess            CORP:    Consilium
  32. ; TITLE: Project Manager        VOICE:    [415] 691-6342
  33. ;       [ User Interface Services ]    USNAIL:    640 Clyde Court
  34. ; UUCP:  ...!uunet!cimshop!rhess        Mountain View, CA 94043
  35. ;------------------------------------------------------------------------------
  36. ;; new news-get-news-list-of-files(), an ls based mechanism...      [ 5-24-89 ]
  37. ;; enhanced news-get-pruned-list-of-files() to use the previous mechanism...
  38. ;; elimintated access to "possibly-bogus" file list mechanism...
  39. ;------------------------------------------------------------------------------
  40. ;; modified news-current-news-group, now a global variable...       [ 5-12-89 ]
  41. ;; enhanced summary-mode to support viewing news group subscription...
  42. ;; enhanced news-list-news-groups() to use summary-mode mechanism...
  43. ;------------------------------------------------------------------------------
  44. ;; enhanced summary-mode to support a "next-group" mechanism...     [ 4-21-89 ]
  45. ;------------------------------------------------------------------------------
  46. ;; new news-summary mechanism...                                    [ 2-17-89 ]
  47. ;;    [ new mode:  summary-mode ][ based on "view" ]
  48. ;; new mechanism to intelligently move over/around missing articles
  49. ;;    [ required for dealing with "possibly bogus" file list... ]
  50. ;;    [ new var:  news-motion-arg ]
  51. ;; enhanced news-list-news-groups() to use a view-buffer mechanism...
  52. ;; fixed news-current-message-number, now a local variable in group...
  53. ;; fixed bug in mode line display... [ make it show read-only ]
  54. ;; eliminated redundant news-read-in-file call...
  55. ; -----------------------------------------------------------------------------
  56. ;
  57. ;; This file is part of GNU Emacs.
  58.  
  59. ;; GNU Emacs is distributed in the hope that it will be useful,
  60. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  61. ;; accepts responsibility to anyone for the consequences of using it
  62. ;; or for whether it serves any particular purpose or works at all,
  63. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  64. ;; License for full details.
  65.  
  66. ;; Everyone is granted permission to copy, modify and redistribute
  67. ;; GNU Emacs, but only under the conditions described in the
  68. ;; GNU Emacs General Public License.   A copy of this license is
  69. ;; supposed to have been given to you along with GNU Emacs so you
  70. ;; can know your rights and responsibilities.  It should be in a
  71. ;; file named COPYING.  Among other things, the copyright notice
  72. ;; and this notice must be preserved on all copies.
  73.  
  74. ;; Created Sun Mar 10,1985 at 21:35:01 ads and sundar@hernes.ai.mit.edu
  75. ;; Should do the point pdl stuff sometime
  76. ;; finito except pdl.... Sat Mar 16,1985 at 06:43:44
  77. ;; lets keep the summary stuff out until we get it working ..
  78. ;;    sundar@hermes.ai.mit.edu Wed Apr 10,1985 at 16:32:06
  79. ;; hack slash maim. mly@prep.ai.mit.edu Thu 18 Apr, 1985 06:11:14
  80. ;; modified to correct reentrance bug, to not bother with groups that
  81. ;;   received no new traffic since last read completely, to find out
  82. ;;   what traffic a group has available much more quickly when
  83. ;;   possible, to do some completing reads for group names - should
  84. ;;   be much faster...
  85. ;;    KING@KESTREL.arpa, Thu Mar 13 09:03:28 1986
  86. ;; made news-{next,previous}-group skip groups with no new messages; and
  87. ;; added checking for unsubscribed groups to news-add-news-group
  88. ;;    tower@prep.ai.mit.edu Jul 18 1986
  89. ;; bound rmail-output to C-o; and changed header-field commands binding to
  90. ;; agree with the new C-c C-f usage in sendmail
  91. ;;     tower@prep Sep  3 1986
  92. ;; added news-rotate-buffer-body
  93. ;;    tower@prep Oct 17 1986
  94. ;; made messages more user friendly, cleanuped news-inews
  95. ;; move posting and mail code to new file rnewpost.el
  96. ;;    tower@prep Oct 29 1986
  97. ;; added caesar-region, rename news-caesar-buffer-body, hacked accordingly
  98. ;;    tower@prep Nov 21 1986
  99. ;; added (provide 'rnews)    tower@prep 22 Apr 87
  100. ; -----------------------------------------------------------------------------
  101.  
  102. (provide 'rnews)
  103. (require 'mail-utils)
  104.  
  105. (autoload 'rmail-output "rmailout"
  106.   "Append this message to Unix mail file named FILE-NAME."
  107.   t)
  108.  
  109. (autoload 'news-reply "rnewspost"
  110.   "Compose and post a reply to the current article on USENET.
  111. While composing the reply, use \\[mail-yank-original] to yank the original
  112. message into it."
  113.   t)
  114.  
  115. (autoload 'news-mail-other-window "rnewspost"
  116.   "Send mail in another window.
  117. While composing the message, use \\[mail-yank-original] to yank the
  118. original message into it."
  119.   t)
  120.  
  121. (autoload 'news-post-news "rnewspost"
  122.   "Begin editing a new USENET news article to be posted."
  123.   t)
  124.  
  125. (autoload 'news-mail-reply "rnewspost"
  126.   "Mail a reply to the author of the current article.
  127. While composing the reply, use \\[mail-yank-original] to yank the original
  128. message into it."
  129.   t)
  130.  
  131. (defvar rmail-last-file (expand-file-name "~/mbox.news"))
  132.  
  133. ;Now in paths.el.
  134. ;(defvar news-path "/usr/spool/news/"
  135. ;  "The root directory below which all news files are stored.")
  136.  
  137. (defvar news-startup-file "$HOME/.newsrc" "Contains ~/.newsrc")
  138. (defvar news-certification-file "$HOME/.news-dates" "Contains ~/.news-dates")
  139.  
  140. ;; random headers that we decide to ignore.
  141. (defvar news-ignored-headers
  142.   "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:"
  143.   "All random fields within the header of a message.")
  144.  
  145. (defvar news-mode-map nil)
  146. (defvar news-read-first-time-p t)
  147. ;; Contains the (dotified) news groups of which you are a member. 
  148. (defvar news-user-group-list nil)
  149.  
  150. (defvar news-current-news-group nil)
  151. (defvar news-current-group-begin nil)
  152. (defvar news-current-group-end  nil)
  153. (defvar news-current-certifications nil
  154.        "An assoc list of a group name and the time at which it is
  155. known that the group had no new traffic")
  156. (defvar news-current-certifiable nil
  157.     "The time when the directory we are now working on was written")
  158.  
  159. (defvar news-message-filter nil
  160.   "User specifiable filter function that will be called during
  161. formatting of the news file")
  162.  
  163. ;(defvar news-mode-group-string "Starting-Up"
  164. ;  "Mode line group name info is held in this variable")
  165. (defvar news-list-of-files nil
  166.   "Global variable in which we store the list of files
  167. associated with the current newsgroup")
  168.  
  169. (defvar news-list-of-files-possibly-bogus nil
  170.   "variable indicating we only are guessing at which files are available.
  171. Not currently used.")
  172.  
  173. ;; association list in which we store lists of the form
  174. ;; (pointified-group-name (first last old-last))
  175. (defvar news-group-article-assoc nil)
  176.  
  177. (defvar news-groups-buffer-name " *Newsgroups*"
  178.   "Global variable for the news-list-news-groups() buffer name... [ rhess ]")
  179.   
  180. ;;(defvar news-current-message-number 0 "Displayed Article Number")
  181. (defvar news-total-current-group 0 "Total no of messages in group")
  182.  
  183. (defvar news-unsubscribe-groups ())
  184. (defvar news-point-pdl () "List of visited news messages.")
  185. (defvar news-no-jumps-p t)
  186. (defvar news-buffer () "Buffer into which news files are read.")
  187.  
  188. (defvar news-motion-arg 0
  189.   "Current arg for next/previous message motion... [ rhess ]")
  190.  
  191. (defmacro news-push (item ref)
  192.   (list 'setq ref (list 'cons item ref)))
  193.  
  194. (defmacro news-cadr (x) (list 'car (list 'cdr x)))
  195. (defmacro news-cdar (x) (list 'cdr (list 'car x)))
  196. (defmacro news-caddr (x) (list 'car (list 'cdr (list 'cdr x))))
  197. (defmacro news-cadar (x) (list 'car (list 'cdr (list 'car x))))
  198. (defmacro news-caadr (x) (list 'car (list 'car (list 'cdr x))))
  199. (defmacro news-cdadr (x) (list 'cdr (list 'car (list 'cdr x))))
  200.  
  201. (defmacro news-wins (pfx index)
  202.   (` (file-exists-p (concat (, pfx) "/" (int-to-string (, index))))))
  203.  
  204. (defvar news-max-plausible-gap 2
  205.     "* In an rnews directory, the maximum possible gap size.
  206. A gap is a sequence of missing messages between two messages that exist.
  207. An empty file does not contribute to a gap -- it ends one.")
  208.  
  209. ;(defun news-find-first-and-last (prefix base)
  210. ;  (and (news-wins prefix base)
  211. ;       (cons (news-find-first-or-last prefix base -1)
  212. ;         (news-find-first-or-last prefix base 1))))
  213.  
  214. (defmacro news-/ (a1 a2)
  215.   ;; a form of / that guarantees that (/ -1 2) = 0
  216.   (if (zerop (/ -1 2))
  217.       (` (/ (, a1) (, a2)))
  218.     (` (if (< (, a1) 0)
  219.        (- (/ (- (, a1)) (, a2)))
  220.      (/ (, a1) (, a2))))))
  221.  
  222. ;(defun news-find-first-or-last (pfx base dirn)
  223. ;  ;; first use powers of two to find a plausible ceiling
  224. ;  (let ((original-dir dirn))
  225. ;    (while (news-wins pfx (+ base dirn))
  226. ;      (setq dirn (* dirn 2)))
  227. ;    (setq dirn (news-/ dirn 2))
  228. ;    ;; Then use a binary search to find the high water mark
  229. ;    (let ((offset (news-/ dirn 2)))
  230. ;      (while (/= offset 0)
  231. ;    (if (news-wins pfx (+ base dirn offset))
  232. ;        (setq dirn (+ dirn offset)))
  233. ;    (setq offset (news-/ offset 2))))
  234. ;    ;; If this high-water mark is bogus, recurse.
  235. ;    (let ((offset (* news-max-plausible-gap original-dir)))
  236. ;      (while (and (/= offset 0) (not (news-wins pfx (+ base dirn offset))))
  237. ;    (setq offset (- offset original-dir)))
  238. ;      (if (= offset 0)
  239. ;      (+ base dirn)
  240. ;    (news-find-first-or-last pfx (+ base dirn offset) original-dir)))))
  241.  
  242. (defun rnews ()
  243. "Read USENET news for groups for which you are a member and add or
  244. delete groups.
  245. You can reply to articles posted and send articles to any group.
  246.  
  247. Type \\[describe-mode] once reading news to get a list of rnews commands."
  248.   (interactive)
  249.   (let ((last-buffer (buffer-name)))
  250.     (make-local-variable 'rmail-last-file)
  251.     (switch-to-buffer (setq news-buffer (get-buffer-create "*news*")))
  252.     (news-mode)
  253.     (setq news-buffer-save last-buffer)
  254.     (setq buffer-read-only nil)
  255.     (erase-buffer)
  256.     (setq buffer-read-only t)
  257.     (set-buffer-modified-p t)
  258.     (sit-for 0)
  259.     (message "Getting new USENET news...")
  260.     (news-set-mode-line)
  261.     (news-get-certifications)
  262.     (news-get-new-news)))
  263.  
  264. (defun news-group-certification (group)
  265.   (cdr-safe (assoc group news-current-certifications)))
  266.  
  267.  
  268. (defun news-set-current-certifiable ()
  269.   ;; Record the date that corresponds to the directory you are about to check
  270.   (let ((file (concat news-path
  271.               (string-subst-char ?/ ?. news-current-news-group))))
  272.     (setq news-current-certifiable
  273.       (nth 5 (file-attributes
  274.           (or (file-symlink-p file) file))))))
  275.  
  276. (defun news-get-certifications ()
  277.   ;; Read the certified-read file from last session
  278.   (save-excursion
  279.     (save-window-excursion
  280.       (setq news-current-certifications
  281.         (car-safe
  282.          (condition-case var
  283.          (let*
  284.              ((file (substitute-in-file-name news-certification-file))
  285.               (buf (find-file-noselect file)))
  286.            (and (file-exists-p file)
  287.             (progn
  288.               (switch-to-buffer buf 'norecord)
  289.               (unwind-protect
  290.                   (read-from-string (buffer-string))
  291.                 (kill-buffer buf)))))
  292.            (error nil)))))))
  293.  
  294. (defun news-write-certifications ()
  295.   ;; Write a certification file.
  296.   ;; This is an assoc list of group names with doubletons that represent
  297.   ;; mod times of the directory when group is read completely.
  298.   (save-excursion
  299.     (save-window-excursion
  300.       (with-output-to-temp-buffer
  301.       "*CeRtIfIcAtIoNs*"
  302.       (print news-current-certifications))
  303.       (let ((buf (get-buffer "*CeRtIfIcAtIoNs*")))
  304.     (switch-to-buffer buf)
  305.     (write-file (substitute-in-file-name news-certification-file))
  306.     (kill-buffer buf)))))
  307.  
  308. (defun news-set-current-group-certification ()
  309.   (let ((cgc (assoc news-current-news-group news-current-certifications)))
  310.     (if cgc (setcdr cgc news-current-certifiable)
  311.       (news-push (cons news-current-news-group news-current-certifiable)
  312.          news-current-certifications))))
  313.  
  314. (defun news-set-minor-modes ()
  315.   "Creates a minor mode list that has group name, total articles,
  316. and attribute for current article."
  317.   (setq news-minor-modes (list (cons 'foo
  318.                      (concat news-current-message-number
  319.                          "/"
  320.                          news-total-current-group
  321.                          (news-get-attribute-string)))))
  322.   ;; Detect Emacs versions 18.16 and up, which display
  323.   ;; directly from news-minor-modes by using a list for mode-name.
  324.   (or (boundp 'minor-mode-alist)
  325.       (setq minor-modes news-minor-modes)))
  326.  
  327. (defun news-set-message-counters ()
  328.   "Scan through current news-groups filelist to figure out how many messages
  329. are there. Set counters for use with minor mode display."
  330.     (if (null news-list-of-files)
  331.     (setq news-current-message-number 0)))
  332.  
  333. (if news-mode-map
  334.     nil
  335.   (setq news-mode-map (make-keymap))
  336.   (suppress-keymap news-mode-map)
  337.   (define-key news-mode-map "." 'beginning-of-buffer)
  338.   (define-key news-mode-map " " 'scroll-up)
  339.   (define-key news-mode-map "\177" 'scroll-down)
  340.   (define-key news-mode-map "n" 'news-next-message)
  341.   (define-key news-mode-map "c" 'news-make-link-to-message)
  342.   (define-key news-mode-map "p" 'news-previous-message)
  343.   (define-key news-mode-map "j" 'news-goto-message)
  344.   (define-key news-mode-map "q" 'news-exit)
  345.   (define-key news-mode-map "e" 'news-exit)
  346.   (define-key news-mode-map "\ej" 'news-goto-news-group)
  347.   (define-key news-mode-map "\en" 'news-next-group)
  348.   (define-key news-mode-map "\ep" 'news-previous-group)
  349.   (define-key news-mode-map "l" 'news-list-news-groups)
  350.   (define-key news-mode-map "?" 'describe-mode)
  351.   (define-key news-mode-map "g" 'news-get-new-news)
  352.   (define-key news-mode-map "f" 'news-reply)
  353.   (define-key news-mode-map "m" 'news-mail-other-window)
  354.   (define-key news-mode-map "a" 'news-post-news)
  355.   (define-key news-mode-map "r" 'news-mail-reply)
  356.   (define-key news-mode-map "o" 'news-save-item-in-file)
  357.   (define-key news-mode-map "\C-o" 'rmail-output)
  358.   (define-key news-mode-map "s" 'news-view-summary)            ; [rhess]
  359.   (define-key news-mode-map "S" 'news-summary)                 ; [rhess]
  360.   (define-key news-mode-map "T" 'news-summary-all)             ; [rhess]
  361.   (define-key news-mode-map "t" 'news-show-all-headers)
  362.   (define-key news-mode-map "x" 'news-force-update)
  363.   (define-key news-mode-map "A" 'news-add-news-group)
  364.   (define-key news-mode-map "u" 'news-unsubscribe-current-group)
  365.   (define-key news-mode-map "U" 'news-unsubscribe-group)
  366.   (define-key news-mode-map "\C-c\C-r" 'news-caesar-buffer-body))
  367.  
  368. (defun news-mode ()
  369.   "News Mode is used by M-x rnews for reading USENET Newsgroups articles.
  370. New readers can find additional help in newsgroup: news.announce.newusers .
  371. All normal editing commands are turned off.
  372. Instead, these commands are available:
  373.  
  374. .    move point to front of this news article (same as Meta-<).
  375. Space    scroll to next screen of this news article.
  376. Delete  scroll down previous page of this news article.
  377. n    move to next news article, possibly next group.
  378. p    move to previous news article, possibly previous group.
  379. j    jump to news article specified by numeric position.
  380. M-j     jump to news group.
  381. M-n     goto next news group.
  382. M-p     goto previous news group.
  383. l       list all the news groups with current status.
  384. ?       print this help message.
  385. C-c C-r caesar rotate all letters by 13 places in the article's body (rot13).
  386. g       get new USENET news.
  387. f       post a reply article to USENET.
  388. a       post an original news article.
  389. A       add a newsgroup. 
  390. o    save the current article in the named file (append if file exists).
  391. C-o    output this message to a Unix-format mail file (append it).
  392. c       \"copy\" (actually link) current or prefix-arg msg to file.
  393.     warning: target directory and message file must be on same device
  394.         (UNIX magic)
  395. q    quit reading news after updating .newsrc file.
  396. e    exit updating .newsrc file.
  397. m    mail a news article.  Same as C-x 4 m.
  398. x       update last message seen to be the current message.
  399. r    mail a reply to this news article.  Like m but initializes some fields.
  400. s       view summary info for current newsgroup... [rhess]
  401. S       create summary info on new messages in current newsgroup... [rhess]
  402. T       create summary info on all messages in current newsgroup... [rhess]
  403. t       show all the headers this news article originally had.
  404. u       unsubscribe from current newsgroup.
  405. U       unsubscribe from specified newsgroup."
  406.   (interactive)
  407.   (kill-all-local-variables)
  408.   (make-local-variable 'news-read-first-time-p)
  409.   (setq news-read-first-time-p t)
  410. ;  (make-local-variable 'news-current-news-group)
  411. ;  (setq news-current-news-group "??")
  412.   (make-local-variable 'news-current-group-begin)
  413.   (setq news-current-group-begin 0)
  414.   (make-local-variable 'news-current-message-number)
  415.   (setq news-current-message-number 0)
  416.   (make-local-variable 'news-total-current-group)
  417.   (make-local-variable 'news-buffer-save)
  418.   (make-local-variable 'version-control)
  419.   (setq version-control 'never)
  420.   (make-local-variable 'news-point-pdl)
  421. ;  This breaks it.  I don't have time to figure out why. -- RMS
  422. ;  (make-local-variable 'news-group-article-assoc)
  423.   (setq major-mode 'news-mode)
  424.   (if (boundp 'minor-mode-alist)
  425.       ;; Emacs versions 18.16 and up.
  426.       (setq mode-name '("NEWS" news-minor-modes))
  427.     ;; Earlier versions display minor-modes via a special mechanism.
  428.     (setq mode-name "NEWS"))
  429.   (news-set-mode-line)
  430.   (set-syntax-table text-mode-syntax-table)
  431.   (use-local-map news-mode-map)
  432.   (setq local-abbrev-table text-mode-abbrev-table)
  433.   (run-hooks 'news-mode-hook))
  434.  
  435. (defun string-subst-char (new old string)
  436.   (let (index)
  437.     (setq old (regexp-quote (char-to-string old))
  438.       string (substring string 0))
  439.     (while (setq index (string-match old string))
  440.       (aset string index new)))
  441.   string)
  442.  
  443. ;; update read message number
  444. (defmacro news-update-message-read (ngroup nno)
  445.   (list 'setcar
  446.     (list 'news-cdadr
  447.           (list 'assoc ngroup 'news-group-article-assoc))
  448.     nno))
  449.  
  450. (defun news-parse-range (number-string)
  451.   "Parse string representing range of numbers of he form <a>-<b>
  452. to a list (a . b)"
  453.   (let ((n (string-match "-" number-string)))
  454.     (if n
  455.     (cons (string-to-int (substring number-string 0 n))
  456.           (string-to-int (substring number-string (1+ n))))
  457.       (setq n (string-to-int number-string))
  458.       (cons n n))))
  459.  
  460. ;(defun is-in (elt lis)
  461. ;  (catch 'foo
  462. ;    (while lis
  463. ;      (if (equal (car lis) elt)
  464. ;      (throw 'foo t)
  465. ;    (setq lis (cdr lis))))))
  466.  
  467. (defun news-get-new-news ()
  468.   "Get new USENET news, if there is any for the current user."
  469.   (interactive)
  470.   (if (not (null news-user-group-list))
  471.       (news-update-newsrc-file))
  472.   (setq news-group-article-assoc ())
  473.   (setq news-user-group-list ())
  474.   (message "Looking up %s file..." news-startup-file)
  475.   (let ((file (substitute-in-file-name news-startup-file))
  476.     (temp-user-groups ()))
  477.     (save-excursion
  478.       (let ((newsrcbuf (find-file-noselect file))
  479.         start end endofline tem)
  480.     (set-buffer newsrcbuf)
  481.     (goto-char 0)
  482.     (while (search-forward ": " nil t)
  483.       (setq end (point))
  484.       (beginning-of-line)
  485.       (setq start (point))
  486.       (end-of-line)
  487.       (setq endofline (point))
  488.       (setq tem (buffer-substring start (- end 2)))
  489.       (let ((range (news-parse-range
  490.             (buffer-substring end endofline))))
  491.         (if (assoc tem news-group-article-assoc)
  492.         (message "You are subscribed twice to %s; I ignore second"
  493.              tem)          
  494.           (setq temp-user-groups (cons tem temp-user-groups)
  495.             news-group-article-assoc
  496.             (cons (list tem (list (car range)
  497.                       (cdr range)
  498.                       (cdr range)))
  499.               news-group-article-assoc)))))
  500.     (kill-buffer newsrcbuf)))      
  501.     (setq temp-user-groups (nreverse temp-user-groups))
  502.     (message "Prefrobnicating...")
  503.     (switch-to-buffer news-buffer)
  504.     (setq news-user-group-list temp-user-groups)
  505.     (while (and temp-user-groups
  506.         (not (news-read-files-into-buffer
  507.               (car temp-user-groups) nil)))
  508.       (setq temp-user-groups (cdr temp-user-groups)))
  509.     (if (null temp-user-groups)
  510.     (message "No news is good news.")
  511.       (message ""))))
  512.  
  513. (defun news-list-news-groups ()
  514.   "[ NEW ]:  Display all the news groups to which you belong... [ rhess ]"
  515.   (interactive)
  516.   (let ((buff-ptr (current-buffer)))
  517.     (delete-other-windows)
  518.     (if (not (get-buffer news-groups-buffer-name))
  519.     (create-file-buffer news-groups-buffer-name))
  520.     (set-buffer news-groups-buffer-name)
  521.     (if buffer-read-only
  522.     (switch-to-buffer (current-buffer))
  523.       (erase-buffer)
  524.       (let ((temp news-user-group-list))
  525.     (while temp
  526.       (let ((item (assoc (car temp) news-group-article-assoc)))
  527.         (insert (car item))
  528.         (indent-to 33)
  529.         (insert (int-to-string (news-cadr (news-cadr item))))
  530.         (insert "\n")
  531.         (setq temp (cdr temp)))))
  532.       (goto-char 1)
  533.       (set-buffer-modified-p nil)
  534.       ; (view-buffer news-groups-buffer-name)
  535.       (summary-mode news-groups-buffer-name)
  536.       (switch-to-buffer buff-ptr))
  537.     ))
  538.  
  539. ;; Mode line hack
  540. (defun news-set-mode-line ()
  541.   "Set mode line string to something useful... [ rhess ]"
  542.   (let ((buffer-read-only t))
  543.     (setq mode-line-process
  544.       (concat " "
  545.           (if (integerp news-current-message-number)
  546.               (int-to-string news-current-message-number)
  547.             "??")
  548.           "/"
  549.           (if (integerp news-current-group-end)
  550.               (int-to-string news-current-group-end)
  551.             news-current-group-end)))
  552.     (setq mode-line-buffer-identification
  553.       (concat "NEWS: "
  554.           news-current-news-group
  555.           ;; Enough spaces to pad group name to 17 positions.
  556.           (substring "                 "
  557.                  0
  558.                  (max 0 (- 17 (length news-current-news-group))))))
  559.     (set-buffer-modified-p t)
  560.     (sit-for 0)))
  561.  
  562. (defun news-goto-news-group (gp)
  563.   "Takes a string and goes to that news group."
  564.   (interactive (list (completing-read "NewsGroup: "
  565.                       news-group-article-assoc)))
  566.   (message "Jumping to news group %s..." gp)
  567.   (news-select-news-group gp)
  568.   (message "Jumping to news group %s... done." gp)
  569.   )
  570.  
  571. (defun news-select-news-group (gp)
  572.   (let ((grp (assoc gp news-group-article-assoc)))
  573.     (if (null grp)
  574.      (error "Group not subscribed to in file %s." news-startup-file)
  575.       (progn
  576.     (news-update-message-read news-current-news-group
  577.                   (news-cdar news-point-pdl))
  578.     (news-read-files-into-buffer  (car grp) nil)
  579.     ))))
  580.  
  581. (defun news-goto-message (arg)
  582.   "Goes to the article ARG in current newsgroup."
  583.   (interactive "p")
  584.   (setq news-motion-arg 0)
  585.   (if (null current-prefix-arg)
  586.       (setq arg (read-no-blanks-input "Go to article: " "")))
  587.   (news-select-message arg))
  588.  
  589. (defun news-select-message (arg)
  590.   (if (stringp arg) (setq arg (string-to-int arg)))
  591.   (let ((file (concat news-path
  592.               (string-subst-char ?/ ?. news-current-news-group)
  593.               "/" arg)))
  594.     (if (file-exists-p file)
  595.     (let ((buffer-read-only nil))
  596.       (if (= arg 
  597.          (or (news-cadr (memq (news-cdar news-point-pdl)
  598.                       news-list-of-files))
  599.              0))
  600.           (setcdr (car news-point-pdl) arg))
  601.       (setq news-current-message-number arg)
  602.       (news-read-in-file file)
  603.       (news-set-mode-line))
  604.       (if (or (= news-motion-arg 1)
  605.           (= news-motion-arg -1))
  606.       (news-select-message (+ news-motion-arg arg))
  607.     (error "Article %d nonexistent" arg))
  608.       )))
  609.  
  610. (defun news-force-update ()
  611.   "updates the position of last article read in the current news group"
  612.   (interactive)
  613.   (setcdr (car news-point-pdl) news-current-message-number)
  614.   (message "Updated to %d" news-current-message-number))
  615.  
  616. (defun news-next-message (arg)
  617.   "Move ARG messages forward within one newsgroup... [ rhess ]
  618. Negative ARG moves backward.
  619. If ARG is 1 or -1, moves to next or previous newsgroup if at end."
  620.   (interactive "p")
  621.   (let ((no (+ arg news-current-message-number)))
  622.     (if (or (< no news-current-group-begin) 
  623.         (> no news-current-group-end))
  624.     (cond ((= arg 1)
  625.            (if (< no news-current-group-begin)
  626.            (news-select-message news-current-group-begin)
  627.          (news-set-current-group-certification)
  628.          (news-next-group)))
  629.           ((= arg -1)
  630.            (news-previous-group))
  631.           (t (error "Article out of range")))
  632.       (let ((plist (news-get-motion-lists
  633.              news-current-message-number
  634.              news-list-of-files)))
  635.     (setq news-motion-arg arg)
  636.     (if plist
  637.         (if (< arg 0)
  638.         (news-select-message (nth (1- (- arg)) (car (cdr plist))))
  639.           (news-select-message (nth (1- arg) (car plist))))
  640.       (message "[ %s ]:  current article not in active sequence..."
  641.            news-current-message-number))
  642.     ))))
  643.  
  644. (defun news-previous-message (arg)
  645.   "Move ARG messages backward in current newsgroup.
  646. With no arg or arg of 1, move one message
  647. and move to previous newsgroup if at beginning.
  648. A negative ARG means move forward."
  649.   (interactive "p")
  650.   (news-next-message (- arg)))
  651.  
  652. (defun news-move-to-group (arg)
  653.   "Given arg move forward or backward to a new newsgroup."
  654.   (let ((cg news-current-news-group))
  655.     (let ((plist (news-get-motion-lists cg news-user-group-list))
  656.       ngrp)
  657.       (if (< arg 0)
  658.       (or (setq ngrp (nth (1- (- arg)) (news-cadr plist)))
  659.           (error "No previous news groups"))
  660.     (or (setq ngrp (nth arg (car plist)))
  661.         (error "No more news groups")))
  662.       (news-select-news-group ngrp))))
  663.  
  664. (defun news-next-group ()
  665.   "Moves to the next user group."
  666.   (interactive)
  667. ;  (message "Moving to next group...")
  668.   (news-move-to-group 0)
  669.   (while (null news-list-of-files)
  670.     (news-move-to-group 0)))
  671. ;  (message "Moving to next group... done.")
  672.  
  673. (defun news-previous-group ()
  674.   "Moves to the previous user group."
  675.   (interactive)
  676. ;  (message "Moving to previous group...")
  677.   (news-move-to-group -1)
  678.   (while (null news-list-of-files)
  679.     (news-move-to-group -1)))
  680. ;  (message "Moving to previous group... done.")
  681.  
  682. (defun news-get-motion-lists (arg listy)
  683.   "Given a msgnumber/group this will return a list of two lists;
  684. one for moving forward and one for moving backward."
  685.   (let ((temp listy)
  686.     (result ()))
  687.     (catch 'out
  688.       (while temp
  689.     (if (equal (car temp) arg)
  690.         (throw 'out (cons (cdr temp) (list result)))
  691.       (setq result (nconc (list (car temp)) result))
  692.       (setq temp (cdr temp)))))))
  693.  
  694. ;; miscellaneous io routines
  695. (defun news-read-in-file (filename)
  696.   (erase-buffer)
  697.   (let ((start (point)))
  698.   (insert-file-contents filename)
  699.   (news-convert-format)
  700.   (goto-char start)
  701.   (forward-line 1)
  702.   (if (eobp)
  703.       (message "(Empty file?)")
  704.     (goto-char start))))
  705.  
  706. (defun news-convert-format ()
  707.   (save-excursion
  708.     (save-restriction
  709.       (let* ((start (point))
  710.          (end (condition-case ()
  711.               (progn (search-forward "\n\n") (point))
  712.             (error nil)))
  713.          has-from has-date)
  714.        (cond (end
  715.           (narrow-to-region start end)
  716.           (goto-char start)
  717.           (setq has-from (search-forward "\nFrom:" nil t))
  718.           (cond ((and (not has-from) has-date)
  719.              (goto-char start)
  720.              (search-forward "\nDate:")
  721.              (beginning-of-line)
  722.              (kill-line) (kill-line)))
  723.           (news-delete-headers start)
  724.           (goto-char start)))))))
  725.  
  726. (defun news-show-all-headers ()
  727.   "Redisplay current news item with all original headers"
  728.   (interactive)
  729.   (let (news-ignored-headers
  730.     (buffer-read-only nil))
  731.     (erase-buffer)
  732.     (news-set-mode-line)
  733.     (news-read-in-file
  734.      (concat news-path
  735.          (string-subst-char ?/ ?. news-current-news-group)
  736.          "/" (int-to-string news-current-message-number)))))
  737.  
  738. (defun news-delete-headers (pos)
  739.   (goto-char pos)
  740.   (and (stringp news-ignored-headers)
  741.        (while (re-search-forward news-ignored-headers nil t)
  742.      (beginning-of-line)
  743.      (delete-region (point)
  744.             (progn (re-search-forward "\n[^ \t]")
  745.                    (forward-char -1)
  746.                    (point))))))
  747.  
  748. (defun news-exit ()
  749.   "Quit news reading session and update the .newsrc file... [ rhess ]"
  750.   (interactive)
  751.   (progn (message "Updating %s..." news-startup-file)
  752.      (news-update-newsrc-file)
  753.      (news-write-certifications)
  754.      (message "Updating %s... done" news-startup-file)
  755.          ; (message "Now do some real work")
  756.      (and (fboundp 'bury-buffer) (bury-buffer (current-buffer)))
  757.      (switch-to-buffer news-buffer-save)
  758.      (setq news-user-group-list ()))
  759.   )
  760.  
  761. (defun news-update-newsrc-file ()
  762.   "Updates the .newsrc file in the users home dir."
  763.   (let ((newsrcbuf (find-file-noselect
  764.              (substitute-in-file-name news-startup-file)))
  765.     (tem news-user-group-list)
  766.     group)
  767.     (save-excursion
  768.       (if (not (null news-current-news-group))
  769.       (news-update-message-read news-current-news-group
  770.                 (news-cdar news-point-pdl)))
  771.       (switch-to-buffer newsrcbuf)
  772.       (while tem
  773.     (setq group (assoc (car tem)
  774.                news-group-article-assoc))
  775.     (if (= (news-cadr (news-cadr group)) (news-caddr (news-cadr group)))
  776.         nil
  777.       (goto-char 0)
  778.       (if (search-forward (concat (car group) ": ") nil t)
  779.           (kill-line nil)
  780.         (insert (car group) ": \n") (backward-char 1))
  781.       (insert (int-to-string (car (news-cadr group))) "-"
  782.           (int-to-string (news-cadr (news-cadr group)))))
  783.     (setq tem (cdr tem)))
  784.      (while news-unsubscribe-groups
  785.        (setq group (assoc (car news-unsubscribe-groups)
  786.               news-group-article-assoc))
  787.        (goto-char 0)
  788.        (if (search-forward (concat (car group) ": ") nil t)
  789.        (progn
  790.           (backward-char 2)
  791.           (kill-line nil)
  792.           (insert "! " (int-to-string (car (news-cadr group)))
  793.               "-" (int-to-string (news-cadr (news-cadr group))))))
  794.        (setq news-unsubscribe-groups (cdr news-unsubscribe-groups)))
  795.      (save-buffer)
  796.      (kill-buffer (current-buffer)))))
  797.  
  798.  
  799. (defun news-unsubscribe-group (group)
  800.   "Removes you from newgroup GROUP."
  801.   (interactive (list (completing-read  "Unsubscribe from group: "
  802.                       news-group-article-assoc)))
  803.   (news-unsubscribe-internal group))
  804.  
  805. (defun news-unsubscribe-current-group ()
  806.   "Removes you from the newsgroup you are now reading."
  807.   (interactive)
  808.   (if (y-or-n-p "Do you really want to unsubscribe from this group ? ")
  809.       (news-unsubscribe-internal news-current-news-group)))
  810.  
  811. (defun news-unsubscribe-internal (group)
  812.   (let ((tem (assoc group news-group-article-assoc)))
  813.     (if tem
  814.     (progn
  815.       (setq news-unsubscribe-groups (cons group news-unsubscribe-groups))
  816.       (news-update-message-read group (news-cdar news-point-pdl))
  817.       (if (equal group news-current-news-group)
  818.           (news-next-group))
  819.       (message ""))
  820.       (error "Not subscribed to group: %s" group))))
  821.  
  822. (defun news-save-item-in-file (file)
  823.   "Save the current article that is being read by appending to a file."
  824.   (interactive "FSave item in file: ")
  825.   (append-to-file (point-min) (point-max) file))
  826.  
  827. (defun news-get-news-list-of-files (group init-article)
  828.   "[ CORE ]:  creates a list of news articles in a news group... [ rhess ]"
  829.   (let* ((rbuf (current-buffer))
  830.          (wbuf-name "*Scratch-News-Buffer*")
  831.          (wbuf (or (get-buffer wbuf-name)
  832.                    (generate-new-buffer wbuf-name)))
  833.          (articles nil)
  834.          (thisone nil)
  835.      this-message
  836.      (pop-up-windows nil)
  837.          (news-current-path (concat news-path
  838.              (string-subst-char ?/ ?. 
  839.               (if (and group (stringp group))
  840.                   group
  841.                   "public")))))
  842.     (progn
  843.       (setq news-list-of-files nil)
  844.       (message "Prefrobnicating...")
  845.       (call-process "ls" nil wbuf nil "-t -r -F" news-current-path)
  846.       (switch-to-buffer wbuf)
  847.       (goto-char (point-max))
  848.       (while (search-backward "\n" nil t)
  849.     (beginning-of-line)
  850.     (setq this-message
  851.           (buffer-substring (point) (progn (end-of-line) (point))))
  852.     (beginning-of-line)
  853.     ;; dont get confused by directories that look like numbers
  854.     (if (string-match "^[0-9]*$" this-message)
  855.         (news-push (string-to-int this-message) articles)))
  856.       (setq articles (sort articles '<))
  857.       (while (not (null articles))
  858.     (progn
  859.       (setq thisone (car articles))
  860.       (setq articles (cdr articles))
  861.       (if (> thisone init-article)
  862.           (news-push thisone news-list-of-files))))
  863.       (setq news-list-of-files (reverse news-list-of-files))
  864.       (kill-buffer wbuf)
  865.       (switch-to-buffer rbuf)
  866.       ))
  867.   )
  868.  
  869. (defun news-get-pruned-list-of-files (gp-list end-file-no)
  870.   "[ NEW ]: Given a news group it finds all files in the news group.
  871. The arg must be in slashified format... [ rhess ]"
  872.   (let
  873.       ((answer
  874.     (and
  875.      (not (and end-file-no
  876.            (equal (news-set-current-certifiable)
  877.              (news-group-certification gp-list))
  878.            (setq news-list-of-files nil
  879.              news-list-of-files-possibly-bogus t)))
  880.      (let* ((file-directory (concat news-path
  881.                     (string-subst-char ?/ ?. gp-list)))
  882.         tem
  883.         last-winner)
  884.        (setq news-list-of-files-possibly-bogus t news-list-of-files nil)
  885.        (news-get-news-list-of-files gp-list end-file-no)
  886.        (if news-list-of-files
  887.            (progn
  888.          (setq news-list-of-files-possibly-bogus nil)
  889.          (setq news-current-group-end
  890.                (nth (1- (length news-list-of-files))
  891.                 news-list-of-files))
  892.          news-list-of-files)
  893.          (if (null news-list-of-files)
  894.          (progn (setq news-current-group-end 0)
  895.             nil)
  896.            news-list-of-files))))))
  897.     (or answer (progn (news-set-current-group-certification) nil))))
  898.  
  899. (defun news-read-files-into-buffer (group reversep)
  900.   (let* ((files-start-end (news-cadr (assoc group news-group-article-assoc)))
  901.      (start-file-no (car files-start-end))
  902.      (end-file-no (news-cadr files-start-end))
  903.      (buffer-read-only nil))
  904.     (setq news-current-news-group group)
  905.     (setq news-current-message-number nil)
  906.     (setq news-current-group-end nil)
  907.     (news-set-mode-line)
  908.     (news-get-pruned-list-of-files group end-file-no)
  909.     (news-set-mode-line)
  910.     ;; @@ should be a lot smarter than this if we have to move
  911.     ;; @@ around correctly.
  912.     (setq news-point-pdl (list (cons (car files-start-end)
  913.                      (news-cadr files-start-end))))
  914.     (if (null news-list-of-files)
  915.     (progn (erase-buffer)
  916.            (setq news-current-group-end end-file-no)
  917.            (setq news-current-group-begin end-file-no)
  918.            (setq news-current-message-number end-file-no)
  919.            (news-set-mode-line)
  920. ;           (message "No new articles in " group " group.")
  921.            nil)
  922.       (setq news-current-group-begin (car news-list-of-files))
  923.       (if reversep
  924.       (setq news-current-message-number news-current-group-end)
  925.     (if (> (car news-list-of-files) end-file-no)
  926.         (setcdr (car news-point-pdl) (car news-list-of-files)))
  927.     (setq news-current-message-number news-current-group-begin))
  928.       (news-set-message-counters)
  929.       (news-set-mode-line)
  930.       (setq news-motion-arg 1)
  931.       (news-select-message news-current-message-number)
  932. ;      (news-read-in-file (concat news-path
  933. ;                 (string-subst-char ?/ ?. group)
  934. ;                 "/"
  935. ;                 (int-to-string
  936. ;                   news-current-message-number)))
  937.       (news-set-message-counters)
  938.       (news-set-mode-line)
  939.       t)))
  940.  
  941. (defun news-add-news-group (gp)
  942.   "Resubscribe to or add a USENET news group named GROUP (a string)."
  943. ; @@ (completing-read ...)
  944. ; @@ could be based on news library file ../active (slightly facist)
  945. ; @@ or (expensive to compute) all directories under the news spool directory
  946.   (interactive "sAdd news group: ")
  947.   (let ((file-dir (concat news-path (string-subst-char ?/ ?. gp))))
  948.     (save-excursion
  949.       (if (null (assoc gp news-group-article-assoc))
  950.       (let ((newsrcbuf (find-file-noselect
  951.                 (substitute-in-file-name news-startup-file))))
  952.         (if (file-directory-p file-dir)
  953.         (progn
  954.           (switch-to-buffer newsrcbuf)
  955.           (goto-char 0)
  956.           (if (search-forward (concat gp "! ") nil t)
  957.               (progn
  958.             (message "Re-subscribing to group %s." gp)
  959.             ;;@@ news-unsubscribe-groups isn't being used
  960.             ;;(setq news-unsubscribe-groups
  961.             ;;    (delq gp news-unsubscribe-groups))
  962.             (backward-char 2)
  963.             (delete-char 1)
  964.             (insert ":"))
  965.             (progn
  966.               (message
  967.                "Added %s to your list of newsgroups." gp)
  968.               (end-of-buffer)
  969.               (insert gp ": 1-1\n")))
  970.           (search-backward gp nil t)
  971.           (let (start end endofline tem)
  972.             (search-forward ": " nil t)
  973.             (setq end (point))
  974.             (beginning-of-line)
  975.             (setq start (point))
  976.             (end-of-line)
  977.             (setq endofline (point))
  978.             (setq tem (buffer-substring start (- end 2)))
  979.             (let ((range (news-parse-range
  980.                   (buffer-substring end endofline))))
  981.               (setq news-group-article-assoc
  982.                 (cons (list tem (list (car range)
  983.                           (cdr range)
  984.                           (cdr range)))
  985.                   news-group-article-assoc))))
  986.           (save-buffer)
  987.           (kill-buffer (current-buffer)))
  988.           (message "Newsgroup %s doesn't exist." gp)))
  989.     (message "Already subscribed to group %s." gp)))))
  990.  
  991. (defun news-make-link-to-message (number newname)
  992.     "Forges a link to an rnews message numbered number (current if no arg)
  993. Good for hanging on to a message that might or might not be
  994. automatically deleted."
  995.   (interactive "P
  996. FName to link to message: ")
  997.   (add-name-to-file
  998.    (concat news-path
  999.        (string-subst-char ?/ ?. news-current-news-group)
  1000.        "/" (if number
  1001.            (prefix-numeric-value number)
  1002.          news-current-message-number))
  1003.    newname))
  1004.  
  1005. ;;; caesar-region written by phr@prep.ai.mit.edu  Nov 86
  1006. ;;; modified by tower@prep Nov 86
  1007. (defun caesar-region (&optional n)
  1008.   "Caesar rotation of region by N, default 13, for decrypting netnews."
  1009.   (interactive (if current-prefix-arg    ; Was there a prefix arg?
  1010.            (list (prefix-numeric-value current-prefix-arg))
  1011.          (list nil)))
  1012.   (cond ((not (numberp n)) (setq n 13))
  1013.     ((< n 0) (setq n (- 26 (% (- n) 26))))
  1014.     (t (setq n (% n 26))))        ;canonicalize N
  1015.   (if (not (zerop n))        ; no action needed for a rot of 0
  1016.       (progn
  1017.     (if (or (not (boundp 'caesar-translate-table))
  1018.         (/= (aref caesar-translate-table ?a) (+ ?a n)))
  1019.         (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
  1020.           (message "Building caesar-translate-table...")
  1021.           (setq caesar-translate-table (make-vector 256 0))
  1022.           (while (< i 256)
  1023.         (aset caesar-translate-table i i)
  1024.         (setq i (1+ i)))
  1025.           (setq lower (concat lower lower) upper (upcase lower) i 0)
  1026.           (while (< i 26)
  1027.         (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
  1028.         (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
  1029.         (setq i (1+ i)))
  1030.           (message "Building caesar-translate-table... done")))
  1031.     (let ((from (region-beginning))
  1032.           (to (region-end))
  1033.           (i 0) str len)
  1034.       (setq str (buffer-substring from to))
  1035.       (setq len (length str))
  1036.       (while (< i len)
  1037.         (aset str i (aref caesar-translate-table (aref str i)))
  1038.         (setq i (1+ i)))
  1039.       (goto-char from)
  1040.       (kill-region from to)
  1041.       (insert str)))))
  1042.  
  1043. ;;; news-caesar-buffer-body written by paul@media-lab.mit.edu  Wed Oct 1, 1986
  1044. ;;; hacked further by tower@prep.ai.mit.edu
  1045. (defun news-caesar-buffer-body (&optional rotnum)
  1046.   "Caesar rotates all letters in the current buffer by 13 places.
  1047. Used to encode/decode possibly offensive messages (commonly in net.jokes).
  1048. With prefix arg, specifies the number of places to rotate each letter forward.
  1049. Mail and USENET news headers are not rotated."
  1050.   (interactive (if current-prefix-arg    ; Was there a prefix arg?
  1051.            (list (prefix-numeric-value current-prefix-arg))
  1052.          (list nil)))
  1053.   (save-excursion
  1054.     (let ((buffer-status buffer-read-only))
  1055.       (setq buffer-read-only nil)
  1056.       ;; setup the region
  1057.       (set-mark (if (progn (goto-char (point-min))
  1058.                 (search-forward
  1059.                  (concat "\n"
  1060.                      (if (equal major-mode 'news-mode)
  1061.                      ""
  1062.                        mail-header-separator)
  1063.                      "\n") nil t))
  1064.              (point)
  1065.            (point-min)))
  1066.       (goto-char (point-max))
  1067.       (caesar-region rotnum)
  1068.       (setq buffer-read-only buffer-status))))
  1069.  
  1070.  
  1071. ;  [ news-summary extensions ]
  1072. ; -----------------------------------------------------------------------------
  1073. ;  original:  {...}!uunet!cimshop!rhess  12-27-88
  1074. ; -----------------------------------------------------------------------------
  1075. ;  based on [ CORE ] by Dave Platt, {...}!uunet!coherent!dplatt
  1076. ; -----------------------------------------------------------------------------
  1077.  
  1078. (defvar news-sbuf-assoc nil
  1079.   "Collection of active summary buffers... [ rhess ]")
  1080.  
  1081. (defun news-get-sbuf ()
  1082.   "Gets buffer for current news group summary info... [ rhess ]"
  1083.   (let* ((sbuf-entry (assoc news-current-news-group news-sbuf-assoc)))
  1084.     (if sbuf-entry
  1085.     (if (<= news-current-group-end (news-cadr sbuf-entry))
  1086.         (news-caddr sbuf-entry)
  1087.       (progn (news-kill-summary-buffer sbuf-entry)
  1088.          nil))
  1089.       nil
  1090.       )))
  1091.  
  1092. (defun news-create-sbuf ()
  1093.   "Creates the raw buffer for a news group's summary info... [ rhess ]"
  1094.   (let* ((sbuf-name (format " *%s" news-current-news-group))
  1095.      (sbuf))
  1096.     (prog1
  1097.     (setq sbuf (generate-new-buffer sbuf-name))
  1098.       (news-push (list news-current-news-group news-current-group-end sbuf)
  1099.          news-sbuf-assoc))
  1100.     ))
  1101.  
  1102. (defun news-kill-summary-buffer (assoc-entry)
  1103.   "Remove any window(s) displaying the summary buffer and kill it... [ rhess ]"
  1104.   (let* ((sbuf (news-caddr assoc-entry)))
  1105.     (delete-windows-on sbuf)
  1106.     (kill-buffer sbuf)
  1107.     (delq assoc-entry news-sbuf-assoc)
  1108.     ))
  1109.  
  1110. (defun news-view-summary ()
  1111.   "View the summary buffer for current newgroup... [ rhess ]"
  1112.   (interactive)
  1113.   (let* ((sbuf (news-get-sbuf))
  1114.      (rbuf (current-buffer)))
  1115.     (if sbuf
  1116.     (progn (summary-mode sbuf)
  1117.            (switch-to-buffer rbuf))
  1118.       (news-summary))))
  1119.  
  1120. (defun news-summary ()
  1121.   "Create a summary of unseen news articles... [ rhess ]"
  1122.   (interactive)
  1123.   (let* ((newsrc-last-article
  1124.       (news-caddr
  1125.        (news-cadr
  1126.         (assoc news-current-news-group news-group-article-assoc)))
  1127. ;      (car (reverse
  1128. ;        (car (reverse
  1129. ;              (assoc news-current-news-group
  1130. ;                 news-group-article-assoc)))))
  1131.       ))
  1132.     (news-summary-core newsrc-last-article)))
  1133.  
  1134. (defun news-summary-all ()
  1135.   "Create a summary of all news articles... [ rhess ]"
  1136.   (interactive)
  1137.   (news-summary-core 0))
  1138.  
  1139. (defun news-summary-force-update ()
  1140.   "[ Internal ]:  an enhanced functionality news-force-update... [ rhess ]"
  1141.   (if (> news-current-message-number (news-cdar news-point-pdl))
  1142.       (setcdr (car news-point-pdl) news-current-message-number)))
  1143.  
  1144. (defun news-summary-core (init-article)
  1145.   "[ CORE ]:  creates summary of news articles... [ rhess ]"
  1146.   (let* ((sbuf (or (news-get-sbuf)
  1147.            (news-create-sbuf)))
  1148.      (rbuf (current-buffer))
  1149.          (wbuf-name "*Scratch-News-Buffer*")
  1150.          (wbuf (or (get-buffer wbuf-name)
  1151.                    (generate-new-buffer wbuf-name)))
  1152.          (articles nil)
  1153.          (line nil)
  1154.          (signal-var nil)
  1155.      (pop-up-windows nil)
  1156.          (news-current-path (concat news-path
  1157.              (string-subst-char ?/ ?. 
  1158.               (if (and (boundp 'news-current-news-group)
  1159.                        (stringp news-current-news-group))
  1160.                   news-current-news-group
  1161.                   "public")))))
  1162.     (condition-case signal-var
  1163.      (progn
  1164.       (message "Reading files...")
  1165.       (call-process "ls" nil wbuf nil "-t -r" news-current-path)
  1166.       (message "Fetching filenames...")
  1167.       (switch-to-buffer wbuf)
  1168.       (goto-char (point-max))
  1169.       (while (search-backward "\n" nil t)
  1170.        (beginning-of-line)
  1171.        (setq this-message
  1172.           (string-to-int 
  1173.             (buffer-substring (point) (progn (end-of-line) (point)))))
  1174.       (beginning-of-line)
  1175.       (setq articles (cons this-message articles)))
  1176.       (message "Sorting...")
  1177.       (setq articles (sort articles '<))
  1178.       (message "Scanning...")
  1179.       (pop-to-buffer sbuf)
  1180.       (setq buffer-read-only nil)
  1181.       (erase-buffer)
  1182.       (pop-to-buffer wbuf)
  1183.       (setq buffer-read-only nil)
  1184.       (while (not (null articles))
  1185.         (progn
  1186.          (setq thisone (car articles))
  1187.          (setq articles (cdr articles))
  1188.          (if (> thisone init-article)            ; [ rhess ]
  1189.           (progn
  1190.             (pop-to-buffer wbuf)
  1191.             (erase-buffer)
  1192.             (setq thisone (int-to-string thisone))
  1193.             (if (> (baud-rate) search-slow-speed)
  1194.                 (message (concat "Scanning... " thisone)))
  1195.             (insert-file-contents (concat news-current-path "/" thisone))
  1196.             (setq line (news-make-basic-summary-line thisone))
  1197.             (pop-to-buffer sbuf)
  1198.             (setq buffer-read-only nil)
  1199.             (insert line)))))
  1200.       (message "Summary complete"))
  1201.      (quit
  1202.       (message "Summary interrupted")))
  1203.     (setq buffer-read-only t)
  1204.     (setq truncate-lines t)
  1205.     (goto-char (point-min))
  1206.     (kill-buffer wbuf)
  1207.     (switch-to-buffer rbuf)
  1208.     (summary-mode sbuf)
  1209.     (switch-to-buffer rbuf)))
  1210.  
  1211. (defun news-make-basic-summary-line (msgident)
  1212.   "[ CORE ]:  creates summary line for news article... [ rhess ]"
  1213.   (goto-char (point-min))
  1214.   (concat (format "%5s" msgident)
  1215.           " "
  1216.           (save-excursion
  1217.         (if (not (search-forward "Date:" nil t))
  1218.         "      "
  1219.           (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
  1220.               (save-excursion (end-of-line) (point)) t)
  1221.              (format "%2d-%3s"
  1222.                  (string-to-int (buffer-substring
  1223.                          (match-beginning 2)
  1224.                          (match-end 2)))
  1225.                  (buffer-substring
  1226.                   (match-beginning 4) (match-end 4))))
  1227.             ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
  1228.               (save-excursion (end-of-line) (point)) t)
  1229.              (format "%2d-%3s"
  1230.                  (string-to-int (buffer-substring
  1231.                          (match-beginning 4)
  1232.                          (match-end 4)))
  1233.                  (buffer-substring
  1234.                   (match-beginning 2) (match-end 2))))
  1235.             (t "??????"))))
  1236.       "  "
  1237.       (save-excursion
  1238.         (if (not (search-forward "From:" nil t))
  1239.         "                         "
  1240.           (progn (skip-chars-forward " \t")
  1241.              (let* ((from (mail-strip-quoted-names
  1242.                    (buffer-substring
  1243.                     (1- (point))
  1244.                     (progn (end-of-line)
  1245.                        (skip-chars-backward " ")
  1246.                        (point)))))
  1247.                             lo len mch)
  1248.                (setq len (length from))
  1249.                        (if (string-equal "@" (substring from 0 1))
  1250.                          (let ((colon (string-match ":" from)))
  1251.                           (if (not (null colon))
  1252.                            (progn
  1253.                             (setq from (substring from (1+ colon)))
  1254.                             (setq len (length from))))))
  1255.                (setq mch (string-match "[@%]" from))
  1256.                (format "%25s"
  1257.                    (if (or (not mch) (<= len 25))
  1258.                    (substring from (max 0 (- len 25)))
  1259.                  (substring from
  1260.                         (setq lo (cond ((< (- mch 9) 0) 0)
  1261.                                ((< len (+ mch 16))
  1262.                                 (- len 25))
  1263.                                (t (- mch 9))))
  1264.                         (min len (+ lo 25)))))))))
  1265.       "  "
  1266.       (if (search-forward "Subject:" nil t)
  1267.           (progn (skip-chars-forward " \t")
  1268.              (buffer-substring (point)
  1269.                        (progn (end-of-line)
  1270.                           (point))))
  1271.         (re-search-forward "[\n][\n]+" nil t)
  1272.         (buffer-substring (point) (progn (end-of-line) (point))))
  1273.       "\n"))
  1274.  
  1275.  
  1276. ;  [ Summary-Mode ]:  Peruse rnews summary buffer without editing... [ rhess ]
  1277. ;                     Peruse subscription buffer without editing... [ rhess ]
  1278. ; -----------------------------------------------------------------------------
  1279. ;  based on [ View:  author K. Shane Hartman ]
  1280. ; -----------------------------------------------------------------------------
  1281.  
  1282. (defvar summary-mode-map nil)
  1283. (if summary-mode-map
  1284.     nil
  1285.   (setq summary-mode-map (make-keymap))
  1286.   (fillarray summary-mode-map 'Summary-undefined)
  1287.   (define-key summary-mode-map "p"     'previous-line)
  1288.   (define-key summary-mode-map "n"     'next-line)
  1289.   (define-key summary-mode-map "N"     'Summary-next-group)
  1290.   (define-key summary-mode-map "q"     'exit-recursive-edit)
  1291.   (define-key summary-mode-map "s"     'Summary-select-article)
  1292.   (define-key summary-mode-map "x"     'execute-extended-command)
  1293.   (define-key summary-mode-map "<"     'beginning-of-buffer)
  1294.   (define-key summary-mode-map ">"     'end-of-buffer)
  1295.   (define-key summary-mode-map " "     'scroll-up)
  1296.   (define-key summary-mode-map "\177"     'scroll-down)
  1297.   (define-key summary-mode-map "l"     'recenter)
  1298.   (define-key summary-mode-map "\C-a"     'beginning-of-line)
  1299.   (define-key summary-mode-map "\C-s"     'isearch-forward)
  1300.   (define-key summary-mode-map "\C-r"     'isearch-backward)
  1301.   (define-key summary-mode-map "\C-p"     'previous-line)
  1302.   (define-key summary-mode-map "\C-n"     'next-line)
  1303.   (define-key summary-mode-map "\e"     nil)
  1304.   (define-key summary-mode-map "h"     'Helper-help)
  1305.   (define-key summary-mode-map "?"     'Helper-describe-bindings)
  1306.   )
  1307.  
  1308. (defvar summary-hook nil
  1309.   "If non-nil, its value is called when viewing rnews summary buffer.")
  1310.  
  1311. (defvar summary-current-article nil
  1312.   "Current article in rnews buffer... [ rhess ]")
  1313.  
  1314. (defvar summary-selected-article nil
  1315.   "Selected article:  at point in rnews summary buffer... [ rhess ]")
  1316.  
  1317. (defvar summary-newsgroup-mode-p nil
  1318.   "[ Flag ], Setup summary mode for newsgroups or articles... [ rhess ]")
  1319.  
  1320. (defvar summary-select-next-group-p nil
  1321.   "[ Flag ], Select next news group on exit... [ rhess ]")
  1322.  
  1323. (defvar summary-error-message nil
  1324.   "String used contain summary initialization error messages... [ rhess ]")
  1325.  
  1326. (defun summary-helpful-message ()
  1327.   (message
  1328.    (if (and (eq (key-binding "h") 'Helper-help)
  1329.         (eq (key-binding "?") 'Helper-describe-bindings)
  1330.         (eq (key-binding "q") 'exit-recursive-edit))
  1331.        "Type h for help, ? for commands, q to quit..."
  1332.      (substitute-command-keys
  1333.       "Type \\[Helper-help] for help, \\[Helper-describe-bindings] for commands, \\[exit-recursive-edit] to quit."))))
  1334.  
  1335. (defun summary-mode-command-loop ()
  1336.   (let ((old-local-map (current-local-map))
  1337.     (mark-ring)
  1338.     (summary-last-regexp)
  1339.     (Helper-return-blurb
  1340.      (format "continue viewing %s"
  1341.          (if (buffer-file-name)
  1342.              (file-name-nondirectory (buffer-file-name))
  1343.              (buffer-name))))
  1344.     (goal-column 0)
  1345.     (summary-buffer (buffer-name)))
  1346.     (unwind-protect  (progn
  1347.                (use-local-map summary-mode-map)
  1348.                (run-hooks 'summary-hook)
  1349.                (summary-helpful-message)
  1350.                (if summary-error-message
  1351.                (progn
  1352.                  (message summary-error-message)
  1353.                  (setq summary-error-message nil)))
  1354.                (recursive-edit))
  1355.       (save-excursion  (set-buffer summary-buffer)
  1356.                (use-local-map old-local-map)))))
  1357.  
  1358. ; --[ Mode ]-------------------------------------------------------------------
  1359.  
  1360. (defun summary-mode (sbuf)
  1361.   "Major mode for viewing rnews summary buffer but not editing it.
  1362. Letters do not insert themselves.  Instead these commands are provided.
  1363.  
  1364. <        move to beginning of buffer.
  1365. >            move to end of buffer.
  1366. Space            scroll forward lines.
  1367. DEL            scroll backward lines.
  1368. n, C-n        next line.
  1369. p, C-p        previous line.
  1370. N        mark last article and select next news group.
  1371. s        select rnews article at point... 
  1372. x        execute extended command... 
  1373. C-a        beginning of line... [ exit search ]
  1374. C-s        do forward incremental search.
  1375. C-r        do reverse incremental search.
  1376. ?        provide help message (list of commands).
  1377. h        provides help (list of commands or description of a command).
  1378. l        recenters the screen.
  1379. q        exit summary-mode and return to previous buffer.
  1380.  
  1381. Entry to this mode calls the value of  summary-hook  if non-nil.
  1382. \\{summary-mode-map}"
  1383. ;  Not interactive because dangerous things happen
  1384. ;  if you call it without passing a buffer as argument
  1385. ;  and they are not easy to fix.
  1386. ;  (interactive)
  1387.   (setq summary-current-article news-current-message-number)
  1388.   (switch-to-buffer sbuf)
  1389.   (setq summary-selected-article nil)
  1390.   (setq major-mode 'summary-mode)
  1391.   (setq summary-newsgroup-mode-p (equal (buffer-name) 
  1392.                     news-groups-buffer-name))
  1393.   (unwind-protect
  1394.       (let ((buffer-read-only t)
  1395.         (mode-line-buffer-identification
  1396.          (list
  1397.           (if (buffer-file-name)
  1398.           "Viewing %f"
  1399.         "Viewing %b")))
  1400.         (mode-name "Summary"))
  1401.     (beginning-of-line)
  1402.     (if summary-newsgroup-mode-p
  1403.         (progn
  1404.           (goto-char 1)
  1405.           (search-forward news-current-news-group (buffer-end 1) t)
  1406.           (beginning-of-line)
  1407.           )
  1408.       (if summary-current-article
  1409.           (progn
  1410.         (goto-char 1)
  1411.         (if (not (search-forward
  1412.               (int-to-string summary-current-article)
  1413.               (buffer-end 1) t))
  1414.             (progn
  1415.               (ding)
  1416.               (setq
  1417.                summary-error-message
  1418.                (format
  1419.             "[ %s ]:  Current article not in summary buffer..."
  1420.             summary-current-article))))
  1421.         (beginning-of-line))))
  1422.     (catch 'summary-mode-exit (summary-mode-command-loop)))
  1423.     (switch-to-buffer news-buffer)
  1424.     (if summary-selected-article
  1425.     (progn
  1426.       (message "[ %s ]" summary-selected-article)
  1427.       (if summary-newsgroup-mode-p
  1428.           (progn
  1429.         (news-goto-news-group summary-selected-article))
  1430.         (progn (news-select-message summary-selected-article)
  1431.            (news-summary-force-update)
  1432.            (if summary-select-next-group-p
  1433.                (news-next-group))))
  1434.       ))
  1435.     (setq summary-select-next-group-p nil)
  1436.     ))
  1437.  
  1438. ; --[ Interactive ]------------------------------------------------------------
  1439.  
  1440. (defun Summary-select-article ()
  1441.   "Select current article at point and exit... [ rhess ]"
  1442.   (interactive)
  1443.   (let* ((sbuf (current-buffer))
  1444.      (start)
  1445.      (end))
  1446.     (if (eobp) (previous-line 1))
  1447.     (if (not (eobp))
  1448.     (progn
  1449.       (beginning-of-line)
  1450.       (if summary-newsgroup-mode-p
  1451.           (progn
  1452.         (end-of-line)
  1453.         (backward-word 2)
  1454.         (forward-word 1)
  1455.         (setq end (point))
  1456.         (beginning-of-line 1)
  1457.         (setq start (point))
  1458.         (setq summary-selected-article (buffer-substring start end)))
  1459.         (progn
  1460.           (forward-word 1)
  1461.           (setq end (point))
  1462.           (backward-word 1)
  1463.           (setq start (point))
  1464.           (setq summary-selected-article
  1465.             (string-to-int (buffer-substring start end)))))
  1466.       (beginning-of-line)))
  1467.     (exit-recursive-edit)
  1468.     )
  1469.   )
  1470.  
  1471. (defun Summary-next-group ()
  1472.   "Mark last article and select next news group... [ rhess ]"
  1473.   (interactive)
  1474.   (if (not summary-newsgroup-mode-p)
  1475.       (progn (setq summary-select-next-group-p t)
  1476.          (end-of-buffer)
  1477.          (Summary-select-article)))
  1478.   )
  1479.  
  1480. (defun Summary-undefined ()
  1481.   (interactive)
  1482.   (ding)
  1483.   (summary-helpful-message))
  1484.  
  1485. ; ----<eof>
  1486.   
  1487. ;-------------------------------------------------------------------------------
  1488. ;WHO:    Richard Hess            CORP:    Consilium
  1489. ;TITLE:    Project Manager            VOICE:    [415] 691-6342
  1490. ;      [ User Interface Services ]    USNAIL:    640 Clyde Court
  1491. ;UUCP:    ...!uunet!cimshop!rhess            Mountain View, CA 94043
  1492. ;-------------------------------------------------------------------------------
  1493.