Mercurial > emacs
annotate lisp/mail/rnews.el @ 9575:ff5a8ffc542c
Add support for AIX 4.1 and architecture.
author | Richard Kenner <kenner@gnu.org> |
---|---|
date | Mon, 17 Oct 1994 23:16:35 +0000 |
parents | 3e97c809ace1 |
children | 187735b53d52 |
rev | line source |
---|---|
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; rnews.el --- USENET news reader for gnu emacs |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc. |
4 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
5 ;; Maintainer: FSF |
814
38b2499cb3e9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
6 ;; Keywords: news |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
7 |
35 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
35 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
24 ;;; Change Log: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
25 |
35 | 26 ;; Created Sun Mar 10,1985 at 21:35:01 ads and sundar@hernes.ai.mit.edu |
27 ;; Should do the point pdl stuff sometime | |
28 ;; finito except pdl.... Sat Mar 16,1985 at 06:43:44 | |
29 ;; lets keep the summary stuff out until we get it working .. | |
30 ;; sundar@hermes.ai.mit.edu Wed Apr 10,1985 at 16:32:06 | |
31 ;; hack slash maim. mly@prep.ai.mit.edu Thu 18 Apr, 1985 06:11:14 | |
32 ;; modified to correct reentrance bug, to not bother with groups that | |
33 ;; received no new traffic since last read completely, to find out | |
34 ;; what traffic a group has available much more quickly when | |
35 ;; possible, to do some completing reads for group names - should | |
36 ;; be much faster... | |
37 ;; KING@KESTREL.arpa, Thu Mar 13 09:03:28 1986 | |
38 ;; made news-{next,previous}-group skip groups with no new messages; and | |
39 ;; added checking for unsubscribed groups to news-add-news-group | |
40 ;; tower@prep.ai.mit.edu Jul 18 1986 | |
41 ;; bound rmail-output to C-o; and changed header-field commands binding to | |
42 ;; agree with the new C-c C-f usage in sendmail | |
43 ;; tower@prep Sep 3 1986 | |
44 ;; added news-rotate-buffer-body | |
45 ;; tower@prep Oct 17 1986 | |
46 ;; made messages more user friendly, cleanuped news-inews | |
47 ;; move posting and mail code to new file rnewpost.el | |
48 ;; tower@prep Oct 29 1986 | |
49 ;; added caesar-region, rename news-caesar-buffer-body, hacked accordingly | |
50 ;; tower@prep Nov 21 1986 | |
584 | 51 ;; added tower@prep 22 Apr 87 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
52 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
53 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
54 |
35 | 55 (require 'mail-utils) |
56 | |
57 (autoload 'rmail-output "rmailout" | |
58 "Append this message to Unix mail file named FILE-NAME." | |
59 t) | |
60 | |
61 (autoload 'news-reply "rnewspost" | |
62 "Compose and post a reply to the current article on USENET. | |
63 While composing the reply, use \\[mail-yank-original] to yank the original | |
64 message into it." | |
65 t) | |
66 | |
67 (autoload 'news-mail-other-window "rnewspost" | |
68 "Send mail in another window. | |
69 While composing the message, use \\[mail-yank-original] to yank the | |
70 original message into it." | |
71 t) | |
72 | |
73 (autoload 'news-post-news "rnewspost" | |
74 "Begin editing a new USENET news article to be posted." | |
75 t) | |
76 | |
77 (autoload 'news-mail-reply "rnewspost" | |
78 "Mail a reply to the author of the current article. | |
79 While composing the reply, use \\[mail-yank-original] to yank the original | |
80 message into it." | |
81 t) | |
82 | |
83 (defvar news-group-hook-alist nil | |
84 "Alist of (GROUP-REGEXP . HOOK) pairs. | |
85 Just before displaying a message, each HOOK is called | |
86 if its GROUP-REGEXP matches the current newsgroup name.") | |
87 | |
88 (defvar rmail-last-file (expand-file-name "~/mbox.news")) | |
89 | |
90 ;Now in paths.el. | |
91 ;(defvar news-path "/usr/spool/news/" | |
92 ; "The root directory below which all news files are stored.") | |
93 | |
94 (defvar news-startup-file "$HOME/.newsrc" "Contains ~/.newsrc") | |
95 (defvar news-certification-file "$HOME/.news-dates" "Contains ~/.news-dates") | |
96 | |
97 ;; random headers that we decide to ignore. | |
98 (defvar news-ignored-headers | |
99 "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:" | |
100 "All random fields within the header of a message.") | |
101 | |
102 (defvar news-mode-map nil) | |
103 (defvar news-read-first-time-p t) | |
104 ;; Contains the (dotified) news groups of which you are a member. | |
105 (defvar news-user-group-list nil) | |
106 | |
107 (defvar news-current-news-group nil) | |
108 (defvar news-current-group-begin nil) | |
109 (defvar news-current-group-end nil) | |
110 (defvar news-current-certifications nil | |
111 "An assoc list of a group name and the time at which it is | |
112 known that the group had no new traffic") | |
113 (defvar news-current-certifiable nil | |
114 "The time when the directory we are now working on was written") | |
115 | |
116 (defvar news-message-filter nil | |
117 "User specifiable filter function that will be called during | |
118 formatting of the news file") | |
119 | |
120 ;(defvar news-mode-group-string "Starting-Up" | |
121 ; "Mode line group name info is held in this variable") | |
122 (defvar news-list-of-files nil | |
123 "Global variable in which we store the list of files | |
124 associated with the current newsgroup") | |
125 (defvar news-list-of-files-possibly-bogus nil | |
126 "variable indicating we only are guessing at which files are available. | |
127 Not currently used.") | |
128 | |
129 ;; association list in which we store lists of the form | |
130 ;; (pointified-group-name (first last old-last)) | |
131 (defvar news-group-article-assoc nil) | |
132 | |
133 (defvar news-current-message-number 0 "Displayed Article Number") | |
134 (defvar news-total-current-group 0 "Total no of messages in group") | |
135 | |
136 (defvar news-unsubscribe-groups ()) | |
137 (defvar news-point-pdl () "List of visited news messages.") | |
138 (defvar news-no-jumps-p t) | |
139 (defvar news-buffer () "Buffer into which news files are read.") | |
140 | |
141 (defmacro news-push (item ref) | |
142 (list 'setq ref (list 'cons item ref))) | |
143 | |
144 (defmacro news-cadr (x) (list 'car (list 'cdr x))) | |
145 (defmacro news-cdar (x) (list 'cdr (list 'car x))) | |
146 (defmacro news-caddr (x) (list 'car (list 'cdr (list 'cdr x)))) | |
147 (defmacro news-cadar (x) (list 'car (list 'cdr (list 'car x)))) | |
148 (defmacro news-caadr (x) (list 'car (list 'car (list 'cdr x)))) | |
149 (defmacro news-cdadr (x) (list 'cdr (list 'car (list 'cdr x)))) | |
150 | |
151 (defmacro news-wins (pfx index) | |
152 (` (file-exists-p (concat (, pfx) "/" (int-to-string (, index)))))) | |
153 | |
154 (defvar news-max-plausible-gap 2 | |
155 "* In an rnews directory, the maximum possible gap size. | |
156 A gap is a sequence of missing messages between two messages that exist. | |
157 An empty file does not contribute to a gap -- it ends one.") | |
158 | |
159 (defun news-find-first-and-last (prefix base) | |
160 (and (news-wins prefix base) | |
161 (cons (news-find-first-or-last prefix base -1) | |
162 (news-find-first-or-last prefix base 1)))) | |
163 | |
164 (defmacro news-/ (a1 a2) | |
165 ;; a form of / that guarantees that (/ -1 2) = 0 | |
166 (if (zerop (/ -1 2)) | |
167 (` (/ (, a1) (, a2))) | |
168 (` (if (< (, a1) 0) | |
169 (- (/ (- (, a1)) (, a2))) | |
170 (/ (, a1) (, a2)))))) | |
171 | |
172 (defun news-find-first-or-last (pfx base dirn) | |
173 ;; first use powers of two to find a plausible ceiling | |
174 (let ((original-dir dirn)) | |
175 (while (news-wins pfx (+ base dirn)) | |
176 (setq dirn (* dirn 2))) | |
177 (setq dirn (news-/ dirn 2)) | |
178 ;; Then use a binary search to find the high water mark | |
179 (let ((offset (news-/ dirn 2))) | |
180 (while (/= offset 0) | |
181 (if (news-wins pfx (+ base dirn offset)) | |
182 (setq dirn (+ dirn offset))) | |
183 (setq offset (news-/ offset 2)))) | |
184 ;; If this high-water mark is bogus, recurse. | |
185 (let ((offset (* news-max-plausible-gap original-dir))) | |
186 (while (and (/= offset 0) (not (news-wins pfx (+ base dirn offset)))) | |
187 (setq offset (- offset original-dir))) | |
188 (if (= offset 0) | |
189 (+ base dirn) | |
190 (news-find-first-or-last pfx (+ base dirn offset) original-dir))))) | |
191 | |
192 (defun rnews () | |
193 "Read USENET news for groups for which you are a member and add or | |
194 delete groups. | |
195 You can reply to articles posted and send articles to any group. | |
196 | |
197 Type \\[describe-mode] once reading news to get a list of rnews commands." | |
198 (interactive) | |
199 (let ((last-buffer (buffer-name))) | |
200 (make-local-variable 'rmail-last-file) | |
201 (switch-to-buffer (setq news-buffer (get-buffer-create "*news*"))) | |
202 (news-mode) | |
203 (setq news-buffer-save last-buffer) | |
204 (setq buffer-read-only nil) | |
205 (erase-buffer) | |
206 (setq buffer-read-only t) | |
207 (set-buffer-modified-p t) | |
208 (sit-for 0) | |
209 (message "Getting new USENET news...") | |
210 (news-set-mode-line) | |
211 (news-get-certifications) | |
212 (news-get-new-news))) | |
213 | |
214 (defun news-group-certification (group) | |
215 (cdr-safe (assoc group news-current-certifications))) | |
216 | |
217 | |
218 (defun news-set-current-certifiable () | |
219 ;; Record the date that corresponds to the directory you are about to check | |
220 (let ((file (concat news-path | |
221 (string-subst-char ?/ ?. news-current-news-group)))) | |
222 (setq news-current-certifiable | |
223 (nth 5 (file-attributes | |
224 (or (file-symlink-p file) file)))))) | |
225 | |
226 (defun news-get-certifications () | |
227 ;; Read the certified-read file from last session | |
228 (save-excursion | |
229 (save-window-excursion | |
230 (setq news-current-certifications | |
231 (car-safe | |
232 (condition-case var | |
233 (let* | |
234 ((file (substitute-in-file-name news-certification-file)) | |
235 (buf (find-file-noselect file))) | |
236 (and (file-exists-p file) | |
237 (progn | |
238 (switch-to-buffer buf 'norecord) | |
239 (unwind-protect | |
240 (read-from-string (buffer-string)) | |
241 (kill-buffer buf))))) | |
242 (error nil))))))) | |
243 | |
244 (defun news-write-certifications () | |
245 ;; Write a certification file. | |
246 ;; This is an assoc list of group names with doubletons that represent | |
247 ;; mod times of the directory when group is read completely. | |
248 (save-excursion | |
249 (save-window-excursion | |
250 (with-output-to-temp-buffer | |
251 "*CeRtIfIcAtIoNs*" | |
252 (print news-current-certifications)) | |
253 (let ((buf (get-buffer "*CeRtIfIcAtIoNs*"))) | |
254 (switch-to-buffer buf) | |
255 (write-file (substitute-in-file-name news-certification-file)) | |
256 (kill-buffer buf))))) | |
257 | |
258 (defun news-set-current-group-certification () | |
259 (let ((cgc (assoc news-current-news-group news-current-certifications))) | |
260 (if cgc (setcdr cgc news-current-certifiable) | |
261 (news-push (cons news-current-news-group news-current-certifiable) | |
262 news-current-certifications)))) | |
263 | |
264 (defun news-set-minor-modes () | |
265 "Creates a minor mode list that has group name, total articles, | |
266 and attribute for current article." | |
267 (setq news-minor-modes (list (cons 'foo | |
268 (concat news-current-message-number | |
269 "/" | |
270 news-total-current-group | |
271 (news-get-attribute-string))))) | |
272 ;; Detect Emacs versions 18.16 and up, which display | |
273 ;; directly from news-minor-modes by using a list for mode-name. | |
274 (or (boundp 'minor-mode-alist) | |
275 (setq minor-modes news-minor-modes))) | |
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) | |
8571
ec740be1ce7b
(news-mode): Don't set mode-name to a list.
Richard M. Stallman <rms@gnu.org>
parents:
4515
diff
changeset
|
368 (setq mode-line-process '(news-minor-modes)) |
ec740be1ce7b
(news-mode): Don't set mode-name to a list.
Richard M. Stallman <rms@gnu.org>
parents:
4515
diff
changeset
|
369 (setq mode-name "NEWS") |
35 | 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-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-int (substring number-string 0 n)) | |
397 (string-to-int (substring number-string (1+ n)))) | |
398 (setq n (string-to-int 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-int arg))) | |
524 (let ((file (concat news-path | |
525 (string-subst-char ?/ ?. news-current-news-group) | |
526 "/" arg))) | |
8576
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
527 (if (= arg |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
528 (or (news-cadr (memq (news-cdar news-point-pdl) news-list-of-files)) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
529 0)) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
530 (setcdr (car news-point-pdl) arg)) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
531 (setq news-current-message-number arg) |
35 | 532 (if (file-exists-p file) |
8576
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
533 (let ((buffer-read-only nil)) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
534 (news-read-in-file file) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
535 (news-set-mode-line)) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
536 (news-set-mode-line) |
35 | 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 (and (fboundp 'bury-buffer) (bury-buffer (current-buffer))) | |
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 ;; dont get confused by directories that look like numbers | |
800 (file-directory-p | |
801 (concat file-directory "/" (car tem))) | |
802 (<= (string-to-int (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-int 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 facist) | |
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 (end-of-buffer) | |
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@prep.ai.mit.edu Nov 86 | |
923 ;;; modified by tower@prep 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)) | |
4515
85426a9911c0
Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
845
diff
changeset
|
930 (t (setq n (mod n 26)))) ;canonicalize N |
35 | 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@prep.ai.mit.edu | |
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 (progn (goto-char (point-min)) | |
974 (search-forward | |
975 (concat "\n" | |
976 (if (equal major-mode 'news-mode) | |
977 "" | |
978 mail-header-separator) | |
979 "\n") nil t)) | |
980 (point) | |
981 (point-min))) | |
982 (goto-char (point-max)) | |
983 (caesar-region rotnum) | |
984 (setq buffer-read-only buffer-status)))) | |
584 | 985 |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
986 (provide 'rnews) |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
987 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
988 ;;; rnews.el ends here |