1 ;;; nnheaderems.el --- making Gnus backends work under different Emacsen
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (defun nnheader-xmas-run-at-time (time repeat function
&rest args
)
30 "nnheader-run-at-time"
35 (defun nnheader-xmas-cancel-timer (timer)
36 (delete-itimer timer
))
38 ;; Written by Erik Naggum <erik@naggum.no>.
39 ;; Saved by Steve Baur <steve@miranova.com>.
40 (defun nnheader-xmas-insert-file-contents-literally (filename &optional visit beg end replace
)
41 "Like `insert-file-contents', q.v., but only reads in the file.
42 A buffer may be modified in several ways after reading into the buffer due
43 to advanced Emacs features, such as file-name-handlers, format decoding,
45 This function ensures that none of these modifications will take place."
46 (let ( ; (file-name-handler-alist nil)
48 (after-insert-file-functions nil
)
49 (find-buffer-file-type-function
50 (if (fboundp 'find-buffer-file-type
)
51 (symbol-function 'find-buffer-file-type
)
55 (fset 'find-buffer-file-type
(lambda (filename) t
))
56 (insert-file-contents filename visit beg end replace
))
57 (if find-buffer-file-type-function
58 (fset 'find-buffer-file-type find-buffer-file-type-function
)
59 (fmakunbound 'find-buffer-file-type
)))))
61 (defun nnheader-xmas-find-file-noselect (filename &optional nowarn rawfile
)
62 "Read file FILENAME into a buffer and return the buffer.
63 If a buffer exists visiting FILENAME, return that one, but
64 verify that the file has not changed since visited or saved.
65 The buffer is not selected, just returned to the caller."
68 (expand-file-name filename
)))
69 (if (file-directory-p filename
)
70 (if find-file-run-dired
71 (dired-noselect filename
)
72 (error "%s is a directory." filename
))
73 (let* ((buf (get-file-buffer filename
))
74 (truename (abbreviate-file-name (file-truename filename
)))
75 (number (nthcdr 10 (file-attributes truename
)))
76 ;; Find any buffer for a file which has same truename.
78 (if (fboundp 'find-buffer-visiting
)
79 (find-buffer-visiting filename
)
80 (get-file-buffer filename
))))
82 ;; Let user know if there is a buffer with the same truename.
86 (string-equal filename
(buffer-file-name other
))
87 (message "%s and %s are the same file"
88 filename
(buffer-file-name other
)))
89 ;; Optionally also find that buffer.
90 (if (or (and (boundp 'find-file-existing-other-name
)
91 find-file-existing-other-name
)
92 find-file-visit-truename
)
96 (verify-visited-file-modtime buf
)
97 (cond ((not (file-exists-p filename
))
98 (error "File %s no longer exists!" filename
))
100 (if (string= (file-name-nondirectory filename
)
103 (if (buffer-modified-p buf
)
104 "File %s changed on disk. Discard your edits? "
105 "File %s changed on disk. Reread from disk? ")
106 (file-name-nondirectory filename
))
108 (if (buffer-modified-p buf
)
109 "File %s changed on disk. Discard your edits in %s? "
110 "File %s changed on disk. Reread from disk into %s? ")
111 (file-name-nondirectory filename
)
115 (revert-buffer t t
)))))
117 ;;; The truename stuff makes this obsolete.
118 ;;; (let* ((link-name (car (file-attributes filename)))
119 ;;; (linked-buf (and (stringp link-name)
120 ;;; (get-file-buffer link-name))))
121 ;;; (if (bufferp linked-buf)
122 ;;; (message "Symbolic link to file in buffer %s"
123 ;;; (buffer-name linked-buf))))
124 (setq buf
(create-file-buffer filename
))
125 ;; (set-buffer-major-mode buf)
130 (nnheader-insert-file-contents-literally filename t
)
132 ;; Unconditionally set error
135 (insert-file-contents filename t
)
137 ;; Run find-file-not-found-hooks until one returns non-nil.
138 (or t
; (run-hook-with-args-until-success 'find-file-not-found-hooks)
139 ;; If they fail too, set error.
141 ;; Find the file's truename, and maybe use that as visited name.
142 (setq buffer-file-truename truename
)
143 (setq buffer-file-number number
)
144 ;; On VMS, we may want to remember which directory in a search list
145 ;; the file was found in.
146 (and (eq system-type
'vax-vms
)
148 (if (string-match ":" (file-name-directory filename
))
149 (setq logical
(substring (file-name-directory filename
)
150 0 (match-beginning 0))))
151 (not (member logical find-file-not-true-dirname-list
)))
152 (setq buffer-file-name buffer-file-truename
))
153 (if find-file-visit-truename
154 (setq buffer-file-name
156 (expand-file-name buffer-file-truename
))))
157 ;; Set buffer's default directory to that of the file.
158 (setq default-directory
(file-name-directory filename
))
159 ;; Turn off backup files for certain file names. Since
160 ;; this is a permanent local, the major mode won't eliminate it.
161 (and (not (funcall backup-enable-predicate buffer-file-name
))
163 (make-local-variable 'backup-inhibited
)
164 (setq backup-inhibited t
)))
167 (after-find-file error
(not nowarn
)))))
170 (defun nnheader-ms-strip-cr ()
171 "Strip ^M from the end of all lines."
173 (goto-char (point-min))
174 (while (re-search-forward "\r$" nil t
)
175 (delete-backward-char 1))))
179 ;; Do XEmacs function bindings.
180 ((string-match "XEmacs\\|Lucid" emacs-version
)
181 (fset 'nnheader-run-at-time
'nnheader-xmas-run-at-time
)
182 (fset 'nnheader-cancel-timer
'nnheader-xmas-cancel-timer
)
183 (fset 'nnheader-find-file-noselect
'nnheader-xmas-find-file-noselect
)
184 (fset 'nnheader-insert-file-contents-literally
185 (if (fboundp 'insert-file-contents-literally
)
186 'insert-file-contents-literally
187 'nnheader-xmas-insert-file-contents-literally
)))
188 ;; Do Emacs function bindings.
190 (fset 'nnheader-run-at-time
'run-at-time
)
191 (fset 'nnheader-cancel-timer
'cancel-timer
)
192 (fset 'nnheader-find-file-noselect
'find-file-noselect
)
193 (fset 'nnheader-insert-file-contents-literally
194 'insert-file-contents-literally
)
196 (when (memq system-type
'(windows-nt))
197 (add-hook 'nnmail-prepare-incoming-hook
'nnheader-ms-strip-cr
)))
199 (provide 'nnheaderems
)
201 ;;; nnheaderems.el ends here.