Commit | Line | Data |
---|---|---|
eec82323 LMI |
1 | ;;; nnheaderxm.el --- making Gnus backends work under XEmacs |
2 | ;; Copyright (C) 1996,97 Free Software Foundation, Inc. | |
3 | ||
4 | ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 | ;; Keywords: news | |
6 | ||
7 | ;; This file is part of GNU Emacs. | |
8 | ||
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) | |
12 | ;; any later version. | |
13 | ||
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. | |
18 | ||
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. | |
23 | ||
24 | ;;; Commentary: | |
25 | ||
26 | ;;; Code: | |
27 | ||
28 | (eval-and-compile | |
29 | (autoload 'nnheader-insert-file-contents "nnheader")) | |
30 | ||
31 | (defun nnheader-xmas-run-at-time (time repeat function &rest args) | |
32 | (start-itimer | |
33 | "nnheader-run-at-time" | |
34 | `(lambda () | |
35 | (,function ,@args)) | |
36 | time repeat)) | |
37 | ||
38 | (defun nnheader-xmas-cancel-timer (timer) | |
39 | (delete-itimer timer)) | |
40 | ||
41 | (defun nnheader-xmas-cancel-function-timers (function) | |
42 | ) | |
43 | ||
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." | |
49 | (setq filename | |
50 | (abbreviate-file-name | |
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. | |
60 | (other (and (not buf) | |
61 | (get-file-buffer filename))) | |
62 | error) | |
63 | ;; Let user know if there is a buffer with the same truename. | |
64 | (when other | |
65 | (or nowarn | |
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) | |
73 | (setq buf other))) | |
74 | (if buf | |
75 | (or nowarn | |
76 | (verify-visited-file-modtime buf) | |
77 | (cond ((not (file-exists-p filename)) | |
78 | (error "File %s no longer exists!" filename)) | |
79 | ((yes-or-no-p | |
80 | (if (string= (file-name-nondirectory filename) | |
81 | (buffer-name buf)) | |
82 | (format | |
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)) | |
87 | (format | |
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) | |
92 | (buffer-name buf)))) | |
93 | (save-excursion | |
94 | (set-buffer buf) | |
95 | (revert-buffer t t))))) | |
96 | (save-excursion | |
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) | |
106 | (set-buffer buf) | |
107 | (erase-buffer) | |
108 | (if rawfile | |
109 | (condition-case () | |
110 | (nnheader-insert-file-contents filename t) | |
111 | (file-error | |
112 | ;; Unconditionally set error | |
113 | (setq error t))) | |
114 | (condition-case () | |
115 | (insert-file-contents filename t) | |
116 | (file-error | |
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. | |
120 | (setq error t))))) | |
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) | |
127 | (let (logical) | |
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 | |
135 | (setq filename | |
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)) | |
144 | (if rawfile | |
145 | nil | |
146 | (after-find-file error (not nowarn))))) | |
147 | buf))) | |
148 | ||
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) | |
153 | ||
154 | (provide 'nnheaderxm) | |
155 | ||
156 | ;;; nnheaderxm.el ends here. |