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