]> code.delx.au - gnu-emacs/blob - lisp/obsolete/rnews.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / obsolete / rnews.el
1 ;;; rnews.el --- USENET news reader for GNU Emacs
2
3 ;; Copyright (C) 1985, 1986, 1987, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; This file has been obsolete since Emacs 21.1.
29
30 ;;; Change Log:
31
32 ;; Created Sun Mar 10,1985 at 21:35:01 ads and sundar@hernes.ai.mit.edu
33 ;; Should do the point pdl stuff sometime
34 ;; finito except pdl.... Sat Mar 16,1985 at 06:43:44
35 ;; lets keep the summary stuff out until we get it working ..
36 ;; sundar@hermes.ai.mit.edu Wed Apr 10,1985 at 16:32:06
37 ;; hack slash maim. mly@gnu.org Thu 18 Apr, 1985 06:11:14
38 ;; modified to correct reentrance bug, to not bother with groups that
39 ;; received no new traffic since last read completely, to find out
40 ;; what traffic a group has available much more quickly when
41 ;; possible, to do some completing reads for group names - should
42 ;; be much faster...
43 ;; KING@KESTREL.arpa, Thu Mar 13 09:03:28 1986
44 ;; made news-{next,previous}-group skip groups with no new messages; and
45 ;; added checking for unsubscribed groups to news-add-news-group
46 ;; tower@gnu.org Jul 18 1986
47 ;; bound rmail-output to C-o; and changed header-field commands binding to
48 ;; agree with the new C-c C-f usage in sendmail
49 ;; tower@gnu.org Sep 3 1986
50 ;; added news-rotate-buffer-body
51 ;; tower@gnu.org Oct 17 1986
52 ;; made messages more user friendly, cleaned up news-inews
53 ;; move posting and mail code to new file rnewpost.el
54 ;; tower@gnu.org Oct 29 1986
55 ;; added caesar-region, rename news-caesar-buffer-body, hacked accordingly
56 ;; tower@gnu.org Nov 21 1986
57 ;; added tower@gnu.org 22 Apr 87
58
59 ;;; Code:
60
61 (require 'mail-utils)
62 (require 'sendmail)
63
64 (defvar caesar-translate-table)
65 (defvar minor-modes)
66 (defvar news-buffer-save)
67 (defvar news-group-name)
68 (defvar news-minor-modes)
69
70 (autoload 'rmail-output "rmailout"
71 "Append this message to Unix mail file named FILE-NAME."
72 t)
73
74 (autoload 'news-reply "rnewspost"
75 "Compose and post a reply to the current article on USENET.
76 While composing the reply, use \\[mail-yank-original] to yank the original
77 message into it."
78 t)
79
80 (autoload 'news-mail-other-window "rnewspost"
81 "Send mail in another window.
82 While composing the message, use \\[mail-yank-original] to yank the
83 original message into it."
84 t)
85
86 (autoload 'news-post-news "rnewspost"
87 "Begin editing a new USENET news article to be posted."
88 t)
89
90 (autoload 'news-mail-reply "rnewspost"
91 "Mail a reply to the author of the current article.
92 While composing the reply, use \\[mail-yank-original] to yank the original
93 message into it."
94 t)
95
96 (defvar news-group-hook-alist nil
97 "Alist of (GROUP-REGEXP . HOOK) pairs.
98 Just before displaying a message, each HOOK is called
99 if its GROUP-REGEXP matches the current newsgroup name.")
100
101 (defvar rmail-last-file (expand-file-name "~/mbox.news"))
102
103 ;Now in paths.el.
104 ;(defvar news-path "/usr/spool/news/"
105 ; "The root directory below which all news files are stored.")
106
107 (defvar news-startup-file "$HOME/.newsrc" "Contains ~/.newsrc")
108 (defvar news-certification-file "$HOME/.news-dates" "Contains ~/.news-dates")
109
110 ;; random headers that we decide to ignore.
111 (defvar news-ignored-headers
112 "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:"
113 "All random fields within the header of a message.")
114
115 (defvar news-mode-map nil)
116 (defvar news-read-first-time-p t)
117 ;; Contains the (dotified) news groups of which you are a member.
118 (defvar news-user-group-list nil)
119
120 (defvar news-current-news-group nil)
121 (defvar news-current-group-begin nil)
122 (defvar news-current-group-end nil)
123 (defvar news-current-certifications nil
124 "An assoc list of a group name and the time at which it is
125 known that the group had no new traffic")
126 (defvar news-current-certifiable nil
127 "The time when the directory we are now working on was written")
128
129 (defvar news-message-filter nil
130 "User specifiable filter function that will be called during
131 formatting of the news file")
132
133 ;(defvar news-mode-group-string "Starting-Up"
134 ; "Mode line group name info is held in this variable")
135 (defvar news-list-of-files nil
136 "Global variable in which we store the list of files
137 associated with the current newsgroup")
138 (defvar news-list-of-files-possibly-bogus nil
139 "variable indicating we only are guessing at which files are available.
140 Not currently used.")
141
142 ;; association list in which we store lists of the form
143 ;; (pointified-group-name (first last old-last))
144 (defvar news-group-article-assoc nil)
145
146 (defvar news-current-message-number 0 "Displayed Article Number")
147 (defvar news-total-current-group 0 "Total no of messages in group")
148
149 (defvar news-unsubscribe-groups ())
150 (defvar news-point-pdl () "List of visited news messages.")
151 (defvar news-no-jumps-p t)
152 (defvar news-buffer () "Buffer into which news files are read.")
153
154 (defmacro news-push (item ref)
155 (list 'setq ref (list 'cons item ref)))
156
157 (defmacro news-cadr (x) (list 'car (list 'cdr x)))
158 (defmacro news-cdar (x) (list 'cdr (list 'car x)))
159 (defmacro news-caddr (x) (list 'car (list 'cdr (list 'cdr x))))
160 (defmacro news-cadar (x) (list 'car (list 'cdr (list 'car x))))
161 (defmacro news-caadr (x) (list 'car (list 'car (list 'cdr x))))
162 (defmacro news-cdadr (x) (list 'cdr (list 'car (list 'cdr x))))
163
164 (defmacro news-wins (pfx index)
165 `(file-exists-p (concat ,pfx "/" (int-to-string ,index))))
166
167 (defvar news-max-plausible-gap 2
168 "* In an rnews directory, the maximum possible gap size.
169 A gap is a sequence of missing messages between two messages that exist.
170 An empty file does not contribute to a gap -- it ends one.")
171
172 (defun news-find-first-and-last (prefix base)
173 (and (news-wins prefix base)
174 (cons (news-find-first-or-last prefix base -1)
175 (news-find-first-or-last prefix base 1))))
176
177 (defmacro news-/ (a1 a2)
178 ;; a form of / that guarantees that (/ -1 2) = 0
179 (if (zerop (/ -1 2))
180 `(/ ,a1 ,a2)
181 `(if (< ,a1 0)
182 (- (/ (- ,a1) ,a2))
183 (/ ,a1 ,a2))))
184
185 (defun news-find-first-or-last (pfx base dirn)
186 ;; first use powers of two to find a plausible ceiling
187 (let ((original-dir dirn))
188 (while (news-wins pfx (+ base dirn))
189 (setq dirn (* dirn 2)))
190 (setq dirn (news-/ dirn 2))
191 ;; Then use a binary search to find the high water mark
192 (let ((offset (news-/ dirn 2)))
193 (while (/= offset 0)
194 (if (news-wins pfx (+ base dirn offset))
195 (setq dirn (+ dirn offset)))
196 (setq offset (news-/ offset 2))))
197 ;; If this high-water mark is bogus, recurse.
198 (let ((offset (* news-max-plausible-gap original-dir)))
199 (while (and (/= offset 0) (not (news-wins pfx (+ base dirn offset))))
200 (setq offset (- offset original-dir)))
201 (if (= offset 0)
202 (+ base dirn)
203 (news-find-first-or-last pfx (+ base dirn offset) original-dir)))))
204
205 (defun rnews ()
206 "Read USENET news for groups for which you are a member and add or
207 delete groups.
208 You can reply to articles posted and send articles to any group.
209
210 Type \\[describe-mode] once reading news to get a list of rnews commands."
211 (interactive)
212 (let ((last-buffer (buffer-name)))
213 (make-local-variable 'rmail-last-file)
214 (switch-to-buffer (setq news-buffer (get-buffer-create "*news*")))
215 (news-mode)
216 (setq news-buffer-save last-buffer)
217 (setq buffer-read-only nil)
218 (erase-buffer)
219 (setq buffer-read-only t)
220 (set-buffer-modified-p t)
221 (sit-for 0)
222 (message "Getting new USENET news...")
223 (news-set-mode-line)
224 (news-get-certifications)
225 (news-get-new-news)))
226
227 (defun news-group-certification (group)
228 (cdr-safe (assoc group news-current-certifications)))
229
230
231 (defun news-set-current-certifiable ()
232 ;; Record the date that corresponds to the directory you are about to check
233 (let ((file (concat news-path
234 (string-subst-char ?/ ?. news-current-news-group))))
235 (setq news-current-certifiable
236 (nth 5 (file-attributes
237 (or (file-symlink-p file) file))))))
238
239 (defun news-get-certifications ()
240 ;; Read the certified-read file from last session
241 (save-excursion
242 (save-window-excursion
243 (setq news-current-certifications
244 (car-safe
245 (condition-case var
246 (let*
247 ((file (substitute-in-file-name news-certification-file))
248 (buf (find-file-noselect file)))
249 (and (file-exists-p file)
250 (progn
251 (switch-to-buffer buf 'norecord)
252 (unwind-protect
253 (read-from-string (buffer-string))
254 (kill-buffer buf)))))
255 (error nil)))))))
256
257 (defun news-write-certifications ()
258 ;; Write a certification file.
259 ;; This is an assoc list of group names with doubletons that represent
260 ;; mod times of the directory when group is read completely.
261 (save-excursion
262 (save-window-excursion
263 (with-output-to-temp-buffer
264 "*CeRtIfIcAtIoNs*"
265 (print news-current-certifications))
266 (let ((buf (get-buffer "*CeRtIfIcAtIoNs*")))
267 (switch-to-buffer buf)
268 (write-file (substitute-in-file-name news-certification-file))
269 (kill-buffer buf)))))
270
271 (defun news-set-current-group-certification ()
272 (let ((cgc (assoc news-current-news-group news-current-certifications)))
273 (if cgc (setcdr cgc news-current-certifiable)
274 (news-push (cons news-current-news-group news-current-certifiable)
275 news-current-certifications))))
276
277 (defun news-set-message-counters ()
278 "Scan through current news-groups filelist to figure out how many messages
279 are there. Set counters for use with minor mode display."
280 (if (null news-list-of-files)
281 (setq news-current-message-number 0)))
282
283 (if news-mode-map
284 nil
285 (setq news-mode-map (make-keymap))
286 (suppress-keymap news-mode-map)
287 (define-key news-mode-map "." 'beginning-of-buffer)
288 (define-key news-mode-map " " 'scroll-up)
289 (define-key news-mode-map "\177" 'scroll-down)
290 (define-key news-mode-map "n" 'news-next-message)
291 (define-key news-mode-map "c" 'news-make-link-to-message)
292 (define-key news-mode-map "p" 'news-previous-message)
293 (define-key news-mode-map "j" 'news-goto-message)
294 (define-key news-mode-map "q" 'news-exit)
295 (define-key news-mode-map "e" 'news-exit)
296 (define-key news-mode-map "\ej" 'news-goto-news-group)
297 (define-key news-mode-map "\en" 'news-next-group)
298 (define-key news-mode-map "\ep" 'news-previous-group)
299 (define-key news-mode-map "l" 'news-list-news-groups)
300 (define-key news-mode-map "?" 'describe-mode)
301 (define-key news-mode-map "g" 'news-get-new-news)
302 (define-key news-mode-map "f" 'news-reply)
303 (define-key news-mode-map "m" 'news-mail-other-window)
304 (define-key news-mode-map "a" 'news-post-news)
305 (define-key news-mode-map "r" 'news-mail-reply)
306 (define-key news-mode-map "o" 'news-save-item-in-file)
307 (define-key news-mode-map "\C-o" 'rmail-output)
308 (define-key news-mode-map "t" 'news-show-all-headers)
309 (define-key news-mode-map "x" 'news-force-update)
310 (define-key news-mode-map "A" 'news-add-news-group)
311 (define-key news-mode-map "u" 'news-unsubscribe-current-group)
312 (define-key news-mode-map "U" 'news-unsubscribe-group)
313 (define-key news-mode-map "\C-c\C-r" 'news-caesar-buffer-body))
314
315 (defun news-mode ()
316 "News Mode is used by M-x rnews for reading USENET Newsgroups articles.
317 New readers can find additional help in newsgroup: news.announce.newusers .
318 All normal editing commands are turned off.
319 Instead, these commands are available:
320
321 . move point to front of this news article (same as Meta-<).
322 Space scroll to next screen of this news article.
323 Delete scroll down previous page of this news article.
324 n move to next news article, possibly next group.
325 p move to previous news article, possibly previous group.
326 j jump to news article specified by numeric position.
327 M-j jump to news group.
328 M-n goto next news group.
329 M-p goto previous news group.
330 l list all the news groups with current status.
331 ? print this help message.
332 C-c C-r caesar rotate all letters by 13 places in the article's body (rot13).
333 g get new USENET news.
334 f post a reply article to USENET.
335 a post an original news article.
336 A add a newsgroup.
337 o save the current article in the named file (append if file exists).
338 C-o output this message to a Unix-format mail file (append it).
339 c \"copy\" (actually link) current or prefix-arg msg to file.
340 warning: target directory and message file must be on same device
341 (UNIX magic)
342 t show all the headers this news article originally had.
343 q quit reading news after updating .newsrc file.
344 e exit updating .newsrc file.
345 m mail a news article. Same as C-x 4 m.
346 x update last message seen to be the current message.
347 r mail a reply to this news article. Like m but initializes some fields.
348 u unsubscribe from current newsgroup.
349 U unsubscribe from specified newsgroup."
350 (interactive)
351 (kill-all-local-variables)
352 (make-local-variable 'news-read-first-time-p)
353 (setq news-read-first-time-p t)
354 (make-local-variable 'news-current-news-group)
355 ; (setq news-current-news-group "??")
356 (make-local-variable 'news-current-group-begin)
357 (setq news-current-group-begin 0)
358 (make-local-variable 'news-current-message-number)
359 (setq news-current-message-number 0)
360 (make-local-variable 'news-total-current-group)
361 (make-local-variable 'news-buffer-save)
362 (make-local-variable 'version-control)
363 (setq version-control 'never)
364 (make-local-variable 'news-point-pdl)
365 ; This breaks it. I don't have time to figure out why. -- RMS
366 ; (make-local-variable 'news-group-article-assoc)
367 (setq major-mode 'news-mode)
368 (setq mode-line-process '(news-minor-modes))
369 (setq mode-name "NEWS")
370 (news-set-mode-line)
371 (set-syntax-table text-mode-syntax-table)
372 (use-local-map news-mode-map)
373 (setq local-abbrev-table text-mode-abbrev-table)
374 (run-mode-hooks 'news-mode-hook))
375
376 (defun string-subst-char (new old string)
377 (let (index)
378 (setq old (regexp-quote (char-to-string old))
379 string (substring string 0))
380 (while (setq index (string-match old string))
381 (aset string index new)))
382 string)
383
384 ;; update read message number
385 (defmacro news-update-message-read (ngroup nno)
386 (list 'setcar
387 (list 'news-cdadr
388 (list 'assoc ngroup 'news-group-article-assoc))
389 nno))
390
391 (defun news-parse-range (number-string)
392 "Parse string representing range of numbers of he form <a>-<b>
393 to a list (a . b)"
394 (let ((n (string-match "-" number-string)))
395 (if n
396 (cons (string-to-number (substring number-string 0 n))
397 (string-to-number (substring number-string (1+ n))))
398 (setq n (string-to-number number-string))
399 (cons n n))))
400
401 ;(defun is-in (elt lis)
402 ; (catch 'foo
403 ; (while lis
404 ; (if (equal (car lis) elt)
405 ; (throw 'foo t)
406 ; (setq lis (cdr lis))))))
407
408 (defun news-get-new-news ()
409 "Get new USENET news, if there is any for the current user."
410 (interactive)
411 (if (not (null news-user-group-list))
412 (news-update-newsrc-file))
413 (setq news-group-article-assoc ())
414 (setq news-user-group-list ())
415 (message "Looking up %s file..." news-startup-file)
416 (let ((file (substitute-in-file-name news-startup-file))
417 (temp-user-groups ()))
418 (save-excursion
419 (let ((newsrcbuf (find-file-noselect file))
420 start end endofline tem)
421 (set-buffer newsrcbuf)
422 (goto-char 0)
423 (while (search-forward ": " nil t)
424 (setq end (point))
425 (beginning-of-line)
426 (setq start (point))
427 (end-of-line)
428 (setq endofline (point))
429 (setq tem (buffer-substring start (- end 2)))
430 (let ((range (news-parse-range
431 (buffer-substring end endofline))))
432 (if (assoc tem news-group-article-assoc)
433 (message "You are subscribed twice to %s; I ignore second"
434 tem)
435 (setq temp-user-groups (cons tem temp-user-groups)
436 news-group-article-assoc
437 (cons (list tem (list (car range)
438 (cdr range)
439 (cdr range)))
440 news-group-article-assoc)))))
441 (kill-buffer newsrcbuf)))
442 (setq temp-user-groups (nreverse temp-user-groups))
443 (message "Prefrobnicating...")
444 (switch-to-buffer news-buffer)
445 (setq news-user-group-list temp-user-groups)
446 (while (and temp-user-groups
447 (not (news-read-files-into-buffer
448 (car temp-user-groups) nil)))
449 (setq temp-user-groups (cdr temp-user-groups)))
450 (if (null temp-user-groups)
451 (message "No news is good news.")
452 (message ""))))
453
454 (defun news-list-news-groups ()
455 "Display all the news groups to which you belong."
456 (interactive)
457 (with-output-to-temp-buffer "*Newsgroups*"
458 (save-excursion
459 (set-buffer standard-output)
460 (insert
461 "News Group Msg No. News Group Msg No.\n")
462 (insert
463 "------------------------- -------------------------\n")
464 (let ((temp news-user-group-list)
465 (flag nil))
466 (while temp
467 (let ((item (assoc (car temp) news-group-article-assoc)))
468 (insert (car item))
469 (indent-to (if flag 52 20))
470 (insert (int-to-string (news-cadr (news-cadr item))))
471 (if flag
472 (insert "\n")
473 (indent-to 33))
474 (setq temp (cdr temp) flag (not flag))))))))
475
476 ;; Mode line hack
477 (defun news-set-mode-line ()
478 "Set mode line string to something useful."
479 (setq mode-line-process
480 (concat " "
481 (if (integerp news-current-message-number)
482 (int-to-string news-current-message-number)
483 "??")
484 "/"
485 (if (integerp news-current-group-end)
486 (int-to-string news-current-group-end)
487 news-current-group-end)))
488 (setq mode-line-buffer-identification
489 (concat "NEWS: "
490 news-current-news-group
491 ;; Enough spaces to pad group name to 17 positions.
492 (substring " "
493 0 (max 0 (- 17 (length news-current-news-group))))))
494 (set-buffer-modified-p t)
495 (sit-for 0))
496
497 (defun news-goto-news-group (gp)
498 "Takes a string and goes to that news group."
499 (interactive (list (completing-read "NewsGroup: "
500 news-group-article-assoc)))
501 (message "Jumping to news group %s..." gp)
502 (news-select-news-group gp)
503 (message "Jumping to news group %s... done." gp))
504
505 (defun news-select-news-group (gp)
506 (let ((grp (assoc gp news-group-article-assoc)))
507 (if (null grp)
508 (error "Group %s not subscribed to" gp)
509 (progn
510 (news-update-message-read news-current-news-group
511 (news-cdar news-point-pdl))
512 (news-read-files-into-buffer (car grp) nil)
513 (news-set-mode-line)))))
514
515 (defun news-goto-message (arg)
516 "Goes to the article ARG in current newsgroup."
517 (interactive "p")
518 (if (null current-prefix-arg)
519 (setq arg (read-no-blanks-input "Go to article: " "")))
520 (news-select-message arg))
521
522 (defun news-select-message (arg)
523 (if (stringp arg) (setq arg (string-to-number arg)))
524 (let ((file (concat news-path
525 (string-subst-char ?/ ?. news-current-news-group)
526 "/" arg)))
527 (if (= arg
528 (or (news-cadr (memq (news-cdar news-point-pdl) news-list-of-files))
529 0))
530 (setcdr (car news-point-pdl) arg))
531 (setq news-current-message-number arg)
532 (if (file-exists-p file)
533 (let ((buffer-read-only nil))
534 (news-read-in-file file)
535 (news-set-mode-line))
536 (news-set-mode-line)
537 (error "Article %d nonexistent" arg))))
538
539 (defun news-force-update ()
540 "updates the position of last article read in the current news group"
541 (interactive)
542 (setcdr (car news-point-pdl) news-current-message-number)
543 (message "Updated to %d" news-current-message-number))
544
545 (defun news-next-message (arg)
546 "Move ARG messages forward within one newsgroup.
547 Negative ARG moves backward.
548 If ARG is 1 or -1, moves to next or previous newsgroup if at end."
549 (interactive "p")
550 (let ((no (+ arg news-current-message-number)))
551 (if (or (< no news-current-group-begin)
552 (> no news-current-group-end))
553 (cond ((= arg 1)
554 (news-set-current-group-certification)
555 (news-next-group))
556 ((= arg -1)
557 (news-previous-group))
558 (t (error "Article out of range")))
559 (let ((plist (news-get-motion-lists
560 news-current-message-number
561 news-list-of-files)))
562 (if (< arg 0)
563 (news-select-message (nth (1- (- arg)) (car (cdr plist))))
564 (news-select-message (nth (1- arg) (car plist))))))))
565
566 (defun news-previous-message (arg)
567 "Move ARG messages backward in current newsgroup.
568 With no arg or arg of 1, move one message
569 and move to previous newsgroup if at beginning.
570 A negative ARG means move forward."
571 (interactive "p")
572 (news-next-message (- arg)))
573
574 (defun news-move-to-group (arg)
575 "Given arg move forward or backward to a new newsgroup."
576 (let ((cg news-current-news-group))
577 (let ((plist (news-get-motion-lists cg news-user-group-list))
578 ngrp)
579 (if (< arg 0)
580 (or (setq ngrp (nth (1- (- arg)) (news-cadr plist)))
581 (error "No previous news groups"))
582 (or (setq ngrp (nth arg (car plist)))
583 (error "No more news groups")))
584 (news-select-news-group ngrp))))
585
586 (defun news-next-group ()
587 "Moves to the next user group."
588 (interactive)
589 ; (message "Moving to next group...")
590 (news-move-to-group 0)
591 (while (null news-list-of-files)
592 (news-move-to-group 0)))
593 ; (message "Moving to next group... done.")
594
595 (defun news-previous-group ()
596 "Moves to the previous user group."
597 (interactive)
598 ; (message "Moving to previous group...")
599 (news-move-to-group -1)
600 (while (null news-list-of-files)
601 (news-move-to-group -1)))
602 ; (message "Moving to previous group... done.")
603
604 (defun news-get-motion-lists (arg listy)
605 "Given a msgnumber/group this will return a list of two lists;
606 one for moving forward and one for moving backward."
607 (let ((temp listy)
608 (result ()))
609 (catch 'out
610 (while temp
611 (if (equal (car temp) arg)
612 (throw 'out (cons (cdr temp) (list result)))
613 (setq result (nconc (list (car temp)) result))
614 (setq temp (cdr temp)))))))
615
616 ;; miscellaneous io routines
617 (defun news-read-in-file (filename)
618 (erase-buffer)
619 (let ((start (point)))
620 (insert-file-contents filename)
621 (news-convert-format)
622 ;; Run each hook that applies to the current newsgroup.
623 (let ((hooks news-group-hook-alist))
624 (while hooks
625 (goto-char start)
626 (if (string-match (car (car hooks)) news-group-name)
627 (funcall (cdr (car hooks))))
628 (setq hooks (cdr hooks))))
629 (goto-char start)
630 (forward-line 1)
631 (if (eobp)
632 (message "(Empty file?)")
633 (goto-char start))))
634
635 (defun news-convert-format ()
636 (save-excursion
637 (save-restriction
638 (let* ((start (point))
639 (end (condition-case ()
640 (progn (search-forward "\n\n") (point))
641 (error nil)))
642 has-from has-date)
643 (cond (end
644 (narrow-to-region start end)
645 (goto-char start)
646 (setq has-from (search-forward "\nFrom:" nil t))
647 (cond ((and (not has-from) has-date)
648 (goto-char start)
649 (search-forward "\nDate:")
650 (beginning-of-line)
651 (kill-line) (kill-line)))
652 (news-delete-headers start)
653 (goto-char start)))))))
654
655 (defun news-show-all-headers ()
656 "Redisplay current news item with all original headers"
657 (interactive)
658 (let (news-ignored-headers
659 (buffer-read-only ()))
660 (erase-buffer)
661 (news-set-mode-line)
662 (news-read-in-file
663 (concat news-path
664 (string-subst-char ?/ ?. news-current-news-group)
665 "/" (int-to-string news-current-message-number)))))
666
667 (defun news-delete-headers (pos)
668 (goto-char pos)
669 (and (stringp news-ignored-headers)
670 (while (re-search-forward news-ignored-headers nil t)
671 (beginning-of-line)
672 (delete-region (point)
673 (progn (re-search-forward "\n[^ \t]")
674 (forward-char -1)
675 (point))))))
676
677 (defun news-exit ()
678 "Quit news reading session and update the .newsrc file."
679 (interactive)
680 (if (y-or-n-p "Do you really wanna quit reading news ? ")
681 (progn (message "Updating %s..." news-startup-file)
682 (news-update-newsrc-file)
683 (news-write-certifications)
684 (message "Updating %s... done" news-startup-file)
685 (message "Now do some real work")
686 (quit-window)
687 (switch-to-buffer news-buffer-save)
688 (setq news-user-group-list ()))
689 (message "")))
690
691 (defun news-update-newsrc-file ()
692 "Updates the .newsrc file in the users home dir."
693 (let ((newsrcbuf (find-file-noselect
694 (substitute-in-file-name news-startup-file)))
695 (tem news-user-group-list)
696 group)
697 (save-excursion
698 (if (not (null news-current-news-group))
699 (news-update-message-read news-current-news-group
700 (news-cdar news-point-pdl)))
701 (set-buffer newsrcbuf)
702 (while tem
703 (setq group (assoc (car tem) news-group-article-assoc))
704 (if (= (news-cadr (news-cadr group)) (news-caddr (news-cadr group)))
705 nil
706 (goto-char 0)
707 (if (search-forward (concat (car group) ": ") nil t)
708 (kill-line nil)
709 (insert (car group) ": \n") (backward-char 1))
710 (insert (int-to-string (car (news-cadr group))) "-"
711 (int-to-string (news-cadr (news-cadr group)))))
712 (setq tem (cdr tem)))
713 (while news-unsubscribe-groups
714 (setq group (assoc (car news-unsubscribe-groups)
715 news-group-article-assoc))
716 (goto-char 0)
717 (if (search-forward (concat (car group) ": ") nil t)
718 (progn
719 (backward-char 2)
720 (kill-line nil)
721 (insert "! " (int-to-string (car (news-cadr group)))
722 "-" (int-to-string (news-cadr (news-cadr group))))))
723 (setq news-unsubscribe-groups (cdr news-unsubscribe-groups)))
724 (save-buffer)
725 (kill-buffer (current-buffer)))))
726
727
728 (defun news-unsubscribe-group (group)
729 "Removes you from newgroup GROUP."
730 (interactive (list (completing-read "Unsubscribe from group: "
731 news-group-article-assoc)))
732 (news-unsubscribe-internal group))
733
734 (defun news-unsubscribe-current-group ()
735 "Removes you from the newsgroup you are now reading."
736 (interactive)
737 (if (y-or-n-p "Do you really want to unsubscribe from this group ? ")
738 (news-unsubscribe-internal news-current-news-group)))
739
740 (defun news-unsubscribe-internal (group)
741 (let ((tem (assoc group news-group-article-assoc)))
742 (if tem
743 (progn
744 (setq news-unsubscribe-groups (cons group news-unsubscribe-groups))
745 (news-update-message-read group (news-cdar news-point-pdl))
746 (if (equal group news-current-news-group)
747 (news-next-group))
748 (message ""))
749 (error "Not subscribed to group: %s" group))))
750
751 (defun news-save-item-in-file (file)
752 "Save the current article that is being read by appending to a file."
753 (interactive "FSave item in file: ")
754 (append-to-file (point-min) (point-max) file))
755
756 (defun news-get-pruned-list-of-files (gp-list end-file-no)
757 "Given a news group it finds all files in the news group.
758 The arg must be in slashified format.
759 Using ls was found to be too slow in a previous version."
760 (let
761 ((answer
762 (and
763 (not (and end-file-no
764 (equal (news-set-current-certifiable)
765 (news-group-certification gp-list))
766 (setq news-list-of-files nil
767 news-list-of-files-possibly-bogus t)))
768 (let* ((file-directory (concat news-path
769 (string-subst-char ?/ ?. gp-list)))
770 tem
771 (last-winner
772 (and end-file-no
773 (news-wins file-directory end-file-no)
774 (news-find-first-or-last file-directory end-file-no 1))))
775 (setq news-list-of-files-possibly-bogus t news-list-of-files nil)
776 (if last-winner
777 (progn
778 (setq news-list-of-files-possibly-bogus t
779 news-current-group-end last-winner)
780 (while (> last-winner end-file-no)
781 (news-push last-winner news-list-of-files)
782 (setq last-winner (1- last-winner)))
783 news-list-of-files)
784 (if (or (not (file-directory-p file-directory))
785 (not (file-readable-p file-directory)))
786 nil
787 (setq news-list-of-files
788 (condition-case error
789 (directory-files file-directory)
790 (file-error
791 (if (string= (nth 2 error) "permission denied")
792 (message "Newsgroup %s is read-protected"
793 gp-list)
794 (signal 'file-error (cdr error)))
795 nil)))
796 (setq tem news-list-of-files)
797 (while tem
798 (if (or (not (string-match "^[0-9]*$" (car tem)))
799 ;; don't get confused by directories that look like numbers
800 (file-directory-p
801 (concat file-directory "/" (car tem)))
802 (<= (string-to-number (car tem)) end-file-no))
803 (setq news-list-of-files
804 (delq (car tem) news-list-of-files)))
805 (setq tem (cdr tem)))
806 (if (null news-list-of-files)
807 (progn (setq news-current-group-end 0)
808 nil)
809 (setq news-list-of-files
810 (mapcar 'string-to-number news-list-of-files))
811 (setq news-list-of-files (sort news-list-of-files '<))
812 (setq news-current-group-end
813 (elt news-list-of-files
814 (1- (length news-list-of-files))))
815 news-list-of-files)))))))
816 (or answer (progn (news-set-current-group-certification) nil))))
817
818 (defun news-read-files-into-buffer (group reversep)
819 (let* ((files-start-end (news-cadr (assoc group news-group-article-assoc)))
820 (start-file-no (car files-start-end))
821 (end-file-no (news-cadr files-start-end))
822 (buffer-read-only nil))
823 (setq news-current-news-group group)
824 (setq news-current-message-number nil)
825 (setq news-current-group-end nil)
826 (news-set-mode-line)
827 (news-get-pruned-list-of-files group end-file-no)
828 (news-set-mode-line)
829 ;; @@ should be a lot smarter than this if we have to move
830 ;; @@ around correctly.
831 (setq news-point-pdl (list (cons (car files-start-end)
832 (news-cadr files-start-end))))
833 (if (null news-list-of-files)
834 (progn (erase-buffer)
835 (setq news-current-group-end end-file-no)
836 (setq news-current-group-begin end-file-no)
837 (setq news-current-message-number end-file-no)
838 (news-set-mode-line)
839 ; (message "No new articles in " group " group.")
840 nil)
841 (setq news-current-group-begin (car news-list-of-files))
842 (if reversep
843 (setq news-current-message-number news-current-group-end)
844 (if (> (car news-list-of-files) end-file-no)
845 (setcdr (car news-point-pdl) (car news-list-of-files)))
846 (setq news-current-message-number news-current-group-begin))
847 (news-set-message-counters)
848 (news-set-mode-line)
849 (news-read-in-file (concat news-path
850 (string-subst-char ?/ ?. group)
851 "/"
852 (int-to-string
853 news-current-message-number)))
854 (news-set-message-counters)
855 (news-set-mode-line)
856 t)))
857
858 (defun news-add-news-group (gp)
859 "Resubscribe to or add a USENET news group named GROUP (a string)."
860 ; @@ (completing-read ...)
861 ; @@ could be based on news library file ../active (slightly fascist)
862 ; @@ or (expensive to compute) all directories under the news spool directory
863 (interactive "sAdd news group: ")
864 (let ((file-dir (concat news-path (string-subst-char ?/ ?. gp))))
865 (save-excursion
866 (if (null (assoc gp news-group-article-assoc))
867 (let ((newsrcbuf (find-file-noselect
868 (substitute-in-file-name news-startup-file))))
869 (if (file-directory-p file-dir)
870 (progn
871 (switch-to-buffer newsrcbuf)
872 (goto-char 0)
873 (if (search-forward (concat gp "! ") nil t)
874 (progn
875 (message "Re-subscribing to group %s." gp)
876 ;;@@ news-unsubscribe-groups isn't being used
877 ;;(setq news-unsubscribe-groups
878 ;; (delq gp news-unsubscribe-groups))
879 (backward-char 2)
880 (delete-char 1)
881 (insert ":"))
882 (progn
883 (message
884 "Added %s to your list of newsgroups." gp)
885 (goto-char (point-max))
886 (insert gp ": 1-1\n")))
887 (search-backward gp nil t)
888 (let (start end endofline tem)
889 (search-forward ": " nil t)
890 (setq end (point))
891 (beginning-of-line)
892 (setq start (point))
893 (end-of-line)
894 (setq endofline (point))
895 (setq tem (buffer-substring start (- end 2)))
896 (let ((range (news-parse-range
897 (buffer-substring end endofline))))
898 (setq news-group-article-assoc
899 (cons (list tem (list (car range)
900 (cdr range)
901 (cdr range)))
902 news-group-article-assoc))))
903 (save-buffer)
904 (kill-buffer (current-buffer)))
905 (message "Newsgroup %s doesn't exist." gp)))
906 (message "Already subscribed to group %s." gp)))))
907
908 (defun news-make-link-to-message (number newname)
909 "Forges a link to an rnews message numbered number (current if no arg)
910 Good for hanging on to a message that might or might not be
911 automatically deleted."
912 (interactive "P
913 FName to link to message: ")
914 (add-name-to-file
915 (concat news-path
916 (string-subst-char ?/ ?. news-current-news-group)
917 "/" (if number
918 (prefix-numeric-value number)
919 news-current-message-number))
920 newname))
921
922 ;;; caesar-region written by phr@gnu.org Nov 86
923 ;;; modified by tower@gnu.org Nov 86
924 (defun caesar-region (&optional n)
925 "Caesar rotation of region by N, default 13, for decrypting netnews."
926 (interactive (if current-prefix-arg ; Was there a prefix arg?
927 (list (prefix-numeric-value current-prefix-arg))
928 (list nil)))
929 (cond ((not (numberp n)) (setq n 13))
930 (t (setq n (mod n 26)))) ;canonicalize N
931 (if (not (zerop n)) ; no action needed for a rot of 0
932 (progn
933 (if (or (not (boundp 'caesar-translate-table))
934 (/= (aref caesar-translate-table ?a) (+ ?a n)))
935 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
936 (message "Building caesar-translate-table...")
937 (setq caesar-translate-table (make-vector 256 0))
938 (while (< i 256)
939 (aset caesar-translate-table i i)
940 (setq i (1+ i)))
941 (setq lower (concat lower lower) upper (upcase lower) i 0)
942 (while (< i 26)
943 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
944 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
945 (setq i (1+ i)))
946 (message "Building caesar-translate-table... done")))
947 (let ((from (region-beginning))
948 (to (region-end))
949 (i 0) str len)
950 (setq str (buffer-substring from to))
951 (setq len (length str))
952 (while (< i len)
953 (aset str i (aref caesar-translate-table (aref str i)))
954 (setq i (1+ i)))
955 (goto-char from)
956 (kill-region from to)
957 (insert str)))))
958
959 ;;; news-caesar-buffer-body written by paul@media-lab.mit.edu Wed Oct 1, 1986
960 ;;; hacked further by tower@gnu.org
961 (defun news-caesar-buffer-body (&optional rotnum)
962 "Caesar rotates all letters in the current buffer by 13 places.
963 Used to encode/decode possibly offensive messages (commonly in net.jokes).
964 With prefix arg, specifies the number of places to rotate each letter forward.
965 Mail and USENET news headers are not rotated."
966 (interactive (if current-prefix-arg ; Was there a prefix arg?
967 (list (prefix-numeric-value current-prefix-arg))
968 (list nil)))
969 (save-excursion
970 (let ((buffer-status buffer-read-only))
971 (setq buffer-read-only nil)
972 ;; setup the region
973 (set-mark (if (equal major-mode 'news-mode)
974 (progn (goto-char (point-min))
975 (search-forward "\n\n" nil t))
976 (mail-text-start)))
977 (goto-char (point-max))
978 (caesar-region rotnum)
979 (setq buffer-read-only buffer-status))))
980
981 (provide 'rnews)
982
983 ;; arch-tag: c032a20b-cafb-466c-b3fa-5be404a18f8c
984 ;;; rnews.el ends here