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