Mercurial > hg > xemacs-beta
comparison lisp/gnus/nnheaderxm.el @ 153:25f70ba0133c r20-3b3
Import from CVS: tag r20-3b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:38:25 +0200 |
parents | 360340f9fd5f |
children |
comparison
equal
deleted
inserted
replaced
152:4c132ee2d62b | 153:25f70ba0133c |
---|---|
23 | 23 |
24 ;;; Commentary: | 24 ;;; Commentary: |
25 | 25 |
26 ;;; Code: | 26 ;;; Code: |
27 | 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) | 28 (defun nnheader-xmas-run-at-time (time repeat function &rest args) |
32 (start-itimer | 29 (start-itimer |
33 "nnheader-run-at-time" | 30 "nnheader-run-at-time" |
34 `(lambda () | 31 `(lambda () |
35 (,function ,@args)) | 32 (,function ,@args)) |
36 time repeat)) | 33 time repeat)) |
37 | 34 |
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) | 35 (fset 'nnheader-run-at-time 'nnheader-xmas-run-at-time) |
150 (fset 'nnheader-cancel-timer 'nnheader-xmas-cancel-timer) | 36 (fset 'nnheader-cancel-timer 'delete-itimer) |
151 (fset 'nnheader-cancel-function-timers 'nnheader-xmas-cancel-function-timers) | 37 (fset 'nnheader-cancel-function-timers 'ignore) |
152 (fset 'nnheader-find-file-noselect 'nnheader-xmas-find-file-noselect) | |
153 | 38 |
154 (provide 'nnheaderxm) | 39 (provide 'nnheaderxm) |
155 | 40 |
156 ;;; nnheaderxm.el ends here. | 41 ;;; nnheaderxm.el ends here. |