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