1 ;;; nnheader.el --- header access macros for Gnus and its backends
3 ;; Copyright (C) 1987, 88, 89, 90, 93, 94, 95, 96, 97, 98, 99
4 ;; Free Software Foundation, Inc.
6 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
7 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 (eval-when-compile (require 'cl))
36 (defvar nnheader-max-head-length 4096
37 "*Max length of the head of articles.")
39 (defvar nnheader-head-chop-length 2048
40 "*Length of each read operation when trying to fetch HEAD headers.")
42 (defvar nnheader-file-name-translation-alist nil
43 "*Alist that says how to translate characters in file names.
44 For instance, if \":\" is invalid as a file character in file names
45 on your system, you could say something like:
47 \(setq nnheader-file-name-translation-alist '((?: . ?_)))")
50 (autoload 'nnmail-message-id "nnmail")
51 (autoload 'mail-position-on-field "sendmail")
52 (autoload 'message-remove-header "message")
53 (autoload 'cancel-function-timers "timers")
54 (autoload 'gnus-point-at-eol "gnus-util")
55 (autoload 'gnus-delete-line "gnus-util")
56 (autoload 'gnus-buffer-live-p "gnus-util"))
58 ;;; Header access macros.
60 ;; These macros may look very much like the ones in GNUS 4.1. They
61 ;; are, in a way, but you should note that the indices they use have
62 ;; been changed from the internal GNUS format to the NOV format. The
63 ;; makes it possible to read headers from XOVER much faster.
65 ;; The format of a header is now:
66 ;; [number subject from date id references chars lines xref extra]
68 ;; (That next-to-last entry is defined as "misc" in the NOV format,
69 ;; but Gnus uses it for xrefs.)
71 (defmacro mail-header-number (header)
72 "Return article number in HEADER."
75 (defmacro mail-header-set-number (header number)
76 "Set article number of HEADER to NUMBER."
77 `(aset ,header 0 ,number))
79 (defmacro mail-header-subject (header)
80 "Return subject string in HEADER."
83 (defmacro mail-header-set-subject (header subject)
84 "Set article subject of HEADER to SUBJECT."
85 `(aset ,header 1 ,subject))
87 (defmacro mail-header-from (header)
88 "Return author string in HEADER."
91 (defmacro mail-header-set-from (header from)
92 "Set article author of HEADER to FROM."
93 `(aset ,header 2 ,from))
95 (defmacro mail-header-date (header)
96 "Return date in HEADER."
99 (defmacro mail-header-set-date (header date)
100 "Set article date of HEADER to DATE."
101 `(aset ,header 3 ,date))
103 (defalias 'mail-header-message-id 'mail-header-id)
104 (defmacro mail-header-id (header)
105 "Return Id in HEADER."
108 (defalias 'mail-header-set-message-id 'mail-header-set-id)
109 (defmacro mail-header-set-id (header id)
110 "Set article Id of HEADER to ID."
111 `(aset ,header 4 ,id))
113 (defmacro mail-header-references (header)
114 "Return references in HEADER."
117 (defmacro mail-header-set-references (header ref)
118 "Set article references of HEADER to REF."
119 `(aset ,header 5 ,ref))
121 (defmacro mail-header-chars (header)
122 "Return number of chars of article in HEADER."
125 (defmacro mail-header-set-chars (header chars)
126 "Set number of chars in article of HEADER to CHARS."
127 `(aset ,header 6 ,chars))
129 (defmacro mail-header-lines (header)
130 "Return lines in HEADER."
133 (defmacro mail-header-set-lines (header lines)
134 "Set article lines of HEADER to LINES."
135 `(aset ,header 7 ,lines))
137 (defmacro mail-header-xref (header)
138 "Return xref string in HEADER."
141 (defmacro mail-header-set-xref (header xref)
142 "Set article xref of HEADER to xref."
143 `(aset ,header 8 ,xref))
145 (defmacro mail-header-extra (header)
146 "Return the extra headers in HEADER."
149 (defmacro mail-header-set-extra (header extra)
150 "Set the extra headers in HEADER to EXTRA."
151 `(aset ,header 9 ',extra))
153 (defsubst make-mail-header (&optional init)
154 "Create a new mail header structure initialized with INIT."
155 (make-vector 10 init))
157 (defsubst make-full-mail-header (&optional number subject from date id
158 references chars lines xref
160 "Create a new mail header structure initialized with the parameters given."
161 (vector number subject from date id references chars lines xref extra))
163 ;; fake message-ids: generation and detection
165 (defvar nnheader-fake-message-id 1)
167 (defsubst nnheader-generate-fake-message-id ()
168 (concat "fake+none+" (int-to-string (incf nnheader-fake-message-id))))
170 (defsubst nnheader-fake-message-id-p (id)
171 (save-match-data ; regular message-id's are <.*>
172 (string-match "\\`fake\\+none\\+[0-9]+\\'" id)))
174 ;; Parsing headers and NOV lines.
176 (defsubst nnheader-header-value ()
177 (buffer-substring (match-end 0) (gnus-point-at-eol)))
179 (defun nnheader-parse-head (&optional naked)
180 (let ((case-fold-search t)
181 (cur (current-buffer))
182 (buffer-read-only nil)
183 in-reply-to lines p ref)
184 (goto-char (point-min))
187 ;; Search to the beginning of the next header. Error messages
188 ;; do not begin with 2 or 3.
190 (when (or naked (re-search-forward "^[23][0-9]+ " nil t))
191 ;; This implementation of this function, with nine
192 ;; search-forwards instead of the one re-search-forward and
193 ;; a case (which basically was the old function) is actually
194 ;; about twice as fast, even though it looks messier. You
195 ;; can't have everything, I guess. Speed and elegance
196 ;; don't always go hand in hand.
207 (narrow-to-region (point)
208 (or (and (search-forward "\n.\n" nil t)
214 (if (search-forward "\nsubject: " nil t)
215 (nnheader-header-value) "(none)"))
219 (if (search-forward "\nfrom: " nil t)
220 (nnheader-header-value) "(nobody)"))
224 (if (search-forward "\ndate: " nil t)
225 (nnheader-header-value) ""))
229 (if (search-forward "\nmessage-id:" nil t)
231 (1- (or (search-forward "<" (gnus-point-at-eol) t)
233 (or (search-forward ">" (gnus-point-at-eol) t) (point)))
234 ;; If there was no message-id, we just fake one to make
235 ;; subsequent routines simpler.
236 (nnheader-generate-fake-message-id)))
240 (if (search-forward "\nreferences: " nil t)
241 (nnheader-header-value)
242 ;; Get the references from the in-reply-to header if there
243 ;; were no references and the in-reply-to header looks
245 (if (and (search-forward "\nin-reply-to: " nil t)
246 (setq in-reply-to (nnheader-header-value))
247 (string-match "<[^\n>]+>" in-reply-to))
249 (setq ref (substring in-reply-to (match-beginning 0)
251 (while (string-match "<[^\n>]+>"
252 in-reply-to (match-end 0))
253 (setq ref2 (substring in-reply-to (match-beginning 0)
255 (when (> (length ref2) (length ref))
264 (if (search-forward "\nlines: " nil t)
265 (if (numberp (setq lines (read cur)))
271 (and (search-forward "\nxref: " nil t)
272 (nnheader-header-value)))
275 (when nnmail-extra-headers
276 (let ((extra nnmail-extra-headers)
280 (when (search-forward
281 (concat "\n" (symbol-name (car extra)) ": ") nil t)
282 (push (cons (car extra) (nnheader-header-value))
287 (goto-char (point-min))
290 (defmacro nnheader-nov-skip-field ()
291 '(search-forward "\t" eol 'move))
293 (defmacro nnheader-nov-field ()
294 '(buffer-substring (point) (if (nnheader-nov-skip-field) (1- (point)) eol)))
296 (defmacro nnheader-nov-read-integer ()
298 (if (eq (char-after) ?\t)
300 (let ((num (condition-case nil
301 (read (current-buffer))
303 (if (numberp num) num 0)))
304 (or (eobp) (forward-char 1))))
306 (defmacro nnheader-nov-parse-extra ()
308 (while (not (memq (char-after) '(?\n nil)))
309 (setq string (nnheader-nov-field))
310 (when (string-match "^\\([^ :]+\\): " string)
311 (push (cons (intern (match-string 1 string))
312 (substring string (match-end 0)))
316 (defmacro nnheader-nov-read-message-id ()
317 '(let ((id (nnheader-nov-field)))
318 (if (string-match "^<[^>]+>$" id)
320 (nnheader-generate-fake-message-id))))
322 (defun nnheader-parse-nov ()
323 (let ((eol (gnus-point-at-eol)))
325 (nnheader-nov-read-integer) ; number
326 (nnheader-nov-field) ; subject
327 (nnheader-nov-field) ; from
328 (nnheader-nov-field) ; date
329 (nnheader-nov-read-message-id) ; id
330 (nnheader-nov-field) ; refs
331 (nnheader-nov-read-integer) ; chars
332 (nnheader-nov-read-integer) ; lines
333 (if (eq (char-after) ?\n)
335 (nnheader-nov-field)) ; misc
336 (nnheader-nov-parse-extra)))) ; extra
338 (defun nnheader-insert-nov (header)
339 (princ (mail-header-number header) (current-buffer))
342 (or (mail-header-subject header) "(none)") "\t"
343 (or (mail-header-from header) "(nobody)") "\t"
344 (or (mail-header-date header) "") "\t"
345 (or (mail-header-id header)
348 (or (mail-header-references header) "") "\t")
349 (princ (or (mail-header-chars header) 0) (current-buffer))
351 (princ (or (mail-header-lines header) 0) (current-buffer))
353 (when (mail-header-xref header)
354 (insert "Xref: " (mail-header-xref header)))
355 (when (or (mail-header-xref header)
356 (mail-header-extra header))
358 (when (mail-header-extra header)
359 (let ((extra (mail-header-extra header)))
361 (insert (symbol-name (caar extra))
362 ": " (cdar extra) "\t")
366 (defun nnheader-insert-header (header)
368 "Subject: " (or (mail-header-subject header) "(none)") "\n"
369 "From: " (or (mail-header-from header) "(nobody)") "\n"
370 "Date: " (or (mail-header-date header) "") "\n"
371 "Message-ID: " (or (mail-header-id header) (nnmail-message-id)) "\n"
372 "References: " (or (mail-header-references header) "") "\n"
374 (princ (or (mail-header-lines header) 0) (current-buffer))
377 (defun nnheader-insert-article-line (article)
378 (goto-char (point-min))
380 (princ article (current-buffer))
381 (insert " Article retrieved.\n")
382 (search-forward "\n\n" nil 'move)
383 (delete-region (point) (point-max))
387 (defun nnheader-nov-delete-outside-range (beg end)
388 "Delete all NOV lines that lie outside the BEG to END range."
389 ;; First we find the first wanted line.
390 (nnheader-find-nov-line beg)
391 (delete-region (point-min) (point))
392 ;; Then we find the last wanted line.
393 (when (nnheader-find-nov-line end)
395 (delete-region (point) (point-max)))
397 (defun nnheader-find-nov-line (article)
398 "Put point at the NOV line that start with ARTICLE.
399 If ARTICLE doesn't exist, put point where that line
400 would have been. The function will return non-nil if
401 the line could be found."
402 ;; This function basically does a binary search.
403 (let ((max (point-max))
404 (min (goto-char (point-min)))
405 (cur (current-buffer))
409 (goto-char (/ (+ max min) 2))
411 (if (or (= (point) prev)
415 (while (and (not (numberp (setq num (read cur))))
418 (cond ((> num article)
423 (setq found 'yes)))))
424 ;; We may be at the first line.
427 (setq num (read cur)))
428 ;; Now we may have found the article we're looking for, or we
429 ;; may be somewhere near it.
430 (when (and (not (eq found 'yes))
431 (not (eq num article)))
433 (while (and (< (point) max)
434 (or (not (numberp num))
439 (= (setq num (read cur)) article)))
440 (unless (eq num article)
445 ;; Various cruft the backends and Gnus need to communicate.
447 (defvar nntp-server-buffer nil)
448 (defvar gnus-verbose-backends 7
449 "*A number that says how talkative the Gnus backends should be.")
450 (defvar gnus-nov-is-evil nil
451 "If non-nil, Gnus backends will never output headers in the NOV format.")
452 (defvar news-reply-yank-from nil)
453 (defvar news-reply-yank-message-id nil)
455 (defvar nnheader-callback-function nil)
457 (defun nnheader-init-server-buffer ()
458 "Initialize the Gnus-backend communication buffer."
460 (unless (gnus-buffer-live-p nntp-server-buffer)
461 (setq nntp-server-buffer (get-buffer-create " *nntpd*")))
462 (mm-enable-multibyte)
463 (set-buffer nntp-server-buffer)
465 (kill-all-local-variables)
466 (setq case-fold-search t) ;Should ignore case.
469 ;;; Various functions the backends use.
471 (defun nnheader-file-error (file)
472 "Return a string that says what is wrong with FILE."
475 ((not (file-exists-p file))
477 ((file-directory-p file)
479 ((not (file-readable-p file))
480 "%s is not readable"))
483 (defun nnheader-insert-head (file)
484 "Insert the head of the article."
485 (when (file-exists-p file)
486 (if (eq nnheader-max-head-length t)
487 ;; Just read the entire file.
488 (nnheader-insert-file-contents file)
489 ;; Read 1K blocks until we find a separator.
492 (while (and (eq nnheader-head-chop-length
493 (nth 1 (nnheader-insert-file-contents
495 (incf beg nnheader-head-chop-length))))
496 (prog1 (not (search-forward "\n\n" nil t))
497 (goto-char (point-max)))
498 (or (null nnheader-max-head-length)
499 (< beg nnheader-max-head-length))))))
502 (defun nnheader-article-p ()
503 "Say whether the current buffer looks like an article."
504 (goto-char (point-min))
505 (if (not (search-forward "\n\n" nil t))
507 (narrow-to-region (point-min) (1- (point)))
508 (goto-char (point-min))
509 (while (looking-at "[a-zA-Z][^ \t]+:.*\n\\([ \t].*\n\\)*\\|From .*\n")
510 (goto-char (match-end 0)))
515 (defun nnheader-insert-references (references message-id)
516 "Insert a References header based on REFERENCES and MESSAGE-ID."
517 (if (and (not references) (not message-id))
518 ;; This is invalid, but not all articles have Message-IDs.
520 (mail-position-on-field "References")
521 (let ((begin (save-excursion (beginning-of-line) (point)))
526 (when (and references message-id)
530 ;; Fold long References lines to conform to RFC1036 (sort of).
531 ;; The region must end with a newline to fill the region
532 ;; without inserting extra newline.
533 (fill-region-as-paragraph begin (1+ (point))))))
535 (defun nnheader-replace-header (header new-value)
536 "Remove HEADER and insert the NEW-VALUE."
539 (nnheader-narrow-to-headers)
541 (message-remove-header header)
542 (goto-char (point-max))
543 (insert header ": " new-value "\n")))))
545 (defun nnheader-narrow-to-headers ()
546 "Narrow to the head of an article."
549 (goto-char (point-min))
550 (if (search-forward "\n\n" nil t)
553 (goto-char (point-min)))
555 (defun nnheader-set-temp-buffer (name &optional noerase)
556 "Set-buffer to an empty (possibly new) buffer called NAME with undo disabled."
557 (set-buffer (get-buffer-create name))
558 (buffer-disable-undo)
563 (defvar jka-compr-compression-info-list)
564 (defvar nnheader-numerical-files
565 (if (boundp 'jka-compr-compression-info-list)
566 (concat "\\([0-9]+\\)\\("
567 (mapconcat (lambda (i) (aref i 0))
568 jka-compr-compression-info-list "\\|")
571 "Regexp that match numerical files.")
573 (defvar nnheader-numerical-short-files (concat "^" nnheader-numerical-files)
574 "Regexp that matches numerical file names.")
576 (defvar nnheader-numerical-full-files (concat "/" nnheader-numerical-files)
577 "Regexp that matches numerical full file paths.")
579 (defsubst nnheader-file-to-number (file)
580 "Take a file name and return the article number."
581 (if (string= nnheader-numerical-short-files "^[0-9]+$")
583 (string-match nnheader-numerical-short-files file)
584 (string-to-int (match-string 0 file))))
586 (defun nnheader-directory-files-safe (&rest args)
587 ;; It has been reported numerous times that `directory-files'
588 ;; fails with an alarming frequency on NFS mounted file systems.
589 ;; This function executes that function twice and returns
590 ;; the longest result.
591 (let ((first (apply 'directory-files args))
592 (second (apply 'directory-files args)))
593 (if (> (length first) (length second))
597 (defun nnheader-directory-articles (dir)
598 "Return a list of all article files in a directory."
599 (mapcar 'nnheader-file-to-number
600 (nnheader-directory-files-safe
601 dir nil nnheader-numerical-short-files t)))
603 (defun nnheader-article-to-file-alist (dir)
604 "Return an alist of article/file pairs in DIR."
605 (mapcar (lambda (file) (cons (nnheader-file-to-number file) file))
606 (nnheader-directory-files-safe
607 dir nil nnheader-numerical-short-files t)))
609 (defun nnheader-fold-continuation-lines ()
610 "Fold continuation lines in the current buffer."
611 (nnheader-replace-regexp "\\(\r?\n[ \t]+\\)+" " "))
613 (defun nnheader-translate-file-chars (file &optional full)
614 "Translate FILE into something that can be a file name.
615 If FULL, translate everything."
616 (if (null nnheader-file-name-translation-alist)
617 ;; No translation is necessary.
622 ;; Do complete translation.
623 (setq leaf (copy-sequence file)
625 i (if (and (< 1 (length leaf)) (eq ?: (aref leaf 1)))
627 ;; We translate -- but only the file name. We leave the directory
629 (if (string-match "/[^/]+\\'" file)
630 ;; This is needed on NT's and stuff.
631 (setq leaf (substring file (1+ (match-beginning 0)))
632 path (substring file 0 (1+ (match-beginning 0))))
633 ;; Fall back on this.
634 (setq leaf (file-name-nondirectory file)
635 path (file-name-directory file))))
636 (setq len (length leaf))
638 (when (setq trans (cdr (assq (aref leaf i)
639 nnheader-file-name-translation-alist)))
642 (concat path leaf))))
644 (defun nnheader-report (backend &rest args)
645 "Report an error from the BACKEND.
646 The first string in ARGS can be a format string."
647 (set (intern (format "%s-status-string" backend))
648 (if (< (length args) 2)
650 (apply 'format args)))
653 (defun nnheader-get-report (backend)
654 "Get the most recent report from BACKEND."
656 (nnheader-message 5 "%s" (symbol-value (intern (format "%s-status-string"
658 (error (nnheader-message 5 ""))))
660 (defun nnheader-insert (format &rest args)
661 "Clear the communication buffer and insert FORMAT and ARGS into the buffer.
662 If FORMAT isn't a format string, it and all ARGS will be inserted
665 (set-buffer nntp-server-buffer)
667 (if (string-match "%" format)
668 (insert (apply 'format format args))
669 (apply 'insert format args))
672 (defun nnheader-replace-chars-in-string (string from to)
673 "Replace characters in STRING from FROM to TO."
674 (let ((string (substring string 0)) ;Copy string.
675 (len (length string))
677 ;; Replace all occurrences of FROM with TO.
679 (when (= (aref string idx) from)
680 (aset string idx to))
684 (defun nnheader-replace-duplicate-chars-in-string (string from to)
685 "Replace characters in STRING from FROM to TO."
686 (let ((string (substring string 0)) ;Copy string.
687 (len (length string))
689 ;; Replace all occurrences of FROM with TO.
691 (setq i (aref string idx))
692 (when (and (eq prev from) (= i from))
693 (aset string (1- idx) to)
694 (aset string idx to))
699 (defun nnheader-file-to-group (file &optional top)
700 "Return a group name based on FILE and TOP."
701 (nnheader-replace-chars-in-string
705 (substring (expand-file-name file)
708 (file-name-as-directory top))))
712 (defun nnheader-message (level &rest args)
713 "Message if the Gnus backends are talkative."
714 (if (or (not (numberp gnus-verbose-backends))
715 (<= level gnus-verbose-backends))
716 (apply 'message args)
717 (apply 'format args)))
719 (defun nnheader-be-verbose (level)
720 "Return whether the backends should be verbose on LEVEL."
721 (or (not (numberp gnus-verbose-backends))
722 (<= level gnus-verbose-backends)))
724 (defvar nnheader-pathname-coding-system 'binary
725 "*Coding system for pathname.")
727 (defun nnheader-group-pathname (group dir &optional file)
728 "Make pathname for GROUP."
730 (let ((dir (file-name-as-directory (expand-file-name dir))))
731 ;; If this directory exists, we use it directly.
732 (if (file-directory-p (concat dir group))
733 (concat dir group "/")
734 ;; If not, we translate dots into slashes.
736 (mm-encode-coding-string
737 (nnheader-replace-chars-in-string group ?. ?/)
738 nnheader-pathname-coding-system)
740 (cond ((null file) "")
741 ((numberp file) (int-to-string file))
744 (defun nnheader-functionp (form)
745 "Return non-nil if FORM is funcallable."
746 (or (and (symbolp form) (fboundp form))
747 (and (listp form) (eq (car form) 'lambda))))
749 (defun nnheader-concat (dir &rest files)
750 "Concat DIR as directory to FILE."
751 (apply 'concat (file-name-as-directory dir) files))
753 (defun nnheader-ms-strip-cr ()
754 "Strip ^M from the end of all lines."
756 (goto-char (point-min))
757 (while (re-search-forward "\r$" nil t)
758 (delete-backward-char 1))))
760 (defun nnheader-file-size (file)
761 "Return the file size of FILE or 0."
762 (or (nth 7 (file-attributes file)) 0))
764 (defun nnheader-find-etc-directory (package &optional file)
765 "Go through the path and find the \".../etc/PACKAGE\" directory.
766 If FILE, find the \".../etc/PACKAGE\" file instead."
767 (let ((path load-path)
769 ;; We try to find the dir by looking at the load path,
770 ;; stripping away the last component and adding "etc/".
776 (directory-file-name (car path)))
779 (or file (file-directory-p dir)))
782 (setq path (cdr path))))
785 (defvar ange-ftp-path-format)
786 (defvar efs-path-regexp)
787 (defun nnheader-re-read-dir (path)
788 "Re-read directory PATH if PATH is on a remote system."
789 (if (and (fboundp 'efs-re-read-dir) (boundp 'efs-path-regexp))
790 (when (string-match efs-path-regexp path)
791 (efs-re-read-dir path))
792 (when (and (fboundp 'ange-ftp-re-read-dir) (boundp 'ange-ftp-path-format))
793 (when (string-match (car ange-ftp-path-format) path)
794 (ange-ftp-re-read-dir path)))))
796 (defvar nnheader-file-coding-system 'raw-text
797 "Coding system used in file backends of Gnus.")
799 (defun nnheader-insert-file-contents (filename &optional visit beg end replace)
800 "Like `insert-file-contents', q.v., but only reads in the file.
801 A buffer may be modified in several ways after reading into the buffer due
802 to advanced Emacs features, such as file-name-handlers, format decoding,
803 find-file-hooks, etc.
804 This function ensures that none of these modifications will take place."
805 (let ((coding-system-for-read nnheader-file-coding-system))
806 (mm-insert-file-contents filename visit beg end replace)))
808 (defun nnheader-find-file-noselect (&rest args)
809 (let ((format-alist nil)
810 (auto-mode-alist (mm-auto-mode-alist))
811 (default-major-mode 'fundamental-mode)
812 (enable-local-variables nil)
813 (after-insert-file-functions nil)
814 (enable-local-eval nil)
815 (find-file-hooks nil)
816 (coding-system-for-read nnheader-file-coding-system))
817 (apply 'find-file-noselect args)))
819 (defun nnheader-directory-regular-files (dir)
820 "Return a list of all regular files in DIR."
821 (let ((files (directory-files dir t))
824 (when (file-regular-p (car files))
825 (push (car files) out))
829 (defun nnheader-directory-files (&rest args)
830 "Same as `directory-files', but prune \".\" and \"..\"."
831 (let ((files (apply 'directory-files args))
834 (unless (member (file-name-nondirectory (car files)) '("." ".."))
835 (push (car files) out))
839 (defmacro nnheader-skeleton-replace (from &optional to regexp)
840 `(let ((new (generate-new-buffer " *nnheader replace*"))
841 (cur (current-buffer))
844 (goto-char (point-min))
845 (while (,(if regexp 're-search-forward 'search-forward)
847 (insert-buffer-substring
848 cur start (prog1 (match-beginning 0) (set-buffer new)))
849 (goto-char (point-max))
850 ,(when to `(insert ,to))
852 (setq start (point)))
853 (insert-buffer-substring
854 cur start (prog1 (point-max) (set-buffer new)))
855 (copy-to-buffer cur (point-min) (point-max))
856 (kill-buffer (current-buffer))
859 (defun nnheader-replace-string (from to)
860 "Do a fast replacement of FROM to TO from point to point-max."
861 (nnheader-skeleton-replace from to))
863 (defun nnheader-replace-regexp (from to)
864 "Do a fast regexp replacement of FROM to TO from point to point-max."
865 (nnheader-skeleton-replace from to t))
867 (defun nnheader-strip-cr ()
868 "Strip all \r's from the current buffer."
869 (nnheader-skeleton-replace "\r"))
871 (fset 'nnheader-run-at-time 'run-at-time)
872 (fset 'nnheader-cancel-timer 'cancel-timer)
873 (fset 'nnheader-cancel-function-timers 'cancel-function-timers)
875 (when (string-match "XEmacs\\|Lucid" emacs-version)
876 (require 'nnheaderxm))
878 (run-hooks 'nnheader-load-hook)
882 ;;; nnheader.el ends here