1 ;;; nnheaderxm.el --- making Gnus backends work under XEmacs
2 ;; Copyright (C) 1996,97 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.
29 (autoload 'nnheader-insert-file-contents "nnheader"))
31 (defun nnheader-xmas-run-at-time (time repeat function &rest args)
33 "nnheader-run-at-time"
38 (defun nnheader-xmas-cancel-timer (timer)
39 (delete-itimer timer))
41 (defun nnheader-xmas-cancel-function-timers (function)
44 (defun nnheader-xmas-find-file-noselect (filename &optional nowarn rawfile)
45 "Read file FILENAME into a buffer and return the buffer.
46 If a buffer exists visiting FILENAME, return that one, but
47 verify that the file has not changed since visited or saved.
48 The buffer is not selected, just returned to the caller."
51 (expand-file-name filename)))
52 (if (file-directory-p filename)
53 (if find-file-run-dired
54 (dired-noselect filename)
55 (error "%s is a directory." filename))
56 (let* ((buf (get-file-buffer filename))
57 (truename (abbreviate-file-name (file-truename filename)))
58 (number (nthcdr 10 (file-attributes truename)))
59 ;; Find any buffer for a file which has same truename.
61 (get-file-buffer filename)))
63 ;; Let user know if there is a buffer with the same truename.
66 (string-equal filename (buffer-file-name other))
67 (message "%s and %s are the same file"
68 filename (buffer-file-name other)))
69 ;; Optionally also find that buffer.
70 (when (or (and (boundp 'find-file-existing-other-name)
71 find-file-existing-other-name)
72 find-file-visit-truename)
76 (verify-visited-file-modtime buf)
77 (cond ((not (file-exists-p filename))
78 (error "File %s no longer exists!" filename))
80 (if (string= (file-name-nondirectory filename)
83 (if (buffer-modified-p buf)
84 "File %s changed on disk. Discard your edits? "
85 "File %s changed on disk. Reread from disk? ")
86 (file-name-nondirectory filename))
88 (if (buffer-modified-p buf)
89 "File %s changed on disk. Discard your edits in %s? "
90 "File %s changed on disk. Reread from disk into %s? ")
91 (file-name-nondirectory filename)
95 (revert-buffer t t)))))
97 ;;; The truename stuff makes this obsolete.
98 ;;; (let* ((link-name (car (file-attributes filename)))
99 ;;; (linked-buf (and (stringp link-name)
100 ;;; (get-file-buffer link-name))))
101 ;;; (if (bufferp linked-buf)
102 ;;; (message "Symbolic link to file in buffer %s"
103 ;;; (buffer-name linked-buf))))
104 (setq buf (create-file-buffer filename))
105 ;; (set-buffer-major-mode buf)
110 (nnheader-insert-file-contents filename t)
112 ;; Unconditionally set error
115 (insert-file-contents filename t)
117 ;; Run find-file-not-found-hooks until one returns non-nil.
118 (or t ; (run-hook-with-args-until-success 'find-file-not-found-hooks)
119 ;; If they fail too, set error.
121 ;; Find the file's truename, and maybe use that as visited name.
122 (setq buffer-file-truename truename)
123 (setq buffer-file-number number)
124 ;; On VMS, we may want to remember which directory in a search list
125 ;; the file was found in.
126 (and (eq system-type 'vax-vms)
128 (when (string-match ":" (file-name-directory filename))
129 (setq logical (substring (file-name-directory filename)
130 0 (match-beginning 0))))
131 (not (member logical find-file-not-true-dirname-list)))
132 (setq buffer-file-name buffer-file-truename))
133 (when find-file-visit-truename
134 (setq buffer-file-name
136 (expand-file-name buffer-file-truename))))
137 ;; Set buffer's default directory to that of the file.
138 (setq default-directory (file-name-directory filename))
139 ;; Turn off backup files for certain file names. Since
140 ;; this is a permanent local, the major mode won't eliminate it.
141 (when (not (funcall backup-enable-predicate buffer-file-name))
142 (make-local-variable 'backup-inhibited)
143 (setq backup-inhibited t))
146 (after-find-file error (not nowarn)))))
149 (fset 'nnheader-run-at-time 'nnheader-xmas-run-at-time)
150 (fset 'nnheader-cancel-timer 'nnheader-xmas-cancel-timer)
151 (fset 'nnheader-cancel-function-timers 'nnheader-xmas-cancel-function-timers)
152 (fset 'nnheader-find-file-noselect 'nnheader-xmas-find-file-noselect)
154 (provide 'nnheaderxm)
156 ;;; nnheaderxm.el ends here.