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