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