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