Commit | Line | Data |
---|---|---|
b027f415 RS |
1 | ;;; GNUS: an NNTP-based News Reader for GNU Emacs |
2 | ;; Copyright (C) 1987, 1988, 1989, 1990, 1993 Free Software Foundation, Inc. | |
44cdca98 | 3 | |
be89e32b | 4 | ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp> |
8649e3a0 | 5 | ;; Version: $Header: /home/fsf/rms/e19/lisp/RCS/gnus.el,v 1.27 1993/08/10 04:14:17 eggert Exp rms $ |
44cdca98 | 6 | ;; Keywords: news |
e5167999 | 7 | |
745bc783 JB |
8 | ;; This file is part of GNU Emacs. |
9 | ||
08b684de RS |
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 | |
e5167999 | 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
08b684de RS |
13 | ;; any later version. |
14 | ||
745bc783 | 15 | ;; GNU Emacs is distributed in the hope that it will be useful, |
08b684de RS |
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. | |
745bc783 | 19 | |
08b684de RS |
20 | ;; You should have received a copy of the GNU General Public License |
21 | ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
745bc783 | 23 | |
e5167999 ER |
24 | ;;; Commentary: |
25 | ||
b027f415 RS |
26 | ;; How to Install GNUS: |
27 | ;; (0) First of all, remove GNUS related OLD *.elc files (at least | |
28 | ;; nntp.elc). | |
29 | ;; (1) Unshar gnus.el, gnuspost.el, gnusmail.el, gnusmisc.el, and | |
30 | ;; nntp.el. | |
31 | ;; (2) byte-compile-file nntp.el, gnus.el, gnuspost.el, gnusmail.el, | |
32 | ;; and gnusmisc.el. If you have a local news spool, | |
33 | ;; byte-compile-file nnspool.el, too. | |
34 | ;; (3) Define three environment variables in .login file as follows: | |
35 | ;; | |
36 | ;; setenv NNTPSERVER flab | |
37 | ;; setenv DOMAINNAME "stars.flab.Fujitsu.CO.JP" | |
38 | ;; setenv ORGANIZATION "Fujitsu Laboratories Ltd., Kawasaki, Japan." | |
39 | ;; | |
40 | ;; Or instead, define lisp variables in your .emacs, site-init.el, | |
41 | ;; or default.el as follows: | |
42 | ;; | |
43 | ;; (setq gnus-nntp-server "flab") | |
44 | ;; (setq gnus-local-domain "stars.flab.Fujitsu.CO.JP") | |
45 | ;; (setq gnus-local-organization "Fujitsu Laboratories Ltd., ...") | |
46 | ;; | |
47 | ;; If the function (system-name) returns the full internet name, | |
48 | ;; you don't have to define the domain. | |
49 | ;; | |
50 | ;; (4) You may have to define NNTP service name as number 119. | |
51 | ;; | |
52 | ;; (setq gnus-nntp-service 119) | |
53 | ;; | |
54 | ;; Or, if you'd like to use a local news spool directly in stead | |
55 | ;; of NNTP, install nnspool.el and set the variable to nil as | |
56 | ;; follows: | |
57 | ;; | |
58 | ;; (setq gnus-nntp-service nil) | |
59 | ;; | |
60 | ;; (5) If you'd like to use the GENERICFROM feature like the Bnews, | |
61 | ;; define the variable as follows: | |
62 | ;; | |
63 | ;; (setq gnus-use-generic-from t) | |
64 | ;; | |
65 | ;; (6) Define autoload entries in .emacs file as follows: | |
66 | ;; | |
67 | ;; (autoload 'gnus "gnus" "Read network news." t) | |
68 | ;; (autoload 'gnus-post-news "gnuspost" "Post a news." t) | |
69 | ;; | |
70 | ;; (7) Read nntp.el if you have problems with NNTP or kanji handling. | |
71 | ;; | |
72 | ;; (8) Install mhspool.el, tcp.el, and tcp.c if it is necessary. | |
73 | ;; | |
74 | ;; mhspool.el is a package for reading articles or mail in your | |
75 | ;; private directory using GNUS. | |
76 | ;; | |
77 | ;; tcp.el and tcp.c are necessary if and only if your Emacs does | |
78 | ;; not have the function `open-network-stream' which is used for | |
79 | ;; communicating with NNTP server inside Emacs. | |
80 | ;; | |
81 | ;; (9) Install an Info file generated from the texinfo manual gnus.texinfo. | |
82 | ;; | |
83 | ;; If you are not allowed to create the Info file to the standard | |
84 | ;; Info-directory, create it in your private directory and set the | |
85 | ;; variable gnus-info-directory to that directory. | |
745bc783 | 86 | ;; |
44cdca98 RS |
87 | ;; For getting more information about GNUS, consult USENET newsgorup |
88 | ;; gnu.emacs.gnus. | |
745bc783 JB |
89 | |
90 | ;; TO DO: | |
91 | ;; (1) Incremental update of active info. | |
44cdca98 RS |
92 | ;; (2) Asynchronous transmission of large messages. |
93 | ||
94 | ;;; Code: | |
745bc783 | 95 | |
b027f415 | 96 | (provide 'gnus) |
745bc783 JB |
97 | (require 'nntp) |
98 | (require 'mail-utils) | |
99 | ||
44cdca98 RS |
100 | (defvar gnus-default-nntp-server nil |
101 | "*Specify default NNTP server. | |
102 | This variable should be defined in paths.el.") | |
103 | ||
e92a7503 | 104 | (defvar gnus-nntp-server (or (getenv "NNTPSERVER") gnus-default-nntp-server) |
b027f415 | 105 | "*The name of the host running NNTP server. |
745bc783 JB |
106 | If it is a string such as `:DIRECTORY', the user's private DIRECTORY |
107 | is used as a news spool. | |
108 | Initialized from the NNTPSERVER environment variable.") | |
109 | ||
343fbb30 | 110 | (defvar gnus-nntp-service "nntp" |
b027f415 RS |
111 | "*NNTP service name (\"nntp\" or 119). |
112 | Go to a local news spool if its value is nil.") | |
113 | ||
114 | (defvar gnus-startup-file "~/.newsrc" | |
8483b957 | 115 | "*Your `.newsrc' file. Use `.newsrc-SERVER' instead if exists.") |
343fbb30 | 116 | |
745bc783 | 117 | (defvar gnus-signature-file "~/.signature" |
8483b957 | 118 | "*Your `.signature' file. Use `.signature-DISTRIBUTION' instead if exists.") |
745bc783 JB |
119 | |
120 | (defvar gnus-use-cross-reference t | |
b027f415 RS |
121 | "*Specifies what to do with cross references (Xref: field). |
122 | If nil, ignore cross references. If t, mark articles as read in | |
123 | subscribed newsgroups. Otherwise, if not nil nor t, mark articles as | |
124 | read in all newsgroups.") | |
745bc783 JB |
125 | |
126 | (defvar gnus-use-followup-to t | |
127 | "*Specifies what to do with Followup-To: field. | |
eb8c3be9 JB |
128 | If nil, ignore followup-to: field. If t, use its value except for |
129 | `poster'. Otherwise, if not nil nor t, always use its value.") | |
745bc783 JB |
130 | |
131 | (defvar gnus-large-newsgroup 50 | |
132 | "*The number of articles which indicates a large newsgroup. | |
133 | If the number of articles in a newsgroup is greater than the value, | |
134 | confirmation is required for selecting the newsgroup.") | |
135 | ||
136 | (defvar gnus-author-copy (getenv "AUTHORCOPY") | |
b027f415 | 137 | "*File name saving a copy of an article posted using FCC: field. |
745bc783 JB |
138 | Initialized from the AUTHORCOPY environment variable. |
139 | ||
140 | Articles are saved using a function specified by the the variable | |
8483b957 | 141 | `gnus-author-copy-saver' (`rmail-output' is default) if a file name is |
b027f415 RS |
142 | given. Instead, if the first character of the name is `|', the |
143 | contents of the article is piped out to the named program. It is | |
745bc783 JB |
144 | possible to save an article in an MH folder as follows: |
145 | ||
b027f415 | 146 | (setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\")") |
745bc783 JB |
147 | |
148 | (defvar gnus-author-copy-saver (function rmail-output) | |
149 | "*A function called with a file name to save an author copy to. | |
150 | The default function is `rmail-output' which saves in Unix mailbox format.") | |
151 | ||
152 | (defvar gnus-use-long-file-name | |
153 | (not (memq system-type '(usg-unix-v xenix))) | |
b027f415 RS |
154 | "*Non-nil means that a newsgroup name is used as a default file name |
155 | to save articles to. If it's nil, the directory form of a newsgroup is | |
745bc783 JB |
156 | used instead.") |
157 | ||
158 | (defvar gnus-article-save-directory (getenv "SAVEDIR") | |
b027f415 | 159 | "*A directory name to save articles to (default to ~/News). |
745bc783 JB |
160 | Initialized from the SAVEDIR environment variable.") |
161 | ||
b027f415 RS |
162 | (defvar gnus-default-article-saver (function gnus-summary-save-in-rmail) |
163 | "*A function to save articles in your favorite format. | |
745bc783 JB |
164 | The function must be interactively callable (in other words, it must |
165 | be an Emacs command). | |
166 | ||
167 | GNUS provides the following functions: | |
b027f415 RS |
168 | gnus-summary-save-in-rmail (in Rmail format) |
169 | gnus-summary-save-in-mail (in Unix mail format) | |
170 | gnus-summary-save-in-folder (in an MH folder) | |
171 | gnus-summary-save-in-file (in article format).") | |
745bc783 JB |
172 | |
173 | (defvar gnus-rmail-save-name (function gnus-plain-save-name) | |
b027f415 | 174 | "*A function generating a file name to save articles in Rmail format. |
745bc783 JB |
175 | The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.") |
176 | ||
177 | (defvar gnus-mail-save-name (function gnus-plain-save-name) | |
b027f415 | 178 | "*A function generating a file name to save articles in Unix mail format. |
745bc783 JB |
179 | The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.") |
180 | ||
181 | (defvar gnus-folder-save-name (function gnus-folder-save-name) | |
b027f415 | 182 | "*A function generating a file name to save articles in MH folder. |
745bc783 JB |
183 | The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.") |
184 | ||
185 | (defvar gnus-file-save-name (function gnus-numeric-save-name) | |
b027f415 | 186 | "*A function generating a file name to save articles in article format. |
745bc783 JB |
187 | The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.") |
188 | ||
189 | (defvar gnus-kill-file-name "KILL" | |
b027f415 | 190 | "*File name of a KILL file.") |
745bc783 JB |
191 | |
192 | (defvar gnus-novice-user t | |
8483b957 RS |
193 | "*Non-nil means that you are a novice to USENET. |
194 | If non-nil, verbose messages may be displayed | |
195 | or your confirmations may be required.") | |
b027f415 RS |
196 | |
197 | (defvar gnus-interactive-catchup t | |
198 | "*Require your confirmation when catching up a newsgroup if non-nil.") | |
745bc783 JB |
199 | |
200 | (defvar gnus-interactive-post t | |
201 | "*Newsgroup, subject, and distribution will be asked for if non-nil.") | |
202 | ||
b027f415 | 203 | (defvar gnus-interactive-exit t |
8483b957 | 204 | "*Require your confirmation when exiting GNUS if non-nil.") |
b027f415 | 205 | |
745bc783 JB |
206 | (defvar gnus-user-login-name nil |
207 | "*The login name of the user. | |
b027f415 | 208 | Got from the USER and LOGNAME environment variable if undefined.") |
745bc783 JB |
209 | |
210 | (defvar gnus-user-full-name nil | |
211 | "*The full name of the user. | |
b027f415 RS |
212 | Got from the NAME environment variable if undefined.") |
213 | ||
214 | (defvar gnus-show-mime nil | |
215 | "*Show MIME message if non-nil.") | |
745bc783 JB |
216 | |
217 | (defvar gnus-show-threads t | |
b027f415 | 218 | "*Show conversation threads in Summary Mode if non-nil.") |
745bc783 JB |
219 | |
220 | (defvar gnus-thread-hide-subject t | |
221 | "*Non-nil means hide subjects for thread subtrees.") | |
222 | ||
223 | (defvar gnus-thread-hide-subtree nil | |
224 | "*Non-nil means hide thread subtrees initially. | |
8483b957 RS |
225 | If non-nil, you have to run the command `gnus-summary-show-thread' by |
226 | hand or by using `gnus-select-article-hook' to show hidden threads.") | |
745bc783 JB |
227 | |
228 | (defvar gnus-thread-hide-killed t | |
229 | "*Non-nil means hide killed thread subtrees automatically.") | |
230 | ||
231 | (defvar gnus-thread-ignore-subject nil | |
232 | "*Don't take care of subject differences, but only references if non-nil. | |
233 | If it is non-nil, some commands work with subjects do not work properly.") | |
234 | ||
235 | (defvar gnus-thread-indent-level 4 | |
b027f415 RS |
236 | "*Indentation of thread subtrees.") |
237 | ||
238 | (defvar gnus-ignored-newsgroups "^to\\..*$" | |
8483b957 | 239 | "*A regexp to match uninteresting newsgroups in the active file. |
b027f415 RS |
240 | Any lines in the active file matching this regular expression are |
241 | removed from the newsgroup list before anything else is done to it, | |
242 | thus making them effectively invisible.") | |
745bc783 JB |
243 | |
244 | (defvar gnus-ignored-headers | |
b027f415 RS |
245 | "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:" |
246 | "*All random fields within the header of a message.") | |
247 | ||
248 | (defvar gnus-required-headers | |
249 | '(From Date Newsgroups Subject Message-ID Path Organization Distribution) | |
250 | "*All required fields for articles you post. | |
251 | RFC977 and RFC1036 require From, Date, Newsgroups, Subject, Message-ID | |
252 | and Path fields. Organization, Distribution and Lines are optional. | |
253 | If you want GNUS not to insert some field, remove it from the | |
254 | variable.") | |
745bc783 JB |
255 | |
256 | (defvar gnus-show-all-headers nil | |
257 | "*Show all headers of an article if non-nil.") | |
258 | ||
b027f415 | 259 | (defvar gnus-save-all-headers t |
745bc783 JB |
260 | "*Save all headers of an article if non-nil.") |
261 | ||
262 | (defvar gnus-optional-headers (function gnus-optional-lines-and-from) | |
b027f415 | 263 | "*A function generating a optional string displayed in GNUS Summary |
745bc783 JB |
264 | mode buffer. The function is called with an article HEADER. The |
265 | result must be a string excluding `[' and `]'.") | |
266 | ||
267 | (defvar gnus-auto-extend-newsgroup t | |
eb8c3be9 | 268 | "*Extend visible articles to forward and backward if non-nil.") |
745bc783 JB |
269 | |
270 | (defvar gnus-auto-select-first t | |
271 | "*Select the first unread article automagically if non-nil. | |
272 | If you want to prevent automatic selection of the first unread article | |
8483b957 RS |
273 | in some newsgroups, set the variable to nil in `gnus-select-group-hook' |
274 | or `gnus-apply-kill-hook'.") | |
745bc783 JB |
275 | |
276 | (defvar gnus-auto-select-next t | |
277 | "*Select the next newsgroup automagically if non-nil. | |
278 | If the value is t and the next newsgroup is empty, GNUS will exit | |
b027f415 | 279 | Summary mode and go back to Group mode. If the value is neither nil |
8483b957 | 280 | nor t, GNUS will select the following unread newsgroup. Especially, if |
745bc783 JB |
281 | the value is the symbol `quietly', the next unread newsgroup will be |
282 | selected without any confirmations.") | |
283 | ||
284 | (defvar gnus-auto-select-same nil | |
285 | "*Select the next article with the same subject automagically if non-nil.") | |
286 | ||
b027f415 RS |
287 | (defvar gnus-auto-center-summary t |
288 | "*Always center the current summary in GNUS Summary window if non-nil.") | |
289 | ||
290 | (defvar gnus-auto-mail-to-author nil | |
291 | "*Insert `To: author' of the article when following up if non-nil. | |
292 | Mail is sent using the function specified by the variable | |
8483b957 | 293 | `gnus-mail-send-method'.") |
745bc783 JB |
294 | |
295 | (defvar gnus-break-pages t | |
296 | "*Break an article into pages if non-nil. | |
297 | Page delimiter is specified by the variable `gnus-page-delimiter'.") | |
298 | ||
299 | (defvar gnus-page-delimiter "^\^L" | |
300 | "*Regexp describing line-beginnings that separate pages of news article.") | |
301 | ||
302 | (defvar gnus-digest-show-summary t | |
303 | "*Show a summary of undigestified messages if non-nil.") | |
304 | ||
305 | (defvar gnus-digest-separator "^Subject:[ \t]" | |
306 | "*Regexp that separates messages in a digest article.") | |
307 | ||
308 | (defvar gnus-use-full-window t | |
309 | "*Non-nil means to take up the entire screen of Emacs.") | |
310 | ||
311 | (defvar gnus-window-configuration | |
b027f415 RS |
312 | '((summary (0 1 0)) |
313 | (newsgroups (1 0 0)) | |
314 | (article (0 3 10))) | |
315 | "*Specify window configurations for each action. | |
316 | The format of the variable is a list of (ACTION (G S A)), where G, S, | |
317 | and A are the relative height of Group, Summary, and Article windows, | |
318 | respectively. ACTION is `summary', `newsgroups', or `article'.") | |
319 | ||
320 | (defvar gnus-show-mime-method (function metamail-buffer) | |
321 | "*Function to process a MIME message. | |
322 | The function is expected to process current buffer as a MIME message.") | |
745bc783 JB |
323 | |
324 | (defvar gnus-mail-reply-method | |
325 | (function gnus-mail-reply-using-mail) | |
b027f415 | 326 | "*Function to compose reply mail. |
8483b957 RS |
327 | The function `gnus-mail-reply-using-mail' uses usual sendmail mail |
328 | program. The function `gnus-mail-reply-using-mhe' uses the MH-E mail | |
745bc783 JB |
329 | program. You can use yet another program by customizing this variable.") |
330 | ||
b027f415 RS |
331 | (defvar gnus-mail-forward-method |
332 | (function gnus-mail-forward-using-mail) | |
333 | "*Function to forward current message to another user. | |
8483b957 RS |
334 | The function `gnus-mail-reply-using-mail' uses usual sendmail mail |
335 | program. You can use yet another program by customizing this variable.") | |
b027f415 | 336 | |
745bc783 JB |
337 | (defvar gnus-mail-other-window-method |
338 | (function gnus-mail-other-window-using-mail) | |
b027f415 | 339 | "*Function to compose mail in other window. |
8483b957 RS |
340 | The function `gnus-mail-other-window-using-mail' uses the usual sendmail |
341 | mail program. The function `gnus-mail-other-window-using-mhe' uses the MH-E | |
745bc783 JB |
342 | mail program. You can use yet another program by customizing this variable.") |
343 | ||
b027f415 RS |
344 | (defvar gnus-mail-send-method send-mail-function |
345 | "*Function to mail a message too which is being posted as an article. | |
8483b957 RS |
346 | The message must have To: or Cc: field. The default is copied from |
347 | the variable `send-mail-function'.") | |
b027f415 | 348 | |
745bc783 | 349 | (defvar gnus-subscribe-newsgroup-method |
b027f415 RS |
350 | (function gnus-subscribe-alphabetically) |
351 | "*Function called with a newsgroup name when new newsgroup is found. | |
8483b957 RS |
352 | The function `gnus-subscribe-randomly' inserts a new newsgroup a the |
353 | beginning of newsgroups. The function `gnus-subscribe-alphabetically' | |
b027f415 | 354 | inserts it in strict alphabetic order. The function |
8483b957 RS |
355 | `gnus-subscribe-hierarchically' inserts it in hierarchical newsgroup |
356 | order. The function `gnus-subscribe-interactively' asks for your decision.") | |
745bc783 | 357 | |
b027f415 RS |
358 | (defvar gnus-group-mode-hook nil |
359 | "*A hook for GNUS Group Mode.") | |
745bc783 | 360 | |
b027f415 RS |
361 | (defvar gnus-summary-mode-hook nil |
362 | "*A hook for GNUS Summary Mode.") | |
745bc783 | 363 | |
b027f415 RS |
364 | (defvar gnus-article-mode-hook nil |
365 | "*A hook for GNUS Article Mode.") | |
745bc783 | 366 | |
b027f415 RS |
367 | (defvar gnus-kill-file-mode-hook nil |
368 | "*A hook for GNUS KILL File Mode.") | |
745bc783 | 369 | |
b027f415 RS |
370 | (defvar gnus-open-server-hook nil |
371 | "*A hook called just before opening connection to news server.") | |
745bc783 | 372 | |
b027f415 RS |
373 | (defvar gnus-startup-hook nil |
374 | "*A hook called at start up time. | |
375 | This hook is called after GNUS is connected to the NNTP server. So, it | |
376 | is possible to change the behavior of GNUS according to the selected | |
377 | NNTP server.") | |
745bc783 | 378 | |
b027f415 RS |
379 | (defvar gnus-group-prepare-hook nil |
380 | "*A hook called after newsgroup list is created in the Newsgroup buffer. | |
745bc783 JB |
381 | If you want to modify the Newsgroup buffer, you can use this hook.") |
382 | ||
b027f415 RS |
383 | (defvar gnus-summary-prepare-hook nil |
384 | "*A hook called after summary list is created in the Summary buffer. | |
385 | If you want to modify the Summary buffer, you can use this hook.") | |
745bc783 | 386 | |
b027f415 RS |
387 | (defvar gnus-article-prepare-hook nil |
388 | "*A hook called after an article is prepared in the Article buffer. | |
745bc783 JB |
389 | If you want to run a special decoding program like nkf, use this hook.") |
390 | ||
b027f415 RS |
391 | (defvar gnus-select-group-hook nil |
392 | "*A hook called when a newsgroup is selected. | |
393 | If you want to sort Summary buffer by date and then by subject, you | |
745bc783 JB |
394 | can use the following hook: |
395 | ||
8483b957 RS |
396 | \(setq gnus-select-group-hook |
397 | (list | |
398 | (function | |
399 | (lambda () | |
400 | ;; First of all, sort by date. | |
401 | (gnus-keysort-headers | |
402 | (function string-lessp) | |
403 | (function | |
404 | (lambda (a) | |
405 | (gnus-sortable-date (gnus-header-date a))))) | |
406 | ;; Then sort by subject string ignoring `Re:'. | |
407 | ;; If case-fold-search is non-nil, case of letters is ignored. | |
408 | (gnus-keysort-headers | |
409 | (function string-lessp) | |
410 | (function | |
411 | (lambda (a) | |
412 | (if case-fold-search | |
413 | (downcase (gnus-simplify-subject (gnus-header-subject a) t)) | |
414 | (gnus-simplify-subject (gnus-header-subject a) t))))) | |
415 | )))) | |
b027f415 RS |
416 | |
417 | If you'd like to simplify subjects like the | |
418 | `gnus-summary-next-same-subject' command does, you can use the | |
419 | following hook: | |
420 | ||
8483b957 RS |
421 | \(setq gnus-select-group-hook |
422 | (list | |
423 | (function | |
424 | (lambda () | |
425 | (mapcar (function | |
426 | (lambda (header) | |
427 | (nntp-set-header-subject | |
428 | header | |
429 | (gnus-simplify-subject | |
430 | (gnus-header-subject header) 're-only)))) | |
431 | gnus-newsgroup-headers))))) | |
745bc783 | 432 | |
b027f415 RS |
433 | In some newsgroups author name is meaningless. It is possible to |
434 | prevent listing author names in GNUS Summary buffer as follows: | |
745bc783 | 435 | |
8483b957 RS |
436 | \(setq gnus-select-group-hook |
437 | (list | |
438 | (function | |
439 | (lambda () | |
440 | (cond ((string-equal \"comp.sources.unix\" gnus-newsgroup-name) | |
441 | (setq gnus-optional-headers | |
442 | (function gnus-optional-lines))) | |
443 | (t | |
444 | (setq gnus-optional-headers | |
445 | (function gnus-optional-lines-and-from))))))))") | |
745bc783 | 446 | |
b027f415 | 447 | (defvar gnus-select-article-hook |
8483b957 | 448 | '(gnus-summary-show-thread) |
b027f415 RS |
449 | "*A hook called when an article is selected. |
450 | The default hook shows conversation thread subtrees of the selected | |
8483b957 | 451 | article automatically using `gnus-summary-show-thread'. |
745bc783 JB |
452 | |
453 | If you'd like to run RMAIL on a digest article automagically, you can | |
454 | use the following hook: | |
455 | ||
8483b957 RS |
456 | \(setq gnus-select-article-hook |
457 | (list | |
458 | (function | |
459 | (lambda () | |
460 | (gnus-summary-show-thread) | |
461 | (cond ((string-equal \"comp.sys.sun\" gnus-newsgroup-name) | |
462 | (gnus-summary-rmail-digest)) | |
463 | ((and (string-equal \"comp.text\" gnus-newsgroup-name) | |
464 | (string-match \"^TeXhax Digest\" | |
465 | (gnus-header-subject gnus-current-headers))) | |
466 | (gnus-summary-rmail-digest) | |
467 | ))))))") | |
745bc783 | 468 | |
b027f415 | 469 | (defvar gnus-select-digest-hook |
8483b957 RS |
470 | (list |
471 | (function | |
472 | (lambda () | |
473 | ;; Reply-To: is required by `undigestify-rmail-message'. | |
474 | (or (mail-position-on-field "Reply-to" t) | |
475 | (progn | |
476 | (mail-position-on-field "Reply-to") | |
477 | (insert (gnus-fetch-field "From"))))))) | |
b027f415 | 478 | "*A hook called when reading digest messages using Rmail. |
745bc783 | 479 | This hook can be used to modify incomplete digest articles as follows |
8483b957 RS |
480 | \(this is the default): |
481 | ||
482 | \(setq gnus-select-digest-hook | |
483 | (list | |
484 | (function | |
485 | (lambda () | |
486 | ;; Reply-To: is required by `undigestify-rmail-message'. | |
487 | (or (mail-position-on-field \"Reply-to\" t) | |
488 | (progn | |
489 | (mail-position-on-field \"Reply-to\") | |
490 | (insert (gnus-fetch-field \"From\"))))))))") | |
745bc783 | 491 | |
b027f415 RS |
492 | (defvar gnus-rmail-digest-hook nil |
493 | "*A hook called when reading digest messages using Rmail. | |
745bc783 JB |
494 | This hook is intended to customize Rmail mode for reading digest articles.") |
495 | ||
8483b957 | 496 | (defvar gnus-apply-kill-hook '(gnus-apply-kill-file) |
b027f415 | 497 | "*A hook called when a newsgroup is selected and summary list is prepared. |
745bc783 | 498 | This hook is intended to apply a KILL file to the selected newsgroup. |
8483b957 | 499 | The function `gnus-apply-kill-file' is called by default. |
745bc783 | 500 | |
b027f415 RS |
501 | Since a general KILL file is too heavy to use only for a few |
502 | newsgroups, I recommend you to use a lighter hook function. For | |
745bc783 JB |
503 | example, if you'd like to apply a KILL file to articles which contains |
504 | a string `rmgroup' in subject in newsgroup `control', you can use the | |
505 | following hook: | |
506 | ||
8483b957 RS |
507 | \(setq gnus-apply-kill-hook |
508 | (list | |
509 | (function | |
510 | (lambda () | |
511 | (cond ((string-match \"control\" gnus-newsgroup-name) | |
512 | (gnus-kill \"Subject\" \"rmgroup\") | |
513 | (gnus-expunge \"X\")))))))") | |
745bc783 | 514 | |
b027f415 | 515 | (defvar gnus-mark-article-hook |
8483b957 RS |
516 | (list |
517 | (function | |
518 | (lambda () | |
519 | (or (memq gnus-current-article gnus-newsgroup-marked) | |
520 | (gnus-summary-mark-as-read gnus-current-article)) | |
521 | (gnus-summary-set-current-mark "+")))) | |
b027f415 RS |
522 | "*A hook called when an article is selected at the first time. |
523 | The hook is intended to mark an article as read (or unread) | |
524 | automatically when it is selected. | |
745bc783 | 525 | |
b027f415 | 526 | If you'd like to mark as unread (-) instead, use the following hook: |
745bc783 | 527 | |
8483b957 RS |
528 | \(setq gnus-mark-article-hook |
529 | (list | |
530 | (function | |
531 | (lambda () | |
532 | (gnus-summary-mark-as-unread gnus-current-article) | |
533 | (gnus-summary-set-current-mark \"+\")))))") | |
b027f415 | 534 | |
abc01fb8 | 535 | (defvar gnus-prepare-article-hook (list (function gnus-inews-insert-signature)) |
b027f415 | 536 | "*A hook called after preparing body, but before preparing header fields. |
abc01fb8 RS |
537 | The default hook (`gnus-inews-insert-signature') inserts a signature |
538 | file specified by the variable `gnus-signature-file'.") | |
b027f415 | 539 | |
abc01fb8 | 540 | (defvar gnus-inews-article-hook (list (function gnus-inews-do-fcc)) |
b027f415 | 541 | "*A hook called before finally posting an article. |
abc01fb8 | 542 | The default hook (`gnus-inews-do-fcc') does FCC processing (save article |
b027f415 RS |
543 | to a file).") |
544 | ||
545 | (defvar gnus-exit-group-hook nil | |
546 | "*A hook called when exiting (not quitting) Summary mode. | |
547 | If your machine is so slow that exiting from Summary mode takes very | |
abc01fb8 | 548 | long time, set the variable `gnus-use-cross-reference' to nil. This |
745bc783 JB |
549 | inhibits marking articles as read using cross-reference information.") |
550 | ||
b027f415 RS |
551 | (defvar gnus-suspend-gnus-hook nil |
552 | "*A hook called when suspending (not exiting) GNUS.") | |
745bc783 | 553 | |
b027f415 RS |
554 | (defvar gnus-exit-gnus-hook nil |
555 | "*A hook called when exiting (not suspending) GNUS.") | |
745bc783 | 556 | |
b027f415 RS |
557 | (defvar gnus-save-newsrc-hook nil |
558 | "*A hook called when saving the newsrc file. | |
abc01fb8 | 559 | This hook is called before saving the `.newsrc' file.") |
745bc783 | 560 | |
b027f415 RS |
561 | \f |
562 | ;; Site dependent variables. You have to define these variables in | |
563 | ;; site-init.el, default.el or your .emacs. | |
564 | ||
565 | (defvar gnus-local-timezone nil | |
65a91500 RS |
566 | "*Local time zone. |
567 | This value is used only if `current-time-zone' does not work in your Emacs. | |
568 | It specifies the GMT offset, i.e. a decimal integer | |
569 | of the form +-HHMM giving the hours and minutes ahead of (i.e. east of) GMT. | |
570 | For example, +0900 should be used in Japan, since it is 9 hours ahead of GMT. | |
571 | ||
572 | For backwards compatibility, it may also be a string like \"JST\", | |
573 | but strings are obsolescent: you should use numeric offsets instead.") | |
b027f415 RS |
574 | |
575 | (defvar gnus-local-domain nil | |
576 | "*Local domain name without a host name like: \"stars.flab.Fujitsu.CO.JP\" | |
577 | The `DOMAINNAME' environment variable is used instead if defined. If | |
578 | the function (system-name) returns the full internet name, there is no | |
579 | need to define the name.") | |
580 | ||
581 | (defvar gnus-local-organization nil | |
582 | "*Local organization like: \"Fujitsu Laboratories Ltd., Kawasaki, Japan.\" | |
745bc783 JB |
583 | The `ORGANIZATION' environment variable is used instead if defined.") |
584 | ||
b027f415 RS |
585 | (defvar gnus-local-distributions '("local" "world") |
586 | "*List of distributions. | |
587 | The first element in the list is used as default. If distributions | |
588 | file is available, its content is also used.") | |
589 | ||
745bc783 JB |
590 | (defvar gnus-use-generic-from nil |
591 | "*If nil, prepend local host name to the defined domain in the From: | |
592 | field; if stringp, use this; if non-nil, strip of the local host name.") | |
593 | ||
594 | (defvar gnus-use-generic-path nil | |
595 | "*If nil, use the NNTP server name in the Path: field; if stringp, | |
596 | use this; if non-nil, use no host name (user name only)") | |
597 | \f | |
598 | ;; Internal variables. | |
599 | ||
44cdca98 | 600 | (defconst gnus-version "GNUS 4.1" |
745bc783 JB |
601 | "Version numbers of this version of GNUS.") |
602 | ||
44cdca98 RS |
603 | (defconst gnus-emacs-version |
604 | (progn | |
605 | (string-match "[0-9]*" emacs-version) | |
606 | (string-to-int (substring emacs-version | |
607 | (match-beginning 0) (match-end 0)))) | |
608 | "Major version number of this emacs.") | |
609 | ||
b027f415 RS |
610 | (defvar gnus-info-nodes |
611 | '((gnus-group-mode "(gnus)Newsgroup Commands") | |
612 | (gnus-summary-mode "(gnus)Summary Commands") | |
613 | (gnus-article-mode "(gnus)Article Commands") | |
056afaf7 RS |
614 | (gnus-kill-file-mode "(gnus)Kill File") |
615 | (gnus-browse-killed-mode "(gnus)Maintaining Subscriptions")) | |
745bc783 JB |
616 | "Assoc list of major modes and related Info nodes.") |
617 | ||
b027f415 | 618 | ;; Alist syntax is different from that of 3.14.3. |
745bc783 JB |
619 | (defvar gnus-access-methods |
620 | '((nntp | |
b027f415 RS |
621 | (gnus-retrieve-headers nntp-retrieve-headers) |
622 | (gnus-open-server nntp-open-server) | |
623 | (gnus-close-server nntp-close-server) | |
624 | (gnus-server-opened nntp-server-opened) | |
625 | (gnus-status-message nntp-status-message) | |
626 | (gnus-request-article nntp-request-article) | |
627 | (gnus-request-group nntp-request-group) | |
628 | (gnus-request-list nntp-request-list) | |
629 | (gnus-request-list-newsgroups nntp-request-list-newsgroups) | |
630 | (gnus-request-list-distributions nntp-request-list-distributions) | |
631 | (gnus-request-post nntp-request-post)) | |
745bc783 | 632 | (nnspool |
b027f415 RS |
633 | (gnus-retrieve-headers nnspool-retrieve-headers) |
634 | (gnus-open-server nnspool-open-server) | |
635 | (gnus-close-server nnspool-close-server) | |
636 | (gnus-server-opened nnspool-server-opened) | |
637 | (gnus-status-message nnspool-status-message) | |
638 | (gnus-request-article nnspool-request-article) | |
639 | (gnus-request-group nnspool-request-group) | |
640 | (gnus-request-list nnspool-request-list) | |
641 | (gnus-request-list-newsgroups nnspool-request-list-newsgroups) | |
642 | (gnus-request-list-distributions nnspool-request-list-distributions) | |
643 | (gnus-request-post nnspool-request-post)) | |
745bc783 | 644 | (mhspool |
b027f415 RS |
645 | (gnus-retrieve-headers mhspool-retrieve-headers) |
646 | (gnus-open-server mhspool-open-server) | |
647 | (gnus-close-server mhspool-close-server) | |
648 | (gnus-server-opened mhspool-server-opened) | |
649 | (gnus-status-message mhspool-status-message) | |
650 | (gnus-request-article mhspool-request-article) | |
651 | (gnus-request-group mhspool-request-group) | |
652 | (gnus-request-list mhspool-request-list) | |
653 | (gnus-request-list-newsgroups mhspool-request-list-newsgroups) | |
654 | (gnus-request-list-distributions mhspool-request-list-distributions) | |
655 | (gnus-request-post mhspool-request-post))) | |
745bc783 JB |
656 | "Access method for NNTP, nnspool, and mhspool.") |
657 | ||
b027f415 RS |
658 | (defvar gnus-group-buffer "*Newsgroup*") |
659 | (defvar gnus-summary-buffer "*Summary*") | |
660 | (defvar gnus-article-buffer "*Article*") | |
661 | (defvar gnus-digest-buffer "GNUS Digest") | |
662 | (defvar gnus-digest-summary-buffer "GNUS Digest-summary") | |
745bc783 JB |
663 | |
664 | (defvar gnus-buffer-list | |
b027f415 RS |
665 | (list gnus-group-buffer gnus-summary-buffer gnus-article-buffer |
666 | gnus-digest-buffer gnus-digest-summary-buffer) | |
745bc783 JB |
667 | "GNUS buffer names which should be killed when exiting.") |
668 | ||
669 | (defvar gnus-variable-list | |
670 | '(gnus-newsrc-options | |
671 | gnus-newsrc-options-n-yes gnus-newsrc-options-n-no | |
672 | gnus-newsrc-assoc gnus-killed-assoc gnus-marked-assoc) | |
673 | "GNUS variables saved in the quick startup file.") | |
674 | ||
675 | (defvar gnus-overload-functions | |
676 | '((news-inews gnus-inews-news "rnewspost") | |
677 | (caesar-region gnus-caesar-region "rnews")) | |
678 | "Functions overloaded by gnus. | |
679 | It is a list of `(original overload &optional file)'.") | |
680 | ||
b027f415 RS |
681 | (defvar gnus-distribution-list nil) |
682 | ||
745bc783 JB |
683 | (defvar gnus-newsrc-options nil |
684 | "Options line in the .newsrc file.") | |
685 | ||
686 | (defvar gnus-newsrc-options-n-yes nil | |
687 | "Regexp representing subscribed newsgroups.") | |
688 | ||
689 | (defvar gnus-newsrc-options-n-no nil | |
690 | "Regexp representing unsubscribed newsgroups.") | |
691 | ||
692 | (defvar gnus-newsrc-assoc nil | |
b027f415 RS |
693 | "Assoc list of read articles. |
694 | gnus-newsrc-hashtb should be kept so that both hold the same information.") | |
695 | ||
696 | (defvar gnus-newsrc-hashtb nil | |
697 | "Hashtable of gnus-newsrc-assoc.") | |
745bc783 JB |
698 | |
699 | (defvar gnus-killed-assoc nil | |
b027f415 RS |
700 | "Assoc list of newsgroups removed from gnus-newsrc-assoc. |
701 | gnus-killed-hashtb should be kept so that both hold the same information.") | |
702 | ||
703 | (defvar gnus-killed-hashtb nil | |
704 | "Hashtable of gnus-killed-assoc.") | |
745bc783 JB |
705 | |
706 | (defvar gnus-marked-assoc nil | |
b027f415 RS |
707 | "Assoc list of articles marked as unread. |
708 | gnus-marked-hashtb should be kept so that both hold the same information.") | |
709 | ||
710 | (defvar gnus-marked-hashtb nil | |
711 | "Hashtable of gnus-marked-assoc.") | |
745bc783 JB |
712 | |
713 | (defvar gnus-unread-hashtb nil | |
714 | "Hashtable of unread articles.") | |
715 | ||
716 | (defvar gnus-active-hashtb nil | |
717 | "Hashtable of active articles.") | |
718 | ||
719 | (defvar gnus-octive-hashtb nil | |
720 | "Hashtable of OLD active articles.") | |
721 | ||
722 | (defvar gnus-current-startup-file nil | |
723 | "Startup file for the current host.") | |
724 | ||
725 | (defvar gnus-last-search-regexp nil | |
726 | "Default regexp for article search command.") | |
727 | ||
728 | (defvar gnus-last-shell-command nil | |
729 | "Default shell command on article.") | |
730 | ||
731 | (defvar gnus-have-all-newsgroups nil) | |
732 | ||
733 | (defvar gnus-newsgroup-name nil) | |
734 | (defvar gnus-newsgroup-begin nil) | |
735 | (defvar gnus-newsgroup-end nil) | |
736 | (defvar gnus-newsgroup-last-rmail nil) | |
737 | (defvar gnus-newsgroup-last-mail nil) | |
738 | (defvar gnus-newsgroup-last-folder nil) | |
739 | (defvar gnus-newsgroup-last-file nil) | |
740 | ||
741 | (defvar gnus-newsgroup-unreads nil | |
742 | "List of unread articles in the current newsgroup.") | |
743 | ||
744 | (defvar gnus-newsgroup-unselected nil | |
745 | "List of unselected unread articles in the current newsgroup.") | |
746 | ||
747 | (defvar gnus-newsgroup-marked nil | |
748 | "List of marked articles in the current newsgroup (a subset of unread art).") | |
749 | ||
750 | (defvar gnus-newsgroup-headers nil | |
b027f415 RS |
751 | "List of article headers in the current newsgroup. |
752 | If the variable is modified (added or deleted), the function | |
753 | gnus-clear-hashtables-for-newsgroup-headers must be called to clear | |
754 | the hash tables.") | |
755 | (defvar gnus-newsgroup-headers-hashtb-by-id nil) | |
756 | (defvar gnus-newsgroup-headers-hashtb-by-number nil) | |
745bc783 JB |
757 | |
758 | (defvar gnus-current-article nil) | |
759 | (defvar gnus-current-headers nil) | |
760 | (defvar gnus-current-history nil) | |
b027f415 | 761 | (defvar gnus-have-all-headers nil "Must be either T or NIL.") |
745bc783 JB |
762 | (defvar gnus-last-article nil) |
763 | (defvar gnus-current-kill-article nil) | |
764 | ||
765 | ;; Save window configuration. | |
766 | (defvar gnus-winconf-kill-file nil) | |
767 | ||
b027f415 RS |
768 | (defvar gnus-group-mode-map nil) |
769 | (defvar gnus-summary-mode-map nil) | |
770 | (defvar gnus-article-mode-map nil) | |
771 | (defvar gnus-kill-file-mode-map nil) | |
745bc783 JB |
772 | |
773 | (defvar rmail-last-file (expand-file-name "~/XMBOX")) | |
774 | (defvar rmail-last-rmail-file (expand-file-name "~/XNEWS")) | |
775 | ||
776 | ;; Define GNUS Subsystems. | |
b027f415 | 777 | (autoload 'gnus-group-post-news "gnuspost" |
745bc783 | 778 | "Post an article." t) |
b027f415 | 779 | (autoload 'gnus-summary-post-news "gnuspost" |
745bc783 | 780 | "Post an article." t) |
b027f415 | 781 | (autoload 'gnus-summary-followup "gnuspost" |
745bc783 | 782 | "Post a reply article." t) |
b027f415 | 783 | (autoload 'gnus-summary-followup-with-original "gnuspost" |
745bc783 | 784 | "Post a reply article with original article." t) |
b027f415 | 785 | (autoload 'gnus-summary-cancel-article "gnuspost" |
745bc783 JB |
786 | "Cancel an article you posted." t) |
787 | ||
b027f415 | 788 | (autoload 'gnus-summary-reply "gnusmail" |
745bc783 | 789 | "Reply mail to news author." t) |
b027f415 | 790 | (autoload 'gnus-summary-reply-with-original "gnusmail" |
745bc783 | 791 | "Reply mail to news author with original article." t) |
b027f415 RS |
792 | (autoload 'gnus-summary-mail-forward "gnusmail" |
793 | "Forward the current message to another user." t) | |
794 | (autoload 'gnus-summary-mail-other-window "gnusmail" | |
745bc783 JB |
795 | "Compose mail in other window." t) |
796 | ||
b027f415 | 797 | (autoload 'gnus-group-kill-group "gnusmisc" |
745bc783 | 798 | "Kill newsgroup on current line." t) |
b027f415 | 799 | (autoload 'gnus-group-yank-group "gnusmisc" |
745bc783 | 800 | "Yank the last killed newsgroup on current line." t) |
b027f415 RS |
801 | (autoload 'gnus-group-kill-region "gnusmisc" |
802 | "Kill newsgroups in current region." t) | |
803 | (autoload 'gnus-group-transpose-groups "gnusmisc" | |
804 | "Exchange current newsgroup and previous newsgroup." t) | |
805 | (autoload 'gnus-list-killed-groups "gnusmisc" | |
806 | "List the killed newsgroups." t) | |
807 | (autoload 'gnus-gmt-to-local "gnusmisc" | |
808 | "Rewrite Date field in GMT to local in current buffer.") | |
809 | ||
810 | (autoload 'metamail-buffer "metamail" | |
811 | "Process current buffer through 'metamail'." t) | |
812 | ||
813 | (autoload 'timezone-make-sortable-date "timezone") | |
814 | (autoload 'timezone-parse-date "timezone") | |
745bc783 JB |
815 | |
816 | (autoload 'rmail-output "rmailout" | |
817 | "Append this message to Unix mail file named FILE-NAME." t) | |
818 | (autoload 'mail-position-on-field "sendmail") | |
819 | (autoload 'mh-find-path "mh-e") | |
820 | (autoload 'mh-prompt-for-folder "mh-e") | |
821 | ||
b027f415 RS |
822 | (put 'gnus-group-mode 'mode-class 'special) |
823 | (put 'gnus-summary-mode 'mode-class 'special) | |
824 | (put 'gnus-article-mode 'mode-class 'special) | |
745bc783 JB |
825 | |
826 | \f | |
b027f415 | 827 | ;;(put 'gnus-eval-in-buffer-window 'lisp-indent-hook 1) |
745bc783 JB |
828 | |
829 | (defmacro gnus-eval-in-buffer-window (buffer &rest forms) | |
830 | "Pop to BUFFER, evaluate FORMS, and then returns to original window." | |
831 | (` (let ((GNUSStartBufferWindow (selected-window))) | |
832 | (unwind-protect | |
833 | (progn | |
834 | (pop-to-buffer (, buffer)) | |
835 | (,@ forms)) | |
836 | (select-window GNUSStartBufferWindow))))) | |
837 | ||
b027f415 RS |
838 | (defmacro gnus-make-hashtable (&optional hashsize) |
839 | "Make a hash table (default and minimum size is 200). | |
840 | Optional argument HASHSIZE specifies the table size." | |
841 | (` (make-vector (, (if hashsize (` (max (, hashsize) 200)) 200)) 0))) | |
745bc783 JB |
842 | |
843 | (defmacro gnus-gethash (string hashtable) | |
844 | "Get hash value of STRING in HASHTABLE." | |
845 | ;;(` (symbol-value (abbrev-symbol (, string) (, hashtable)))) | |
b027f415 RS |
846 | ;;(` (abbrev-expansion (, string) (, hashtable))) |
847 | (` (symbol-value (intern-soft (, string) (, hashtable))))) | |
745bc783 JB |
848 | |
849 | (defmacro gnus-sethash (string value hashtable) | |
850 | "Set hash value. Arguments are STRING, VALUE, and HASHTABLE." | |
851 | ;; We cannot use define-abbrev since it only accepts string as value. | |
852 | (` (set (intern (, string) (, hashtable)) (, value)))) | |
853 | ||
854 | ;; Note: Macros defined here are also defined in nntp.el. I don't like | |
855 | ;; to put them here, but many users got troubled with the old | |
856 | ;; definitions in nntp.elc. These codes are NNTP 3.10 version. | |
857 | ||
858 | (defmacro nntp-header-number (header) | |
859 | "Return article number in HEADER." | |
860 | (` (aref (, header) 0))) | |
861 | ||
862 | (defmacro nntp-set-header-number (header number) | |
863 | "Set article number of HEADER to NUMBER." | |
864 | (` (aset (, header) 0 (, number)))) | |
865 | ||
866 | (defmacro nntp-header-subject (header) | |
867 | "Return subject string in HEADER." | |
868 | (` (aref (, header) 1))) | |
869 | ||
870 | (defmacro nntp-set-header-subject (header subject) | |
871 | "Set article subject of HEADER to SUBJECT." | |
872 | (` (aset (, header) 1 (, subject)))) | |
873 | ||
874 | (defmacro nntp-header-from (header) | |
875 | "Return author string in HEADER." | |
876 | (` (aref (, header) 2))) | |
877 | ||
878 | (defmacro nntp-set-header-from (header from) | |
879 | "Set article author of HEADER to FROM." | |
880 | (` (aset (, header) 2 (, from)))) | |
881 | ||
882 | (defmacro nntp-header-xref (header) | |
883 | "Return xref string in HEADER." | |
884 | (` (aref (, header) 3))) | |
885 | ||
886 | (defmacro nntp-set-header-xref (header xref) | |
887 | "Set article xref of HEADER to xref." | |
888 | (` (aset (, header) 3 (, xref)))) | |
889 | ||
890 | (defmacro nntp-header-lines (header) | |
891 | "Return lines in HEADER." | |
892 | (` (aref (, header) 4))) | |
893 | ||
894 | (defmacro nntp-set-header-lines (header lines) | |
895 | "Set article lines of HEADER to LINES." | |
896 | (` (aset (, header) 4 (, lines)))) | |
897 | ||
898 | (defmacro nntp-header-date (header) | |
899 | "Return date in HEADER." | |
900 | (` (aref (, header) 5))) | |
901 | ||
902 | (defmacro nntp-set-header-date (header date) | |
903 | "Set article date of HEADER to DATE." | |
904 | (` (aset (, header) 5 (, date)))) | |
905 | ||
906 | (defmacro nntp-header-id (header) | |
907 | "Return Id in HEADER." | |
908 | (` (aref (, header) 6))) | |
909 | ||
910 | (defmacro nntp-set-header-id (header id) | |
911 | "Set article Id of HEADER to ID." | |
912 | (` (aset (, header) 6 (, id)))) | |
913 | ||
914 | (defmacro nntp-header-references (header) | |
915 | "Return references in HEADER." | |
916 | (` (aref (, header) 7))) | |
917 | ||
918 | (defmacro nntp-set-header-references (header ref) | |
919 | "Set article references of HEADER to REF." | |
920 | (` (aset (, header) 7 (, ref)))) | |
921 | ||
922 | \f | |
923 | ;;; | |
924 | ;;; GNUS Group Mode | |
925 | ;;; | |
926 | ||
b027f415 | 927 | (if gnus-group-mode-map |
745bc783 | 928 | nil |
b027f415 RS |
929 | (setq gnus-group-mode-map (make-keymap)) |
930 | (suppress-keymap gnus-group-mode-map) | |
931 | (define-key gnus-group-mode-map " " 'gnus-group-read-group) | |
932 | (define-key gnus-group-mode-map "=" 'gnus-group-select-group) | |
933 | (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group) | |
934 | (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group) | |
935 | (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group) | |
936 | (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group) | |
937 | (define-key gnus-group-mode-map "N" 'gnus-group-next-group) | |
938 | (define-key gnus-group-mode-map "P" 'gnus-group-prev-group) | |
939 | (define-key gnus-group-mode-map "\C-n" 'gnus-group-next-group) | |
940 | (define-key gnus-group-mode-map "\C-p" 'gnus-group-prev-group) | |
941 | (define-key gnus-group-mode-map "\r" 'next-line) | |
942 | ;;(define-key gnus-group-mode-map "/" 'isearch-forward) | |
943 | (define-key gnus-group-mode-map "<" 'beginning-of-buffer) | |
944 | (define-key gnus-group-mode-map ">" 'end-of-buffer) | |
945 | (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group) | |
946 | (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group) | |
947 | (define-key gnus-group-mode-map "c" 'gnus-group-catchup) | |
948 | (define-key gnus-group-mode-map "C" 'gnus-group-catchup-all) | |
949 | (define-key gnus-group-mode-map "l" 'gnus-group-list-groups) | |
950 | (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups) | |
951 | (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news) | |
952 | (define-key gnus-group-mode-map "R" 'gnus-group-restart) | |
953 | (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups) | |
954 | (define-key gnus-group-mode-map "r" 'gnus-group-restrict-groups) | |
955 | (define-key gnus-group-mode-map "a" 'gnus-group-post-news) | |
956 | (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill) | |
957 | (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill) | |
958 | (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group) | |
959 | (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group) | |
960 | (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region) | |
961 | (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups) | |
962 | (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-list-killed-groups) | |
963 | (define-key gnus-group-mode-map "V" 'gnus-version) | |
964 | ;;(define-key gnus-group-mode-map "x" 'gnus-group-force-update) | |
965 | (define-key gnus-group-mode-map "s" 'gnus-group-force-update) | |
966 | (define-key gnus-group-mode-map "z" 'gnus-group-suspend) | |
967 | (define-key gnus-group-mode-map "q" 'gnus-group-exit) | |
968 | (define-key gnus-group-mode-map "Q" 'gnus-group-quit) | |
969 | (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly) | |
970 | (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node)) | |
971 | ||
972 | (defun gnus-group-mode () | |
745bc783 JB |
973 | "Major mode for reading network news. |
974 | All normal editing commands are turned off. | |
975 | Instead, these commands are available: | |
b027f415 RS |
976 | |
977 | SPC Read articles in this newsgroup. | |
978 | = Select this newsgroup. | |
979 | j Move to the specified newsgroup. | |
980 | n Move to the next unread newsgroup. | |
981 | p Move to the previous unread newsgroup. | |
982 | C-n Move to the next newsgroup. | |
983 | C-p Move to the previous newsgroup. | |
984 | < Move point to the beginning of this buffer. | |
985 | > Move point to the end of this buffer. | |
986 | u Unsubscribe from (subscribe to) this newsgroup. | |
987 | U Unsubscribe from (subscribe to) the specified newsgroup. | |
988 | c Mark all articles as read, preserving marked articles. | |
989 | C Mark all articles in this newsgroup as read. | |
990 | l Revert this buffer. | |
991 | L List all newsgroups. | |
992 | g Get new news. | |
993 | R Force to read the raw .newsrc file and get new news. | |
994 | b Check bogus newsgroups. | |
995 | r Restrict visible newsgroups to the current region. | |
996 | a Post a new article. | |
997 | ESC k Edit a local KILL file applied to this newsgroup. | |
998 | ESC K Edit a global KILL file applied to all newsgroups. | |
999 | C-k Kill this newsgroup. | |
1000 | C-y Yank killed newsgroup here. | |
1001 | C-w Kill newsgroups in current region (excluding current point). | |
1002 | C-x C-t Exchange this newsgroup and previous newsgroup. | |
1003 | C-c C-l list killed newsgroups. | |
1004 | s Save .newsrc file. | |
1005 | z Suspend reading news. | |
1006 | q Quit reading news. | |
1007 | Q Quit reading news without saving .newsrc file. | |
1008 | V Show the version number of this GNUS. | |
1009 | ? Describe Group Mode commands briefly. | |
1010 | C-h m Describe Group Mode. | |
1011 | C-c C-i Read Info about Group Mode. | |
745bc783 JB |
1012 | |
1013 | The name of the host running NNTP server is asked for if no default | |
1014 | host is specified. It is also possible to choose another NNTP server | |
1015 | even when the default server is defined by giving a prefix argument to | |
1016 | the command `\\[gnus]'. | |
1017 | ||
1018 | If an NNTP server is preceded by a colon such as `:Mail', the user's | |
1019 | private directory `~/Mail' is used as a news spool. This makes it | |
1020 | possible to read mail stored in MH folders or articles saved by GNUS. | |
1021 | File names of mail or articles must consist of only numeric | |
1022 | characters. Otherwise, they are ignored. | |
1023 | ||
1024 | If there is a file named `~/.newsrc-SERVER', it is used as the | |
1025 | startup file instead of standard one when talking to SERVER. It is | |
1026 | possible to talk to many hosts by using different startup files for | |
1027 | each. | |
1028 | ||
1029 | Option `-n' of the options line in the startup file is recognized | |
1030 | properly the same as the Bnews system. For example, if the options | |
1031 | line is `options -n !talk talk.rumors', newsgroups under the `talk' | |
1032 | hierarchy except for `talk.rumors' are ignored while checking new | |
1033 | newsgroups. | |
1034 | ||
1035 | If there is a file named `~/.signature-DISTRIBUTION', it is used as | |
1036 | signature file instead of standard one when posting a news in | |
1037 | DISTRIBUTION. | |
1038 | ||
1039 | If an Info file generated from `gnus.texinfo' is installed, you can | |
1040 | read an appropriate Info node of the Info file according to the | |
b027f415 | 1041 | current major mode of GNUS by \\[gnus-info-find-node]. |
745bc783 JB |
1042 | |
1043 | The variable `gnus-version', `nntp-version', `nnspool-version', and | |
1044 | `mhspool-version' have the version numbers of this version of gnus.el, | |
1045 | nntp.el, nnspool.el, and mhspoo.el, respectively. | |
1046 | ||
1047 | User customizable variables: | |
1048 | gnus-nntp-server | |
1049 | Specifies the name of the host running the NNTP server. If its | |
1050 | value is a string such as `:DIRECTORY', the user's private | |
b027f415 RS |
1051 | DIRECTORY is used as a news spool. The variable is initialized |
1052 | from the NNTPSERVER environment variable. | |
745bc783 JB |
1053 | |
1054 | gnus-nntp-service | |
b027f415 RS |
1055 | Specifies a NNTP service name. It is usually \"nntp\" or 119. |
1056 | Nil forces GNUS to use a local news spool if the variable | |
1057 | `gnus-nntp-server' is set to the local host name. | |
745bc783 JB |
1058 | |
1059 | gnus-startup-file | |
b027f415 RS |
1060 | Specifies a startup file (.newsrc). If there is a file named |
1061 | `.newsrc-SERVER', it's used instead when talking to SERVER. I | |
745bc783 JB |
1062 | recommend you to use the server specific file, if you'd like to |
1063 | talk to many servers. Especially if you'd like to read your | |
1064 | private directory, the name of the file must be | |
1065 | `.newsrc-:DIRECTORY'. | |
1066 | ||
1067 | gnus-signature-file | |
b027f415 | 1068 | Specifies a signature file (.signature). If there is a file named |
745bc783 | 1069 | `.signature-DISTRIBUTION', it's used instead when posting an |
b027f415 RS |
1070 | article in DISTRIBUTION. Set the variable to nil to prevent |
1071 | appending the file automatically. If you use an NNTP inews which | |
745bc783 JB |
1072 | comes with the NNTP package, you may have to set the variable to |
1073 | nil. | |
1074 | ||
1075 | gnus-use-cross-reference | |
1076 | Specifies what to do with cross references (Xref: field). If it | |
1077 | is nil, cross references are ignored. If it is t, articles in | |
1078 | subscribed newsgroups are only marked as read. Otherwise, if it | |
1079 | is not nil nor t, articles in all newsgroups are marked as read. | |
1080 | ||
1081 | gnus-use-followup-to | |
1082 | Specifies what to do with followup-to: field. If it is nil, its | |
1083 | value is ignored. If it is non-nil, its value is used as followup | |
1084 | newsgroups. Especially, if it is t and field value is `poster', | |
1085 | your confirmation is required. | |
1086 | ||
1087 | gnus-author-copy | |
1088 | Specifies a file name to save a copy of article you posted using | |
1089 | FCC: field. If the first character of the value is `|', the | |
1090 | contents of the article is piped out to a program specified by the | |
1091 | rest of the value. The variable is initialized from the | |
1092 | AUTHORCOPY environment variable. | |
1093 | ||
1094 | gnus-author-copy-saver | |
1095 | Specifies a function to save an author copy. The function is | |
1096 | called with a file name. The default function `rmail-output' | |
1097 | saves in Unix mail format. | |
1098 | ||
1099 | gnus-kill-file-name | |
1100 | Use specified file name as a KILL file (default to `KILL'). | |
1101 | ||
1102 | gnus-novice-user | |
1103 | Non-nil means that you are a novice to USENET. If non-nil, | |
1104 | verbose messages may be displayed or your confirmations may be | |
1105 | required. | |
1106 | ||
1107 | gnus-interactive-post | |
1108 | Non-nil means that newsgroup, subject and distribution are asked | |
1109 | for interactively when posting a new article. | |
1110 | ||
1111 | gnus-use-full-window | |
1112 | Non-nil means to take up the entire screen of Emacs. | |
1113 | ||
1114 | gnus-window-configuration | |
b027f415 | 1115 | Specifies the configuration of Group, Summary, and Article |
745bc783 | 1116 | windows. It is a list of (ACTION (G S A)), where G, S, and A are |
b027f415 RS |
1117 | the relative height of Group, Summary, and Article windows, |
1118 | respectively. ACTION is `summary', `newsgroups', or `article'. | |
745bc783 JB |
1119 | |
1120 | gnus-subscribe-newsgroup-method | |
1121 | Specifies a function called with a newsgroup name when new | |
1122 | newsgroup is found. The default definition adds new newsgroup at | |
1123 | the beginning of other newsgroups. | |
1124 | ||
b027f415 RS |
1125 | And more and more. Please refer to texinfo documentation. |
1126 | ||
745bc783 | 1127 | Various hooks for customization: |
b027f415 | 1128 | gnus-group-mode-hook |
745bc783 JB |
1129 | Entry to this mode calls the value with no arguments, if that |
1130 | value is non-nil. This hook is called before GNUS is connected to | |
1131 | the NNTP server. So, you can change or define the NNTP server in | |
1132 | this hook. | |
1133 | ||
b027f415 | 1134 | gnus-startup-hook |
745bc783 JB |
1135 | Called with no arguments after the NNTP server is selected. It is |
1136 | possible to change the behavior of GNUS or initialize the | |
1137 | variables according to the selected NNTP server. | |
1138 | ||
b027f415 | 1139 | gnus-group-prepare-hook |
745bc783 JB |
1140 | Called with no arguments after a newsgroup list is created in the |
1141 | Newsgroup buffer, if that value is non-nil. | |
1142 | ||
b027f415 | 1143 | gnus-save-newsrc-hook |
745bc783 JB |
1144 | Called with no arguments when saving newsrc file if that value is |
1145 | non-nil. | |
1146 | ||
b027f415 RS |
1147 | gnus-prepare-article-hook |
1148 | Called with no arguments after preparing message body, but before | |
1149 | preparing header fields which is automatically generated if that | |
1150 | value is non-nil. The default hook (gnus-inews-insert-signature) | |
1151 | inserts a signature file. | |
1152 | ||
1153 | gnus-inews-article-hook | |
745bc783 | 1154 | Called with no arguments when posting an article if that value is |
b027f415 RS |
1155 | non-nil. This hook is called just before posting an article. The |
1156 | default hook does FCC (save an article to the specified file). | |
745bc783 | 1157 | |
b027f415 | 1158 | gnus-suspend-gnus-hook |
745bc783 JB |
1159 | Called with no arguments when suspending (not exiting) GNUS, if |
1160 | that value is non-nil. | |
1161 | ||
b027f415 | 1162 | gnus-exit-gnus-hook |
745bc783 JB |
1163 | Called with no arguments when exiting (not suspending) GNUS, if |
1164 | that value is non-nil." | |
1165 | (interactive) | |
1166 | (kill-all-local-variables) | |
1167 | ;; Gee. Why don't you upgrade? | |
1168 | (cond ((boundp 'mode-line-modified) | |
1169 | (setq mode-line-modified "--- ")) | |
1170 | ((listp (default-value 'mode-line-format)) | |
1171 | (setq mode-line-format | |
1172 | (cons "--- " (cdr (default-value 'mode-line-format))))) | |
1173 | (t | |
1174 | (setq mode-line-format | |
1175 | "--- GNUS: List of Newsgroups %[(%m)%]----%3p-%-"))) | |
b027f415 | 1176 | (setq major-mode 'gnus-group-mode) |
745bc783 JB |
1177 | (setq mode-name "Newsgroup") |
1178 | (setq mode-line-buffer-identification "GNUS: List of Newsgroups") | |
1179 | (setq mode-line-process nil) | |
b027f415 RS |
1180 | (use-local-map gnus-group-mode-map) |
1181 | (buffer-flush-undo (current-buffer)) | |
745bc783 | 1182 | (setq buffer-read-only t) ;Disable modification |
b027f415 | 1183 | (run-hooks 'gnus-group-mode-hook)) |
745bc783 JB |
1184 | |
1185 | ;;;###autoload | |
1186 | (defun gnus (&optional confirm) | |
1187 | "Read network news. | |
1188 | If optional argument CONFIRM is non-nil, ask NNTP server." | |
1189 | (interactive "P") | |
1190 | (unwind-protect | |
1191 | (progn | |
b027f415 RS |
1192 | (switch-to-buffer (get-buffer-create gnus-group-buffer)) |
1193 | (gnus-group-mode) | |
745bc783 JB |
1194 | (gnus-start-news-server confirm)) |
1195 | (if (not (gnus-server-opened)) | |
b027f415 | 1196 | (gnus-group-quit) |
745bc783 JB |
1197 | ;; NNTP server is successfully open. |
1198 | (setq mode-line-process (format " {%s}" gnus-nntp-server)) | |
1199 | (let ((buffer-read-only nil)) | |
1200 | (erase-buffer) | |
b027f415 | 1201 | (gnus-group-startup-message) |
745bc783 | 1202 | (sit-for 0)) |
b027f415 RS |
1203 | (run-hooks 'gnus-startup-hook) |
1204 | (gnus-setup-news) | |
745bc783 | 1205 | (if gnus-novice-user |
b027f415 RS |
1206 | (gnus-group-describe-briefly)) ;Show brief help message. |
1207 | (gnus-group-list-groups nil) | |
745bc783 JB |
1208 | ))) |
1209 | ||
b027f415 | 1210 | (defun gnus-group-startup-message () |
745bc783 JB |
1211 | "Insert startup message in current buffer." |
1212 | ;; Insert the message. | |
44cdca98 RS |
1213 | (insert |
1214 | (format " | |
1215 | %s | |
745bc783 JB |
1216 | |
1217 | NNTP-based News Reader for GNU Emacs | |
1218 | ||
1219 | ||
1220 | If you have any trouble with this software, please let me | |
1221 | know. I will fix your problems in the next release. | |
1222 | ||
1223 | Comments, suggestions, and bug fixes are welcome. | |
1224 | ||
1225 | Masanobu UMEDA | |
44cdca98 | 1226 | umerin@mse.kyutech.ac.jp" gnus-version)) |
745bc783 JB |
1227 | ;; And then hack it. |
1228 | ;; 57 is the longest line. | |
1229 | (indent-rigidly (point-min) (point-max) (/ (max (- (window-width) 57) 0) 2)) | |
1230 | (goto-char (point-min)) | |
1231 | ;; +4 is fuzzy factor. | |
1232 | (insert-char ?\n (/ (max (- (window-height) 18) 0) 2))) | |
1233 | ||
b027f415 | 1234 | (defun gnus-group-list-groups (show-all) |
745bc783 JB |
1235 | "List newsgroups in the Newsgroup buffer. |
1236 | If argument SHOW-ALL is non-nil, unsubscribed groups are also listed." | |
1237 | (interactive "P") | |
b027f415 RS |
1238 | (let ((case-fold-search nil) |
1239 | (last-group ;Current newsgroup. | |
1240 | (gnus-group-group-name)) | |
745bc783 JB |
1241 | (next-group ;Next possible newsgroup. |
1242 | (progn | |
b027f415 RS |
1243 | (gnus-group-search-forward nil nil) |
1244 | (gnus-group-group-name))) | |
745bc783 JB |
1245 | (prev-group ;Previous possible newsgroup. |
1246 | (progn | |
b027f415 RS |
1247 | (gnus-group-search-forward t nil) |
1248 | (gnus-group-group-name)))) | |
1249 | (set-buffer gnus-group-buffer) ;May call from out of Group buffer | |
1250 | (gnus-group-prepare show-all) | |
745bc783 JB |
1251 | (if (zerop (buffer-size)) |
1252 | (message "No news is good news") | |
1253 | ;; Go to last newsgroup if possible. If cannot, try next and | |
1254 | ;; previous. If all fail, go to first unread newsgroup. | |
1255 | (goto-char (point-min)) | |
1256 | (or (and last-group | |
b027f415 | 1257 | (re-search-forward (gnus-group-make-regexp last-group) nil t)) |
745bc783 | 1258 | (and next-group |
b027f415 | 1259 | (re-search-forward (gnus-group-make-regexp next-group) nil t)) |
745bc783 | 1260 | (and prev-group |
b027f415 RS |
1261 | (re-search-forward (gnus-group-make-regexp prev-group) nil t)) |
1262 | (gnus-group-search-forward nil nil t)) | |
745bc783 JB |
1263 | ;; Adjust cursor point. |
1264 | (beginning-of-line) | |
1265 | (search-forward ":" nil t) | |
1266 | ))) | |
1267 | ||
b027f415 | 1268 | (defun gnus-group-prepare (&optional all) |
745bc783 JB |
1269 | "Prepare list of newsgroups in current buffer. |
1270 | If optional argument ALL is non-nil, unsubscribed groups are also listed." | |
1271 | (let ((buffer-read-only nil) | |
1272 | (newsrc gnus-newsrc-assoc) | |
1273 | (group-info nil) | |
1274 | (group-name nil) | |
1275 | (unread-count 0) | |
1276 | ;; This specifies the format of Group buffer. | |
1277 | (cntl "%s%s%5d: %s\n")) | |
1278 | (erase-buffer) | |
1279 | ;; List newsgroups. | |
1280 | (while newsrc | |
1281 | (setq group-info (car newsrc)) | |
1282 | (setq group-name (car group-info)) | |
1283 | (setq unread-count (nth 1 (gnus-gethash group-name gnus-unread-hashtb))) | |
1284 | (if (or all | |
1285 | (and (nth 1 group-info) ;Subscribed. | |
1286 | (> unread-count 0))) ;There are unread articles. | |
b027f415 | 1287 | ;; Yes, I can use gnus-group-prepare-line, but this is faster. |
745bc783 JB |
1288 | (insert |
1289 | (format cntl | |
1290 | ;; Subscribed or not. | |
1291 | (if (nth 1 group-info) " " "U") | |
1292 | ;; Has new news? | |
1293 | (if (and (> unread-count 0) | |
1294 | (>= 0 | |
1295 | (- unread-count | |
1296 | (length | |
b027f415 RS |
1297 | (cdr (gnus-gethash group-name |
1298 | gnus-marked-hashtb)))))) | |
745bc783 JB |
1299 | "*" " ") |
1300 | ;; Number of unread articles. | |
1301 | unread-count | |
1302 | ;; Newsgroup name. | |
1303 | group-name)) | |
1304 | ) | |
1305 | (setq newsrc (cdr newsrc)) | |
1306 | ) | |
1307 | (setq gnus-have-all-newsgroups all) | |
1308 | (goto-char (point-min)) | |
b027f415 | 1309 | (run-hooks 'gnus-group-prepare-hook) |
745bc783 JB |
1310 | )) |
1311 | ||
b027f415 | 1312 | (defun gnus-group-prepare-line (info) |
745bc783 JB |
1313 | "Return a string for the Newsgroup buffer from INFO. |
1314 | INFO is an element of gnus-newsrc-assoc or gnus-killed-assoc." | |
1315 | (let* ((group-name (car info)) | |
1316 | (unread-count | |
1317 | (or (nth 1 (gnus-gethash group-name gnus-unread-hashtb)) | |
1318 | ;; Not in hash table, so compute it now. | |
1319 | (gnus-number-of-articles | |
1320 | (gnus-difference-of-range | |
1321 | (nth 2 (gnus-gethash group-name gnus-active-hashtb)) | |
1322 | (nthcdr 2 info))))) | |
1323 | ;; This specifies the format of Group buffer. | |
1324 | (cntl "%s%s%5d: %s\n")) | |
1325 | (format cntl | |
1326 | ;; Subscribed or not. | |
1327 | (if (nth 1 info) " " "U") | |
1328 | ;; Has new news? | |
1329 | (if (and (> unread-count 0) | |
1330 | (>= 0 | |
1331 | (- unread-count | |
1332 | (length | |
b027f415 RS |
1333 | (cdr (gnus-gethash group-name |
1334 | gnus-marked-hashtb)))))) | |
745bc783 JB |
1335 | "*" " ") |
1336 | ;; Number of unread articles. | |
1337 | unread-count | |
1338 | ;; Newsgroup name. | |
1339 | group-name | |
1340 | ))) | |
1341 | ||
b027f415 | 1342 | (defun gnus-group-update-group (group &optional visible-only) |
745bc783 JB |
1343 | "Update newsgroup info of GROUP. |
1344 | If optional argument VISIBLE-ONLY is non-nil, non displayed group is ignored." | |
1345 | (let ((buffer-read-only nil) | |
b027f415 RS |
1346 | (case-fold-search nil) ;appleIIgs vs. appleiigs |
1347 | (regexp (gnus-group-make-regexp group)) | |
745bc783 JB |
1348 | (visible nil)) |
1349 | ;; Buffer may be narrowed. | |
1350 | (save-restriction | |
1351 | (widen) | |
b027f415 RS |
1352 | ;; Search a line to modify. If the buffer is large, the search |
1353 | ;; takes long time. In most cases, current point is on the line | |
1354 | ;; we are looking for. So, first of all, check current line. | |
1355 | ;; And then if current point is in the first half, search from | |
1356 | ;; the beginning. Otherwise, search from the end. | |
1357 | (if (cond ((progn | |
1358 | (beginning-of-line) | |
1359 | (looking-at regexp))) | |
1360 | ((and (> (/ (buffer-size) 2) (point)) ;In the first half. | |
1361 | (progn | |
1362 | (goto-char (point-min)) | |
1363 | (re-search-forward regexp nil t)))) | |
1364 | ((progn | |
1365 | (goto-char (point-max)) | |
1366 | (re-search-backward regexp nil t)))) | |
745bc783 JB |
1367 | ;; GROUP is listed in current buffer. So, delete old line. |
1368 | (progn | |
1369 | (setq visible t) | |
1370 | (beginning-of-line) | |
1371 | (delete-region (point) (progn (forward-line 1) (point))) | |
b027f415 RS |
1372 | ) |
1373 | ;; No such line in the buffer, so insert it at the top. | |
1374 | (goto-char (point-min))) | |
745bc783 JB |
1375 | (if (or visible (not visible-only)) |
1376 | (progn | |
b027f415 RS |
1377 | (insert (gnus-group-prepare-line |
1378 | (gnus-gethash group gnus-newsrc-hashtb))) | |
745bc783 JB |
1379 | (forward-line -1) ;Move point on that line. |
1380 | )) | |
1381 | ))) | |
1382 | ||
b027f415 | 1383 | (defun gnus-group-group-name () |
745bc783 JB |
1384 | "Get newsgroup name around point." |
1385 | (save-excursion | |
1386 | (beginning-of-line) | |
b027f415 | 1387 | (if (looking-at "^.+:[ \t]+\\([^ \t\n]+\\)\\([ \t].*\\|$\\)") |
745bc783 JB |
1388 | (buffer-substring (match-beginning 1) (match-end 1)) |
1389 | ))) | |
1390 | ||
b027f415 RS |
1391 | (defun gnus-group-make-regexp (newsgroup) |
1392 | "Return regexp that matches for a line of NEWSGROUP." | |
1393 | (concat "^.+: " (regexp-quote newsgroup) "\\([ \t].*\\|$\\)")) | |
1394 | ||
1395 | (defun gnus-group-search-forward (backward norest &optional heretoo) | |
1396 | "Search for the next (or previous) newsgroup. | |
1397 | If 1st argument BACKWARD is non-nil, search backward instead. | |
1398 | If 2nd argument NOREST is non-nil, don't care about newsgroup property. | |
1399 | If optional argument HERETOO is non-nil, current line is searched for, too." | |
1400 | (let ((case-fold-search nil) | |
1401 | (func | |
1402 | (if backward | |
1403 | (function re-search-backward) (function re-search-forward))) | |
1404 | (regexp | |
1405 | (format "^%s[ \t]*\\(%s\\):" | |
1406 | (if norest ".." " [ \t]") | |
1407 | (if norest "[0-9]+" "[1-9][0-9]*"))) | |
1408 | (found nil)) | |
1409 | (if backward | |
1410 | (if heretoo | |
1411 | (end-of-line) | |
1412 | (beginning-of-line)) | |
1413 | (if heretoo | |
1414 | (beginning-of-line) | |
1415 | (end-of-line))) | |
1416 | (setq found (funcall func regexp nil t)) | |
1417 | ;; Adjust cursor point. | |
1418 | (beginning-of-line) | |
1419 | (search-forward ":" nil t) | |
1420 | ;; Return T if found. | |
1421 | found | |
1422 | )) | |
1423 | ||
1424 | ;; GNUS Group mode command | |
1425 | ||
1426 | (defun gnus-group-read-group (all &optional no-article) | |
745bc783 JB |
1427 | "Read news in this newsgroup. |
1428 | If argument ALL is non-nil, already read articles become readable. | |
1429 | If optional argument NO-ARTICLE is non-nil, no article body is displayed." | |
1430 | (interactive "P") | |
b027f415 | 1431 | (let ((group (gnus-group-group-name))) ;Newsgroup name to read. |
745bc783 | 1432 | (if group |
b027f415 | 1433 | (gnus-summary-read-group |
745bc783 JB |
1434 | group |
1435 | (or all | |
b027f415 | 1436 | ;;(not (nth 1 (gnus-gethash group gnus-newsrc-hashtb))) ;Unsubscribed |
745bc783 JB |
1437 | (zerop |
1438 | (nth 1 (gnus-gethash group gnus-unread-hashtb)))) ;No unread | |
1439 | no-article | |
1440 | )) | |
1441 | )) | |
1442 | ||
b027f415 | 1443 | (defun gnus-group-select-group (all) |
745bc783 JB |
1444 | "Select this newsgroup. |
1445 | No article is selected automatically. | |
1446 | If argument ALL is non-nil, already read articles become readable." | |
1447 | (interactive "P") | |
b027f415 | 1448 | (gnus-group-read-group all t)) |
745bc783 | 1449 | |
b027f415 | 1450 | (defun gnus-group-jump-to-group (group) |
745bc783 JB |
1451 | "Jump to newsgroup GROUP." |
1452 | (interactive | |
1453 | (list (completing-read "Newsgroup: " gnus-newsrc-assoc nil 'require-match))) | |
b027f415 RS |
1454 | (let ((case-fold-search nil)) |
1455 | (goto-char (point-min)) | |
1456 | (or (re-search-forward (gnus-group-make-regexp group) nil t) | |
1457 | (if (gnus-gethash group gnus-newsrc-hashtb) | |
1458 | ;; Add GROUP entry, then seach again. | |
1459 | (gnus-group-update-group group))) | |
745bc783 JB |
1460 | ;; Adjust cursor point. |
1461 | (beginning-of-line) | |
1462 | (search-forward ":" nil t) | |
745bc783 JB |
1463 | )) |
1464 | ||
b027f415 | 1465 | (defun gnus-group-next-group (n) |
745bc783 JB |
1466 | "Go to next N'th newsgroup." |
1467 | (interactive "p") | |
1468 | (while (and (> n 1) | |
b027f415 | 1469 | (gnus-group-search-forward nil t)) |
745bc783 | 1470 | (setq n (1- n))) |
b027f415 | 1471 | (or (gnus-group-search-forward nil t) |
745bc783 JB |
1472 | (message "No more newsgroups"))) |
1473 | ||
b027f415 | 1474 | (defun gnus-group-next-unread-group (n) |
745bc783 JB |
1475 | "Go to next N'th unread newsgroup." |
1476 | (interactive "p") | |
1477 | (while (and (> n 1) | |
b027f415 | 1478 | (gnus-group-search-forward nil nil)) |
745bc783 | 1479 | (setq n (1- n))) |
b027f415 | 1480 | (or (gnus-group-search-forward nil nil) |
745bc783 JB |
1481 | (message "No more unread newsgroups"))) |
1482 | ||
b027f415 | 1483 | (defun gnus-group-prev-group (n) |
745bc783 JB |
1484 | "Go to previous N'th newsgroup." |
1485 | (interactive "p") | |
1486 | (while (and (> n 1) | |
b027f415 | 1487 | (gnus-group-search-forward t t)) |
745bc783 | 1488 | (setq n (1- n))) |
b027f415 | 1489 | (or (gnus-group-search-forward t t) |
745bc783 JB |
1490 | (message "No more newsgroups"))) |
1491 | ||
b027f415 | 1492 | (defun gnus-group-prev-unread-group (n) |
745bc783 JB |
1493 | "Go to previous N'th unread newsgroup." |
1494 | (interactive "p") | |
1495 | (while (and (> n 1) | |
b027f415 | 1496 | (gnus-group-search-forward t nil)) |
745bc783 | 1497 | (setq n (1- n))) |
b027f415 | 1498 | (or (gnus-group-search-forward t nil) |
745bc783 JB |
1499 | (message "No more unread newsgroups"))) |
1500 | ||
b027f415 | 1501 | (defun gnus-group-catchup (all) |
745bc783 JB |
1502 | "Mark all articles not marked as unread in current newsgroup as read. |
1503 | If prefix argument ALL is non-nil, all articles are marked as read. | |
1504 | Cross references (Xref: field) of articles are ignored." | |
1505 | (interactive "P") | |
b027f415 | 1506 | (let* ((group (gnus-group-group-name)) |
745bc783 | 1507 | (marked (if (not all) |
b027f415 | 1508 | (cdr (gnus-gethash group gnus-marked-hashtb))))) |
745bc783 | 1509 | (and group |
b027f415 | 1510 | (or (not gnus-interactive-catchup) ;Without confirmation? |
745bc783 JB |
1511 | (y-or-n-p |
1512 | (if all | |
1513 | "Do you really want to mark everything as read? " | |
1514 | "Delete all articles not marked as read? "))) | |
1515 | (progn | |
b027f415 | 1516 | (message "") ;Clear "Yes or No" question. |
745bc783 JB |
1517 | ;; Any marked articles will be preserved. |
1518 | (gnus-update-unread-articles group marked marked) | |
b027f415 RS |
1519 | (gnus-group-update-group group) |
1520 | (gnus-group-next-group 1))) | |
745bc783 JB |
1521 | )) |
1522 | ||
b027f415 | 1523 | (defun gnus-group-catchup-all () |
745bc783 JB |
1524 | "Mark all articles in current newsgroup as read. |
1525 | Cross references (Xref: field) of articles are ignored." | |
1526 | (interactive) | |
b027f415 | 1527 | (gnus-group-catchup t)) |
745bc783 | 1528 | |
b027f415 | 1529 | (defun gnus-group-unsubscribe-current-group () |
745bc783 JB |
1530 | "Toggle subscribe from/to unsubscribe current group." |
1531 | (interactive) | |
b027f415 RS |
1532 | (gnus-group-unsubscribe-group (gnus-group-group-name)) |
1533 | (gnus-group-next-group 1)) | |
745bc783 | 1534 | |
b027f415 | 1535 | (defun gnus-group-unsubscribe-group (group) |
745bc783 JB |
1536 | "Toggle subscribe from/to unsubscribe GROUP. |
1537 | New newsgroup is added to .newsrc automatically." | |
1538 | (interactive | |
1539 | (list (completing-read "Newsgroup: " | |
1540 | gnus-active-hashtb nil 'require-match))) | |
b027f415 | 1541 | (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb))) |
745bc783 JB |
1542 | (cond ((not (null newsrc)) |
1543 | ;; Toggle subscription flag. | |
1544 | (setcar (nthcdr 1 newsrc) (not (nth 1 newsrc))) | |
1545 | (gnus-update-newsrc-buffer group) | |
b027f415 | 1546 | (gnus-group-update-group group) |
745bc783 JB |
1547 | ;; Adjust cursor point. |
1548 | (beginning-of-line) | |
1549 | (search-forward ":" nil t)) | |
1550 | ((and (stringp group) | |
1551 | (gnus-gethash group gnus-active-hashtb)) | |
1552 | ;; Add new newsgroup. | |
1553 | (gnus-add-newsgroup group) | |
b027f415 | 1554 | (gnus-group-update-group group) |
745bc783 JB |
1555 | ;; Adjust cursor point. |
1556 | (beginning-of-line) | |
1557 | (search-forward ":" nil t)) | |
1558 | (t (error "No such newsgroup: %s" group))) | |
1559 | )) | |
1560 | ||
b027f415 | 1561 | (defun gnus-group-list-all-groups () |
745bc783 JB |
1562 | "List all of newsgroups in the Newsgroup buffer." |
1563 | (interactive) | |
b027f415 | 1564 | (gnus-group-list-groups t)) |
745bc783 | 1565 | |
b027f415 RS |
1566 | (defun gnus-group-get-new-news () |
1567 | "Get newly arrived articles. In fact, read the active file again." | |
745bc783 | 1568 | (interactive) |
b027f415 RS |
1569 | (gnus-setup-news) |
1570 | (gnus-group-list-groups gnus-have-all-newsgroups)) | |
745bc783 | 1571 | |
b027f415 | 1572 | (defun gnus-group-restart () |
745bc783 JB |
1573 | "Force GNUS to read the raw startup file." |
1574 | (interactive) | |
1575 | (gnus-save-newsrc-file) | |
b027f415 RS |
1576 | (gnus-setup-news t) ;Force to read the raw startup file. |
1577 | (gnus-group-list-groups gnus-have-all-newsgroups)) | |
745bc783 | 1578 | |
b027f415 | 1579 | (defun gnus-group-check-bogus-groups () |
745bc783 JB |
1580 | "Check bogus newsgroups." |
1581 | (interactive) | |
1582 | (gnus-check-bogus-newsgroups t) ;Require confirmation. | |
b027f415 | 1583 | (gnus-group-list-groups gnus-have-all-newsgroups)) |
745bc783 | 1584 | |
b027f415 | 1585 | (defun gnus-group-restrict-groups (start end) |
745bc783 JB |
1586 | "Restrict visible newsgroups to the current region (START and END). |
1587 | Type \\[widen] to remove restriction." | |
1588 | (interactive "r") | |
1589 | (save-excursion | |
1590 | (narrow-to-region (progn | |
1591 | (goto-char start) | |
1592 | (beginning-of-line) | |
1593 | (point)) | |
1594 | (progn | |
1595 | (goto-char end) | |
1596 | (forward-line 1) | |
1597 | (point)))) | |
1598 | (message (substitute-command-keys "Type \\[widen] to remove restriction"))) | |
1599 | ||
b027f415 | 1600 | (defun gnus-group-edit-global-kill () |
745bc783 JB |
1601 | "Edit a global KILL file." |
1602 | (interactive) | |
1603 | (setq gnus-current-kill-article nil) ;No articles selected. | |
b027f415 | 1604 | (gnus-kill-file-edit-file nil) ;Nil stands for global KILL file. |
745bc783 JB |
1605 | (message |
1606 | (substitute-command-keys | |
b027f415 | 1607 | "Editing a global KILL file (Type \\[gnus-kill-file-exit] to exit)"))) |
745bc783 | 1608 | |
b027f415 | 1609 | (defun gnus-group-edit-local-kill () |
745bc783 JB |
1610 | "Edit a local KILL file." |
1611 | (interactive) | |
1612 | (setq gnus-current-kill-article nil) ;No articles selected. | |
b027f415 | 1613 | (gnus-kill-file-edit-file (gnus-group-group-name)) |
745bc783 JB |
1614 | (message |
1615 | (substitute-command-keys | |
b027f415 | 1616 | "Editing a local KILL file (Type \\[gnus-kill-file-exit] to exit)"))) |
745bc783 | 1617 | |
b027f415 | 1618 | (defun gnus-group-force-update () |
745bc783 JB |
1619 | "Update .newsrc file." |
1620 | (interactive) | |
1621 | (gnus-save-newsrc-file)) | |
1622 | ||
b027f415 | 1623 | (defun gnus-group-suspend () |
745bc783 JB |
1624 | "Suspend the current GNUS session. |
1625 | In fact, cleanup buffers except for Group Mode buffer. | |
b027f415 | 1626 | The hook gnus-suspend-gnus-hook is called before actually suspending." |
745bc783 | 1627 | (interactive) |
b027f415 | 1628 | (run-hooks 'gnus-suspend-gnus-hook) |
745bc783 JB |
1629 | ;; Kill GNUS buffers except for Group Mode buffer. |
1630 | (let ((buffers gnus-buffer-list)) | |
1631 | (while buffers | |
b027f415 | 1632 | (and (not (eq (car buffers) gnus-group-buffer)) |
745bc783 JB |
1633 | (get-buffer (car buffers)) |
1634 | (kill-buffer (car buffers))) | |
1635 | (setq buffers (cdr buffers)) | |
1636 | )) | |
1637 | (bury-buffer)) | |
1638 | ||
b027f415 | 1639 | (defun gnus-group-exit () |
745bc783 | 1640 | "Quit reading news after updating .newsrc. |
b027f415 | 1641 | The hook gnus-exit-gnus-hook is called before actually quitting." |
745bc783 JB |
1642 | (interactive) |
1643 | (if (or noninteractive ;For gnus-batch-kill | |
1644 | (zerop (buffer-size)) ;No news is good news. | |
1645 | (not (gnus-server-opened)) ;NNTP connection closed. | |
b027f415 | 1646 | (not gnus-interactive-exit) ;Without confirmation |
745bc783 JB |
1647 | (y-or-n-p "Are you sure you want to quit reading news? ")) |
1648 | (progn | |
1649 | (message "") ;Erase "Yes or No" question. | |
b027f415 | 1650 | (run-hooks 'gnus-exit-gnus-hook) |
745bc783 JB |
1651 | (gnus-save-newsrc-file) |
1652 | (gnus-clear-system) | |
1653 | (gnus-close-server)) | |
1654 | )) | |
1655 | ||
b027f415 | 1656 | (defun gnus-group-quit () |
745bc783 | 1657 | "Quit reading news without updating .newsrc. |
b027f415 | 1658 | The hook gnus-exit-gnus-hook is called before actually quitting." |
745bc783 | 1659 | (interactive) |
b027f415 RS |
1660 | (if (or noninteractive ;For gnus-batch-kill |
1661 | (zerop (buffer-size)) | |
745bc783 JB |
1662 | (not (gnus-server-opened)) |
1663 | (yes-or-no-p | |
1664 | (format "Quit reading news without saving %s? " | |
1665 | (file-name-nondirectory gnus-current-startup-file)))) | |
1666 | (progn | |
1667 | (message "") ;Erase "Yes or No" question. | |
b027f415 | 1668 | (run-hooks 'gnus-exit-gnus-hook) |
745bc783 JB |
1669 | (gnus-clear-system) |
1670 | (gnus-close-server)) | |
1671 | )) | |
1672 | ||
b027f415 | 1673 | (defun gnus-group-describe-briefly () |
745bc783 JB |
1674 | "Describe Group mode commands briefly." |
1675 | (interactive) | |
1676 | (message | |
1677 | (concat | |
b027f415 RS |
1678 | (substitute-command-keys "\\[gnus-group-read-group]:Select ") |
1679 | (substitute-command-keys "\\[gnus-group-next-unread-group]:Forward ") | |
1680 | (substitute-command-keys "\\[gnus-group-prev-unread-group]:Backward ") | |
1681 | (substitute-command-keys "\\[gnus-group-exit]:Exit ") | |
1682 | (substitute-command-keys "\\[gnus-info-find-node]:Run Info ") | |
1683 | (substitute-command-keys "\\[gnus-group-describe-briefly]:This help") | |
745bc783 JB |
1684 | ))) |
1685 | ||
1686 | \f | |
1687 | ;;; | |
b027f415 | 1688 | ;;; GNUS Summary Mode |
745bc783 JB |
1689 | ;;; |
1690 | ||
b027f415 | 1691 | (if gnus-summary-mode-map |
745bc783 | 1692 | nil |
b027f415 RS |
1693 | (setq gnus-summary-mode-map (make-keymap)) |
1694 | (suppress-keymap gnus-summary-mode-map) | |
1695 | (define-key gnus-summary-mode-map " " 'gnus-summary-next-page) | |
1696 | (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page) | |
1697 | (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up) | |
1698 | (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article) | |
1699 | (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article) | |
1700 | (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article) | |
1701 | (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article) | |
1702 | (define-key gnus-summary-mode-map "\e\C-n" 'gnus-summary-next-same-subject) | |
1703 | (define-key gnus-summary-mode-map "\e\C-p" 'gnus-summary-prev-same-subject) | |
1704 | ;;(define-key gnus-summary-mode-map "\e\C-n" 'gnus-summary-next-unread-same-subject) | |
1705 | ;;(define-key gnus-summary-mode-map "\e\C-p" 'gnus-summary-prev-unread-same-subject) | |
1706 | (define-key gnus-summary-mode-map "\C-c\C-n" 'gnus-summary-next-digest) | |
1707 | (define-key gnus-summary-mode-map "\C-c\C-p" 'gnus-summary-prev-digest) | |
1708 | (define-key gnus-summary-mode-map "\C-n" 'gnus-summary-next-subject) | |
1709 | (define-key gnus-summary-mode-map "\C-p" 'gnus-summary-prev-subject) | |
1710 | (define-key gnus-summary-mode-map "\en" 'gnus-summary-next-unread-subject) | |
1711 | (define-key gnus-summary-mode-map "\ep" 'gnus-summary-prev-unread-subject) | |
1712 | ;;(define-key gnus-summary-mode-map "\C-cn" 'gnus-summary-next-group) | |
1713 | ;;(define-key gnus-summary-mode-map "\C-cp" 'gnus-summary-prev-group) | |
1714 | (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article) | |
1715 | ;;(define-key gnus-summary-mode-map "/" 'isearch-forward) | |
1716 | (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article) | |
1717 | (define-key gnus-summary-mode-map "\es" 'gnus-summary-search-article-forward) | |
1718 | ;;(define-key gnus-summary-mode-map "\eS" 'gnus-summary-search-article-backward) | |
1719 | (define-key gnus-summary-mode-map "\er" 'gnus-summary-search-article-backward) | |
1720 | (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article) | |
1721 | (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article) | |
1722 | (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-subject) | |
1723 | ;;(define-key gnus-summary-mode-map "J" 'gnus-summary-goto-article) | |
1724 | (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article) | |
1725 | (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article) | |
1726 | ;;(define-key gnus-summary-mode-map "\er" 'gnus-summary-refer-article) | |
1727 | (define-key gnus-summary-mode-map "\e^" 'gnus-summary-refer-article) | |
1728 | (define-key gnus-summary-mode-map "u" 'gnus-summary-mark-as-unread-forward) | |
1729 | (define-key gnus-summary-mode-map "U" 'gnus-summary-mark-as-unread-backward) | |
1730 | (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward) | |
1731 | (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward) | |
1732 | (define-key gnus-summary-mode-map "\eu" 'gnus-summary-clear-mark-forward) | |
1733 | (define-key gnus-summary-mode-map "\eU" 'gnus-summary-clear-mark-backward) | |
1734 | (define-key gnus-summary-mode-map "k" 'gnus-summary-kill-same-subject-and-select) | |
1735 | (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject) | |
1736 | (define-key gnus-summary-mode-map "\e\C-t" 'gnus-summary-toggle-threads) | |
1737 | (define-key gnus-summary-mode-map "\e\C-s" 'gnus-summary-show-thread) | |
1738 | (define-key gnus-summary-mode-map "\e\C-h" 'gnus-summary-hide-thread) | |
1739 | (define-key gnus-summary-mode-map "\e\C-f" 'gnus-summary-next-thread) | |
1740 | (define-key gnus-summary-mode-map "\e\C-b" 'gnus-summary-prev-thread) | |
1741 | (define-key gnus-summary-mode-map "\e\C-u" 'gnus-summary-up-thread) | |
1742 | (define-key gnus-summary-mode-map "\e\C-d" 'gnus-summary-down-thread) | |
1743 | (define-key gnus-summary-mode-map "\e\C-k" 'gnus-summary-kill-thread) | |
1744 | (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command) | |
1745 | ;;(define-key gnus-summary-mode-map "c" 'gnus-summary-catchup) | |
1746 | ;;(define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-all) | |
1747 | (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit) | |
1748 | ;;(define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-all-and-exit) | |
1749 | (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation) | |
1750 | (define-key gnus-summary-mode-map "x" 'gnus-summary-delete-marked-as-read) | |
1751 | (define-key gnus-summary-mode-map "X" 'gnus-summary-delete-marked-with) | |
1752 | (define-key gnus-summary-mode-map "\C-c\C-sn" 'gnus-summary-sort-by-number) | |
1753 | (define-key gnus-summary-mode-map "\C-c\C-sa" 'gnus-summary-sort-by-author) | |
1754 | (define-key gnus-summary-mode-map "\C-c\C-ss" 'gnus-summary-sort-by-subject) | |
1755 | (define-key gnus-summary-mode-map "\C-c\C-sd" 'gnus-summary-sort-by-date) | |
1756 | (define-key gnus-summary-mode-map "\C-c\C-s\C-n" 'gnus-summary-sort-by-number) | |
1757 | (define-key gnus-summary-mode-map "\C-c\C-s\C-a" 'gnus-summary-sort-by-author) | |
1758 | (define-key gnus-summary-mode-map "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject) | |
1759 | (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date) | |
1760 | (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window) | |
1761 | ;;(define-key gnus-summary-mode-map "G" 'gnus-summary-reselect-current-group) | |
1762 | (define-key gnus-summary-mode-map "\C-x\C-s" 'gnus-summary-reselect-current-group) | |
1763 | (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking) | |
1764 | (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message) | |
1765 | (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article) | |
1766 | (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header) | |
1767 | ;;(define-key gnus-summary-mode-map "v" 'gnus-summary-show-all-headers) | |
1768 | (define-key gnus-summary-mode-map "\et" 'gnus-summary-toggle-mime) | |
1769 | (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-rmail-digest) | |
1770 | (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news) | |
1771 | (define-key gnus-summary-mode-map "f" 'gnus-summary-followup) | |
1772 | (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original) | |
1773 | (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article) | |
1774 | (define-key gnus-summary-mode-map "r" 'gnus-summary-reply) | |
1775 | (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original) | |
1776 | (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward) | |
1777 | (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window) | |
1778 | (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article) | |
1779 | (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-in-mail) | |
1780 | (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output) | |
1781 | (define-key gnus-summary-mode-map "\ek" 'gnus-summary-edit-local-kill) | |
1782 | (define-key gnus-summary-mode-map "\eK" 'gnus-summary-edit-global-kill) | |
1783 | (define-key gnus-summary-mode-map "V" 'gnus-version) | |
1784 | (define-key gnus-summary-mode-map "q" 'gnus-summary-exit) | |
1785 | (define-key gnus-summary-mode-map "Q" 'gnus-summary-quit) | |
1786 | (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly) | |
1787 | (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node)) | |
1788 | ||
1789 | (defun gnus-summary-mode () | |
745bc783 JB |
1790 | "Major mode for reading articles in this newsgroup. |
1791 | All normal editing commands are turned off. | |
1792 | Instead, these commands are available: | |
b027f415 RS |
1793 | |
1794 | SPC Scroll to the next page of the current article. The next unread | |
1795 | article is selected automatically at the end of the message. | |
1796 | DEL Scroll to the previous page of the current article. | |
1797 | RET Scroll up (or down) one line the current article. | |
1798 | n Move to the next unread article. | |
1799 | p Move to the previous unread article. | |
1800 | N Move to the next article. | |
1801 | P Move to the previous article. | |
1802 | ESC C-n Move to the next article which has the same subject as the | |
1803 | current article. | |
1804 | ESC C-p Move to the previous article which has the same subject as the | |
1805 | current article. | |
1806 | \\[gnus-summary-next-unread-same-subject] | |
1807 | Move to the next unread article which has the same subject as the | |
1808 | current article. | |
1809 | \\[gnus-summary-prev-unread-same-subject] | |
1810 | Move to the previous unread article which has the same subject as | |
1811 | the current article. | |
1812 | C-c C-n Scroll to the next digested message of the current article. | |
1813 | C-c C-p Scroll to the previous digested message of the current article. | |
1814 | C-n Move to the next subject. | |
1815 | C-p Move to the previous subject. | |
1816 | ESC n Move to the next unread subject. | |
1817 | ESC p Move to the previous unread subject. | |
1818 | \\[gnus-summary-next-group] | |
1819 | Exit the current newsgroup and select the next unread newsgroup. | |
1820 | \\[gnus-summary-prev-group] | |
1821 | Exit the current newsgroup and select the previous unread newsgroup. | |
1822 | . Jump to the first unread article in the current newsgroup. | |
1823 | s Do an incremental search forward on the current article. | |
1824 | ESC s Search for an article containing a regexp forward. | |
1825 | ESC r Search for an article containing a regexp backward. | |
1826 | < Move point to the beginning of the current article. | |
1827 | > Move point to the end of the current article. | |
1828 | j Jump to the article specified by the numeric article ID. | |
1829 | l Jump to the article you read last. | |
1830 | ^ Refer to parent of the current article. | |
1831 | ESC ^ Refer to the article specified by the Message-ID. | |
1832 | u Mark the current article as unread, and go forward. | |
1833 | U Mark the current article as unread, and go backward. | |
1834 | d Mark the current article as read, and go forward. | |
1835 | D Mark the current article as read, and go backward. | |
1836 | ESC u Clear the current article's mark, and go forward. | |
1837 | ESC U Clear the current article's mark, and go backward. | |
1838 | k Mark articles which has the same subject as the current article as | |
1839 | read, and then select the next unread article. | |
1840 | C-k Mark articles which has the same subject as the current article as | |
1841 | read. | |
1842 | ESC k Edit a local KILL file applied to the current newsgroup. | |
1843 | ESC K Edit a global KILL file applied to all newsgroups. | |
1844 | ESC C-t Toggle showing conversation threads. | |
1845 | ESC C-s Show thread subtrees. | |
1846 | ESC C-h Hide thread subtrees. | |
1847 | \\[gnus-summary-show-all-threads] Show all thread subtrees. | |
1848 | \\[gnus-summary-hide-all-threads] Hide all thread subtrees. | |
1849 | ESC C-f Go to the same level next thread. | |
1850 | ESC C-b Go to the same level previous thread. | |
1851 | ESC C-d Go downward current thread. | |
1852 | ESC C-u Go upward current thread. | |
1853 | ESC C-k Mark articles under current thread as read. | |
1854 | & Execute a command for each article conditionally. | |
1855 | \\[gnus-summary-catchup] | |
1856 | Mark all articles as read in the current newsgroup, preserving | |
1857 | articles marked as unread. | |
1858 | \\[gnus-summary-catchup-all] | |
1859 | Mark all articles as read in the current newsgroup. | |
1860 | \\[gnus-summary-catchup-and-exit] | |
1861 | Catch up all articles not marked as unread, and then exit the | |
1862 | current newsgroup. | |
1863 | \\[gnus-summary-catchup-all-and-exit] | |
1864 | Catch up all articles, and then exit the current newsgroup. | |
1865 | C-t Toggle truncations of subject lines. | |
1866 | x Delete subject lines marked as read. | |
1867 | X Delete subject lines with the specific marks. | |
1868 | C-c C-s C-n Sort subjects by article number. | |
1869 | C-c C-s C-a Sort subjects by article author. | |
1870 | C-c C-s C-s Sort subjects alphabetically. | |
1871 | C-c C-s C-d Sort subjects by date. | |
1872 | = Expand Summary window to show headers full window. | |
1873 | C-x C-s Reselect the current newsgroup. Prefix argument means to select all. | |
1874 | w Stop page breaking by linefeed. | |
1875 | C-c C-r Caesar rotates letters by 13/47 places. | |
1876 | g Force to show the current article. | |
1877 | t Show original article header if pruned header currently shown, or | |
1878 | vice versa. | |
1879 | ESC-t Toggle MIME processing. | |
1880 | C-d Run RMAIL on the current digest article. | |
1881 | a Post a new article. | |
1882 | f Post a reply article. | |
1883 | F Post a reply article with original article. | |
1884 | C Cancel the current article. | |
1885 | r Mail a message to the author. | |
1886 | R Mail a message to the author with original author. | |
1887 | C-c C-f Forward the current message to another user. | |
1888 | m Mail a message in other window. | |
1889 | o Save the current article in your favorite format. | |
1890 | C-o Append the current article to a file in Unix mail format. | |
1891 | | Pipe the contents of the current article to a subprocess. | |
1892 | q Quit reading news in the current newsgroup. | |
1893 | Q Quit reading news without recording unread articles information. | |
1894 | V Show the version number of this GNUS. | |
1895 | ? Describe Summary mode commands briefly. | |
1896 | C-h m Describe Summary mode. | |
1897 | C-c C-i Read Info about Summary mode. | |
745bc783 JB |
1898 | |
1899 | User customizable variables: | |
1900 | gnus-large-newsgroup | |
1901 | The number of articles which indicates a large newsgroup. If the | |
1902 | number of articles in a newsgroup is greater than the value, the | |
b027f415 RS |
1903 | number of articles to be selected is asked for. If the given value |
1904 | N is positive, the last N articles is selected. If N is negative, | |
1905 | the first N articles are selected. An empty string means to select | |
745bc783 JB |
1906 | all articles. |
1907 | ||
1908 | gnus-use-long-file-name | |
1909 | Non-nil means that a newsgroup name is used as a default file name | |
b027f415 | 1910 | to save articles to. If it's nil, the directory form of a |
745bc783 JB |
1911 | newsgroup is used instead. |
1912 | ||
1913 | gnus-default-article-saver | |
1914 | Specifies your favorite article saver which is interactively | |
b027f415 | 1915 | funcallable. Following functions are available: |
745bc783 | 1916 | |
b027f415 RS |
1917 | gnus-summary-save-in-rmail (in Rmail format) |
1918 | gnus-summary-save-in-mail (in Unix mail format) | |
1919 | gnus-summary-save-in-folder (in MH folder) | |
1920 | gnus-summary-save-in-file (in article format). | |
745bc783 JB |
1921 | |
1922 | gnus-rmail-save-name | |
1923 | gnus-mail-save-name | |
1924 | gnus-folder-save-name | |
1925 | gnus-file-save-name | |
1926 | Specifies a function generating a file name to save articles in | |
1927 | specified format. The function is called with NEWSGROUP, HEADERS, | |
1928 | and optional LAST-FILE. Access macros to the headers are defined | |
b027f415 RS |
1929 | as nntp-header-FIELD, and functions are defined as |
1930 | gnus-header-FIELD. | |
745bc783 JB |
1931 | |
1932 | gnus-article-save-directory | |
1933 | Specifies a directory name to save articles to using the commands | |
b027f415 RS |
1934 | gnus-summary-save-in-rmail, gnus-summary-save-in-mail and |
1935 | gnus-summary-save-in-file. The variable is initialized from the | |
745bc783 JB |
1936 | SAVEDIR environment variable. |
1937 | ||
1938 | gnus-show-all-headers | |
1939 | Non-nil means that all headers of an article are shown. | |
1940 | ||
1941 | gnus-save-all-headers | |
1942 | Non-nil means that all headers of an article are saved in a file. | |
1943 | ||
b027f415 RS |
1944 | gnus-show-mime |
1945 | Non-nil means that show a MIME message. | |
1946 | ||
745bc783 JB |
1947 | gnus-show-threads |
1948 | Non-nil means that conversation threads are shown in tree structure. | |
1949 | ||
1950 | gnus-thread-hide-subject | |
1951 | Non-nil means that subjects for thread subtrees are hidden. | |
1952 | ||
1953 | gnus-thread-hide-subtree | |
1954 | Non-nil means that thread subtrees are hidden initially. | |
1955 | ||
1956 | gnus-thread-hide-killed | |
1957 | Non-nil means that killed thread subtrees are hidden automatically. | |
1958 | ||
1959 | gnus-thread-ignore-subject | |
1960 | Non-nil means that subject differences are ignored in constructing | |
1961 | thread trees. | |
1962 | ||
1963 | gnus-thread-indent-level | |
1964 | Indentation of thread subtrees. | |
1965 | ||
1966 | gnus-optional-headers | |
1967 | Specifies a function which generates an optional string displayed | |
b027f415 | 1968 | in the Summary buffer. The function is called with an article |
745bc783 JB |
1969 | HEADERS. The result must be a string excluding `[' and `]'. The |
1970 | default function returns a string like NNN:AUTHOR, where NNN is | |
1971 | the number of lines in an article and AUTHOR is the name of the | |
1972 | author. | |
1973 | ||
1974 | gnus-auto-extend-newsgroup | |
1975 | Non-nil means visible articles are extended to forward and | |
1976 | backward automatically if possible. | |
1977 | ||
1978 | gnus-auto-select-first | |
1979 | Non-nil means the first unread article is selected automagically | |
b027f415 | 1980 | when a newsgroup is selected normally (by gnus-group-read-group). |
745bc783 JB |
1981 | If you'd like to prevent automatic selection of the first unread |
1982 | article in some newsgroups, set the variable to nil in | |
b027f415 | 1983 | gnus-select-group-hook or gnus-apply-kill-hook. |
745bc783 JB |
1984 | |
1985 | gnus-auto-select-next | |
1986 | Non-nil means the next newsgroup is selected automagically at the | |
1987 | end of the newsgroup. If the value is t and the next newsgroup is | |
b027f415 | 1988 | empty (no unread articles), GNUS will exit Summary mode and go |
745bc783 | 1989 | back to Group mode. If the value is neither nil nor t, GNUS won't |
b027f415 | 1990 | exit Summary mode but select the following unread newsgroup. |
745bc783 JB |
1991 | Especially, if the value is the symbol `quietly', the next unread |
1992 | newsgroup will be selected without any confirmations. | |
1993 | ||
1994 | gnus-auto-select-same | |
1995 | Non-nil means an article with the same subject as the current | |
1996 | article is selected automagically like `rn -S'. | |
1997 | ||
b027f415 RS |
1998 | gnus-auto-center-summary |
1999 | Non-nil means the point of Summary Mode window is always kept | |
745bc783 JB |
2000 | centered. |
2001 | ||
2002 | gnus-break-pages | |
2003 | Non-nil means an article is broken into pages at page delimiters. | |
2004 | This may not work with some versions of GNU Emacs earlier than | |
2005 | version 18.50. | |
2006 | ||
2007 | gnus-page-delimiter | |
2008 | Specifies a regexp describing line-beginnings that separate pages | |
2009 | of news article. | |
2010 | ||
2011 | [gnus-more-message is obsolete. overlay-arrow-string interfares | |
2012 | with other subsystems, such as dbx mode.] | |
2013 | ||
2014 | gnus-digest-show-summary | |
2015 | Non-nil means that a summary of digest messages is shown when | |
b027f415 RS |
2016 | reading a digest article using `gnus-summary-rmail-digest' |
2017 | command. | |
745bc783 JB |
2018 | |
2019 | gnus-digest-separator | |
2020 | Specifies a regexp separating messages in a digest article. | |
2021 | ||
2022 | gnus-mail-reply-method | |
2023 | gnus-mail-other-window-method | |
2024 | Specifies a function to begin composing mail message using | |
b027f415 RS |
2025 | commands gnus-summary-reply and gnus-summary-mail-other-window. |
2026 | Functions gnus-mail-reply-using-mail and gnus-mail-reply-using-mhe | |
2027 | are available for the value of gnus-mail-reply-method. And | |
2028 | functions gnus-mail-other-window-using-mail and | |
745bc783 JB |
2029 | gnus-mail-other-window-using-mhe are available for the value of |
2030 | gnus-mail-other-window-method. | |
2031 | ||
b027f415 RS |
2032 | gnus-mail-send-method |
2033 | Specifies a function to mail a message too which is being posted | |
2034 | as an article. The message must have To: or Cc: field. The value | |
2035 | of the variable send-mail-function is the default function which | |
2036 | uses sendmail mail program. | |
2037 | ||
745bc783 | 2038 | Various hooks for customization: |
b027f415 | 2039 | gnus-summary-mode-hook |
745bc783 JB |
2040 | Entry to this mode calls the value with no arguments, if that |
2041 | value is non-nil. | |
2042 | ||
b027f415 | 2043 | gnus-select-group-hook |
745bc783 | 2044 | Called with no arguments when newsgroup is selected, if that value |
b027f415 | 2045 | is non-nil. It is possible to sort subjects in this hook. See the |
745bc783 JB |
2046 | documentation of this variable for more information. |
2047 | ||
b027f415 RS |
2048 | gnus-summary-prepare-hook |
2049 | Called with no arguments after a summary list is created in the | |
2050 | Summary buffer, if that value is non-nil. If you'd like to modify | |
745bc783 JB |
2051 | the buffer, you can use this hook. |
2052 | ||
b027f415 | 2053 | gnus-select-article-hook |
745bc783 | 2054 | Called with no arguments when an article is selected, if that |
b027f415 RS |
2055 | value is non-nil. See the documentation of this variable for more |
2056 | information. | |
745bc783 | 2057 | |
b027f415 | 2058 | gnus-select-digest-hook |
745bc783 | 2059 | Called with no arguments when reading digest messages using Rmail, |
b027f415 RS |
2060 | if that value is non-nil. This hook can be used to modify an |
2061 | article so that Rmail can work with it. See the documentation of | |
745bc783 JB |
2062 | the variable for more information. |
2063 | ||
b027f415 | 2064 | gnus-rmail-digest-hook |
745bc783 | 2065 | Called with no arguments when reading digest messages using Rmail, |
b027f415 | 2066 | if that value is non-nil. This hook is intended to customize Rmail |
745bc783 JB |
2067 | mode. |
2068 | ||
b027f415 | 2069 | gnus-apply-kill-hook |
745bc783 | 2070 | Called with no arguments when a newsgroup is selected and the |
b027f415 RS |
2071 | Summary buffer is prepared. This hook is intended to apply a KILL |
2072 | file to the selected newsgroup. The format of KILL file is | |
745bc783 | 2073 | completely different from that of version 3.8. You have to rewrite |
b027f415 | 2074 | them in the new format. See the documentation of Kill file mode |
745bc783 JB |
2075 | for more information. |
2076 | ||
b027f415 | 2077 | gnus-mark-article-hook |
745bc783 | 2078 | Called with no arguments when an article is selected at the first |
b027f415 | 2079 | time. The hook is intended to mark an article as read (or unread) |
745bc783 JB |
2080 | automatically when it is selected. See the documentation of the |
2081 | variable for more information. | |
2082 | ||
b027f415 | 2083 | gnus-exit-group-hook |
745bc783 | 2084 | Called with no arguments when exiting the current newsgroup, if |
b027f415 RS |
2085 | that value is non-nil. If your machine is so slow that exiting |
2086 | from Summary mode takes very long time, inhibit marking articles | |
745bc783 | 2087 | as read using cross-references by setting the variable |
b027f415 | 2088 | gnus-use-cross-reference to nil in this hook." |
745bc783 JB |
2089 | (interactive) |
2090 | (kill-all-local-variables) | |
2091 | ;; Gee. Why don't you upgrade? | |
2092 | (cond ((boundp 'mode-line-modified) | |
2093 | (setq mode-line-modified "--- ")) | |
2094 | ((listp (default-value 'mode-line-format)) | |
2095 | (setq mode-line-format | |
2096 | (cons "--- " (cdr (default-value 'mode-line-format)))))) | |
b027f415 RS |
2097 | ;; To disable display-time facility. |
2098 | ;;(make-local-variable 'global-mode-string) | |
2099 | ;;(setq global-mode-string nil) | |
2100 | (setq major-mode 'gnus-summary-mode) | |
2101 | (setq mode-name "Summary") | |
745bc783 JB |
2102 | ;;(setq mode-line-process '(" " gnus-newsgroup-name)) |
2103 | (make-local-variable 'minor-mode-alist) | |
2104 | (or (assq 'gnus-show-threads minor-mode-alist) | |
2105 | (setq minor-mode-alist | |
2106 | (cons (list 'gnus-show-threads " Thread") minor-mode-alist))) | |
b027f415 RS |
2107 | (gnus-summary-set-mode-line) |
2108 | (use-local-map gnus-summary-mode-map) | |
2109 | (buffer-flush-undo (current-buffer)) | |
745bc783 JB |
2110 | (setq buffer-read-only t) ;Disable modification |
2111 | (setq truncate-lines t) ;Stop line folding | |
2112 | (setq selective-display t) | |
2113 | (setq selective-display-ellipses t) ;Display `...' | |
2114 | ;;(setq case-fold-search t) | |
b027f415 RS |
2115 | (run-hooks 'gnus-summary-mode-hook)) |
2116 | ||
2117 | (defun gnus-summary-setup-buffer () | |
2118 | "Initialize Summary buffer." | |
2119 | (if (get-buffer gnus-summary-buffer) | |
2120 | (set-buffer gnus-summary-buffer) | |
2121 | (set-buffer (get-buffer-create gnus-summary-buffer)) | |
2122 | (gnus-summary-mode) | |
745bc783 JB |
2123 | )) |
2124 | ||
b027f415 | 2125 | (defun gnus-summary-read-group (group &optional show-all no-article) |
745bc783 | 2126 | "Start reading news in newsgroup GROUP. |
b027f415 | 2127 | If optional 1st argument SHOW-ALL is non-nil, already read articles are |
745bc783 | 2128 | also listed. |
b027f415 | 2129 | If optional 2nd argument NO-ARTICLE is non-nil, no article is selected |
745bc783 JB |
2130 | initially." |
2131 | (message "Retrieving newsgroup: %s..." group) | |
2132 | (if (gnus-select-newsgroup group show-all) | |
2133 | (progn | |
2134 | ;; Don't switch-to-buffer to prevent displaying old contents | |
2135 | ;; of the buffer until new subjects list is created. | |
2136 | ;; Suggested by Juha Heinanen <jh@tut.fi> | |
b027f415 | 2137 | (gnus-summary-setup-buffer) |
745bc783 | 2138 | ;; You can change the order of subjects in this hook. |
b027f415 RS |
2139 | (run-hooks 'gnus-select-group-hook) |
2140 | (gnus-summary-prepare) | |
745bc783 | 2141 | ;; Function `gnus-apply-kill-file' must be called in this hook. |
b027f415 | 2142 | (run-hooks 'gnus-apply-kill-hook) |
745bc783 JB |
2143 | (if (zerop (buffer-size)) |
2144 | ;; This newsgroup is empty. | |
2145 | (progn | |
b027f415 | 2146 | (gnus-summary-catchup-and-exit nil t) ;Without confirmations. |
745bc783 JB |
2147 | (message "No unread news")) |
2148 | ;; Hide conversation thread subtrees. We cannot do this in | |
b027f415 | 2149 | ;; gnus-summary-prepare-hook since kill processing may not |
745bc783 JB |
2150 | ;; work with hidden articles. |
2151 | (and gnus-show-threads | |
2152 | gnus-thread-hide-subtree | |
b027f415 | 2153 | (gnus-summary-hide-all-threads)) |
745bc783 JB |
2154 | ;; Show first unread article if requested. |
2155 | (goto-char (point-min)) | |
2156 | (if (and (not no-article) | |
2157 | gnus-auto-select-first | |
b027f415 | 2158 | (gnus-summary-first-unread-article)) |
745bc783 JB |
2159 | ;; Window is configured automatically. |
2160 | ;; Current buffer may be changed as a result of hook | |
b027f415 | 2161 | ;; evaluation, especially by gnus-summary-rmail-digest |
745bc783 | 2162 | ;; command, so we should adjust cursor point carefully. |
b027f415 | 2163 | (if (eq (current-buffer) (get-buffer gnus-summary-buffer)) |
745bc783 JB |
2164 | (progn |
2165 | ;; Adjust cursor point. | |
2166 | (beginning-of-line) | |
2167 | (search-forward ":" nil t))) | |
b027f415 RS |
2168 | (gnus-configure-windows 'summary) |
2169 | (pop-to-buffer gnus-summary-buffer) | |
2170 | (gnus-summary-set-mode-line) | |
745bc783 | 2171 | ;; I sometime get confused with the old Article buffer. |
b027f415 RS |
2172 | (if (get-buffer gnus-article-buffer) |
2173 | (if (get-buffer-window gnus-article-buffer) | |
745bc783 | 2174 | (save-excursion |
b027f415 | 2175 | (set-buffer gnus-article-buffer) |
745bc783 JB |
2176 | (let ((buffer-read-only nil)) |
2177 | (erase-buffer))) | |
b027f415 | 2178 | (kill-buffer gnus-article-buffer))) |
745bc783 JB |
2179 | ;; Adjust cursor point. |
2180 | (beginning-of-line) | |
2181 | (search-forward ":" nil t)) | |
2182 | )) | |
2183 | ;; Cannot select newsgroup GROUP. | |
2184 | (if (gnus-gethash group gnus-active-hashtb) | |
2185 | (progn | |
2186 | ;; If NNTP is used, nntp_access file may not be installed | |
2187 | ;; properly. Otherwise, may be active file problem. | |
2188 | (ding) | |
b027f415 RS |
2189 | (message |
2190 | (gnus-nntp-message | |
2191 | (format "Cannot select %s. May be security or active file problem." group))) | |
745bc783 JB |
2192 | (sit-for 0)) |
2193 | ;; Check bogus newsgroups. | |
2194 | ;; We must be in Group Mode buffer. | |
b027f415 | 2195 | (gnus-group-check-bogus-groups)) |
745bc783 JB |
2196 | )) |
2197 | ||
b027f415 RS |
2198 | (defun gnus-summary-prepare () |
2199 | "Prepare summary list of current newsgroup in Summary buffer." | |
745bc783 JB |
2200 | (let ((buffer-read-only nil)) |
2201 | ;; Note: The next codes are not actually used because the user who | |
b027f415 | 2202 | ;; want it can define them in gnus-select-group-hook. |
745bc783 JB |
2203 | ;; Print verbose messages if too many articles are selected. |
2204 | ;; (and (numberp gnus-large-newsgroup) | |
2205 | ;; (> (length gnus-newsgroup-headers) gnus-large-newsgroup) | |
2206 | ;; (message "Preparing headers...")) | |
2207 | (erase-buffer) | |
b027f415 | 2208 | (gnus-summary-prepare-threads |
745bc783 JB |
2209 | (if gnus-show-threads |
2210 | (gnus-make-threads gnus-newsgroup-headers) | |
2211 | gnus-newsgroup-headers) 0) | |
2212 | ;; Erase header retrieval message. | |
2213 | (message "") | |
b027f415 | 2214 | ;; Call hooks for modifying Summary buffer. |
745bc783 JB |
2215 | ;; Suggested by sven@tde.LTH.Se (Sven Mattisson). |
2216 | (goto-char (point-min)) | |
b027f415 | 2217 | (run-hooks 'gnus-summary-prepare-hook) |
745bc783 JB |
2218 | )) |
2219 | ||
2220 | ;; Basic ideas by Paul Dworkin <paul@media-lab.media.mit.edu> | |
b027f415 | 2221 | ;; Subject bug fix by jbw@bigbird.bu.edu (Joe Wells) |
745bc783 | 2222 | |
b027f415 RS |
2223 | (defun gnus-summary-prepare-threads (threads level &optional parent-subject) |
2224 | "Prepare Summary buffer from THREADS and indentation LEVEL. | |
2225 | THREADS is a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...]).' | |
2226 | Optional PARENT-SUBJECT specifies the subject of the parent." | |
745bc783 JB |
2227 | (let ((thread nil) |
2228 | (header nil) | |
2229 | (number nil) | |
b027f415 RS |
2230 | (subject nil) |
2231 | (child-subject nil) | |
2232 | (parent-subject (or parent-subject "")) | |
745bc783 JB |
2233 | ;; `M Indent NUM: [OPT] SUBJECT' |
2234 | (cntl (format "%%s %%s%%%dd: [%%s] %%s\n" | |
2235 | (length (prin1-to-string gnus-newsgroup-end))))) | |
2236 | (while threads | |
2237 | (setq thread (car threads)) | |
2238 | (setq threads (cdr threads)) | |
2239 | ;; If thread is a cons, hierarchical threads is given. | |
2240 | ;; Otherwise, thread itself is header. | |
2241 | (if (consp thread) | |
2242 | (setq header (car thread)) | |
2243 | (setq header thread)) | |
2244 | ;; Print valid header only. | |
2245 | (if (vectorp header) ;Depends on nntp.el. | |
2246 | (progn | |
2247 | (setq number (nntp-header-number header)) | |
b027f415 RS |
2248 | (setq subject (nntp-header-subject header)) |
2249 | (setq child-subject (gnus-simplify-subject subject 're-only)) | |
745bc783 JB |
2250 | (insert |
2251 | (format cntl | |
2252 | ;; Read or not. | |
2253 | (cond ((memq number gnus-newsgroup-marked) "-") | |
2254 | ((memq number gnus-newsgroup-unreads) " ") | |
2255 | (t "D")) | |
2256 | ;; Thread level. | |
2257 | (make-string (* level gnus-thread-indent-level) ? ) | |
2258 | ;; Article number. | |
2259 | number | |
2260 | ;; Optional headers. | |
2261 | (or (and gnus-optional-headers | |
2262 | (funcall gnus-optional-headers header)) "") | |
2263 | ;; Its subject string. | |
2264 | (concat (if (or (zerop level) | |
b027f415 RS |
2265 | (not gnus-thread-hide-subject) |
2266 | ;; Subject is different from the parent. | |
2267 | (not (string-equal | |
2268 | parent-subject child-subject))) | |
745bc783 JB |
2269 | nil |
2270 | (make-string (window-width) ? )) | |
b027f415 | 2271 | subject) |
745bc783 JB |
2272 | )) |
2273 | )) | |
2274 | ;; Print subthreads. | |
2275 | (and (consp thread) | |
2276 | (cdr thread) | |
b027f415 RS |
2277 | (gnus-summary-prepare-threads |
2278 | (cdr thread) (1+ level) child-subject)) | |
745bc783 JB |
2279 | ))) |
2280 | ||
b027f415 RS |
2281 | ;;(defun gnus-summary-set-mode-line () |
2282 | ;; "Set Summary mode line string." | |
2283 | ;; ;; The value must be a string to escape %-constructs. | |
2284 | ;; (let ((subject | |
2285 | ;; (if gnus-current-headers | |
2286 | ;; (nntp-header-subject gnus-current-headers) gnus-newsgroup-name))) | |
2287 | ;; (setq mode-line-buffer-identification | |
2288 | ;; (concat "GNUS: " | |
2289 | ;; subject | |
2290 | ;; ;; Enough spaces to pad subject to 17 positions. | |
2291 | ;; (make-string (max 0 (- 17 (length subject))) ? )))) | |
2292 | ;; (set-buffer-modified-p t)) | |
2293 | ||
2294 | ;; New implementation in gnus 3.14.3 | |
2295 | ||
2296 | (defun gnus-summary-set-mode-line () | |
2297 | "Set Summary mode line string. | |
2298 | If you don't like it, define your own gnus-summary-set-mode-line." | |
2299 | (let ((unmarked | |
2300 | (- (length gnus-newsgroup-unreads) | |
2301 | (length (gnus-intersection | |
2302 | gnus-newsgroup-unreads gnus-newsgroup-marked)))) | |
2303 | (unselected | |
2304 | (- (length gnus-newsgroup-unselected) | |
2305 | (length (gnus-intersection | |
2306 | gnus-newsgroup-unselected gnus-newsgroup-marked))))) | |
745bc783 | 2307 | (setq mode-line-buffer-identification |
b027f415 RS |
2308 | (list 17 |
2309 | (format "GNUS: %s%s %s" | |
2310 | gnus-newsgroup-name | |
2311 | (if gnus-current-article | |
2312 | (format "/%d" gnus-current-article) "") | |
2313 | ;; Basic ideas by tale@pawl.rpi.edu. | |
2314 | (cond ((and (zerop unmarked) | |
2315 | (zerop unselected)) | |
2316 | "") | |
2317 | ((zerop unselected) | |
2318 | (format "{%d more}" unmarked)) | |
2319 | (t | |
2320 | (format "{%d(+%d) more}" unmarked unselected))) | |
2321 | )))) | |
745bc783 JB |
2322 | (set-buffer-modified-p t)) |
2323 | ||
b027f415 | 2324 | ;; GNUS Summary mode command. |
745bc783 | 2325 | |
b027f415 | 2326 | (defun gnus-summary-search-group (&optional backward) |
745bc783 JB |
2327 | "Search for next unread newsgroup. |
2328 | If optional argument BACKWARD is non-nil, search backward instead." | |
2329 | (save-excursion | |
b027f415 | 2330 | (set-buffer gnus-group-buffer) |
745bc783 JB |
2331 | (save-excursion |
2332 | ;; We don't want to alter current point of Group mode buffer. | |
b027f415 RS |
2333 | (if (gnus-group-search-forward backward nil) |
2334 | (gnus-group-group-name)) | |
745bc783 JB |
2335 | ))) |
2336 | ||
b027f415 | 2337 | (defun gnus-summary-search-subject (backward unread subject) |
745bc783 | 2338 | "Search for article forward. |
b027f415 RS |
2339 | If 1st argument BACKWARD is non-nil, search backward. |
2340 | If 2nd argument UNREAD is non-nil, only unread article is selected. | |
2341 | If 3rd argument SUBJECT is non-nil, the article which has | |
745bc783 | 2342 | the same subject will be searched for." |
b027f415 RS |
2343 | (let ((func |
2344 | (if backward | |
2345 | (function re-search-backward) (function re-search-forward))) | |
745bc783 JB |
2346 | (article nil) |
2347 | ;; We have to take care of hidden lines. | |
2348 | (regexp | |
2349 | (format "^%s[ \t]+\\([0-9]+\\):.\\[[^]\r\n]*\\][ \t]+%s" | |
2350 | ;;(if unread " " ".") | |
2351 | (cond ((eq unread t) " ") (unread "[ ---]") (t ".")) | |
2352 | (if subject | |
2353 | (concat "\\([Rr][Ee]:[ \t]+\\)*" | |
2354 | (regexp-quote (gnus-simplify-subject subject)) | |
2355 | ;; Ignore words in parentheses. | |
2356 | "\\([ \t]*([^\r\n]*)\\)*[ \t]*\\(\r\\|$\\)") | |
2357 | "") | |
2358 | ))) | |
2359 | (if backward | |
2360 | (beginning-of-line) | |
2361 | (end-of-line)) | |
2362 | (if (funcall func regexp nil t) | |
2363 | (setq article | |
2364 | (string-to-int | |
2365 | (buffer-substring (match-beginning 1) (match-end 1))))) | |
2366 | ;; Adjust cursor point. | |
2367 | (beginning-of-line) | |
2368 | (search-forward ":" nil t) | |
2369 | ;; This is the result. | |
2370 | article | |
2371 | )) | |
2372 | ||
b027f415 | 2373 | (defun gnus-summary-search-forward (&optional unread subject) |
745bc783 | 2374 | "Search for article forward. |
b027f415 RS |
2375 | If 1st optional argument UNREAD is non-nil, only unread article is selected. |
2376 | If 2nd optional argument SUBJECT is non-nil, the article which has | |
745bc783 | 2377 | the same subject will be searched for." |
b027f415 | 2378 | (gnus-summary-search-subject nil unread subject)) |
745bc783 | 2379 | |
b027f415 | 2380 | (defun gnus-summary-search-backward (&optional unread subject) |
745bc783 | 2381 | "Search for article backward. |
b027f415 RS |
2382 | If 1st optional argument UNREAD is non-nil, only unread article is selected. |
2383 | If 2nd optional argument SUBJECT is non-nil, the article which has | |
745bc783 | 2384 | the same subject will be searched for." |
b027f415 | 2385 | (gnus-summary-search-subject t unread subject)) |
745bc783 | 2386 | |
b027f415 | 2387 | (defun gnus-summary-article-number () |
745bc783 JB |
2388 | "Article number around point. If nothing, return current number." |
2389 | (save-excursion | |
2390 | (beginning-of-line) | |
2391 | (if (looking-at ".[ \t]+\\([0-9]+\\):") | |
2392 | (string-to-int | |
2393 | (buffer-substring (match-beginning 1) (match-end 1))) | |
2394 | ;; If search fail, return current article number. | |
2395 | gnus-current-article | |
2396 | ))) | |
2397 | ||
b027f415 | 2398 | (defun gnus-summary-subject-string () |
745bc783 JB |
2399 | "Return current subject string or nil if nothing." |
2400 | (save-excursion | |
2401 | ;; It is possible to implement this function using | |
b027f415 | 2402 | ;; `gnus-summary-article-number' and `gnus-newsgroup-headers'. |
745bc783 JB |
2403 | (beginning-of-line) |
2404 | ;; We have to take care of hidden lines. | |
2405 | (if (looking-at ".[ \t]+[0-9]+:.\\[[^]\r\n]*\\][ \t]+\\([^\r\n]*\\)[\r\n]") | |
2406 | (buffer-substring (match-beginning 1) (match-end 1))) | |
2407 | )) | |
2408 | ||
b027f415 | 2409 | (defun gnus-summary-goto-subject (article) |
745bc783 JB |
2410 | "Move point to ARTICLE's subject." |
2411 | (interactive | |
2412 | (list | |
2413 | (string-to-int | |
2414 | (completing-read "Article number: " | |
2415 | (mapcar | |
2416 | (function | |
2417 | (lambda (headers) | |
2418 | (list | |
2419 | (int-to-string (nntp-header-number headers))))) | |
2420 | gnus-newsgroup-headers) | |
2421 | nil 'require-match)))) | |
2422 | (let ((current (point))) | |
2423 | (goto-char (point-min)) | |
2424 | (or (and article (re-search-forward (format "^.[ \t]+%d:" article) nil t)) | |
2425 | (progn (goto-char current) nil)) | |
2426 | )) | |
2427 | ||
b027f415 RS |
2428 | (defun gnus-summary-recenter () |
2429 | "Center point in Summary window." | |
2430 | ;; Scroll window so as to cursor comes center of Summary window | |
745bc783 JB |
2431 | ;; only when article is displayed. |
2432 | ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle). | |
2433 | ;; Recenter only when requested. | |
b027f415 RS |
2434 | ;; Subbested by popovich@park.cs.columbia.edu |
2435 | (and gnus-auto-center-summary | |
2436 | (get-buffer-window gnus-article-buffer) | |
745bc783 JB |
2437 | (< (/ (- (window-height) 1) 2) |
2438 | (count-lines (point) (point-max))) | |
2439 | (recenter (/ (- (window-height) 2) 2)))) | |
2440 | ||
2441 | ;; Walking around Group mode buffer. | |
2442 | ||
b027f415 | 2443 | (defun gnus-summary-jump-to-group (newsgroup) |
745bc783 JB |
2444 | "Move point to NEWSGROUP in Group mode buffer." |
2445 | ;; Keep update point of Group mode buffer if visible. | |
2446 | (if (eq (current-buffer) | |
b027f415 | 2447 | (get-buffer gnus-group-buffer)) |
745bc783 JB |
2448 | (save-window-excursion |
2449 | ;; Take care of tree window mode. | |
b027f415 RS |
2450 | (if (get-buffer-window gnus-group-buffer) |
2451 | (pop-to-buffer gnus-group-buffer)) | |
2452 | (gnus-group-jump-to-group newsgroup)) | |
745bc783 JB |
2453 | (save-excursion |
2454 | ;; Take care of tree window mode. | |
b027f415 RS |
2455 | (if (get-buffer-window gnus-group-buffer) |
2456 | (pop-to-buffer gnus-group-buffer) | |
2457 | (set-buffer gnus-group-buffer)) | |
2458 | (gnus-group-jump-to-group newsgroup)))) | |
745bc783 | 2459 | |
b027f415 | 2460 | (defun gnus-summary-next-group (no-article) |
745bc783 JB |
2461 | "Exit current newsgroup and then select next unread newsgroup. |
2462 | If prefix argument NO-ARTICLE is non-nil, no article is selected initially." | |
2463 | (interactive "P") | |
2464 | ;; Make sure Group mode buffer point is on current newsgroup. | |
b027f415 RS |
2465 | (gnus-summary-jump-to-group gnus-newsgroup-name) |
2466 | (let ((group (gnus-summary-search-group))) | |
745bc783 JB |
2467 | (if (null group) |
2468 | (progn | |
2469 | (message "Exiting %s..." gnus-newsgroup-name) | |
b027f415 | 2470 | (gnus-summary-exit) |
745bc783 JB |
2471 | (message "")) |
2472 | (message "Selecting %s..." group) | |
b027f415 | 2473 | (gnus-summary-exit t) ;Exit Summary mode temporary. |
745bc783 JB |
2474 | ;; We are now in Group mode buffer. |
2475 | ;; Make sure Group mode buffer point is on GROUP. | |
b027f415 RS |
2476 | (gnus-summary-jump-to-group group) |
2477 | (gnus-summary-read-group group nil no-article) | |
745bc783 | 2478 | (or (eq (current-buffer) |
b027f415 | 2479 | (get-buffer gnus-summary-buffer)) |
745bc783 JB |
2480 | (eq gnus-auto-select-next t) |
2481 | ;; Expected newsgroup has nothing to read since the articles | |
2482 | ;; are marked as read by cross-referencing. So, try next | |
2483 | ;; newsgroup. (Make sure we are in Group mode buffer now.) | |
2484 | (and (eq (current-buffer) | |
b027f415 RS |
2485 | (get-buffer gnus-group-buffer)) |
2486 | (gnus-group-group-name) | |
2487 | (gnus-summary-read-group | |
2488 | (gnus-group-group-name) nil no-article)) | |
745bc783 JB |
2489 | ) |
2490 | ))) | |
2491 | ||
b027f415 | 2492 | (defun gnus-summary-prev-group (no-article) |
745bc783 JB |
2493 | "Exit current newsgroup and then select previous unread newsgroup. |
2494 | If prefix argument NO-ARTICLE is non-nil, no article is selected initially." | |
2495 | (interactive "P") | |
2496 | ;; Make sure Group mode buffer point is on current newsgroup. | |
b027f415 RS |
2497 | (gnus-summary-jump-to-group gnus-newsgroup-name) |
2498 | (let ((group (gnus-summary-search-group t))) | |
745bc783 JB |
2499 | (if (null group) |
2500 | (progn | |
2501 | (message "Exiting %s..." gnus-newsgroup-name) | |
b027f415 | 2502 | (gnus-summary-exit) |
745bc783 JB |
2503 | (message "")) |
2504 | (message "Selecting %s..." group) | |
b027f415 | 2505 | (gnus-summary-exit t) ;Exit Summary mode temporary. |
745bc783 JB |
2506 | ;; We are now in Group mode buffer. |
2507 | ;; We have to adjust point of Group mode buffer because current | |
2508 | ;; point is moved to next unread newsgroup by exiting. | |
b027f415 RS |
2509 | (gnus-summary-jump-to-group group) |
2510 | (gnus-summary-read-group group nil no-article) | |
745bc783 | 2511 | (or (eq (current-buffer) |
b027f415 | 2512 | (get-buffer gnus-summary-buffer)) |
745bc783 JB |
2513 | (eq gnus-auto-select-next t) |
2514 | ;; Expected newsgroup has nothing to read since the articles | |
2515 | ;; are marked as read by cross-referencing. So, try next | |
2516 | ;; newsgroup. (Make sure we are in Group mode buffer now.) | |
2517 | (and (eq (current-buffer) | |
b027f415 RS |
2518 | (get-buffer gnus-group-buffer)) |
2519 | (gnus-summary-search-group t) | |
2520 | (gnus-summary-read-group | |
2521 | (gnus-summary-search-group t) nil no-article)) | |
745bc783 JB |
2522 | ) |
2523 | ))) | |
2524 | ||
b027f415 | 2525 | ;; Walking around summary lines. |
745bc783 | 2526 | |
b027f415 RS |
2527 | (defun gnus-summary-next-subject (n &optional unread) |
2528 | "Go to next N'th summary line. | |
745bc783 JB |
2529 | If optional argument UNREAD is non-nil, only unread article is selected." |
2530 | (interactive "p") | |
2531 | (while (and (> n 1) | |
b027f415 | 2532 | (gnus-summary-search-forward unread)) |
745bc783 | 2533 | (setq n (1- n))) |
b027f415 RS |
2534 | (cond ((gnus-summary-search-forward unread) |
2535 | (gnus-summary-recenter)) | |
745bc783 JB |
2536 | (unread |
2537 | (message "No more unread articles")) | |
2538 | (t | |
2539 | (message "No more articles")) | |
2540 | )) | |
2541 | ||
b027f415 RS |
2542 | (defun gnus-summary-next-unread-subject (n) |
2543 | "Go to next N'th unread summary line." | |
745bc783 | 2544 | (interactive "p") |
b027f415 | 2545 | (gnus-summary-next-subject n t)) |
745bc783 | 2546 | |
b027f415 RS |
2547 | (defun gnus-summary-prev-subject (n &optional unread) |
2548 | "Go to previous N'th summary line. | |
745bc783 JB |
2549 | If optional argument UNREAD is non-nil, only unread article is selected." |
2550 | (interactive "p") | |
2551 | (while (and (> n 1) | |
b027f415 | 2552 | (gnus-summary-search-backward unread)) |
745bc783 | 2553 | (setq n (1- n))) |
b027f415 RS |
2554 | (cond ((gnus-summary-search-backward unread) |
2555 | (gnus-summary-recenter)) | |
745bc783 JB |
2556 | (unread |
2557 | (message "No more unread articles")) | |
2558 | (t | |
2559 | (message "No more articles")) | |
2560 | )) | |
2561 | ||
b027f415 RS |
2562 | (defun gnus-summary-prev-unread-subject (n) |
2563 | "Go to previous N'th unread summary line." | |
745bc783 | 2564 | (interactive "p") |
b027f415 | 2565 | (gnus-summary-prev-subject n t)) |
745bc783 | 2566 | |
b027f415 | 2567 | ;; Walking around summary lines with displaying articles. |
745bc783 | 2568 | |
b027f415 RS |
2569 | (defun gnus-summary-expand-window () |
2570 | "Expand Summary window to show headers full window." | |
745bc783 | 2571 | (interactive) |
b027f415 RS |
2572 | (gnus-configure-windows 'summary) |
2573 | (pop-to-buffer gnus-summary-buffer)) | |
745bc783 | 2574 | |
b027f415 | 2575 | (defun gnus-summary-display-article (article &optional all-header) |
745bc783 JB |
2576 | "Display ARTICLE in Article buffer." |
2577 | (if (null article) | |
2578 | nil | |
b027f415 RS |
2579 | (gnus-configure-windows 'article) |
2580 | (pop-to-buffer gnus-summary-buffer) | |
2581 | (gnus-article-prepare article all-header) | |
2582 | (gnus-summary-recenter) | |
2583 | (gnus-summary-set-mode-line) | |
2584 | (run-hooks 'gnus-select-article-hook) | |
745bc783 JB |
2585 | ;; Successfully display article. |
2586 | t | |
2587 | )) | |
2588 | ||
b027f415 | 2589 | (defun gnus-summary-select-article (&optional all-headers force) |
745bc783 | 2590 | "Select the current article. |
b027f415 RS |
2591 | Optional first argument ALL-HEADERS is non-nil, show all header fields. |
2592 | Optional second argument FORCE is nil, the article is only selected | |
2593 | again when current header does not match with ALL-HEADERS option." | |
2594 | (let ((article (gnus-summary-article-number)) | |
2595 | (all-headers (not (not all-headers)))) ;Must be T or NIL. | |
745bc783 JB |
2596 | (if (or (null gnus-current-article) |
2597 | (/= article gnus-current-article) | |
2598 | (and force (not (eq all-headers gnus-have-all-headers)))) | |
b027f415 RS |
2599 | ;; The selected one is different from that of the current article. |
2600 | (gnus-summary-display-article article all-headers) | |
2601 | (gnus-configure-windows 'article) | |
2602 | (pop-to-buffer gnus-summary-buffer)) | |
745bc783 JB |
2603 | )) |
2604 | ||
b027f415 | 2605 | (defun gnus-summary-set-current-mark (&optional current-mark) |
745bc783 JB |
2606 | "Put `+' at the current article. |
2607 | Optional argument specifies CURRENT-MARK instead of `+'." | |
2608 | (save-excursion | |
b027f415 | 2609 | (set-buffer gnus-summary-buffer) |
745bc783 JB |
2610 | (let ((buffer-read-only nil)) |
2611 | (goto-char (point-min)) | |
2612 | ;; First of all clear mark at last article. | |
2613 | (if (re-search-forward "^.[ \t]+[0-9]+:[^ \t]" nil t) | |
2614 | (progn | |
2615 | (delete-char -1) | |
2616 | (insert " ") | |
2617 | (goto-char (point-min)))) | |
2618 | (if (re-search-forward (format "^.[ \t]+%d:" gnus-current-article) nil t) | |
2619 | (progn | |
2620 | (delete-char 1) | |
2621 | (insert (or current-mark "+")))) | |
2622 | ))) | |
2623 | ||
b027f415 RS |
2624 | ;;(defun gnus-summary-next-article (unread &optional subject) |
2625 | ;; "Select article after current one. | |
2626 | ;;If argument UNREAD is non-nil, only unread article is selected." | |
2627 | ;; (interactive "P") | |
2628 | ;; (cond ((gnus-summary-display-article | |
2629 | ;; (gnus-summary-search-forward unread subject))) | |
2630 | ;; (unread | |
2631 | ;; (message "No more unread articles")) | |
2632 | ;; (t | |
2633 | ;; (message "No more articles")) | |
2634 | ;; )) | |
2635 | ||
2636 | (defun gnus-summary-next-article (unread &optional subject) | |
745bc783 JB |
2637 | "Select article after current one. |
2638 | If argument UNREAD is non-nil, only unread article is selected." | |
2639 | (interactive "P") | |
2640 | (let ((header nil)) | |
b027f415 RS |
2641 | (cond ((gnus-summary-display-article |
2642 | (gnus-summary-search-forward unread subject))) | |
745bc783 JB |
2643 | ((and subject |
2644 | gnus-auto-select-same | |
2645 | (gnus-set-difference gnus-newsgroup-unreads | |
2646 | gnus-newsgroup-marked) | |
2647 | (memq this-command | |
b027f415 RS |
2648 | '(gnus-summary-next-unread-article |
2649 | gnus-summary-next-page | |
2650 | gnus-summary-kill-same-subject-and-select | |
2651 | ;;gnus-summary-next-article | |
2652 | ;;gnus-summary-next-same-subject | |
2653 | ;;gnus-summary-next-unread-same-subject | |
745bc783 JB |
2654 | ))) |
2655 | ;; Wrap article pointer if there are unread articles. | |
b027f415 | 2656 | ;; Hook function, such as gnus-summary-rmail-digest, may |
745bc783 JB |
2657 | ;; change current buffer, so need check. |
2658 | (let ((buffer (current-buffer)) | |
2659 | (last-point (point))) | |
2660 | ;; No more articles with same subject, so jump to the first | |
2661 | ;; unread article. | |
b027f415 | 2662 | (gnus-summary-first-unread-article) |
745bc783 JB |
2663 | ;;(and (eq buffer (current-buffer)) |
2664 | ;; (= (point) last-point) | |
2665 | ;; ;; Ignore given SUBJECT, and try again. | |
b027f415 | 2666 | ;; (gnus-summary-next-article unread nil)) |
745bc783 JB |
2667 | (and (eq buffer (current-buffer)) |
2668 | (< (point) last-point) | |
2669 | (message "Wrapped")) | |
2670 | )) | |
b027f415 RS |
2671 | ((and gnus-auto-extend-newsgroup |
2672 | (not unread) ;Not unread only | |
2673 | (not subject) ;Only if subject is not specified. | |
745bc783 JB |
2674 | (setq header (gnus-more-header-forward))) |
2675 | ;; Extend to next article if possible. | |
2676 | ;; Basic ideas by himacdonald@watdragon.waterloo.edu | |
2677 | (gnus-extend-newsgroup header nil) | |
2678 | ;; Threads feature must be turned off. | |
2679 | (let ((buffer-read-only nil)) | |
2680 | (goto-char (point-max)) | |
b027f415 RS |
2681 | (gnus-summary-prepare-threads (list header) 0)) |
2682 | (gnus-summary-goto-article gnus-newsgroup-end)) | |
745bc783 JB |
2683 | (t |
2684 | ;; Select next newsgroup automatically if requested. | |
2685 | (let ((cmd (string-to-char (this-command-keys))) | |
b027f415 | 2686 | (group (gnus-summary-search-group)) |
745bc783 JB |
2687 | (auto-select |
2688 | (and gnus-auto-select-next | |
2689 | ;;(null (gnus-set-difference gnus-newsgroup-unreads | |
2690 | ;; gnus-newsgroup-marked)) | |
2691 | (memq this-command | |
b027f415 RS |
2692 | '(gnus-summary-next-unread-article |
2693 | gnus-summary-next-article | |
2694 | gnus-summary-next-page | |
2695 | gnus-summary-next-same-subject | |
2696 | gnus-summary-next-unread-same-subject | |
2697 | gnus-summary-kill-same-subject | |
2698 | gnus-summary-kill-same-subject-and-select | |
745bc783 JB |
2699 | )) |
2700 | ;; Ignore characters typed ahead. | |
2701 | (not (input-pending-p)) | |
2702 | ))) | |
2703 | (message "No more%s articles%s" | |
2704 | (if unread " unread" "") | |
2705 | (if (and auto-select | |
2706 | (not (eq gnus-auto-select-next 'quietly))) | |
2707 | (if group | |
b027f415 | 2708 | (format " (Type %s for %s [%d])" |
745bc783 JB |
2709 | (key-description (char-to-string cmd)) |
2710 | group | |
2711 | (nth 1 (gnus-gethash group | |
2712 | gnus-unread-hashtb))) | |
2713 | (format " (Type %s to exit %s)" | |
2714 | (key-description (char-to-string cmd)) | |
2715 | gnus-newsgroup-name | |
2716 | )) | |
2717 | "")) | |
2718 | ;; Select next unread newsgroup automagically. | |
2719 | (cond ((and auto-select | |
2720 | (eq gnus-auto-select-next 'quietly)) | |
2721 | ;; Select quietly. | |
b027f415 | 2722 | (gnus-summary-next-group nil)) |
745bc783 JB |
2723 | (auto-select |
2724 | ;; Confirm auto selection. | |
2725 | (let ((char (read-char))) | |
2726 | (if (= char cmd) | |
b027f415 RS |
2727 | (gnus-summary-next-group nil) |
2728 | (setq unread-command-char char)))) | |
745bc783 JB |
2729 | ) |
2730 | )) | |
2731 | ))) | |
2732 | ||
b027f415 | 2733 | (defun gnus-summary-next-unread-article () |
745bc783 JB |
2734 | "Select unread article after current one." |
2735 | (interactive) | |
b027f415 RS |
2736 | (gnus-summary-next-article t (and gnus-auto-select-same |
2737 | (gnus-summary-subject-string)))) | |
745bc783 | 2738 | |
b027f415 | 2739 | (defun gnus-summary-prev-article (unread &optional subject) |
745bc783 JB |
2740 | "Select article before current one. |
2741 | If argument UNREAD is non-nil, only unread article is selected." | |
2742 | (interactive "P") | |
2743 | (let ((header nil)) | |
b027f415 RS |
2744 | (cond ((gnus-summary-display-article |
2745 | (gnus-summary-search-backward unread subject))) | |
745bc783 JB |
2746 | ((and subject |
2747 | gnus-auto-select-same | |
2748 | (gnus-set-difference gnus-newsgroup-unreads | |
2749 | gnus-newsgroup-marked) | |
2750 | (memq this-command | |
b027f415 RS |
2751 | '(gnus-summary-prev-unread-article |
2752 | ;;gnus-summary-prev-page | |
2753 | ;;gnus-summary-prev-article | |
2754 | ;;gnus-summary-prev-same-subject | |
2755 | ;;gnus-summary-prev-unread-same-subject | |
745bc783 JB |
2756 | ))) |
2757 | ;; Ignore given SUBJECT, and try again. | |
b027f415 | 2758 | (gnus-summary-prev-article unread nil)) |
745bc783 JB |
2759 | (unread |
2760 | (message "No more unread articles")) | |
2761 | ((and gnus-auto-extend-newsgroup | |
b027f415 | 2762 | (not subject) ;Only if subject is not specified. |
745bc783 JB |
2763 | (setq header (gnus-more-header-backward))) |
2764 | ;; Extend to previous article if possible. | |
2765 | ;; Basic ideas by himacdonald@watdragon.waterloo.edu | |
2766 | (gnus-extend-newsgroup header t) | |
2767 | (let ((buffer-read-only nil)) | |
2768 | (goto-char (point-min)) | |
b027f415 RS |
2769 | (gnus-summary-prepare-threads (list header) 0)) |
2770 | (gnus-summary-goto-article gnus-newsgroup-begin)) | |
745bc783 JB |
2771 | (t |
2772 | (message "No more articles")) | |
2773 | ))) | |
2774 | ||
b027f415 | 2775 | (defun gnus-summary-prev-unread-article () |
745bc783 JB |
2776 | "Select unred article before current one." |
2777 | (interactive) | |
b027f415 RS |
2778 | (gnus-summary-prev-article t (and gnus-auto-select-same |
2779 | (gnus-summary-subject-string)))) | |
745bc783 | 2780 | |
b027f415 | 2781 | (defun gnus-summary-next-page (lines) |
745bc783 | 2782 | "Show next page of selected article. |
eb8c3be9 | 2783 | If end of article, select next article. |
745bc783 JB |
2784 | Argument LINES specifies lines to be scrolled up." |
2785 | (interactive "P") | |
b027f415 | 2786 | (let ((article (gnus-summary-article-number)) |
745bc783 JB |
2787 | (endp nil)) |
2788 | (if (or (null gnus-current-article) | |
2789 | (/= article gnus-current-article)) | |
2790 | ;; Selected subject is different from current article's. | |
b027f415 RS |
2791 | (gnus-summary-display-article article) |
2792 | (gnus-configure-windows 'article) | |
2793 | (pop-to-buffer gnus-summary-buffer) | |
2794 | (gnus-eval-in-buffer-window gnus-article-buffer | |
2795 | (setq endp (gnus-article-next-page lines))) | |
745bc783 JB |
2796 | (cond ((and endp lines) |
2797 | (message "End of message")) | |
2798 | ((and endp (null lines)) | |
b027f415 | 2799 | (gnus-summary-next-unread-article))) |
745bc783 JB |
2800 | ))) |
2801 | ||
b027f415 | 2802 | (defun gnus-summary-prev-page (lines) |
745bc783 JB |
2803 | "Show previous page of selected article. |
2804 | Argument LINES specifies lines to be scrolled down." | |
2805 | (interactive "P") | |
b027f415 | 2806 | (let ((article (gnus-summary-article-number))) |
745bc783 JB |
2807 | (if (or (null gnus-current-article) |
2808 | (/= article gnus-current-article)) | |
2809 | ;; Selected subject is different from current article's. | |
b027f415 RS |
2810 | (gnus-summary-display-article article) |
2811 | (gnus-configure-windows 'article) | |
2812 | (pop-to-buffer gnus-summary-buffer) | |
2813 | (gnus-eval-in-buffer-window gnus-article-buffer | |
2814 | (gnus-article-prev-page lines)) | |
745bc783 JB |
2815 | ))) |
2816 | ||
b027f415 | 2817 | (defun gnus-summary-scroll-up (lines) |
745bc783 JB |
2818 | "Scroll up (or down) one line current article. |
2819 | Argument LINES specifies lines to be scrolled up (or down if negative)." | |
2820 | (interactive "p") | |
b027f415 RS |
2821 | (gnus-summary-select-article) |
2822 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 | 2823 | (cond ((> lines 0) |
b027f415 | 2824 | (if (gnus-article-next-page lines) |
745bc783 JB |
2825 | (message "End of message"))) |
2826 | ((< lines 0) | |
b027f415 | 2827 | (gnus-article-prev-page (- 0 lines)))) |
745bc783 JB |
2828 | )) |
2829 | ||
b027f415 | 2830 | (defun gnus-summary-next-same-subject () |
745bc783 JB |
2831 | "Select next article which has the same subject as current one." |
2832 | (interactive) | |
b027f415 | 2833 | (gnus-summary-next-article nil (gnus-summary-subject-string))) |
745bc783 | 2834 | |
b027f415 | 2835 | (defun gnus-summary-prev-same-subject () |
745bc783 JB |
2836 | "Select previous article which has the same subject as current one." |
2837 | (interactive) | |
b027f415 | 2838 | (gnus-summary-prev-article nil (gnus-summary-subject-string))) |
745bc783 | 2839 | |
b027f415 | 2840 | (defun gnus-summary-next-unread-same-subject () |
745bc783 JB |
2841 | "Select next unread article which has the same subject as current one." |
2842 | (interactive) | |
b027f415 | 2843 | (gnus-summary-next-article t (gnus-summary-subject-string))) |
745bc783 | 2844 | |
b027f415 | 2845 | (defun gnus-summary-prev-unread-same-subject () |
745bc783 JB |
2846 | "Select previous unread article which has the same subject as current one." |
2847 | (interactive) | |
b027f415 | 2848 | (gnus-summary-prev-article t (gnus-summary-subject-string))) |
745bc783 | 2849 | |
b027f415 | 2850 | (defun gnus-summary-refer-parent-article (child) |
745bc783 JB |
2851 | "Refer parent article of current article. |
2852 | If a prefix argument CHILD is non-nil, go back to the child article | |
2853 | using internally maintained articles history. | |
2854 | NOTE: This command may not work with nnspool.el." | |
2855 | (interactive "P") | |
b027f415 | 2856 | (gnus-summary-select-article t t) ;Request all headers. |
745bc783 JB |
2857 | (let ((referenced-id nil)) ;Message-id of parent or child article. |
2858 | (if child | |
2859 | ;; Go back to child article using history. | |
b027f415 RS |
2860 | (gnus-summary-refer-article nil) |
2861 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
2862 | ;; Look for parent Message-ID. |
2863 | ;; We cannot use gnus-current-headers to get references | |
eb8c3be9 | 2864 | ;; because we may be looking at parent or referred article. |
745bc783 JB |
2865 | (let ((references (gnus-fetch-field "References"))) |
2866 | ;; Get the last message-id in the references. | |
2867 | (and references | |
2868 | (string-match "\\(<[^<>]+>\\)[^>]*\\'" references) | |
2869 | (setq referenced-id | |
2870 | (substring references | |
2871 | (match-beginning 1) (match-end 1)))) | |
2872 | )) | |
2873 | (if (stringp referenced-id) | |
b027f415 | 2874 | (gnus-summary-refer-article referenced-id) |
745bc783 JB |
2875 | (error "No more parents")) |
2876 | ))) | |
2877 | ||
b027f415 | 2878 | (defun gnus-summary-refer-article (message-id) |
745bc783 | 2879 | "Refer article specified by MESSAGE-ID. |
b027f415 | 2880 | If the MESSAGE-ID is nil or an empty string, Message-ID is poped from |
745bc783 | 2881 | internally maintained articles history. |
b027f415 | 2882 | NOTE: This command may not work with nnspool.el nor mhspool.el." |
745bc783 JB |
2883 | (interactive "sMessage-ID: ") |
2884 | ;; Make sure that this command depends on the fact that article | |
2885 | ;; related information is not updated when an article is retrieved | |
2886 | ;; by Message-ID. | |
b027f415 | 2887 | (gnus-summary-select-article t t) ;Request all headers. |
745bc783 JB |
2888 | (if (and (stringp message-id) |
2889 | (> (length message-id) 0)) | |
b027f415 | 2890 | (gnus-eval-in-buffer-window gnus-article-buffer |
745bc783 JB |
2891 | ;; Construct the correct Message-ID if necessary. |
2892 | ;; Suggested by tale@pawl.rpi.edu. | |
2893 | (or (string-match "^<" message-id) | |
2894 | (setq message-id (concat "<" message-id))) | |
2895 | (or (string-match ">$" message-id) | |
2896 | (setq message-id (concat message-id ">"))) | |
2897 | ;; Push current message-id on history. | |
2898 | ;; We cannot use gnus-current-headers to get current | |
eb8c3be9 | 2899 | ;; message-id because we may be looking at parent or referred |
745bc783 JB |
2900 | ;; article. |
2901 | (let ((current (gnus-fetch-field "Message-ID"))) | |
2902 | (or (equal current message-id) ;Nothing to do. | |
2903 | (equal current (car gnus-current-history)) | |
2904 | (setq gnus-current-history | |
2905 | (cons current gnus-current-history))) | |
2906 | )) | |
2907 | ;; Pop message-id from history. | |
2908 | (setq message-id (car gnus-current-history)) | |
2909 | (setq gnus-current-history (cdr gnus-current-history))) | |
2910 | (if (stringp message-id) | |
b027f415 RS |
2911 | ;; Retrieve article by message-id. This may not work with |
2912 | ;; nnspool nor mhspool. | |
2913 | (gnus-article-prepare message-id t) | |
745bc783 JB |
2914 | (error "No such references")) |
2915 | ) | |
2916 | ||
b027f415 | 2917 | (defun gnus-summary-next-digest (nth) |
745bc783 JB |
2918 | "Move to head of NTH next digested message." |
2919 | (interactive "p") | |
b027f415 RS |
2920 | (gnus-summary-select-article) |
2921 | (gnus-eval-in-buffer-window gnus-article-buffer | |
2922 | (gnus-article-next-digest (or nth 1)) | |
745bc783 JB |
2923 | )) |
2924 | ||
b027f415 | 2925 | (defun gnus-summary-prev-digest (nth) |
745bc783 JB |
2926 | "Move to head of NTH previous digested message." |
2927 | (interactive "p") | |
b027f415 RS |
2928 | (gnus-summary-select-article) |
2929 | (gnus-eval-in-buffer-window gnus-article-buffer | |
2930 | (gnus-article-prev-digest (or nth 1)) | |
745bc783 JB |
2931 | )) |
2932 | ||
b027f415 RS |
2933 | (defun gnus-summary-first-unread-article () |
2934 | "Select first unread article. Return non-nil if successfully selected." | |
745bc783 JB |
2935 | (interactive) |
2936 | (let ((begin (point))) | |
2937 | (goto-char (point-min)) | |
2938 | (if (re-search-forward "^ [ \t]+[0-9]+:" nil t) | |
b027f415 | 2939 | (gnus-summary-display-article (gnus-summary-article-number)) |
745bc783 JB |
2940 | ;; If there is no unread articles, stay there. |
2941 | (goto-char begin) | |
b027f415 | 2942 | ;;(gnus-summary-display-article (gnus-summary-article-number)) |
745bc783 JB |
2943 | (message "No more unread articles") |
2944 | nil | |
2945 | ) | |
2946 | )) | |
2947 | ||
b027f415 | 2948 | (defun gnus-summary-isearch-article () |
745bc783 JB |
2949 | "Do incremental search forward on current article." |
2950 | (interactive) | |
b027f415 RS |
2951 | (gnus-summary-select-article) |
2952 | (gnus-eval-in-buffer-window gnus-article-buffer | |
abc01fb8 | 2953 | (isearch-forward))) |
745bc783 | 2954 | |
b027f415 | 2955 | (defun gnus-summary-search-article-forward (regexp) |
745bc783 | 2956 | "Search for an article containing REGEXP forward. |
b027f415 | 2957 | gnus-select-article-hook is not called during the search." |
745bc783 JB |
2958 | (interactive |
2959 | (list (read-string | |
2960 | (concat "Search forward (regexp): " | |
2961 | (if gnus-last-search-regexp | |
2962 | (concat "(default " gnus-last-search-regexp ") ")))))) | |
2963 | (if (string-equal regexp "") | |
2964 | (setq regexp (or gnus-last-search-regexp "")) | |
2965 | (setq gnus-last-search-regexp regexp)) | |
b027f415 RS |
2966 | (if (gnus-summary-search-article regexp nil) |
2967 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
2968 | (recenter 0) |
2969 | ;;(sit-for 1) | |
2970 | ) | |
2971 | (error "Search failed: \"%s\"" regexp) | |
2972 | )) | |
2973 | ||
b027f415 | 2974 | (defun gnus-summary-search-article-backward (regexp) |
745bc783 | 2975 | "Search for an article containing REGEXP backward. |
b027f415 | 2976 | gnus-select-article-hook is not called during the search." |
745bc783 JB |
2977 | (interactive |
2978 | (list (read-string | |
2979 | (concat "Search backward (regexp): " | |
2980 | (if gnus-last-search-regexp | |
2981 | (concat "(default " gnus-last-search-regexp ") ")))))) | |
2982 | (if (string-equal regexp "") | |
2983 | (setq regexp (or gnus-last-search-regexp "")) | |
2984 | (setq gnus-last-search-regexp regexp)) | |
b027f415 RS |
2985 | (if (gnus-summary-search-article regexp t) |
2986 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
2987 | (recenter 0) |
2988 | ;;(sit-for 1) | |
2989 | ) | |
2990 | (error "Search failed: \"%s\"" regexp) | |
2991 | )) | |
2992 | ||
b027f415 | 2993 | (defun gnus-summary-search-article (regexp &optional backward) |
745bc783 JB |
2994 | "Search for an article containing REGEXP. |
2995 | Optional argument BACKWARD means do search for backward. | |
b027f415 RS |
2996 | gnus-select-article-hook is not called during the search." |
2997 | (let ((gnus-select-article-hook nil) ;Disable hook. | |
2998 | (gnus-mark-article-hook nil) ;Inhibit marking as read. | |
745bc783 JB |
2999 | (re-search |
3000 | (if backward | |
3001 | (function re-search-backward) (function re-search-forward))) | |
3002 | (found nil) | |
3003 | (last nil)) | |
3004 | ;; Hidden thread subtrees must be searched for ,too. | |
b027f415 | 3005 | (gnus-summary-show-all-threads) |
745bc783 JB |
3006 | ;; First of all, search current article. |
3007 | ;; We don't want to read article again from NNTP server nor reset | |
3008 | ;; current point. | |
b027f415 | 3009 | (gnus-summary-select-article) |
745bc783 JB |
3010 | (message "Searching article: %d..." gnus-current-article) |
3011 | (setq last gnus-current-article) | |
b027f415 | 3012 | (gnus-eval-in-buffer-window gnus-article-buffer |
745bc783 JB |
3013 | (save-restriction |
3014 | (widen) | |
3015 | ;; Begin search from current point. | |
3016 | (setq found (funcall re-search regexp nil t)))) | |
3017 | ;; Then search next articles. | |
3018 | (while (and (not found) | |
b027f415 RS |
3019 | (gnus-summary-display-article |
3020 | (gnus-summary-search-subject backward nil nil))) | |
745bc783 | 3021 | (message "Searching article: %d..." gnus-current-article) |
b027f415 | 3022 | (gnus-eval-in-buffer-window gnus-article-buffer |
745bc783 JB |
3023 | (save-restriction |
3024 | (widen) | |
3025 | (goto-char (if backward (point-max) (point-min))) | |
3026 | (setq found (funcall re-search regexp nil t))) | |
3027 | )) | |
3028 | (message "") | |
3029 | ;; Adjust article pointer. | |
3030 | (or (eq last gnus-current-article) | |
3031 | (setq gnus-last-article last)) | |
3032 | ;; Return T if found such article. | |
3033 | found | |
3034 | )) | |
3035 | ||
b027f415 RS |
3036 | (defun gnus-summary-execute-command (field regexp command &optional backward) |
3037 | "If FIELD of article header matches REGEXP, execute a COMMAND string. | |
745bc783 JB |
3038 | If FIELD is an empty string (or nil), entire article body is searched for. |
3039 | If optional (prefix) argument BACKWARD is non-nil, do backward instead." | |
3040 | (interactive | |
3041 | (list (let ((completion-ignore-case t)) | |
3042 | (completing-read "Field name: " | |
3043 | '(("Number")("Subject")("From") | |
3044 | ("Lines")("Date")("Id") | |
3045 | ("Xref")("References")) | |
3046 | nil 'require-match)) | |
3047 | (read-string "Regexp: ") | |
3048 | (read-key-sequence "Command: ") | |
3049 | current-prefix-arg)) | |
3050 | ;; Hidden thread subtrees must be searched for ,too. | |
b027f415 | 3051 | (gnus-summary-show-all-threads) |
745bc783 JB |
3052 | ;; We don't want to change current point nor window configuration. |
3053 | (save-excursion | |
3054 | (save-window-excursion | |
3055 | (message "Executing %s..." (key-description command)) | |
3056 | ;; We'd like to execute COMMAND interactively so as to give arguments. | |
3057 | (gnus-execute field regexp | |
3058 | (` (lambda () | |
3059 | (call-interactively '(, (key-binding command))))) | |
3060 | backward) | |
3061 | (message "Executing %s... done" (key-description command))))) | |
3062 | ||
b027f415 | 3063 | (defun gnus-summary-beginning-of-article () |
745bc783 JB |
3064 | "Go to beginning of article body" |
3065 | (interactive) | |
b027f415 RS |
3066 | (gnus-summary-select-article) |
3067 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
3068 | (widen) |
3069 | (beginning-of-buffer) | |
3070 | (if gnus-break-pages | |
3071 | (gnus-narrow-to-page)) | |
3072 | )) | |
3073 | ||
b027f415 | 3074 | (defun gnus-summary-end-of-article () |
745bc783 JB |
3075 | "Go to end of article body" |
3076 | (interactive) | |
b027f415 RS |
3077 | (gnus-summary-select-article) |
3078 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
3079 | (widen) |
3080 | (end-of-buffer) | |
3081 | (if gnus-break-pages | |
3082 | (gnus-narrow-to-page)) | |
3083 | )) | |
3084 | ||
b027f415 | 3085 | (defun gnus-summary-goto-article (article &optional all-headers) |
745bc783 JB |
3086 | "Read ARTICLE if exists. |
3087 | Optional argument ALL-HEADERS means all headers are shown." | |
3088 | (interactive | |
3089 | (list | |
3090 | (string-to-int | |
3091 | (completing-read "Article number: " | |
3092 | (mapcar | |
3093 | (function | |
3094 | (lambda (headers) | |
3095 | (list | |
3096 | (int-to-string (nntp-header-number headers))))) | |
3097 | gnus-newsgroup-headers) | |
3098 | nil 'require-match)))) | |
b027f415 RS |
3099 | (if (gnus-summary-goto-subject article) |
3100 | (gnus-summary-display-article article all-headers))) | |
745bc783 | 3101 | |
b027f415 | 3102 | (defun gnus-summary-goto-last-article () |
745bc783 JB |
3103 | "Go to last subject line." |
3104 | (interactive) | |
3105 | (if gnus-last-article | |
b027f415 | 3106 | (gnus-summary-goto-article gnus-last-article))) |
745bc783 | 3107 | |
b027f415 | 3108 | (defun gnus-summary-show-article () |
745bc783 JB |
3109 | "Force to show current article." |
3110 | (interactive) | |
3111 | ;; The following is a trick to force to read the current article again. | |
3112 | (setq gnus-have-all-headers (not gnus-have-all-headers)) | |
b027f415 | 3113 | (gnus-summary-select-article (not gnus-have-all-headers) t)) |
745bc783 | 3114 | |
b027f415 | 3115 | (defun gnus-summary-toggle-header (arg) |
745bc783 JB |
3116 | "Show original header if pruned header currently shown, or vice versa. |
3117 | With arg, show original header iff arg is positive." | |
3118 | (interactive "P") | |
3119 | ;; Variable gnus-show-all-headers must be NIL to toggle really. | |
3120 | (let ((gnus-show-all-headers nil) | |
3121 | (all-headers | |
3122 | (if (null arg) (not gnus-have-all-headers) | |
3123 | (> (prefix-numeric-value arg) 0)))) | |
b027f415 | 3124 | (gnus-summary-select-article all-headers t))) |
745bc783 | 3125 | |
b027f415 | 3126 | (defun gnus-summary-show-all-headers () |
745bc783 JB |
3127 | "Show original article header." |
3128 | (interactive) | |
b027f415 RS |
3129 | (gnus-summary-select-article t t)) |
3130 | ||
3131 | (defun gnus-summary-toggle-mime (arg) | |
3132 | "Toggle MIME processing. | |
3133 | With arg, turn MIME processing on iff arg is positive." | |
3134 | (interactive "P") | |
3135 | (setq gnus-show-mime | |
3136 | (if (null arg) (not gnus-show-mime) | |
3137 | (> (prefix-numeric-value arg) 0))) | |
3138 | ;; The following is a trick to force to read the current article again. | |
3139 | (setq gnus-have-all-headers (not gnus-have-all-headers)) | |
3140 | (gnus-summary-select-article (not gnus-have-all-headers) t)) | |
745bc783 | 3141 | |
b027f415 | 3142 | (defun gnus-summary-stop-page-breaking () |
745bc783 JB |
3143 | "Stop page breaking by linefeed temporary (Widen article buffer)." |
3144 | (interactive) | |
b027f415 RS |
3145 | (gnus-summary-select-article) |
3146 | (gnus-eval-in-buffer-window gnus-article-buffer | |
3147 | (widen) | |
3148 | )) | |
745bc783 | 3149 | |
b027f415 | 3150 | (defun gnus-summary-kill-same-subject-and-select (unmark) |
745bc783 JB |
3151 | "Mark articles which has the same subject as read, and then select next. |
3152 | If argument UNMARK is positive, remove any kinds of marks. | |
3153 | If argument UNMARK is negative, mark articles as unread instead." | |
3154 | (interactive "P") | |
3155 | (if unmark | |
3156 | (setq unmark (prefix-numeric-value unmark))) | |
3157 | (let ((count | |
b027f415 RS |
3158 | (gnus-summary-mark-same-subject |
3159 | (gnus-summary-subject-string) unmark))) | |
745bc783 JB |
3160 | ;; Select next unread article. If auto-select-same mode, should |
3161 | ;; select the first unread article. | |
b027f415 RS |
3162 | (gnus-summary-next-article t (and gnus-auto-select-same |
3163 | (gnus-summary-subject-string))) | |
745bc783 JB |
3164 | (message "%d articles are marked as %s" |
3165 | count (if unmark "unread" "read")) | |
3166 | )) | |
3167 | ||
b027f415 | 3168 | (defun gnus-summary-kill-same-subject (unmark) |
745bc783 JB |
3169 | "Mark articles which has the same subject as read. |
3170 | If argument UNMARK is positive, remove any kinds of marks. | |
3171 | If argument UNMARK is negative, mark articles as unread instead." | |
3172 | (interactive "P") | |
3173 | (if unmark | |
3174 | (setq unmark (prefix-numeric-value unmark))) | |
3175 | (let ((count | |
b027f415 RS |
3176 | (gnus-summary-mark-same-subject |
3177 | (gnus-summary-subject-string) unmark))) | |
745bc783 JB |
3178 | ;; If marked as read, go to next unread subject. |
3179 | (if (null unmark) | |
3180 | ;; Go to next unread subject. | |
b027f415 | 3181 | (gnus-summary-next-subject 1 t)) |
745bc783 JB |
3182 | (message "%d articles are marked as %s" |
3183 | count (if unmark "unread" "read")) | |
3184 | )) | |
3185 | ||
b027f415 | 3186 | (defun gnus-summary-mark-same-subject (subject &optional unmark) |
745bc783 JB |
3187 | "Mark articles with same SUBJECT as read, and return marked number. |
3188 | If optional argument UNMARK is positive, remove any kinds of marks. | |
3189 | If optional argument UNMARK is negative, mark articles as unread instead." | |
3190 | (let ((count 1)) | |
3191 | (save-excursion | |
3192 | (cond ((null unmark) | |
b027f415 | 3193 | (gnus-summary-mark-as-read nil "K")) |
745bc783 | 3194 | ((> unmark 0) |
b027f415 | 3195 | (gnus-summary-mark-as-unread nil t)) |
745bc783 | 3196 | (t |
b027f415 | 3197 | (gnus-summary-mark-as-unread))) |
745bc783 | 3198 | (while (and subject |
b027f415 | 3199 | (gnus-summary-search-forward nil subject)) |
745bc783 | 3200 | (cond ((null unmark) |
b027f415 | 3201 | (gnus-summary-mark-as-read nil "K")) |
745bc783 | 3202 | ((> unmark 0) |
b027f415 | 3203 | (gnus-summary-mark-as-unread nil t)) |
745bc783 | 3204 | (t |
b027f415 | 3205 | (gnus-summary-mark-as-unread))) |
745bc783 JB |
3206 | (setq count (1+ count)) |
3207 | )) | |
3208 | ;; Hide killed thread subtrees. Does not work properly always. | |
3209 | ;;(and (null unmark) | |
3210 | ;; gnus-thread-hide-killed | |
b027f415 | 3211 | ;; (gnus-summary-hide-thread)) |
745bc783 JB |
3212 | ;; Return number of articles marked as read. |
3213 | count | |
3214 | )) | |
3215 | ||
b027f415 | 3216 | (defun gnus-summary-mark-as-unread-forward (count) |
745bc783 JB |
3217 | "Mark current article as unread, and then go forward. |
3218 | Argument COUNT specifies number of articles marked as unread." | |
3219 | (interactive "p") | |
3220 | (while (> count 0) | |
b027f415 RS |
3221 | (gnus-summary-mark-as-unread nil nil) |
3222 | (gnus-summary-next-subject 1 nil) | |
745bc783 JB |
3223 | (setq count (1- count)))) |
3224 | ||
b027f415 | 3225 | (defun gnus-summary-mark-as-unread-backward (count) |
745bc783 JB |
3226 | "Mark current article as unread, and then go backward. |
3227 | Argument COUNT specifies number of articles marked as unread." | |
3228 | (interactive "p") | |
3229 | (while (> count 0) | |
b027f415 RS |
3230 | (gnus-summary-mark-as-unread nil nil) |
3231 | (gnus-summary-prev-subject 1 nil) | |
745bc783 JB |
3232 | (setq count (1- count)))) |
3233 | ||
b027f415 | 3234 | (defun gnus-summary-mark-as-unread (&optional article clear-mark) |
745bc783 | 3235 | "Mark current article as unread. |
b027f415 RS |
3236 | Optional 1st argument ARTICLE specifies article number to be marked as unread. |
3237 | Optional 2nd argument CLEAR-MARK remove any kinds of mark." | |
745bc783 | 3238 | (save-excursion |
b027f415 | 3239 | (set-buffer gnus-summary-buffer) |
745bc783 | 3240 | ;; First of all, show hidden thread subtrees. |
b027f415 | 3241 | (gnus-summary-show-thread) |
745bc783 | 3242 | (let* ((buffer-read-only nil) |
b027f415 | 3243 | (current (gnus-summary-article-number)) |
745bc783 JB |
3244 | (article (or article current))) |
3245 | (gnus-mark-article-as-unread article clear-mark) | |
3246 | (if (or (eq article current) | |
b027f415 | 3247 | (gnus-summary-goto-subject article)) |
745bc783 JB |
3248 | (progn |
3249 | (beginning-of-line) | |
3250 | (delete-char 1) | |
3251 | (insert (if clear-mark " " "-")))) | |
3252 | ))) | |
3253 | ||
b027f415 | 3254 | (defun gnus-summary-mark-as-read-forward (count) |
745bc783 JB |
3255 | "Mark current article as read, and then go forward. |
3256 | Argument COUNT specifies number of articles marked as read" | |
3257 | (interactive "p") | |
3258 | (while (> count 0) | |
b027f415 RS |
3259 | (gnus-summary-mark-as-read) |
3260 | (gnus-summary-next-subject 1 'unread-only) | |
745bc783 JB |
3261 | (setq count (1- count)))) |
3262 | ||
b027f415 | 3263 | (defun gnus-summary-mark-as-read-backward (count) |
745bc783 JB |
3264 | "Mark current article as read, and then go backward. |
3265 | Argument COUNT specifies number of articles marked as read" | |
3266 | (interactive "p") | |
3267 | (while (> count 0) | |
b027f415 RS |
3268 | (gnus-summary-mark-as-read) |
3269 | (gnus-summary-prev-subject 1 'unread-only) | |
745bc783 JB |
3270 | (setq count (1- count)))) |
3271 | ||
b027f415 | 3272 | (defun gnus-summary-mark-as-read (&optional article mark) |
745bc783 | 3273 | "Mark current article as read. |
b027f415 RS |
3274 | Optional 1st argument ARTICLE specifies article number to be marked as read. |
3275 | Optional 2nd argument MARK specifies a string inserted at beginning of line. | |
745bc783 JB |
3276 | Any kind of string (length 1) except for a space and `-' is ok." |
3277 | (save-excursion | |
b027f415 | 3278 | (set-buffer gnus-summary-buffer) |
745bc783 | 3279 | ;; First of all, show hidden thread subtrees. |
b027f415 | 3280 | (gnus-summary-show-thread) |
745bc783 JB |
3281 | (let* ((buffer-read-only nil) |
3282 | (mark (or mark "D")) ;Default mark is `D'. | |
b027f415 | 3283 | (current (gnus-summary-article-number)) |
745bc783 JB |
3284 | (article (or article current))) |
3285 | (gnus-mark-article-as-read article) | |
3286 | (if (or (eq article current) | |
b027f415 | 3287 | (gnus-summary-goto-subject article)) |
745bc783 JB |
3288 | (progn |
3289 | (beginning-of-line) | |
3290 | (delete-char 1) | |
3291 | (insert mark))) | |
3292 | ))) | |
3293 | ||
b027f415 | 3294 | (defun gnus-summary-clear-mark-forward (count) |
745bc783 JB |
3295 | "Remove current article's mark, and go forward. |
3296 | Argument COUNT specifies number of articles unmarked" | |
3297 | (interactive "p") | |
3298 | (while (> count 0) | |
b027f415 RS |
3299 | (gnus-summary-mark-as-unread nil t) |
3300 | (gnus-summary-next-subject 1 nil) | |
745bc783 JB |
3301 | (setq count (1- count)))) |
3302 | ||
b027f415 | 3303 | (defun gnus-summary-clear-mark-backward (count) |
745bc783 JB |
3304 | "Remove current article's mark, and go backward. |
3305 | Argument COUNT specifies number of articles unmarked" | |
3306 | (interactive "p") | |
3307 | (while (> count 0) | |
b027f415 RS |
3308 | (gnus-summary-mark-as-unread nil t) |
3309 | (gnus-summary-prev-subject 1 nil) | |
745bc783 JB |
3310 | (setq count (1- count)))) |
3311 | ||
b027f415 RS |
3312 | (defun gnus-summary-delete-marked-as-read () |
3313 | "Delete lines which is marked as read." | |
745bc783 JB |
3314 | (interactive) |
3315 | (if gnus-newsgroup-unreads | |
3316 | (let ((buffer-read-only nil)) | |
3317 | (save-excursion | |
3318 | (goto-char (point-min)) | |
3319 | (delete-non-matching-lines "^[ ---]")) | |
3320 | ;; Adjust point. | |
3321 | (if (eobp) | |
b027f415 | 3322 | (gnus-summary-prev-subject 1) |
745bc783 JB |
3323 | (beginning-of-line) |
3324 | (search-forward ":" nil t))) | |
3325 | ;; It is not so good idea to make the buffer empty. | |
3326 | (message "All articles are marked as read") | |
3327 | )) | |
3328 | ||
b027f415 | 3329 | (defun gnus-summary-delete-marked-with (marks) |
745bc783 JB |
3330 | "Delete lines which are marked with MARKS (e.g. \"DK\")." |
3331 | (interactive "sMarks: ") | |
3332 | (let ((buffer-read-only nil)) | |
3333 | (save-excursion | |
3334 | (goto-char (point-min)) | |
3335 | (delete-matching-lines (concat "^[" marks "]"))) | |
3336 | ;; Adjust point. | |
3337 | (or (zerop (buffer-size)) | |
3338 | (if (eobp) | |
b027f415 | 3339 | (gnus-summary-prev-subject 1) |
745bc783 JB |
3340 | (beginning-of-line) |
3341 | (search-forward ":" nil t))) | |
3342 | )) | |
3343 | ||
3344 | ;; Thread-based commands. | |
3345 | ||
b027f415 | 3346 | (defun gnus-summary-toggle-threads (arg) |
745bc783 JB |
3347 | "Toggle showing conversation threads. |
3348 | With arg, turn showing conversation threads on iff arg is positive." | |
3349 | (interactive "P") | |
b027f415 | 3350 | (let ((current (gnus-summary-article-number))) |
745bc783 JB |
3351 | (setq gnus-show-threads |
3352 | (if (null arg) (not gnus-show-threads) | |
3353 | (> (prefix-numeric-value arg) 0))) | |
b027f415 RS |
3354 | (gnus-summary-prepare) |
3355 | (gnus-summary-goto-subject current) | |
745bc783 JB |
3356 | )) |
3357 | ||
b027f415 | 3358 | (defun gnus-summary-show-all-threads () |
745bc783 JB |
3359 | "Show all thread subtrees." |
3360 | (interactive) | |
3361 | (if gnus-show-threads | |
3362 | (save-excursion | |
3363 | (let ((buffer-read-only nil)) | |
3364 | (subst-char-in-region (point-min) (point-max) ?\^M ?\n t) | |
3365 | )))) | |
3366 | ||
b027f415 | 3367 | (defun gnus-summary-show-thread () |
745bc783 JB |
3368 | "Show thread subtrees." |
3369 | (interactive) | |
3370 | (if gnus-show-threads | |
3371 | (save-excursion | |
3372 | (let ((buffer-read-only nil)) | |
3373 | (subst-char-in-region (progn | |
3374 | (beginning-of-line) (point)) | |
3375 | (progn | |
3376 | (end-of-line) (point)) | |
3377 | ?\^M ?\n t) | |
3378 | )))) | |
3379 | ||
b027f415 | 3380 | (defun gnus-summary-hide-all-threads () |
745bc783 JB |
3381 | "Hide all thread subtrees." |
3382 | (interactive) | |
3383 | (if gnus-show-threads | |
3384 | (save-excursion | |
3385 | ;; Adjust cursor point. | |
3386 | (goto-char (point-min)) | |
3387 | (search-forward ":" nil t) | |
3388 | (let ((level (current-column))) | |
b027f415 RS |
3389 | (gnus-summary-hide-thread) |
3390 | (while (gnus-summary-search-forward) | |
745bc783 | 3391 | (and (>= level (current-column)) |
b027f415 | 3392 | (gnus-summary-hide-thread))) |
745bc783 JB |
3393 | )))) |
3394 | ||
b027f415 | 3395 | (defun gnus-summary-hide-thread () |
745bc783 JB |
3396 | "Hide thread subtrees." |
3397 | (interactive) | |
3398 | (if gnus-show-threads | |
3399 | (save-excursion | |
3400 | ;; Adjust cursor point. | |
3401 | (beginning-of-line) | |
3402 | (search-forward ":" nil t) | |
3403 | (let ((buffer-read-only nil) | |
3404 | (init (point)) | |
3405 | (last (point)) | |
3406 | (level (current-column))) | |
b027f415 | 3407 | (while (and (gnus-summary-search-forward) |
745bc783 JB |
3408 | (< level (current-column))) |
3409 | ;; Interested in lower levels. | |
3410 | (if (< level (current-column)) | |
3411 | (progn | |
3412 | (setq last (point)) | |
3413 | )) | |
3414 | ) | |
3415 | (subst-char-in-region init last ?\n ?\^M t) | |
3416 | )))) | |
3417 | ||
b027f415 | 3418 | (defun gnus-summary-next-thread (n) |
745bc783 JB |
3419 | "Go to the same level next thread. |
3420 | Argument N specifies the number of threads." | |
3421 | (interactive "p") | |
3422 | ;; Adjust cursor point. | |
3423 | (beginning-of-line) | |
3424 | (search-forward ":" nil t) | |
3425 | (let ((init (point)) | |
3426 | (last (point)) | |
3427 | (level (current-column))) | |
3428 | (while (and (> n 0) | |
b027f415 | 3429 | (gnus-summary-search-forward) |
745bc783 JB |
3430 | (<= level (current-column))) |
3431 | ;; We have to skip lower levels. | |
3432 | (if (= level (current-column)) | |
3433 | (progn | |
3434 | (setq last (point)) | |
3435 | (setq n (1- n)) | |
3436 | )) | |
3437 | ) | |
3438 | ;; Return non-nil if successfully move to the next. | |
3439 | (prog1 (not (= init last)) | |
3440 | (goto-char last)) | |
3441 | )) | |
3442 | ||
b027f415 | 3443 | (defun gnus-summary-prev-thread (n) |
745bc783 JB |
3444 | "Go to the same level previous thread. |
3445 | Argument N specifies the number of threads." | |
3446 | (interactive "p") | |
3447 | ;; Adjust cursor point. | |
3448 | (beginning-of-line) | |
3449 | (search-forward ":" nil t) | |
3450 | (let ((init (point)) | |
3451 | (last (point)) | |
3452 | (level (current-column))) | |
3453 | (while (and (> n 0) | |
b027f415 | 3454 | (gnus-summary-search-backward) |
745bc783 JB |
3455 | (<= level (current-column))) |
3456 | ;; We have to skip lower levels. | |
3457 | (if (= level (current-column)) | |
3458 | (progn | |
3459 | (setq last (point)) | |
3460 | (setq n (1- n)) | |
3461 | )) | |
3462 | ) | |
3463 | ;; Return non-nil if successfully move to the previous. | |
3464 | (prog1 (not (= init last)) | |
3465 | (goto-char last)) | |
3466 | )) | |
3467 | ||
b027f415 | 3468 | (defun gnus-summary-down-thread (d) |
745bc783 JB |
3469 | "Go downward current thread. |
3470 | Argument D specifies the depth goes down." | |
3471 | (interactive "p") | |
3472 | ;; Adjust cursor point. | |
3473 | (beginning-of-line) | |
3474 | (search-forward ":" nil t) | |
3475 | (let ((last (point)) | |
3476 | (level (current-column))) | |
3477 | (while (and (> d 0) | |
b027f415 | 3478 | (gnus-summary-search-forward) |
745bc783 JB |
3479 | (<= level (current-column))) ;<= can be <. Which do you like? |
3480 | ;; We have to skip the same levels. | |
3481 | (if (< level (current-column)) | |
3482 | (progn | |
3483 | (setq last (point)) | |
3484 | (setq level (current-column)) | |
3485 | (setq d (1- d)) | |
3486 | )) | |
3487 | ) | |
3488 | (goto-char last) | |
3489 | )) | |
3490 | ||
b027f415 | 3491 | (defun gnus-summary-up-thread (d) |
745bc783 JB |
3492 | "Go upward current thread. |
3493 | Argument D specifies the depth goes up." | |
3494 | (interactive "p") | |
3495 | ;; Adjust cursor point. | |
3496 | (beginning-of-line) | |
3497 | (search-forward ":" nil t) | |
3498 | (let ((last (point)) | |
3499 | (level (current-column))) | |
3500 | (while (and (> d 0) | |
b027f415 | 3501 | (gnus-summary-search-backward)) |
745bc783 JB |
3502 | ;; We have to skip the same levels. |
3503 | (if (> level (current-column)) | |
3504 | (progn | |
3505 | (setq last (point)) | |
3506 | (setq level (current-column)) | |
3507 | (setq d (1- d)) | |
3508 | )) | |
3509 | ) | |
3510 | (goto-char last) | |
3511 | )) | |
3512 | ||
b027f415 | 3513 | (defun gnus-summary-kill-thread (unmark) |
745bc783 JB |
3514 | "Mark articles under current thread as read. |
3515 | If argument UNMARK is positive, remove any kinds of marks. | |
3516 | If argument UNMARK is negative, mark articles as unread instead." | |
3517 | (interactive "P") | |
3518 | (if unmark | |
3519 | (setq unmark (prefix-numeric-value unmark))) | |
3520 | ;; Adjust cursor point. | |
3521 | (beginning-of-line) | |
3522 | (search-forward ":" nil t) | |
3523 | (save-excursion | |
3524 | (let ((level (current-column))) | |
3525 | ;; Mark current article. | |
3526 | (cond ((null unmark) | |
b027f415 | 3527 | (gnus-summary-mark-as-read nil "K")) |
745bc783 | 3528 | ((> unmark 0) |
b027f415 | 3529 | (gnus-summary-mark-as-unread nil t)) |
745bc783 | 3530 | (t |
b027f415 | 3531 | (gnus-summary-mark-as-unread)) |
745bc783 JB |
3532 | ) |
3533 | ;; Mark following articles. | |
b027f415 | 3534 | (while (and (gnus-summary-search-forward) |
745bc783 JB |
3535 | (< level (current-column))) |
3536 | (cond ((null unmark) | |
b027f415 | 3537 | (gnus-summary-mark-as-read nil "K")) |
745bc783 | 3538 | ((> unmark 0) |
b027f415 | 3539 | (gnus-summary-mark-as-unread nil t)) |
745bc783 | 3540 | (t |
b027f415 | 3541 | (gnus-summary-mark-as-unread)) |
745bc783 JB |
3542 | )) |
3543 | )) | |
3544 | ;; Hide killed subtrees. | |
3545 | (and (null unmark) | |
3546 | gnus-thread-hide-killed | |
b027f415 | 3547 | (gnus-summary-hide-thread)) |
745bc783 JB |
3548 | ;; If marked as read, go to next unread subject. |
3549 | (if (null unmark) | |
3550 | ;; Go to next unread subject. | |
b027f415 | 3551 | (gnus-summary-next-subject 1 t)) |
745bc783 JB |
3552 | ) |
3553 | ||
b027f415 RS |
3554 | (defun gnus-summary-toggle-truncation (arg) |
3555 | "Toggle truncation of summary lines. | |
3556 | With arg, turn line truncation on iff arg is positive." | |
745bc783 JB |
3557 | (interactive "P") |
3558 | (setq truncate-lines | |
3559 | (if (null arg) (not truncate-lines) | |
3560 | (> (prefix-numeric-value arg) 0))) | |
3561 | (redraw-display)) | |
3562 | ||
b027f415 RS |
3563 | (defun gnus-summary-sort-by-number (reverse) |
3564 | "Sort Summary buffer by article number. | |
745bc783 JB |
3565 | Argument REVERSE means reverse order." |
3566 | (interactive "P") | |
b027f415 RS |
3567 | (gnus-summary-keysort-summary |
3568 | (function <) | |
745bc783 | 3569 | (function |
b027f415 RS |
3570 | (lambda (a) |
3571 | (nntp-header-number a))) | |
745bc783 JB |
3572 | reverse |
3573 | )) | |
3574 | ||
b027f415 RS |
3575 | (defun gnus-summary-sort-by-author (reverse) |
3576 | "Sort Summary buffer by author name alphabetically. | |
745bc783 JB |
3577 | If case-fold-search is non-nil, case of letters is ignored. |
3578 | Argument REVERSE means reverse order." | |
3579 | (interactive "P") | |
b027f415 RS |
3580 | (gnus-summary-keysort-summary |
3581 | (function string-lessp) | |
745bc783 | 3582 | (function |
b027f415 RS |
3583 | (lambda (a) |
3584 | (if case-fold-search | |
3585 | (downcase (nntp-header-from a)) | |
3586 | (nntp-header-from a)))) | |
745bc783 JB |
3587 | reverse |
3588 | )) | |
3589 | ||
b027f415 RS |
3590 | (defun gnus-summary-sort-by-subject (reverse) |
3591 | "Sort Summary buffer by subject alphabetically. `Re:'s are ignored. | |
745bc783 JB |
3592 | If case-fold-search is non-nil, case of letters is ignored. |
3593 | Argument REVERSE means reverse order." | |
3594 | (interactive "P") | |
b027f415 RS |
3595 | (gnus-summary-keysort-summary |
3596 | (function string-lessp) | |
745bc783 | 3597 | (function |
b027f415 RS |
3598 | (lambda (a) |
3599 | (if case-fold-search | |
3600 | (downcase (gnus-simplify-subject (nntp-header-subject a) 're-only)) | |
3601 | (gnus-simplify-subject (nntp-header-subject a) 're-only)))) | |
745bc783 JB |
3602 | reverse |
3603 | )) | |
3604 | ||
b027f415 RS |
3605 | (defun gnus-summary-sort-by-date (reverse) |
3606 | "Sort Summary buffer by date. | |
745bc783 JB |
3607 | Argument REVERSE means reverse order." |
3608 | (interactive "P") | |
b027f415 RS |
3609 | (gnus-summary-keysort-summary |
3610 | (function string-lessp) | |
745bc783 | 3611 | (function |
b027f415 RS |
3612 | (lambda (a) |
3613 | (gnus-sortable-date (nntp-header-date a)))) | |
745bc783 JB |
3614 | reverse |
3615 | )) | |
3616 | ||
b027f415 RS |
3617 | (defun gnus-summary-keysort-summary (predicate key &optional reverse) |
3618 | "Sort Summary buffer by PREDICATE using a value passed by KEY. | |
3619 | Optional argument REVERSE means reverse order." | |
3620 | (let ((current (gnus-summary-article-number))) | |
3621 | (gnus-keysort-headers predicate key reverse) | |
3622 | (gnus-summary-prepare) | |
3623 | (gnus-summary-goto-subject current) | |
3624 | )) | |
3625 | ||
3626 | (defun gnus-summary-sort-summary (predicate &optional reverse) | |
3627 | "Sort Summary buffer by PREDICATE. | |
745bc783 | 3628 | Optional argument REVERSE means reverse order." |
b027f415 | 3629 | (let ((current (gnus-summary-article-number))) |
745bc783 | 3630 | (gnus-sort-headers predicate reverse) |
b027f415 RS |
3631 | (gnus-summary-prepare) |
3632 | (gnus-summary-goto-subject current) | |
745bc783 JB |
3633 | )) |
3634 | ||
b027f415 | 3635 | (defun gnus-summary-reselect-current-group (show-all) |
745bc783 JB |
3636 | "Once exit and then reselect the current newsgroup. |
3637 | Prefix argument SHOW-ALL means to select all articles." | |
3638 | (interactive "P") | |
b027f415 RS |
3639 | (let ((current-subject (gnus-summary-article-number))) |
3640 | (gnus-summary-exit t) | |
745bc783 JB |
3641 | ;; We have to adjust the point of Group mode buffer because the |
3642 | ;; current point was moved to the next unread newsgroup by | |
3643 | ;; exiting. | |
b027f415 RS |
3644 | (gnus-summary-jump-to-group gnus-newsgroup-name) |
3645 | (gnus-group-read-group show-all t) | |
3646 | (gnus-summary-goto-subject current-subject) | |
745bc783 JB |
3647 | )) |
3648 | ||
b027f415 | 3649 | (defun gnus-summary-caesar-message (rotnum) |
745bc783 JB |
3650 | "Caesar rotates all letters of current message by 13/47 places. |
3651 | With prefix arg, specifies the number of places to rotate each letter forward. | |
3652 | Caesar rotates Japanese letters by 47 places in any case." | |
3653 | (interactive "P") | |
b027f415 | 3654 | (gnus-summary-select-article) |
745bc783 | 3655 | (gnus-overload-functions) |
b027f415 | 3656 | (gnus-eval-in-buffer-window gnus-article-buffer |
745bc783 JB |
3657 | (save-restriction |
3658 | (widen) | |
3659 | ;; We don't want to jump to the beginning of the message. | |
3660 | ;; `save-excursion' does not do its job. | |
3661 | (move-to-window-line 0) | |
3662 | (let ((last (point))) | |
3663 | (news-caesar-buffer-body rotnum) | |
3664 | (goto-char last) | |
3665 | (recenter 0) | |
3666 | )) | |
3667 | )) | |
3668 | ||
b027f415 | 3669 | (defun gnus-summary-rmail-digest () |
745bc783 | 3670 | "Run RMAIL on current digest article. |
b027f415 RS |
3671 | gnus-select-digest-hook will be called with no arguments, if that |
3672 | value is non-nil. It is possible to modify the article so that Rmail | |
745bc783 | 3673 | can work with it. |
b027f415 RS |
3674 | gnus-rmail-digest-hook will be called with no arguments, if that value |
3675 | is non-nil. The hook is intended to customize Rmail mode." | |
745bc783 | 3676 | (interactive) |
b027f415 | 3677 | (gnus-summary-select-article) |
745bc783 | 3678 | (require 'rmail) |
b027f415 RS |
3679 | (let ((artbuf gnus-article-buffer) |
3680 | (digbuf (get-buffer-create gnus-digest-buffer)) | |
745bc783 JB |
3681 | (mail-header-separator "")) |
3682 | (set-buffer digbuf) | |
b027f415 | 3683 | (buffer-flush-undo (current-buffer)) |
745bc783 JB |
3684 | (setq buffer-read-only nil) |
3685 | (erase-buffer) | |
3686 | (insert-buffer-substring artbuf) | |
b027f415 | 3687 | (run-hooks 'gnus-select-digest-hook) |
745bc783 JB |
3688 | (gnus-convert-article-to-rmail) |
3689 | (goto-char (point-min)) | |
3690 | ;; Rmail initializations. | |
3691 | (rmail-insert-rmail-file-header) | |
3692 | (rmail-mode) | |
3693 | (rmail-set-message-counters) | |
3694 | (rmail-show-message) | |
3695 | (condition-case () | |
3696 | (progn | |
3697 | (undigestify-rmail-message) | |
3698 | (rmail-expunge) ;Delete original message. | |
3699 | ;; File name is meaningless but `save-buffer' requires it. | |
3700 | (setq buffer-file-name "GNUS Digest") | |
3701 | (setq mode-line-buffer-identification | |
3702 | (concat "Digest: " | |
3703 | (nntp-header-subject gnus-current-headers))) | |
3704 | ;; There is no need to write this buffer to a file. | |
3705 | (make-local-variable 'write-file-hooks) | |
3706 | (setq write-file-hooks | |
3707 | (list (function | |
3708 | (lambda () | |
3709 | (set-buffer-modified-p nil) | |
3710 | (message "(No changes need to be saved)") | |
3711 | 'no-need-to-write-this-buffer)))) | |
3712 | ;; Default file name saving digest messages. | |
3713 | (setq rmail-last-rmail-file | |
3714 | (funcall gnus-rmail-save-name | |
3715 | gnus-newsgroup-name | |
3716 | gnus-current-headers | |
3717 | gnus-newsgroup-last-rmail | |
3718 | )) | |
3719 | (setq rmail-last-file | |
3720 | (funcall gnus-mail-save-name | |
3721 | gnus-newsgroup-name | |
3722 | gnus-current-headers | |
3723 | gnus-newsgroup-last-mail | |
3724 | )) | |
3725 | ;; Prevent generating new buffer named ***<N> each time. | |
3726 | (setq rmail-summary-buffer | |
b027f415 RS |
3727 | (get-buffer-create gnus-digest-summary-buffer)) |
3728 | (run-hooks 'gnus-rmail-digest-hook) | |
745bc783 JB |
3729 | ;; Take all windows safely. |
3730 | (gnus-configure-windows '(1 0 0)) | |
b027f415 RS |
3731 | (pop-to-buffer gnus-group-buffer) |
3732 | ;; Use Summary Article windows for Digest summary and | |
745bc783 JB |
3733 | ;; Digest buffers. |
3734 | (if gnus-digest-show-summary | |
b027f415 RS |
3735 | (let ((gnus-summary-buffer gnus-digest-summary-buffer) |
3736 | (gnus-article-buffer gnus-digest-buffer)) | |
3737 | (gnus-configure-windows 'article) | |
3738 | (pop-to-buffer gnus-digest-buffer) | |
745bc783 | 3739 | (rmail-summary) |
b027f415 | 3740 | (pop-to-buffer gnus-digest-summary-buffer) |
745bc783 JB |
3741 | (message (substitute-command-keys |
3742 | "Type \\[rmail-summary-quit] to return to GNUS"))) | |
b027f415 RS |
3743 | (let ((gnus-summary-buffer gnus-digest-buffer)) |
3744 | (gnus-configure-windows 'summary) | |
3745 | (pop-to-buffer gnus-digest-buffer) | |
745bc783 JB |
3746 | (message (substitute-command-keys |
3747 | "Type \\[rmail-quit] to return to GNUS"))) | |
3748 | ) | |
3749 | ;; Move the buffers to the end of buffer list. | |
b027f415 RS |
3750 | (bury-buffer gnus-article-buffer) |
3751 | (bury-buffer gnus-group-buffer) | |
3752 | (bury-buffer gnus-digest-summary-buffer) | |
3753 | (bury-buffer gnus-digest-buffer)) | |
745bc783 JB |
3754 | (error (set-buffer-modified-p nil) |
3755 | (kill-buffer digbuf) | |
3756 | ;; This command should not signal an error because the | |
3757 | ;; command is called from hooks. | |
3758 | (ding) (message "Article is not a digest"))) | |
3759 | )) | |
3760 | ||
b027f415 | 3761 | (defun gnus-summary-save-article () |
745bc783 | 3762 | "Save this article using default saver function. |
b027f415 | 3763 | The variable `gnus-default-article-saver' specifies the saver function." |
745bc783 | 3764 | (interactive) |
b027f415 | 3765 | (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers) |
745bc783 JB |
3766 | (if gnus-default-article-saver |
3767 | (call-interactively gnus-default-article-saver) | |
3768 | (error "No default saver is defined."))) | |
3769 | ||
b027f415 | 3770 | (defun gnus-summary-save-in-rmail (&optional filename) |
745bc783 JB |
3771 | "Append this article to Rmail file. |
3772 | Optional argument FILENAME specifies file name. | |
3773 | Directory to save to is default to `gnus-article-save-directory' which | |
3774 | is initialized from the SAVEDIR environment variable." | |
3775 | (interactive) | |
b027f415 RS |
3776 | (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers) |
3777 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
3778 | (save-excursion |
3779 | (save-restriction | |
3780 | (widen) | |
3781 | (let ((default-name | |
3782 | (funcall gnus-rmail-save-name | |
3783 | gnus-newsgroup-name | |
3784 | gnus-current-headers | |
3785 | gnus-newsgroup-last-rmail | |
3786 | ))) | |
3787 | (or filename | |
3788 | (setq filename | |
3789 | (read-file-name | |
3790 | (concat "Save article in Rmail file: (default " | |
3791 | (file-name-nondirectory default-name) | |
3792 | ") ") | |
3793 | (file-name-directory default-name) | |
3794 | default-name))) | |
3795 | (gnus-make-directory (file-name-directory filename)) | |
3796 | (gnus-output-to-rmail filename) | |
3797 | ;; Remember the directory name to save articles. | |
3798 | (setq gnus-newsgroup-last-rmail filename) | |
3799 | ))) | |
3800 | )) | |
3801 | ||
b027f415 | 3802 | (defun gnus-summary-save-in-mail (&optional filename) |
745bc783 JB |
3803 | "Append this article to Unix mail file. |
3804 | Optional argument FILENAME specifies file name. | |
3805 | Directory to save to is default to `gnus-article-save-directory' which | |
3806 | is initialized from the SAVEDIR environment variable." | |
3807 | (interactive) | |
b027f415 RS |
3808 | (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers) |
3809 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
3810 | (save-excursion |
3811 | (save-restriction | |
3812 | (widen) | |
3813 | (let ((default-name | |
3814 | (funcall gnus-mail-save-name | |
3815 | gnus-newsgroup-name | |
3816 | gnus-current-headers | |
3817 | gnus-newsgroup-last-mail | |
3818 | ))) | |
3819 | (or filename | |
3820 | (setq filename | |
3821 | (read-file-name | |
3822 | (concat "Save article in Unix mail file: (default " | |
3823 | (file-name-nondirectory default-name) | |
3824 | ") ") | |
3825 | (file-name-directory default-name) | |
3826 | default-name))) | |
3827 | (gnus-make-directory (file-name-directory filename)) | |
8649e3a0 | 3828 | (rmail-output filename 1 t t) |
745bc783 JB |
3829 | ;; Remember the directory name to save articles. |
3830 | (setq gnus-newsgroup-last-mail filename) | |
3831 | ))) | |
3832 | )) | |
3833 | ||
b027f415 | 3834 | (defun gnus-summary-save-in-file (&optional filename) |
745bc783 JB |
3835 | "Append this article to file. |
3836 | Optional argument FILENAME specifies file name. | |
3837 | Directory to save to is default to `gnus-article-save-directory' which | |
3838 | is initialized from the SAVEDIR environment variable." | |
3839 | (interactive) | |
b027f415 RS |
3840 | (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers) |
3841 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
3842 | (save-excursion |
3843 | (save-restriction | |
3844 | (widen) | |
3845 | (let ((default-name | |
3846 | (funcall gnus-file-save-name | |
3847 | gnus-newsgroup-name | |
3848 | gnus-current-headers | |
3849 | gnus-newsgroup-last-file | |
3850 | ))) | |
3851 | (or filename | |
3852 | (setq filename | |
3853 | (read-file-name | |
3854 | (concat "Save article in file: (default " | |
3855 | (file-name-nondirectory default-name) | |
3856 | ") ") | |
3857 | (file-name-directory default-name) | |
3858 | default-name))) | |
3859 | (gnus-make-directory (file-name-directory filename)) | |
3860 | (gnus-output-to-file filename) | |
3861 | ;; Remember the directory name to save articles. | |
3862 | (setq gnus-newsgroup-last-file filename) | |
3863 | ))) | |
3864 | )) | |
3865 | ||
b027f415 | 3866 | (defun gnus-summary-save-in-folder (&optional folder) |
745bc783 JB |
3867 | "Save this article to MH folder (using `rcvstore' in MH library). |
3868 | Optional argument FOLDER specifies folder name." | |
3869 | (interactive) | |
b027f415 RS |
3870 | (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers) |
3871 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
3872 | (save-restriction |
3873 | (widen) | |
3874 | ;; Thanks to yuki@flab.Fujitsu.JUNET and ohm@kaba.junet. | |
3875 | (mh-find-path) | |
3876 | (let ((folder | |
3877 | (or folder | |
3878 | (mh-prompt-for-folder "Save article in" | |
3879 | (funcall gnus-folder-save-name | |
3880 | gnus-newsgroup-name | |
3881 | gnus-current-headers | |
3882 | gnus-newsgroup-last-folder | |
3883 | ) | |
3884 | t | |
3885 | ))) | |
3886 | (errbuf (get-buffer-create " *GNUS rcvstore*"))) | |
3887 | (unwind-protect | |
3888 | (call-process-region (point-min) (point-max) | |
3889 | (expand-file-name "rcvstore" mh-lib) | |
3890 | nil errbuf nil folder) | |
3891 | (set-buffer errbuf) | |
3892 | (if (zerop (buffer-size)) | |
3893 | (message "Article saved in folder: %s" folder) | |
3894 | (message "%s" (buffer-string))) | |
3895 | (kill-buffer errbuf) | |
3896 | (setq gnus-newsgroup-last-folder folder)) | |
3897 | )) | |
3898 | )) | |
3899 | ||
b027f415 | 3900 | (defun gnus-summary-pipe-output () |
745bc783 JB |
3901 | "Pipe this article to subprocess." |
3902 | (interactive) | |
3903 | ;; Ignore `gnus-save-all-headers' since this is not save command. | |
b027f415 RS |
3904 | ;;(gnus-summary-select-article) |
3905 | ;; Huuum. Is this right? | |
3906 | (gnus-summary-select-article gnus-save-all-headers gnus-save-all-headers) | |
3907 | (gnus-eval-in-buffer-window gnus-article-buffer | |
745bc783 JB |
3908 | (save-restriction |
3909 | (widen) | |
3910 | (let ((command (read-string "Shell command on article: " | |
3911 | gnus-last-shell-command))) | |
3912 | (if (string-equal command "") | |
3913 | (setq command gnus-last-shell-command)) | |
3914 | (shell-command-on-region (point-min) (point-max) command nil) | |
3915 | (setq gnus-last-shell-command command) | |
3916 | )) | |
3917 | )) | |
3918 | ||
b027f415 | 3919 | (defun gnus-summary-catchup (all &optional quietly) |
745bc783 JB |
3920 | "Mark all articles not marked as unread in this newsgroup as read. |
3921 | If prefix argument ALL is non-nil, all articles are marked as read." | |
3922 | (interactive "P") | |
3923 | (if (or quietly | |
3924 | (y-or-n-p | |
3925 | (if all | |
3926 | "Do you really want to mark everything as read? " | |
3927 | "Delete all articles not marked as unread? "))) | |
3928 | (let ((unmarked | |
3929 | (gnus-set-difference gnus-newsgroup-unreads | |
3930 | (if (not all) gnus-newsgroup-marked)))) | |
3931 | (message "") ;Erase "Yes or No" question. | |
b027f415 RS |
3932 | ;; Hidden thread subtrees must be searched for ,too. |
3933 | (gnus-summary-show-all-threads) | |
745bc783 | 3934 | (while unmarked |
b027f415 | 3935 | (gnus-summary-mark-as-read (car unmarked) "C") |
745bc783 JB |
3936 | (setq unmarked (cdr unmarked)) |
3937 | )) | |
3938 | )) | |
3939 | ||
b027f415 | 3940 | (defun gnus-summary-catchup-all (&optional quietly) |
745bc783 JB |
3941 | "Mark all articles in this newsgroup as read." |
3942 | (interactive) | |
b027f415 | 3943 | (gnus-summary-catchup t quietly)) |
745bc783 | 3944 | |
b027f415 | 3945 | (defun gnus-summary-catchup-and-exit (all &optional quietly) |
745bc783 JB |
3946 | "Mark all articles not marked as unread in this newsgroup as read, then exit. |
3947 | If prefix argument ALL is non-nil, all articles are marked as read." | |
3948 | (interactive "P") | |
3949 | (if (or quietly | |
3950 | (y-or-n-p | |
3951 | (if all | |
3952 | "Do you really want to mark everything as read? " | |
3953 | "Delete all articles not marked as unread? "))) | |
3954 | (let ((unmarked | |
3955 | (gnus-set-difference gnus-newsgroup-unreads | |
3956 | (if (not all) gnus-newsgroup-marked)))) | |
3957 | (message "") ;Erase "Yes or No" question. | |
3958 | (while unmarked | |
3959 | (gnus-mark-article-as-read (car unmarked)) | |
3960 | (setq unmarked (cdr unmarked))) | |
3961 | ;; Select next newsgroup or exit. | |
3962 | (cond ((eq gnus-auto-select-next 'quietly) | |
3963 | ;; Select next newsgroup quietly. | |
b027f415 | 3964 | (gnus-summary-next-group nil)) |
745bc783 | 3965 | (t |
b027f415 | 3966 | (gnus-summary-exit))) |
745bc783 JB |
3967 | ))) |
3968 | ||
b027f415 | 3969 | (defun gnus-summary-catchup-all-and-exit (&optional quietly) |
745bc783 JB |
3970 | "Mark all articles in this newsgroup as read, and then exit." |
3971 | (interactive) | |
b027f415 | 3972 | (gnus-summary-catchup-and-exit t quietly)) |
745bc783 | 3973 | |
b027f415 | 3974 | (defun gnus-summary-edit-global-kill () |
745bc783 JB |
3975 | "Edit a global KILL file." |
3976 | (interactive) | |
b027f415 RS |
3977 | (setq gnus-current-kill-article (gnus-summary-article-number)) |
3978 | (gnus-kill-file-edit-file nil) ;Nil stands for global KILL file. | |
745bc783 JB |
3979 | (message |
3980 | (substitute-command-keys | |
b027f415 | 3981 | "Editing a global KILL file (Type \\[gnus-kill-file-exit] to exit)"))) |
745bc783 | 3982 | |
b027f415 | 3983 | (defun gnus-summary-edit-local-kill () |
745bc783 JB |
3984 | "Edit a local KILL file applied to the current newsgroup." |
3985 | (interactive) | |
b027f415 RS |
3986 | (setq gnus-current-kill-article (gnus-summary-article-number)) |
3987 | (gnus-kill-file-edit-file gnus-newsgroup-name) | |
745bc783 JB |
3988 | (message |
3989 | (substitute-command-keys | |
b027f415 | 3990 | "Editing a local KILL file (Type \\[gnus-kill-file-exit] to exit)"))) |
745bc783 | 3991 | |
b027f415 | 3992 | (defun gnus-summary-exit (&optional temporary) |
745bc783 | 3993 | "Exit reading current newsgroup, and then return to group selection mode. |
b027f415 | 3994 | gnus-exit-group-hook is called with no arguments if that value is non-nil." |
745bc783 JB |
3995 | (interactive) |
3996 | (let ((updated nil) | |
3997 | (gnus-newsgroup-headers gnus-newsgroup-headers) | |
3998 | (gnus-newsgroup-unreads gnus-newsgroup-unreads) | |
3999 | (gnus-newsgroup-unselected gnus-newsgroup-unselected) | |
4000 | (gnus-newsgroup-marked gnus-newsgroup-marked)) | |
b027f415 RS |
4001 | ;; Important internal variables are saved, so we can reenter |
4002 | ;; Summary buffer even if hook changes them. | |
4003 | (run-hooks 'gnus-exit-group-hook) | |
745bc783 JB |
4004 | (gnus-update-unread-articles gnus-newsgroup-name |
4005 | (append gnus-newsgroup-unselected | |
4006 | gnus-newsgroup-unreads) | |
4007 | gnus-newsgroup-marked) | |
4008 | ;; T means ignore unsubscribed newsgroups. | |
4009 | (if gnus-use-cross-reference | |
4010 | (setq updated | |
4011 | (gnus-mark-as-read-by-xref gnus-newsgroup-name | |
4012 | gnus-newsgroup-headers | |
4013 | gnus-newsgroup-unreads | |
4014 | (eq gnus-use-cross-reference t) | |
4015 | ))) | |
4016 | ;; Do not switch windows but change the buffer to work. | |
b027f415 | 4017 | (set-buffer gnus-group-buffer) |
745bc783 JB |
4018 | ;; Update cross referenced group info. |
4019 | (while updated | |
b027f415 | 4020 | (gnus-group-update-group (car updated) t) ;Ignore invisible group. |
745bc783 | 4021 | (setq updated (cdr updated))) |
b027f415 | 4022 | (gnus-group-update-group gnus-newsgroup-name)) |
745bc783 | 4023 | ;; Make sure where I was, and go to next newsgroup. |
b027f415 RS |
4024 | (gnus-group-jump-to-group gnus-newsgroup-name) |
4025 | (gnus-group-next-unread-group 1) | |
745bc783 JB |
4026 | (if temporary |
4027 | ;; If exiting temporary, caller should adjust Group mode | |
4028 | ;; buffer point by itself. | |
4029 | nil ;Nothing to do. | |
4030 | ;; Return to Group mode buffer. | |
b027f415 RS |
4031 | (if (get-buffer gnus-summary-buffer) |
4032 | (bury-buffer gnus-summary-buffer)) | |
4033 | (if (get-buffer gnus-article-buffer) | |
4034 | (bury-buffer gnus-article-buffer)) | |
4035 | (gnus-configure-windows 'newsgroups) | |
4036 | (pop-to-buffer gnus-group-buffer))) | |
4037 | ||
4038 | (defun gnus-summary-quit () | |
745bc783 JB |
4039 | "Quit reading current newsgroup without updating read article info." |
4040 | (interactive) | |
4041 | (if (y-or-n-p "Do you really wanna quit reading this group? ") | |
4042 | (progn | |
4043 | (message "") ;Erase "Yes or No" question. | |
4044 | ;; Return to Group selection mode. | |
b027f415 RS |
4045 | (if (get-buffer gnus-summary-buffer) |
4046 | (bury-buffer gnus-summary-buffer)) | |
4047 | (if (get-buffer gnus-article-buffer) | |
4048 | (bury-buffer gnus-article-buffer)) | |
4049 | (gnus-configure-windows 'newsgroups) | |
4050 | (pop-to-buffer gnus-group-buffer) | |
4051 | (gnus-group-jump-to-group gnus-newsgroup-name) ;Make sure where I was. | |
4052 | (gnus-group-next-group 1) ;(gnus-group-next-unread-group 1) | |
745bc783 JB |
4053 | ))) |
4054 | ||
b027f415 RS |
4055 | (defun gnus-summary-describe-briefly () |
4056 | "Describe Summary mode commands briefly." | |
745bc783 JB |
4057 | (interactive) |
4058 | (message | |
4059 | (concat | |
b027f415 RS |
4060 | (substitute-command-keys "\\[gnus-summary-next-page]:Select ") |
4061 | (substitute-command-keys "\\[gnus-summary-next-unread-article]:Forward ") | |
4062 | (substitute-command-keys "\\[gnus-summary-prev-unread-article]:Backward ") | |
4063 | (substitute-command-keys "\\[gnus-summary-exit]:Exit ") | |
4064 | (substitute-command-keys "\\[gnus-info-find-node]:Run Info ") | |
4065 | (substitute-command-keys "\\[gnus-summary-describe-briefly]:This help") | |
745bc783 JB |
4066 | ))) |
4067 | ||
4068 | \f | |
4069 | ;;; | |
4070 | ;;; GNUS Article Mode | |
4071 | ;;; | |
4072 | ||
b027f415 | 4073 | (if gnus-article-mode-map |
745bc783 | 4074 | nil |
b027f415 RS |
4075 | (setq gnus-article-mode-map (make-keymap)) |
4076 | (suppress-keymap gnus-article-mode-map) | |
4077 | (define-key gnus-article-mode-map " " 'gnus-article-next-page) | |
4078 | (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page) | |
4079 | (define-key gnus-article-mode-map "r" 'gnus-article-refer-article) | |
4080 | (define-key gnus-article-mode-map "o" 'gnus-article-pop-article) | |
4081 | (define-key gnus-article-mode-map "h" 'gnus-article-show-summary) | |
4082 | (define-key gnus-article-mode-map "s" 'gnus-article-show-summary) | |
4083 | (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly) | |
4084 | (define-key gnus-article-mode-map "\C-c\C-i" 'gnus-info-find-node)) | |
4085 | ||
4086 | (defun gnus-article-mode () | |
745bc783 JB |
4087 | "Major mode for browsing through an article. |
4088 | All normal editing commands are turned off. | |
4089 | Instead, these commands are available: | |
b027f415 | 4090 | \\{gnus-article-mode-map} |
745bc783 JB |
4091 | |
4092 | Various hooks for customization: | |
b027f415 | 4093 | gnus-article-mode-hook |
745bc783 JB |
4094 | Entry to this mode calls the value with no arguments, if that |
4095 | value is non-nil. | |
4096 | ||
b027f415 | 4097 | gnus-article-prepare-hook |
745bc783 JB |
4098 | Called with no arguments after an article is prepared for reading, |
4099 | if that value is non-nil." | |
4100 | (interactive) | |
4101 | (kill-all-local-variables) | |
4102 | ;; Gee. Why don't you upgrade? | |
4103 | (cond ((boundp 'mode-line-modified) | |
4104 | (setq mode-line-modified "--- ")) | |
4105 | ((listp (default-value 'mode-line-format)) | |
4106 | (setq mode-line-format | |
4107 | (cons "--- " (cdr (default-value 'mode-line-format)))))) | |
b027f415 RS |
4108 | ;; To disable display-time facility. |
4109 | ;;(make-local-variable 'global-mode-string) | |
4110 | ;;(setq global-mode-string nil) | |
4111 | (setq major-mode 'gnus-article-mode) | |
745bc783 | 4112 | (setq mode-name "Article") |
b027f415 RS |
4113 | (make-local-variable 'minor-mode-alist) |
4114 | (or (assq 'gnus-show-mime minor-mode-alist) | |
4115 | (setq minor-mode-alist | |
4116 | (cons (list 'gnus-show-mime " MIME") minor-mode-alist))) | |
4117 | (gnus-article-set-mode-line) | |
4118 | (use-local-map gnus-article-mode-map) | |
745bc783 JB |
4119 | (make-local-variable 'page-delimiter) |
4120 | (setq page-delimiter gnus-page-delimiter) | |
4121 | (make-local-variable 'mail-header-separator) | |
4122 | (setq mail-header-separator "") ;For caesar function. | |
b027f415 | 4123 | (buffer-flush-undo (current-buffer)) |
745bc783 | 4124 | (setq buffer-read-only t) ;Disable modification |
b027f415 | 4125 | (run-hooks 'gnus-article-mode-hook)) |
745bc783 | 4126 | |
b027f415 | 4127 | (defun gnus-article-setup-buffer () |
745bc783 | 4128 | "Initialize Article mode buffer." |
b027f415 | 4129 | (or (get-buffer gnus-article-buffer) |
745bc783 | 4130 | (save-excursion |
b027f415 RS |
4131 | (set-buffer (get-buffer-create gnus-article-buffer)) |
4132 | (gnus-article-mode)) | |
745bc783 JB |
4133 | )) |
4134 | ||
b027f415 | 4135 | (defun gnus-article-prepare (article &optional all-headers) |
745bc783 | 4136 | "Prepare ARTICLE in Article mode buffer. |
b027f415 | 4137 | ARTICLE can be either a article number or Message-ID. |
745bc783 | 4138 | If optional argument ALL-HEADERS is non-nil, all headers are inserted." |
b027f415 RS |
4139 | ;; Make sure a connection to NNTP server is alive. |
4140 | (if (not (gnus-server-opened)) | |
4141 | (progn | |
4142 | (gnus-start-news-server) | |
4143 | (gnus-request-group gnus-newsgroup-name))) | |
745bc783 | 4144 | (save-excursion |
b027f415 | 4145 | (set-buffer gnus-article-buffer) |
745bc783 JB |
4146 | (let ((buffer-read-only nil)) |
4147 | (erase-buffer) | |
b027f415 RS |
4148 | ;; mhspool does not work with Message-ID. So, let's translate |
4149 | ;; it into an article number as possible as can. This may help | |
4150 | ;; nnspool too. | |
4151 | ;; Note: this conversion must be done here since if the article | |
4152 | ;; is specified by number or message-id has a different meaning | |
4153 | ;; in the following. | |
4154 | (if (let* ((header | |
4155 | (and (stringp article) | |
4156 | (gnus-get-header-by-id article))) | |
4157 | (article | |
4158 | (if header | |
4159 | (nntp-header-number header) article))) | |
4160 | (gnus-request-article article)) | |
745bc783 JB |
4161 | (progn |
4162 | ;; Prepare article buffer | |
4163 | (insert-buffer-substring nntp-server-buffer) | |
b027f415 RS |
4164 | ;; gnus-have-all-headers must be either T or NIL. |
4165 | (setq gnus-have-all-headers | |
4166 | (not (not (or all-headers gnus-show-all-headers)))) | |
745bc783 JB |
4167 | (if (and (numberp article) |
4168 | (not (eq article gnus-current-article))) | |
b027f415 | 4169 | ;; Seems me that a new article has been selected. |
745bc783 JB |
4170 | (progn |
4171 | ;; gnus-current-article must be an article number. | |
4172 | (setq gnus-last-article gnus-current-article) | |
4173 | (setq gnus-current-article article) | |
b027f415 RS |
4174 | ;; (setq gnus-current-headers |
4175 | ;; (gnus-find-header-by-number gnus-newsgroup-headers | |
4176 | ;; gnus-current-article)) | |
745bc783 | 4177 | (setq gnus-current-headers |
b027f415 RS |
4178 | (gnus-get-header-by-number gnus-current-article)) |
4179 | (run-hooks 'gnus-mark-article-hook) | |
745bc783 | 4180 | )) |
b027f415 RS |
4181 | ;; Clear article history only when the article is |
4182 | ;; retrieved by the article number. | |
4183 | (if (numberp article) | |
4184 | (setq gnus-current-history nil)) | |
4185 | ;; Hooks for modifying contents of the article. This hook | |
745bc783 | 4186 | ;; must be called before being narrowed. |
b027f415 RS |
4187 | (run-hooks 'gnus-article-prepare-hook) |
4188 | ;; Decode MIME message. | |
4189 | (if (and gnus-show-mime | |
4190 | (gnus-fetch-field "Mime-Version")) | |
4191 | (funcall gnus-show-mime-method)) | |
745bc783 JB |
4192 | ;; Delete unnecessary headers. |
4193 | (or gnus-have-all-headers | |
b027f415 | 4194 | (gnus-article-delete-headers)) |
745bc783 JB |
4195 | ;; Do page break. |
4196 | (goto-char (point-min)) | |
4197 | (if gnus-break-pages | |
4198 | (gnus-narrow-to-page)) | |
4199 | ;; Next function must be called after setting | |
4200 | ;; `gnus-current-article' variable and narrowed to page. | |
b027f415 | 4201 | (gnus-article-set-mode-line) |
745bc783 | 4202 | ) |
b027f415 | 4203 | ;; There is no such article. |
745bc783 | 4204 | (if (numberp article) |
b027f415 | 4205 | (gnus-summary-mark-as-read article)) |
745bc783 JB |
4206 | (ding) (message "No such article (may be canceled)")) |
4207 | ))) | |
4208 | ||
b027f415 | 4209 | (defun gnus-article-show-all-headers () |
745bc783 JB |
4210 | "Show all article headers in Article mode buffer." |
4211 | (or gnus-have-all-headers | |
b027f415 | 4212 | (gnus-article-prepare gnus-current-article t))) |
745bc783 | 4213 | |
b027f415 | 4214 | ;;(defun gnus-article-set-mode-line () |
745bc783 JB |
4215 | ;; "Set Article mode line string." |
4216 | ;; (setq mode-line-buffer-identification | |
4217 | ;; (list 17 | |
4218 | ;; (format "GNUS: %s {%d-%d} %d" | |
4219 | ;; gnus-newsgroup-name | |
4220 | ;; gnus-newsgroup-begin | |
4221 | ;; gnus-newsgroup-end | |
4222 | ;; gnus-current-article | |
4223 | ;; ))) | |
4224 | ;; (set-buffer-modified-p t)) | |
4225 | ||
b027f415 RS |
4226 | ;;(defun gnus-article-set-mode-line () |
4227 | ;; "Set Article mode line string." | |
4228 | ;; (let ((unmarked | |
4229 | ;; (- (length gnus-newsgroup-unreads) | |
4230 | ;; (length (gnus-intersection | |
4231 | ;; gnus-newsgroup-unreads gnus-newsgroup-marked)))) | |
4232 | ;; (unselected | |
4233 | ;; (- (length gnus-newsgroup-unselected) | |
4234 | ;; (length (gnus-intersection | |
4235 | ;; gnus-newsgroup-unselected gnus-newsgroup-marked))))) | |
4236 | ;; (setq mode-line-buffer-identification | |
4237 | ;; (list 17 | |
4238 | ;; (format "GNUS: %s{%d} %s" | |
4239 | ;; gnus-newsgroup-name | |
4240 | ;; gnus-current-article | |
4241 | ;; ;; This is proposed by tale@pawl.rpi.edu. | |
4242 | ;; (cond ((and (zerop unmarked) | |
4243 | ;; (zerop unselected)) | |
4244 | ;; " ") | |
4245 | ;; ((zerop unselected) | |
4246 | ;; (format "%d more" unmarked)) | |
4247 | ;; (t | |
4248 | ;; (format "%d(+%d) more" unmarked unselected))) | |
4249 | ;; )))) | |
4250 | ;; (set-buffer-modified-p t)) | |
4251 | ||
4252 | ;; New implementation in gnus 3.14.3 | |
4253 | ||
4254 | (defun gnus-article-set-mode-line () | |
4255 | "Set Article mode line string. | |
4256 | If you don't like it, define your own gnus-article-set-mode-line." | |
4257 | (let ((maxlen 15) ;Maximum subject length | |
4258 | (subject | |
4259 | (if gnus-current-headers | |
4260 | (nntp-header-subject gnus-current-headers) ""))) | |
4261 | ;; The value must be a string to escape %-constructs because of subject. | |
745bc783 | 4262 | (setq mode-line-buffer-identification |
b027f415 RS |
4263 | (format "GNUS: %s%s %s%s%s" |
4264 | gnus-newsgroup-name | |
4265 | (if gnus-current-article | |
4266 | (format "/%d" gnus-current-article) "") | |
4267 | (substring subject 0 (min (length subject) maxlen)) | |
4268 | (if (> (length subject) maxlen) "..." "") | |
4269 | (make-string (max 0 (- 17 (length subject))) ? ) | |
4270 | ))) | |
745bc783 JB |
4271 | (set-buffer-modified-p t)) |
4272 | ||
b027f415 | 4273 | (defun gnus-article-delete-headers () |
745bc783 JB |
4274 | "Delete unnecessary headers." |
4275 | (save-excursion | |
4276 | (save-restriction | |
4277 | (goto-char (point-min)) | |
4278 | (narrow-to-region (point-min) | |
4279 | (progn (search-forward "\n\n" nil 'move) (point))) | |
4280 | (goto-char (point-min)) | |
4281 | (and (stringp gnus-ignored-headers) | |
4282 | (while (re-search-forward gnus-ignored-headers nil t) | |
4283 | (beginning-of-line) | |
4284 | (delete-region (point) | |
4285 | (progn (re-search-forward "\n[^ \t]") | |
4286 | (forward-char -1) | |
4287 | (point))))) | |
4288 | ))) | |
4289 | ||
4290 | ;; Working on article's buffer | |
4291 | ||
b027f415 | 4292 | (defun gnus-article-next-page (lines) |
745bc783 JB |
4293 | "Show next page of current article. |
4294 | If end of article, return non-nil. Otherwise return nil. | |
4295 | Argument LINES specifies lines to be scrolled up." | |
4296 | (interactive "P") | |
4297 | (move-to-window-line -1) | |
4298 | ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo) | |
4299 | (if (save-excursion | |
4300 | (end-of-line) | |
4301 | (and (pos-visible-in-window-p) ;Not continuation line. | |
4302 | (eobp))) | |
4303 | ;; Nothing in this page. | |
4304 | (if (or (not gnus-break-pages) | |
4305 | (save-excursion | |
4306 | (save-restriction | |
4307 | (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer? | |
4308 | t ;Nothing more. | |
4309 | (gnus-narrow-to-page 1) ;Go to next page. | |
4310 | nil | |
4311 | ) | |
4312 | ;; More in this page. | |
4313 | (condition-case () | |
4314 | (scroll-up lines) | |
4315 | (end-of-buffer | |
4316 | ;; Long lines may cause an end-of-buffer error. | |
4317 | (goto-char (point-max)))) | |
4318 | nil | |
4319 | )) | |
4320 | ||
b027f415 | 4321 | (defun gnus-article-prev-page (lines) |
745bc783 JB |
4322 | "Show previous page of current article. |
4323 | Argument LINES specifies lines to be scrolled down." | |
4324 | (interactive "P") | |
4325 | (move-to-window-line 0) | |
4326 | (if (and gnus-break-pages | |
4327 | (bobp) | |
4328 | (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer? | |
4329 | (progn | |
4330 | (gnus-narrow-to-page -1) ;Go to previous page. | |
4331 | (goto-char (point-max)) | |
4332 | (recenter -1)) | |
4333 | (scroll-down lines))) | |
4334 | ||
b027f415 | 4335 | (defun gnus-article-next-digest (nth) |
745bc783 JB |
4336 | "Move to head of NTH next digested message. |
4337 | Set mark at end of digested message." | |
4338 | ;; Stop page breaking in digest mode. | |
4339 | (widen) | |
4340 | (end-of-line) | |
4341 | ;; Skip NTH - 1 digest. | |
4342 | ;; Suggested by Khalid Sattar <admin@cs.exeter.ac.uk>. | |
4343 | ;; Digest separator is customizable. | |
4344 | ;; Suggested by Skip Montanaro <montanaro@sprite.crd.ge.com>. | |
4345 | (while (and (> nth 1) | |
4346 | (re-search-forward gnus-digest-separator nil 'move)) | |
4347 | (setq nth (1- nth))) | |
4348 | (if (re-search-forward gnus-digest-separator nil t) | |
4349 | (let ((begin (point))) | |
4350 | ;; Search for end of this message. | |
4351 | (end-of-line) | |
4352 | (if (re-search-forward gnus-digest-separator nil t) | |
4353 | (progn | |
4354 | (search-backward "\n\n") ;This may be incorrect. | |
4355 | (forward-line 1)) | |
4356 | (goto-char (point-max))) | |
4357 | (push-mark) ;Set mark at end of digested message. | |
4358 | (goto-char begin) | |
4359 | (beginning-of-line) | |
4360 | ;; Show From: and Subject: fields. | |
4361 | (recenter 1)) | |
4362 | (message "End of message") | |
4363 | )) | |
4364 | ||
b027f415 | 4365 | (defun gnus-article-prev-digest (nth) |
745bc783 JB |
4366 | "Move to head of NTH previous digested message." |
4367 | ;; Stop page breaking in digest mode. | |
4368 | (widen) | |
4369 | (beginning-of-line) | |
4370 | ;; Skip NTH - 1 digest. | |
4371 | ;; Suggested by Khalid Sattar <admin@cs.exeter.ac.uk>. | |
4372 | ;; Digest separator is customizable. | |
4373 | ;; Suggested by Skip Montanaro <montanaro@sprite.crd.ge.com>. | |
4374 | (while (and (> nth 1) | |
4375 | (re-search-backward gnus-digest-separator nil 'move)) | |
4376 | (setq nth (1- nth))) | |
4377 | (if (re-search-backward gnus-digest-separator nil t) | |
4378 | (let ((begin (point))) | |
4379 | ;; Search for end of this message. | |
4380 | (end-of-line) | |
4381 | (if (re-search-forward gnus-digest-separator nil t) | |
4382 | (progn | |
4383 | (search-backward "\n\n") ;This may be incorrect. | |
4384 | (forward-line 1)) | |
4385 | (goto-char (point-max))) | |
4386 | (push-mark) ;Set mark at end of digested message. | |
4387 | (goto-char begin) | |
4388 | ;; Show From: and Subject: fields. | |
4389 | (recenter 1)) | |
4390 | (goto-char (point-min)) | |
4391 | (message "Top of message") | |
4392 | )) | |
4393 | ||
b027f415 | 4394 | (defun gnus-article-refer-article () |
745bc783 JB |
4395 | "Read article specified by message-id around point." |
4396 | (interactive) | |
4397 | (save-window-excursion | |
4398 | (save-excursion | |
4399 | (re-search-forward ">" nil t) ;Move point to end of "<....>". | |
4400 | (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t) | |
4401 | (let ((message-id | |
4402 | (buffer-substring (match-beginning 1) (match-end 1)))) | |
b027f415 RS |
4403 | (set-buffer gnus-summary-buffer) |
4404 | (gnus-summary-refer-article message-id)) | |
745bc783 JB |
4405 | (error "No references around point")) |
4406 | ))) | |
4407 | ||
b027f415 | 4408 | (defun gnus-article-pop-article () |
745bc783 JB |
4409 | "Pop up article history." |
4410 | (interactive) | |
4411 | (save-window-excursion | |
b027f415 RS |
4412 | (set-buffer gnus-summary-buffer) |
4413 | (gnus-summary-refer-article nil))) | |
745bc783 | 4414 | |
b027f415 RS |
4415 | (defun gnus-article-show-summary () |
4416 | "Reconfigure windows to show Summary buffer." | |
745bc783 | 4417 | (interactive) |
b027f415 RS |
4418 | (gnus-configure-windows 'article) |
4419 | (pop-to-buffer gnus-summary-buffer) | |
4420 | (gnus-summary-goto-subject gnus-current-article)) | |
745bc783 | 4421 | |
b027f415 | 4422 | (defun gnus-article-describe-briefly () |
745bc783 JB |
4423 | "Describe Article mode commands briefly." |
4424 | (interactive) | |
4425 | (message | |
4426 | (concat | |
b027f415 RS |
4427 | (substitute-command-keys "\\[gnus-article-next-page]:Next page ") |
4428 | (substitute-command-keys "\\[gnus-article-prev-page]:Prev page ") | |
4429 | (substitute-command-keys "\\[gnus-article-show-summary]:Show Summary ") | |
4430 | (substitute-command-keys "\\[gnus-info-find-node]:Run Info ") | |
4431 | (substitute-command-keys "\\[gnus-article-describe-briefly]:This help") | |
745bc783 JB |
4432 | ))) |
4433 | ||
4434 | \f | |
4435 | ;;; | |
4436 | ;;; GNUS KILL-File Mode | |
4437 | ;;; | |
4438 | ||
b027f415 | 4439 | (if gnus-kill-file-mode-map |
745bc783 | 4440 | nil |
b027f415 RS |
4441 | (setq gnus-kill-file-mode-map (copy-keymap emacs-lisp-mode-map)) |
4442 | (define-key gnus-kill-file-mode-map "\C-c\C-k\C-s" 'gnus-kill-file-kill-by-subject) | |
4443 | (define-key gnus-kill-file-mode-map "\C-c\C-k\C-a" 'gnus-kill-file-kill-by-author) | |
4444 | (define-key gnus-kill-file-mode-map "\C-c\C-a" 'gnus-kill-file-apply-buffer) | |
4445 | (define-key gnus-kill-file-mode-map "\C-c\C-e" 'gnus-kill-file-apply-last-sexp) | |
4446 | (define-key gnus-kill-file-mode-map "\C-c\C-c" 'gnus-kill-file-exit) | |
4447 | (define-key gnus-kill-file-mode-map "\C-c\C-i" 'gnus-info-find-node)) | |
4448 | ||
4449 | (defun gnus-kill-file-mode () | |
745bc783 JB |
4450 | "Major mode for editing KILL file. |
4451 | ||
4452 | In addition to Emacs-Lisp Mode, the following commands are available: | |
4453 | ||
b027f415 RS |
4454 | \\[gnus-kill-file-kill-by-subject] Insert KILL command for current subject. |
4455 | \\[gnus-kill-file-kill-by-author] Insert KILL command for current author. | |
4456 | \\[gnus-kill-file-apply-buffer] Apply current buffer to selected newsgroup. | |
4457 | \\[gnus-kill-file-apply-last-sexp] Apply sexp before point to selected newsgroup. | |
4458 | \\[gnus-kill-file-exit] Save file and exit editing KILL file. | |
4459 | \\[gnus-info-find-node] Read Info about KILL file. | |
745bc783 JB |
4460 | |
4461 | A KILL file contains lisp expressions to be applied to a selected | |
4462 | newsgroup. The purpose is to mark articles as read on the basis of | |
4463 | some set of regexps. A global KILL file is applied to every newsgroup, | |
4464 | and a local KILL file is applied to a specified newsgroup. Since a | |
4465 | global KILL file is applied to every newsgroup, for better performance | |
4466 | use a local one. | |
4467 | ||
4468 | A KILL file can contain any kind of Emacs lisp expressions expected | |
b027f415 | 4469 | to be evaluated in the Summary buffer. Writing lisp programs for this |
745bc783 JB |
4470 | purpose is not so easy because the internal working of GNUS must be |
4471 | well-known. For this reason, GNUS provides a general function which | |
4472 | does this easily for non-Lisp programmers. | |
4473 | ||
b027f415 | 4474 | The `gnus-kill' function executes commands available in Summary Mode |
745bc783 JB |
4475 | by their key sequences. `gnus-kill' should be called with FIELD, |
4476 | REGEXP and optional COMMAND and ALL. FIELD is a string representing | |
4477 | the header field or an empty string. If FIELD is an empty string, the | |
4478 | entire article body is searched for. REGEXP is a string which is | |
4479 | compared with FIELD value. COMMAND is a string representing a valid | |
b027f415 RS |
4480 | key sequence in Summary Mode or Lisp expression. COMMAND is default to |
4481 | '(gnus-summary-mark-as-read nil \"X\"). Make sure that COMMAND is | |
4482 | executed in the Summary buffer. If the second optional argument ALL | |
745bc783 JB |
4483 | is non-nil, the COMMAND is applied to articles which are already |
4484 | marked as read or unread. Articles which are marked are skipped over | |
4485 | by default. | |
4486 | ||
4487 | For example, if you want to mark articles of which subjects contain | |
4488 | the string `AI' as read, a possible KILL file may look like: | |
4489 | ||
4490 | (gnus-kill \"Subject\" \"AI\") | |
4491 | ||
4492 | If you want to mark articles with `D' instead of `X', you can use | |
4493 | the following expression: | |
4494 | ||
4495 | (gnus-kill \"Subject\" \"AI\" \"d\") | |
4496 | ||
4497 | In this example it is assumed that the command | |
b027f415 | 4498 | `gnus-summary-mark-as-read-forward' is assigned to `d' in Summary Mode. |
745bc783 JB |
4499 | |
4500 | It is possible to delete unnecessary headers which are marked with | |
4501 | `X' in a KILL file as follows: | |
4502 | ||
4503 | (gnus-expunge \"X\") | |
4504 | ||
b027f415 | 4505 | If the Summary buffer is empty after applying KILL files, GNUS will |
745bc783 JB |
4506 | exit the selected newsgroup normally. If headers which are marked |
4507 | with `D' are deleted in a KILL file, it is impossible to read articles | |
4508 | which are marked as read in the previous GNUS sessions. Marks other | |
4509 | than `D' should be used for articles which should really be deleted. | |
4510 | ||
4511 | Entry to this mode calls emacs-lisp-mode-hook and | |
b027f415 | 4512 | gnus-kill-file-mode-hook with no arguments, if that value is non-nil." |
745bc783 JB |
4513 | (interactive) |
4514 | (kill-all-local-variables) | |
b027f415 | 4515 | (use-local-map gnus-kill-file-mode-map) |
745bc783 | 4516 | (set-syntax-table emacs-lisp-mode-syntax-table) |
b027f415 | 4517 | (setq major-mode 'gnus-kill-file-mode) |
745bc783 JB |
4518 | (setq mode-name "KILL-File") |
4519 | (lisp-mode-variables nil) | |
b027f415 | 4520 | (run-hooks 'emacs-lisp-mode-hook 'gnus-kill-file-mode-hook)) |
745bc783 | 4521 | |
b027f415 | 4522 | (defun gnus-kill-file-edit-file (newsgroup) |
745bc783 JB |
4523 | "Begin editing a KILL file of NEWSGROUP. |
4524 | If NEWSGROUP is nil, the global KILL file is selected." | |
4525 | (interactive "sNewsgroup: ") | |
4526 | (let ((file (gnus-newsgroup-kill-file newsgroup))) | |
4527 | (gnus-make-directory (file-name-directory file)) | |
4528 | ;; Save current window configuration if this is first invocation. | |
4529 | (or (and (get-file-buffer file) | |
4530 | (get-buffer-window (get-file-buffer file))) | |
4531 | (setq gnus-winconf-kill-file (current-window-configuration))) | |
4532 | ;; Hack windows. | |
4533 | (let ((buffer (find-file-noselect file))) | |
4534 | (cond ((get-buffer-window buffer) | |
4535 | (pop-to-buffer buffer)) | |
b027f415 | 4536 | ((eq major-mode 'gnus-group-mode) |
745bc783 | 4537 | (gnus-configure-windows '(1 0 0)) ;Take all windows. |
b027f415 RS |
4538 | (pop-to-buffer gnus-group-buffer) |
4539 | (let ((gnus-summary-buffer buffer)) | |
745bc783 JB |
4540 | (gnus-configure-windows '(1 1 0)) ;Split into two. |
4541 | (pop-to-buffer buffer))) | |
b027f415 RS |
4542 | ((eq major-mode 'gnus-summary-mode) |
4543 | (gnus-configure-windows 'article) | |
4544 | (pop-to-buffer gnus-article-buffer) | |
4545 | (bury-buffer gnus-article-buffer) | |
745bc783 JB |
4546 | (switch-to-buffer buffer)) |
4547 | (t ;No good rules. | |
4548 | (find-file-other-window file)) | |
4549 | )) | |
b027f415 | 4550 | (gnus-kill-file-mode) |
745bc783 JB |
4551 | )) |
4552 | ||
b027f415 | 4553 | (defun gnus-kill-file-kill-by-subject () |
745bc783 JB |
4554 | "Insert KILL command for current subject." |
4555 | (interactive) | |
4556 | (insert | |
4557 | (format "(gnus-kill \"Subject\" %s)\n" | |
4558 | (prin1-to-string | |
4559 | (if gnus-current-kill-article | |
4560 | (regexp-quote | |
4561 | (nntp-header-subject | |
b027f415 RS |
4562 | ;; No need to speed up this command. |
4563 | ;;(gnus-get-header-by-number gnus-current-kill-article) | |
745bc783 JB |
4564 | (gnus-find-header-by-number gnus-newsgroup-headers |
4565 | gnus-current-kill-article))) | |
4566 | ""))))) | |
4567 | ||
b027f415 | 4568 | (defun gnus-kill-file-kill-by-author () |
745bc783 JB |
4569 | "Insert KILL command for current author." |
4570 | (interactive) | |
4571 | (insert | |
4572 | (format "(gnus-kill \"From\" %s)\n" | |
4573 | (prin1-to-string | |
4574 | (if gnus-current-kill-article | |
4575 | (regexp-quote | |
4576 | (nntp-header-from | |
b027f415 RS |
4577 | ;; No need to speed up this command. |
4578 | ;;(gnus-get-header-by-number gnus-current-kill-article) | |
745bc783 JB |
4579 | (gnus-find-header-by-number gnus-newsgroup-headers |
4580 | gnus-current-kill-article))) | |
4581 | ""))))) | |
4582 | ||
b027f415 | 4583 | (defun gnus-kill-file-apply-buffer () |
745bc783 JB |
4584 | "Apply current buffer to current newsgroup." |
4585 | (interactive) | |
4586 | (if (and gnus-current-kill-article | |
b027f415 | 4587 | (get-buffer gnus-summary-buffer)) |
745bc783 JB |
4588 | ;; Assume newsgroup is selected. |
4589 | (let ((string (concat "(progn \n" (buffer-string) "\n)" ))) | |
4590 | (save-excursion | |
4591 | (save-window-excursion | |
b027f415 | 4592 | (pop-to-buffer gnus-summary-buffer) |
745bc783 JB |
4593 | (eval (car (read-from-string string)))))) |
4594 | (ding) (message "No newsgroup is selected."))) | |
4595 | ||
b027f415 | 4596 | (defun gnus-kill-file-apply-last-sexp () |
745bc783 JB |
4597 | "Apply sexp before point in current buffer to current newsgroup." |
4598 | (interactive) | |
4599 | (if (and gnus-current-kill-article | |
b027f415 | 4600 | (get-buffer gnus-summary-buffer)) |
745bc783 JB |
4601 | ;; Assume newsgroup is selected. |
4602 | (let ((string | |
4603 | (buffer-substring | |
4604 | (save-excursion (forward-sexp -1) (point)) (point)))) | |
4605 | (save-excursion | |
4606 | (save-window-excursion | |
b027f415 | 4607 | (pop-to-buffer gnus-summary-buffer) |
745bc783 JB |
4608 | (eval (car (read-from-string string)))))) |
4609 | (ding) (message "No newsgroup is selected."))) | |
4610 | ||
b027f415 | 4611 | (defun gnus-kill-file-exit () |
745bc783 JB |
4612 | "Save a KILL file, then return to the previous buffer." |
4613 | (interactive) | |
4614 | (save-buffer) | |
4615 | (let ((killbuf (current-buffer))) | |
4616 | ;; We don't want to return to Article buffer. | |
b027f415 RS |
4617 | (and (get-buffer gnus-article-buffer) |
4618 | (bury-buffer (get-buffer gnus-article-buffer))) | |
745bc783 JB |
4619 | ;; Delete the KILL file windows. |
4620 | (delete-windows-on killbuf) | |
4621 | ;; Restore last window configuration if available. | |
4622 | (and gnus-winconf-kill-file | |
4623 | (set-window-configuration gnus-winconf-kill-file)) | |
4624 | (setq gnus-winconf-kill-file nil) | |
4625 | ;; Kill the KILL file buffer. Suggested by tale@pawl.rpi.edu. | |
4626 | (kill-buffer killbuf))) | |
4627 | ||
4628 | \f | |
4629 | ;;; | |
4630 | ;;; Utility functions | |
4631 | ;;; | |
4632 | ||
4633 | ;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti) | |
4634 | ||
4635 | (defun gnus-batch-kill () | |
4636 | "Run batched KILL. | |
4637 | Usage: emacs -batch -l gnus -f gnus-batch-kill NEWSGROUP ..." | |
4638 | (if (not noninteractive) | |
4639 | (error "gnus-batch-kill is to be used only with -batch")) | |
4640 | (let* ((group nil) | |
4641 | (subscribed nil) | |
4642 | (newsrc nil) | |
4643 | (yes-and-no | |
4644 | (gnus-parse-n-options | |
4645 | (apply (function concat) | |
4646 | (mapcar (function (lambda (g) (concat g " "))) | |
4647 | command-line-args-left)))) | |
4648 | (yes (car yes-and-no)) | |
4649 | (no (cdr yes-and-no)) | |
4650 | ;; Disable verbose message. | |
4651 | (gnus-novice-user nil) | |
4652 | (gnus-large-newsgroup nil) | |
4653 | (nntp-large-newsgroup nil)) | |
4654 | ;; Eat all arguments. | |
4655 | (setq command-line-args-left nil) | |
4656 | ;; Startup GNUS. | |
4657 | (gnus) | |
4658 | ;; Apply kills to specified newsgroups in command line arguments. | |
4659 | (setq newsrc (copy-sequence gnus-newsrc-assoc)) | |
4660 | (while newsrc | |
4661 | (setq group (car (car newsrc))) | |
4662 | (setq subscribed (nth 1 (car newsrc))) | |
4663 | (setq newsrc (cdr newsrc)) | |
4664 | (if (and subscribed | |
4665 | (not (zerop (nth 1 (gnus-gethash group gnus-unread-hashtb)))) | |
4666 | (if yes | |
4667 | (string-match yes group) t) | |
4668 | (or (null no) | |
4669 | (not (string-match no group)))) | |
4670 | (progn | |
b027f415 RS |
4671 | (gnus-summary-read-group group nil t) |
4672 | (if (eq (current-buffer) (get-buffer gnus-summary-buffer)) | |
4673 | (gnus-summary-exit t)) | |
745bc783 JB |
4674 | )) |
4675 | ) | |
4676 | ;; Finally, exit Emacs. | |
b027f415 RS |
4677 | (set-buffer gnus-group-buffer) |
4678 | (gnus-group-exit) | |
745bc783 JB |
4679 | )) |
4680 | ||
b027f415 RS |
4681 | ;; For saving articles |
4682 | ||
745bc783 JB |
4683 | (defun gnus-Numeric-save-name (newsgroup headers &optional last-file) |
4684 | "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
4685 | If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num. | |
4686 | Otherwise, it is like ~/News/news/group/num." | |
4687 | (let ((default | |
4688 | (expand-file-name | |
4689 | (concat (if gnus-use-long-file-name | |
b027f415 | 4690 | (gnus-capitalize-newsgroup newsgroup) |
745bc783 JB |
4691 | (gnus-newsgroup-directory-form newsgroup)) |
4692 | "/" (int-to-string (nntp-header-number headers))) | |
4693 | (or gnus-article-save-directory "~/News")))) | |
4694 | (if (and last-file | |
4695 | (string-equal (file-name-directory default) | |
4696 | (file-name-directory last-file)) | |
4697 | (string-match "^[0-9]+$" (file-name-nondirectory last-file))) | |
4698 | default | |
4699 | (or last-file default)))) | |
4700 | ||
4701 | (defun gnus-numeric-save-name (newsgroup headers &optional last-file) | |
4702 | "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
4703 | If variable `gnus-use-long-file-name' is nil, it is ~/News/news.group/num. | |
4704 | Otherwise, it is like ~/News/news/group/num." | |
4705 | (let ((default | |
4706 | (expand-file-name | |
4707 | (concat (if gnus-use-long-file-name | |
4708 | newsgroup | |
4709 | (gnus-newsgroup-directory-form newsgroup)) | |
4710 | "/" (int-to-string (nntp-header-number headers))) | |
4711 | (or gnus-article-save-directory "~/News")))) | |
4712 | (if (and last-file | |
4713 | (string-equal (file-name-directory default) | |
4714 | (file-name-directory last-file)) | |
4715 | (string-match "^[0-9]+$" (file-name-nondirectory last-file))) | |
4716 | default | |
4717 | (or last-file default)))) | |
4718 | ||
4719 | (defun gnus-Plain-save-name (newsgroup headers &optional last-file) | |
4720 | "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
4721 | If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group. | |
4722 | Otherwise, it is like ~/News/news/group/news." | |
4723 | (or last-file | |
4724 | (expand-file-name | |
4725 | (if gnus-use-long-file-name | |
b027f415 | 4726 | (gnus-capitalize-newsgroup newsgroup) |
745bc783 JB |
4727 | (concat (gnus-newsgroup-directory-form newsgroup) "/news")) |
4728 | (or gnus-article-save-directory "~/News")))) | |
4729 | ||
4730 | (defun gnus-plain-save-name (newsgroup headers &optional last-file) | |
4731 | "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
4732 | If variable `gnus-use-long-file-name' is nil, it is ~/News/news.group. | |
4733 | Otherwise, it is like ~/News/news/group/news." | |
4734 | (or last-file | |
4735 | (expand-file-name | |
4736 | (if gnus-use-long-file-name | |
4737 | newsgroup | |
4738 | (concat (gnus-newsgroup-directory-form newsgroup) "/news")) | |
4739 | (or gnus-article-save-directory "~/News")))) | |
4740 | ||
4741 | (defun gnus-Folder-save-name (newsgroup headers &optional last-folder) | |
4742 | "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER. | |
4743 | If variable `gnus-use-long-file-name' is nil, it is +News.group. | |
4744 | Otherwise, it is like +news/group." | |
4745 | (or last-folder | |
4746 | (concat "+" | |
4747 | (if gnus-use-long-file-name | |
b027f415 | 4748 | (gnus-capitalize-newsgroup newsgroup) |
745bc783 JB |
4749 | (gnus-newsgroup-directory-form newsgroup))))) |
4750 | ||
4751 | (defun gnus-folder-save-name (newsgroup headers &optional last-folder) | |
4752 | "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER. | |
4753 | If variable `gnus-use-long-file-name' is nil, it is +news.group. | |
4754 | Otherwise, it is like +news/group." | |
4755 | (or last-folder | |
4756 | (concat "+" | |
4757 | (if gnus-use-long-file-name | |
4758 | newsgroup | |
4759 | (gnus-newsgroup-directory-form newsgroup))))) | |
4760 | ||
b027f415 RS |
4761 | ;; For KILL files |
4762 | ||
745bc783 JB |
4763 | (defun gnus-apply-kill-file () |
4764 | "Apply KILL file to the current newsgroup." | |
4765 | ;; Apply the global KILL file. | |
4766 | (load (gnus-newsgroup-kill-file nil) t nil t) | |
4767 | ;; And then apply the local KILL file. | |
4768 | (load (gnus-newsgroup-kill-file gnus-newsgroup-name) t nil t)) | |
4769 | ||
4770 | (defun gnus-Newsgroup-kill-file (newsgroup) | |
4771 | "Return the name of a KILL file of NEWSGROUP. | |
4772 | If NEWSGROUP is nil, return the global KILL file instead." | |
4773 | (cond ((or (null newsgroup) | |
4774 | (string-equal newsgroup "")) | |
4775 | ;; The global KILL file is placed at top of the directory. | |
4776 | (expand-file-name gnus-kill-file-name | |
4777 | (or gnus-article-save-directory "~/News"))) | |
4778 | (gnus-use-long-file-name | |
4779 | ;; Append ".KILL" to capitalized newsgroup name. | |
b027f415 | 4780 | (expand-file-name (concat (gnus-capitalize-newsgroup newsgroup) |
745bc783 JB |
4781 | "." gnus-kill-file-name) |
4782 | (or gnus-article-save-directory "~/News"))) | |
4783 | (t | |
4784 | ;; Place "KILL" under the hierarchical directory. | |
4785 | (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) | |
4786 | "/" gnus-kill-file-name) | |
4787 | (or gnus-article-save-directory "~/News"))) | |
4788 | )) | |
4789 | ||
4790 | (defun gnus-newsgroup-kill-file (newsgroup) | |
4791 | "Return the name of a KILL file of NEWSGROUP. | |
4792 | If NEWSGROUP is nil, return the global KILL file instead." | |
4793 | (cond ((or (null newsgroup) | |
4794 | (string-equal newsgroup "")) | |
4795 | ;; The global KILL file is placed at top of the directory. | |
4796 | (expand-file-name gnus-kill-file-name | |
4797 | (or gnus-article-save-directory "~/News"))) | |
4798 | (gnus-use-long-file-name | |
4799 | ;; Append ".KILL" to newsgroup name. | |
4800 | (expand-file-name (concat newsgroup "." gnus-kill-file-name) | |
4801 | (or gnus-article-save-directory "~/News"))) | |
4802 | (t | |
4803 | ;; Place "KILL" under the hierarchical directory. | |
4804 | (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) | |
4805 | "/" gnus-kill-file-name) | |
4806 | (or gnus-article-save-directory "~/News"))) | |
4807 | )) | |
4808 | ||
b027f415 RS |
4809 | ;; For subscribing new newsgroup |
4810 | ||
4811 | (defun gnus-subscribe-randomly (newsgroup) | |
4812 | "Subscribe new NEWSGROUP and insert it at the beginning of newsgroups." | |
4813 | (gnus-subscribe-newsgroup newsgroup | |
4814 | (car (car gnus-newsrc-assoc)))) | |
4815 | ||
4816 | (defun gnus-subscribe-alphabetically (newgroup) | |
4817 | "Subscribe new NEWSGROUP and insert it in strict alphabetic order." | |
4818 | ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams) | |
4819 | (let ((groups gnus-newsrc-assoc) | |
4820 | (before nil)) | |
4821 | (while (and (not before) groups) | |
4822 | (if (string< newgroup (car (car groups))) | |
4823 | (setq before (car (car groups))) | |
4824 | (setq groups (cdr groups)))) | |
4825 | (gnus-subscribe-newsgroup newgroup before) | |
4826 | )) | |
4827 | ||
4828 | (defun gnus-subscribe-hierarchically (newgroup) | |
4829 | "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order." | |
4830 | ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams) | |
4831 | (save-excursion | |
4832 | (set-buffer (find-file-noselect gnus-current-startup-file)) | |
4833 | (let ((groupkey newgroup) | |
4834 | (before nil)) | |
4835 | (while (and (not before) groupkey) | |
4836 | (goto-char (point-min)) | |
4837 | (let ((groupkey-re | |
4838 | (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]"))) | |
4839 | (while (and (re-search-forward groupkey-re nil t) | |
4840 | (progn | |
4841 | (setq before (buffer-substring | |
4842 | (match-beginning 1) (match-end 1))) | |
4843 | (string< before newgroup))) | |
4844 | )) | |
4845 | ;; Remove tail of newsgroup name (eg. a.b.c -> a.b) | |
4846 | (setq groupkey | |
4847 | (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey) | |
4848 | (substring groupkey (match-beginning 1) (match-end 1))))) | |
4849 | (gnus-subscribe-newsgroup newgroup before) | |
4850 | ))) | |
4851 | ||
4852 | (defun gnus-subscribe-interactively (newsgroup) | |
4853 | "Subscribe new NEWSGROUP interactively. | |
4854 | It is inserted in hierarchical newsgroup order if subscribed. | |
4855 | Unless, it is killed." | |
4856 | (if (y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup)) | |
4857 | (gnus-subscribe-hierarchically newsgroup) | |
4858 | ;; Save in kill-ring | |
4859 | (gnus-subscribe-newsgroup newsgroup) | |
4860 | (gnus-kill-newsgroup newsgroup))) | |
4861 | ||
4862 | (defun gnus-subscribe-newsgroup (newsgroup &optional next) | |
4863 | "Subscribe new NEWSGROUP. | |
4864 | If optional argument NEXT is non-nil, it is inserted before NEXT." | |
4865 | (gnus-insert-newsgroup (list newsgroup t) next) | |
4866 | (message "Subscribe newsgroup: %s" newsgroup)) | |
4867 | ||
4868 | ;; For directories | |
4869 | ||
745bc783 JB |
4870 | (defun gnus-newsgroup-directory-form (newsgroup) |
4871 | "Make hierarchical directory name from NEWSGROUP name." | |
4872 | (let ((newsgroup (substring newsgroup 0)) ;Copy string. | |
4873 | (len (length newsgroup)) | |
4874 | (idx 0)) | |
eb8c3be9 | 4875 | ;; Replace all occurrences of `.' with `/'. |
745bc783 JB |
4876 | (while (< idx len) |
4877 | (if (= (aref newsgroup idx) ?.) | |
4878 | (aset newsgroup idx ?/)) | |
4879 | (setq idx (1+ idx))) | |
4880 | newsgroup | |
4881 | )) | |
4882 | ||
4883 | (defun gnus-make-directory (directory) | |
4884 | "Make DIRECTORY recursively." | |
4885 | (let ((directory (expand-file-name directory default-directory))) | |
4886 | (or (file-exists-p directory) | |
4887 | (gnus-make-directory-1 "" directory)) | |
4888 | )) | |
4889 | ||
4890 | (defun gnus-make-directory-1 (head tail) | |
4891 | (cond ((string-match "^/\\([^/]+\\)" tail) | |
b027f415 RS |
4892 | ;; ange-ftp interferes with calling match-* after |
4893 | ;; calling file-name-as-directory. | |
4894 | (let ((beg (match-beginning 1)) | |
4895 | (end (match-end 1))) | |
4896 | (setq head (concat (file-name-as-directory head) | |
4897 | (substring tail beg end))) | |
4898 | (or (file-exists-p head) | |
4899 | (call-process "mkdir" nil nil nil head)) | |
4900 | (gnus-make-directory-1 head (substring tail end)))) | |
745bc783 JB |
4901 | ((string-equal tail "") t) |
4902 | )) | |
4903 | ||
b027f415 RS |
4904 | (defun gnus-capitalize-newsgroup (newsgroup) |
4905 | "Capitalize NEWSGROUP name with treating '.' and '-' as part of words." | |
4906 | ;; Suggested by "Jonathan I. Kamens" <jik@pit-manager.MIT.EDU>. | |
4907 | (let ((current-syntax-table (copy-syntax-table (syntax-table)))) | |
4908 | (unwind-protect | |
4909 | (progn | |
4910 | (modify-syntax-entry ?- "w") | |
4911 | (modify-syntax-entry ?. "w") | |
4912 | (capitalize newsgroup)) | |
4913 | (set-syntax-table current-syntax-table)))) | |
4914 | ||
745bc783 JB |
4915 | (defun gnus-simplify-subject (subject &optional re-only) |
4916 | "Remove `Re:' and words in parentheses. | |
4917 | If optional argument RE-ONLY is non-nil, strip `Re:' only." | |
4918 | (let ((case-fold-search t)) ;Ignore case. | |
4919 | ;; Remove `Re:' and `Re^N:'. | |
4920 | (if (string-match "\\`\\(re\\(\\^[0-9]+\\)?:[ \t]+\\)+" subject) | |
4921 | (setq subject (substring subject (match-end 0)))) | |
4922 | ;; Remove words in parentheses from end. | |
4923 | (or re-only | |
4924 | (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject) | |
4925 | (setq subject (substring subject 0 (match-beginning 0))))) | |
4926 | ;; Return subject string. | |
4927 | subject | |
4928 | )) | |
4929 | ||
4930 | (defun gnus-optional-lines-and-from (header) | |
4931 | "Return a string like `NNN:AUTHOR' from HEADER." | |
4932 | (let ((name-length (length "umerin@photon"))) | |
4933 | (substring (format "%3d:%s" | |
4934 | ;; Lines of the article. | |
4935 | ;; Suggested by dana@bellcore.com. | |
4936 | (nntp-header-lines header) | |
4937 | ;; Its author. | |
4938 | (concat (mail-strip-quoted-names | |
4939 | (nntp-header-from header)) | |
4940 | (make-string name-length ? ))) | |
4941 | ;; 4 stands for length of `NNN:'. | |
4942 | 0 (+ 4 name-length)))) | |
4943 | ||
4944 | (defun gnus-optional-lines (header) | |
4945 | "Return a string like `NNN' from HEADER." | |
4946 | (format "%4d" (nntp-header-lines header))) | |
4947 | ||
b027f415 RS |
4948 | ;; Basic ideas by flee@cs.psu.edu (Felix Lee) |
4949 | ||
4950 | (defun gnus-keysort-headers (predicate key &optional reverse) | |
4951 | "Sort current headers by PREDICATE using a value passed by KEY safely. | |
4952 | *Safely* means C-g quitting is disabled during sort. | |
4953 | Optional argument REVERSE means reverse order." | |
4954 | (let ((inhibit-quit t)) | |
4955 | (setq gnus-newsgroup-headers | |
4956 | (if reverse | |
4957 | (nreverse | |
4958 | (gnus-keysort (nreverse gnus-newsgroup-headers) predicate key)) | |
4959 | (gnus-keysort gnus-newsgroup-headers predicate key))) | |
4960 | ;; Make sure we don't have to call | |
4961 | ;; gnus-clear-hashtables-for-newsgroup-headers to clear hash | |
4962 | ;; tables for the variable gnus-newsgroup-headers since no new | |
4963 | ;; entry is added to nor deleted from the variable. | |
4964 | )) | |
4965 | ||
4966 | (defun gnus-keysort (list predicate key) | |
4967 | "Sort LIST by PREDICATE using a value passed by KEY." | |
4968 | (mapcar (function cdr) | |
4969 | (sort (mapcar (function (lambda (a) (cons (funcall key a) a))) list) | |
4970 | (function (lambda (a b) | |
4971 | (funcall predicate (car a) (car b))))))) | |
4972 | ||
745bc783 | 4973 | (defun gnus-sort-headers (predicate &optional reverse) |
b027f415 RS |
4974 | "Sort current headers by PREDICATE safely. |
4975 | *Safely* means C-g quitting is disabled during sort. | |
745bc783 JB |
4976 | Optional argument REVERSE means reverse order." |
4977 | (let ((inhibit-quit t)) | |
4978 | (setq gnus-newsgroup-headers | |
4979 | (if reverse | |
4980 | (nreverse (sort (nreverse gnus-newsgroup-headers) predicate)) | |
4981 | (sort gnus-newsgroup-headers predicate))) | |
b027f415 RS |
4982 | ;; Make sure we don't have to call |
4983 | ;; gnus-clear-hashtables-for-newsgroup-headers to clear hash | |
4984 | ;; tables for the variable gnus-newsgroup-headers since no new | |
4985 | ;; entry is added to nor deleted from the variable. | |
745bc783 JB |
4986 | )) |
4987 | ||
4988 | (defun gnus-string-lessp (a b) | |
4989 | "Return T if first arg string is less than second in lexicographic order. | |
4990 | If case-fold-search is non-nil, case of letters is ignored." | |
4991 | (if case-fold-search | |
b027f415 RS |
4992 | (string-lessp (downcase a) (downcase b)) |
4993 | (string-lessp a b))) | |
745bc783 JB |
4994 | |
4995 | (defun gnus-date-lessp (date1 date2) | |
4996 | "Return T if DATE1 is earlyer than DATE2." | |
b027f415 RS |
4997 | (string-lessp (gnus-sortable-date date1) |
4998 | (gnus-sortable-date date2))) | |
4999 | ||
5000 | (defun gnus-sortable-date (date) | |
5001 | "Make sortable string by string-lessp from DATE. | |
5002 | Timezone package is used." | |
5003 | (let* ((date (timezone-parse-date date)) ;[Y M D T] | |
5004 | (year (string-to-int (aref date 0))) | |
5005 | (month (string-to-int (aref date 1))) | |
5006 | (day (string-to-int (aref date 2))) | |
5007 | (time (aref date 3))) ;HH:MM:SS | |
5008 | ;; Timezone package is used. But, we don't have to care about | |
5009 | ;; the timezone since article's timezones are always GMT. | |
5010 | (timezone-make-sortable-date year month day time) | |
745bc783 JB |
5011 | )) |
5012 | ||
b027f415 RS |
5013 | ;;(defun gnus-sortable-date (date) |
5014 | ;; "Make sortable string by string-lessp from DATE." | |
5015 | ;; (let ((month '(("JAN" . " 1")("FEB" . " 2")("MAR" . " 3") | |
5016 | ;; ("APR" . " 4")("MAY" . " 5")("JUN" . " 6") | |
5017 | ;; ("JUL" . " 7")("AUG" . " 8")("SEP" . " 9") | |
5018 | ;; ("OCT" . "10")("NOV" . "11")("DEC" . "12"))) | |
5019 | ;; (date (or date ""))) | |
5020 | ;; ;; Can understand the following styles: | |
5021 | ;; ;; (1) 14 Apr 89 03:20:12 GMT | |
5022 | ;; ;; (2) Fri, 17 Mar 89 4:01:33 GMT | |
5023 | ;; (if (string-match | |
5024 | ;; "\\([0-9]+\\) \\([^ ,]+\\) \\([0-9]+\\) \\([0-9:]+\\)" date) | |
5025 | ;; (concat | |
5026 | ;; ;; Year | |
5027 | ;; (substring date (match-beginning 3) (match-end 3)) | |
5028 | ;; ;; Month | |
5029 | ;; (cdr | |
5030 | ;; (assoc | |
5031 | ;; (upcase (substring date (match-beginning 2) (match-end 2))) month)) | |
5032 | ;; ;; Day | |
5033 | ;; (format "%2d" (string-to-int | |
5034 | ;; (substring date | |
5035 | ;; (match-beginning 1) (match-end 1)))) | |
5036 | ;; ;; Time | |
5037 | ;; (substring date (match-beginning 4) (match-end 4))) | |
5038 | ;; ;; Cannot understand DATE string. | |
5039 | ;; date | |
5040 | ;; ) | |
5041 | ;; )) | |
5042 | ||
745bc783 JB |
5043 | (defun gnus-fetch-field (field) |
5044 | "Return the value of the header FIELD of current article." | |
5045 | (save-excursion | |
5046 | (save-restriction | |
5047 | (widen) | |
5048 | (goto-char (point-min)) | |
5049 | (narrow-to-region (point-min) | |
5050 | (progn (search-forward "\n\n" nil 'move) (point))) | |
5051 | (mail-fetch-field field)))) | |
5052 | ||
b027f415 | 5053 | (fset 'gnus-expunge 'gnus-summary-delete-marked-with) |
745bc783 JB |
5054 | |
5055 | (defun gnus-kill (field regexp &optional command all) | |
5056 | "If FIELD of an article matches REGEXP, execute COMMAND. | |
b027f415 RS |
5057 | Optional 1st argument COMMAND is default to |
5058 | (gnus-summary-mark-as-read nil \"X\"). | |
5059 | If optional 2nd argument ALL is non-nil, articles marked are also applied to. | |
5060 | If FIELD is an empty string (or nil), entire article body is searched for. | |
745bc783 JB |
5061 | COMMAND must be a lisp expression or a string representing a key sequence." |
5062 | ;; We don't want to change current point nor window configuration. | |
5063 | (save-excursion | |
5064 | (save-window-excursion | |
b027f415 RS |
5065 | ;; Selected window must be Summary buffer to execute keyboard |
5066 | ;; macros correctly. See command_loop_1. | |
5067 | (switch-to-buffer gnus-summary-buffer 'norecord) | |
745bc783 JB |
5068 | (goto-char (point-min)) ;From the beginning. |
5069 | (if (null command) | |
b027f415 | 5070 | (setq command '(gnus-summary-mark-as-read nil "X"))) |
745bc783 JB |
5071 | (gnus-execute field regexp command nil (not all)) |
5072 | ))) | |
5073 | ||
5074 | (defun gnus-execute (field regexp form &optional backward ignore-marked) | |
5075 | "If FIELD of article header matches REGEXP, execute lisp FORM (or a string). | |
5076 | If FIELD is an empty string (or nil), entire article body is searched for. | |
b027f415 RS |
5077 | If optional 1st argument BACKWARD is non-nil, do backward instead. |
5078 | If optional 2nd argument IGNORE-MARKED is non-nil, articles which are | |
745bc783 JB |
5079 | marked as read or unread are ignored." |
5080 | (let ((function nil) | |
5081 | (header nil) | |
5082 | (article nil)) | |
5083 | (if (string-equal field "") | |
5084 | (setq field nil)) | |
5085 | (if (null field) | |
5086 | nil | |
5087 | (or (stringp field) | |
5088 | (setq field (symbol-name field))) | |
5089 | ;; Get access function of header filed. | |
5090 | (setq function (intern-soft (concat "gnus-header-" (downcase field)))) | |
5091 | (if (and function (fboundp function)) | |
5092 | (setq function (symbol-function function)) | |
5093 | (error "Unknown header field: \"%s\"" field))) | |
5094 | ;; Make FORM funcallable. | |
5095 | (if (and (listp form) (not (eq (car form) 'lambda))) | |
5096 | (setq form (list 'lambda nil form))) | |
5097 | ;; Starting from the current article. | |
5098 | (or (and ignore-marked | |
5099 | ;; Articles marked as read and unread should be ignored. | |
b027f415 | 5100 | (setq article (gnus-summary-article-number)) |
745bc783 JB |
5101 | (or (not (memq article gnus-newsgroup-unreads)) ;Marked as read. |
5102 | (memq article gnus-newsgroup-marked) ;Marked as unread. | |
5103 | )) | |
5104 | (gnus-execute-1 function regexp form)) | |
b027f415 | 5105 | (while (gnus-summary-search-subject backward ignore-marked nil) |
745bc783 JB |
5106 | (gnus-execute-1 function regexp form)) |
5107 | )) | |
5108 | ||
5109 | (defun gnus-execute-1 (function regexp form) | |
5110 | (save-excursion | |
b027f415 RS |
5111 | ;; The point of Summary buffer must be saved during execution. |
5112 | (let ((article (gnus-summary-article-number))) | |
745bc783 JB |
5113 | (if (null article) |
5114 | nil ;Nothing to do. | |
5115 | (if function | |
5116 | ;; Compare with header field. | |
b027f415 RS |
5117 | (let (;;(header (gnus-find-header-by-number |
5118 | ;; gnus-newsgroup-headers article)) | |
5119 | (header (gnus-get-header-by-number article)) | |
745bc783 JB |
5120 | (value nil)) |
5121 | (and header | |
5122 | (progn | |
5123 | (setq value (funcall function header)) | |
5124 | ;; Number (Lines:) or symbol must be converted to string. | |
5125 | (or (stringp value) | |
5126 | (setq value (prin1-to-string value))) | |
5127 | (string-match regexp value)) | |
5128 | (if (stringp form) ;Keyboard macro. | |
5129 | (execute-kbd-macro form) | |
5130 | (funcall form)))) | |
5131 | ;; Search article body. | |
5132 | (let ((gnus-current-article nil) ;Save article pointer. | |
5133 | (gnus-last-article nil) | |
5134 | (gnus-break-pages nil) ;No need to break pages. | |
b027f415 | 5135 | (gnus-mark-article-hook nil)) ;Inhibit marking as read. |
745bc783 | 5136 | (message "Searching for article: %d..." article) |
b027f415 RS |
5137 | (gnus-article-setup-buffer) |
5138 | (gnus-article-prepare article t) | |
745bc783 | 5139 | (if (save-excursion |
b027f415 | 5140 | (set-buffer gnus-article-buffer) |
745bc783 JB |
5141 | (goto-char (point-min)) |
5142 | (re-search-forward regexp nil t)) | |
5143 | (if (stringp form) ;Keyboard macro. | |
5144 | (execute-kbd-macro form) | |
5145 | (funcall form)))) | |
5146 | )) | |
5147 | ))) | |
5148 | ||
5149 | ;;; caesar-region written by phr@prep.ai.mit.edu Nov 86 | |
5150 | ;;; modified by tower@prep Nov 86 | |
5151 | ;;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47. | |
5152 | ||
5153 | (defun gnus-caesar-region (&optional n) | |
5154 | "Caesar rotation of region by N, default 13, for decrypting netnews. | |
5155 | ROT47 will be performed for Japanese text in any case." | |
5156 | (interactive (if current-prefix-arg ; Was there a prefix arg? | |
5157 | (list (prefix-numeric-value current-prefix-arg)) | |
5158 | (list nil))) | |
5159 | (cond ((not (numberp n)) (setq n 13)) | |
7fa8a898 | 5160 | (t (setq n (mod n 26)))) ;canonicalize N |
745bc783 JB |
5161 | (if (not (zerop n)) ; no action needed for a rot of 0 |
5162 | (progn | |
5163 | (if (or (not (boundp 'caesar-translate-table)) | |
5164 | (/= (aref caesar-translate-table ?a) (+ ?a n))) | |
5165 | (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper) | |
5166 | (message "Building caesar-translate-table...") | |
5167 | (setq caesar-translate-table (make-vector 256 0)) | |
5168 | (while (< i 256) | |
5169 | (aset caesar-translate-table i i) | |
5170 | (setq i (1+ i))) | |
5171 | (setq lower (concat lower lower) upper (upcase lower) i 0) | |
5172 | (while (< i 26) | |
5173 | (aset caesar-translate-table (+ ?a i) (aref lower (+ i n))) | |
5174 | (aset caesar-translate-table (+ ?A i) (aref upper (+ i n))) | |
5175 | (setq i (1+ i))) | |
5176 | ;; ROT47 for Japanese text. | |
5177 | ;; Thanks to ichikawa@flab.fujitsu.junet. | |
5178 | (setq i 161) | |
5179 | (let ((t1 (logior ?O 128)) | |
5180 | (t2 (logior ?! 128)) | |
5181 | (t3 (logior ?~ 128))) | |
5182 | (while (< i 256) | |
5183 | (aset caesar-translate-table i | |
5184 | (let ((v (aref caesar-translate-table i))) | |
5185 | (if (<= v t1) (if (< v t2) v (+ v 47)) | |
5186 | (if (<= v t3) (- v 47) v)))) | |
5187 | (setq i (1+ i)))) | |
5188 | (message "Building caesar-translate-table... done"))) | |
5189 | (let ((from (region-beginning)) | |
5190 | (to (region-end)) | |
5191 | (i 0) str len) | |
5192 | (setq str (buffer-substring from to)) | |
5193 | (setq len (length str)) | |
5194 | (while (< i len) | |
5195 | (aset str i (aref caesar-translate-table (aref str i))) | |
5196 | (setq i (1+ i))) | |
5197 | (goto-char from) | |
5198 | (delete-region from to) | |
5199 | (insert str))))) | |
5200 | ||
5201 | ;; Functions accessing headers. | |
5202 | ;; Functions are more convenient than macros in some case. | |
5203 | ||
5204 | (defun gnus-header-number (header) | |
5205 | "Return article number in HEADER." | |
5206 | (nntp-header-number header)) | |
5207 | ||
5208 | (defun gnus-header-subject (header) | |
5209 | "Return subject string in HEADER." | |
5210 | (nntp-header-subject header)) | |
5211 | ||
5212 | (defun gnus-header-from (header) | |
5213 | "Return author string in HEADER." | |
5214 | (nntp-header-from header)) | |
5215 | ||
5216 | (defun gnus-header-xref (header) | |
5217 | "Return xref string in HEADER." | |
5218 | (nntp-header-xref header)) | |
5219 | ||
5220 | (defun gnus-header-lines (header) | |
5221 | "Return lines in HEADER." | |
5222 | (nntp-header-lines header)) | |
5223 | ||
5224 | (defun gnus-header-date (header) | |
5225 | "Return date in HEADER." | |
5226 | (nntp-header-date header)) | |
5227 | ||
5228 | (defun gnus-header-id (header) | |
5229 | "Return Id in HEADER." | |
5230 | (nntp-header-id header)) | |
5231 | ||
5232 | (defun gnus-header-references (header) | |
5233 | "Return references in HEADER." | |
5234 | (nntp-header-references header)) | |
5235 | ||
5236 | \f | |
5237 | ;;; | |
5238 | ;;; Article savers. | |
5239 | ;;; | |
5240 | ||
5241 | (defun gnus-output-to-rmail (file-name) | |
5242 | "Append the current article to an Rmail file named FILE-NAME." | |
5243 | (require 'rmail) | |
5244 | ;; Most of these codes are borrowed from rmailout.el. | |
5245 | (setq file-name (expand-file-name file-name)) | |
5246 | (setq rmail-last-rmail-file file-name) | |
5247 | (let ((artbuf (current-buffer)) | |
5248 | (tmpbuf (get-buffer-create " *GNUS-output*"))) | |
5249 | (save-excursion | |
5250 | (or (get-file-buffer file-name) | |
5251 | (file-exists-p file-name) | |
5252 | (if (yes-or-no-p | |
5253 | (concat "\"" file-name "\" does not exist, create it? ")) | |
5254 | (let ((file-buffer (create-file-buffer file-name))) | |
5255 | (save-excursion | |
5256 | (set-buffer file-buffer) | |
5257 | (rmail-insert-rmail-file-header) | |
5258 | (let ((require-final-newline nil)) | |
5259 | (write-region (point-min) (point-max) file-name t 1))) | |
5260 | (kill-buffer file-buffer)) | |
5261 | (error "Output file does not exist"))) | |
5262 | (set-buffer tmpbuf) | |
b027f415 | 5263 | (buffer-flush-undo (current-buffer)) |
745bc783 JB |
5264 | (erase-buffer) |
5265 | (insert-buffer-substring artbuf) | |
5266 | (gnus-convert-article-to-rmail) | |
5267 | ;; Decide whether to append to a file or to an Emacs buffer. | |
5268 | (let ((outbuf (get-file-buffer file-name))) | |
5269 | (if (not outbuf) | |
5270 | (append-to-file (point-min) (point-max) file-name) | |
5271 | ;; File has been visited, in buffer OUTBUF. | |
5272 | (set-buffer outbuf) | |
5273 | (let ((buffer-read-only nil) | |
5274 | (msg (and (boundp 'rmail-current-message) | |
5275 | rmail-current-message))) | |
5276 | ;; If MSG is non-nil, buffer is in RMAIL mode. | |
5277 | (if msg | |
5278 | (progn (widen) | |
5279 | (narrow-to-region (point-max) (point-max)))) | |
5280 | (insert-buffer-substring tmpbuf) | |
5281 | (if msg | |
5282 | (progn | |
5283 | (goto-char (point-min)) | |
5284 | (widen) | |
5285 | (search-backward "\^_") | |
5286 | (narrow-to-region (point) (point-max)) | |
5287 | (goto-char (1+ (point-min))) | |
5288 | (rmail-count-new-messages t) | |
5289 | (rmail-show-message msg)))))) | |
5290 | ) | |
5291 | (kill-buffer tmpbuf) | |
5292 | )) | |
5293 | ||
5294 | (defun gnus-output-to-file (file-name) | |
5295 | "Append the current article to a file named FILE-NAME." | |
5296 | (setq file-name (expand-file-name file-name)) | |
5297 | (let ((artbuf (current-buffer)) | |
5298 | (tmpbuf (get-buffer-create " *GNUS-output*"))) | |
5299 | (save-excursion | |
5300 | (set-buffer tmpbuf) | |
b027f415 | 5301 | (buffer-flush-undo (current-buffer)) |
745bc783 JB |
5302 | (erase-buffer) |
5303 | (insert-buffer-substring artbuf) | |
5304 | ;; Append newline at end of the buffer as separator, and then | |
5305 | ;; save it to file. | |
5306 | (goto-char (point-max)) | |
5307 | (insert "\n") | |
5308 | (append-to-file (point-min) (point-max) file-name)) | |
5309 | (kill-buffer tmpbuf) | |
5310 | )) | |
5311 | ||
5312 | (defun gnus-convert-article-to-rmail () | |
5313 | "Convert article in current buffer to Rmail message format." | |
5314 | (let ((buffer-read-only nil)) | |
5315 | ;; Convert article directly into Babyl format. | |
5316 | ;; Suggested by Rob Austein <sra@lcs.mit.edu> | |
5317 | (goto-char (point-min)) | |
5318 | (insert "\^L\n0, unseen,,\n*** EOOH ***\n") | |
5319 | (while (search-forward "\n\^_" nil t) ;single char | |
5320 | (replace-match "\n^_")) ;2 chars: "^" and "_" | |
5321 | (goto-char (point-max)) | |
5322 | (insert "\^_"))) | |
5323 | ||
5324 | ;;(defun gnus-convert-article-to-rmail () | |
5325 | ;; "Convert article in current buffer to Rmail message format." | |
5326 | ;; (let ((buffer-read-only nil)) | |
5327 | ;; ;; Insert special header of Unix mail. | |
5328 | ;; (goto-char (point-min)) | |
5329 | ;; (insert "From " | |
5330 | ;; (or (mail-strip-quoted-names (mail-fetch-field "from")) | |
5331 | ;; "unknown") | |
5332 | ;; " " (current-time-string) "\n") | |
5333 | ;; ;; Stop quoting `From' since this seems unnecessary in most cases. | |
5334 | ;; ;; ``Quote'' "\nFrom " as "\n>From " | |
5335 | ;; ;;(while (search-forward "\nFrom " nil t) | |
5336 | ;; ;; (forward-char -5) | |
5337 | ;; ;; (insert ?>)) | |
5338 | ;; ;; Convert article to babyl format. | |
5339 | ;; (rmail-convert-to-babyl-format) | |
5340 | ;; )) | |
5341 | ||
5342 | \f | |
5343 | ;;; | |
5344 | ;;; Internal functions. | |
5345 | ;;; | |
5346 | ||
5347 | (defun gnus-start-news-server (&optional confirm) | |
5348 | "Open network stream to remote NNTP server. | |
5349 | If optional argument CONFIRM is non-nil, ask you host that NNTP server | |
5350 | is running even if it is defined. | |
b027f415 | 5351 | Run gnus-open-server-hook just before opening news server." |
745bc783 JB |
5352 | (if (gnus-server-opened) |
5353 | ;; Stream is already opened. | |
5354 | nil | |
5355 | ;; Open NNTP server. | |
5356 | (if (or confirm | |
5357 | (null gnus-nntp-server)) | |
1c595d45 JB |
5358 | ;; If someone has set the service to nil, then this should always |
5359 | ;; be the local host. | |
5360 | (if gnus-nntp-service | |
5361 | (if (and (boundp 'gnus-secondary-servers) gnus-secondary-servers) | |
5362 | ;; Read server name with completion. | |
5363 | (setq gnus-nntp-server | |
5364 | (completing-read "NNTP server: " | |
5365 | (cons (list gnus-nntp-server) | |
5366 | gnus-secondary-servers) | |
5367 | nil nil gnus-nntp-server)) | |
5368 | (setq gnus-nntp-server | |
5369 | (read-string "NNTP server: " gnus-nntp-server))) | |
5370 | (setq gnus-nntp-server ""))) | |
745bc783 | 5371 | ;; If no server name is given, local host is assumed. |
b027f415 RS |
5372 | (if (or (string-equal gnus-nntp-server "") |
5373 | (string-equal gnus-nntp-server "::")) ;RMS preference. | |
745bc783 | 5374 | (setq gnus-nntp-server (system-name))) |
b027f415 RS |
5375 | ;; gnus-nntp-server must be either (system-name), ':DIRECTORY', or |
5376 | ;; nntp server name. I mean '::' cannot be a value of | |
5377 | ;; gnus-nntp-server. | |
5378 | (cond ((and (null gnus-nntp-service) | |
5379 | (string-equal gnus-nntp-server (system-name))) | |
343fbb30 RS |
5380 | (require 'nnspool) |
5381 | (gnus-define-access-method 'nnspool) | |
5382 | (message "Looking up local news spool...")) | |
5383 | ((string-match ":" gnus-nntp-server) | |
745bc783 JB |
5384 | ;; :DIRECTORY |
5385 | (require 'mhspool) | |
5386 | (gnus-define-access-method 'mhspool) | |
5387 | (message "Looking up private directory...")) | |
745bc783 JB |
5388 | (t |
5389 | (gnus-define-access-method 'nntp) | |
5390 | (message "Connecting to NNTP server on %s..." gnus-nntp-server))) | |
b027f415 RS |
5391 | (run-hooks 'gnus-open-server-hook) |
5392 | (cond ((gnus-server-opened) ;Maybe opened in gnus-open-server-hook. | |
5393 | (message "")) | |
5394 | ((gnus-open-server gnus-nntp-server gnus-nntp-service) | |
5395 | (message "")) | |
5396 | (t | |
5397 | (error | |
5398 | (gnus-nntp-message | |
5399 | (format "Cannot open NNTP server on %s" gnus-nntp-server))))) | |
745bc783 JB |
5400 | )) |
5401 | ||
5402 | ;; Dummy functions used only once. Should return nil. | |
5403 | (defun gnus-server-opened () nil) | |
5404 | (defun gnus-close-server () nil) | |
5405 | ||
b027f415 RS |
5406 | (defun gnus-nntp-message (&optional message) |
5407 | "Return a message returned from NNTP server. | |
5408 | If no message is available and optional MESSAGE is given, return it." | |
5409 | (let ((status (gnus-status-message)) | |
5410 | (message (or message ""))) | |
5411 | (if (and (stringp status) | |
5412 | (> (length status) 0)) | |
5413 | status message))) | |
5414 | ||
745bc783 JB |
5415 | (defun gnus-define-access-method (method &optional access-methods) |
5416 | "Define access functions for the access METHOD. | |
eb8c3be9 | 5417 | Methods definition is taken from optional argument ACCESS-METHODS or |
745bc783 JB |
5418 | the variable gnus-access-methods." |
5419 | (let ((bindings | |
5420 | (cdr (assoc method (or access-methods gnus-access-methods))))) | |
5421 | (if (null bindings) | |
5422 | (error "Unknown access method: %s" method) | |
5423 | ;; Should not use symbol-function here since overload does not work. | |
5424 | (while bindings | |
b027f415 RS |
5425 | ;; Alist syntax is different from that of 3.14.3. |
5426 | (fset (car (car bindings)) (car (cdr (car bindings)))) | |
745bc783 JB |
5427 | (setq bindings (cdr bindings))) |
5428 | ))) | |
5429 | ||
5430 | (defun gnus-select-newsgroup (group &optional show-all) | |
5431 | "Select newsgroup GROUP. | |
5432 | If optional argument SHOW-ALL is non-nil, all of articles in the group | |
5433 | are selected." | |
b027f415 RS |
5434 | ;; Make sure a connection to NNTP server is alive. |
5435 | (gnus-start-news-server) | |
745bc783 JB |
5436 | (if (gnus-request-group group) |
5437 | (let ((articles nil)) | |
5438 | (setq gnus-newsgroup-name group) | |
5439 | (setq gnus-newsgroup-unreads | |
5440 | (gnus-uncompress-sequence | |
5441 | (nthcdr 2 (gnus-gethash group gnus-unread-hashtb)))) | |
5442 | (cond (show-all | |
5443 | ;; Select all active articles. | |
5444 | (setq articles | |
5445 | (gnus-uncompress-sequence | |
5446 | (nthcdr 2 (gnus-gethash group gnus-active-hashtb))))) | |
5447 | (t | |
5448 | ;; Select unread articles only. | |
5449 | (setq articles gnus-newsgroup-unreads))) | |
5450 | ;; Require confirmation if selecting large newsgroup. | |
5451 | (setq gnus-newsgroup-unselected nil) | |
5452 | (if (not (numberp gnus-large-newsgroup)) | |
5453 | nil | |
5454 | (let ((selected nil) | |
5455 | (number (length articles))) | |
5456 | (if (> number gnus-large-newsgroup) | |
5457 | (progn | |
5458 | (condition-case () | |
5459 | (let ((input | |
5460 | (read-string | |
5461 | (format | |
5462 | "How many articles from %s (default %d): " | |
5463 | gnus-newsgroup-name number)))) | |
5464 | (setq selected | |
5465 | (if (string-equal input "") | |
5466 | number (string-to-int input)))) | |
5467 | (quit | |
5468 | (setq selected 0))) | |
5469 | (cond ((and (> selected 0) | |
5470 | (< selected number)) | |
5471 | ;; Select last N articles. | |
5472 | (setq articles (nthcdr (- number selected) articles))) | |
5473 | ((and (< selected 0) | |
5474 | (< (- 0 selected) number)) | |
5475 | ;; Select first N articles. | |
5476 | (setq selected (- 0 selected)) | |
5477 | (setq articles (copy-sequence articles)) | |
5478 | (setcdr (nthcdr (1- selected) articles) nil)) | |
5479 | ((zerop selected) | |
5480 | (setq articles nil)) | |
5481 | ;; Otherwise select all. | |
5482 | ) | |
5483 | ;; Get unselected unread articles. | |
5484 | (setq gnus-newsgroup-unselected | |
5485 | (gnus-set-difference gnus-newsgroup-unreads articles)) | |
5486 | )) | |
5487 | )) | |
5488 | ;; Get headers list. | |
5489 | (setq gnus-newsgroup-headers (gnus-retrieve-headers articles)) | |
5490 | ;; UNREADS may contain expired articles, so we have to remove | |
5491 | ;; them from the list. | |
5492 | (setq gnus-newsgroup-unreads | |
5493 | (gnus-intersection gnus-newsgroup-unreads | |
5494 | (mapcar | |
5495 | (function | |
5496 | (lambda (header) | |
5497 | (nntp-header-number header))) | |
5498 | gnus-newsgroup-headers))) | |
5499 | ;; Marked article must be a subset of unread articles. | |
5500 | (setq gnus-newsgroup-marked | |
5501 | (gnus-intersection (append gnus-newsgroup-unselected | |
5502 | gnus-newsgroup-unreads) | |
b027f415 RS |
5503 | (cdr |
5504 | (gnus-gethash group gnus-marked-hashtb)))) | |
745bc783 JB |
5505 | ;; First and last article in this newsgroup. |
5506 | (setq gnus-newsgroup-begin | |
5507 | (if gnus-newsgroup-headers | |
5508 | (nntp-header-number (car gnus-newsgroup-headers)) | |
5509 | 0 | |
5510 | )) | |
5511 | (setq gnus-newsgroup-end | |
5512 | (if gnus-newsgroup-headers | |
5513 | (nntp-header-number | |
5514 | (gnus-last-element gnus-newsgroup-headers)) | |
5515 | 0 | |
5516 | )) | |
5517 | ;; File name that an article was saved last. | |
5518 | (setq gnus-newsgroup-last-rmail nil) | |
5519 | (setq gnus-newsgroup-last-mail nil) | |
5520 | (setq gnus-newsgroup-last-folder nil) | |
5521 | (setq gnus-newsgroup-last-file nil) | |
5522 | ;; Reset article pointer etc. | |
5523 | (setq gnus-current-article nil) | |
5524 | (setq gnus-current-headers nil) | |
5525 | (setq gnus-current-history nil) | |
5526 | (setq gnus-have-all-headers nil) | |
5527 | (setq gnus-last-article nil) | |
b027f415 RS |
5528 | ;; Clear old hash tables for the variable gnus-newsgroup-headers. |
5529 | (gnus-clear-hashtables-for-newsgroup-headers) | |
745bc783 JB |
5530 | ;; GROUP is successfully selected. |
5531 | t | |
5532 | ) | |
5533 | )) | |
5534 | ||
b027f415 RS |
5535 | ;; Hacking for making header search much faster. |
5536 | ||
5537 | (defun gnus-get-header-by-number (number) | |
5538 | "Return a header specified by a NUMBER. | |
5539 | If the variable gnus-newsgroup-headers is updated, the hashed table | |
5540 | gnus-newsgroup-headers-hashtb-by-number must be set to nil to indicate | |
5541 | rehash is necessary." | |
5542 | (or gnus-newsgroup-headers-hashtb-by-number | |
5543 | (gnus-make-headers-hashtable-by-number)) | |
5544 | (gnus-gethash (int-to-string number) | |
5545 | gnus-newsgroup-headers-hashtb-by-number)) | |
5546 | ||
5547 | (defun gnus-get-header-by-id (id) | |
5548 | "Return a header specified by an ID. | |
5549 | If the variable gnus-newsgroup-headers is updated, the hashed table | |
5550 | gnus-newsgroup-headers-hashtb-by-id must be set to nil to indicate | |
5551 | rehash is necessary." | |
5552 | (or gnus-newsgroup-headers-hashtb-by-id | |
5553 | (gnus-make-headers-hashtable-by-id)) | |
5554 | (and (stringp id) | |
5555 | (gnus-gethash id gnus-newsgroup-headers-hashtb-by-id))) | |
5556 | ||
5557 | (defun gnus-make-headers-hashtable-by-number () | |
5558 | "Make hashtable for the variable gnus-newsgroup-headers by number." | |
5559 | (let ((header nil) | |
5560 | (headers gnus-newsgroup-headers)) | |
5561 | (setq gnus-newsgroup-headers-hashtb-by-number | |
5562 | (gnus-make-hashtable (length headers))) | |
5563 | (while headers | |
5564 | (setq header (car headers)) | |
5565 | (gnus-sethash (int-to-string (nntp-header-number header)) | |
5566 | header gnus-newsgroup-headers-hashtb-by-number) | |
5567 | (setq headers (cdr headers)) | |
5568 | ))) | |
5569 | ||
5570 | (defun gnus-make-headers-hashtable-by-id () | |
5571 | "Make hashtable for the variable gnus-newsgroup-headers by id." | |
5572 | (let ((header nil) | |
5573 | (headers gnus-newsgroup-headers)) | |
5574 | (setq gnus-newsgroup-headers-hashtb-by-id | |
5575 | (gnus-make-hashtable (length headers))) | |
5576 | (while headers | |
5577 | (setq header (car headers)) | |
5578 | (gnus-sethash (nntp-header-id header) | |
5579 | header gnus-newsgroup-headers-hashtb-by-id) | |
5580 | (setq headers (cdr headers)) | |
5581 | ))) | |
5582 | ||
5583 | (defun gnus-clear-hashtables-for-newsgroup-headers () | |
5584 | "Clear hash tables created for the variable gnus-newsgroup-headers." | |
5585 | (setq gnus-newsgroup-headers-hashtb-by-id nil) | |
5586 | (setq gnus-newsgroup-headers-hashtb-by-number nil)) | |
5587 | ||
745bc783 JB |
5588 | (defun gnus-more-header-backward () |
5589 | "Find new header backward." | |
5590 | (let ((first | |
5591 | (car (nth 2 (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))) | |
5592 | (artnum gnus-newsgroup-begin) | |
5593 | (header nil)) | |
5594 | (while (and (not header) | |
5595 | (> artnum first)) | |
5596 | (setq artnum (1- artnum)) | |
5597 | (setq header (car (gnus-retrieve-headers (list artnum))))) | |
5598 | header | |
5599 | )) | |
5600 | ||
5601 | (defun gnus-more-header-forward () | |
5602 | "Find new header forward." | |
5603 | (let ((last | |
5604 | (cdr (nth 2 (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))) | |
5605 | (artnum gnus-newsgroup-end) | |
5606 | (header nil)) | |
5607 | (while (and (not header) | |
5608 | (< artnum last)) | |
5609 | (setq artnum (1+ artnum)) | |
5610 | (setq header (car (gnus-retrieve-headers (list artnum))))) | |
5611 | header | |
5612 | )) | |
5613 | ||
5614 | (defun gnus-extend-newsgroup (header &optional backward) | |
5615 | "Extend newsgroup selection with HEADER. | |
5616 | Optional argument BACKWARD means extend toward backward." | |
5617 | (if header | |
5618 | (let ((artnum (nntp-header-number header))) | |
5619 | (setq gnus-newsgroup-headers | |
5620 | (if backward | |
5621 | (cons header gnus-newsgroup-headers) | |
5622 | (append gnus-newsgroup-headers (list header)))) | |
b027f415 RS |
5623 | ;; Clear current hash tables for the variable gnus-newsgroup-headers. |
5624 | (gnus-clear-hashtables-for-newsgroup-headers) | |
745bc783 JB |
5625 | ;; We have to update unreads and unselected, but don't have to |
5626 | ;; care about gnus-newsgroup-marked. | |
5627 | (if (memq artnum gnus-newsgroup-unselected) | |
5628 | (setq gnus-newsgroup-unreads | |
5629 | (cons artnum gnus-newsgroup-unreads))) | |
5630 | (setq gnus-newsgroup-unselected | |
5631 | (delq artnum gnus-newsgroup-unselected)) | |
5632 | (setq gnus-newsgroup-begin (min gnus-newsgroup-begin artnum)) | |
5633 | (setq gnus-newsgroup-end (max gnus-newsgroup-end artnum)) | |
5634 | ))) | |
5635 | ||
5636 | (defun gnus-mark-article-as-read (article) | |
5637 | "Remember that ARTICLE is marked as read." | |
5638 | ;; Remove from unread and marked list. | |
5639 | (setq gnus-newsgroup-unreads | |
5640 | (delq article gnus-newsgroup-unreads)) | |
5641 | (setq gnus-newsgroup-marked | |
5642 | (delq article gnus-newsgroup-marked))) | |
5643 | ||
5644 | (defun gnus-mark-article-as-unread (article &optional clear-mark) | |
5645 | "Remember that ARTICLE is marked as unread. | |
5646 | Optional argument CLEAR-MARK means ARTICLE should not be remembered | |
5647 | that it was marked as read once." | |
5648 | ;; Add to unread list. | |
5649 | (or (memq article gnus-newsgroup-unreads) | |
5650 | (setq gnus-newsgroup-unreads | |
5651 | (cons article gnus-newsgroup-unreads))) | |
5652 | ;; If CLEAR-MARK is non-nil, the article must be removed from marked | |
5653 | ;; list. Otherwise, it must be added to the list. | |
5654 | (if clear-mark | |
5655 | (setq gnus-newsgroup-marked | |
5656 | (delq article gnus-newsgroup-marked)) | |
5657 | (or (memq article gnus-newsgroup-marked) | |
5658 | (setq gnus-newsgroup-marked | |
5659 | (cons article gnus-newsgroup-marked))))) | |
5660 | ||
5661 | (defun gnus-clear-system () | |
5662 | "Clear all variables and buffer." | |
5663 | ;; Clear GNUS variables. | |
5664 | (let ((variables gnus-variable-list)) | |
5665 | (while variables | |
5666 | (set (car variables) nil) | |
5667 | (setq variables (cdr variables)))) | |
5668 | ;; Clear other internal variables. | |
b027f415 RS |
5669 | (setq gnus-newsrc-hashtb nil) |
5670 | (setq gnus-marked-hashtb nil) | |
5671 | (setq gnus-killed-hashtb nil) | |
745bc783 | 5672 | (setq gnus-active-hashtb nil) |
b027f415 | 5673 | (setq gnus-octive-hashtb nil) |
745bc783 | 5674 | (setq gnus-unread-hashtb nil) |
b027f415 RS |
5675 | (setq gnus-newsgroup-headers nil) |
5676 | (setq gnus-newsgroup-headers-hashtb-by-id nil) | |
5677 | (setq gnus-newsgroup-headers-hashtb-by-number nil) | |
745bc783 JB |
5678 | ;; Kill the startup file. |
5679 | (and gnus-current-startup-file | |
5680 | (get-file-buffer gnus-current-startup-file) | |
5681 | (kill-buffer (get-file-buffer gnus-current-startup-file))) | |
5682 | (setq gnus-current-startup-file nil) | |
5683 | ;; Kill GNUS buffers. | |
5684 | (let ((buffers gnus-buffer-list)) | |
5685 | (while buffers | |
5686 | (if (get-buffer (car buffers)) | |
5687 | (kill-buffer (car buffers))) | |
5688 | (setq buffers (cdr buffers)) | |
5689 | ))) | |
5690 | ||
5691 | (defun gnus-configure-windows (action) | |
5692 | "Configure GNUS windows according to the next ACTION. | |
b027f415 | 5693 | The ACTION is either a symbol, such as `summary', or a |
745bc783 | 5694 | configuration list such as `(1 1 2)'. If ACTION is not a list, |
b027f415 | 5695 | configuration list is got from the variable gnus-window-configuration." |
745bc783 JB |
5696 | (let* ((windows |
5697 | (if (listp action) | |
5698 | action (car (cdr (assq action gnus-window-configuration))))) | |
b027f415 RS |
5699 | (grpwin (get-buffer-window gnus-group-buffer)) |
5700 | (subwin (get-buffer-window gnus-summary-buffer)) | |
5701 | (artwin (get-buffer-window gnus-article-buffer)) | |
745bc783 JB |
5702 | (winsum nil) |
5703 | (height nil) | |
5704 | (grpheight 0) | |
5705 | (subheight 0) | |
5706 | (artheight 0)) | |
5707 | (if (or (null windows) ;No configuration is specified. | |
5708 | (and (eq (null grpwin) | |
5709 | (zerop (nth 0 windows))) | |
5710 | (eq (null subwin) | |
5711 | (zerop (nth 1 windows))) | |
5712 | (eq (null artwin) | |
5713 | (zerop (nth 2 windows))))) | |
5714 | ;; No need to change window configuration. | |
5715 | nil | |
5716 | (select-window (or grpwin subwin artwin (selected-window))) | |
5717 | ;; First of all, compute the height of each window. | |
5718 | (cond (gnus-use-full-window | |
5719 | ;; Take up the entire screen. | |
5720 | (delete-other-windows) | |
5721 | (setq height (window-height (selected-window)))) | |
5722 | (t | |
5723 | (setq height (+ (if grpwin (window-height grpwin) 0) | |
5724 | (if subwin (window-height subwin) 0) | |
5725 | (if artwin (window-height artwin) 0))))) | |
5726 | ;; The Newsgroup buffer exits always. So, use it to extend the | |
5727 | ;; Group window so as to get enough window space. | |
b027f415 RS |
5728 | (switch-to-buffer gnus-group-buffer 'norecord) |
5729 | (and (get-buffer gnus-summary-buffer) | |
5730 | (delete-windows-on gnus-summary-buffer)) | |
5731 | (and (get-buffer gnus-article-buffer) | |
5732 | (delete-windows-on gnus-article-buffer)) | |
745bc783 JB |
5733 | ;; Compute expected window height. |
5734 | (setq winsum (apply (function +) windows)) | |
5735 | (if (not (zerop (nth 0 windows))) | |
5736 | (setq grpheight (max window-min-height | |
5737 | (/ (* height (nth 0 windows)) winsum)))) | |
5738 | (if (not (zerop (nth 1 windows))) | |
5739 | (setq subheight (max window-min-height | |
5740 | (/ (* height (nth 1 windows)) winsum)))) | |
5741 | (if (not (zerop (nth 2 windows))) | |
5742 | (setq artheight (max window-min-height | |
5743 | (/ (* height (nth 2 windows)) winsum)))) | |
5744 | (setq height (+ grpheight subheight artheight)) | |
5745 | (enlarge-window (max 0 (- height (window-height (selected-window))))) | |
5746 | ;; Then split the window. | |
5747 | (and (not (zerop artheight)) | |
5748 | (or (not (zerop grpheight)) | |
5749 | (not (zerop subheight))) | |
5750 | (split-window-vertically (+ grpheight subheight))) | |
5751 | (and (not (zerop grpheight)) | |
5752 | (not (zerop subheight)) | |
5753 | (split-window-vertically grpheight)) | |
5754 | ;; Then select buffers in each window. | |
5755 | (and (not (zerop grpheight)) | |
5756 | (progn | |
b027f415 | 5757 | (switch-to-buffer gnus-group-buffer 'norecord) |
745bc783 JB |
5758 | (other-window 1))) |
5759 | (and (not (zerop subheight)) | |
5760 | (progn | |
b027f415 | 5761 | (switch-to-buffer gnus-summary-buffer 'norecord) |
745bc783 JB |
5762 | (other-window 1))) |
5763 | (and (not (zerop artheight)) | |
5764 | (progn | |
5765 | ;; If Article buffer does not exist, it will be created | |
5766 | ;; and initialized. | |
b027f415 RS |
5767 | (gnus-article-setup-buffer) |
5768 | (switch-to-buffer gnus-article-buffer 'norecord))) | |
745bc783 JB |
5769 | ) |
5770 | )) | |
5771 | ||
5772 | (defun gnus-find-header-by-number (headers number) | |
5773 | "Return a header which is a element of HEADERS and has NUMBER." | |
5774 | (let ((found nil)) | |
5775 | (while (and headers (not found)) | |
5776 | ;; We cannot use `=' to accept non-numeric NUMBER. | |
5777 | (if (eq number (nntp-header-number (car headers))) | |
5778 | (setq found (car headers))) | |
5779 | (setq headers (cdr headers))) | |
5780 | found | |
5781 | )) | |
5782 | ||
5783 | (defun gnus-find-header-by-id (headers id) | |
5784 | "Return a header which is a element of HEADERS and has Message-ID." | |
5785 | (let ((found nil)) | |
5786 | (while (and headers (not found)) | |
5787 | (if (string-equal id (nntp-header-id (car headers))) | |
5788 | (setq found (car headers))) | |
5789 | (setq headers (cdr headers))) | |
5790 | found | |
5791 | )) | |
5792 | ||
5793 | (defun gnus-version () | |
5794 | "Version numbers of this version of GNUS." | |
5795 | (interactive) | |
5796 | (cond ((and (boundp 'mhspool-version) (boundp 'nnspool-version)) | |
5797 | (message "%s; %s; %s; %s" | |
5798 | gnus-version nntp-version nnspool-version mhspool-version)) | |
5799 | ((boundp 'mhspool-version) | |
5800 | (message "%s; %s; %s" | |
5801 | gnus-version nntp-version mhspool-version)) | |
5802 | ((boundp 'nnspool-version) | |
5803 | (message "%s; %s; %s" | |
5804 | gnus-version nntp-version nnspool-version)) | |
5805 | (t | |
5806 | (message "%s; %s" gnus-version nntp-version)))) | |
5807 | ||
b027f415 | 5808 | (defun gnus-info-find-node () |
745bc783 JB |
5809 | "Find Info documentation of GNUS." |
5810 | (interactive) | |
5811 | (require 'info) | |
5812 | ;; Enlarge info window if needed. | |
b027f415 | 5813 | (cond ((eq major-mode 'gnus-group-mode) |
745bc783 | 5814 | (gnus-configure-windows '(1 0 0)) ;Take all windows. |
b027f415 RS |
5815 | (pop-to-buffer gnus-group-buffer)) |
5816 | ((eq major-mode 'gnus-summary-mode) | |
745bc783 | 5817 | (gnus-configure-windows '(0 1 0)) ;Take all windows. |
b027f415 | 5818 | (pop-to-buffer gnus-summary-buffer))) |
655793e5 | 5819 | (Info-goto-node (car (cdr (assq major-mode gnus-info-nodes))))) |
745bc783 JB |
5820 | |
5821 | (defun gnus-overload-functions (&optional overloads) | |
5822 | "Overload functions specified by optional argument OVERLOADS. | |
5823 | If nothing is specified, use the variable gnus-overload-functions." | |
5824 | (let ((defs nil) | |
5825 | (overloads (or overloads gnus-overload-functions))) | |
5826 | (while overloads | |
5827 | (setq defs (car overloads)) | |
5828 | (setq overloads (cdr overloads)) | |
5829 | ;; Load file before overloading function if necessary. Make | |
eb8c3be9 | 5830 | ;; sure we cannot use `require' always. |
745bc783 JB |
5831 | (and (not (fboundp (car defs))) |
5832 | (car (cdr (cdr defs))) | |
5833 | (load (car (cdr (cdr defs))) nil 'nomessage)) | |
5834 | (fset (car defs) (car (cdr defs))) | |
5835 | ))) | |
5836 | ||
5837 | (defun gnus-make-threads (newsgroup-headers) | |
5838 | "Make conversation threads tree from NEWSGROUP-HEADERS." | |
5839 | (let ((headers newsgroup-headers) | |
b027f415 | 5840 | (refer nil) |
745bc783 JB |
5841 | (h nil) |
5842 | (d nil) | |
5843 | (roots nil) | |
5844 | (dependencies nil)) | |
5845 | ;; Make message dependency alist. | |
5846 | (while headers | |
5847 | (setq h (car headers)) | |
5848 | (setq headers (cdr headers)) | |
5849 | ;; Ignore invalid headers. | |
5850 | (if (vectorp h) ;Depends on nntp.el. | |
5851 | (progn | |
5852 | ;; Ignore broken references, e.g "<123@a.b.c". | |
b027f415 RS |
5853 | (setq refer (nntp-header-references h)) |
5854 | (setq d (and refer | |
5855 | (string-match "\\(<[^<>]+>\\)[^>]*$" refer) | |
5856 | ;; (gnus-find-header-by-id | |
5857 | ;; newsgroup-headers | |
5858 | ;; (substring refer (match-beginning 1) (match-end 1))) | |
5859 | ;; In fact if the variable newsgroup-headers | |
5860 | ;; is not 'equal' to the variable | |
5861 | ;; gnus-newsgroup-headers, the following | |
5862 | ;; function call may return bogus value. | |
5863 | (gnus-get-header-by-id | |
5864 | (substring refer (match-beginning 1) (match-end 1))) | |
5865 | )) | |
745bc783 JB |
5866 | ;; Check subject equality. |
5867 | (or gnus-thread-ignore-subject | |
5868 | (null d) | |
5869 | (string-equal (gnus-simplify-subject | |
5870 | (nntp-header-subject h) 're) | |
5871 | (gnus-simplify-subject | |
5872 | (nntp-header-subject d) 're)) | |
5873 | ;; H should be a thread root. | |
5874 | (setq d nil)) | |
5875 | ;; H depends on D. | |
5876 | (setq dependencies | |
5877 | (cons (cons h d) dependencies)) | |
5878 | ;; H is a thread root. | |
5879 | (if (null d) | |
5880 | (setq roots (cons h roots))) | |
5881 | )) | |
5882 | ) | |
5883 | ;; Make complete threads from the roots. | |
5884 | ;; Note: dependencies are in reverse order, but | |
5885 | ;; gnus-make-threads-1 processes it in reverse order again. So, | |
5886 | ;; we don't have to worry about it. | |
5887 | (mapcar | |
5888 | (function | |
5889 | (lambda (root) | |
5890 | (gnus-make-threads-1 root dependencies))) (nreverse roots)) | |
5891 | )) | |
5892 | ||
5893 | (defun gnus-make-threads-1 (parent dependencies) | |
5894 | (let ((children nil) | |
5895 | (d nil) | |
5896 | (depends dependencies)) | |
5897 | ;; Find children. | |
5898 | (while depends | |
5899 | (setq d (car depends)) | |
5900 | (setq depends (cdr depends)) | |
5901 | (and (cdr d) | |
5902 | (eq (nntp-header-id parent) (nntp-header-id (cdr d))) | |
5903 | (setq children (cons (car d) children)))) | |
5904 | ;; Go down. | |
5905 | (cons parent | |
5906 | (mapcar | |
5907 | (function | |
5908 | (lambda (child) | |
5909 | (gnus-make-threads-1 child dependencies))) children)) | |
5910 | )) | |
5911 | ||
5912 | (defun gnus-narrow-to-page (&optional arg) | |
5913 | "Make text outside current page invisible except for page delimiter. | |
5914 | A numeric arg specifies to move forward or backward by that many pages, | |
5915 | thus showing a page other than the one point was originally in." | |
5916 | (interactive "P") | |
5917 | (setq arg (if arg (prefix-numeric-value arg) 0)) | |
5918 | (save-excursion | |
5919 | (forward-page -1) ;Beginning of current page. | |
5920 | (widen) | |
5921 | (if (> arg 0) | |
5922 | (forward-page arg) | |
5923 | (if (< arg 0) | |
5924 | (forward-page (1- arg)))) | |
5925 | ;; Find the end of the page. | |
5926 | (forward-page) | |
5927 | ;; If we stopped due to end of buffer, stay there. | |
5928 | ;; If we stopped after a page delimiter, put end of restriction | |
5929 | ;; at the beginning of that line. | |
5930 | ;; These are commented out. | |
5931 | ;; (if (save-excursion (beginning-of-line) | |
5932 | ;; (looking-at page-delimiter)) | |
5933 | ;; (beginning-of-line)) | |
5934 | (narrow-to-region (point) | |
5935 | (progn | |
5936 | ;; Find the top of the page. | |
5937 | (forward-page -1) | |
5938 | ;; If we found beginning of buffer, stay there. | |
5939 | ;; If extra text follows page delimiter on same line, | |
5940 | ;; include it. | |
5941 | ;; Otherwise, show text starting with following line. | |
5942 | (if (and (eolp) (not (bobp))) | |
5943 | (forward-line 1)) | |
5944 | (point))) | |
5945 | )) | |
5946 | ||
b027f415 RS |
5947 | ;; Create hash table for alist, such as gnus-newsrc-assoc, |
5948 | ;; gnus-killed-assoc, and gnus-marked-assoc. | |
5949 | ||
5950 | (defun gnus-make-hashtable-from-alist (alist &optional hashsize) | |
5951 | "Return hash table for ALIST. | |
5952 | Optional argument HASHSIZE specifies the hashtable size. | |
5953 | Hash key is a car of alist element, which must be a string." | |
5954 | (let ((hashtb (gnus-make-hashtable (or hashsize (length alist))))) | |
5955 | (while alist | |
5956 | (gnus-sethash (car (car alist)) ;Newsgroup name | |
5957 | (car alist) ;Alist element | |
5958 | hashtb) | |
5959 | (setq alist (cdr alist))) | |
5960 | hashtb | |
5961 | )) | |
5962 | ||
745bc783 JB |
5963 | (defun gnus-last-element (list) |
5964 | "Return last element of LIST." | |
5965 | (let ((last nil)) | |
5966 | (while list | |
5967 | (if (null (cdr list)) | |
5968 | (setq last (car list))) | |
5969 | (setq list (cdr list))) | |
5970 | last | |
5971 | )) | |
5972 | ||
5973 | (defun gnus-set-difference (list1 list2) | |
5974 | "Return a list of elements of LIST1 that do not appear in LIST2." | |
5975 | (let ((list1 (copy-sequence list1))) | |
5976 | (while list2 | |
5977 | (setq list1 (delq (car list2) list1)) | |
5978 | (setq list2 (cdr list2))) | |
5979 | list1 | |
5980 | )) | |
5981 | ||
5982 | (defun gnus-intersection (list1 list2) | |
5983 | "Return a list of elements that appear in both LIST1 and LIST2." | |
5984 | (let ((result nil)) | |
5985 | (while list2 | |
5986 | (if (memq (car list2) list1) | |
5987 | (setq result (cons (car list2) result))) | |
5988 | (setq list2 (cdr list2))) | |
5989 | result | |
5990 | )) | |
5991 | ||
5992 | \f | |
5993 | ;;; | |
5994 | ;;; Get information about active articles, already read articles, and | |
5995 | ;;; still unread articles. | |
5996 | ;;; | |
5997 | ||
5998 | ;; GNUS internal format of gnus-newsrc-assoc and gnus-killed-assoc: | |
5999 | ;; (("general" t (1 . 1)) | |
6000 | ;; ("misc" t (1 . 10) (12 . 15)) | |
6001 | ;; ("test" nil (1 . 99)) ...) | |
6002 | ;; GNUS internal format of gnus-marked-assoc: | |
6003 | ;; (("general" 1 2 3) | |
6004 | ;; ("misc" 2) ...) | |
6005 | ;; GNUS internal format of gnus-active-hashtb: | |
6006 | ;; (("general" t (1 . 1)) | |
6007 | ;; ("misc" t (1 . 10)) | |
6008 | ;; ("test" nil (1 . 99)) ...) | |
6009 | ;; GNUS internal format of gnus-unread-hashtb: | |
6010 | ;; (("general" 1 (1 . 1)) | |
6011 | ;; ("misc" 14 (1 . 10) (12 . 15)) | |
6012 | ;; ("test" 99 (1 . 99)) ...) | |
6013 | ||
b027f415 | 6014 | (defun gnus-setup-news (&optional rawfile) |
745bc783 JB |
6015 | "Setup news information. |
6016 | If optional argument RAWFILE is non-nil, force to read raw startup file." | |
6017 | (let ((init (not (and gnus-newsrc-assoc | |
6018 | gnus-active-hashtb | |
6019 | gnus-unread-hashtb | |
6020 | (not rawfile) | |
6021 | )))) | |
6022 | ;; We have to clear some variables to re-initialize news info. | |
6023 | (if init | |
6024 | (setq gnus-newsrc-assoc nil | |
6025 | gnus-active-hashtb nil | |
6026 | gnus-unread-hashtb nil)) | |
745bc783 | 6027 | (gnus-read-active-file) |
b027f415 RS |
6028 | ;; Initialize only once. |
6029 | (if init | |
6030 | (progn | |
6031 | ;; Get distributions only once. | |
6032 | (gnus-read-distributions-file) | |
6033 | ;; newsrc file must be read after reading active file since | |
6034 | ;; its size is used to guess the size of gnus-newsrc-hashtb. | |
6035 | (gnus-read-newsrc-file rawfile) | |
6036 | )) | |
745bc783 JB |
6037 | (gnus-expire-marked-articles) |
6038 | (gnus-get-unread-articles) | |
6039 | ;; Check new newsgroups and subscribe them. | |
6040 | (if init | |
6041 | (let ((new-newsgroups (gnus-find-new-newsgroups))) | |
6042 | (while new-newsgroups | |
6043 | (funcall gnus-subscribe-newsgroup-method (car new-newsgroups)) | |
6044 | (setq new-newsgroups (cdr new-newsgroups)) | |
6045 | ))) | |
6046 | )) | |
6047 | ||
745bc783 JB |
6048 | (defun gnus-add-newsgroup (newsgroup) |
6049 | "Subscribe new NEWSGROUP safely and put it at top." | |
b027f415 | 6050 | (and (null (gnus-gethash newsgroup gnus-newsrc-hashtb)) ;Really new? |
745bc783 | 6051 | (gnus-gethash newsgroup gnus-active-hashtb) ;Really exist? |
b027f415 | 6052 | (gnus-insert-newsgroup (or (gnus-gethash newsgroup gnus-killed-hashtb) |
745bc783 JB |
6053 | (list newsgroup t)) |
6054 | (car (car gnus-newsrc-assoc))))) | |
6055 | ||
6056 | (defun gnus-find-new-newsgroups () | |
6057 | "Looking for new newsgroups and return names. | |
6058 | `-n' option of options line in .newsrc file is recognized." | |
6059 | (let ((group nil) | |
6060 | (new-newsgroups nil)) | |
6061 | (mapatoms | |
6062 | (function | |
6063 | (lambda (sym) | |
6064 | (setq group (symbol-name sym)) | |
6065 | ;; Taking account of `-n' option. | |
6066 | (and (or (null gnus-newsrc-options-n-no) | |
6067 | (not (string-match gnus-newsrc-options-n-no group)) | |
6068 | (and gnus-newsrc-options-n-yes | |
6069 | (string-match gnus-newsrc-options-n-yes group))) | |
b027f415 RS |
6070 | (null (gnus-gethash group gnus-killed-hashtb)) ;Ignore killed. |
6071 | (null (gnus-gethash group gnus-newsrc-hashtb)) ;Really new. | |
745bc783 JB |
6072 | ;; Find new newsgroup. |
6073 | (setq new-newsgroups | |
6074 | (cons group new-newsgroups))) | |
6075 | )) | |
6076 | gnus-active-hashtb) | |
6077 | ;; Return new newsgroups. | |
6078 | new-newsgroups | |
6079 | )) | |
6080 | ||
6081 | (defun gnus-kill-newsgroup (group) | |
6082 | "Kill GROUP from gnus-newsrc-assoc, .newsrc and gnus-unread-hashtb." | |
b027f415 | 6083 | (let ((info (gnus-gethash group gnus-newsrc-hashtb))) |
745bc783 JB |
6084 | (if (null info) |
6085 | nil | |
b027f415 | 6086 | ;; Delete from gnus-newsrc-assoc and gnus-newsrc-hashtb. |
745bc783 | 6087 | (setq gnus-newsrc-assoc (delq info gnus-newsrc-assoc)) |
b027f415 RS |
6088 | (gnus-sethash group nil gnus-newsrc-hashtb) |
6089 | ;; Add to gnus-killed-assoc and gnus-killed-hashtb. | |
745bc783 JB |
6090 | (setq gnus-killed-assoc |
6091 | (cons info | |
b027f415 RS |
6092 | (delq (gnus-gethash group gnus-killed-hashtb) |
6093 | gnus-killed-assoc))) | |
6094 | (gnus-sethash group info gnus-killed-hashtb) | |
745bc783 JB |
6095 | ;; Clear unread hashtable. |
6096 | ;; Thanks cwitty@csli.Stanford.EDU (Carl Witty). | |
6097 | (gnus-sethash group nil gnus-unread-hashtb) | |
6098 | ;; Then delete from .newsrc | |
6099 | (gnus-update-newsrc-buffer group 'delete) | |
6100 | ;; Return the deleted newsrc entry. | |
6101 | info | |
6102 | ))) | |
6103 | ||
6104 | (defun gnus-insert-newsgroup (info &optional next) | |
6105 | "Insert newsrc INFO entry before NEXT. | |
6106 | If optional argument NEXT is nil, appended to the last." | |
6107 | (if (null info) | |
6108 | (error "Invalid argument: %s" info)) | |
6109 | (let* ((group (car info)) ;Newsgroup name. | |
6110 | (range | |
6111 | (gnus-difference-of-range | |
6112 | (nth 2 (gnus-gethash group gnus-active-hashtb)) (nthcdr 2 info)))) | |
6113 | ;; Check duplication. | |
b027f415 | 6114 | (if (gnus-gethash group gnus-newsrc-hashtb) |
745bc783 | 6115 | (error "Duplicated: %s" group)) |
b027f415 | 6116 | ;; Insert to gnus-newsrc-assoc and gnus-newsrc-hashtb. |
745bc783 JB |
6117 | (if (string-equal next (car (car gnus-newsrc-assoc))) |
6118 | (setq gnus-newsrc-assoc | |
6119 | (cons info gnus-newsrc-assoc)) | |
6120 | (let ((found nil) | |
b027f415 RS |
6121 | (rest (cdr gnus-newsrc-assoc)) |
6122 | (tail gnus-newsrc-assoc)) | |
745bc783 JB |
6123 | ;; Seach insertion point. |
6124 | (while (and (not found) rest) | |
6125 | (if (string-equal next (car (car rest))) | |
6126 | (setq found t) | |
6127 | (setq rest (cdr rest)) | |
6128 | (setq tail (cdr tail)) | |
6129 | )) | |
6130 | ;; Find it. | |
b027f415 RS |
6131 | (if (consp tail) |
6132 | (setcdr tail (cons info rest)) | |
6133 | ;; gnus-newsrc-assoc must be nil. | |
6134 | (setq gnus-newsrc-assoc | |
6135 | (append gnus-newsrc-assoc (cons info rest)))) | |
745bc783 | 6136 | )) |
b027f415 RS |
6137 | (gnus-sethash group info gnus-newsrc-hashtb) |
6138 | ;; Delete from gnus-killed-assoc and gnus-killed-hashtb. | |
745bc783 | 6139 | (setq gnus-killed-assoc |
b027f415 RS |
6140 | (delq (gnus-gethash group gnus-killed-hashtb) gnus-killed-assoc)) |
6141 | (gnus-sethash group nil gnus-killed-hashtb) | |
745bc783 JB |
6142 | ;; Then insert to .newsrc. |
6143 | (gnus-update-newsrc-buffer group nil next) | |
6144 | ;; Add to gnus-unread-hashtb. | |
6145 | (gnus-sethash group | |
6146 | (cons group ;Newsgroup name. | |
6147 | (cons (gnus-number-of-articles range) range)) | |
6148 | gnus-unread-hashtb) | |
6149 | )) | |
6150 | ||
6151 | (defun gnus-check-killed-newsgroups () | |
b027f415 RS |
6152 | "Check consistency between gnus-newsrc-assoc and gnus-killed-assoc. |
6153 | gnus-killed-hashtb is also updated." | |
745bc783 JB |
6154 | (let ((group nil) |
6155 | (new-killed nil) | |
6156 | (old-killed gnus-killed-assoc)) | |
6157 | (while old-killed | |
6158 | (setq group (car (car old-killed))) | |
6159 | (and (or (null gnus-newsrc-options-n-no) | |
6160 | (not (string-match gnus-newsrc-options-n-no group)) | |
6161 | (and gnus-newsrc-options-n-yes | |
6162 | (string-match gnus-newsrc-options-n-yes group))) | |
b027f415 | 6163 | (null (gnus-gethash group gnus-newsrc-hashtb)) ;No duplication. |
745bc783 JB |
6164 | ;; Subscribed in options line and not in gnus-newsrc-assoc. |
6165 | (setq new-killed | |
6166 | (cons (car old-killed) new-killed))) | |
6167 | (setq old-killed (cdr old-killed)) | |
6168 | ) | |
6169 | (setq gnus-killed-assoc (nreverse new-killed)) | |
b027f415 RS |
6170 | (setq gnus-killed-hashtb |
6171 | (gnus-make-hashtable-from-alist gnus-killed-assoc)) | |
745bc783 JB |
6172 | )) |
6173 | ||
6174 | (defun gnus-check-bogus-newsgroups (&optional confirm) | |
6175 | "Delete bogus newsgroups. | |
6176 | If optional argument CONFIRM is non-nil, confirm deletion of newsgroups." | |
6177 | (let ((group nil) ;Newsgroup name temporary used. | |
6178 | (old-newsrc gnus-newsrc-assoc) | |
6179 | (new-newsrc nil) | |
6180 | (bogus nil) ;List of bogus newsgroups. | |
6181 | (old-killed gnus-killed-assoc) | |
6182 | (new-killed nil) | |
6183 | (old-marked gnus-marked-assoc) | |
6184 | (new-marked nil)) | |
6185 | (message "Checking bogus newsgroups...") | |
b027f415 | 6186 | ;; Update gnus-newsrc-assoc and gnus-newsrc-hashtb. |
745bc783 JB |
6187 | (while old-newsrc |
6188 | (setq group (car (car old-newsrc))) | |
6189 | (if (or (gnus-gethash group gnus-active-hashtb) | |
6190 | (and confirm | |
6191 | (not (y-or-n-p | |
6192 | (format "Delete bogus newsgroup: %s " group))))) | |
6193 | ;; Active newsgroup. | |
6194 | (setq new-newsrc (cons (car old-newsrc) new-newsrc)) | |
6195 | ;; Found a bogus newsgroup. | |
6196 | (setq bogus (cons group bogus))) | |
6197 | (setq old-newsrc (cdr old-newsrc)) | |
6198 | ) | |
6199 | (setq gnus-newsrc-assoc (nreverse new-newsrc)) | |
b027f415 RS |
6200 | (setq gnus-newsrc-hashtb |
6201 | (gnus-make-hashtable-from-alist gnus-newsrc-assoc)) | |
6202 | ;; Update gnus-killed-assoc and gnus-killed-hashtb. | |
745bc783 JB |
6203 | ;; The killed newsgroups are deleted without any confirmations. |
6204 | (while old-killed | |
6205 | (setq group (car (car old-killed))) | |
6206 | (and (gnus-gethash group gnus-active-hashtb) | |
b027f415 | 6207 | (null (gnus-gethash group gnus-newsrc-hashtb)) |
745bc783 JB |
6208 | ;; Active and really killed newsgroup. |
6209 | (setq new-killed (cons (car old-killed) new-killed))) | |
6210 | (setq old-killed (cdr old-killed)) | |
6211 | ) | |
6212 | (setq gnus-killed-assoc (nreverse new-killed)) | |
b027f415 RS |
6213 | (setq gnus-killed-hashtb |
6214 | (gnus-make-hashtable-from-alist gnus-killed-assoc)) | |
745bc783 JB |
6215 | ;; Remove BOGUS from .newsrc file. |
6216 | (while bogus | |
6217 | (gnus-update-newsrc-buffer (car bogus) 'delete) | |
6218 | (setq bogus (cdr bogus))) | |
b027f415 | 6219 | ;; Update gnus-marked-assoc and gnus-marked-hashtb. |
745bc783 JB |
6220 | (while old-marked |
6221 | (setq group (car (car old-marked))) | |
6222 | (if (and (cdr (car old-marked)) ;Non-empty? | |
b027f415 | 6223 | (gnus-gethash group gnus-newsrc-hashtb)) ;Not bogus? |
745bc783 JB |
6224 | (setq new-marked (cons (car old-marked) new-marked))) |
6225 | (setq old-marked (cdr old-marked))) | |
6226 | (setq gnus-marked-assoc new-marked) | |
b027f415 RS |
6227 | (setq gnus-marked-hashtb |
6228 | (gnus-make-hashtable-from-alist gnus-marked-assoc)) | |
745bc783 JB |
6229 | (message "Checking bogus newsgroups... done") |
6230 | )) | |
6231 | ||
6232 | (defun gnus-get-unread-articles () | |
6233 | "Compute diffs between active and read articles." | |
6234 | (let ((read gnus-newsrc-assoc) | |
6235 | (group-info nil) | |
6236 | (group-name nil) | |
6237 | (active nil) | |
6238 | (range nil)) | |
6239 | (message "Checking new news...") | |
6240 | (or gnus-unread-hashtb | |
b027f415 RS |
6241 | (setq gnus-unread-hashtb |
6242 | (gnus-make-hashtable (length gnus-active-hashtb)))) | |
745bc783 JB |
6243 | (while read |
6244 | (setq group-info (car read)) ;About one newsgroup | |
6245 | (setq group-name (car group-info)) | |
6246 | (setq active (nth 2 (gnus-gethash group-name gnus-active-hashtb))) | |
6247 | (if (and gnus-octive-hashtb | |
6248 | ;; Is nothing changed? | |
6249 | (equal active | |
6250 | (nth 2 (gnus-gethash group-name gnus-octive-hashtb))) | |
6251 | ;; Is this newsgroup in the unread hash table? | |
6252 | (gnus-gethash group-name gnus-unread-hashtb) | |
6253 | ) | |
6254 | nil ;Nothing to do. | |
6255 | (setq range (gnus-difference-of-range active (nthcdr 2 group-info))) | |
6256 | (gnus-sethash group-name | |
6257 | (cons group-name ;Group name | |
6258 | (cons (gnus-number-of-articles range) | |
6259 | range)) ;Range of unread articles | |
6260 | gnus-unread-hashtb) | |
6261 | ) | |
6262 | (setq read (cdr read)) | |
6263 | ) | |
6264 | (message "Checking new news... done") | |
6265 | )) | |
6266 | ||
6267 | (defun gnus-expire-marked-articles () | |
6268 | "Check expired article which is marked as unread." | |
6269 | (let ((marked-assoc gnus-marked-assoc) | |
6270 | (updated-assoc nil) | |
6271 | (marked nil) ;Current marked info. | |
6272 | (articles nil) ;List of marked articles. | |
6273 | (updated nil) ;List of real marked. | |
6274 | (begin nil)) | |
6275 | (while marked-assoc | |
6276 | (setq marked (car marked-assoc)) | |
6277 | (setq articles (cdr marked)) | |
6278 | (setq updated nil) | |
6279 | (setq begin | |
6280 | (car (nth 2 (gnus-gethash (car marked) gnus-active-hashtb)))) | |
6281 | (while (and begin articles) | |
6282 | (if (>= (car articles) begin) | |
6283 | ;; This article is still active. | |
6284 | (setq updated (cons (car articles) updated))) | |
6285 | (setq articles (cdr articles))) | |
6286 | (if updated | |
6287 | (setq updated-assoc | |
6288 | (cons (cons (car marked) updated) updated-assoc))) | |
6289 | (setq marked-assoc (cdr marked-assoc))) | |
6290 | (setq gnus-marked-assoc updated-assoc) | |
b027f415 RS |
6291 | (setq gnus-marked-hashtb |
6292 | (gnus-make-hashtable-from-alist gnus-marked-assoc)) | |
745bc783 JB |
6293 | )) |
6294 | ||
6295 | (defun gnus-mark-as-read-by-xref | |
6296 | (group headers unreads &optional subscribed-only) | |
6297 | "Mark articles as read using cross references and return updated newsgroups. | |
6298 | Arguments are GROUP, HEADERS, UNREADS, and optional SUBSCRIBED-ONLY." | |
6299 | (let ((xref-list nil) | |
6300 | (header nil) | |
6301 | (xrefs nil) ;One Xref: field info. | |
6302 | (xref nil) ;(NEWSGROUP . ARTICLE) | |
6303 | (gname nil) ;Newsgroup name | |
6304 | (article nil)) ;Article number | |
6305 | (while headers | |
6306 | (setq header (car headers)) | |
6307 | (if (memq (nntp-header-number header) unreads) | |
6308 | ;; This article is not yet marked as read. | |
6309 | nil | |
6310 | (setq xrefs (gnus-parse-xref-field (nntp-header-xref header))) | |
6311 | ;; For each cross reference info. in one Xref: field. | |
6312 | (while xrefs | |
6313 | (setq xref (car xrefs)) | |
6314 | (setq gname (car xref)) ;Newsgroup name | |
6315 | (setq article (cdr xref)) ;Article number | |
6316 | (or (string-equal group gname) ;Ignore current newsgroup. | |
6317 | ;; Ignore unsubscribed newsgroup if requested. | |
6318 | (and subscribed-only | |
b027f415 | 6319 | (not (nth 1 (gnus-gethash gname gnus-newsrc-hashtb)))) |
745bc783 | 6320 | ;; Ignore article marked as unread. |
b027f415 | 6321 | (memq article (cdr (gnus-gethash gname gnus-marked-hashtb))) |
745bc783 JB |
6322 | (let ((group-xref (assoc gname xref-list))) |
6323 | (if group-xref | |
6324 | (if (memq article (cdr group-xref)) | |
6325 | nil ;Alread marked. | |
6326 | (setcdr group-xref (cons article (cdr group-xref)))) | |
6327 | ;; Create new assoc entry for GROUP. | |
6328 | (setq xref-list (cons (list gname article) xref-list))) | |
6329 | )) | |
6330 | (setq xrefs (cdr xrefs)) | |
6331 | )) | |
6332 | (setq headers (cdr headers))) | |
6333 | ;; Mark cross referenced articles as read. | |
6334 | (gnus-mark-xrefed-as-read xref-list) | |
6335 | ;;(message "%s %s" (prin1-to-string unreads) (prin1-to-string xref-list)) | |
6336 | ;; Return list of updated group name. | |
6337 | (mapcar (function car) xref-list) | |
6338 | )) | |
6339 | ||
6340 | (defun gnus-parse-xref-field (xref-value) | |
6341 | "Parse Xref: field value, and return list of `(group . article-id)'." | |
6342 | (let ((xref-list nil) | |
6343 | (xref-value (or xref-value ""))) | |
6344 | ;; Remove server host name. | |
6345 | (if (string-match "^[ \t]*[^ \t,]+[ \t,]+\\(.*\\)$" xref-value) | |
6346 | (setq xref-value (substring xref-value (match-beginning 1))) | |
6347 | (setq xref-value nil)) | |
6348 | ;; Process each xref info. | |
6349 | (while xref-value | |
6350 | (if (string-match | |
6351 | "^[ \t,]*\\([^ \t,]+\\):\\([0-9]+\\)[^0-9]*" xref-value) | |
6352 | (progn | |
6353 | (setq xref-list | |
6354 | (cons | |
6355 | (cons | |
6356 | ;; Group name | |
6357 | (substring xref-value (match-beginning 1) (match-end 1)) | |
6358 | ;; Article-ID | |
6359 | (string-to-int | |
6360 | (substring xref-value (match-beginning 2) (match-end 2)))) | |
6361 | xref-list)) | |
6362 | (setq xref-value (substring xref-value (match-end 2)))) | |
6363 | (setq xref-value nil))) | |
6364 | ;; Return alist. | |
6365 | xref-list | |
6366 | )) | |
6367 | ||
6368 | (defun gnus-mark-xrefed-as-read (xrefs) | |
6369 | "Update unread article information using XREFS alist." | |
6370 | (let ((group nil) | |
6371 | (idlist nil) | |
6372 | (unread nil)) | |
6373 | (while xrefs | |
6374 | (setq group (car (car xrefs))) | |
6375 | (setq idlist (cdr (car xrefs))) | |
6376 | (setq unread (gnus-uncompress-sequence | |
6377 | (nthcdr 2 (gnus-gethash group gnus-unread-hashtb)))) | |
6378 | (while idlist | |
6379 | (setq unread (delq (car idlist) unread)) | |
6380 | (setq idlist (cdr idlist))) | |
6381 | (gnus-update-unread-articles group unread 'ignore) | |
6382 | (setq xrefs (cdr xrefs)) | |
6383 | ))) | |
6384 | ||
6385 | (defun gnus-update-unread-articles (group unread-list marked-list) | |
6386 | "Update unread articles of GROUP using UNREAD-LIST and MARKED-LIST." | |
6387 | (let ((active (nth 2 (gnus-gethash group gnus-active-hashtb))) | |
6388 | (unread (gnus-gethash group gnus-unread-hashtb))) | |
6389 | (if (or (null active) (null unread)) | |
6390 | ;; Ignore unknown newsgroup. | |
6391 | nil | |
6392 | ;; Update gnus-unread-hashtb. | |
6393 | (if unread-list | |
6394 | (setcdr (cdr unread) | |
6395 | (gnus-compress-sequence unread-list)) | |
6396 | ;; All of the articles are read. | |
6397 | (setcdr (cdr unread) '((0 . 0)))) | |
6398 | ;; Number of unread articles. | |
6399 | (setcar (cdr unread) | |
6400 | (gnus-number-of-articles (nthcdr 2 unread))) | |
6401 | ;; Update gnus-newsrc-assoc. | |
6402 | (if (> (car active) 0) | |
6403 | ;; Articles from 1 to N are not active. | |
6404 | (setq active (cons 1 (cdr active)))) | |
b027f415 | 6405 | (setcdr (cdr (gnus-gethash group gnus-newsrc-hashtb)) |
745bc783 JB |
6406 | (gnus-difference-of-range active (nthcdr 2 unread))) |
6407 | ;; Update .newsrc buffer. | |
6408 | (gnus-update-newsrc-buffer group) | |
6409 | ;; Update gnus-marked-assoc. | |
6410 | (if (listp marked-list) ;Includes NIL. | |
b027f415 RS |
6411 | (let ((marked (gnus-gethash group gnus-marked-hashtb))) |
6412 | (cond (marked ;There is an entry. | |
745bc783 JB |
6413 | (setcdr marked marked-list)) |
6414 | (marked-list ;Non-NIL. | |
b027f415 RS |
6415 | (let ((info (cons group marked-list))) |
6416 | ;; hashtb must share the same cons cell. | |
6417 | (setq gnus-marked-assoc | |
6418 | (cons info gnus-marked-assoc)) | |
6419 | (gnus-sethash group info gnus-marked-hashtb) | |
6420 | )) | |
745bc783 JB |
6421 | ))) |
6422 | ))) | |
6423 | ||
6424 | (defun gnus-read-active-file () | |
6425 | "Get active file from NNTP server." | |
b027f415 RS |
6426 | ;; Make sure a connection to NNTP server is alive. |
6427 | (gnus-start-news-server) | |
745bc783 JB |
6428 | (message "Reading active file...") |
6429 | (if (gnus-request-list) ;Get active file from server | |
6430 | (save-excursion | |
6431 | (set-buffer nntp-server-buffer) | |
745bc783 JB |
6432 | (gnus-active-to-gnus-format) |
6433 | (message "Reading active file... done")) | |
6434 | (error "Cannot read active file from NNTP server."))) | |
6435 | ||
6436 | (defun gnus-active-to-gnus-format () | |
b027f415 RS |
6437 | "Convert active file format to internal format. |
6438 | Lines matching gnus-ignored-newsgroups are ignored." | |
745bc783 JB |
6439 | ;; Delete unnecessary lines. |
6440 | (goto-char (point-min)) | |
b027f415 RS |
6441 | ;;(delete-matching-lines "^to\\..*$") |
6442 | (delete-matching-lines gnus-ignored-newsgroups) | |
6443 | ;; Save OLD active info. | |
6444 | (setq gnus-octive-hashtb gnus-active-hashtb) | |
6445 | ;; Make large enough hash table. | |
6446 | (setq gnus-active-hashtb | |
6447 | (gnus-make-hashtable (count-lines (point-min) (point-max)))) | |
745bc783 JB |
6448 | ;; Store active file in hashtable. |
6449 | (goto-char (point-min)) | |
6450 | (while | |
6451 | (re-search-forward | |
6452 | "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([ymn]\\).*$" | |
6453 | nil t) | |
6454 | (gnus-sethash | |
6455 | (buffer-substring (match-beginning 1) (match-end 1)) | |
6456 | (list (buffer-substring (match-beginning 1) (match-end 1)) | |
6457 | (string-equal | |
6458 | "y" (buffer-substring (match-beginning 4) (match-end 4))) | |
6459 | (cons (string-to-int | |
6460 | (buffer-substring (match-beginning 3) (match-end 3))) | |
6461 | (string-to-int | |
6462 | (buffer-substring (match-beginning 2) (match-end 2))))) | |
b027f415 RS |
6463 | gnus-active-hashtb) |
6464 | )) | |
745bc783 JB |
6465 | |
6466 | (defun gnus-read-newsrc-file (&optional rawfile) | |
6467 | "Read startup FILE. | |
6468 | If optional argument RAWFILE is non-nil, the raw startup file is read." | |
b027f415 | 6469 | (setq gnus-current-startup-file (gnus-make-newsrc-file gnus-startup-file)) |
745bc783 JB |
6470 | ;; Reset variables which may be included in the quick startup file. |
6471 | (let ((variables gnus-variable-list)) | |
6472 | (while variables | |
6473 | (set (car variables) nil) | |
6474 | (setq variables (cdr variables)))) | |
6475 | (let* ((newsrc-file gnus-current-startup-file) | |
6476 | (quick-file (concat newsrc-file ".el")) | |
b027f415 | 6477 | (quick-loaded nil)) |
745bc783 JB |
6478 | (save-excursion |
6479 | ;; Prepare .newsrc buffer. | |
6480 | (set-buffer (find-file-noselect newsrc-file)) | |
6481 | ;; It is not so good idea turning off undo. | |
b027f415 | 6482 | ;;(buffer-flush-undo (current-buffer)) |
745bc783 JB |
6483 | ;; Load quick .newsrc to restore gnus-marked-assoc and |
6484 | ;; gnus-killed-assoc even if gnus-newsrc-assoc is out of date. | |
6485 | (condition-case nil | |
b027f415 RS |
6486 | (progn |
6487 | (setq quick-loaded (load quick-file t t t)) | |
6488 | ;; Recreate hashtables. | |
6489 | (setq gnus-killed-hashtb | |
6490 | (gnus-make-hashtable-from-alist gnus-killed-assoc)) | |
6491 | (setq gnus-marked-hashtb | |
6492 | (gnus-make-hashtable-from-alist gnus-marked-assoc)) | |
6493 | ) | |
745bc783 JB |
6494 | (error nil)) |
6495 | (cond ((and (not rawfile) ;Not forced to read the raw file. | |
b027f415 | 6496 | ;; .newsrc.el is newer than .newsrc. |
abc01fb8 RS |
6497 | ;; Do it this way in case timestamps are identical |
6498 | ;; (on fast machines/disks). | |
6499 | (not (file-newer-than-file-p newsrc-file quick-file)) | |
745bc783 JB |
6500 | quick-loaded |
6501 | gnus-newsrc-assoc ;Really loaded? | |
6502 | ) | |
6503 | ;; We don't have to read the raw startup file. | |
b027f415 RS |
6504 | ;; gnus-newsrc-assoc may be defined in the quick startup file. |
6505 | ;; So, we have to define the hashtable here. | |
6506 | (setq gnus-newsrc-hashtb | |
6507 | (gnus-make-hashtable-from-alist gnus-newsrc-assoc))) | |
745bc783 JB |
6508 | (t |
6509 | ;; Since .newsrc file is newer than quick file, read it. | |
6510 | (message "Reading %s..." newsrc-file) | |
6511 | (gnus-newsrc-to-gnus-format) | |
6512 | (gnus-check-killed-newsgroups) | |
6513 | (message "Reading %s... Done" newsrc-file))) | |
6514 | ))) | |
6515 | ||
6516 | (defun gnus-make-newsrc-file (file) | |
6517 | "Make server dependent file name by catenating FILE and server host name." | |
6518 | (let* ((file (expand-file-name file nil)) | |
6519 | (real-file (concat file "-" gnus-nntp-server))) | |
6520 | (if (file-exists-p real-file) | |
6521 | real-file file) | |
6522 | )) | |
6523 | ||
6524 | (defun gnus-newsrc-to-gnus-format () | |
6525 | "Parse current buffer as .newsrc file." | |
6526 | (let ((newsgroup nil) | |
6527 | (subscribe nil) | |
6528 | (ranges nil) | |
6529 | (subrange nil) | |
6530 | (read-list nil)) | |
6531 | ;; We have to re-initialize these variable (except for | |
6532 | ;; gnus-marked-assoc and gnus-killed-assoc) because quick startup | |
6533 | ;; file may contain bogus values. | |
6534 | (setq gnus-newsrc-options nil) | |
6535 | (setq gnus-newsrc-options-n-yes nil) | |
6536 | (setq gnus-newsrc-options-n-no nil) | |
6537 | (setq gnus-newsrc-assoc nil) | |
b027f415 RS |
6538 | ;; Make large enough hash table. |
6539 | (setq gnus-newsrc-hashtb | |
6540 | (gnus-make-hashtable | |
6541 | (max (length gnus-active-hashtb) | |
6542 | (count-lines (point-min) (point-max))))) | |
745bc783 JB |
6543 | ;; Save options line to variable. |
6544 | ;; Lines beginning with white spaces are treated as continuation | |
6545 | ;; line. Refer man page of newsrc(5). | |
6546 | (goto-char (point-min)) | |
6547 | (if (re-search-forward | |
6548 | "^[ \t]*options[ \t]*\\(.*\\(\n[ \t]+.*\\)*\\)[ \t]*$" nil t) | |
6549 | (progn | |
6550 | ;; Save entire options line. | |
6551 | (setq gnus-newsrc-options | |
6552 | (buffer-substring (match-beginning 1) (match-end 1))) | |
6553 | ;; Compile "-n" option. | |
6554 | (if (string-match "\\(^\\|[ \t\n]\\)-n" gnus-newsrc-options) | |
6555 | (let ((yes-and-no | |
6556 | (gnus-parse-n-options | |
6557 | (substring gnus-newsrc-options (match-end 0))))) | |
6558 | (setq gnus-newsrc-options-n-yes (car yes-and-no)) | |
6559 | (setq gnus-newsrc-options-n-no (cdr yes-and-no)) | |
6560 | )) | |
6561 | )) | |
6562 | ;; Parse body of .newsrc file | |
6563 | ;; Options line continuation lines must be also considered here. | |
6564 | ;; Before supporting continuation lines, " newsgroup ! 1-5" was | |
6565 | ;; okay, but now it is invalid. It should be "newsgroup! 1-5". | |
6566 | (goto-char (point-min)) | |
6567 | ;; Due to overflows in regex.c, change the following regexp: | |
6568 | ;; "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(.*\\)$" | |
17df4d9d JB |
6569 | ;; Suggested by composer@bucsf.bu.edu (Jeff Kellem) |
6570 | ;; but no longer viable because of extensive backtracking in Emacs 19: | |
44cdca98 RS |
6571 | ;; "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(\\(...\\)*.*\\)$" |
6572 | ;; but, the following causes trouble on some case: | |
6573 | ;; "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(\\|[^ \t\n].*\\)$" | |
745bc783 | 6574 | (while (re-search-forward |
44cdca98 RS |
6575 | (if (= gnus-emacs-version 18) |
6576 | "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(\\(...\\)*.*\\)$" | |
6577 | "^\\([^:! \t\n]+\\)\\([:!]\\)[ \t]*\\(.*\\)$") | |
6578 | nil t) | |
745bc783 JB |
6579 | (setq newsgroup (buffer-substring (match-beginning 1) (match-end 1))) |
6580 | ;; Check duplications of newsgroups. | |
6581 | ;; Note: Checking the duplications takes very long time. | |
b027f415 | 6582 | (if (gnus-gethash newsgroup gnus-newsrc-hashtb) |
745bc783 JB |
6583 | (message "Ignore duplicated newsgroup: %s" newsgroup) |
6584 | (setq subscribe | |
6585 | (string-equal | |
6586 | ":" (buffer-substring (match-beginning 2) (match-end 2)))) | |
6587 | (setq ranges (buffer-substring (match-beginning 3) (match-end 3))) | |
6588 | (setq read-list nil) | |
6589 | (while (string-match "^[, \t]*\\([0-9-]+\\)" ranges) | |
6590 | (setq subrange (substring ranges (match-beginning 1) (match-end 1))) | |
6591 | (setq ranges (substring ranges (match-end 1))) | |
6592 | (cond ((string-match "^\\([0-9]+\\)-\\([0-9]+\\)$" subrange) | |
6593 | (setq read-list | |
6594 | (cons | |
6595 | (cons (string-to-int | |
6596 | (substring subrange | |
6597 | (match-beginning 1) (match-end 1))) | |
6598 | (string-to-int | |
6599 | (substring subrange | |
6600 | (match-beginning 2) (match-end 2)))) | |
6601 | read-list))) | |
6602 | ((string-match "^[0-9]+$" subrange) | |
6603 | (setq read-list | |
6604 | (cons (cons (string-to-int subrange) | |
6605 | (string-to-int subrange)) | |
6606 | read-list))) | |
6607 | (t | |
6608 | (ding) (message "Ignoring bogus lines of %s" newsgroup) | |
6609 | (sit-for 0)) | |
6610 | )) | |
6611 | (setq gnus-newsrc-assoc | |
6612 | (cons (cons newsgroup (cons subscribe (nreverse read-list))) | |
6613 | gnus-newsrc-assoc)) | |
b027f415 RS |
6614 | ;; Update gnus-newsrc-hashtb one by one. |
6615 | (gnus-sethash newsgroup (car gnus-newsrc-assoc) gnus-newsrc-hashtb) | |
745bc783 | 6616 | )) |
b027f415 | 6617 | (setq gnus-newsrc-assoc (nreverse gnus-newsrc-assoc)) |
745bc783 JB |
6618 | )) |
6619 | ||
6620 | (defun gnus-parse-n-options (options) | |
6621 | "Parse -n NEWSGROUPS options and return a cons of YES and NO regexps." | |
6622 | (let ((yes nil) | |
6623 | (no nil) | |
6624 | (yes-or-no nil) ;`!' or not. | |
6625 | (newsgroup nil)) | |
6626 | ;; Parse each newsgroup description such as "comp.all". Commas | |
6627 | ;; and white spaces can be a newsgroup separator. | |
6628 | (while | |
6629 | (string-match "^[ \t\n,]*\\(!?\\)\\([^--- \t\n,][^ \t\n,]*\\)" options) | |
6630 | (setq yes-or-no | |
6631 | (substring options (match-beginning 1) (match-end 1))) | |
6632 | (setq newsgroup | |
6633 | (regexp-quote | |
6634 | (substring options | |
6635 | (match-beginning 2) (match-end 2)))) | |
6636 | (setq options (substring options (match-end 2))) | |
6637 | ;; Rewrite "all" to ".+" not ".*". ".+" requires at least one | |
6638 | ;; character. | |
6639 | (while (string-match "\\(^\\|\\\\[.]\\)all\\(\\\\[.]\\|$\\)" newsgroup) | |
6640 | (setq newsgroup | |
6641 | (concat (substring newsgroup 0 (match-end 1)) | |
6642 | ".+" | |
6643 | (substring newsgroup (match-beginning 2))))) | |
b027f415 | 6644 | ;; It is yes or no. |
745bc783 JB |
6645 | (cond ((string-equal yes-or-no "!") |
6646 | (setq no (cons newsgroup no))) | |
6647 | ((string-equal newsgroup ".+")) ;Ignore `all'. | |
6648 | (t | |
b027f415 RS |
6649 | (setq yes (cons newsgroup yes)))) |
6650 | ) | |
745bc783 | 6651 | ;; Make a cons of regexps from parsing result. |
b027f415 RS |
6652 | ;; We have to append \(\.\|$\) to prevent matching substring of |
6653 | ;; newsgroup. For example, "jp.net" should not match with | |
6654 | ;; "jp.network". | |
6655 | ;; Fixes for large regexp problems are from yonezu@nak.math.keio.ac.jp. | |
745bc783 JB |
6656 | (cons (if yes |
6657 | (concat "^\\(" | |
6658 | (apply (function concat) | |
6659 | (mapcar | |
6660 | (function | |
6661 | (lambda (newsgroup) | |
6662 | (concat newsgroup "\\|"))) | |
6663 | (cdr yes))) | |
b027f415 | 6664 | (car yes) "\\)\\(\\.\\|$\\)")) |
745bc783 JB |
6665 | (if no |
6666 | (concat "^\\(" | |
6667 | (apply (function concat) | |
6668 | (mapcar | |
6669 | (function | |
6670 | (lambda (newsgroup) | |
6671 | (concat newsgroup "\\|"))) | |
6672 | (cdr no))) | |
b027f415 | 6673 | (car no) "\\)\\(\\.\\|$\\)"))) |
745bc783 JB |
6674 | )) |
6675 | ||
6676 | (defun gnus-save-newsrc-file () | |
6677 | "Save to .newsrc FILE." | |
6678 | ;; Note: We cannot save .newsrc file if all newsgroups are removed | |
6679 | ;; from the variable gnus-newsrc-assoc. | |
6680 | (and (or gnus-newsrc-assoc gnus-killed-assoc) | |
6681 | gnus-current-startup-file | |
6682 | (save-excursion | |
6683 | ;; A buffer containing .newsrc file may be deleted. | |
6684 | (set-buffer (find-file-noselect gnus-current-startup-file)) | |
6685 | (if (not (buffer-modified-p)) | |
6686 | (message "(No changes need to be saved)") | |
6687 | (message "Saving %s..." gnus-current-startup-file) | |
6688 | (let ((make-backup-files t) | |
6689 | (version-control nil) | |
6690 | (require-final-newline t)) ;Don't ask even if requested. | |
6691 | ;; Make backup file of master newsrc. | |
6692 | ;; You can stop or change version control of backup file. | |
6693 | ;; Suggested by jason@violet.berkeley.edu. | |
b027f415 | 6694 | (run-hooks 'gnus-save-newsrc-hook) |
745bc783 JB |
6695 | (save-buffer)) |
6696 | ;; Quickly loadable .newsrc. | |
6697 | (set-buffer (get-buffer-create " *GNUS-newsrc*")) | |
b027f415 | 6698 | (buffer-flush-undo (current-buffer)) |
745bc783 JB |
6699 | (erase-buffer) |
6700 | (gnus-gnus-to-quick-newsrc-format) | |
6701 | (let ((make-backup-files nil) | |
6702 | (version-control nil) | |
6703 | (require-final-newline t)) ;Don't ask even if requested. | |
6704 | (write-file (concat gnus-current-startup-file ".el"))) | |
6705 | (kill-buffer (current-buffer)) | |
6706 | (message "Saving %s... Done" gnus-current-startup-file) | |
6707 | )) | |
6708 | )) | |
6709 | ||
6710 | (defun gnus-update-newsrc-buffer (group &optional delete next) | |
6711 | "Incrementally update .newsrc buffer about GROUP. | |
b027f415 RS |
6712 | If optional 1st argument DELETE is non-nil, delete the group. |
6713 | If optional 2nd argument NEXT is non-nil, inserted before it." | |
745bc783 JB |
6714 | (save-excursion |
6715 | ;; Taking account of the killed startup file. | |
6716 | ;; Suggested by tale@pawl.rpi.edu. | |
6717 | (set-buffer (or (get-file-buffer gnus-current-startup-file) | |
6718 | (find-file-noselect gnus-current-startup-file))) | |
6719 | ;; Options line continuation lines must be also considered here. | |
6720 | ;; Before supporting continuation lines, " newsgroup ! 1-5" was | |
6721 | ;; okay, but now it is invalid. It should be "newsgroup! 1-5". | |
6722 | (let ((deleted nil) | |
b027f415 | 6723 | (case-fold-search nil) ;Should NOT ignore case. |
745bc783 JB |
6724 | (buffer-read-only nil)) ;May be not modifiable. |
6725 | ;; Delete ALL entries which match for GROUP. | |
6726 | (goto-char (point-min)) | |
6727 | (while (re-search-forward | |
6728 | (concat "^" (regexp-quote group) "[:!]") nil t) | |
6729 | (beginning-of-line) | |
6730 | (delete-region (point) (progn (forward-line 1) (point))) | |
6731 | (setq deleted t) ;Old entry is deleted. | |
6732 | ) | |
6733 | (if delete | |
6734 | nil | |
6735 | ;; Insert group entry. | |
b027f415 | 6736 | (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb))) |
745bc783 JB |
6737 | (if (null newsrc) |
6738 | nil | |
6739 | ;; Find insertion point. | |
6740 | (cond (deleted nil) ;Insert here. | |
6741 | ((and (stringp next) | |
6742 | (progn | |
6743 | (goto-char (point-min)) | |
6744 | (re-search-forward | |
6745 | (concat "^" (regexp-quote next) "[:!]") nil t))) | |
6746 | (beginning-of-line)) | |
6747 | (t | |
6748 | (goto-char (point-max)) | |
6749 | (or (bolp) | |
6750 | (insert "\n")))) | |
6751 | ;; Insert after options line. | |
6752 | (if (looking-at "^[ \t]*options\\([ \t]\\|$\\)") | |
6753 | (progn | |
6754 | (forward-line 1) | |
6755 | ;; Skip continuation lines. | |
6756 | (while (and (not (eobp)) | |
6757 | (looking-at "^[ \t]+")) | |
6758 | (forward-line 1)))) | |
6759 | (insert group ;Group name | |
6760 | (if (nth 1 newsrc) ": " "! ")) ;Subscribed? | |
6761 | (gnus-ranges-to-newsrc-format (nthcdr 2 newsrc)) ;Read articles | |
6762 | (insert "\n") | |
6763 | ))) | |
6764 | ))) | |
6765 | ||
6766 | (defun gnus-gnus-to-quick-newsrc-format () | |
b027f415 | 6767 | "Insert GNUS variables such as gnus-newsrc-assoc in lisp format." |
745bc783 JB |
6768 | (insert ";; GNUS internal format of .newsrc.\n") |
6769 | (insert ";; Touch .newsrc instead if you think to remove this file.\n") | |
6770 | (let ((variable nil) | |
6771 | (variables gnus-variable-list) | |
b027f415 RS |
6772 | ;; Temporary rebind to make changes |
6773 | ;; gnus-check-killed-newsgroups in invisible. | |
6774 | (gnus-killed-assoc gnus-killed-assoc) | |
6775 | (gnus-killed-hashtb gnus-killed-hashtb)) | |
6776 | ;; Remove duplicated or unsubscribed newsgroups in | |
6777 | ;; gnus-killed-assoc (and gnus-killed-hashtb). | |
745bc783 JB |
6778 | (gnus-check-killed-newsgroups) |
6779 | ;; Then, insert lisp expressions. | |
6780 | (while variables | |
6781 | (setq variable (car variables)) | |
6782 | (and (boundp variable) | |
6783 | (symbol-value variable) | |
6784 | (insert "(setq " (symbol-name variable) " '" | |
6785 | (prin1-to-string (symbol-value variable)) | |
6786 | ")\n")) | |
6787 | (setq variables (cdr variables))) | |
6788 | )) | |
6789 | ||
6790 | (defun gnus-ranges-to-newsrc-format (ranges) | |
6791 | "Insert ranges of read articles." | |
6792 | (let ((range nil)) ;Range is a pair of BEGIN and END. | |
6793 | (while ranges | |
6794 | (setq range (car ranges)) | |
6795 | (setq ranges (cdr ranges)) | |
6796 | (cond ((= (car range) (cdr range)) | |
6797 | (if (= (car range) 0) | |
6798 | (setq ranges nil) ;No unread articles. | |
6799 | (insert (int-to-string (car range))) | |
6800 | (if ranges (insert ",")) | |
6801 | )) | |
6802 | (t | |
6803 | (insert (int-to-string (car range)) | |
6804 | "-" | |
6805 | (int-to-string (cdr range))) | |
6806 | (if ranges (insert ",")) | |
6807 | )) | |
6808 | ))) | |
6809 | ||
6810 | (defun gnus-compress-sequence (numbers) | |
6811 | "Convert list of sorted numbers to ranges." | |
6812 | (let* ((numbers (sort (copy-sequence numbers) (function <))) | |
6813 | (first (car numbers)) | |
6814 | (last (car numbers)) | |
6815 | (result nil)) | |
6816 | (while numbers | |
6817 | (cond ((= last (car numbers)) nil) ;Omit duplicated number | |
6818 | ((= (1+ last) (car numbers)) ;Still in sequence | |
6819 | (setq last (car numbers))) | |
6820 | (t ;End of one sequence | |
6821 | (setq result (cons (cons first last) result)) | |
6822 | (setq first (car numbers)) | |
6823 | (setq last (car numbers))) | |
6824 | ) | |
6825 | (setq numbers (cdr numbers)) | |
6826 | ) | |
6827 | (nreverse (cons (cons first last) result)) | |
6828 | )) | |
6829 | ||
6830 | (defun gnus-uncompress-sequence (ranges) | |
6831 | "Expand compressed format of sequence." | |
6832 | (let ((first nil) | |
6833 | (last nil) | |
6834 | (result nil)) | |
6835 | (while ranges | |
6836 | (setq first (car (car ranges))) | |
6837 | (setq last (cdr (car ranges))) | |
6838 | (while (< first last) | |
6839 | (setq result (cons first result)) | |
6840 | (setq first (1+ first))) | |
6841 | (setq result (cons first result)) | |
6842 | (setq ranges (cdr ranges)) | |
6843 | ) | |
6844 | (nreverse result) | |
6845 | )) | |
6846 | ||
6847 | (defun gnus-number-of-articles (range) | |
6848 | "Compute number of articles from RANGE `((beg1 . end1) (beg2 . end2) ...)'." | |
6849 | (let ((count 0)) | |
6850 | (while range | |
6851 | (if (/= (cdr (car range)) 0) | |
6852 | ;; If end1 is 0, it must be skipped. Usually no articles in | |
6853 | ;; this group. | |
6854 | (setq count (+ count 1 (- (cdr (car range)) (car (car range)))))) | |
6855 | (setq range (cdr range)) | |
6856 | ) | |
6857 | count ;Result | |
6858 | )) | |
6859 | ||
6860 | (defun gnus-difference-of-range (src obj) | |
6861 | "Compute (SRC - OBJ) on range. | |
6862 | Range of SRC is expressed as `(beg . end)'. | |
6863 | Range of OBJ is expressed as `((beg1 . end1) (beg2 . end2) ...)." | |
6864 | (let ((beg (car src)) | |
6865 | (end (cdr src)) | |
6866 | (range nil)) ;This is result. | |
6867 | ;; Src may be nil. | |
6868 | (while (and src obj) | |
6869 | (let ((beg1 (car (car obj))) | |
6870 | (end1 (cdr (car obj)))) | |
6871 | (cond ((> beg end) | |
6872 | (setq obj nil)) ;Terminate loop | |
6873 | ((< beg beg1) | |
6874 | (setq range (cons (cons beg (min (1- beg1) end)) range)) | |
6875 | (setq beg (1+ end1))) | |
6876 | ((>= beg beg1) | |
6877 | (setq beg (max beg (1+ end1)))) | |
6878 | ) | |
6879 | (setq obj (cdr obj)) ;Next OBJ | |
6880 | )) | |
6881 | ;; Src may be nil. | |
6882 | (if (and src (<= beg end)) | |
6883 | (setq range (cons (cons beg end) range))) | |
6884 | ;; Result | |
6885 | (if range | |
6886 | (nreverse range) | |
6887 | (list (cons 0 0))) | |
6888 | )) | |
6889 | ||
b027f415 RS |
6890 | (defun gnus-read-distributions-file () |
6891 | "Get distributions file from NNTP server (NNTP2 functionality)." | |
6892 | ;; Make sure a connection to NNTP server is alive. | |
6893 | (gnus-start-news-server) | |
6894 | (message "Reading distributions file...") | |
6895 | (setq gnus-distribution-list nil) | |
6896 | (if (gnus-request-list-distributions) | |
6897 | (save-excursion | |
6898 | (set-buffer nntp-server-buffer) | |
6899 | (gnus-distributions-to-gnus-format) | |
6900 | (message "Reading distributions file... done")) | |
6901 | ;; It's not a fatal error. | |
6902 | ;;(error "Cannot read distributions file from NNTP server.") | |
6903 | ) | |
6904 | ;; Merge with user supplied default distributions. | |
6905 | (let ((defaults (reverse gnus-local-distributions)) | |
6906 | (dist nil)) | |
6907 | (while defaults | |
6908 | (setq dist (assoc (car defaults) gnus-distribution-list)) | |
6909 | (if dist | |
6910 | (setq gnus-distribution-list | |
6911 | (delq dist gnus-distribution-list))) | |
6912 | (setq gnus-distribution-list | |
6913 | (cons (list (car defaults)) gnus-distribution-list)) | |
6914 | (setq defaults (cdr defaults)) | |
6915 | ))) | |
6916 | ||
6917 | (defun gnus-distributions-to-gnus-format () | |
6918 | "Convert distributions file format to internal format." | |
6919 | (setq gnus-distribution-list nil) | |
6920 | (goto-char (point-min)) | |
6921 | (while (re-search-forward "^\\([^ \t\n]+\\).*$" nil t) | |
6922 | (setq gnus-distribution-list | |
6923 | (cons (list (buffer-substring (match-beginning 1) (match-end 1))) | |
6924 | gnus-distribution-list))) | |
6925 | (setq gnus-distribution-list | |
6926 | (nreverse gnus-distribution-list))) | |
6927 | ||
6928 | ;; Some older version of GNU Emacs does not support function | |
6929 | ;; `file-newer-than-file-p'. | |
6930 | ||
6931 | (or (fboundp 'file-newer-than-file-p) | |
6932 | (defun file-newer-than-file-p (file1 file2) | |
6933 | "Return t if file FILE1 is newer than file FILE2. | |
6934 | If FILE1 does not exist, the answer is nil; | |
6935 | otherwise, if FILE2 does not exist, the answer is t." | |
6936 | (let ((mod1 (nth 5 (file-attributes file1))) | |
6937 | (mod2 (nth 5 (file-attributes file2)))) | |
6938 | (cond ((not (file-exists-p file1)) nil) | |
6939 | ((not (file-exists-p file2)) t) | |
6940 | ((and mod2 mod1) | |
6941 | (or (< (car mod2) (car mod1)) | |
6942 | (and (= (car mod2) (car mod1)) | |
6943 | (<= (nth 1 mod2) (nth 1 mod1))))) | |
6944 | )))) | |
6945 | ||
745bc783 JB |
6946 | \f |
6947 | ;;Local variables: | |
b027f415 | 6948 | ;;eval: (put 'gnus-eval-in-buffer-window 'lisp-indent-hook 1) |
745bc783 | 6949 | ;;end: |
44cdca98 RS |
6950 | |
6951 | ;;; gnus.el ends here |