1 ;;; files.el --- file input and output commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
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
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;; Defines most of Emacs's file- and directory-handling functions,
26 ;; including basic file visiting, backup generation, link handling,
27 ;; ITS-id version control, load- and write-hook handling, and the like.
31 (defconst delete-auto-save-files t
32 "*Non-nil means delete a buffer's auto-save file when the buffer is saved.")
34 (defconst directory-abbrev-alist
36 "*Alist of abbreviations for file directories.
37 A list of elements of the form (FROM . TO), each meaning to replace
38 FROM with TO when it appears in a directory name. This replacement is
39 done when setting up the default directory of a newly visited file.
40 *Every* FROM string should start with `^'.
42 Use this feature when you have directories which you normally refer to
43 via absolute symbolic links. Make TO the name of the link, and FROM
44 the name it is linked to.")
46 ;;; Turn off backup files on VMS since it has version numbers.
47 (defconst make-backup-files
(not (eq system-type
'vax-vms
))
48 "*Create a backup of each file when it is saved for the first time.
49 This can be done by renaming the file or by copying.
51 Renaming means that Emacs renames the existing file so that it is a
52 backup file, then writes the buffer into a new file. Any other names
53 that the old file had will now refer to the backup file. The new file
54 is owned by you and its group is defaulted.
56 Copying means that Emacs copies the existing file into the backup
57 file, then writes the buffer on top of the existing file. Any other
58 names that the old file had will now refer to the new (edited) file.
59 The file's owner and group are unchanged.
61 The choice of renaming or copying is controlled by the variables
62 `backup-by-copying', `backup-by-copying-when-linked' and
63 `backup-by-copying-when-mismatch'.")
65 ;; Do this so that local variables based on the file name
66 ;; are not overridden by the major mode.
67 (defvar backup-inhibited nil
68 "Non-nil means don't make a backup file for this buffer.")
69 (put 'backup-inhibited
'permanent-local t
)
71 (defconst backup-by-copying nil
72 "*Non-nil means always use copying to create backup files.
73 See documentation of variable `make-backup-files'.")
75 (defconst backup-by-copying-when-linked nil
76 "*Non-nil means use copying to create backups for files with multiple names.
77 This causes the alternate names to refer to the latest version as edited.
78 This variable is relevant only if `backup-by-copying' is nil.")
80 (defconst backup-by-copying-when-mismatch nil
81 "*Non-nil means create backups by copying if this preserves owner or group.
82 Renaming may still be used (subject to control of other variables)
83 when it would not result in changing the owner or group of the file;
84 that is, for files which are owned by you and whose group matches
85 the default for a new file created there by you.
86 This variable is relevant only if `backup-by-copying' is nil.")
88 (defvar backup-enable-predicate
90 (or (< (length name
) 5)
91 (not (string-equal "/tmp/" (substring name
0 5)))))
92 "Predicate that looks at a file name and decides whether to make backups.
93 Called with an absolute file name as argument, it returns t to enable backup.")
95 (defconst buffer-offer-save nil
96 "*Non-nil in a buffer means offer to save the buffer on exit
97 even if the buffer is not visiting a file.
98 Automatically local in all buffers.")
99 (make-variable-buffer-local 'buffer-offer-save
)
101 (defconst find-file-existing-other-name nil
102 "*Non-nil means find a file under alternative names, in existing buffers.
103 This means if any existing buffer is visiting the file you want
104 under another name, you get the existing buffer instead of a new buffer.")
106 (defconst find-file-visit-truename nil
107 "*Non-nil means visit a file under its truename.
108 The truename of a file is found by chasing all links
109 both at the file level and at the levels of the containing directories.")
111 (defvar buffer-file-truename nil
112 "The truename of the file visited in the current buffer.
113 This variable is automatically local in all buffers, when non-nil.")
114 (make-variable-buffer-local 'buffer-file-truename
)
115 (put 'buffer-file-truename
'permanent-local t
)
117 (defvar buffer-file-number nil
118 "The device number and file number of the file visited in the current buffer.
119 The value is a list of the form (FILENUM DEVNUM).
120 This pair of numbers uniquely identifies the file.
121 If the buffer is visiting a new file, the value is nil.")
122 (make-variable-buffer-local 'buffer-file-number
)
123 (put 'buffer-file-number
'permanent-local t
)
125 (defconst file-precious-flag nil
126 "*Non-nil means protect against I/O errors while saving files.
127 Some modes set this non-nil in particular buffers.")
129 (defvar version-control nil
130 "*Control use of version numbers for backup files.
131 t means make numeric backup versions unconditionally.
132 nil means make them for files that have some already.
133 never means do not make them.")
135 (defvar dired-kept-versions
2
136 "*When cleaning directory, number of versions to keep.")
138 (defvar trim-versions-without-asking nil
139 "*If t, deletes excess backup versions silently.
140 If nil, asks confirmation. Any other value prevents any trimming.")
142 (defvar kept-old-versions
2
143 "*Number of oldest versions to keep when a new numbered backup is made.")
145 (defvar kept-new-versions
2
146 "*Number of newest versions to keep when a new numbered backup is made.
147 Includes the new backup. Must be > 0")
149 (defconst require-final-newline nil
150 "*Value of t says silently ensure a file ends in a newline when it is saved.
151 Non-nil but not t says ask user whether to add a newline when there isn't one.
152 nil means don't add newlines.")
154 (defconst auto-save-default t
155 "*Non-nil says by default do auto-saving of every file-visiting buffer.")
157 (defconst auto-save-visited-file-name nil
158 "*Non-nil says auto-save a buffer in the file it is visiting, when practical.
159 Normally auto-save files are written under other names.")
161 (defconst save-abbrevs nil
162 "*Non-nil means save word abbrevs too when files are saved.
163 Loading an abbrev file sets this to t.")
165 (defconst find-file-run-dired t
166 "*Non-nil says run dired if `find-file' is given the name of a directory.")
168 ;;;It is not useful to make this a local variable.
169 ;;;(put 'find-file-not-found-hooks 'permanent-local t)
170 (defvar find-file-not-found-hooks nil
171 "List of functions to be called for `find-file' on nonexistent file.
172 These functions are called as soon as the error is detected.
173 `buffer-file-name' is already set up.
174 The functions are called in the order given until one of them returns non-nil.")
176 ;;;It is not useful to make this a local variable.
177 ;;;(put 'find-file-hooks 'permanent-local t)
178 (defvar find-file-hooks nil
179 "List of functions to be called after a buffer is loaded from a file.
180 The buffer's local variables (if any) will have been processed before the
181 functions are called.")
183 ;;; In case someone does make it local.
184 (put 'write-file-hooks
'permanent-local t
)
185 (defvar write-file-hooks nil
186 "List of functions to be called before writing out a buffer to a file.
187 If one of them returns non-nil, the file is considered already written
188 and the rest are not called.
189 These hooks are considered to pertain to the visited file.
190 So this list is cleared if you change the visited file name.
191 See also `write-contents-hooks'.
192 Don't make this variable buffer-local; instead, use `local-write-file-hooks'.")
194 (put 'local-write-file-hooks
'permanent-local t
)
195 (defvar local-write-file-hooks nil
196 "Just like `write-file-hooks', except intended for per-buffer use.
197 The functions in this list are called before the ones in
198 `write-file-hooks'.")
200 (defvar write-contents-hooks nil
201 "List of functions to be called before writing out a buffer to a file.
202 If one of them returns non-nil, the file is considered already written
203 and the rest are not called.
204 These hooks are considered to pertain to the buffer's contents,
205 not to the particular visited file; thus, `set-visited-file-name' does
206 not clear this variable, but changing the major mode does clear it.
207 See also `write-file-hooks'.")
209 (defconst enable-local-variables t
210 "*Control use of local-variables lists in files you visit.
211 The value can be t, nil or something else.
212 A value of t means local-variables lists are obeyed;
213 nil means they are ignored; anything else means query.
215 The command \\[normal-mode] always obeys local-variables lists
216 and ignores this variable.")
218 (defconst enable-local-eval
'maybe
219 "*Control processing of the \"variable\" `eval' in a file's local variables.
220 The value can be t, nil or something else.
221 A value of t means obey `eval' variables;
222 nil means ignore them; anything else means query.
224 The command \\[normal-mode] always obeys local-variables lists
225 and ignores this variable.")
227 ;; Avoid losing in versions where CLASH_DETECTION is disabled.
228 (or (fboundp 'lock-buffer
)
229 (defalias 'lock-buffer
'ignore
))
230 (or (fboundp 'unlock-buffer
)
231 (defalias 'unlock-buffer
'ignore
))
234 "Show the current default directory."
236 (message "Directory %s" default-directory
))
239 "Value of the CDPATH environment variable, as a list.
240 Not actually set up until the first time you you use it.")
242 (defun parse-colon-path (cd-path)
243 "Explode a colon-separated list of paths into a string list."
245 (let (cd-prefix cd-list
(cd-start 0) cd-colon
)
246 (setq cd-path
(concat cd-path
":"))
247 (while (setq cd-colon
(string-match ":" cd-path cd-start
))
250 (list (substitute-in-file-name
251 (file-name-as-directory
252 (substring cd-path cd-start cd-colon
))))))
253 (setq cd-start
(+ cd-colon
1)))
256 (defun cd-absolute (dir)
257 "Change current directory to given absolute path DIR."
258 (interactive "DChange default directory: ")
259 (setq dir
(expand-file-name dir
))
260 (if (not (eq system-type
'vax-vms
))
261 (setq dir
(file-name-as-directory dir
)))
262 (if (not (file-directory-p dir
))
263 (error "%s is not a directory" dir
)
264 (if (file-executable-p dir
)
265 (setq default-directory dir
)
266 (error "Cannot cd to %s: Permission denied" dir
))))
269 "Make DIR become the current buffer's default directory.
270 If your environment imcludes a $CDPATH variable, cd tries each one of that
271 colon-separated list of directories when resolving a relative cd."
272 (interactive "FChange default directory: ")
273 (let ((first (aref dir
0)))
274 (if (or (= first ?
/) (= first ?~
))
275 (cd-absolute (expand-file-name dir
))
277 (let ((trypath (parse-colon-path (getenv "CDPATH"))))
278 (setq cd-path
(or trypath
(list "./")))))
279 (if (not (catch 'found
281 (function (lambda (x)
282 (let ((f (expand-file-name (concat x dir
))))
283 (if (file-directory-p f
)
286 (throw 'found t
))))))
289 (error "No such directory on your cd path.")))
292 (defun load-file (file)
293 "Load the Lisp file named FILE."
294 (interactive "fLoad file: ")
295 (load (expand-file-name file
) nil nil t
))
297 (defun load-library (library)
298 "Load the library named LIBRARY.
299 This is an interface to the function `load'."
300 (interactive "sLoad library: ")
303 ;; OTHER is the other file to be compared.
304 (defun file-local-copy (file)
305 "Copy the file FILE into a temporary file on this machine.
306 Returns the name of the local copy, or nil, if FILE is directly
308 (let ((handler (find-file-name-handler file
)))
310 (funcall handler
'file-local-copy file
)
313 (defun file-truename (filename)
314 "Return the truename of FILENAME, which should be absolute.
315 The truename of a file name is found by chasing symbolic links
316 both at the level of the file and at the level of the directories
317 containing it, until no links are left at any level."
318 (if (string= filename
"~")
320 (setq filename
(expand-file-name filename
))
321 (if (string= filename
"")
322 (setq filename
"/"))))
323 (let ((handler (find-file-name-handler filename
)))
324 ;; For file name that has a special handler, call handler.
325 ;; This is so that ange-ftp can save time by doing a no-op.
327 (funcall handler
'file-truename filename
)
328 (let ((dir (file-name-directory filename
))
330 ;; Get the truename of the directory.
331 (setq dirfile
(directory-file-name dir
))
332 ;; If these are equal, we have the (or a) root directory.
333 (or (string= dir dirfile
)
334 (setq dir
(file-name-as-directory (file-truename dirfile
))))
335 ;; Put it back on the file name.
336 (setq filename
(concat dir
(file-name-nondirectory filename
)))
337 ;; Is the file name the name of a link?
338 (setq target
(file-symlink-p filename
))
340 ;; Yes => chase that link, then start all over
341 ;; since the link may point to a directory name that uses links.
342 (file-truename (expand-file-name target dir
))
346 (defun file-chase-links (filename)
347 "Chase links in FILENAME until a name that is not a link.
348 Does not examine containing directories for links,
349 unlike `file-truename'."
350 (let (tem (count 100) (newname filename
))
351 (while (setq tem
(file-symlink-p newname
))
353 (error "Apparent cycle of symbolic links for %s" filename
))
354 ;; Handle `..' by hand, since it needs to work in the
355 ;; target of any directory symlink.
356 ;; This code is not quite complete; it does not handle
357 ;; embedded .. in some cases such as ./../foo and foo/bar/../../../lose.
358 (while (string-match "\\.\\./" tem
)
359 (setq tem
(substring tem
3))
360 (setq newname
(file-name-as-directory
361 ;; Do the .. by hand.
364 ;; Chase links in the default dir of the symlink.
367 (file-name-directory newname
))))))))
368 (setq newname
(expand-file-name tem
(file-name-directory newname
)))
369 (setq count
(1- count
)))
372 (defun switch-to-buffer-other-window (buffer)
373 "Select buffer BUFFER in another window."
374 (interactive "BSwitch to buffer in other window: ")
375 (let ((pop-up-windows t
))
376 (pop-to-buffer buffer t
)))
378 (defun switch-to-buffer-other-frame (buffer)
379 "Switch to buffer BUFFER in another frame."
380 (interactive "BSwitch to buffer in other frame: ")
381 (let ((pop-up-frames t
))
382 (pop-to-buffer buffer t
)))
384 (defun find-file (filename)
386 Switch to a buffer visiting file FILENAME,
387 creating one if none already exists."
388 (interactive "FFind file: ")
389 (switch-to-buffer (find-file-noselect filename
)))
391 (defun find-file-other-window (filename)
392 "Edit file FILENAME, in another window.
393 May create a new window, or reuse an existing one.
394 See the function `display-buffer'."
395 (interactive "FFind file in other window: ")
396 (switch-to-buffer-other-window (find-file-noselect filename
)))
398 (defun find-file-other-frame (filename)
399 "Edit file FILENAME, in another frame.
400 May create a new frame, or reuse an existing one.
401 See the function `display-buffer'."
402 (interactive "FFind file in other frame: ")
403 (switch-to-buffer-other-frame (find-file-noselect filename
)))
405 (defun find-file-read-only (filename)
406 "Edit file FILENAME but don't allow changes.
407 Like \\[find-file] but marks buffer as read-only.
408 Use \\[toggle-read-only] to permit editing."
409 (interactive "fFind file read-only: ")
411 (setq buffer-read-only t
)
414 (defun find-file-read-only-other-window (filename)
415 "Edit file FILENAME in another window but don't allow changes.
416 Like \\[find-file-other-window] but marks buffer as read-only.
417 Use \\[toggle-read-only] to permit editing."
418 (interactive "fFind file read-only other window: ")
419 (find-file-other-window filename
)
420 (setq buffer-read-only t
)
423 (defun find-file-read-only-other-frame (filename)
424 "Edit file FILENAME in another frame but don't allow changes.
425 Like \\[find-file-other-frame] but marks buffer as read-only.
426 Use \\[toggle-read-only] to permit editing."
427 (interactive "fFind file read-only other frame: ")
428 (find-file-other-frame filename
)
429 (setq buffer-read-only t
)
432 (defun find-alternate-file (filename)
433 "Find file FILENAME, select its buffer, kill previous buffer.
434 If the current buffer now contains an empty file that you just visited
435 \(presumably by mistake), use this command to visit the file you really want."
437 (let ((file buffer-file-name
)
441 (setq file-name
(file-name-nondirectory file
)
442 file-dir
(file-name-directory file
)))
443 (list (read-file-name
444 "Find alternate file: " file-dir nil nil file-name
))))
445 (and (buffer-modified-p)
446 ;; (not buffer-read-only)
447 (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
450 (let ((obuf (current-buffer))
451 (ofile buffer-file-name
)
452 (onum buffer-file-number
)
453 (otrue buffer-file-truename
)
454 (oname (buffer-name)))
455 (rename-buffer " **lose**")
456 (setq buffer-file-name nil
)
457 (setq buffer-file-number nil
)
458 (setq buffer-file-truename nil
)
462 (find-file filename
))
463 (cond ((eq obuf
(current-buffer))
464 (setq buffer-file-name ofile
)
465 (setq buffer-file-number onum
)
466 (setq buffer-file-truename otrue
)
468 (rename-buffer oname
))))
469 (or (eq (current-buffer) obuf
)
470 (kill-buffer obuf
))))
472 (defun create-file-buffer (filename)
473 "Create a suitably named buffer for visiting FILENAME, and return it.
474 FILENAME (sans directory) is used unchanged if that name is free;
475 otherwise a string <2> or <3> or ... is appended to get an unused name."
476 (let ((lastname (file-name-nondirectory filename
)))
477 (if (string= lastname
"")
478 (setq lastname filename
))
479 (generate-new-buffer lastname
)))
481 (defun generate-new-buffer (name)
482 "Create and return a buffer with a name based on NAME.
483 Choose the buffer's name using `generate-new-buffer-name'."
484 (get-buffer-create (generate-new-buffer-name name
)))
486 (defconst automount-dir-prefix
"^/tmp_mnt/"
487 "Regexp to match the automounter prefix in a directory name.")
489 (defvar abbreviated-home-dir nil
490 "The the user's homedir abbreviated according to `directory-abbrev-list'.")
492 (defun abbreviate-file-name (filename)
493 "Return a version of FILENAME shortened using `directory-abbrev-alist'.
494 This also substitutes \"~\" for the user's home directory.
495 Type \\[describe-variable] directory-abbrev-alist RET for more information."
496 ;; Get rid of the prefixes added by the automounter.
497 (if (and (string-match automount-dir-prefix filename
)
498 (file-exists-p (file-name-directory
499 (substring filename
(1- (match-end 0))))))
500 (setq filename
(substring filename
(1- (match-end 0)))))
501 (let ((tail directory-abbrev-alist
))
502 ;; If any elt of directory-abbrev-alist matches this name,
503 ;; abbreviate accordingly.
505 (if (string-match (car (car tail
)) filename
)
507 (concat (cdr (car tail
)) (substring filename
(match-end 0)))))
508 (setq tail
(cdr tail
)))
509 ;; Compute and save the abbreviated homedir name.
510 ;; We defer computing this until the first time it's needed, to
511 ;; give time for directory-abbrev-alist to be set properly.
512 (or abbreviated-home-dir
513 (setq abbreviated-home-dir
514 (let ((abbreviated-home-dir "$foo"))
515 (concat "^" (abbreviate-file-name (expand-file-name "~"))))))
516 ;; If FILENAME starts with the abbreviated homedir,
517 ;; make it start with `~' instead.
518 (if (string-match abbreviated-home-dir filename
)
521 ;; If abbreviated-home-dir ends with a slash,
522 ;; don't remove the corresponding slash from
523 ;; filename. On MS-DOS and OS/2, you can have
524 ;; home directories like "g:/", in which it is
525 ;; important not to remove the slash. And what
526 ;; about poor root on Unix systems?
527 (if (eq ?
/ (aref abbreviated-home-dir
528 (1- (length abbreviated-home-dir
))))
531 (substring filename
(match-end 0)))))
534 (defvar find-file-not-true-dirname-list nil
535 "*List of logical names for which visiting shouldn't save the true dirname.
536 On VMS, when you visit a file using a logical name that searches a path,
537 you may or may not want the visited file name to record the specific
538 directory where the file was found. If you *do not* want that, add the logical
539 name to this list as a string.")
541 (defun find-file-noselect (filename &optional nowarn
)
542 "Read file FILENAME into a buffer and return the buffer.
543 If a buffer exists visiting FILENAME, return that one, but
544 verify that the file has not changed since visited or saved.
545 The buffer is not selected, just returned to the caller."
547 (abbreviate-file-name
548 (expand-file-name filename
)))
549 (if (file-directory-p filename
)
550 (if find-file-run-dired
551 (dired-noselect filename
)
552 (error "%s is a directory." filename
))
553 (let* ((buf (get-file-buffer filename
))
554 (truename (abbreviate-file-name (file-truename filename
)))
555 (number (nthcdr 10 (file-attributes truename
)))
556 ;; Find any buffer for a file which has same truename.
560 (list (buffer-list)))
561 (while (and (not found
) list
)
563 (set-buffer (car list
))
564 (if (and buffer-file-name
565 (string= buffer-file-truename truename
))
566 (setq found
(car list
))))
567 (setq list
(cdr list
)))
573 (list (buffer-list)))
574 (while (and (not found
) list
)
576 (set-buffer (car list
))
577 (if (and (equal buffer-file-number number
)
578 ;; Verify this buffer's file number
579 ;; still belongs to its file.
580 (file-exists-p buffer-file-name
)
581 (equal (nthcdr 10 (file-attributes buffer-file-name
)) number
))
582 (setq found
(car list
))))
583 (setq list
(cdr list
)))
586 ;; Let user know if there is a buffer with the same truename.
587 (if (and (not buf
) same-truename
(not nowarn
))
588 (message "%s and %s are the same file (%s)"
589 filename
(buffer-file-name same-truename
)
591 (if (and (not buf
) same-number
(not nowarn
))
592 (message "%s and %s are the same file"
593 filename
(buffer-file-name same-number
))))
595 ;; Optionally also find that buffer.
596 (if (or find-file-existing-other-name find-file-visit-truename
)
597 (setq buf
(or same-truename same-number
)))
600 (verify-visited-file-modtime buf
)
601 (cond ((not (file-exists-p filename
))
602 (error "File %s no longer exists!" filename
))
605 (if (buffer-modified-p buf
)
606 "File %s changed on disk. Discard your edits? "
607 "File %s changed on disk. Read the new version? ")
608 (file-name-nondirectory filename
)))
611 (revert-buffer t t
)))))
613 ;;; The truename stuff makes this obsolete.
614 ;;; (let* ((link-name (car (file-attributes filename)))
615 ;;; (linked-buf (and (stringp link-name)
616 ;;; (get-file-buffer link-name))))
617 ;;; (if (bufferp linked-buf)
618 ;;; (message "Symbolic link to file in buffer %s"
619 ;;; (buffer-name linked-buf))))
620 (setq buf
(create-file-buffer filename
))
624 (insert-file-contents filename t
)
627 ;; Run find-file-not-found-hooks until one returns non-nil.
628 (let ((hooks find-file-not-found-hooks
))
630 (not (funcall (car hooks
))))
631 (setq hooks
(cdr hooks
))))))
632 ;; Find the file's truename, and maybe use that as visited name.
633 (setq buffer-file-truename
(abbreviate-file-name truename
))
634 (setq buffer-file-number number
)
635 ;; On VMS, we may want to remember which directory in a search list
636 ;; the file was found in.
637 (and (eq system-type
'vax-vms
)
639 (if (string-match ":" (file-name-directory filename
))
640 (setq logical
(substring (file-name-directory filename
)
641 0 (match-beginning 0))))
642 (not (member logical find-file-not-true-dirname-list
)))
643 (setq buffer-file-name buffer-file-truename
))
644 (if find-file-visit-truename
645 (setq buffer-file-name
647 (expand-file-name buffer-file-truename
))))
648 ;; Set buffer's default directory to that of the file.
649 (setq default-directory
(file-name-directory filename
))
650 ;; Turn off backup files for certain file names. Since
651 ;; this is a permanent local, the major mode won't eliminate it.
652 (and (not (funcall backup-enable-predicate buffer-file-name
))
654 (make-local-variable 'backup-inhibited
)
655 (setq backup-inhibited t
)))
656 (after-find-file error
(not nowarn
))))
659 (defun after-find-file (&optional error warn noauto
)
660 "Called after finding a file and by the default revert function.
661 Sets buffer mode, parses local variables.
662 Optional args ERROR, WARN, and NOAUTO: ERROR non-nil means there was an
663 error in reading the file. WARN non-nil means warn if there
664 exists an auto-save file more recent than the visited file.
665 NOAUTO means don't mess with auto-save mode.
666 Finishes by calling the functions in `find-file-hooks'."
667 (setq buffer-read-only
(not (file-writable-p buffer-file-name
)))
672 (cond ((and error
(file-attributes buffer-file-name
))
673 (setq buffer-read-only t
)
674 "File exists, but is read-protected.")
675 ((not buffer-read-only
)
677 (file-newer-than-file-p (make-auto-save-file-name)
679 "Auto save file is newer; consider M-x recover-file"
681 (if error
"(New file)" nil
)))
684 "Note: file is write protected")
685 ((file-attributes (directory-file-name default-directory
))
686 "File not found and directory write-protected")
687 ((file-exists-p (file-name-directory buffer-file-name
))
688 (setq buffer-read-only nil
))
690 (setq buffer-read-only nil
)
691 (if (file-exists-p (file-name-directory (directory-file-name (file-name-directory buffer-file-name
))))
692 "Use M-x make-dir RET RET to create the directory"
693 "Use C-u M-x make-dir RET RET to create directory and its parents")))))
697 (or not-serious
(sit-for 1 nil t
)))))
698 (if (and auto-save-default
(not noauto
))
701 (mapcar 'funcall find-file-hooks
))
703 (defun normal-mode (&optional find-file
)
704 "Choose the major mode for this buffer automatically.
705 Also sets up any specified local variables of the file.
706 Uses the visited file name, the -*- line, and the local variables spec.
708 This function is called automatically from `find-file'. In that case,
709 we may set up specified local variables depending on the value of
710 `enable-local-variables': if it is t, we do; if it is nil, we don't;
711 otherwise, we query. `enable-local-variables' is ignored if you
712 run `normal-mode' explicitly."
714 (or find-file
(funcall (or default-major-mode
'fundamental-mode
)))
717 (error (message "File mode specification error: %s"
718 (prin1-to-string err
))))
720 (let ((enable-local-variables (or (not find-file
)
721 enable-local-variables
)))
722 (hack-local-variables))
723 (error (message "File local-variables error: %s"
724 (prin1-to-string err
)))))
726 (defvar auto-mode-alist
(mapcar 'purecopy
727 '(("\\.text\\'" . text-mode
)
730 ("\\.tex\\'" . TeX-mode
)
731 ("\\.ltx\\'" . LaTeX-mode
)
732 ("\\.el\\'" . emacs-lisp-mode
)
733 ("\\.mm\\'" . nroff-mode
)
734 ("\\.me\\'" . nroff-mode
)
735 ("\\.ms\\'" . nroff-mode
)
736 ("\\.man\\'" . nroff-mode
)
737 ("\\.scm\\'" . scheme-mode
)
738 ("\\.l\\'" . lisp-mode
)
739 ("\\.lisp\\'" . lisp-mode
)
740 ("\\.f\\'" . fortran-mode
)
741 ("\\.for\\'" . fortran-mode
)
742 ("\\.mss\\'" . scribe-mode
)
743 ("\\.pl\\'" . prolog-mode
)
744 ("\\.cc\\'" . c
++-mode
)
745 ("\\.hh\\'" . c
++-mode
)
746 ("\\.C\\'" . c
++-mode
)
747 ("\\.H\\'" . c
++-mode
)
748 ;;; ("\\.mk\\'" . makefile-mode)
749 ;;; ("[Mm]akefile" . makefile-mode)
750 ;;; Less common extensions come here
751 ;;; so more common ones above are found faster.
752 ("\\.s\\'" . asm-mode
)
753 ("ChangeLog\\'" . change-log-mode
)
754 ("ChangeLog.[0-9]+\\'" . change-log-mode
)
755 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode
)
756 ;; The following should come after the ChangeLog pattern
757 ;; for the sake of ChangeLog.1, etc.
758 ("\\.[12345678]\\'" . nroff-mode
)
759 ("\\.TeX\\'" . TeX-mode
)
760 ("\\.sty\\'" . LaTeX-mode
)
761 ("\\.bbl\\'" . LaTeX-mode
)
762 ("\\.bib\\'" . bibtex-mode
)
763 ("\\.article\\'" . text-mode
)
764 ("\\.letter\\'" . text-mode
)
765 ("\\.texinfo\\'" . texinfo-mode
)
766 ("\\.texi\\'" . texinfo-mode
)
767 ("\\.lsp\\'" . lisp-mode
)
768 ("\\.awk\\'" . awk-mode
)
769 ("\\.prolog\\'" . prolog-mode
)
770 ("\\.tar\\'" . tar-mode
)
771 ;; Mailer puts message to be edited in
772 ;; /tmp/Re.... or Message
773 ("^/tmp/Re" . text-mode
)
774 ("/Message[0-9]*\\'" . text-mode
)
775 ;; some news reader is reported to use this
776 ("^/tmp/fol/" . text-mode
)
778 ("\\.lex\\'" . c-mode
)
779 ("\\.oak\\'" . scheme-mode
)
780 ("\\.scm.[0-9]*\\'" . scheme-mode
)
781 ("\\.sgm\\'" . sgml-mode
)
782 ("\\.sgml\\'" . sgml-mode
)
783 ("\\.dtd\\'" . sgml-mode
)
784 ;; .emacs following a directory delimiter
785 ;; in either Unix or VMS syntax.
786 ("[]>:/]\\..*emacs\\'" . emacs-lisp-mode
)
787 ("\\.ml\\'" . lisp-mode
)))
789 Alist of filename patterns vs corresponding major mode functions.
790 Each element looks like (REGEXP . FUNCTION).
791 Visiting a file whose name matches REGEXP causes FUNCTION to be called.")
793 (defconst inhibit-local-variables-regexps
'("\\.tar$")
794 "List of regexps; if one matches a file name, don't look for local vars.")
796 (defun set-auto-mode ()
797 "Select major mode appropriate for current buffer.
798 This checks for a -*- mode tag in the buffer's text, or
799 compares the filename against the entries in auto-mode-alist. It does
800 not check for the \"mode:\" local variable in the Local Variables
801 section of the file; for that, use `hack-local-variables'.
803 If `enable-local-variables' is nil, this function does not check for a
805 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
808 (goto-char (point-min))
809 (skip-chars-forward " \t\n")
810 (if (and enable-local-variables
811 ;; Don't look for -*- if this file name matches any
812 ;; of the regexps in inhibit-local-variables-regexps.
813 (not (let ((temp inhibit-local-variables-regexps
))
815 (not (string-match (car temp
)
817 (setq temp
(cdr temp
)))
819 (search-forward "-*-" (save-excursion
820 ;; If the file begins with "#!"
821 ;; (exec interpreter magic), look
822 ;; for mode frobs in the first two
823 ;; lines. You cannot necessarily
824 ;; put them in the first line of
825 ;; such a file without screwing up
826 ;; the interpreter invocation.
827 (end-of-line (and (looking-at "^#!") 2))
830 (skip-chars-forward " \t")
832 (search-forward "-*-"
833 (save-excursion (end-of-line) (point))
837 (skip-chars-backward " \t")
840 (if (search-forward ":" end t
)
843 (if (let ((case-fold-search t
))
844 (search-forward "mode:" end t
))
846 (skip-chars-forward " \t")
848 (if (search-forward ";" end t
)
851 (skip-chars-backward " \t")
852 (setq mode
(buffer-substring beg
(point))))))
853 (setq mode
(buffer-substring beg end
)))))
854 (setq mode
(intern (concat (downcase mode
) "-mode")))
856 (let ((alist auto-mode-alist
)
857 (name buffer-file-name
))
858 (let ((case-fold-search (eq system-type
'vax-vms
)))
859 ;; Remove backup-suffixes from file name.
860 (setq name
(file-name-sans-versions name
))
861 ;; Find first matching alist entry.
862 (while (and (not mode
) alist
)
863 (if (string-match (car (car alist
)) name
)
864 (setq mode
(cdr (car alist
))))
865 (setq alist
(cdr alist
))))))))
866 (if mode
(funcall mode
))))
868 (defun hack-local-variables-prop-line ()
869 ;; Set local variables specified in the -*- line.
870 ;; Returns t if mode was set.
872 (goto-char (point-min))
873 (skip-chars-forward " \t\n\r")
875 (end (save-excursion (end-of-line) (point)))
877 ;; Parse the -*- line into the `result' alist.
878 (cond ((not (search-forward "-*-" end t
))
881 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
882 ;; Simple form: "-*- MODENAME -*-".
885 (intern (buffer-substring
889 ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
890 ;; (last ";" is optional).
892 (if (search-forward "-*-" end t
)
893 (setq end
(- (point) 3))
894 (error "-*- not terminated before end of line")))
895 (while (< (point) end
)
896 (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
897 (error "malformed -*- line"))
898 (goto-char (match-end 0))
899 (let ((key (intern (downcase (buffer-substring
902 (val (save-restriction
903 (narrow-to-region (point) end
)
904 (read (current-buffer)))))
905 (setq result
(cons (cons key val
) result
))
906 (skip-chars-forward " \t;")))
907 (setq result
(nreverse result
))))
911 (while (setq mode
(assq 'mode result
))
912 (setq mode-p t result
(delq mode result
))
913 (funcall (intern (concat (downcase (symbol-name (cdr mode
)))
917 (or (eq enable-local-variables t
)
918 (and enable-local-variables
919 (save-window-excursion
920 (switch-to-buffer (current-buffer))
921 (y-or-n-p (format "Set local variables as specified in -*- line of %s? "
922 (file-name-nondirectory buffer-file-name
)))))))
924 (let ((key (car (car result
)))
925 (val (cdr (car result
))))
926 ;; 'mode has already been removed from this list.
927 (hack-one-local-variable key val
))
928 (setq result
(cdr result
))))
931 (defun hack-local-variables ()
932 "Parse and put into effect this buffer's local variables spec."
933 (hack-local-variables-prop-line)
934 ;; Look for "Local variables:" line in last page.
936 (goto-char (point-max))
937 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move
)
938 (if (let ((case-fold-search t
))
939 (and (search-forward "Local Variables:" nil t
)
940 (or (eq enable-local-variables t
)
941 (and enable-local-variables
942 (save-window-excursion
943 (switch-to-buffer (current-buffer))
946 (set-window-start (selected-window) (point)))
947 (y-or-n-p (format "Set local variables as specified at end of %s? "
948 (file-name-nondirectory buffer-file-name
))))))))
950 prefix prefixlen suffix beg
951 (enable-local-eval enable-local-eval
))
952 ;; The prefix is what comes before "local variables:" in its line.
953 ;; The suffix is what comes after "local variables:" in its line.
954 (skip-chars-forward " \t")
956 (setq suffix
(buffer-substring (point)
957 (progn (end-of-line) (point)))))
958 (goto-char (match-beginning 0))
961 (buffer-substring (point)
962 (progn (beginning-of-line) (point)))))
964 (if prefix
(setq prefixlen
(length prefix
)
965 prefix
(regexp-quote prefix
)))
966 (if suffix
(setq suffix
(concat (regexp-quote suffix
) "$")))
968 ;; Look at next local variable spec.
969 (if selective-display
(re-search-forward "[\n\C-m]")
971 ;; Skip the prefix, if any.
973 (if (looking-at prefix
)
974 (forward-char prefixlen
)
975 (error "Local variables entry is missing the prefix")))
976 ;; Find the variable name; strip whitespace.
977 (skip-chars-forward " \t")
979 (skip-chars-forward "^:\n")
980 (if (eolp) (error "Missing colon in local variables entry"))
981 (skip-chars-backward " \t")
982 (let* ((str (buffer-substring beg
(point)))
985 ;; Setting variable named "end" means end of list.
986 (if (string-equal (downcase str
) "end")
988 ;; Otherwise read the variable value.
989 (skip-chars-forward "^:")
991 (setq val
(read (current-buffer)))
992 (skip-chars-backward "\n")
993 (skip-chars-forward " \t")
994 (or (if suffix
(looking-at suffix
) (eolp))
995 (error "Local variables entry is terminated incorrectly"))
996 ;; Set the variable. "Variables" mode and eval are funny.
997 (hack-one-local-variable var val
))))))))
999 (defconst ignored-local-variables
1000 '(enable-local-eval)
1001 "Variables to be ignored in a file's local variable spec.")
1003 ;; "Set" one variable in a local variables spec.
1004 ;; A few variable names are treated specially.
1005 (defun hack-one-local-variable (var val
)
1006 (cond ((eq var
'mode
)
1007 (funcall (intern (concat (downcase (symbol-name val
))
1009 ((memq var ignored-local-variables
)
1011 ;; "Setting" eval means either eval it or do nothing.
1013 (if (and (not (string= (user-login-name) "root"))
1014 (or (eq enable-local-eval t
)
1015 (and enable-local-eval
1016 (save-window-excursion
1017 (switch-to-buffer (current-buffer))
1020 (set-window-start (selected-window) (point)))
1021 (setq enable-local-eval
1022 (y-or-n-p (format "Process `eval' local variable in file %s? "
1023 (file-name-nondirectory buffer-file-name
))))))))
1024 (save-excursion (eval val
))
1025 (message "Ignoring `eval:' in file's local variables")))
1026 ;; Ordinary variable, really set it.
1027 (t (make-local-variable var
)
1031 (defun set-visited-file-name (filename)
1032 "Change name of file visited in current buffer to FILENAME.
1033 The next time the buffer is saved it will go in the newly specified file.
1034 nil or empty string as argument means make buffer not be visiting any file.
1035 Remember to delete the initial contents of the minibuffer
1036 if you wish to pass an empty string as the argument."
1037 (interactive "FSet visited file name: ")
1040 (if (string-equal filename
"")
1042 (expand-file-name filename
))))
1043 (or (equal filename buffer-file-name
)
1046 (lock-buffer filename
)
1048 (setq buffer-file-name filename
)
1049 (if filename
; make buffer name reflect filename.
1050 (let ((new-name (file-name-nondirectory buffer-file-name
)))
1051 (if (string= new-name
"")
1052 (error "Empty file name"))
1053 (if (eq system-type
'vax-vms
)
1054 (setq new-name
(downcase new-name
)))
1055 (setq default-directory
(file-name-directory buffer-file-name
))
1056 (rename-buffer new-name t
)))
1057 (setq buffer-backed-up nil
)
1058 (clear-visited-file-modtime)
1061 (setq buffer-file-truename
1062 (abbreviate-file-name (file-truename buffer-file-name
)))
1063 (if find-file-visit-truename
1064 (setq buffer-file-name buffer-file-truename
))
1065 (setq buffer-file-number
(nth 10 (file-attributes buffer-file-name
))))
1066 (setq buffer-file-truename nil buffer-file-number nil
))
1067 ;; write-file-hooks is normally used for things like ftp-find-file
1068 ;; that visit things that are not local files as if they were files.
1069 ;; Changing to visit an ordinary local file instead should flush the hook.
1070 (kill-local-variable 'write-file-hooks
)
1071 (kill-local-variable 'local-write-file-hooks
)
1072 (kill-local-variable 'revert-buffer-function
)
1073 (kill-local-variable 'backup-inhibited
)
1074 ;; Turn off backup files for certain file names.
1075 ;; Since this is a permanent local, the major mode won't eliminate it.
1076 (and (not (funcall backup-enable-predicate buffer-file-name
))
1078 (make-local-variable 'backup-inhibited
)
1079 (setq backup-inhibited t
)))
1080 ;; If auto-save was not already on, turn it on if appropriate.
1081 (if (not buffer-auto-save-file-name
)
1082 (auto-save-mode (and buffer-file-name auto-save-default
))
1083 ;; If auto save is on, start using a new name.
1084 ;; We deliberately don't rename or delete the old auto save
1085 ;; for the old visited file name. This is because perhaps
1086 ;; the user wants to save the new state and then compare with the
1087 ;; previous state from the auto save file.
1088 (setq buffer-auto-save-file-name
1089 (make-auto-save-file-name)))
1090 (if buffer-file-name
1091 (set-buffer-modified-p t
)))
1093 (defun write-file (filename)
1094 "Write current buffer into file FILENAME.
1095 Makes buffer visit that file, and marks it not modified.
1096 If the buffer is already visiting a file, you can specify
1097 a directory name as FILENAME, to write a file of the same
1098 old name in that directory."
1099 ;; (interactive "FWrite file: ")
1101 (list (if buffer-file-name
1102 (read-file-name "Write file: "
1104 (read-file-name "Write file: "
1105 (cdr (assq 'default-directory
1106 (buffer-local-variables)))
1107 nil nil
(buffer-name)))))
1108 (or (null filename
) (string-equal filename
"")
1110 ;; If arg is just a directory,
1111 ;; use same file name, but in that directory.
1112 (if (and (file-directory-p filename
) buffer-file-name
)
1113 (setq filename
(concat (file-name-as-directory filename
)
1114 (file-name-nondirectory buffer-file-name
))))
1115 (set-visited-file-name filename
)))
1116 (set-buffer-modified-p t
)
1119 (defun backup-buffer ()
1120 "Make a backup of the disk file visited by the current buffer, if appropriate.
1121 This is normally done before saving the buffer the first time.
1122 If the value is non-nil, it is the result of `file-modes' on the original
1123 file; this means that the caller, after saving the buffer, should change
1124 the modes of the new file to agree with the old modes."
1125 (if (and make-backup-files
(not backup-inhibited
)
1126 (not buffer-backed-up
)
1127 (file-exists-p buffer-file-name
)
1128 (memq (aref (elt (file-attributes buffer-file-name
) 8) 0)
1130 (let ((real-file-name buffer-file-name
)
1131 backup-info backupname targets setmodes
)
1132 ;; If specified name is a symbolic link, chase it to the target.
1133 ;; Thus we make the backups in the directory where the real file is.
1134 (setq real-file-name
(file-chase-links real-file-name
))
1135 (setq backup-info
(find-backup-file-name real-file-name
)
1136 backupname
(car backup-info
)
1137 targets
(cdr backup-info
))
1138 ;;; (if (file-directory-p buffer-file-name)
1139 ;;; (error "Cannot save buffer in directory %s" buffer-file-name))
1141 (let ((delete-old-versions
1142 ;; If have old versions to maybe delete,
1143 ;; ask the user to confirm now, before doing anything.
1144 ;; But don't actually delete til later.
1146 (or (eq trim-versions-without-asking t
) (eq trim-versions-without-asking nil
))
1147 (or trim-versions-without-asking
1148 (y-or-n-p (format "Delete excess backup versions of %s? "
1149 real-file-name
))))))
1150 ;; Actually write the back up file.
1152 (if (or file-precious-flag
1153 ; (file-symlink-p buffer-file-name)
1155 (and backup-by-copying-when-linked
1156 (> (file-nlinks real-file-name
) 1))
1157 (and backup-by-copying-when-mismatch
1158 (let ((attr (file-attributes real-file-name
)))
1160 (/= (nth 2 attr
) (user-uid))))))
1162 (copy-file real-file-name backupname t t
)
1164 ;; If copying fails because file BACKUPNAME
1165 ;; is not writable, delete that file and try again.
1166 (if (and (file-exists-p backupname
)
1167 (not (file-writable-p backupname
)))
1168 (delete-file backupname
))
1169 (copy-file real-file-name backupname t t
)))
1170 ;; rename-file should delete old backup.
1171 (rename-file real-file-name backupname t
)
1172 (setq setmodes
(file-modes backupname
)))
1174 ;; If trouble writing the backup, write it in ~.
1175 (setq backupname
(expand-file-name "~/%backup%~"))
1176 (message "Cannot write backup file; backing up in ~/%%backup%%~")
1179 (copy-file real-file-name backupname t t
)
1181 ;; If copying fails because file BACKUPNAME
1182 ;; is not writable, delete that file and try again.
1183 (if (and (file-exists-p backupname
)
1184 (not (file-writable-p backupname
)))
1185 (delete-file backupname
))
1186 (copy-file real-file-name backupname t t
)))))
1187 (setq buffer-backed-up t
)
1188 ;; Now delete the old versions, if desired.
1189 (if delete-old-versions
1192 (delete-file (car targets
))
1194 (setq targets
(cdr targets
))))
1196 (file-error nil
)))))
1198 (defun file-name-sans-versions (name &optional keep-backup-version
)
1199 "Return FILENAME sans backup versions or strings.
1200 This is a separate procedure so your site-init or startup file can
1202 If the optional argument KEEP-BACKUP-VERSION is non-nil,
1203 we do not remove backup version numbers, only true file version numbers."
1204 (let ((handler (find-file-name-handler name
)))
1206 (funcall handler
'file-name-sans-versions name keep-backup-version
)
1208 (if (eq system-type
'vax-vms
)
1209 ;; VMS version number is (a) semicolon, optional
1210 ;; sign, zero or more digits or (b) period, option
1211 ;; sign, zero or more digits, provided this is the
1212 ;; second period encountered outside of the
1213 ;; device/directory part of the file name.
1214 (or (string-match ";[---+]?[0-9]*\\'" name
)
1215 (if (string-match "\\.[^]>:]*\\(\\.[---+]?[0-9]*\\)\\'"
1217 (match-beginning 1))
1219 (if keep-backup-version
1221 (or (string-match "\\.~[0-9]+~\\'" name
)
1222 (string-match "~\\'" name
)
1223 (length name
))))))))
1225 (defun make-backup-file-name (file)
1226 "Create the non-numeric backup file name for FILE.
1227 This is a separate function so you can redefine it for customization."
1230 (defun backup-file-name-p (file)
1231 "Return non-nil if FILE is a backup file name (numeric or not).
1232 This is a separate function so you can redefine it for customization.
1233 You may need to redefine `file-name-sans-versions' as well."
1234 (string-match "~$" file
))
1236 ;; This is used in various files.
1237 ;; The usage of bv-length is not very clean,
1238 ;; but I can't see a good alternative,
1239 ;; so as of now I am leaving it alone.
1240 (defun backup-extract-version (fn)
1241 "Given the name of a numeric backup file, return the backup number.
1242 Uses the free variable `bv-length', whose value should be
1243 the index in the name where the version number begins."
1244 (if (and (string-match "[0-9]+~$" fn bv-length
)
1245 (= (match-beginning 0) bv-length
))
1246 (string-to-int (substring fn bv-length -
1))
1249 ;; I believe there is no need to alter this behavior for VMS;
1250 ;; since backup files are not made on VMS, it should not get called.
1251 (defun find-backup-file-name (fn)
1252 "Find a file name for a backup file, and suggestions for deletions.
1253 Value is a list whose car is the name for the backup file
1254 and whose cdr is a list of old versions to consider deleting now."
1255 (if (eq version-control
'never
)
1256 (list (make-backup-file-name fn
))
1257 (let* ((base-versions (concat (file-name-nondirectory fn
) ".~"))
1258 (bv-length (length base-versions
))
1259 (possibilities (file-name-all-completions
1261 (file-name-directory fn
)))
1262 (versions (sort (mapcar
1263 (function backup-extract-version
)
1266 (high-water-mark (apply 'max
0 versions
))
1269 (> high-water-mark
0)))
1270 (number-to-delete (- (length versions
)
1271 kept-old-versions kept-new-versions -
1)))
1272 (if (not deserve-versions-p
)
1273 (list (make-backup-file-name fn
))
1274 (cons (concat fn
".~" (int-to-string (1+ high-water-mark
)) "~")
1275 (if (and (> number-to-delete
0)
1276 ;; Delete nothing if there is overflow
1277 ;; in the number of versions to keep.
1278 (>= (+ kept-new-versions kept-old-versions -
1) 0))
1279 (mapcar (function (lambda (n)
1280 (concat fn
".~" (int-to-string n
) "~")))
1281 (let ((v (nthcdr kept-old-versions versions
)))
1282 (rplacd (nthcdr (1- number-to-delete
) v
) ())
1285 (defun file-nlinks (filename)
1286 "Return number of names file FILENAME has."
1287 (car (cdr (file-attributes filename
))))
1289 (defun file-relative-name-1 (directory)
1290 (cond ((string= directory
"/")
1292 ((string-match (concat "^" (regexp-quote directory
))
1294 (substring filename
(match-end 0)))
1296 (file-relative-name-1
1297 (file-name-directory (substring directory
0 -
1))))))
1299 (defun file-relative-name (filename &optional directory
)
1300 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
1301 (setq filename
(expand-file-name filename
)
1302 directory
(file-name-as-directory (if directory
1303 (expand-file-name directory
)
1304 default-directory
)))
1305 (file-relative-name-1 directory
))
1307 (defun save-buffer (&optional args
)
1308 "Save current buffer in visited file if modified. Versions described below.
1309 By default, makes the previous version into a backup file
1310 if previously requested or if this is the first save.
1311 With 1 or 3 \\[universal-argument]'s, marks this version
1312 to become a backup when the next save is done.
1313 With 2 or 3 \\[universal-argument]'s,
1314 unconditionally makes the previous version into a backup file.
1315 With argument of 0, never makes the previous version into a backup file.
1317 If a file's name is FOO, the names of its numbered backup versions are
1318 FOO.~i~ for various integers i. A non-numbered backup file is called FOO~.
1319 Numeric backups (rather than FOO~) will be made if value of
1320 `version-control' is not the atom `never' and either there are already
1321 numeric versions of the file being backed up, or `version-control' is
1323 We don't want excessive versions piling up, so there are variables
1324 `kept-old-versions', which tells Emacs how many oldest versions to keep,
1325 and `kept-new-versions', which tells how many newest versions to keep.
1326 Defaults are 2 old versions and 2 new.
1327 `dired-kept-versions' controls dired's clean-directory (.) command.
1328 If `trim-versions-without-asking' is nil, system will query user
1329 before trimming versions. Otherwise it does it silently."
1331 (let ((modp (buffer-modified-p))
1332 (large (> (buffer-size) 50000))
1333 (make-backup-files (and make-backup-files
(not (eq args
0)))))
1334 (and modp
(memq args
'(16 64)) (setq buffer-backed-up nil
))
1335 (if (and modp large
) (message "Saving file %s..." (buffer-file-name)))
1337 (and modp
(memq args
'(4 64)) (setq buffer-backed-up nil
))))
1339 (defun delete-auto-save-file-if-necessary (&optional force
)
1340 "Delete auto-save file for current buffer if `delete-auto-save-files' is t.
1341 Normally delete only if the file was written by this Emacs since
1342 the last real save, but optional arg FORCE non-nil means delete anyway."
1343 (and buffer-auto-save-file-name delete-auto-save-files
1344 (not (string= buffer-file-name buffer-auto-save-file-name
))
1345 (or force
(recent-auto-save-p))
1348 (delete-file buffer-auto-save-file-name
)
1350 (set-buffer-auto-saved))))
1352 (defun basic-save-buffer ()
1353 "Save the current buffer in its visited file, if it has been modified."
1355 (if (buffer-modified-p)
1356 (let ((recent-save (recent-auto-save-p))
1357 setmodes tempsetmodes
)
1358 ;; On VMS, rename file and buffer to get rid of version number.
1359 (if (and (eq system-type
'vax-vms
)
1360 (not (string= buffer-file-name
1361 (file-name-sans-versions buffer-file-name
))))
1362 (let (buffer-new-name)
1363 ;; Strip VMS version number before save.
1364 (setq buffer-file-name
1365 (file-name-sans-versions buffer-file-name
))
1366 ;; Construct a (unique) buffer name to correspond.
1367 (let ((buf (create-file-buffer (downcase buffer-file-name
))))
1368 (setq buffer-new-name
(buffer-name buf
))
1370 (rename-buffer buffer-new-name
)))
1371 ;; If buffer has no file name, ask user for one.
1372 (or buffer-file-name
1374 (setq buffer-file-name
1375 (expand-file-name (read-file-name "File to save in: ") nil
)
1376 default-directory
(file-name-directory buffer-file-name
))
1377 (auto-save-mode auto-save-default
)))
1378 (or (verify-visited-file-modtime (current-buffer))
1379 (not (file-exists-p buffer-file-name
))
1381 (format "%s has changed since visited or saved. Save anyway? "
1382 (file-name-nondirectory buffer-file-name
)))
1383 (error "Save not confirmed"))
1386 (and (> (point-max) 1)
1387 (/= (char-after (1- (point-max))) ?
\n)
1388 (or (eq require-final-newline t
)
1389 (and require-final-newline
1391 (format "Buffer %s does not end in newline. Add one? "
1394 (goto-char (point-max))
1396 (let ((hooks (append write-contents-hooks local-write-file-hooks
1400 (not (setq done
(funcall (car hooks
)))))
1401 (setq hooks
(cdr hooks
)))
1402 ;; If a hook returned t, file is already "written".
1404 (if (not (file-writable-p buffer-file-name
))
1405 (let ((dir (file-name-directory buffer-file-name
)))
1406 (if (not (file-directory-p dir
))
1407 (error "%s is not a directory" dir
)
1408 (if (not (file-exists-p buffer-file-name
))
1409 (error "Directory %s write-protected" dir
)
1411 (format "File %s is write-protected; try to save anyway? "
1412 (file-name-nondirectory
1414 (setq tempsetmodes t
)
1415 (error "Attempt to save to a file which you aren't allowed to write"))))))
1416 (or buffer-backed-up
1417 (setq setmodes
(backup-buffer)))
1418 (if file-precious-flag
1419 ;; If file is precious, write temp name, then rename it.
1420 (let ((dir (file-name-directory buffer-file-name
))
1421 (realname buffer-file-name
)
1422 tempname temp nogood i succeed
)
1425 ;; Find the temporary name to write under.
1427 (setq tempname
(format "%s#tmp#%d" dir i
))
1428 (setq nogood
(file-exists-p tempname
))
1431 (progn (clear-visited-file-modtime)
1432 (write-region (point-min) (point-max)
1433 tempname nil realname
)
1435 ;; If writing the temp file fails,
1436 ;; delete the temp file.
1437 (or succeed
(delete-file tempname
)))
1438 ;; Since we have created an entirely new file
1439 ;; and renamed it, make sure it gets the
1440 ;; right permission bits set.
1441 (setq setmodes
(file-modes buffer-file-name
))
1442 ;; We succeeded in writing the temp file,
1444 (rename-file tempname buffer-file-name t
))
1445 ;; If file not writable, see if we can make it writable
1446 ;; temporarily while we write it.
1447 ;; But no need to do so if we have just backed it up
1448 ;; (setmodes is set) because that says we're superseding.
1449 (cond ((and tempsetmodes
(not setmodes
))
1450 ;; Change the mode back, after writing.
1451 (setq setmodes
(file-modes buffer-file-name
))
1452 (set-file-modes buffer-file-name
511)))
1453 (write-region (point-min) (point-max)
1454 buffer-file-name nil t
)))))
1455 (setq buffer-file-number
(nth 10 (file-attributes buffer-file-name
)))
1458 (set-file-modes buffer-file-name setmodes
)
1460 ;; If the auto-save file was recent before this command,
1462 (delete-auto-save-file-if-necessary recent-save
)
1463 (run-hooks 'after-save-hooks
))
1464 (message "(No changes need to be saved)")))
1466 (defun save-some-buffers (&optional arg exiting
)
1467 "Save some modified file-visiting buffers. Asks user about each one.
1468 Optional argument (the prefix) non-nil means save all with no questions.
1469 Optional second argument EXITING means ask about certain non-file buffers
1470 as well as about file buffers."
1472 (save-window-excursion
1473 (if (zerop (map-y-or-n-p
1476 (and (buffer-modified-p buffer
)
1478 (buffer-file-name buffer
)
1482 (and buffer-offer-save
(> (buffer-size) 0)))))
1485 (if (buffer-file-name buffer
)
1486 (format "Save file %s? "
1487 (buffer-file-name buffer
))
1488 (format "Save buffer %s? "
1489 (buffer-name buffer
)))))))
1495 '("buffer" "buffers" "save")
1496 (list (list ?\C-r
(lambda (buf)
1498 (setq view-exit-action
1500 (exit-recursive-edit)))
1502 ;; Return nil to ask about BUF again.
1504 "display the current buffer"))
1506 (message "(No files need saving)"))))
1508 (defun not-modified (&optional arg
)
1509 "Mark current buffer as unmodified, not needing to be saved.
1510 With prefix arg, mark buffer as modified, so \\[save-buffer] will save."
1512 (message (if arg
"Modification-flag set"
1513 "Modification-flag cleared"))
1514 (set-buffer-modified-p arg
))
1516 (defun toggle-read-only (&optional arg
)
1517 "Change whether this buffer is visiting its file read-only.
1518 With arg, set read-only iff arg is positive."
1520 (setq buffer-read-only
1522 (not buffer-read-only
)
1523 (> (prefix-numeric-value arg
) 0)))
1524 ;; Force mode-line redisplay
1525 (set-buffer-modified-p (buffer-modified-p)))
1527 (defun insert-file (filename)
1528 "Insert contents of file FILENAME into buffer after point.
1529 Set mark after the inserted text.
1531 This function is meant for the user to run interactively.
1532 Don't call it from programs! Use `insert-file-contents' instead.
1533 \(Its calling sequence is different; see its documentation)."
1534 (interactive "fInsert file: ")
1535 (let ((tem (insert-file-contents filename
)))
1536 (push-mark (+ (point) (car (cdr tem
))))))
1538 (defun append-to-file (start end filename
)
1539 "Append the contents of the region to the end of file FILENAME.
1540 When called from a function, expects three arguments,
1541 START, END and FILENAME. START and END are buffer positions
1542 saying what text to write."
1543 (interactive "r\nFAppend to file: ")
1544 (write-region start end filename t
))
1546 (defun file-newest-backup (filename)
1547 "Return most recent backup file for FILENAME or nil if no backups exist."
1548 (let* ((filename (expand-file-name filename
))
1549 (file (file-name-nondirectory filename
))
1550 (dir (file-name-directory filename
))
1551 (comp (file-name-all-completions file dir
))
1554 (setq file
(concat dir
(car comp
))
1556 (if (and (backup-file-name-p file
)
1557 (or (null newest
) (file-newer-than-file-p file newest
)))
1558 (setq newest file
)))
1561 (defun rename-uniquely ()
1562 "Rename current buffer to a similar name not already taken.
1563 This function is useful for creating multiple shell process buffers
1564 or multiple mail buffers, etc."
1566 (let* ((new-buf (generate-new-buffer (buffer-name)))
1567 (name (buffer-name new-buf
)))
1568 (kill-buffer new-buf
)
1569 (rename-buffer name
)
1570 (set-buffer-modified-p (buffer-modified-p)))) ; force mode line update
1572 (defun make-directory (dir &optional parents
)
1573 "Create the directory DIR and any nonexistent parent dirs."
1574 (interactive "FMake directory: \nP")
1575 (let ((handler (find-file-name-handler dir
)))
1577 (funcall handler
'make-directory dir parents
)
1579 (make-directory-internal dir
)
1580 (let ((dir (directory-file-name (expand-file-name dir
)))
1582 (while (not (file-exists-p dir
))
1583 (setq create-list
(cons dir create-list
)
1584 dir
(directory-file-name (file-name-directory dir
))))
1586 (make-directory-internal (car create-list
))
1587 (setq create-list
(cdr create-list
))))))))
1589 (put 'revert-buffer-function
'permanent-local t
)
1590 (defvar revert-buffer-function nil
1591 "Function to use to revert this buffer, or nil to do the default.")
1593 (put 'revert-buffer-insert-file-contents-function
'permanent-local t
)
1594 (defvar revert-buffer-insert-file-contents-function nil
1595 "Function to use to insert contents when reverting this buffer.
1596 Gets two args, first the nominal file name to use,
1597 and second, t if reading the auto-save file.")
1599 (defun revert-buffer (&optional ignore-auto noconfirm
)
1600 "Replace the buffer text with the text of the visited file on disk.
1601 This undoes all changes since the file was visited or saved.
1602 With a prefix argument, offer to revert from latest auto-save file, if
1603 that is more recent than the visited file.
1605 When called from lisp, the first argument is IGNORE-AUTO; only offer
1606 to revert from the auto-save file when this is nil. Note that the
1607 sense of this argument is the reverse of the prefix argument, for the
1608 sake of backward compatibility. IGNORE-AUTO is optional, defaulting
1611 Optional second argument NOCONFIRM means don't ask for confirmation at
1614 If the value of `revert-buffer-function' is non-nil, it is called to
1616 ;; I admit it's odd to reverse the sense of the prefix argument, but
1617 ;; there is a lot of code out there which assumes that the first
1618 ;; argument should be t to avoid consulting the auto-save file, and
1619 ;; there's no straightforward way to encourage authors to notice a
1620 ;; reversal of the argument sense. So I'm just changing the user
1621 ;; interface, but leaving the programmatic interface the same.
1622 (interactive (list (not prefix-arg
)))
1623 (if revert-buffer-function
1624 (funcall revert-buffer-function ignore-auto noconfirm
)
1625 (let* ((opoint (point))
1626 (auto-save-p (and (not ignore-auto
)
1627 (recent-auto-save-p)
1628 buffer-auto-save-file-name
1629 (file-readable-p buffer-auto-save-file-name
)
1631 "Buffer has been auto-saved recently. Revert from auto-save file? ")))
1632 (file-name (if auto-save-p
1633 buffer-auto-save-file-name
1635 (cond ((null file-name
)
1636 (error "Buffer does not seem to be associated with any file"))
1638 (yes-or-no-p (format "Revert buffer from file %s? "
1640 ;; If file was backed up but has changed since,
1641 ;; we shd make another backup.
1642 (and (not auto-save-p
)
1643 (not (verify-visited-file-modtime (current-buffer)))
1644 (setq buffer-backed-up nil
))
1645 ;; Get rid of all undo records for this buffer.
1646 (or (eq buffer-undo-list t
)
1647 (setq buffer-undo-list nil
))
1648 (let ((buffer-read-only nil
)
1649 ;; Don't make undo records for the reversion.
1650 (buffer-undo-list t
))
1651 (if revert-buffer-insert-file-contents-function
1652 (funcall revert-buffer-insert-file-contents-function
1653 file-name auto-save-p
)
1654 (if (not (file-exists-p file-name
))
1655 (error "File %s no longer exists!" file-name
))
1656 ;; Bind buffer-file-name to nil
1657 ;; so that we don't try to lock the file.
1658 (let ((buffer-file-name nil
))
1662 (insert-file-contents file-name
(not auto-save-p
))))
1663 (goto-char (min opoint
(point-max)))
1664 (after-find-file nil nil t
)
1667 (defun recover-file (file)
1668 "Visit file FILE, but get contents from its last auto-save file."
1670 (let ((prompt-file buffer-file-name
)
1674 (setq file-name
(file-name-nondirectory prompt-file
)
1675 file-dir
(file-name-directory prompt-file
)))
1676 (list (read-file-name "Recover file: "
1677 file-dir nil nil file-name
))))
1678 (setq file
(expand-file-name file
))
1679 (if (auto-save-file-name-p file
) (error "%s is an auto-save file" file
))
1680 (let ((file-name (let ((buffer-file-name file
))
1681 (make-auto-save-file-name))))
1682 (cond ((not (file-newer-than-file-p file-name file
))
1683 (error "Auto-save file %s not current" file-name
))
1684 ((save-window-excursion
1685 (if (not (eq system-type
'vax-vms
))
1686 (with-output-to-temp-buffer "*Directory*"
1687 (buffer-disable-undo standard-output
)
1688 (call-process "ls" nil standard-output nil
1689 (if (file-symlink-p file
) "-lL" "-l")
1691 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
1692 (switch-to-buffer (find-file-noselect file t
))
1693 (let ((buffer-read-only nil
))
1695 (insert-file-contents file-name nil
))
1696 (after-find-file nil nil t
))
1697 (t (error "Recover-file cancelled.")))))
1699 (defun kill-some-buffers ()
1700 "For each buffer, ask whether to kill it."
1702 (let ((list (buffer-list)))
1704 (let* ((buffer (car list
))
1705 (name (buffer-name buffer
)))
1706 (and (not (string-equal name
""))
1707 (/= (aref name
0) ?
)
1709 (format "Buffer %s %s. Kill? "
1711 (if (buffer-modified-p buffer
)
1712 "HAS BEEN EDITED" "is unmodified")))
1713 (kill-buffer buffer
)))
1714 (setq list
(cdr list
)))))
1716 (defun auto-save-mode (arg)
1717 "Toggle auto-saving of contents of current buffer.
1718 With prefix argument ARG, turn auto-saving on if positive, else off."
1720 (setq buffer-auto-save-file-name
1722 (not buffer-auto-save-file-name
)
1723 (or (eq arg t
) (listp arg
) (and (integerp arg
) (> arg
0))))
1724 (if (and buffer-file-name auto-save-visited-file-name
1725 (not buffer-read-only
))
1727 (make-auto-save-file-name))))
1729 (message "Auto-save %s (in this buffer)"
1730 (if buffer-auto-save-file-name
"on" "off")))
1731 buffer-auto-save-file-name
)
1733 (defun rename-auto-save-file ()
1734 "Adjust current buffer's auto save file name for current conditions.
1735 Also rename any existing auto save file, if it was made in this session."
1736 (let ((osave buffer-auto-save-file-name
))
1737 (setq buffer-auto-save-file-name
1738 (make-auto-save-file-name))
1739 (if (and osave buffer-auto-save-file-name
1740 (not (string= buffer-auto-save-file-name buffer-file-name
))
1741 (not (string= buffer-auto-save-file-name osave
))
1742 (file-exists-p osave
)
1743 (recent-auto-save-p))
1744 (rename-file osave buffer-auto-save-file-name t
))))
1746 (defun make-auto-save-file-name ()
1747 "Return file name to use for auto-saves of current buffer.
1748 Does not consider `auto-save-visited-file-name' as that variable is checked
1749 before calling this function. You can redefine this for customization.
1750 See also `auto-save-file-name-p'."
1751 (if buffer-file-name
1752 (concat (file-name-directory buffer-file-name
)
1754 (file-name-nondirectory buffer-file-name
)
1756 ;; For non-file bfr, use bfr name and Emacs pid.
1757 (expand-file-name (format "#%s#%s#" (buffer-name) (make-temp-name "")))))
1759 (defun auto-save-file-name-p (filename)
1760 "Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'.
1761 FILENAME should lack slashes. You can redefine this for customization."
1762 (string-match "^#.*#$" filename
))
1764 (defconst list-directory-brief-switches
1765 (if (eq system-type
'vax-vms
) "" "-CF")
1766 "*Switches for list-directory to pass to `ls' for brief listing,")
1768 (defconst list-directory-verbose-switches
1769 (if (eq system-type
'vax-vms
)
1770 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)"
1772 "*Switches for list-directory to pass to `ls' for verbose listing,")
1774 (defun list-directory (dirname &optional verbose
)
1775 "Display a list of files in or matching DIRNAME, a la `ls'.
1776 DIRNAME is globbed by the shell if necessary.
1777 Prefix arg (second arg if noninteractive) means supply -l switch to `ls'.
1778 Actions controlled by variables `list-directory-brief-switches'
1779 and `list-directory-verbose-switches'."
1780 (interactive (let ((pfx current-prefix-arg
))
1781 (list (read-file-name (if pfx
"List directory (verbose): "
1782 "List directory (brief): ")
1783 nil default-directory nil
)
1785 (let ((switches (if verbose list-directory-verbose-switches
1786 list-directory-brief-switches
)))
1787 (or dirname
(setq dirname default-directory
))
1788 (setq dirname
(expand-file-name dirname
))
1789 (with-output-to-temp-buffer "*Directory*"
1790 (buffer-disable-undo standard-output
)
1791 (princ "Directory ")
1795 (set-buffer "*Directory*")
1796 (let ((wildcard (not (file-directory-p dirname
))))
1797 (insert-directory dirname switches wildcard
(not wildcard
)))))))
1799 (defvar insert-directory-program
"ls"
1800 "Absolute or relative name of the `ls' program used by `insert-directory'.")
1803 ;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
1804 ;; FULL-DIRECTORY-P is nil.
1805 ;; The single line of output must display FILE's name as it was
1806 ;; given, namely, an absolute path name.
1807 ;; - must insert exactly one line for each file if WILDCARD or
1808 ;; FULL-DIRECTORY-P is t, plus one optional "total" line
1809 ;; before the file lines, plus optional text after the file lines.
1810 ;; Lines are delimited by "\n", so filenames containing "\n" are not
1812 ;; File lines should display the basename.
1813 ;; - must be consistent with
1814 ;; - functions dired-move-to-filename, (these two define what a file line is)
1815 ;; dired-move-to-end-of-filename,
1816 ;; dired-between-files, (shortcut for (not (dired-move-to-filename)))
1817 ;; dired-insert-headerline
1818 ;; dired-after-subdir-garbage (defines what a "total" line is)
1819 ;; - variable dired-subdir-regexp
1820 (defun insert-directory (file switches
&optional wildcard full-directory-p
)
1821 "Insert directory listing for of FILE, formatted according to SWITCHES.
1822 Leaves point after the inserted text.
1823 Optional third arg WILDCARD means treat FILE as shell wildcard.
1824 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
1825 switches do not contain `d', so that a full listing is expected.
1827 This works by running a directory listing program
1828 whose name is in the variable `insert-directory-program'.
1829 If WILDCARD, it also runs the shell specified by `shell-file-name'."
1830 (let ((handler (find-file-name-handler file
)))
1832 (funcall handler
'insert-directory file switches
1833 wildcard full-directory-p
)
1834 (if (eq system-type
'vax-vms
)
1835 (vms-read-directory file switches
(current-buffer))
1837 (let ((default-directory (file-name-directory file
)))
1838 (call-process shell-file-name nil t nil
1839 "-c" (concat insert-directory-program
1841 (file-name-nondirectory file
))))
1842 ;; Barry Margolin says: "SunOS 4.1.3 (and SV and POSIX?)
1843 ;; lists the link if we give a link to a directory - yuck!"
1844 ;; That's why we used to chase symlinks. But we don't want
1845 ;; to chase links before passing the filename to ls; that
1846 ;; would mean that our line of output would not display
1847 ;; FILE's name as given. To really address the problem that
1848 ;; SunOS 4.1.3 has, we need to find the right switch to get
1849 ;; a descripton of the link itself.
1851 ;; (while (setq symlink (file-symlink-p file))
1852 ;; (setq file symlink)))
1853 (call-process insert-directory-program nil t nil switches file
))))))
1855 (defun save-buffers-kill-emacs (&optional arg
)
1856 "Offer to save each buffer, then kill this Emacs process.
1857 With prefix arg, silently save all file-visiting buffers, then kill."
1859 (save-some-buffers arg t
)
1860 (and (or (not (memq t
(mapcar (function
1861 (lambda (buf) (and (buffer-file-name buf
)
1862 (buffer-modified-p buf
))))
1864 (yes-or-no-p "Modified buffers exist; exit anyway? "))
1865 (or (not (fboundp 'process-list
))
1866 ;; process-list is not defined on VMS.
1867 (let ((processes (process-list))
1870 (and (memq (process-status (car processes
)) '(run stop open
))
1871 (let ((val (process-kill-without-query (car processes
))))
1872 (process-kill-without-query (car processes
) val
)
1875 (setq processes
(cdr processes
)))
1877 (yes-or-no-p "Active processes exist; kill them and exit anyway? "))))
1880 (define-key ctl-x-map
"\C-f" 'find-file
)
1881 (define-key ctl-x-map
"\C-q" 'toggle-read-only
)
1882 (define-key ctl-x-map
"\C-r" 'find-file-read-only
)
1883 (define-key ctl-x-map
"\C-v" 'find-alternate-file
)
1884 (define-key ctl-x-map
"\C-s" 'save-buffer
)
1885 (define-key ctl-x-map
"s" 'save-some-buffers
)
1886 (define-key ctl-x-map
"\C-w" 'write-file
)
1887 (define-key ctl-x-map
"i" 'insert-file
)
1888 (define-key esc-map
"~" 'not-modified
)
1889 (define-key ctl-x-map
"\C-d" 'list-directory
)
1890 (define-key ctl-x-map
"\C-c" 'save-buffers-kill-emacs
)
1892 (define-key ctl-x-4-map
"f" 'find-file-other-window
)
1893 (define-key ctl-x-4-map
"r" 'find-file-read-only-other-window
)
1894 (define-key ctl-x-4-map
"\C-f" 'find-file-other-window
)
1895 (define-key ctl-x-4-map
"b" 'switch-to-buffer-other-window
)
1896 (define-key ctl-x-4-map
"\C-o" 'display-buffer
)
1898 (define-key ctl-x-5-map
"b" 'switch-to-buffer-other-frame
)
1899 (define-key ctl-x-5-map
"f" 'find-file-other-frame
)
1900 (define-key ctl-x-5-map
"\C-f" 'find-file-other-frame
)
1901 (define-key ctl-x-5-map
"r" 'find-file-read-only-other-frame
)
1903 ;;; files.el ends here