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