annotate lisp/gnus/nnheader.el @ 18:d95e72db5c07 r19-15b92

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