35063
|
1 ;;; rnews.el --- USENET news reader for gnu emacs
|
|
2
|
|
3 ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: FSF
|
|
6 ;; Keywords: news
|
|
7
|
|
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
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
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 the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
|
24
|
|
25 ;;; Change Log:
|
|
26
|
|
27 ;; Created Sun Mar 10,1985 at 21:35:01 ads and sundar@hernes.ai.mit.edu
|
|
28 ;; Should do the point pdl stuff sometime
|
|
29 ;; finito except pdl.... Sat Mar 16,1985 at 06:43:44
|
|
30 ;; lets keep the summary stuff out until we get it working ..
|
|
31 ;; sundar@hermes.ai.mit.edu Wed Apr 10,1985 at 16:32:06
|
|
32 ;; hack slash maim. mly@gnu.org Thu 18 Apr, 1985 06:11:14
|
|
33 ;; modified to correct reentrance bug, to not bother with groups that
|
|
34 ;; received no new traffic since last read completely, to find out
|
|
35 ;; what traffic a group has available much more quickly when
|
|
36 ;; possible, to do some completing reads for group names - should
|
|
37 ;; be much faster...
|
|
38 ;; KING@KESTREL.arpa, Thu Mar 13 09:03:28 1986
|
|
39 ;; made news-{next,previous}-group skip groups with no new messages; and
|
|
40 ;; added checking for unsubscribed groups to news-add-news-group
|
|
41 ;; tower@gnu.org Jul 18 1986
|
|
42 ;; bound rmail-output to C-o; and changed header-field commands binding to
|
|
43 ;; agree with the new C-c C-f usage in sendmail
|
|
44 ;; tower@gnu.org Sep 3 1986
|
|
45 ;; added news-rotate-buffer-body
|
|
46 ;; tower@gnu.org Oct 17 1986
|
|
47 ;; made messages more user friendly, cleaned up news-inews
|
|
48 ;; move posting and mail code to new file rnewpost.el
|
|
49 ;; tower@gnu.org Oct 29 1986
|
|
50 ;; added caesar-region, rename news-caesar-buffer-body, hacked accordingly
|
|
51 ;; tower@gnu.org Nov 21 1986
|
|
52 ;; added tower@gnu.org 22 Apr 87
|
|
53
|
|
54 ;;; Code:
|
|
55
|
|
56 (require 'mail-utils)
|
|
57 (require 'sendmail)
|
|
58
|
|
59 (autoload 'rmail-output "rmailout"
|
|
60 "Append this message to Unix mail file named FILE-NAME."
|
|
61 t)
|
|
62
|
|
63 (autoload 'news-reply "rnewspost"
|
|
64 "Compose and post a reply to the current article on USENET.
|
|
65 While composing the reply, use \\[mail-yank-original] to yank the original
|
|
66 message into it."
|
|
67 t)
|
|
68
|
|
69 (autoload 'news-mail-other-window "rnewspost"
|
|
70 "Send mail in another window.
|
|
71 While composing the message, use \\[mail-yank-original] to yank the
|
|
72 original message into it."
|
|
73 t)
|
|
74
|
|
75 (autoload 'news-post-news "rnewspost"
|
|
76 "Begin editing a new USENET news article to be posted."
|
|
77 t)
|
|
78
|
|
79 (autoload 'news-mail-reply "rnewspost"
|
|
80 "Mail a reply to the author of the current article.
|
|
81 While composing the reply, use \\[mail-yank-original] to yank the original
|
|
82 message into it."
|
|
83 t)
|
|
84
|
|
85 (defvar news-group-hook-alist nil
|
|
86 "Alist of (GROUP-REGEXP . HOOK) pairs.
|
|
87 Just before displaying a message, each HOOK is called
|
|
88 if its GROUP-REGEXP matches the current newsgroup name.")
|
|
89
|
|
90 (defvar rmail-last-file (expand-file-name "~/mbox.news"))
|
|
91
|
|
92 ;Now in paths.el.
|
|
93 ;(defvar news-path "/usr/spool/news/"
|
|
94 ; "The root directory below which all news files are stored.")
|
|
95
|
|
96 (defvar news-startup-file "$HOME/.newsrc" "Contains ~/.newsrc")
|
|
97 (defvar news-certification-file "$HOME/.news-dates" "Contains ~/.news-dates")
|
|
98
|
|
99 ;; random headers that we decide to ignore.
|
|
100 (defvar news-ignored-headers
|
|
101 "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:"
|
|
102 "All random fields within the header of a message.")
|
|
103
|
|
104 (defvar news-mode-map nil)
|
|
105 (defvar news-read-first-time-p t)
|
|
106 ;; Contains the (dotified) news groups of which you are a member.
|
|
107 (defvar news-user-group-list nil)
|
|
108
|
|
109 (defvar news-current-news-group nil)
|
|
110 (defvar news-current-group-begin nil)
|
|
111 (defvar news-current-group-end nil)
|
|
112 (defvar news-current-certifications nil
|
|
113 "An assoc list of a group name and the time at which it is
|
|
114 known that the group had no new traffic")
|
|
115 (defvar news-current-certifiable nil
|
|
116 "The time when the directory we are now working on was written")
|
|
117
|
|
118 (defvar news-message-filter nil
|
|
119 "User specifiable filter function that will be called during
|
|
120 formatting of the news file")
|
|
121
|
|
122 ;(defvar news-mode-group-string "Starting-Up"
|
|
123 ; "Mode line group name info is held in this variable")
|
|
124 (defvar news-list-of-files nil
|
|
125 "Global variable in which we store the list of files
|
|
126 associated with the current newsgroup")
|
|
127 (defvar news-list-of-files-possibly-bogus nil
|
|
128 "variable indicating we only are guessing at which files are available.
|
|
129 Not currently used.")
|
|
130
|
|
131 ;; association list in which we store lists of the form
|
|
132 ;; (pointified-group-name (first last old-last))
|
|
133 (defvar news-group-article-assoc nil)
|
|
134
|
|
135 (defvar news-current-message-number 0 "Displayed Article Number")
|
|
136 (defvar news-total-current-group 0 "Total no of messages in group")
|
|
137
|
|
138 (defvar news-unsubscribe-groups ())
|
|
139 (defvar news-point-pdl () "List of visited news messages.")
|
|
140 (defvar news-no-jumps-p t)
|
|
141 (defvar news-buffer () "Buffer into which news files are read.")
|
|
142
|
|
143 (defmacro news-push (item ref)
|
|
144 (list 'setq ref (list 'cons item ref)))
|
|
145
|
|
146 (defmacro news-cadr (x) (list 'car (list 'cdr x)))
|
|
147 (defmacro news-cdar (x) (list 'cdr (list 'car x)))
|
|
148 (defmacro news-caddr (x) (list 'car (list 'cdr (list 'cdr x))))
|
|
149 (defmacro news-cadar (x) (list 'car (list 'cdr (list 'car x))))
|
|
150 (defmacro news-caadr (x) (list 'car (list 'car (list 'cdr x))))
|
|
151 (defmacro news-cdadr (x) (list 'cdr (list 'car (list 'cdr x))))
|
|
152
|
|
153 (defmacro news-wins (pfx index)
|
|
154 `(file-exists-p (concat ,pfx "/" (int-to-string ,index))))
|
|
155
|
|
156 (defvar news-max-plausible-gap 2
|
|
157 "* In an rnews directory, the maximum possible gap size.
|
|
158 A gap is a sequence of missing messages between two messages that exist.
|
|
159 An empty file does not contribute to a gap -- it ends one.")
|
|
160
|
|
161 (defun news-find-first-and-last (prefix base)
|
|
162 (and (news-wins prefix base)
|
|
163 (cons (news-find-first-or-last prefix base -1)
|
|
164 (news-find-first-or-last prefix base 1))))
|
|
165
|
|
166 (defmacro news-/ (a1 a2)
|
|
167 ;; a form of / that guarantees that (/ -1 2) = 0
|
|
168 (if (zerop (/ -1 2))
|
|
169 `(/ ,a1 ,a2)
|
|
170 `(if (< ,a1 0)
|
|
171 (- (/ (- ,a1) ,a2))
|
|
172 (/ ,a1 ,a2))))
|
|
173
|
|
174 (defun news-find-first-or-last (pfx base dirn)
|
|
175 ;; first use powers of two to find a plausible ceiling
|
|
176 (let ((original-dir dirn))
|
|
177 (while (news-wins pfx (+ base dirn))
|
|
178 (setq dirn (* dirn 2)))
|
|
179 (setq dirn (news-/ dirn 2))
|
|
180 ;; Then use a binary search to find the high water mark
|
|
181 (let ((offset (news-/ dirn 2)))
|
|
182 (while (/= offset 0)
|
|
183 (if (news-wins pfx (+ base dirn offset))
|
|
184 (setq dirn (+ dirn offset)))
|
|
185 (setq offset (news-/ offset 2))))
|
|
186 ;; If this high-water mark is bogus, recurse.
|
|
187 (let ((offset (* news-max-plausible-gap original-dir)))
|
|
188 (while (and (/= offset 0) (not (news-wins pfx (+ base dirn offset))))
|
|
189 (setq offset (- offset original-dir)))
|
|
190 (if (= offset 0)
|
|
191 (+ base dirn)
|
|
192 (news-find-first-or-last pfx (+ base dirn offset) original-dir)))))
|
|
193
|
|
194 (defun rnews ()
|
|
195 "Read USENET news for groups for which you are a member and add or
|
|
196 delete groups.
|
|
197 You can reply to articles posted and send articles to any group.
|
|
198
|
|
199 Type \\[describe-mode] once reading news to get a list of rnews commands."
|
|
200 (interactive)
|
|
201 (let ((last-buffer (buffer-name)))
|
|
202 (make-local-variable 'rmail-last-file)
|
|
203 (switch-to-buffer (setq news-buffer (get-buffer-create "*news*")))
|
|
204 (news-mode)
|
|
205 (setq news-buffer-save last-buffer)
|
|
206 (setq buffer-read-only nil)
|
|
207 (erase-buffer)
|
|
208 (setq buffer-read-only t)
|
|
209 (set-buffer-modified-p t)
|
|
210 (sit-for 0)
|
|
211 (message "Getting new USENET news...")
|
|
212 (news-set-mode-line)
|
|
213 (news-get-certifications)
|
|
214 (news-get-new-news)))
|
|
215
|
|
216 (defun news-group-certification (group)
|
|
217 (cdr-safe (assoc group news-current-certifications)))
|
|
218
|
|
219
|
|
220 (defun news-set-current-certifiable ()
|
|
221 ;; Record the date that corresponds to the directory you are about to check
|
|
222 (let ((file (concat news-path
|
|
223 (string-subst-char ?/ ?. news-current-news-group))))
|
|
224 (setq news-current-certifiable
|
|
225 (nth 5 (file-attributes
|
|
226 (or (file-symlink-p file) file))))))
|
|
227
|
|
228 (defun news-get-certifications ()
|
|
229 ;; Read the certified-read file from last session
|
|
230 (save-excursion
|
|
231 (save-window-excursion
|
|
232 (setq news-current-certifications
|
|
233 (car-safe
|
|
234 (condition-case var
|
|
235 (let*
|
|
236 ((file (substitute-in-file-name news-certification-file))
|
|
237 (buf (find-file-noselect file)))
|
|
238 (and (file-exists-p file)
|
|
239 (progn
|
|
240 (switch-to-buffer buf 'norecord)
|
|
241 (unwind-protect
|
|
242 (read-from-string (buffer-string))
|
|
243 (kill-buffer buf)))))
|
|
244 (error nil)))))))
|
|
245
|
|
246 (defun news-write-certifications ()
|
|
247 ;; Write a certification file.
|
|
248 ;; This is an assoc list of group names with doubletons that represent
|
|
249 ;; mod times of the directory when group is read completely.
|
|
250 (save-excursion
|
|
251 (save-window-excursion
|
|
252 (with-output-to-temp-buffer
|
|
253 "*CeRtIfIcAtIoNs*"
|
|
254 (print news-current-certifications))
|
|
255 (let ((buf (get-buffer "*CeRtIfIcAtIoNs*")))
|
|
256 (switch-to-buffer buf)
|
|
257 (write-file (substitute-in-file-name news-certification-file))
|
|
258 (kill-buffer buf)))))
|
|
259
|
|
260 (defun news-set-current-group-certification ()
|
|
261 (let ((cgc (assoc news-current-news-group news-current-certifications)))
|
|
262 (if cgc (setcdr cgc news-current-certifiable)
|
|
263 (news-push (cons news-current-news-group news-current-certifiable)
|
|
264 news-current-certifications))))
|
|
265
|
|
266 (defun news-set-minor-modes ()
|
|
267 "Creates a minor mode list that has group name, total articles,
|
|
268 and attribute for current article."
|
|
269 (setq news-minor-modes (list (cons 'foo
|
|
270 (concat news-current-message-number
|
|
271 "/"
|
|
272 news-total-current-group
|
|
273 (news-get-attribute-string)))))
|
|
274 ;; Detect Emacs versions 18.16 and up, which display
|
|
275 ;; directly from news-minor-modes by using a list for mode-name.
|
|
276 (or (boundp 'minor-mode-alist)
|
|
277 (setq minor-modes news-minor-modes)))
|
|
278
|
|
279 (defun news-set-message-counters ()
|
|
280 "Scan through current news-groups filelist to figure out how many messages
|
|
281 are there. Set counters for use with minor mode display."
|
|
282 (if (null news-list-of-files)
|
|
283 (setq news-current-message-number 0)))
|
|
284
|
|
285 (if news-mode-map
|
|
286 nil
|
|
287 (setq news-mode-map (make-keymap))
|
|
288 (suppress-keymap news-mode-map)
|
|
289 (define-key news-mode-map "." 'beginning-of-buffer)
|
|
290 (define-key news-mode-map " " 'scroll-up)
|
|
291 (define-key news-mode-map "\177" 'scroll-down)
|
|
292 (define-key news-mode-map "n" 'news-next-message)
|
|
293 (define-key news-mode-map "c" 'news-make-link-to-message)
|
|
294 (define-key news-mode-map "p" 'news-previous-message)
|
|
295 (define-key news-mode-map "j" 'news-goto-message)
|
|
296 (define-key news-mode-map "q" 'news-exit)
|
|
297 (define-key news-mode-map "e" 'news-exit)
|
|
298 (define-key news-mode-map "\ej" 'news-goto-news-group)
|
|
299 (define-key news-mode-map "\en" 'news-next-group)
|
|
300 (define-key news-mode-map "\ep" 'news-previous-group)
|
|
301 (define-key news-mode-map "l" 'news-list-news-groups)
|
|
302 (define-key news-mode-map "?" 'describe-mode)
|
|
303 (define-key news-mode-map "g" 'news-get-new-news)
|
|
304 (define-key news-mode-map "f" 'news-reply)
|
|
305 (define-key news-mode-map "m" 'news-mail-other-window)
|
|
306 (define-key news-mode-map "a" 'news-post-news)
|
|
307 (define-key news-mode-map "r" 'news-mail-reply)
|
|
308 (define-key news-mode-map "o" 'news-save-item-in-file)
|
|
309 (define-key news-mode-map "\C-o" 'rmail-output)
|
|
310 (define-key news-mode-map "t" 'news-show-all-headers)
|
|
311 (define-key news-mode-map "x" 'news-force-update)
|
|
312 (define-key news-mode-map "A" 'news-add-news-group)
|
|
313 (define-key news-mode-map "u" 'news-unsubscribe-current-group)
|
|
314 (define-key news-mode-map "U" 'news-unsubscribe-group)
|
|
315 (define-key news-mode-map "\C-c\C-r" 'news-caesar-buffer-body))
|
|
316
|
|
317 (defun news-mode ()
|
|
318 "News Mode is used by M-x rnews for reading USENET Newsgroups articles.
|
|
319 New readers can find additional help in newsgroup: news.announce.newusers .
|
|
320 All normal editing commands are turned off.
|
|
321 Instead, these commands are available:
|
|
322
|
|
323 . move point to front of this news article (same as Meta-<).
|
|
324 Space scroll to next screen of this news article.
|
|
325 Delete scroll down previous page of this news article.
|
|
326 n move to next news article, possibly next group.
|
|
327 p move to previous news article, possibly previous group.
|
|
328 j jump to news article specified by numeric position.
|
|
329 M-j jump to news group.
|
|
330 M-n goto next news group.
|
|
331 M-p goto previous news group.
|
|
332 l list all the news groups with current status.
|
|
333 ? print this help message.
|
|
334 C-c C-r caesar rotate all letters by 13 places in the article's body (rot13).
|
|
335 g get new USENET news.
|
|
336 f post a reply article to USENET.
|
|
337 a post an original news article.
|
|
338 A add a newsgroup.
|
|
339 o save the current article in the named file (append if file exists).
|
|
340 C-o output this message to a Unix-format mail file (append it).
|
|
341 c \"copy\" (actually link) current or prefix-arg msg to file.
|
|
342 warning: target directory and message file must be on same device
|
|
343 (UNIX magic)
|
|
344 t show all the headers this news article originally had.
|
|
345 q quit reading news after updating .newsrc file.
|
|
346 e exit updating .newsrc file.
|
|
347 m mail a news article. Same as C-x 4 m.
|
|
348 x update last message seen to be the current message.
|
|
349 r mail a reply to this news article. Like m but initializes some fields.
|
|
350 u unsubscribe from current newsgroup.
|
|
351 U unsubscribe from specified newsgroup."
|
|
352 (interactive)
|
|
353 (kill-all-local-variables)
|
|
354 (make-local-variable 'news-read-first-time-p)
|
|
355 (setq news-read-first-time-p t)
|
|
356 (make-local-variable 'news-current-news-group)
|
|
357 ; (setq news-current-news-group "??")
|
|
358 (make-local-variable 'news-current-group-begin)
|
|
359 (setq news-current-group-begin 0)
|
|
360 (make-local-variable 'news-current-message-number)
|
|
361 (setq news-current-message-number 0)
|
|
362 (make-local-variable 'news-total-current-group)
|
|
363 (make-local-variable 'news-buffer-save)
|
|
364 (make-local-variable 'version-control)
|
|
365 (setq version-control 'never)
|
|
366 (make-local-variable 'news-point-pdl)
|
|
367 ; This breaks it. I don't have time to figure out why. -- RMS
|
|
368 ; (make-local-variable 'news-group-article-assoc)
|
|
369 (setq major-mode 'news-mode)
|
|
370 (setq mode-line-process '(news-minor-modes))
|
|
371 (setq mode-name "NEWS")
|
|
372 (news-set-mode-line)
|
|
373 (set-syntax-table text-mode-syntax-table)
|
|
374 (use-local-map news-mode-map)
|
|
375 (setq local-abbrev-table text-mode-abbrev-table)
|
|
376 (run-hooks 'news-mode-hook))
|
|
377
|
|
378 (defun string-subst-char (new old string)
|
|
379 (let (index)
|
|
380 (setq old (regexp-quote (char-to-string old))
|
|
381 string (substring string 0))
|
|
382 (while (setq index (string-match old string))
|
|
383 (aset string index new)))
|
|
384 string)
|
|
385
|
|
386 ;; update read message number
|
|
387 (defmacro news-update-message-read (ngroup nno)
|
|
388 (list 'setcar
|
|
389 (list 'news-cdadr
|
|
390 (list 'assoc ngroup 'news-group-article-assoc))
|
|
391 nno))
|
|
392
|
|
393 (defun news-parse-range (number-string)
|
|
394 "Parse string representing range of numbers of he form <a>-<b>
|
|
395 to a list (a . b)"
|
|
396 (let ((n (string-match "-" number-string)))
|
|
397 (if n
|
|
398 (cons (string-to-int (substring number-string 0 n))
|
|
399 (string-to-int (substring number-string (1+ n))))
|
|
400 (setq n (string-to-int number-string))
|
|
401 (cons n n))))
|
|
402
|
|
403 ;(defun is-in (elt lis)
|
|
404 ; (catch 'foo
|
|
405 ; (while lis
|
|
406 ; (if (equal (car lis) elt)
|
|
407 ; (throw 'foo t)
|
|
408 ; (setq lis (cdr lis))))))
|
|
409
|
|
410 (defun news-get-new-news ()
|
|
411 "Get new USENET news, if there is any for the current user."
|
|
412 (interactive)
|
|
413 (if (not (null news-user-group-list))
|
|
414 (news-update-newsrc-file))
|
|
415 (setq news-group-article-assoc ())
|
|
416 (setq news-user-group-list ())
|
|
417 (message "Looking up %s file..." news-startup-file)
|
|
418 (let ((file (substitute-in-file-name news-startup-file))
|
|
419 (temp-user-groups ()))
|
|
420 (save-excursion
|
|
421 (let ((newsrcbuf (find-file-noselect file))
|
|
422 start end endofline tem)
|
|
423 (set-buffer newsrcbuf)
|
|
424 (goto-char 0)
|
|
425 (while (search-forward ": " nil t)
|
|
426 (setq end (point))
|
|
427 (beginning-of-line)
|
|
428 (setq start (point))
|
|
429 (end-of-line)
|
|
430 (setq endofline (point))
|
|
431 (setq tem (buffer-substring start (- end 2)))
|
|
432 (let ((range (news-parse-range
|
|
433 (buffer-substring end endofline))))
|
|
434 (if (assoc tem news-group-article-assoc)
|
|
435 (message "You are subscribed twice to %s; I ignore second"
|
|
436 tem)
|
|
437 (setq temp-user-groups (cons tem temp-user-groups)
|
|
438 news-group-article-assoc
|
|
439 (cons (list tem (list (car range)
|
|
440 (cdr range)
|
|
441 (cdr range)))
|
|
442 news-group-article-assoc)))))
|
|
443 (kill-buffer newsrcbuf)))
|
|
444 (setq temp-user-groups (nreverse temp-user-groups))
|
|
445 (message "Prefrobnicating...")
|
|
446 (switch-to-buffer news-buffer)
|
|
447 (setq news-user-group-list temp-user-groups)
|
|
448 (while (and temp-user-groups
|
|
449 (not (news-read-files-into-buffer
|
|
450 (car temp-user-groups) nil)))
|
|
451 (setq temp-user-groups (cdr temp-user-groups)))
|
|
452 (if (null temp-user-groups)
|
|
453 (message "No news is good news.")
|
|
454 (message ""))))
|
|
455
|
|
456 (defun news-list-news-groups ()
|
|
457 "Display all the news groups to which you belong."
|
|
458 (interactive)
|
|
459 (with-output-to-temp-buffer "*Newsgroups*"
|
|
460 (save-excursion
|
|
461 (set-buffer standard-output)
|
|
462 (insert
|
|
463 "News Group Msg No. News Group Msg No.\n")
|
|
464 (insert
|
|
465 "------------------------- -------------------------\n")
|
|
466 (let ((temp news-user-group-list)
|
|
467 (flag nil))
|
|
468 (while temp
|
|
469 (let ((item (assoc (car temp) news-group-article-assoc)))
|
|
470 (insert (car item))
|
|
471 (indent-to (if flag 52 20))
|
|
472 (insert (int-to-string (news-cadr (news-cadr item))))
|
|
473 (if flag
|
|
474 (insert "\n")
|
|
475 (indent-to 33))
|
|
476 (setq temp (cdr temp) flag (not flag))))))))
|
|
477
|
|
478 ;; Mode line hack
|
|
479 (defun news-set-mode-line ()
|
|
480 "Set mode line string to something useful."
|
|
481 (setq mode-line-process
|
|
482 (concat " "
|
|
483 (if (integerp news-current-message-number)
|
|
484 (int-to-string news-current-message-number)
|
|
485 "??")
|
|
486 "/"
|
|
487 (if (integerp news-current-group-end)
|
|
488 (int-to-string news-current-group-end)
|
|
489 news-current-group-end)))
|
|
490 (setq mode-line-buffer-identification
|
|
491 (concat "NEWS: "
|
|
492 news-current-news-group
|
|
493 ;; Enough spaces to pad group name to 17 positions.
|
|
494 (substring " "
|
|
495 0 (max 0 (- 17 (length news-current-news-group))))))
|
|
496 (set-buffer-modified-p t)
|
|
497 (sit-for 0))
|
|
498
|
|
499 (defun news-goto-news-group (gp)
|
|
500 "Takes a string and goes to that news group."
|
|
501 (interactive (list (completing-read "NewsGroup: "
|
|
502 news-group-article-assoc)))
|
|
503 (message "Jumping to news group %s..." gp)
|
|
504 (news-select-news-group gp)
|
|
505 (message "Jumping to news group %s... done." gp))
|
|
506
|
|
507 (defun news-select-news-group (gp)
|
|
508 (let ((grp (assoc gp news-group-article-assoc)))
|
|
509 (if (null grp)
|
|
510 (error "Group %s not subscribed to" gp)
|
|
511 (progn
|
|
512 (news-update-message-read news-current-news-group
|
|
513 (news-cdar news-point-pdl))
|
|
514 (news-read-files-into-buffer (car grp) nil)
|
|
515 (news-set-mode-line)))))
|
|
516
|
|
517 (defun news-goto-message (arg)
|
|
518 "Goes to the article ARG in current newsgroup."
|
|
519 (interactive "p")
|
|
520 (if (null current-prefix-arg)
|
|
521 (setq arg (read-no-blanks-input "Go to article: " "")))
|
|
522 (news-select-message arg))
|
|
523
|
|
524 (defun news-select-message (arg)
|
|
525 (if (stringp arg) (setq arg (string-to-int arg)))
|
|
526 (let ((file (concat news-path
|
|
527 (string-subst-char ?/ ?. news-current-news-group)
|
|
528 "/" arg)))
|
|
529 (if (= arg
|
|
530 (or (news-cadr (memq (news-cdar news-point-pdl) news-list-of-files))
|
|
531 0))
|
|
532 (setcdr (car news-point-pdl) arg))
|
|
533 (setq news-current-message-number arg)
|
|
534 (if (file-exists-p file)
|
|
535 (let ((buffer-read-only nil))
|
|
536 (news-read-in-file file)
|
|
537 (news-set-mode-line))
|
|
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 (quit-window)
|
|
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 ;; don't 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 fascist)
|
|
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@gnu.org Nov 86
|
|
925 ;;; modified by tower@gnu.org 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 (t (setq n (mod n 26)))) ;canonicalize N
|
|
933 (if (not (zerop n)) ; no action needed for a rot of 0
|
|
934 (progn
|
|
935 (if (or (not (boundp 'caesar-translate-table))
|
|
936 (/= (aref caesar-translate-table ?a) (+ ?a n)))
|
|
937 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
|
|
938 (message "Building caesar-translate-table...")
|
|
939 (setq caesar-translate-table (make-vector 256 0))
|
|
940 (while (< i 256)
|
|
941 (aset caesar-translate-table i i)
|
|
942 (setq i (1+ i)))
|
|
943 (setq lower (concat lower lower) upper (upcase lower) i 0)
|
|
944 (while (< i 26)
|
|
945 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
|
|
946 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
|
|
947 (setq i (1+ i)))
|
|
948 (message "Building caesar-translate-table... done")))
|
|
949 (let ((from (region-beginning))
|
|
950 (to (region-end))
|
|
951 (i 0) str len)
|
|
952 (setq str (buffer-substring from to))
|
|
953 (setq len (length str))
|
|
954 (while (< i len)
|
|
955 (aset str i (aref caesar-translate-table (aref str i)))
|
|
956 (setq i (1+ i)))
|
|
957 (goto-char from)
|
|
958 (kill-region from to)
|
|
959 (insert str)))))
|
|
960
|
|
961 ;;; news-caesar-buffer-body written by paul@media-lab.mit.edu Wed Oct 1, 1986
|
|
962 ;;; hacked further by tower@gnu.org
|
|
963 (defun news-caesar-buffer-body (&optional rotnum)
|
|
964 "Caesar rotates all letters in the current buffer by 13 places.
|
|
965 Used to encode/decode possibly offensive messages (commonly in net.jokes).
|
|
966 With prefix arg, specifies the number of places to rotate each letter forward.
|
|
967 Mail and USENET news headers are not rotated."
|
|
968 (interactive (if current-prefix-arg ; Was there a prefix arg?
|
|
969 (list (prefix-numeric-value current-prefix-arg))
|
|
970 (list nil)))
|
|
971 (save-excursion
|
|
972 (let ((buffer-status buffer-read-only))
|
|
973 (setq buffer-read-only nil)
|
|
974 ;; setup the region
|
|
975 (set-mark (if (equal major-mode 'news-mode)
|
|
976 (progn (goto-char (point-min))
|
|
977 (search-forward "\n\n" nil t))
|
|
978 (mail-text-start)))
|
|
979 (goto-char (point-max))
|
|
980 (caesar-region rotnum)
|
|
981 (setq buffer-read-only buffer-status))))
|
|
982
|
|
983 (provide 'rnews)
|
|
984
|
|
985 ;;; rnews.el ends here
|