annotate lisp/gnus/nnheaderxm.el @ 7:c153ca296910

Added tag r19-15b4 for changeset 27bc7f280385
author cvs
date Mon, 13 Aug 2007 08:47:16 +0200
parents 376386a54a3c
children 0293115a14e9
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 ;;; nnheaderxm.el --- making Gnus backends work under XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
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: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: news
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defun nnheader-xmas-run-at-time (time repeat function &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (start-itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 "nnheader-run-at-time"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 `(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (,function ,@args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 time repeat))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defun nnheader-xmas-cancel-timer (timer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (delete-itimer timer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; Written by Erik Naggum <erik@naggum.no>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; Saved by Steve Baur <steve@miranova.com>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (defun nnheader-xmas-insert-file-contents-literally (filename &optional visit beg end replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "Like `insert-file-contents', q.v., but only reads in the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 A buffer may be modified in several ways after reading into the buffer due
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 to advanced Emacs features, such as file-name-handlers, format decoding,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 find-file-hooks, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 This function ensures that none of these modifications will take place."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (let ( ; (file-name-handler-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (format-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (after-insert-file-functions nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (find-buffer-file-type-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (if (fboundp 'find-buffer-file-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (symbol-function 'find-buffer-file-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (fset 'find-buffer-file-type (lambda (filename) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (insert-file-contents filename visit beg end replace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (if find-buffer-file-type-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (fset 'find-buffer-file-type find-buffer-file-type-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (fmakunbound 'find-buffer-file-type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defun nnheader-xmas-find-file-noselect (filename &optional nowarn rawfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "Read file FILENAME into a buffer and return the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 If a buffer exists visiting FILENAME, return that one, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 verify that the file has not changed since visited or saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 The buffer is not selected, just returned to the caller."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (abbreviate-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (expand-file-name filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (if (file-directory-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (if find-file-run-dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (dired-noselect filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (error "%s is a directory." filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (let* ((buf (get-file-buffer filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (truename (abbreviate-file-name (file-truename filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (number (nthcdr 10 (file-attributes truename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; Find any buffer for a file which has same truename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (other (and (not buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (get-file-buffer filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; Let user know if there is a buffer with the same truename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (if other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (or nowarn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (string-equal filename (buffer-file-name other))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (message "%s and %s are the same file"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 filename (buffer-file-name other)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; Optionally also find that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (if (or (and (boundp 'find-file-existing-other-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 find-file-existing-other-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 find-file-visit-truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq buf other))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (if buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (or nowarn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (verify-visited-file-modtime buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (cond ((not (file-exists-p filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (error "File %s no longer exists!" filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ((yes-or-no-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (if (string= (file-name-nondirectory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (buffer-name buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (if (buffer-modified-p buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "File %s changed on disk. Discard your edits? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 "File %s changed on disk. Reread from disk? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (if (buffer-modified-p buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "File %s changed on disk. Discard your edits in %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "File %s changed on disk. Reread from disk into %s? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (file-name-nondirectory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (buffer-name buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (revert-buffer t t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; The truename stuff makes this obsolete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; (let* ((link-name (car (file-attributes filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; (linked-buf (and (stringp link-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; (get-file-buffer link-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;; (if (bufferp linked-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;;; (message "Symbolic link to file in buffer %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;; (buffer-name linked-buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (setq buf (create-file-buffer filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; (set-buffer-major-mode buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if rawfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (nnheader-insert-file-contents-literally filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (file-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; Unconditionally set error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (setq error t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (insert-file-contents filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (file-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; Run find-file-not-found-hooks until one returns non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (or t ; (run-hook-with-args-until-success 'find-file-not-found-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; If they fail too, set error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (setq error t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; Find the file's truename, and maybe use that as visited name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (setq buffer-file-truename truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (setq buffer-file-number number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; On VMS, we may want to remember which directory in a search list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; the file was found in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (and (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (let (logical)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (if (string-match ":" (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq logical (substring (file-name-directory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (not (member logical find-file-not-true-dirname-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (setq buffer-file-name buffer-file-truename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (if find-file-visit-truename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (expand-file-name buffer-file-truename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; Set buffer's default directory to that of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (setq default-directory (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; Turn off backup files for certain file names. Since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; this is a permanent local, the major mode won't eliminate it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (and (not (funcall backup-enable-predicate buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (make-local-variable 'backup-inhibited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (setq backup-inhibited t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if rawfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (after-find-file error (not nowarn)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (fset 'nnheader-run-at-time 'nnheader-xmas-run-at-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (fset 'nnheader-cancel-timer 'nnheader-xmas-cancel-timer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (fset 'nnheader-find-file-noselect 'nnheader-xmas-find-file-noselect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (fset 'nnheader-insert-file-contents-literally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (if (fboundp 'insert-file-contents-literally)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 'insert-file-contents-literally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 'nnheader-xmas-insert-file-contents-literally))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (provide 'nnheaderxm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;;; nnheaderxm.el ends here.