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