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