Mercurial > emacs
annotate lisp/gnus/nnheader.el @ 41059:70987a4f43c8
Fixed some doc strings to properly quote symbols.
author | Sam Steingold <sds@gnu.org> |
---|---|
date | Wed, 14 Nov 2001 20:22:13 +0000 |
parents | 9fd6579b27ec |
children | 963ff40e6512 |
rev | line source |
---|---|
17493 | 1 ;;; nnheader.el --- header access macros for Gnus and its backends |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
2 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
3 ;; Copyright (C) 1987, 1988, 1989, 1990, 1993, 1994, 1995, 1996, |
35486
9be4b357b53a
(toplevel): Don't require `gnus-util' at
Gerd Moellmann <gerd@gnu.org>
parents:
35463
diff
changeset
|
4 ;; 1997, 1998, 2000, 2001 |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
5 ;; Free Software Foundation, Inc. |
17493 | 6 |
7 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
8 ;; Lars Magne Ingebrigtsen <larsi@gnus.org> |
17493 | 9 ;; Keywords: news |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
26 ;; Boston, MA 02111-1307, USA. | |
27 | |
28 ;;; Commentary: | |
29 | |
30 ;;; Code: | |
31 | |
19493
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
32 (eval-when-compile (require 'cl)) |
35486
9be4b357b53a
(toplevel): Don't require `gnus-util' at
Gerd Moellmann <gerd@gnu.org>
parents:
35463
diff
changeset
|
33 |
9be4b357b53a
(toplevel): Don't require `gnus-util' at
Gerd Moellmann <gerd@gnu.org>
parents:
35463
diff
changeset
|
34 ;; Requiring `gnus-util' at compile time creates a circular |
9be4b357b53a
(toplevel): Don't require `gnus-util' at
Gerd Moellmann <gerd@gnu.org>
parents:
35463
diff
changeset
|
35 ;; dependency between nnheader.el and gnus-util.el. |
9be4b357b53a
(toplevel): Don't require `gnus-util' at
Gerd Moellmann <gerd@gnu.org>
parents:
35463
diff
changeset
|
36 ;(eval-when-compile (require 'gnus-util)) |
19493
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
37 |
17493 | 38 (require 'mail-utils) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
39 (require 'mm-util) |
33300
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
40 (eval-and-compile |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
41 (autoload 'gnus-intersection "gnus-range") |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
42 (autoload 'gnus-sorted-complement "gnus-range")) |
17493 | 43 |
44 (defvar nnheader-max-head-length 4096 | |
45 "*Max length of the head of articles.") | |
46 | |
47 (defvar nnheader-head-chop-length 2048 | |
48 "*Length of each read operation when trying to fetch HEAD headers.") | |
49 | |
50 (defvar nnheader-file-name-translation-alist nil | |
51 "*Alist that says how to translate characters in file names. | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
52 For instance, if \":\" is invalid as a file character in file names |
17493 | 53 on your system, you could say something like: |
54 | |
55 \(setq nnheader-file-name-translation-alist '((?: . ?_)))") | |
56 | |
57 (eval-and-compile | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
58 (autoload 'nnmail-message-id "nnmail") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
59 (autoload 'mail-position-on-field "sendmail") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
60 (autoload 'message-remove-header "message") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
61 (autoload 'gnus-point-at-eol "gnus-util") |
35463
3279d2b52568
(gnus-delete-line): Autoload it as a macro.
Andreas Schwab <schwab@suse.de>
parents:
33342
diff
changeset
|
62 (autoload 'gnus-delete-line "gnus-util" nil nil 'macro) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
63 (autoload 'gnus-buffer-live-p "gnus-util")) |
17493 | 64 |
65 ;;; Header access macros. | |
66 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
67 ;; These macros may look very much like the ones in GNUS 4.1. They |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
68 ;; are, in a way, but you should note that the indices they use have |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
69 ;; been changed from the internal GNUS format to the NOV format. The |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
70 ;; makes it possible to read headers from XOVER much faster. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
71 ;; |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
72 ;; The format of a header is now: |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
73 ;; [number subject from date id references chars lines xref extra] |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
74 ;; |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
75 ;; (That next-to-last entry is defined as "misc" in the NOV format, |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
76 ;; but Gnus uses it for xrefs.) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
77 |
17493 | 78 (defmacro mail-header-number (header) |
79 "Return article number in HEADER." | |
80 `(aref ,header 0)) | |
81 | |
82 (defmacro mail-header-set-number (header number) | |
83 "Set article number of HEADER to NUMBER." | |
84 `(aset ,header 0 ,number)) | |
85 | |
86 (defmacro mail-header-subject (header) | |
87 "Return subject string in HEADER." | |
88 `(aref ,header 1)) | |
89 | |
90 (defmacro mail-header-set-subject (header subject) | |
91 "Set article subject of HEADER to SUBJECT." | |
92 `(aset ,header 1 ,subject)) | |
93 | |
94 (defmacro mail-header-from (header) | |
95 "Return author string in HEADER." | |
96 `(aref ,header 2)) | |
97 | |
98 (defmacro mail-header-set-from (header from) | |
99 "Set article author of HEADER to FROM." | |
100 `(aset ,header 2 ,from)) | |
101 | |
102 (defmacro mail-header-date (header) | |
103 "Return date in HEADER." | |
104 `(aref ,header 3)) | |
105 | |
106 (defmacro mail-header-set-date (header date) | |
107 "Set article date of HEADER to DATE." | |
108 `(aset ,header 3 ,date)) | |
109 | |
110 (defalias 'mail-header-message-id 'mail-header-id) | |
111 (defmacro mail-header-id (header) | |
112 "Return Id in HEADER." | |
113 `(aref ,header 4)) | |
114 | |
115 (defalias 'mail-header-set-message-id 'mail-header-set-id) | |
116 (defmacro mail-header-set-id (header id) | |
117 "Set article Id of HEADER to ID." | |
118 `(aset ,header 4 ,id)) | |
119 | |
120 (defmacro mail-header-references (header) | |
121 "Return references in HEADER." | |
122 `(aref ,header 5)) | |
123 | |
124 (defmacro mail-header-set-references (header ref) | |
125 "Set article references of HEADER to REF." | |
126 `(aset ,header 5 ,ref)) | |
127 | |
128 (defmacro mail-header-chars (header) | |
129 "Return number of chars of article in HEADER." | |
130 `(aref ,header 6)) | |
131 | |
132 (defmacro mail-header-set-chars (header chars) | |
133 "Set number of chars in article of HEADER to CHARS." | |
134 `(aset ,header 6 ,chars)) | |
135 | |
136 (defmacro mail-header-lines (header) | |
137 "Return lines in HEADER." | |
138 `(aref ,header 7)) | |
139 | |
140 (defmacro mail-header-set-lines (header lines) | |
141 "Set article lines of HEADER to LINES." | |
142 `(aset ,header 7 ,lines)) | |
143 | |
144 (defmacro mail-header-xref (header) | |
145 "Return xref string in HEADER." | |
146 `(aref ,header 8)) | |
147 | |
148 (defmacro mail-header-set-xref (header xref) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
149 "Set article XREF of HEADER to xref." |
17493 | 150 `(aset ,header 8 ,xref)) |
151 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
152 (defmacro mail-header-extra (header) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
153 "Return the extra headers in HEADER." |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
154 `(aref ,header 9)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
155 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
156 (defmacro mail-header-set-extra (header extra) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
157 "Set the extra headers in HEADER to EXTRA." |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
158 `(aset ,header 9 ',extra)) |
17493 | 159 |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
160 (defsubst make-mail-header (&optional init) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
161 "Create a new mail header structure initialized with INIT." |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
162 (make-vector 10 init)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
163 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
164 (defsubst make-full-mail-header (&optional number subject from date id |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
165 references chars lines xref |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
166 extra) |
17493 | 167 "Create a new mail header structure initialized with the parameters given." |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
168 (vector number subject from date id references chars lines xref extra)) |
17493 | 169 |
170 ;; fake message-ids: generation and detection | |
171 | |
172 (defvar nnheader-fake-message-id 1) | |
173 | |
174 (defsubst nnheader-generate-fake-message-id () | |
175 (concat "fake+none+" (int-to-string (incf nnheader-fake-message-id)))) | |
176 | |
177 (defsubst nnheader-fake-message-id-p (id) | |
178 (save-match-data ; regular message-id's are <.*> | |
179 (string-match "\\`fake\\+none\\+[0-9]+\\'" id))) | |
180 | |
181 ;; Parsing headers and NOV lines. | |
182 | |
183 (defsubst nnheader-header-value () | |
184 (buffer-substring (match-end 0) (gnus-point-at-eol))) | |
185 | |
186 (defun nnheader-parse-head (&optional naked) | |
187 (let ((case-fold-search t) | |
188 (cur (current-buffer)) | |
189 (buffer-read-only nil) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
190 in-reply-to lines p ref) |
17493 | 191 (goto-char (point-min)) |
192 (when naked | |
193 (insert "\n")) | |
194 ;; Search to the beginning of the next header. Error messages | |
195 ;; do not begin with 2 or 3. | |
196 (prog1 | |
197 (when (or naked (re-search-forward "^[23][0-9]+ " nil t)) | |
198 ;; This implementation of this function, with nine | |
199 ;; search-forwards instead of the one re-search-forward and | |
200 ;; a case (which basically was the old function) is actually | |
201 ;; about twice as fast, even though it looks messier. You | |
202 ;; can't have everything, I guess. Speed and elegance | |
203 ;; don't always go hand in hand. | |
204 (vector | |
205 ;; Number. | |
206 (if naked | |
207 (progn | |
208 (setq p (point-min)) | |
209 0) | |
210 (prog1 | |
211 (read cur) | |
212 (end-of-line) | |
213 (setq p (point)) | |
214 (narrow-to-region (point) | |
215 (or (and (search-forward "\n.\n" nil t) | |
216 (- (point) 2)) | |
217 (point))))) | |
218 ;; Subject. | |
219 (progn | |
220 (goto-char p) | |
221 (if (search-forward "\nsubject: " nil t) | |
222 (nnheader-header-value) "(none)")) | |
223 ;; From. | |
224 (progn | |
225 (goto-char p) | |
32972
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
226 (if (or (search-forward "\nfrom: " nil t) |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
227 (search-forward "\nfrom:" nil t)) |
17493 | 228 (nnheader-header-value) "(nobody)")) |
229 ;; Date. | |
230 (progn | |
231 (goto-char p) | |
232 (if (search-forward "\ndate: " nil t) | |
233 (nnheader-header-value) "")) | |
234 ;; Message-ID. | |
235 (progn | |
236 (goto-char p) | |
237 (if (search-forward "\nmessage-id:" nil t) | |
238 (buffer-substring | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
239 (1- (or (search-forward "<" (gnus-point-at-eol) t) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
240 (point))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
241 (or (search-forward ">" (gnus-point-at-eol) t) (point))) |
17493 | 242 ;; If there was no message-id, we just fake one to make |
243 ;; subsequent routines simpler. | |
244 (nnheader-generate-fake-message-id))) | |
245 ;; References. | |
246 (progn | |
247 (goto-char p) | |
248 (if (search-forward "\nreferences: " nil t) | |
249 (nnheader-header-value) | |
250 ;; Get the references from the in-reply-to header if there | |
251 ;; were no references and the in-reply-to header looks | |
252 ;; promising. | |
253 (if (and (search-forward "\nin-reply-to: " nil t) | |
254 (setq in-reply-to (nnheader-header-value)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
255 (string-match "<[^\n>]+>" in-reply-to)) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
256 (let (ref2) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
257 (setq ref (substring in-reply-to (match-beginning 0) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
258 (match-end 0))) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
259 (while (string-match "<[^\n>]+>" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
260 in-reply-to (match-end 0)) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
261 (setq ref2 (substring in-reply-to (match-beginning 0) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
262 (match-end 0))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
263 (when (> (length ref2) (length ref)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
264 (setq ref ref2))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
265 ref) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
266 nil))) |
17493 | 267 ;; Chars. |
268 0 | |
269 ;; Lines. | |
270 (progn | |
271 (goto-char p) | |
272 (if (search-forward "\nlines: " nil t) | |
273 (if (numberp (setq lines (read cur))) | |
274 lines 0) | |
275 0)) | |
276 ;; Xref. | |
277 (progn | |
278 (goto-char p) | |
279 (and (search-forward "\nxref: " nil t) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
280 (nnheader-header-value))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
281 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
282 ;; Extra. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
283 (when nnmail-extra-headers |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
284 (let ((extra nnmail-extra-headers) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
285 out) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
286 (while extra |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
287 (goto-char p) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
288 (when (search-forward |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
289 (concat "\n" (symbol-name (car extra)) ": ") nil t) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
290 (push (cons (car extra) (nnheader-header-value)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
291 out)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
292 (pop extra)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
293 out)))) |
17493 | 294 (when naked |
295 (goto-char (point-min)) | |
296 (delete-char 1))))) | |
297 | |
298 (defmacro nnheader-nov-skip-field () | |
299 '(search-forward "\t" eol 'move)) | |
300 | |
301 (defmacro nnheader-nov-field () | |
302 '(buffer-substring (point) (if (nnheader-nov-skip-field) (1- (point)) eol))) | |
303 | |
304 (defmacro nnheader-nov-read-integer () | |
305 '(prog1 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
306 (if (eq (char-after) ?\t) |
17493 | 307 0 |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
308 (let ((num (condition-case nil |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
309 (read (current-buffer)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
310 (error nil)))) |
17493 | 311 (if (numberp num) num 0))) |
312 (or (eobp) (forward-char 1)))) | |
313 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
314 (defmacro nnheader-nov-parse-extra () |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
315 '(let (out string) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
316 (while (not (memq (char-after) '(?\n nil))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
317 (setq string (nnheader-nov-field)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
318 (when (string-match "^\\([^ :]+\\): " string) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
319 (push (cons (intern (match-string 1 string)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
320 (substring string (match-end 0))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
321 out))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
322 out)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
323 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
324 (defmacro nnheader-nov-read-message-id () |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
325 '(let ((id (nnheader-nov-field))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
326 (if (string-match "^<[^>]+>$" id) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
327 id |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
328 (nnheader-generate-fake-message-id)))) |
17493 | 329 |
330 (defun nnheader-parse-nov () | |
331 (let ((eol (gnus-point-at-eol))) | |
332 (vector | |
333 (nnheader-nov-read-integer) ; number | |
334 (nnheader-nov-field) ; subject | |
335 (nnheader-nov-field) ; from | |
336 (nnheader-nov-field) ; date | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
337 (nnheader-nov-read-message-id) ; id |
17493 | 338 (nnheader-nov-field) ; refs |
339 (nnheader-nov-read-integer) ; chars | |
340 (nnheader-nov-read-integer) ; lines | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
341 (if (eq (char-after) ?\n) |
17493 | 342 nil |
31785 | 343 (if (looking-at "Xref: ") |
344 (goto-char (match-end 0))) | |
345 (nnheader-nov-field)) ; Xref | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
346 (nnheader-nov-parse-extra)))) ; extra |
17493 | 347 |
348 (defun nnheader-insert-nov (header) | |
349 (princ (mail-header-number header) (current-buffer)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
350 (let ((p (point))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
351 (insert |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
352 "\t" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
353 (or (mail-header-subject header) "(none)") "\t" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
354 (or (mail-header-from header) "(nobody)") "\t" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
355 (or (mail-header-date header) "") "\t" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
356 (or (mail-header-id header) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
357 (nnmail-message-id)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
358 "\t" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
359 (or (mail-header-references header) "") "\t") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
360 (princ (or (mail-header-chars header) 0) (current-buffer)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
361 (insert "\t") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
362 (princ (or (mail-header-lines header) 0) (current-buffer)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
363 (insert "\t") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
364 (when (mail-header-xref header) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
365 (insert "Xref: " (mail-header-xref header))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
366 (when (or (mail-header-xref header) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
367 (mail-header-extra header)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
368 (insert "\t")) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
369 (when (mail-header-extra header) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
370 (let ((extra (mail-header-extra header))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
371 (while extra |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
372 (insert (symbol-name (caar extra)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
373 ": " (cdar extra) "\t") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
374 (pop extra)))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
375 (insert "\n") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
376 (backward-char 1) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
377 (while (search-backward "\n" p t) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
378 (delete-char 1)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
379 (forward-line 1))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
380 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
381 (defun nnheader-insert-header (header) |
17493 | 382 (insert |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
383 "Subject: " (or (mail-header-subject header) "(none)") "\n" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
384 "From: " (or (mail-header-from header) "(nobody)") "\n" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
385 "Date: " (or (mail-header-date header) "") "\n" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
386 "Message-ID: " (or (mail-header-id header) (nnmail-message-id)) "\n" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
387 "References: " (or (mail-header-references header) "") "\n" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
388 "Lines: ") |
17493 | 389 (princ (or (mail-header-lines header) 0) (current-buffer)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
390 (insert "\n\n")) |
17493 | 391 |
392 (defun nnheader-insert-article-line (article) | |
393 (goto-char (point-min)) | |
394 (insert "220 ") | |
395 (princ article (current-buffer)) | |
396 (insert " Article retrieved.\n") | |
397 (search-forward "\n\n" nil 'move) | |
398 (delete-region (point) (point-max)) | |
399 (forward-char -1) | |
400 (insert ".")) | |
401 | |
402 (defun nnheader-nov-delete-outside-range (beg end) | |
403 "Delete all NOV lines that lie outside the BEG to END range." | |
404 ;; First we find the first wanted line. | |
405 (nnheader-find-nov-line beg) | |
406 (delete-region (point-min) (point)) | |
407 ;; Then we find the last wanted line. | |
408 (when (nnheader-find-nov-line end) | |
409 (forward-line 1)) | |
410 (delete-region (point) (point-max))) | |
411 | |
412 (defun nnheader-find-nov-line (article) | |
413 "Put point at the NOV line that start with ARTICLE. | |
414 If ARTICLE doesn't exist, put point where that line | |
415 would have been. The function will return non-nil if | |
416 the line could be found." | |
417 ;; This function basically does a binary search. | |
418 (let ((max (point-max)) | |
419 (min (goto-char (point-min))) | |
420 (cur (current-buffer)) | |
421 (prev (point-min)) | |
422 num found) | |
423 (while (not found) | |
424 (goto-char (/ (+ max min) 2)) | |
425 (beginning-of-line) | |
426 (if (or (= (point) prev) | |
427 (eobp)) | |
428 (setq found t) | |
429 (setq prev (point)) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
430 (while (and (not (numberp (setq num (read cur)))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
431 (not (eobp))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
432 (gnus-delete-line)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
433 (cond ((> num article) |
17493 | 434 (setq max (point))) |
435 ((< num article) | |
436 (setq min (point))) | |
437 (t | |
438 (setq found 'yes))))) | |
439 ;; We may be at the first line. | |
440 (when (and (not num) | |
441 (not (eobp))) | |
442 (setq num (read cur))) | |
443 ;; Now we may have found the article we're looking for, or we | |
444 ;; may be somewhere near it. | |
445 (when (and (not (eq found 'yes)) | |
446 (not (eq num article))) | |
447 (setq found (point)) | |
448 (while (and (< (point) max) | |
449 (or (not (numberp num)) | |
450 (< num article))) | |
451 (forward-line 1) | |
452 (setq found (point)) | |
453 (or (eobp) | |
454 (= (setq num (read cur)) article))) | |
455 (unless (eq num article) | |
456 (goto-char found))) | |
457 (beginning-of-line) | |
458 (eq num article))) | |
459 | |
460 ;; Various cruft the backends and Gnus need to communicate. | |
461 | |
462 (defvar nntp-server-buffer nil) | |
463 (defvar gnus-verbose-backends 7 | |
464 "*A number that says how talkative the Gnus backends should be.") | |
465 (defvar gnus-nov-is-evil nil | |
466 "If non-nil, Gnus backends will never output headers in the NOV format.") | |
467 (defvar news-reply-yank-from nil) | |
468 (defvar news-reply-yank-message-id nil) | |
469 | |
470 (defvar nnheader-callback-function nil) | |
471 | |
472 (defun nnheader-init-server-buffer () | |
473 "Initialize the Gnus-backend communication buffer." | |
474 (save-excursion | |
475 (unless (gnus-buffer-live-p nntp-server-buffer) | |
476 (setq nntp-server-buffer (get-buffer-create " *nntpd*"))) | |
38284
9fd6579b27ec
(nnheader-init-server-buffer): Make sure the
Gerd Moellmann <gerd@gnu.org>
parents:
35486
diff
changeset
|
477 (set-buffer nntp-server-buffer) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
478 (mm-enable-multibyte) |
17493 | 479 (erase-buffer) |
480 (kill-all-local-variables) | |
481 (setq case-fold-search t) ;Should ignore case. | |
482 t)) | |
483 | |
484 ;;; Various functions the backends use. | |
485 | |
486 (defun nnheader-file-error (file) | |
487 "Return a string that says what is wrong with FILE." | |
488 (format | |
489 (cond | |
490 ((not (file-exists-p file)) | |
491 "%s does not exist") | |
492 ((file-directory-p file) | |
493 "%s is a directory") | |
494 ((not (file-readable-p file)) | |
495 "%s is not readable")) | |
496 file)) | |
497 | |
498 (defun nnheader-insert-head (file) | |
499 "Insert the head of the article." | |
500 (when (file-exists-p file) | |
501 (if (eq nnheader-max-head-length t) | |
502 ;; Just read the entire file. | |
503 (nnheader-insert-file-contents file) | |
504 ;; Read 1K blocks until we find a separator. | |
505 (let ((beg 0) | |
506 format-alist) | |
507 (while (and (eq nnheader-head-chop-length | |
508 (nth 1 (nnheader-insert-file-contents | |
509 file nil beg | |
510 (incf beg nnheader-head-chop-length)))) | |
511 (prog1 (not (search-forward "\n\n" nil t)) | |
512 (goto-char (point-max))) | |
513 (or (null nnheader-max-head-length) | |
514 (< beg nnheader-max-head-length)))))) | |
515 t)) | |
516 | |
517 (defun nnheader-article-p () | |
518 "Say whether the current buffer looks like an article." | |
519 (goto-char (point-min)) | |
520 (if (not (search-forward "\n\n" nil t)) | |
521 nil | |
522 (narrow-to-region (point-min) (1- (point))) | |
523 (goto-char (point-min)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
524 (while (looking-at "[a-zA-Z][^ \t]+:.*\n\\([ \t].*\n\\)*\\|From .*\n") |
17493 | 525 (goto-char (match-end 0))) |
526 (prog1 | |
527 (eobp) | |
528 (widen)))) | |
529 | |
530 (defun nnheader-insert-references (references message-id) | |
531 "Insert a References header based on REFERENCES and MESSAGE-ID." | |
532 (if (and (not references) (not message-id)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
533 ;; This is invalid, but not all articles have Message-IDs. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
534 () |
17493 | 535 (mail-position-on-field "References") |
536 (let ((begin (save-excursion (beginning-of-line) (point))) | |
537 (fill-column 78) | |
538 (fill-prefix "\t")) | |
539 (when references | |
540 (insert references)) | |
541 (when (and references message-id) | |
542 (insert " ")) | |
543 (when message-id | |
544 (insert message-id)) | |
545 ;; Fold long References lines to conform to RFC1036 (sort of). | |
546 ;; The region must end with a newline to fill the region | |
547 ;; without inserting extra newline. | |
548 (fill-region-as-paragraph begin (1+ (point)))))) | |
549 | |
550 (defun nnheader-replace-header (header new-value) | |
551 "Remove HEADER and insert the NEW-VALUE." | |
552 (save-excursion | |
553 (save-restriction | |
554 (nnheader-narrow-to-headers) | |
555 (prog1 | |
556 (message-remove-header header) | |
557 (goto-char (point-max)) | |
558 (insert header ": " new-value "\n"))))) | |
559 | |
560 (defun nnheader-narrow-to-headers () | |
561 "Narrow to the head of an article." | |
562 (widen) | |
563 (narrow-to-region | |
564 (goto-char (point-min)) | |
565 (if (search-forward "\n\n" nil t) | |
566 (1- (point)) | |
567 (point-max))) | |
568 (goto-char (point-min))) | |
569 | |
570 (defun nnheader-set-temp-buffer (name &optional noerase) | |
571 "Set-buffer to an empty (possibly new) buffer called NAME with undo disabled." | |
572 (set-buffer (get-buffer-create name)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
573 (buffer-disable-undo) |
17493 | 574 (unless noerase |
575 (erase-buffer)) | |
576 (current-buffer)) | |
577 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
578 (eval-when-compile (defvar jka-compr-compression-info-list)) |
17493 | 579 (defvar nnheader-numerical-files |
580 (if (boundp 'jka-compr-compression-info-list) | |
581 (concat "\\([0-9]+\\)\\(" | |
582 (mapconcat (lambda (i) (aref i 0)) | |
583 jka-compr-compression-info-list "\\|") | |
584 "\\)?") | |
585 "[0-9]+$") | |
586 "Regexp that match numerical files.") | |
587 | |
588 (defvar nnheader-numerical-short-files (concat "^" nnheader-numerical-files) | |
589 "Regexp that matches numerical file names.") | |
590 | |
591 (defvar nnheader-numerical-full-files (concat "/" nnheader-numerical-files) | |
592 "Regexp that matches numerical full file paths.") | |
593 | |
594 (defsubst nnheader-file-to-number (file) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
595 "Take a FILE name and return the article number." |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
596 (if (string= nnheader-numerical-short-files "^[0-9]+$") |
17493 | 597 (string-to-int file) |
598 (string-match nnheader-numerical-short-files file) | |
599 (string-to-int (match-string 0 file)))) | |
600 | |
601 (defun nnheader-directory-files-safe (&rest args) | |
602 ;; It has been reported numerous times that `directory-files' | |
603 ;; fails with an alarming frequency on NFS mounted file systems. | |
604 ;; This function executes that function twice and returns | |
605 ;; the longest result. | |
606 (let ((first (apply 'directory-files args)) | |
607 (second (apply 'directory-files args))) | |
608 (if (> (length first) (length second)) | |
609 first | |
610 second))) | |
611 | |
612 (defun nnheader-directory-articles (dir) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
613 "Return a list of all article files in directory DIR." |
17493 | 614 (mapcar 'nnheader-file-to-number |
615 (nnheader-directory-files-safe | |
616 dir nil nnheader-numerical-short-files t))) | |
617 | |
618 (defun nnheader-article-to-file-alist (dir) | |
619 "Return an alist of article/file pairs in DIR." | |
620 (mapcar (lambda (file) (cons (nnheader-file-to-number file) file)) | |
621 (nnheader-directory-files-safe | |
622 dir nil nnheader-numerical-short-files t))) | |
623 | |
624 (defun nnheader-fold-continuation-lines () | |
625 "Fold continuation lines in the current buffer." | |
626 (nnheader-replace-regexp "\\(\r?\n[ \t]+\\)+" " ")) | |
627 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
628 (defun nnheader-translate-file-chars (file &optional full) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
629 "Translate FILE into something that can be a file name. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
630 If FULL, translate everything." |
17493 | 631 (if (null nnheader-file-name-translation-alist) |
632 ;; No translation is necessary. | |
633 file | |
634 (let* ((i 0) | |
635 trans leaf path len) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
636 (if full |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
637 ;; Do complete translation. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
638 (setq leaf (copy-sequence file) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
639 path "" |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
640 i (if (and (< 1 (length leaf)) (eq ?: (aref leaf 1))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
641 2 0)) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
642 ;; We translate -- but only the file name. We leave the directory |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
643 ;; alone. |
32972
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
644 (if (and (featurep 'xemacs) |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
645 (memq system-type '(win32 w32 mswindows windows-nt))) |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
646 ;; This is needed on NT and stuff, because |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
647 ;; file-name-nondirectory is not enough to split |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
648 ;; file names, containing ':', e.g. |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
649 ;; "d:\\Work\\News\\nntp+news.fido7.ru:fido7.ru.gnu.SCORE" |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
650 ;; |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
651 ;; we are trying to correctly split such names: |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
652 ;; "d:file.name" -> "a:" "file.name" |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
653 ;; "aaa:bbb.ccc" -> "" "aaa:bbb.ccc" |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
654 ;; "d:aaa\\bbb:ccc" -> "d:aaa\\" "bbb:ccc" |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
655 ;; etc. |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
656 ;; to translate then only the file name part. |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
657 (progn |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
658 (setq leaf file |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
659 path "") |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
660 (if (string-match "\\(^\\w:\\|[/\\]\\)\\([^/\\]+\\)$" file) |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
661 (setq leaf (substring file (match-beginning 2)) |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
662 path (substring file 0 (match-beginning 2))))) |
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
663 ;; Emacs DTRT, says andrewi. |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
664 (setq leaf (file-name-nondirectory file) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
665 path (file-name-directory file)))) |
17493 | 666 (setq len (length leaf)) |
667 (while (< i len) | |
668 (when (setq trans (cdr (assq (aref leaf i) | |
669 nnheader-file-name-translation-alist))) | |
670 (aset leaf i trans)) | |
671 (incf i)) | |
672 (concat path leaf)))) | |
673 | |
674 (defun nnheader-report (backend &rest args) | |
675 "Report an error from the BACKEND. | |
676 The first string in ARGS can be a format string." | |
677 (set (intern (format "%s-status-string" backend)) | |
678 (if (< (length args) 2) | |
679 (car args) | |
680 (apply 'format args))) | |
681 nil) | |
682 | |
683 (defun nnheader-get-report (backend) | |
684 "Get the most recent report from BACKEND." | |
685 (condition-case () | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
686 (nnheader-message 5 "%s" (symbol-value (intern (format "%s-status-string" |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
687 backend)))) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
688 (error (nnheader-message 5 "")))) |
17493 | 689 |
690 (defun nnheader-insert (format &rest args) | |
691 "Clear the communication buffer and insert FORMAT and ARGS into the buffer. | |
692 If FORMAT isn't a format string, it and all ARGS will be inserted | |
693 without formatting." | |
694 (save-excursion | |
695 (set-buffer nntp-server-buffer) | |
696 (erase-buffer) | |
697 (if (string-match "%" format) | |
698 (insert (apply 'format format args)) | |
699 (apply 'insert format args)) | |
700 t)) | |
701 | |
33300
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
702 (eval-and-compile |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
703 (if (fboundp 'subst-char-in-string) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
704 (defsubst nnheader-replace-chars-in-string (string from to) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
705 (subst-char-in-string from to string)) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
706 (defun nnheader-replace-chars-in-string (string from to) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
707 "Replace characters in STRING from FROM to TO." |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
708 (let ((string (substring string 0)) ;Copy string. |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
709 (len (length string)) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
710 (idx 0)) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
711 ;; Replace all occurrences of FROM with TO. |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
712 (while (< idx len) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
713 (when (= (aref string idx) from) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
714 (aset string idx to)) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
715 (setq idx (1+ idx))) |
cae923af5a5d
Wrap subst-char-in-string def in eval-and-compile.
Dave Love <fx@gnu.org>
parents:
32972
diff
changeset
|
716 string)))) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
717 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
718 (defun nnheader-replace-duplicate-chars-in-string (string from to) |
17493 | 719 "Replace characters in STRING from FROM to TO." |
720 (let ((string (substring string 0)) ;Copy string. | |
721 (len (length string)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
722 (idx 0) prev i) |
17493 | 723 ;; Replace all occurrences of FROM with TO. |
724 (while (< idx len) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
725 (setq i (aref string idx)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
726 (when (and (eq prev from) (= i from)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
727 (aset string (1- idx) to) |
17493 | 728 (aset string idx to)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
729 (setq prev i) |
17493 | 730 (setq idx (1+ idx))) |
731 string)) | |
732 | |
733 (defun nnheader-file-to-group (file &optional top) | |
734 "Return a group name based on FILE and TOP." | |
735 (nnheader-replace-chars-in-string | |
736 (if (not top) | |
737 file | |
738 (condition-case () | |
739 (substring (expand-file-name file) | |
740 (length | |
741 (expand-file-name | |
742 (file-name-as-directory top)))) | |
743 (error ""))) | |
744 ?/ ?.)) | |
745 | |
746 (defun nnheader-message (level &rest args) | |
747 "Message if the Gnus backends are talkative." | |
748 (if (or (not (numberp gnus-verbose-backends)) | |
749 (<= level gnus-verbose-backends)) | |
750 (apply 'message args) | |
751 (apply 'format args))) | |
752 | |
753 (defun nnheader-be-verbose (level) | |
754 "Return whether the backends should be verbose on LEVEL." | |
755 (or (not (numberp gnus-verbose-backends)) | |
756 (<= level gnus-verbose-backends))) | |
757 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
758 (defvar nnheader-pathname-coding-system 'binary |
19596
33877efba398
(nnheader-pathname-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19493
diff
changeset
|
759 "*Coding system for pathname.") |
33877efba398
(nnheader-pathname-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19493
diff
changeset
|
760 |
17493 | 761 (defun nnheader-group-pathname (group dir &optional file) |
762 "Make pathname for GROUP." | |
763 (concat | |
764 (let ((dir (file-name-as-directory (expand-file-name dir)))) | |
765 ;; If this directory exists, we use it directly. | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
766 (file-name-as-directory |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
767 (if (file-directory-p (concat dir group)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
768 (expand-file-name group dir) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
769 ;; If not, we translate dots into slashes. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
770 (expand-file-name (mm-encode-coding-string |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
771 (nnheader-replace-chars-in-string group ?. ?/) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
772 nnheader-pathname-coding-system) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
773 dir)))) |
17493 | 774 (cond ((null file) "") |
775 ((numberp file) (int-to-string file)) | |
776 (t file)))) | |
777 | |
778 (defun nnheader-functionp (form) | |
779 "Return non-nil if FORM is funcallable." | |
780 (or (and (symbolp form) (fboundp form)) | |
781 (and (listp form) (eq (car form) 'lambda)))) | |
782 | |
783 (defun nnheader-concat (dir &rest files) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
784 "Concat DIR as directory to FILES." |
17493 | 785 (apply 'concat (file-name-as-directory dir) files)) |
786 | |
787 (defun nnheader-ms-strip-cr () | |
788 "Strip ^M from the end of all lines." | |
789 (save-excursion | |
790 (goto-char (point-min)) | |
791 (while (re-search-forward "\r$" nil t) | |
792 (delete-backward-char 1)))) | |
793 | |
794 (defun nnheader-file-size (file) | |
795 "Return the file size of FILE or 0." | |
796 (or (nth 7 (file-attributes file)) 0)) | |
797 | |
798 (defun nnheader-find-etc-directory (package &optional file) | |
799 "Go through the path and find the \".../etc/PACKAGE\" directory. | |
800 If FILE, find the \".../etc/PACKAGE\" file instead." | |
801 (let ((path load-path) | |
802 dir result) | |
803 ;; We try to find the dir by looking at the load path, | |
804 ;; stripping away the last component and adding "etc/". | |
805 (while path | |
806 (if (and (car path) | |
807 (file-exists-p | |
808 (setq dir (concat | |
809 (file-name-directory | |
810 (directory-file-name (car path))) | |
811 "etc/" package | |
812 (if file "" "/")))) | |
813 (or file (file-directory-p dir))) | |
814 (setq result dir | |
815 path nil) | |
816 (setq path (cdr path)))) | |
817 result)) | |
818 | |
33301
c1c373a70748
Put some defvars in eval-when-compile.
Dave Love <fx@gnu.org>
parents:
33300
diff
changeset
|
819 (eval-when-compile |
c1c373a70748
Put some defvars in eval-when-compile.
Dave Love <fx@gnu.org>
parents:
33300
diff
changeset
|
820 (defvar ange-ftp-path-format) |
c1c373a70748
Put some defvars in eval-when-compile.
Dave Love <fx@gnu.org>
parents:
33300
diff
changeset
|
821 (defvar efs-path-regexp)) |
17493 | 822 (defun nnheader-re-read-dir (path) |
823 "Re-read directory PATH if PATH is on a remote system." | |
824 (if (and (fboundp 'efs-re-read-dir) (boundp 'efs-path-regexp)) | |
825 (when (string-match efs-path-regexp path) | |
826 (efs-re-read-dir path)) | |
827 (when (and (fboundp 'ange-ftp-re-read-dir) (boundp 'ange-ftp-path-format)) | |
828 (when (string-match (car ange-ftp-path-format) path) | |
829 (ange-ftp-re-read-dir path))))) | |
830 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
831 (defvar nnheader-file-coding-system 'raw-text |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
832 "Coding system used in file backends of Gnus.") |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
833 |
17493 | 834 (defun nnheader-insert-file-contents (filename &optional visit beg end replace) |
835 "Like `insert-file-contents', q.v., but only reads in the file. | |
836 A buffer may be modified in several ways after reading into the buffer due | |
837 to advanced Emacs features, such as file-name-handlers, format decoding, | |
838 find-file-hooks, etc. | |
839 This function ensures that none of these modifications will take place." | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
840 (let ((coding-system-for-read nnheader-file-coding-system)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
841 (mm-insert-file-contents filename visit beg end replace))) |
17493 | 842 |
843 (defun nnheader-find-file-noselect (&rest args) | |
844 (let ((format-alist nil) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
845 (auto-mode-alist (mm-auto-mode-alist)) |
17493 | 846 (default-major-mode 'fundamental-mode) |
847 (enable-local-variables nil) | |
19596
33877efba398
(nnheader-pathname-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19493
diff
changeset
|
848 (after-insert-file-functions nil) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
849 (enable-local-eval nil) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
850 (find-file-hooks nil) |
19596
33877efba398
(nnheader-pathname-coding-system): New variable.
Kenichi Handa <handa@m17n.org>
parents:
19493
diff
changeset
|
851 (coding-system-for-read nnheader-file-coding-system)) |
17493 | 852 (apply 'find-file-noselect args))) |
853 | |
854 (defun nnheader-directory-regular-files (dir) | |
855 "Return a list of all regular files in DIR." | |
856 (let ((files (directory-files dir t)) | |
857 out) | |
858 (while files | |
859 (when (file-regular-p (car files)) | |
860 (push (car files) out)) | |
861 (pop files)) | |
862 (nreverse out))) | |
863 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
864 (defun nnheader-directory-files (&rest args) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
865 "Same as `directory-files', but prune \".\" and \"..\"." |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
866 (let ((files (apply 'directory-files args)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
867 out) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
868 (while files |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
869 (unless (member (file-name-nondirectory (car files)) '("." "..")) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
870 (push (car files) out)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
871 (pop files)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
872 (nreverse out))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
873 |
17493 | 874 (defmacro nnheader-skeleton-replace (from &optional to regexp) |
875 `(let ((new (generate-new-buffer " *nnheader replace*")) | |
876 (cur (current-buffer)) | |
877 (start (point-min))) | |
878 (set-buffer cur) | |
879 (goto-char (point-min)) | |
880 (while (,(if regexp 're-search-forward 'search-forward) | |
881 ,from nil t) | |
882 (insert-buffer-substring | |
883 cur start (prog1 (match-beginning 0) (set-buffer new))) | |
884 (goto-char (point-max)) | |
885 ,(when to `(insert ,to)) | |
886 (set-buffer cur) | |
887 (setq start (point))) | |
888 (insert-buffer-substring | |
889 cur start (prog1 (point-max) (set-buffer new))) | |
890 (copy-to-buffer cur (point-min) (point-max)) | |
891 (kill-buffer (current-buffer)) | |
892 (set-buffer cur))) | |
893 | |
894 (defun nnheader-replace-string (from to) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
895 "Do a fast replacement of FROM to TO from point to `point-max'." |
17493 | 896 (nnheader-skeleton-replace from to)) |
897 | |
898 (defun nnheader-replace-regexp (from to) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
899 "Do a fast regexp replacement of FROM to TO from point to `point-max'." |
17493 | 900 (nnheader-skeleton-replace from to t)) |
901 | |
902 (defun nnheader-strip-cr () | |
903 "Strip all \r's from the current buffer." | |
904 (nnheader-skeleton-replace "\r")) | |
905 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
906 (defalias 'nnheader-run-at-time 'run-at-time) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
907 (defalias 'nnheader-cancel-timer 'cancel-timer) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
908 (defalias 'nnheader-cancel-function-timers 'cancel-function-timers) |
17493 | 909 |
32972
a51631f90704
2000-09-24 Simon Josefsson <simon@josefsson.org>
Dave Love <fx@gnu.org>
parents:
31785
diff
changeset
|
910 (when (featurep 'xemacs) |
17493 | 911 (require 'nnheaderxm)) |
912 | |
913 (run-hooks 'nnheader-load-hook) | |
914 | |
915 (provide 'nnheader) | |
916 | |
917 ;;; nnheader.el ends here |