Mercurial > emacs
annotate lisp/mail/rnews.el @ 19905:9a4cdbf423ea
(viper-smart-suffix-list): Fix customize type.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 13 Sep 1997 06:11:09 +0000 |
parents | 83f275dcd93a |
children | 440d5927ef18 |
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 | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
35 | 24 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
25 ;;; Change Log: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
26 |
35 | 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 | |
14040 | 47 ;; made messages more user friendly, cleaned up news-inews |
35 | 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 | |
584 | 52 ;; added tower@prep 22 Apr 87 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
53 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
54 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
658
diff
changeset
|
55 |
35 | 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) | |
8571
ec740be1ce7b
(news-mode): Don't set mode-name to a list.
Richard M. Stallman <rms@gnu.org>
parents:
4515
diff
changeset
|
369 (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
|
370 (setq mode-name "NEWS") |
35 | 371 (news-set-mode-line) |
372 (set-syntax-table text-mode-syntax-table) | |
373 (use-local-map news-mode-map) | |
374 (setq local-abbrev-table text-mode-abbrev-table) | |
375 (run-hooks 'news-mode-hook)) | |
376 | |
377 (defun string-subst-char (new old string) | |
378 (let (index) | |
379 (setq old (regexp-quote (char-to-string old)) | |
380 string (substring string 0)) | |
381 (while (setq index (string-match old string)) | |
382 (aset string index new))) | |
383 string) | |
384 | |
385 ;; update read message number | |
386 (defmacro news-update-message-read (ngroup nno) | |
387 (list 'setcar | |
388 (list 'news-cdadr | |
389 (list 'assoc ngroup 'news-group-article-assoc)) | |
390 nno)) | |
391 | |
392 (defun news-parse-range (number-string) | |
393 "Parse string representing range of numbers of he form <a>-<b> | |
394 to a list (a . b)" | |
395 (let ((n (string-match "-" number-string))) | |
396 (if n | |
397 (cons (string-to-int (substring number-string 0 n)) | |
398 (string-to-int (substring number-string (1+ n)))) | |
399 (setq n (string-to-int number-string)) | |
400 (cons n n)))) | |
401 | |
402 ;(defun is-in (elt lis) | |
403 ; (catch 'foo | |
404 ; (while lis | |
405 ; (if (equal (car lis) elt) | |
406 ; (throw 'foo t) | |
407 ; (setq lis (cdr lis)))))) | |
408 | |
409 (defun news-get-new-news () | |
410 "Get new USENET news, if there is any for the current user." | |
411 (interactive) | |
412 (if (not (null news-user-group-list)) | |
413 (news-update-newsrc-file)) | |
414 (setq news-group-article-assoc ()) | |
415 (setq news-user-group-list ()) | |
416 (message "Looking up %s file..." news-startup-file) | |
417 (let ((file (substitute-in-file-name news-startup-file)) | |
418 (temp-user-groups ())) | |
419 (save-excursion | |
420 (let ((newsrcbuf (find-file-noselect file)) | |
421 start end endofline tem) | |
422 (set-buffer newsrcbuf) | |
423 (goto-char 0) | |
424 (while (search-forward ": " nil t) | |
425 (setq end (point)) | |
426 (beginning-of-line) | |
427 (setq start (point)) | |
428 (end-of-line) | |
429 (setq endofline (point)) | |
430 (setq tem (buffer-substring start (- end 2))) | |
431 (let ((range (news-parse-range | |
432 (buffer-substring end endofline)))) | |
433 (if (assoc tem news-group-article-assoc) | |
434 (message "You are subscribed twice to %s; I ignore second" | |
435 tem) | |
436 (setq temp-user-groups (cons tem temp-user-groups) | |
437 news-group-article-assoc | |
438 (cons (list tem (list (car range) | |
439 (cdr range) | |
440 (cdr range))) | |
441 news-group-article-assoc))))) | |
442 (kill-buffer newsrcbuf))) | |
443 (setq temp-user-groups (nreverse temp-user-groups)) | |
444 (message "Prefrobnicating...") | |
445 (switch-to-buffer news-buffer) | |
446 (setq news-user-group-list temp-user-groups) | |
447 (while (and temp-user-groups | |
448 (not (news-read-files-into-buffer | |
449 (car temp-user-groups) nil))) | |
450 (setq temp-user-groups (cdr temp-user-groups))) | |
451 (if (null temp-user-groups) | |
452 (message "No news is good news.") | |
453 (message "")))) | |
454 | |
455 (defun news-list-news-groups () | |
456 "Display all the news groups to which you belong." | |
457 (interactive) | |
458 (with-output-to-temp-buffer "*Newsgroups*" | |
459 (save-excursion | |
460 (set-buffer standard-output) | |
461 (insert | |
462 "News Group Msg No. News Group Msg No.\n") | |
463 (insert | |
464 "------------------------- -------------------------\n") | |
465 (let ((temp news-user-group-list) | |
466 (flag nil)) | |
467 (while temp | |
468 (let ((item (assoc (car temp) news-group-article-assoc))) | |
469 (insert (car item)) | |
470 (indent-to (if flag 52 20)) | |
471 (insert (int-to-string (news-cadr (news-cadr item)))) | |
472 (if flag | |
473 (insert "\n") | |
474 (indent-to 33)) | |
475 (setq temp (cdr temp) flag (not flag)))))))) | |
476 | |
477 ;; Mode line hack | |
478 (defun news-set-mode-line () | |
479 "Set mode line string to something useful." | |
480 (setq mode-line-process | |
481 (concat " " | |
482 (if (integerp news-current-message-number) | |
483 (int-to-string news-current-message-number) | |
484 "??") | |
485 "/" | |
486 (if (integerp news-current-group-end) | |
487 (int-to-string news-current-group-end) | |
488 news-current-group-end))) | |
489 (setq mode-line-buffer-identification | |
490 (concat "NEWS: " | |
491 news-current-news-group | |
492 ;; Enough spaces to pad group name to 17 positions. | |
493 (substring " " | |
494 0 (max 0 (- 17 (length news-current-news-group)))))) | |
495 (set-buffer-modified-p t) | |
496 (sit-for 0)) | |
497 | |
498 (defun news-goto-news-group (gp) | |
499 "Takes a string and goes to that news group." | |
500 (interactive (list (completing-read "NewsGroup: " | |
501 news-group-article-assoc))) | |
502 (message "Jumping to news group %s..." gp) | |
503 (news-select-news-group gp) | |
504 (message "Jumping to news group %s... done." gp)) | |
505 | |
506 (defun news-select-news-group (gp) | |
507 (let ((grp (assoc gp news-group-article-assoc))) | |
508 (if (null grp) | |
509 (error "Group %s not subscribed to" gp) | |
510 (progn | |
511 (news-update-message-read news-current-news-group | |
512 (news-cdar news-point-pdl)) | |
513 (news-read-files-into-buffer (car grp) nil) | |
514 (news-set-mode-line))))) | |
515 | |
516 (defun news-goto-message (arg) | |
517 "Goes to the article ARG in current newsgroup." | |
518 (interactive "p") | |
519 (if (null current-prefix-arg) | |
520 (setq arg (read-no-blanks-input "Go to article: " ""))) | |
521 (news-select-message arg)) | |
522 | |
523 (defun news-select-message (arg) | |
524 (if (stringp arg) (setq arg (string-to-int arg))) | |
525 (let ((file (concat news-path | |
526 (string-subst-char ?/ ?. news-current-news-group) | |
527 "/" arg))) | |
8576
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
528 (if (= arg |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
529 (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
|
530 0)) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
531 (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
|
532 (setq news-current-message-number arg) |
35 | 533 (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
|
534 (let ((buffer-read-only nil)) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
535 (news-read-in-file file) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
536 (news-set-mode-line)) |
3e97c809ace1
(news-select-message): Do most of the work
Richard M. Stallman <rms@gnu.org>
parents:
8571
diff
changeset
|
537 (news-set-mode-line) |
35 | 538 (error "Article %d nonexistent" arg)))) |
539 | |
540 (defun news-force-update () | |
541 "updates the position of last article read in the current news group" | |
542 (interactive) | |
543 (setcdr (car news-point-pdl) news-current-message-number) | |
544 (message "Updated to %d" news-current-message-number)) | |
545 | |
546 (defun news-next-message (arg) | |
547 "Move ARG messages forward within one newsgroup. | |
548 Negative ARG moves backward. | |
549 If ARG is 1 or -1, moves to next or previous newsgroup if at end." | |
550 (interactive "p") | |
551 (let ((no (+ arg news-current-message-number))) | |
552 (if (or (< no news-current-group-begin) | |
553 (> no news-current-group-end)) | |
554 (cond ((= arg 1) | |
555 (news-set-current-group-certification) | |
556 (news-next-group)) | |
557 ((= arg -1) | |
558 (news-previous-group)) | |
559 (t (error "Article out of range"))) | |
560 (let ((plist (news-get-motion-lists | |
561 news-current-message-number | |
562 news-list-of-files))) | |
563 (if (< arg 0) | |
564 (news-select-message (nth (1- (- arg)) (car (cdr plist)))) | |
565 (news-select-message (nth (1- arg) (car plist)))))))) | |
566 | |
567 (defun news-previous-message (arg) | |
568 "Move ARG messages backward in current newsgroup. | |
569 With no arg or arg of 1, move one message | |
570 and move to previous newsgroup if at beginning. | |
571 A negative ARG means move forward." | |
572 (interactive "p") | |
573 (news-next-message (- arg))) | |
574 | |
575 (defun news-move-to-group (arg) | |
576 "Given arg move forward or backward to a new newsgroup." | |
577 (let ((cg news-current-news-group)) | |
578 (let ((plist (news-get-motion-lists cg news-user-group-list)) | |
579 ngrp) | |
580 (if (< arg 0) | |
581 (or (setq ngrp (nth (1- (- arg)) (news-cadr plist))) | |
582 (error "No previous news groups")) | |
583 (or (setq ngrp (nth arg (car plist))) | |
584 (error "No more news groups"))) | |
585 (news-select-news-group ngrp)))) | |
586 | |
587 (defun news-next-group () | |
588 "Moves to the next user group." | |
589 (interactive) | |
590 ; (message "Moving to next group...") | |
591 (news-move-to-group 0) | |
592 (while (null news-list-of-files) | |
593 (news-move-to-group 0))) | |
594 ; (message "Moving to next group... done.") | |
595 | |
596 (defun news-previous-group () | |
597 "Moves to the previous user group." | |
598 (interactive) | |
599 ; (message "Moving to previous group...") | |
600 (news-move-to-group -1) | |
601 (while (null news-list-of-files) | |
602 (news-move-to-group -1))) | |
603 ; (message "Moving to previous group... done.") | |
604 | |
605 (defun news-get-motion-lists (arg listy) | |
606 "Given a msgnumber/group this will return a list of two lists; | |
607 one for moving forward and one for moving backward." | |
608 (let ((temp listy) | |
609 (result ())) | |
610 (catch 'out | |
611 (while temp | |
612 (if (equal (car temp) arg) | |
613 (throw 'out (cons (cdr temp) (list result))) | |
614 (setq result (nconc (list (car temp)) result)) | |
615 (setq temp (cdr temp))))))) | |
616 | |
617 ;; miscellaneous io routines | |
618 (defun news-read-in-file (filename) | |
619 (erase-buffer) | |
620 (let ((start (point))) | |
621 (insert-file-contents filename) | |
622 (news-convert-format) | |
623 ;; Run each hook that applies to the current newsgroup. | |
624 (let ((hooks news-group-hook-alist)) | |
625 (while hooks | |
626 (goto-char start) | |
627 (if (string-match (car (car hooks)) news-group-name) | |
628 (funcall (cdr (car hooks)))) | |
629 (setq hooks (cdr hooks)))) | |
630 (goto-char start) | |
631 (forward-line 1) | |
632 (if (eobp) | |
633 (message "(Empty file?)") | |
634 (goto-char start)))) | |
635 | |
636 (defun news-convert-format () | |
637 (save-excursion | |
638 (save-restriction | |
639 (let* ((start (point)) | |
640 (end (condition-case () | |
641 (progn (search-forward "\n\n") (point)) | |
642 (error nil))) | |
643 has-from has-date) | |
644 (cond (end | |
645 (narrow-to-region start end) | |
646 (goto-char start) | |
647 (setq has-from (search-forward "\nFrom:" nil t)) | |
648 (cond ((and (not has-from) has-date) | |
649 (goto-char start) | |
650 (search-forward "\nDate:") | |
651 (beginning-of-line) | |
652 (kill-line) (kill-line))) | |
653 (news-delete-headers start) | |
654 (goto-char start))))))) | |
655 | |
656 (defun news-show-all-headers () | |
657 "Redisplay current news item with all original headers" | |
658 (interactive) | |
659 (let (news-ignored-headers | |
660 (buffer-read-only ())) | |
661 (erase-buffer) | |
662 (news-set-mode-line) | |
663 (news-read-in-file | |
664 (concat news-path | |
665 (string-subst-char ?/ ?. news-current-news-group) | |
666 "/" (int-to-string news-current-message-number))))) | |
667 | |
668 (defun news-delete-headers (pos) | |
669 (goto-char pos) | |
670 (and (stringp news-ignored-headers) | |
671 (while (re-search-forward news-ignored-headers nil t) | |
672 (beginning-of-line) | |
673 (delete-region (point) | |
674 (progn (re-search-forward "\n[^ \t]") | |
675 (forward-char -1) | |
676 (point)))))) | |
677 | |
678 (defun news-exit () | |
679 "Quit news reading session and update the .newsrc file." | |
680 (interactive) | |
681 (if (y-or-n-p "Do you really wanna quit reading news ? ") | |
682 (progn (message "Updating %s..." news-startup-file) | |
683 (news-update-newsrc-file) | |
684 (news-write-certifications) | |
685 (message "Updating %s... done" news-startup-file) | |
686 (message "Now do some real work") | |
687 (and (fboundp 'bury-buffer) (bury-buffer (current-buffer))) | |
688 (switch-to-buffer news-buffer-save) | |
689 (setq news-user-group-list ())) | |
690 (message ""))) | |
691 | |
692 (defun news-update-newsrc-file () | |
693 "Updates the .newsrc file in the users home dir." | |
694 (let ((newsrcbuf (find-file-noselect | |
695 (substitute-in-file-name news-startup-file))) | |
696 (tem news-user-group-list) | |
697 group) | |
698 (save-excursion | |
699 (if (not (null news-current-news-group)) | |
700 (news-update-message-read news-current-news-group | |
701 (news-cdar news-point-pdl))) | |
702 (set-buffer newsrcbuf) | |
703 (while tem | |
704 (setq group (assoc (car tem) news-group-article-assoc)) | |
705 (if (= (news-cadr (news-cadr group)) (news-caddr (news-cadr group))) | |
706 nil | |
707 (goto-char 0) | |
708 (if (search-forward (concat (car group) ": ") nil t) | |
709 (kill-line nil) | |
710 (insert (car group) ": \n") (backward-char 1)) | |
711 (insert (int-to-string (car (news-cadr group))) "-" | |
712 (int-to-string (news-cadr (news-cadr group))))) | |
713 (setq tem (cdr tem))) | |
714 (while news-unsubscribe-groups | |
715 (setq group (assoc (car news-unsubscribe-groups) | |
716 news-group-article-assoc)) | |
717 (goto-char 0) | |
718 (if (search-forward (concat (car group) ": ") nil t) | |
719 (progn | |
720 (backward-char 2) | |
721 (kill-line nil) | |
722 (insert "! " (int-to-string (car (news-cadr group))) | |
723 "-" (int-to-string (news-cadr (news-cadr group)))))) | |
724 (setq news-unsubscribe-groups (cdr news-unsubscribe-groups))) | |
725 (save-buffer) | |
726 (kill-buffer (current-buffer))))) | |
727 | |
728 | |
729 (defun news-unsubscribe-group (group) | |
730 "Removes you from newgroup GROUP." | |
731 (interactive (list (completing-read "Unsubscribe from group: " | |
732 news-group-article-assoc))) | |
733 (news-unsubscribe-internal group)) | |
734 | |
735 (defun news-unsubscribe-current-group () | |
736 "Removes you from the newsgroup you are now reading." | |
737 (interactive) | |
738 (if (y-or-n-p "Do you really want to unsubscribe from this group ? ") | |
739 (news-unsubscribe-internal news-current-news-group))) | |
740 | |
741 (defun news-unsubscribe-internal (group) | |
742 (let ((tem (assoc group news-group-article-assoc))) | |
743 (if tem | |
744 (progn | |
745 (setq news-unsubscribe-groups (cons group news-unsubscribe-groups)) | |
746 (news-update-message-read group (news-cdar news-point-pdl)) | |
747 (if (equal group news-current-news-group) | |
748 (news-next-group)) | |
749 (message "")) | |
750 (error "Not subscribed to group: %s" group)))) | |
751 | |
752 (defun news-save-item-in-file (file) | |
753 "Save the current article that is being read by appending to a file." | |
754 (interactive "FSave item in file: ") | |
755 (append-to-file (point-min) (point-max) file)) | |
756 | |
757 (defun news-get-pruned-list-of-files (gp-list end-file-no) | |
758 "Given a news group it finds all files in the news group. | |
759 The arg must be in slashified format. | |
760 Using ls was found to be too slow in a previous version." | |
761 (let | |
762 ((answer | |
763 (and | |
764 (not (and end-file-no | |
765 (equal (news-set-current-certifiable) | |
766 (news-group-certification gp-list)) | |
767 (setq news-list-of-files nil | |
768 news-list-of-files-possibly-bogus t))) | |
769 (let* ((file-directory (concat news-path | |
770 (string-subst-char ?/ ?. gp-list))) | |
771 tem | |
772 (last-winner | |
773 (and end-file-no | |
774 (news-wins file-directory end-file-no) | |
775 (news-find-first-or-last file-directory end-file-no 1)))) | |
776 (setq news-list-of-files-possibly-bogus t news-list-of-files nil) | |
777 (if last-winner | |
778 (progn | |
779 (setq news-list-of-files-possibly-bogus t | |
780 news-current-group-end last-winner) | |
781 (while (> last-winner end-file-no) | |
782 (news-push last-winner news-list-of-files) | |
783 (setq last-winner (1- last-winner))) | |
784 news-list-of-files) | |
785 (if (or (not (file-directory-p file-directory)) | |
786 (not (file-readable-p file-directory))) | |
787 nil | |
788 (setq news-list-of-files | |
789 (condition-case error | |
790 (directory-files file-directory) | |
791 (file-error | |
792 (if (string= (nth 2 error) "permission denied") | |
793 (message "Newsgroup %s is read-protected" | |
794 gp-list) | |
795 (signal 'file-error (cdr error))) | |
796 nil))) | |
797 (setq tem news-list-of-files) | |
798 (while tem | |
799 (if (or (not (string-match "^[0-9]*$" (car tem))) | |
14040 | 800 ;; don't get confused by directories that look like numbers |
35 | 801 (file-directory-p |
802 (concat file-directory "/" (car tem))) | |
803 (<= (string-to-int (car tem)) end-file-no)) | |
804 (setq news-list-of-files | |
805 (delq (car tem) news-list-of-files))) | |
806 (setq tem (cdr tem))) | |
807 (if (null news-list-of-files) | |
808 (progn (setq news-current-group-end 0) | |
809 nil) | |
810 (setq news-list-of-files | |
811 (mapcar 'string-to-int news-list-of-files)) | |
812 (setq news-list-of-files (sort news-list-of-files '<)) | |
813 (setq news-current-group-end | |
814 (elt news-list-of-files | |
815 (1- (length news-list-of-files)))) | |
816 news-list-of-files))))))) | |
817 (or answer (progn (news-set-current-group-certification) nil)))) | |
818 | |
819 (defun news-read-files-into-buffer (group reversep) | |
820 (let* ((files-start-end (news-cadr (assoc group news-group-article-assoc))) | |
821 (start-file-no (car files-start-end)) | |
822 (end-file-no (news-cadr files-start-end)) | |
823 (buffer-read-only nil)) | |
824 (setq news-current-news-group group) | |
825 (setq news-current-message-number nil) | |
826 (setq news-current-group-end nil) | |
827 (news-set-mode-line) | |
828 (news-get-pruned-list-of-files group end-file-no) | |
829 (news-set-mode-line) | |
830 ;; @@ should be a lot smarter than this if we have to move | |
831 ;; @@ around correctly. | |
832 (setq news-point-pdl (list (cons (car files-start-end) | |
833 (news-cadr files-start-end)))) | |
834 (if (null news-list-of-files) | |
835 (progn (erase-buffer) | |
836 (setq news-current-group-end end-file-no) | |
837 (setq news-current-group-begin end-file-no) | |
838 (setq news-current-message-number end-file-no) | |
839 (news-set-mode-line) | |
840 ; (message "No new articles in " group " group.") | |
841 nil) | |
842 (setq news-current-group-begin (car news-list-of-files)) | |
843 (if reversep | |
844 (setq news-current-message-number news-current-group-end) | |
845 (if (> (car news-list-of-files) end-file-no) | |
846 (setcdr (car news-point-pdl) (car news-list-of-files))) | |
847 (setq news-current-message-number news-current-group-begin)) | |
848 (news-set-message-counters) | |
849 (news-set-mode-line) | |
850 (news-read-in-file (concat news-path | |
851 (string-subst-char ?/ ?. group) | |
852 "/" | |
853 (int-to-string | |
854 news-current-message-number))) | |
855 (news-set-message-counters) | |
856 (news-set-mode-line) | |
857 t))) | |
858 | |
859 (defun news-add-news-group (gp) | |
860 "Resubscribe to or add a USENET news group named GROUP (a string)." | |
861 ; @@ (completing-read ...) | |
14040 | 862 ; @@ could be based on news library file ../active (slightly fascist) |
35 | 863 ; @@ or (expensive to compute) all directories under the news spool directory |
864 (interactive "sAdd news group: ") | |
865 (let ((file-dir (concat news-path (string-subst-char ?/ ?. gp)))) | |
866 (save-excursion | |
867 (if (null (assoc gp news-group-article-assoc)) | |
868 (let ((newsrcbuf (find-file-noselect | |
869 (substitute-in-file-name news-startup-file)))) | |
870 (if (file-directory-p file-dir) | |
871 (progn | |
872 (switch-to-buffer newsrcbuf) | |
873 (goto-char 0) | |
874 (if (search-forward (concat gp "! ") nil t) | |
875 (progn | |
876 (message "Re-subscribing to group %s." gp) | |
877 ;;@@ news-unsubscribe-groups isn't being used | |
878 ;;(setq news-unsubscribe-groups | |
879 ;; (delq gp news-unsubscribe-groups)) | |
880 (backward-char 2) | |
881 (delete-char 1) | |
882 (insert ":")) | |
883 (progn | |
884 (message | |
885 "Added %s to your list of newsgroups." gp) | |
886 (end-of-buffer) | |
887 (insert gp ": 1-1\n"))) | |
888 (search-backward gp nil t) | |
889 (let (start end endofline tem) | |
890 (search-forward ": " nil t) | |
891 (setq end (point)) | |
892 (beginning-of-line) | |
893 (setq start (point)) | |
894 (end-of-line) | |
895 (setq endofline (point)) | |
896 (setq tem (buffer-substring start (- end 2))) | |
897 (let ((range (news-parse-range | |
898 (buffer-substring end endofline)))) | |
899 (setq news-group-article-assoc | |
900 (cons (list tem (list (car range) | |
901 (cdr range) | |
902 (cdr range))) | |
903 news-group-article-assoc)))) | |
904 (save-buffer) | |
905 (kill-buffer (current-buffer))) | |
906 (message "Newsgroup %s doesn't exist." gp))) | |
907 (message "Already subscribed to group %s." gp))))) | |
908 | |
909 (defun news-make-link-to-message (number newname) | |
910 "Forges a link to an rnews message numbered number (current if no arg) | |
911 Good for hanging on to a message that might or might not be | |
912 automatically deleted." | |
913 (interactive "P | |
914 FName to link to message: ") | |
915 (add-name-to-file | |
916 (concat news-path | |
917 (string-subst-char ?/ ?. news-current-news-group) | |
918 "/" (if number | |
919 (prefix-numeric-value number) | |
920 news-current-message-number)) | |
921 newname)) | |
922 | |
923 ;;; caesar-region written by phr@prep.ai.mit.edu Nov 86 | |
924 ;;; modified by tower@prep Nov 86 | |
925 (defun caesar-region (&optional n) | |
926 "Caesar rotation of region by N, default 13, for decrypting netnews." | |
927 (interactive (if current-prefix-arg ; Was there a prefix arg? | |
928 (list (prefix-numeric-value current-prefix-arg)) | |
929 (list nil))) | |
930 (cond ((not (numberp n)) (setq n 13)) | |
4515
85426a9911c0
Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents:
845
diff
changeset
|
931 (t (setq n (mod n 26)))) ;canonicalize N |
35 | 932 (if (not (zerop n)) ; no action needed for a rot of 0 |
933 (progn | |
934 (if (or (not (boundp 'caesar-translate-table)) | |
935 (/= (aref caesar-translate-table ?a) (+ ?a n))) | |
936 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper) | |
937 (message "Building caesar-translate-table...") | |
938 (setq caesar-translate-table (make-vector 256 0)) | |
939 (while (< i 256) | |
940 (aset caesar-translate-table i i) | |
941 (setq i (1+ i))) | |
942 (setq lower (concat lower lower) upper (upcase lower) i 0) | |
943 (while (< i 26) | |
944 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n))) | |
945 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n))) | |
946 (setq i (1+ i))) | |
947 (message "Building caesar-translate-table... done"))) | |
948 (let ((from (region-beginning)) | |
949 (to (region-end)) | |
950 (i 0) str len) | |
951 (setq str (buffer-substring from to)) | |
952 (setq len (length str)) | |
953 (while (< i len) | |
954 (aset str i (aref caesar-translate-table (aref str i))) | |
955 (setq i (1+ i))) | |
956 (goto-char from) | |
957 (kill-region from to) | |
958 (insert str))))) | |
959 | |
960 ;;; news-caesar-buffer-body written by paul@media-lab.mit.edu Wed Oct 1, 1986 | |
961 ;;; hacked further by tower@prep.ai.mit.edu | |
962 (defun news-caesar-buffer-body (&optional rotnum) | |
963 "Caesar rotates all letters in the current buffer by 13 places. | |
964 Used to encode/decode possibly offensive messages (commonly in net.jokes). | |
965 With prefix arg, specifies the number of places to rotate each letter forward. | |
966 Mail and USENET news headers are not rotated." | |
967 (interactive (if current-prefix-arg ; Was there a prefix arg? | |
968 (list (prefix-numeric-value current-prefix-arg)) | |
969 (list nil))) | |
970 (save-excursion | |
971 (let ((buffer-status buffer-read-only)) | |
972 (setq buffer-read-only nil) | |
973 ;; setup the region | |
974 (set-mark (if (progn (goto-char (point-min)) | |
975 (search-forward | |
976 (concat "\n" | |
977 (if (equal major-mode 'news-mode) | |
978 "" | |
979 mail-header-separator) | |
980 "\n") nil t)) | |
981 (point) | |
982 (point-min))) | |
983 (goto-char (point-max)) | |
984 (caesar-region rotnum) | |
985 (setq buffer-read-only buffer-status)))) | |
584 | 986 |
658
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
987 (provide 'rnews) |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
988 |
7cbd4fcd8b0f
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
989 ;;; rnews.el ends here |