Mercurial > hg > xemacs-beta
comparison lisp/prim/files.el @ 72:b9518feda344 r20-0b31
Import from CVS: tag r20-0b31
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:03:46 +0200 |
parents | 131b0175ea99 |
children | 54cc21c15cbb |
comparison
equal
deleted
inserted
replaced
71:bae944334fa4 | 72:b9518feda344 |
---|---|
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | 14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 ;; General Public License for more details. | 16 ;; General Public License for more details. |
17 | 17 |
18 ;; You should have received a copy of the GNU General Public License | 18 ;; You should have received a copy of the GNU General Public License |
19 ;; along with XEmacs; see the file COPYING. If not, write to the | 19 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
20 ;; Free Software Foundation, 59 Temple Place - Suite 330, | 20 ;; Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA |
21 ;; Boston, MA 02111-1307, USA. | 21 ;; 02111-1307, USA. |
22 | 22 |
23 ;;; Synched up with: FSF 19.30. | 23 ;;; Synched up with: FSF 19.34 [Partial]. |
24 ;;; Warning: Merging this file is tough. Beware. | 24 ;;; Warning: Merging this file is tough. Beware. |
25 | 25 |
26 ;;; Commentary: | 26 ;;; Commentary: |
27 | 27 |
28 ;; Defines most of XEmacs's file- and directory-handling functions, | 28 ;; Defines most of XEmacs's file- and directory-handling functions, |
29 ;; including basic file visiting, backup generation, link handling, | 29 ;; including basic file visiting, backup generation, link handling, |
30 ;; ITS-id version control, load- and write-hook handling, and the like. | 30 ;; ITS-id version control, load- and write-hook handling, and the like. |
31 | 31 |
32 ;;; Code: | 32 ;;; Code: |
33 | 33 |
34 ;; Avoid compilation warnings. | 34 ;; XEmacs: Avoid compilation warnings. |
35 (defvar overriding-file-coding-system) | 35 (defvar overriding-file-coding-system) |
36 (defvar file-coding-system) | 36 (defvar file-coding-system) |
37 | 37 |
38 ;; In buffer.c | 38 ;; XEmacs: In buffer.c |
39 ;(defconst delete-auto-save-files t | 39 ;(defconst delete-auto-save-files t |
40 ; "*Non-nil means delete auto-save file when a buffer is saved or killed.") | 40 ; "*Non-nil means delete auto-save file when a buffer is saved or killed.") |
41 | |
42 ;; FSF has automount-dir-prefix. Our directory-abbrev-alist is more general. | |
43 ;; note: tmp_mnt bogosity conversion is established in paths.el. | |
44 (defvar directory-abbrev-alist nil | |
45 "*Alist of abbreviations for file directories. | |
46 A list of elements of the form (FROM . TO), each meaning to replace | |
47 FROM with TO when it appears in a directory name. | |
48 This replacement is done when setting up the default directory of a | |
49 newly visited file. *Every* FROM string should start with \\\\` or ^. | |
50 | |
51 Use this feature when you have directories which you normally refer to | |
52 via absolute symbolic links or to eliminate automounter mount points | |
53 from the beginning of your filenames. Make TO the name of the link, | |
54 and FROM the name it is linked to.") | |
41 | 55 |
42 ;;; Turn off backup files on VMS since it has version numbers. | 56 ;;; Turn off backup files on VMS since it has version numbers. |
43 (defconst make-backup-files (not (eq system-type 'vax-vms)) | 57 (defconst make-backup-files (not (eq system-type 'vax-vms)) |
44 "*Non-nil means make a backup of a file the first time it is saved. | 58 "*Non-nil means make a backup of a file the first time it is saved. |
45 This can be done by renaming the file or by copying. | 59 This can be done by renaming the file or by copying. |
94 "*Non-nil in a buffer means offer to save the buffer on exit | 108 "*Non-nil in a buffer means offer to save the buffer on exit |
95 even if the buffer is not visiting a file. | 109 even if the buffer is not visiting a file. |
96 Automatically local in all buffers.") | 110 Automatically local in all buffers.") |
97 (make-variable-buffer-local 'buffer-offer-save) | 111 (make-variable-buffer-local 'buffer-offer-save) |
98 | 112 |
113 ;; FSF uses normal defconst | |
99 (defvaralias 'find-file-visit-truename 'find-file-use-truenames) | 114 (defvaralias 'find-file-visit-truename 'find-file-use-truenames) |
100 (defvaralias 'find-file-existing-other-name 'find-file-compare-truenames) | 115 (defvaralias 'find-file-existing-other-name 'find-file-compare-truenames) |
101 | 116 |
102 (defvar buffer-file-number nil | 117 (defvar buffer-file-number nil |
103 "The device number and file number of the file visited in the current buffer. | 118 "The device number and file number of the file visited in the current buffer. |
105 This pair of numbers uniquely identifies the file. | 120 This pair of numbers uniquely identifies the file. |
106 If the buffer is visiting a new file, the value is nil.") | 121 If the buffer is visiting a new file, the value is nil.") |
107 (make-variable-buffer-local 'buffer-file-number) | 122 (make-variable-buffer-local 'buffer-file-number) |
108 (put 'buffer-file-number 'permanent-local t) | 123 (put 'buffer-file-number 'permanent-local t) |
109 | 124 |
125 (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt))) | |
126 "Non-nil means that buffer-file-number uniquely identifies files.") | |
127 | |
110 (defconst file-precious-flag nil | 128 (defconst file-precious-flag nil |
111 "*Non-nil means protect against I/O errors while saving files. | 129 "*Non-nil means protect against I/O errors while saving files. |
112 Some modes set this non-nil in particular buffers. | 130 Some modes set this non-nil in particular buffers. |
113 | 131 |
114 This feature works by writing the new contents into a temporary file | 132 This feature works by writing the new contents into a temporary file |
178 "List of functions to be called before writing out a buffer to a file. | 196 "List of functions to be called before writing out a buffer to a file. |
179 If one of them returns non-nil, the file is considered already written | 197 If one of them returns non-nil, the file is considered already written |
180 and the rest are not called. | 198 and the rest are not called. |
181 These hooks are considered to pertain to the visited file. | 199 These hooks are considered to pertain to the visited file. |
182 So this list is cleared if you change the visited file name. | 200 So this list is cleared if you change the visited file name. |
183 See also `write-contents-hooks' and `continue-save-buffer'. | 201 See also `write-contents-hooks' and `continue-save-buffer'.") |
184 Don't make this variable buffer-local; instead, use `local-write-file-hooks'.") | |
185 ;;; However, in case someone does make it local... | 202 ;;; However, in case someone does make it local... |
186 (put 'write-file-hooks 'permanent-local t) | 203 (put 'write-file-hooks 'permanent-local t) |
187 | 204 |
188 (defvar local-write-file-hooks nil | 205 (defvar local-write-file-hooks nil |
189 "Just like `write-file-hooks', except intended for per-buffer use. | 206 "Just like `write-file-hooks', except intended for per-buffer use. |
190 The functions in this list are called before the ones in | 207 The functions in this list are called before the ones in |
191 `write-file-hooks'.") | 208 `write-file-hooks'. |
209 | |
210 This variable is meant to be used for hooks that have to do with a | |
211 particular visited file. Therefore, it is a permanent local, so that | |
212 changing the major mode does not clear it. However, calling | |
213 `set-visited-file-name' does clear it.") | |
192 (make-variable-buffer-local 'local-write-file-hooks) | 214 (make-variable-buffer-local 'local-write-file-hooks) |
193 (put 'local-write-file-hooks 'permanent-local t) | 215 (put 'local-write-file-hooks 'permanent-local t) |
194 | 216 |
195 | 217 |
196 ;; #### think about this (added by Sun). | 218 ;; #### think about this (added by Sun). |
211 These hooks are considered to pertain to the buffer's contents, | 233 These hooks are considered to pertain to the buffer's contents, |
212 not to the particular visited file; thus, `set-visited-file-name' does | 234 not to the particular visited file; thus, `set-visited-file-name' does |
213 not clear this variable, but changing the major mode does clear it. | 235 not clear this variable, but changing the major mode does clear it. |
214 See also `write-file-hooks' and `continue-save-buffer'.") | 236 See also `write-file-hooks' and `continue-save-buffer'.") |
215 | 237 |
216 ;; Not in FSF19 | 238 ;; XEmacs addition |
217 ;; Energize needed this to hook into save-buffer at a lower level; we need | 239 ;; Energize needed this to hook into save-buffer at a lower level; we need |
218 ;; to provide a new output method, but don't want to have to duplicate all | 240 ;; to provide a new output method, but don't want to have to duplicate all |
219 ;; of the backup file and file modes logic.that does not occur if one uses | 241 ;; of the backup file and file modes logic.that does not occur if one uses |
220 ;; a write-file-hook which returns non-nil. | 242 ;; a write-file-hook which returns non-nil. |
221 (put 'write-file-data-hooks 'permanent-local t) | 243 (put 'write-file-data-hooks 'permanent-local t) |
245 A value of t means obey `eval' variables; | 267 A value of t means obey `eval' variables; |
246 nil means ignore them; anything else means query. | 268 nil means ignore them; anything else means query. |
247 | 269 |
248 The command \\[normal-mode] always obeys local-variables lists | 270 The command \\[normal-mode] always obeys local-variables lists |
249 and ignores this variable.") | 271 and ignores this variable.") |
250 | |
251 (defvar hack-local-variables-hook nil | |
252 "Normal hook run after processing a file's local variables specs. | |
253 Major modes can use this to examine user-specified local variables | |
254 in order to initialize other data structure based on them. | |
255 | |
256 This hook runs even if there were no local variables or if their | |
257 evaluation was suppressed. See also `enable-local-variables' and | |
258 `enable-local-eval'.") | |
259 | 272 |
260 ;; Avoid losing in versions where CLASH_DETECTION is disabled. | 273 ;; Avoid losing in versions where CLASH_DETECTION is disabled. |
261 (or (fboundp 'lock-buffer) | 274 (or (fboundp 'lock-buffer) |
262 (defalias 'lock-buffer 'ignore)) | 275 (defalias 'lock-buffer 'ignore)) |
263 (or (fboundp 'unlock-buffer) | 276 (or (fboundp 'unlock-buffer) |
298 "Character used to separate concatenated paths.") | 311 "Character used to separate concatenated paths.") |
299 | 312 |
300 (defun parse-colon-path (cd-path) | 313 (defun parse-colon-path (cd-path) |
301 "Explode a colon-separated list of paths into a string list." | 314 "Explode a colon-separated list of paths into a string list." |
302 (and cd-path | 315 (and cd-path |
303 (let (cd-list (cd-start 0) cd-colon) | 316 (let (cd-list cd-list (cd-start 0) cd-colon) |
304 (setq cd-path (concat cd-path path-separator)) | 317 (setq cd-path (concat cd-path path-separator)) |
305 (while (setq cd-colon (string-match path-separator cd-path cd-start)) | 318 (while (setq cd-colon (string-match path-separator cd-path cd-start)) |
306 (setq cd-list | 319 (setq cd-list |
307 (nconc cd-list | 320 (nconc cd-list |
308 (list (if (= cd-start cd-colon) | 321 (list (if (= cd-start cd-colon) |
333 | 346 |
334 (defun cd (dir) | 347 (defun cd (dir) |
335 "Make DIR become the current buffer's default directory. | 348 "Make DIR become the current buffer's default directory. |
336 If your environment includes a `CDPATH' variable, try each one of that | 349 If your environment includes a `CDPATH' variable, try each one of that |
337 colon-separated list of directories when resolving a relative directory name." | 350 colon-separated list of directories when resolving a relative directory name." |
338 ; (interactive "DChange default directory: ") | |
339 (interactive | 351 (interactive |
340 ;; XEmacs change? | 352 ;; XEmacs change? (read-file-name => read-directory-name) |
341 (list (read-directory-name "Change default directory: " | 353 (list (read-directory-name "Change default directory: " |
342 default-directory default-directory | 354 default-directory default-directory |
343 (and (member cd-path '(nil ("./"))) | 355 (and (member cd-path '(nil ("./"))) |
344 (null (getenv "CDPATH")))))) | 356 (null (getenv "CDPATH")))))) |
345 (if (file-name-absolute-p dir) | 357 (if (file-name-absolute-p dir) |
346 (cd-absolute (expand-file-name dir)) | 358 (cd-absolute (expand-file-name dir)) |
347 (progn | 359 ;; XEmacs |
348 (if (null cd-path) | 360 (if (null cd-path) |
349 ;;#### Unix-specific | 361 ;;#### Unix-specific |
350 (let ((trypath (parse-colon-path (getenv "CDPATH")))) | 362 (let ((trypath (parse-colon-path (getenv "CDPATH")))) |
351 (setq cd-path (or trypath (list "./"))))) | 363 (setq cd-path (or trypath (list "./"))))) |
352 (or (catch 'found | 364 (or (catch 'found |
353 (mapcar #'(lambda (x) | 365 (mapcar #'(lambda (x) |
354 (let ((f (expand-file-name (concat x dir)))) | 366 (let ((f (expand-file-name (concat x dir)))) |
355 (if (file-directory-p f) | 367 (if (file-directory-p f) |
356 (progn | 368 (progn |
357 (cd-absolute f) | 369 (cd-absolute f) |
358 (throw 'found t))))) | 370 (throw 'found t))))) |
359 cd-path) | 371 cd-path) |
360 nil) | 372 nil) |
361 ;; jwz: give a better error message to those of us with the | 373 ;; jwz: give a better error message to those of us with the |
362 ;; good taste not to use a kludge like $CDPATH. | 374 ;; good taste not to use a kludge like $CDPATH. |
363 (if (equal cd-path '("./")) | 375 (if (equal cd-path '("./")) |
364 (error "No such directory: %s" (expand-file-name dir)) | 376 (error "No such directory: %s" (expand-file-name dir)) |
365 (error "Directory not found in $CDPATH: %s" dir)))))) | 377 (error "Directory not found in $CDPATH: %s" dir))))) |
366 | 378 |
367 (defun load-file (file) | 379 (defun load-file (file) |
368 "Load the Lisp file named FILE." | 380 "Load the Lisp file named FILE." |
369 (interactive "fLoad file: ") | 381 (interactive "fLoad file: ") |
370 (load (expand-file-name file) nil nil t)) | 382 (load (expand-file-name file) nil nil t)) |
371 | 383 |
372 ; We now dump utils/lib-complete.el which has improved versions of these. | 384 ; We now dump utils/lib-complete.el which has improved versions of this. |
373 ;(defun load-library (library) | 385 ;(defun load-library (library) |
374 ; "Load the library named LIBRARY. | 386 ; "Load the library named LIBRARY. |
375 ;This is an interface to the function `load'." | 387 ;This is an interface to the function `load'." |
376 ; (interactive "sLoad library: ") | 388 ; (interactive "sLoad library: ") |
377 ; (load library)) | 389 ; (load library)) |
392 (let ((handler (find-file-name-handler file 'file-local-copy))) | 404 (let ((handler (find-file-name-handler file 'file-local-copy))) |
393 (if handler | 405 (if handler |
394 (funcall handler 'file-local-copy file) | 406 (funcall handler 'file-local-copy file) |
395 nil))) | 407 nil))) |
396 | 408 |
409 ;; XEmacs change block | |
397 ; We have this in C and use the realpath() system call. | 410 ; We have this in C and use the realpath() system call. |
398 | 411 |
399 ;(defun file-truename (filename &optional counter prev-dirs) | 412 ;(defun file-truename (filename &optional counter prev-dirs) |
400 ; "Return the truename of FILENAME, which should be absolute. | 413 ; "Return the truename of FILENAME, which should be absolute. |
401 ;The truename of a file name is found by chasing symbolic links | 414 ;The truename of a file name is found by chasing symbolic links |
501 dir))))) | 514 dir))))) |
502 (if (and find-file-use-truenames buffer-file-truename) | 515 (if (and find-file-use-truenames buffer-file-truename) |
503 (setq buffer-file-name (abbreviate-file-name buffer-file-truename) | 516 (setq buffer-file-name (abbreviate-file-name buffer-file-truename) |
504 default-directory (file-name-directory buffer-file-name))) | 517 default-directory (file-name-directory buffer-file-name))) |
505 buffer-file-truename)) | 518 buffer-file-truename)) |
519 ;; End XEmacs change block | |
506 | 520 |
507 (defun file-chase-links (filename) | 521 (defun file-chase-links (filename) |
508 "Chase links in FILENAME until a name that is not a link. | 522 "Chase links in FILENAME until a name that is not a link. |
509 Does not examine containing directories for links, | 523 Does not examine containing directories for links, |
510 unlike `file-truename'." | 524 unlike `file-truename'." |
742 | 756 |
743 (defun generate-new-buffer (name) | 757 (defun generate-new-buffer (name) |
744 "Create and return a buffer with a name based on NAME. | 758 "Create and return a buffer with a name based on NAME. |
745 Choose the buffer's name using `generate-new-buffer-name'." | 759 Choose the buffer's name using `generate-new-buffer-name'." |
746 (get-buffer-create (generate-new-buffer-name name))) | 760 (get-buffer-create (generate-new-buffer-name name))) |
747 | |
748 ;; FSF has automount-dir-prefix. Our directory-abbrev-alist is more general. | |
749 ;; note: tmp_mnt bogosity conversion is established in paths.el. | |
750 (defvar directory-abbrev-alist nil | |
751 "*Alist of abbreviations for file directories. | |
752 A list of elements of the form (FROM . TO), each meaning to replace | |
753 FROM with TO when it appears in a directory name. | |
754 This replacement is done when setting up the default directory of a | |
755 newly visited file. *Every* FROM string should start with \\\\` or ^. | |
756 | |
757 Use this feature when you have directories which you normally refer to | |
758 via absolute symbolic links or to eliminate automounter mount points | |
759 from the beginning of your filenames. Make TO the name of the link, | |
760 and FROM the name it is linked to.") | |
761 | 761 |
762 (defvar abbreviated-home-dir nil | 762 (defvar abbreviated-home-dir nil |
763 "The user's homedir abbreviated according to `directory-abbrev-alist'.") | 763 "The user's homedir abbreviated according to `directory-abbrev-alist'.") |
764 | 764 |
765 (defun abbreviate-file-name (filename &optional hack-homedir) | 765 (defun abbreviate-file-name (filename &optional hack-homedir) |
1254 (setq alist nil)) | 1254 (setq alist nil)) |
1255 (setq alist (cdr alist)))))) | 1255 (setq alist (cdr alist)))))) |
1256 (if mode | 1256 (if mode |
1257 (funcall mode)) | 1257 (funcall mode)) |
1258 )))))) | 1258 )))))) |
1259 | |
1260 (defvar hack-local-variables-hook nil | |
1261 "Normal hook run after processing a file's local variables specs. | |
1262 Major modes can use this to examine user-specified local variables | |
1263 in order to initialize other data structure based on them. | |
1264 | |
1265 This hook runs even if there were no local variables or if their | |
1266 evaluation was suppressed. See also `enable-local-variables' and | |
1267 `enable-local-eval'.") | |
1259 | 1268 |
1260 (defun hack-local-variables (&optional force) | 1269 (defun hack-local-variables (&optional force) |
1261 "Parse, and bind or evaluate as appropriate, any local variables | 1270 "Parse, and bind or evaluate as appropriate, any local variables |
1262 for current buffer." | 1271 for current buffer." |
1263 ;; Don't look for -*- if this file name matches any | 1272 ;; Don't look for -*- if this file name matches any |
2905 (if (> count 0) | 2914 (if (> count 0) |
2906 filename | 2915 filename |
2907 (error "Apparently circular symlink path")))) | 2916 (error "Apparently circular symlink path")))) |
2908 | 2917 |
2909 ;;; files.el ends here | 2918 ;;; files.el ends here |
2910 | |
2911 | |
2912 |