(auto-mode-alist): added pairs for .ms, .man, .mk, [Mm]akefile, .lex.
[emacs.git] / lisp / files.el
blob93455cff93311df820be7c446cb2b204f4079304
1 ;;; files.el --- file input and output commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
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)
12 ;; any later version.
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.
23 ;;; Commentary:
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.
29 ;;; Code:
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
35 nil
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
89 '(lambda (name)
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 (fset 'lock-buffer 'ignore))
230 (or (fboundp 'unlock-buffer)
231 (fset 'unlock-buffer 'ignore))
233 (defun pwd ()
234 "Show the current default directory."
235 (interactive nil)
236 (message "Directory %s" default-directory))
238 (defun cd (dir)
239 "Make DIR become the current buffer's default directory."
240 (interactive "DChange default directory: ")
241 (setq dir (expand-file-name dir))
242 (if (not (eq system-type 'vax-vms))
243 (setq dir (file-name-as-directory dir)))
244 (if (not (file-directory-p dir))
245 (error "%s is not a directory" dir)
246 (if (file-executable-p dir)
247 (setq default-directory dir)
248 (error "Cannot cd to %s: Permission denied" dir)))
249 ;; We used to call pwd at this point. That's not terribly helpful
250 ;; when we're invoking cd interactively, and the new cmushell-based
251 ;; shell has its own (better) facilities for this.
254 (defun load-file (file)
255 "Load the Lisp file named FILE."
256 (interactive "fLoad file: ")
257 (load (expand-file-name file) nil nil t))
259 (defun load-library (library)
260 "Load the library named LIBRARY.
261 This is an interface to the function `load'."
262 (interactive "sLoad library: ")
263 (load library))
265 ;; OTHER is the other file to be compared.
266 (defun file-local-copy (file)
267 "Copy the file FILE into a temporary file on this machine.
268 Returns the name of the local copy, or nil, if FILE is directly
269 accessible."
270 (let ((handler (find-file-name-handler file)))
271 (if handler
272 (funcall handler 'file-local-copy file)
273 nil)))
275 (defun file-truename (filename)
276 "Return the truename of FILENAME, which should be absolute.
277 The truename of a file name is found by chasing symbolic links
278 both at the level of the file and at the level of the directories
279 containing it, until no links are left at any level."
280 (if (string= filename "~")
281 (setq filename (expand-file-name filename)))
282 (let ((handler (find-file-name-handler filename)))
283 ;; For file name that has a special handler, call handler.
284 ;; This is so that ange-ftp can save time by doing a no-op.
285 (if handler
286 (funcall handler 'file-truename filename)
287 (let ((dir (file-name-directory filename))
288 target dirfile)
289 ;; Get the truename of the directory.
290 (setq dirfile (directory-file-name dir))
291 ;; If these are equal, we have the (or a) root directory.
292 (or (string= dir dirfile)
293 (setq dir (file-name-as-directory (file-truename dirfile))))
294 ;; Put it back on the file name.
295 (setq filename (concat dir (file-name-nondirectory filename)))
296 ;; Is the file name the name of a link?
297 (setq target (file-symlink-p filename))
298 (if target
299 ;; Yes => chase that link, then start all over
300 ;; since the link may point to a directory name that uses links.
301 (file-truename (expand-file-name target dir))
302 ;; No, we are done!
303 filename)))))
306 (defun switch-to-buffer-other-window (buffer)
307 "Select buffer BUFFER in another window."
308 (interactive "BSwitch to buffer in other window: ")
309 (let ((pop-up-windows t))
310 (pop-to-buffer buffer t)))
312 (defun switch-to-buffer-other-frame (buffer)
313 "Switch to buffer BUFFER in another frame."
314 (interactive "BSwitch to buffer in other frame: ")
315 (let ((pop-up-frames t))
316 (pop-to-buffer buffer t)))
318 (defun find-file (filename)
319 "Edit file FILENAME.
320 Switch to a buffer visiting file FILENAME,
321 creating one if none already exists."
322 (interactive "FFind file: ")
323 (switch-to-buffer (find-file-noselect filename)))
325 (defun find-file-other-window (filename)
326 "Edit file FILENAME, in another window.
327 May create a new window, or reuse an existing one.
328 See the function `display-buffer'."
329 (interactive "FFind file in other window: ")
330 (switch-to-buffer-other-window (find-file-noselect filename)))
332 (defun find-file-other-frame (filename)
333 "Edit file FILENAME, in another frame.
334 May create a new frame, or reuse an existing one.
335 See the function `display-buffer'."
336 (interactive "FFind file in other frame: ")
337 (switch-to-buffer-other-frame (find-file-noselect filename)))
339 (defun find-file-read-only (filename)
340 "Edit file FILENAME but don't allow changes.
341 Like \\[find-file] but marks buffer as read-only.
342 Use \\[toggle-read-only] to permit editing."
343 (interactive "fFind file read-only: ")
344 (find-file filename)
345 (setq buffer-read-only t))
347 (defun find-file-read-only-other-window (filename)
348 "Edit file FILENAME in another window but don't allow changes.
349 Like \\[find-file-other-window] but marks buffer as read-only.
350 Use \\[toggle-read-only] to permit editing."
351 (interactive "fFind file read-only other window: ")
352 (find-file filename)
353 (setq buffer-read-only t))
355 (defun find-file-read-only-other-frame (filename)
356 "Edit file FILENAME in another frame but don't allow changes.
357 Like \\[find-file-other-frame] but marks buffer as read-only.
358 Use \\[toggle-read-only] to permit editing."
359 (interactive "fFind file read-only other frame: ")
360 (find-file-other-frame filename)
361 (setq buffer-read-only t))
363 (defun find-alternate-file (filename)
364 "Find file FILENAME, select its buffer, kill previous buffer.
365 If the current buffer now contains an empty file that you just visited
366 \(presumably by mistake), use this command to visit the file you really want."
367 (interactive
368 (let ((file buffer-file-name)
369 (file-name nil)
370 (file-dir nil))
371 (and file
372 (setq file-name (file-name-nondirectory file)
373 file-dir (file-name-directory file)))
374 (list (read-file-name
375 "Find alternate file: " file-dir nil nil file-name))))
376 (and (buffer-modified-p)
377 ;; (not buffer-read-only)
378 (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
379 (buffer-name))))
380 (error "Aborted"))
381 (let ((obuf (current-buffer))
382 (ofile buffer-file-name)
383 (oname (buffer-name)))
384 (rename-buffer " **lose**")
385 (setq buffer-file-name nil)
386 (unwind-protect
387 (progn
388 (unlock-buffer)
389 (find-file filename))
390 (cond ((eq obuf (current-buffer))
391 (setq buffer-file-name ofile)
392 (lock-buffer)
393 (rename-buffer oname))))
394 (or (eq (current-buffer) obuf)
395 (kill-buffer obuf))))
397 (defun create-file-buffer (filename)
398 "Create a suitably named buffer for visiting FILENAME, and return it.
399 FILENAME (sans directory) is used unchanged if that name is free;
400 otherwise a string <2> or <3> or ... is appended to get an unused name."
401 (let ((lastname (file-name-nondirectory filename)))
402 (if (string= lastname "")
403 (setq lastname filename))
404 (generate-new-buffer lastname)))
406 (defun generate-new-buffer (name)
407 "Create and return a buffer with a name based on NAME.
408 Choose the buffer's name using `generate-new-buffer-name'."
409 (get-buffer-create (generate-new-buffer-name name)))
411 (defconst automount-dir-prefix "^/tmp_mnt/"
412 "Regexp to match the automounter prefix in a directory name.")
414 (defvar abbreviated-home-dir nil
415 "The the user's homedir abbreviated according to `directory-abbrev-list'.")
417 (defun abbreviate-file-name (filename)
418 "Return a version of FILENAME shortened using `directory-abbrev-alist'.
419 This also substitutes \"~\" for the user's home directory.
420 Type \\[describe-variable] directory-abbrev-alist RET for more information."
421 ;; Get rid of the prefixes added by the automounter.
422 (if (and (string-match automount-dir-prefix filename)
423 (file-exists-p (file-name-directory
424 (substring filename (1- (match-end 0))))))
425 (setq filename (substring filename (1- (match-end 0)))))
426 (let ((tail directory-abbrev-alist))
427 ;; If any elt of directory-abbrev-alist matches this name,
428 ;; abbreviate accordingly.
429 (while tail
430 (if (string-match (car (car tail)) filename)
431 (setq filename
432 (concat (cdr (car tail)) (substring filename (match-end 0)))))
433 (setq tail (cdr tail)))
434 ;; Compute and save the abbreviated homedir name.
435 ;; We defer computing this until the first time it's needed, to
436 ;; give time for directory-abbrev-alist to be set properly.
437 (or abbreviated-home-dir
438 (setq abbreviated-home-dir
439 (let ((abbreviated-home-dir "$foo"))
440 (concat "^" (abbreviate-file-name (expand-file-name "~"))))))
441 ;; If FILENAME starts with the abbreviated homedir,
442 ;; make it start with `~' instead.
443 (if (string-match abbreviated-home-dir filename)
444 (setq filename
445 (concat "~" (substring filename (match-end 0)))))
446 filename))
448 (defun find-file-noselect (filename &optional nowarn)
449 "Read file FILENAME into a buffer and return the buffer.
450 If a buffer exists visiting FILENAME, return that one, but
451 verify that the file has not changed since visited or saved.
452 The buffer is not selected, just returned to the caller."
453 (setq filename
454 (abbreviate-file-name
455 (expand-file-name filename)))
456 (if (file-directory-p filename)
457 (if find-file-run-dired
458 (dired-noselect filename)
459 (error "%s is a directory." filename))
460 (let* ((buf (get-file-buffer filename))
461 (truename (abbreviate-file-name (file-truename filename)))
462 (number (nthcdr 10 (file-attributes truename)))
463 ;; Find any buffer for a file which has same truename.
464 (same-truename
465 (or buf ; Shortcut
466 (let (found
467 (list (buffer-list)))
468 (while (and (not found) list)
469 (save-excursion
470 (set-buffer (car list))
471 (if (string= buffer-file-truename truename)
472 (setq found (car list))))
473 (setq list (cdr list)))
474 found)))
475 (same-number
476 (or buf ; Shortcut
477 (and number
478 (let (found
479 (list (buffer-list)))
480 (while (and (not found) list)
481 (save-excursion
482 (set-buffer (car list))
483 (if (equal buffer-file-number number)
484 (setq found (car list))))
485 (setq list (cdr list)))
486 found))))
487 error)
488 ;; Let user know if there is a buffer with the same truename.
489 (if (and (not buf) same-truename (not nowarn))
490 (message "%s and %s are the same file (%s)"
491 filename (buffer-file-name same-truename)
492 truename)
493 (if (and (not buf) same-number (not nowarn))
494 (message "%s and %s are the same file"
495 filename (buffer-file-name same-number))))
497 ;; Optionally also find that buffer.
498 (if (or find-file-existing-other-name find-file-visit-truename)
499 (setq buf (or same-truename same-number)))
500 (if buf
501 (or nowarn
502 (verify-visited-file-modtime buf)
503 (cond ((not (file-exists-p filename))
504 (error "File %s no longer exists!" filename))
505 ((yes-or-no-p
506 (format
507 (if (buffer-modified-p buf)
508 "File %s changed on disk. Discard your edits? "
509 "File %s changed on disk. Read the new version? ")
510 (file-name-nondirectory filename)))
511 (save-excursion
512 (set-buffer buf)
513 (revert-buffer t t)))))
514 (save-excursion
515 ;;; The truename stuff makes this obsolete.
516 ;;; (let* ((link-name (car (file-attributes filename)))
517 ;;; (linked-buf (and (stringp link-name)
518 ;;; (get-file-buffer link-name))))
519 ;;; (if (bufferp linked-buf)
520 ;;; (message "Symbolic link to file in buffer %s"
521 ;;; (buffer-name linked-buf))))
522 (setq buf (create-file-buffer filename))
523 (set-buffer buf)
524 (erase-buffer)
525 (condition-case ()
526 (insert-file-contents filename t)
527 (file-error
528 (setq error t)
529 ;; Run find-file-not-found-hooks until one returns non-nil.
530 (let ((hooks find-file-not-found-hooks))
531 (while (and hooks
532 (not (funcall (car hooks))))
533 (setq hooks (cdr hooks))))))
534 ;; Find the file's truename, and maybe use that as visited name.
535 (setq buffer-file-truename (abbreviate-file-name truename))
536 (setq buffer-file-number number)
537 (if find-file-visit-truename (setq filename buffer-file-truename))
538 ;; Set buffer's default directory to that of the file.
539 (setq default-directory (file-name-directory filename))
540 ;; Turn off backup files for certain file names. Since
541 ;; this is a permanent local, the major mode won't eliminate it.
542 (and (not (funcall backup-enable-predicate buffer-file-name))
543 (progn
544 (make-local-variable 'backup-inhibited)
545 (setq backup-inhibited t)))
546 (after-find-file error (not nowarn))))
547 buf)))
549 (defun after-find-file (&optional error warn noauto)
550 "Called after finding a file and by the default revert function.
551 Sets buffer mode, parses local variables.
552 Optional args ERROR, WARN, and NOAUTO: ERROR non-nil means there was an
553 error in reading the file. WARN non-nil means warn if there
554 exists an auto-save file more recent than the visited file.
555 NOAUTO means don't mess with auto-save mode.
556 Finishes by calling the functions in `find-file-hooks'."
557 (setq buffer-read-only (not (file-writable-p buffer-file-name)))
558 (if noninteractive
560 (let* (not-serious
561 (msg
562 (cond ((and error (file-attributes buffer-file-name))
563 (setq buffer-read-only t)
564 "File exists, but is read-protected.")
565 ((not buffer-read-only)
566 (if (and warn
567 (file-newer-than-file-p (make-auto-save-file-name)
568 buffer-file-name))
569 "Auto save file is newer; consider M-x recover-file"
570 (setq not-serious t)
571 (if error "(New file)" nil)))
572 ((not error)
573 (setq not-serious t)
574 "Note: file is write protected")
575 ((file-attributes (directory-file-name default-directory))
576 "File not found and directory write-protected")
577 ((file-exists-p (file-name-directory buffer-file-name))
578 (setq buffer-read-only nil))
580 (setq buffer-read-only nil)
581 (if (file-exists-p (file-name-directory (directory-file-name (file-name-directory buffer-file-name))))
582 "Use M-x make-dir RET RET to create the directory"
583 "Use C-u M-x make-dir RET RET to create directory and its parents")))))
584 (if msg
585 (progn
586 (message msg)
587 (or not-serious (sit-for 1 nil t)))))
588 (if (and auto-save-default (not noauto))
589 (auto-save-mode t)))
590 (normal-mode t)
591 (mapcar 'funcall find-file-hooks))
593 (defun normal-mode (&optional find-file)
594 "Choose the major mode for this buffer automatically.
595 Also sets up any specified local variables of the file.
596 Uses the visited file name, the -*- line, and the local variables spec.
598 This function is called automatically from `find-file'. In that case,
599 we may set up specified local variables depending on the value of
600 `enable-local-variables': if it is t, we do; if it is nil, we don't;
601 otherwise, we query. `enable-local-variables' is ignored if you
602 run `normal-mode' explicitly."
603 (interactive)
604 (or find-file (funcall (or default-major-mode 'fundamental-mode)))
605 (condition-case err
606 (set-auto-mode)
607 (error (message "File mode specification error: %s"
608 (prin1-to-string err))))
609 (condition-case err
610 (let ((enable-local-variables (or (not find-file)
611 enable-local-variables)))
612 (hack-local-variables))
613 (error (message "File local-variables error: %s"
614 (prin1-to-string err)))))
616 (defvar auto-mode-alist (mapcar 'purecopy
617 '(("\\.text\\'" . text-mode)
618 ("\\.c\\'" . c-mode)
619 ("\\.h\\'" . c-mode)
620 ("\\.tex\\'" . TeX-mode)
621 ("\\.ltx\\'" . LaTeX-mode)
622 ("\\.el\\'" . emacs-lisp-mode)
623 ("\\.mm\\'" . nroff-mode)
624 ("\\.me\\'" . nroff-mode)
625 ("\\.ms\\'" . nroff-mode)
626 ("\\.man\\'" . nroff-mode)
627 ("\\.scm\\'" . scheme-mode)
628 ("\\.l\\'" . lisp-mode)
629 ("\\.lisp\\'" . lisp-mode)
630 ("\\.f\\'" . fortran-mode)
631 ("\\.for\\'" . fortran-mode)
632 ("\\.mss\\'" . scribe-mode)
633 ("\\.pl\\'" . prolog-mode)
634 ("\\.cc\\'" . c++-mode)
635 ("\\.C\\'" . c++-mode)
636 ("\\.mk" . . makefile-mode)
637 ("[Mm]akefile" . makefile-mode)
638 ;;; Less common extensions come here
639 ;;; so more common ones above are found faster.
640 ("\\.s\\'" . asm-mode)
641 ("ChangeLog\\'" . change-log-mode)
642 ("ChangeLog.[0-9]+\\'" . change-log-mode)
643 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode)
644 ;; The following should come after the ChangeLog pattern
645 ;; for the sake of ChangeLog.1, etc.
646 ("\\.[12345678]\\'" . nroff-mode)
647 ("\\.TeX\\'" . TeX-mode)
648 ("\\.sty\\'" . LaTeX-mode)
649 ("\\.bbl\\'" . LaTeX-mode)
650 ("\\.bib\\'" . bibtex-mode)
651 ("\\.article\\'" . text-mode)
652 ("\\.letter\\'" . text-mode)
653 ("\\.texinfo\\'" . texinfo-mode)
654 ("\\.texi\\'" . texinfo-mode)
655 ("\\.lsp\\'" . lisp-mode)
656 ("\\.awk\\'" . awk-mode)
657 ("\\.prolog\\'" . prolog-mode)
658 ("\\.tar\\'" . tar-mode)
659 ;; Mailer puts message to be edited in
660 ;; /tmp/Re.... or Message
661 ("^/tmp/Re" . text-mode)
662 ("/Message[0-9]*\\'" . text-mode)
663 ;; some news reader is reported to use this
664 ("^/tmp/fol/" . text-mode)
665 ("\\.y\\'" . c-mode)
666 ("\\.lex\\'" . c-mode)
667 ("\\.oak\\'" . scheme-mode)
668 ("\\.scm.[0-9]*\\'" . scheme-mode)
669 ;; .emacs following a directory delimiter
670 ;; in either Unix or VMS syntax.
671 ("[]>:/]\\..*emacs\\'" . emacs-lisp-mode)
672 ("\\.ml\\'" . lisp-mode)))
674 Alist of filename patterns vs corresponding major mode functions.
675 Each element looks like (REGEXP . FUNCTION).
676 Visiting a file whose name matches REGEXP causes FUNCTION to be called.")
678 (defun set-auto-mode ()
679 "Select major mode appropriate for current buffer.
680 This checks for a -*- mode tag in the buffer's text, or
681 compares the filename against the entries in auto-mode-alist. It does
682 not check for the \"mode:\" local variable in the Local Variables
683 section of the file; for that, use `hack-local-variables'.
685 If `enable-local-variables' is nil, this function does not check for a
686 -*- mode tag."
687 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
688 (let (beg end mode)
689 (save-excursion
690 (goto-char (point-min))
691 (skip-chars-forward " \t\n")
692 (if (and enable-local-variables
693 (search-forward "-*-" (save-excursion (end-of-line) (point)) t)
694 (progn
695 (skip-chars-forward " \t")
696 (setq beg (point))
697 (search-forward "-*-"
698 (save-excursion (end-of-line) (point))
700 (progn
701 (forward-char -3)
702 (skip-chars-backward " \t")
703 (setq end (point))
704 (goto-char beg)
705 (if (search-forward ":" end t)
706 (progn
707 (goto-char beg)
708 (if (let ((case-fold-search t))
709 (search-forward "mode:" end t))
710 (progn
711 (skip-chars-forward " \t")
712 (setq beg (point))
713 (if (search-forward ";" end t)
714 (forward-char -1)
715 (goto-char end))
716 (skip-chars-backward " \t")
717 (setq mode (buffer-substring beg (point))))))
718 (setq mode (buffer-substring beg end)))))
719 (setq mode (intern (concat (downcase mode) "-mode")))
720 (let ((alist auto-mode-alist)
721 (name buffer-file-name))
722 (let ((case-fold-search (eq system-type 'vax-vms)))
723 ;; Remove backup-suffixes from file name.
724 (setq name (file-name-sans-versions name))
725 ;; Find first matching alist entry.
726 (while (and (not mode) alist)
727 (if (string-match (car (car alist)) name)
728 (setq mode (cdr (car alist))))
729 (setq alist (cdr alist)))))))
730 (if mode (funcall mode))))
732 (defun hack-local-variables-prop-line ()
733 ;; Set local variables specified in the -*- line.
734 ;; Returns t if mode was set.
735 (save-excursion
736 (goto-char (point-min))
737 (skip-chars-forward " \t\n\r")
738 (let ((result '())
739 (end (save-excursion (end-of-line) (point)))
740 mode-p)
741 ;; Parse the -*- line into the `result' alist.
742 (cond ((not (search-forward "-*-" end t))
743 ;; doesn't have one.
744 nil)
745 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
746 ;; Simple form: "-*- MODENAME -*-".
747 (setq result
748 (list (cons 'mode
749 (intern (buffer-substring
750 (match-beginning 1)
751 (match-end 1)))))))
753 ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
754 ;; (last ";" is optional).
755 (save-excursion
756 (if (search-forward "-*-" end t)
757 (setq end (- (point) 3))
758 (error "-*- not terminated before end of line")))
759 (while (< (point) end)
760 (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
761 (error "malformed -*- line"))
762 (goto-char (match-end 0))
763 (let ((key (intern (downcase (buffer-substring
764 (match-beginning 1)
765 (match-end 1)))))
766 (val (save-restriction
767 (narrow-to-region (point) end)
768 (read (current-buffer)))))
769 (setq result (cons (cons key val) result))
770 (skip-chars-forward " \t;")))
771 (setq result (nreverse result))))
773 ;; Mode is magic.
774 (let (mode)
775 (while (setq mode (assq 'mode result))
776 (setq mode-p t result (delq mode result))
777 (funcall (intern (concat (downcase (symbol-name (cdr mode)))
778 "-mode")))))
780 (if (and result
781 (or (eq enable-local-variables t)
782 (and enable-local-variables
783 (save-window-excursion
784 (switch-to-buffer (current-buffer))
785 (y-or-n-p (format "Set local variables as specified in -*- line of %s? "
786 (file-name-nondirectory buffer-file-name)))))))
787 (while result
788 (let ((key (car (car result)))
789 (val (cdr (car result))))
790 ;; 'mode has already been removed from this list.
791 (hack-one-local-variable key val))
792 (setq result (cdr result))))
793 mode-p)))
795 (defun hack-local-variables ()
796 "Parse and put into effect this buffer's local variables spec."
797 (hack-local-variables-prop-line)
798 ;; Look for "Local variables:" line in last page.
799 (save-excursion
800 (goto-char (point-max))
801 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
802 (if (let ((case-fold-search t))
803 (and (search-forward "Local Variables:" nil t)
804 (or (eq enable-local-variables t)
805 (and enable-local-variables
806 (save-window-excursion
807 (switch-to-buffer (current-buffer))
808 (save-excursion
809 (beginning-of-line)
810 (set-window-start (selected-window) (point)))
811 (y-or-n-p (format "Set local variables as specified at end of %s? "
812 (file-name-nondirectory buffer-file-name))))))))
813 (let ((continue t)
814 prefix prefixlen suffix beg
815 (enable-local-eval enable-local-eval))
816 ;; The prefix is what comes before "local variables:" in its line.
817 ;; The suffix is what comes after "local variables:" in its line.
818 (skip-chars-forward " \t")
819 (or (eolp)
820 (setq suffix (buffer-substring (point)
821 (progn (end-of-line) (point)))))
822 (goto-char (match-beginning 0))
823 (or (bolp)
824 (setq prefix
825 (buffer-substring (point)
826 (progn (beginning-of-line) (point)))))
828 (if prefix (setq prefixlen (length prefix)
829 prefix (regexp-quote prefix)))
830 (if suffix (setq suffix (concat (regexp-quote suffix) "$")))
831 (while continue
832 ;; Look at next local variable spec.
833 (if selective-display (re-search-forward "[\n\C-m]")
834 (forward-line 1))
835 ;; Skip the prefix, if any.
836 (if prefix
837 (if (looking-at prefix)
838 (forward-char prefixlen)
839 (error "Local variables entry is missing the prefix")))
840 ;; Find the variable name; strip whitespace.
841 (skip-chars-forward " \t")
842 (setq beg (point))
843 (skip-chars-forward "^:\n")
844 (if (eolp) (error "Missing colon in local variables entry"))
845 (skip-chars-backward " \t")
846 (let* ((str (buffer-substring beg (point)))
847 (var (read str))
848 val)
849 ;; Setting variable named "end" means end of list.
850 (if (string-equal (downcase str) "end")
851 (setq continue nil)
852 ;; Otherwise read the variable value.
853 (skip-chars-forward "^:")
854 (forward-char 1)
855 (setq val (read (current-buffer)))
856 (skip-chars-backward "\n")
857 (skip-chars-forward " \t")
858 (or (if suffix (looking-at suffix) (eolp))
859 (error "Local variables entry is terminated incorrectly"))
860 ;; Set the variable. "Variables" mode and eval are funny.
861 (hack-one-local-variable var val))))))))
863 (defconst ignored-local-variables
864 '(enable-local-eval)
865 "Variables to be ignored in a file's local variable spec.")
867 ;; "Set" one variable in a local variables spec.
868 ;; A few variable names are treated specially.
869 (defun hack-one-local-variable (var val)
870 (cond ((eq var 'mode)
871 (funcall (intern (concat (downcase (symbol-name val))
872 "-mode"))))
873 ((memq var ignored-local-variables)
874 nil)
875 ;; "Setting" eval means either eval it or do nothing.
876 ((eq var 'eval)
877 (if (and (not (string= (user-login-name) "root"))
878 (or (eq enable-local-eval t)
879 (and enable-local-eval
880 (save-window-excursion
881 (switch-to-buffer (current-buffer))
882 (save-excursion
883 (beginning-of-line)
884 (set-window-start (selected-window) (point)))
885 (setq enable-local-eval
886 (y-or-n-p (format "Process `eval' local variable in file %s? "
887 (file-name-nondirectory buffer-file-name))))))))
888 (save-excursion (eval val))
889 (message "Ignoring `eval:' in file's local variables")))
890 ;; Ordinary variable, really set it.
891 (t (make-local-variable var)
892 (set var val))))
895 (defun set-visited-file-name (filename)
896 "Change name of file visited in current buffer to FILENAME.
897 The next time the buffer is saved it will go in the newly specified file.
898 nil or empty string as argument means make buffer not be visiting any file.
899 Remember to delete the initial contents of the minibuffer
900 if you wish to pass an empty string as the argument."
901 (interactive "FSet visited file name: ")
902 (if filename
903 (setq filename
904 (if (string-equal filename "")
906 (expand-file-name filename))))
907 (or (equal filename buffer-file-name)
908 (null filename)
909 (progn
910 (lock-buffer filename)
911 (unlock-buffer)))
912 (setq buffer-file-name filename)
913 (if filename ; make buffer name reflect filename.
914 (let ((new-name (file-name-nondirectory buffer-file-name)))
915 (if (string= new-name "")
916 (error "Empty file name"))
917 (if (eq system-type 'vax-vms)
918 (setq new-name (downcase new-name)))
919 (setq default-directory (file-name-directory buffer-file-name))
920 (rename-buffer new-name t)))
921 (setq buffer-backed-up nil)
922 (clear-visited-file-modtime)
923 (if filename
924 (progn
925 (setq buffer-file-truename
926 (abbreviate-file-name (file-truename buffer-file-name)))
927 (if find-file-visit-truename
928 (setq buffer-file-name buffer-file-truename))
929 (setq buffer-file-number (nth 10 (file-attributes buffer-file-name))))
930 (setq buffer-file-truename nil buffer-file-number nil))
931 ;; write-file-hooks is normally used for things like ftp-find-file
932 ;; that visit things that are not local files as if they were files.
933 ;; Changing to visit an ordinary local file instead should flush the hook.
934 (kill-local-variable 'write-file-hooks)
935 (kill-local-variable 'local-write-file-hooks)
936 (kill-local-variable 'revert-buffer-function)
937 (kill-local-variable 'backup-inhibited)
938 ;; Turn off backup files for certain file names.
939 ;; Since this is a permanent local, the major mode won't eliminate it.
940 (and (not (funcall backup-enable-predicate buffer-file-name))
941 (progn
942 (make-local-variable 'backup-inhibited)
943 (setq backup-inhibited t)))
944 ;; If auto-save was not already on, turn it on if appropriate.
945 (if (not buffer-auto-save-file-name)
946 (auto-save-mode (and buffer-file-name auto-save-default))
947 ;; If auto save is on, start using a new name.
948 ;; We deliberately don't rename or delete the old auto save
949 ;; for the old visited file name. This is because perhaps
950 ;; the user wants to save the new state and then compare with the
951 ;; previous state from the auto save file.
952 (setq buffer-auto-save-file-name
953 (make-auto-save-file-name)))
954 (if buffer-file-name
955 (set-buffer-modified-p t)))
957 (defun write-file (filename)
958 "Write current buffer into file FILENAME.
959 Makes buffer visit that file, and marks it not modified.
960 If the buffer is already visiting a file, you can specify
961 a directory name as FILENAME, to write a file of the same
962 old name in that directory."
963 ;; (interactive "FWrite file: ")
964 (interactive
965 (list (if buffer-file-name
966 (read-file-name "Write file: "
967 nil nil nil nil)
968 (read-file-name "Write file: "
969 (cdr (assq 'default-directory
970 (buffer-local-variables)))
971 nil nil (buffer-name)))))
972 (or (null filename) (string-equal filename "")
973 (progn
974 ;; If arg is just a directory,
975 ;; use same file name, but in that directory.
976 (if (and (file-directory-p filename) buffer-file-name)
977 (setq filename (concat (file-name-as-directory filename)
978 (file-name-nondirectory buffer-file-name))))
979 (set-visited-file-name filename)))
980 (set-buffer-modified-p t)
981 (save-buffer))
983 (defun backup-buffer ()
984 "Make a backup of the disk file visited by the current buffer, if appropriate.
985 This is normally done before saving the buffer the first time.
986 If the value is non-nil, it is the result of `file-modes' on the original
987 file; this means that the caller, after saving the buffer, should change
988 the modes of the new file to agree with the old modes."
989 (if (and make-backup-files (not backup-inhibited)
990 (not buffer-backed-up)
991 (file-exists-p buffer-file-name)
992 (memq (aref (elt (file-attributes buffer-file-name) 8) 0)
993 '(?- ?l)))
994 (let ((real-file-name buffer-file-name)
995 backup-info backupname targets setmodes)
996 ;; If specified name is a symbolic link, chase it to the target.
997 ;; Thus we make the backups in the directory where the real file is.
998 (while (let ((tem (file-symlink-p real-file-name)))
999 (if tem
1000 (setq real-file-name
1001 (expand-file-name tem
1002 (file-name-directory real-file-name))))
1003 tem))
1004 (setq backup-info (find-backup-file-name real-file-name)
1005 backupname (car backup-info)
1006 targets (cdr backup-info))
1007 ;;; (if (file-directory-p buffer-file-name)
1008 ;;; (error "Cannot save buffer in directory %s" buffer-file-name))
1009 (condition-case ()
1010 (let ((delete-old-versions
1011 ;; If have old versions to maybe delete,
1012 ;; ask the user to confirm now, before doing anything.
1013 ;; But don't actually delete til later.
1014 (and targets
1015 (or (eq trim-versions-without-asking t) (eq trim-versions-without-asking nil))
1016 (or trim-versions-without-asking
1017 (y-or-n-p (format "Delete excess backup versions of %s? "
1018 real-file-name))))))
1019 ;; Actually write the back up file.
1020 (condition-case ()
1021 (if (or file-precious-flag
1022 ; (file-symlink-p buffer-file-name)
1023 backup-by-copying
1024 (and backup-by-copying-when-linked
1025 (> (file-nlinks real-file-name) 1))
1026 (and backup-by-copying-when-mismatch
1027 (let ((attr (file-attributes real-file-name)))
1028 (or (nth 9 attr)
1029 (/= (nth 2 attr) (user-uid))))))
1030 (condition-case ()
1031 (copy-file real-file-name backupname t t)
1032 (file-error
1033 ;; If copying fails because file BACKUPNAME
1034 ;; is not writable, delete that file and try again.
1035 (if (and (file-exists-p backupname)
1036 (not (file-writable-p backupname)))
1037 (delete-file backupname))
1038 (copy-file real-file-name backupname t t)))
1039 ;; rename-file should delete old backup.
1040 (rename-file real-file-name backupname t)
1041 (setq setmodes (file-modes backupname)))
1042 (file-error
1043 ;; If trouble writing the backup, write it in ~.
1044 (setq backupname (expand-file-name "~/%backup%~"))
1045 (message "Cannot write backup file; backing up in ~/%%backup%%~")
1046 (sleep-for 1)
1047 (condition-case ()
1048 (copy-file real-file-name backupname t t)
1049 (file-error
1050 ;; If copying fails because file BACKUPNAME
1051 ;; is not writable, delete that file and try again.
1052 (if (and (file-exists-p backupname)
1053 (not (file-writable-p backupname)))
1054 (delete-file backupname))
1055 (copy-file real-file-name backupname t t)))))
1056 (setq buffer-backed-up t)
1057 ;; Now delete the old versions, if desired.
1058 (if delete-old-versions
1059 (while targets
1060 (condition-case ()
1061 (delete-file (car targets))
1062 (file-error nil))
1063 (setq targets (cdr targets))))
1064 setmodes)
1065 (file-error nil)))))
1067 (defun file-name-sans-versions (name &optional keep-backup-version)
1068 "Return FILENAME sans backup versions or strings.
1069 This is a separate procedure so your site-init or startup file can
1070 redefine it.
1071 If the optional argument KEEP-BACKUP-VERSION is non-nil,
1072 we do not remove backup version numbers, only true file version numbers."
1073 (let ((handler (find-file-name-handler name)))
1074 (if handler
1075 (funcall handler 'file-name-sans-versions name keep-backup-version)
1076 (substring name 0
1077 (if (eq system-type 'vax-vms)
1078 ;; VMS version number is (a) semicolon, optional
1079 ;; sign, zero or more digits or (b) period, option
1080 ;; sign, zero or more digits, provided this is the
1081 ;; second period encountered outside of the
1082 ;; device/directory part of the file name.
1083 (or (string-match ";[---+]?[0-9]*\\'" name)
1084 (if (string-match "\\.[^]>:]*\\(\\.[---+]?[0-9]*\\)\\'"
1085 name)
1086 (match-beginning 1))
1087 (length name))
1088 (if keep-backup-version
1089 (length name)
1090 (or (string-match "\\.~[0-9]+~\\'" name)
1091 (string-match "~\\'" name)
1092 (length name))))))))
1094 (defun make-backup-file-name (file)
1095 "Create the non-numeric backup file name for FILE.
1096 This is a separate function so you can redefine it for customization."
1097 (concat file "~"))
1099 (defun backup-file-name-p (file)
1100 "Return non-nil if FILE is a backup file name (numeric or not).
1101 This is a separate function so you can redefine it for customization.
1102 You may need to redefine `file-name-sans-versions' as well."
1103 (string-match "~$" file))
1105 ;; This is used in various files.
1106 ;; The usage of bv-length is not very clean,
1107 ;; but I can't see a good alternative,
1108 ;; so as of now I am leaving it alone.
1109 (defun backup-extract-version (fn)
1110 "Given the name of a numeric backup file, return the backup number.
1111 Uses the free variable `bv-length', whose value should be
1112 the index in the name where the version number begins."
1113 (if (and (string-match "[0-9]+~$" fn bv-length)
1114 (= (match-beginning 0) bv-length))
1115 (string-to-int (substring fn bv-length -1))
1118 ;; I believe there is no need to alter this behavior for VMS;
1119 ;; since backup files are not made on VMS, it should not get called.
1120 (defun find-backup-file-name (fn)
1121 "Find a file name for a backup file, and suggestions for deletions.
1122 Value is a list whose car is the name for the backup file
1123 and whose cdr is a list of old versions to consider deleting now."
1124 (if (eq version-control 'never)
1125 (list (make-backup-file-name fn))
1126 (let* ((base-versions (concat (file-name-nondirectory fn) ".~"))
1127 (bv-length (length base-versions))
1128 (possibilities (file-name-all-completions
1129 base-versions
1130 (file-name-directory fn)))
1131 (versions (sort (mapcar
1132 (function backup-extract-version)
1133 possibilities)
1134 '<))
1135 (high-water-mark (apply 'max 0 versions))
1136 (deserve-versions-p
1137 (or version-control
1138 (> high-water-mark 0)))
1139 (number-to-delete (- (length versions)
1140 kept-old-versions kept-new-versions -1)))
1141 (if (not deserve-versions-p)
1142 (list (make-backup-file-name fn))
1143 (cons (concat fn ".~" (int-to-string (1+ high-water-mark)) "~")
1144 (if (> number-to-delete 0)
1145 (mapcar (function (lambda (n)
1146 (concat fn ".~" (int-to-string n) "~")))
1147 (let ((v (nthcdr kept-old-versions versions)))
1148 (rplacd (nthcdr (1- number-to-delete) v) ())
1149 v))))))))
1151 (defun file-nlinks (filename)
1152 "Return number of names file FILENAME has."
1153 (car (cdr (file-attributes filename))))
1155 (defun file-relative-name-1 (directory)
1156 (cond ((string= directory "/")
1157 filename)
1158 ((string-match (concat "^" (regexp-quote directory))
1159 filename)
1160 (substring filename (match-end 0)))
1162 (file-relative-name-1
1163 (file-name-directory (substring directory 0 -1))))))
1165 (defun file-relative-name (filename &optional directory)
1166 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
1167 (setq filename (expand-file-name filename)
1168 directory (file-name-as-directory (if directory
1169 (expand-file-name directory)
1170 default-directory)))
1171 (file-relative-name-1 directory))
1173 (defun save-buffer (&optional args)
1174 "Save current buffer in visited file if modified. Versions described below.
1175 By default, makes the previous version into a backup file
1176 if previously requested or if this is the first save.
1177 With 1 or 3 \\[universal-argument]'s, marks this version
1178 to become a backup when the next save is done.
1179 With 2 or 3 \\[universal-argument]'s,
1180 unconditionally makes the previous version into a backup file.
1181 With argument of 0, never makes the previous version into a backup file.
1183 If a file's name is FOO, the names of its numbered backup versions are
1184 FOO.~i~ for various integers i. A non-numbered backup file is called FOO~.
1185 Numeric backups (rather than FOO~) will be made if value of
1186 `version-control' is not the atom `never' and either there are already
1187 numeric versions of the file being backed up, or `version-control' is
1188 non-nil.
1189 We don't want excessive versions piling up, so there are variables
1190 `kept-old-versions', which tells Emacs how many oldest versions to keep,
1191 and `kept-new-versions', which tells how many newest versions to keep.
1192 Defaults are 2 old versions and 2 new.
1193 `dired-kept-versions' controls dired's clean-directory (.) command.
1194 If `trim-versions-without-asking' is nil, system will query user
1195 before trimming versions. Otherwise it does it silently."
1196 (interactive "p")
1197 (let ((modp (buffer-modified-p))
1198 (large (> (buffer-size) 50000))
1199 (make-backup-files (and make-backup-files (not (eq args 0)))))
1200 (and modp (memq args '(16 64)) (setq buffer-backed-up nil))
1201 (if (and modp large) (message "Saving file %s..." (buffer-file-name)))
1202 (basic-save-buffer)
1203 (and modp (memq args '(4 64)) (setq buffer-backed-up nil))))
1205 (defun delete-auto-save-file-if-necessary (&optional force)
1206 "Delete auto-save file for current buffer if `delete-auto-save-files' is t.
1207 Normally delete only if the file was written by this Emacs since
1208 the last real save, but optional arg FORCE non-nil means delete anyway."
1209 (and buffer-auto-save-file-name delete-auto-save-files
1210 (not (string= buffer-file-name buffer-auto-save-file-name))
1211 (or force (recent-auto-save-p))
1212 (progn
1213 (condition-case ()
1214 (delete-file buffer-auto-save-file-name)
1215 (file-error nil))
1216 (set-buffer-auto-saved))))
1218 (defun basic-save-buffer ()
1219 "Save the current buffer in its visited file, if it has been modified."
1220 (interactive)
1221 (if (buffer-modified-p)
1222 (let ((recent-save (recent-auto-save-p))
1223 setmodes tempsetmodes)
1224 ;; On VMS, rename file and buffer to get rid of version number.
1225 (if (and (eq system-type 'vax-vms)
1226 (not (string= buffer-file-name
1227 (file-name-sans-versions buffer-file-name))))
1228 (let (buffer-new-name)
1229 ;; Strip VMS version number before save.
1230 (setq buffer-file-name
1231 (file-name-sans-versions buffer-file-name))
1232 ;; Construct a (unique) buffer name to correspond.
1233 (let ((buf (create-file-buffer (downcase buffer-file-name))))
1234 (setq buffer-new-name (buffer-name buf))
1235 (kill-buffer buf))
1236 (rename-buffer buffer-new-name)))
1237 ;; If buffer has no file name, ask user for one.
1238 (or buffer-file-name
1239 (progn
1240 (setq buffer-file-name
1241 (expand-file-name (read-file-name "File to save in: ") nil)
1242 default-directory (file-name-directory buffer-file-name))
1243 (auto-save-mode auto-save-default)))
1244 (or (verify-visited-file-modtime (current-buffer))
1245 (not (file-exists-p buffer-file-name))
1246 (yes-or-no-p
1247 (format "%s has changed since visited or saved. Save anyway? "
1248 (file-name-nondirectory buffer-file-name)))
1249 (error "Save not confirmed"))
1250 (save-restriction
1251 (widen)
1252 (and (> (point-max) 1)
1253 (/= (char-after (1- (point-max))) ?\n)
1254 (or (eq require-final-newline t)
1255 (and require-final-newline
1256 (y-or-n-p
1257 (format "Buffer %s does not end in newline. Add one? "
1258 (buffer-name)))))
1259 (save-excursion
1260 (goto-char (point-max))
1261 (insert ?\n)))
1262 (let ((hooks (append write-contents-hooks local-write-file-hooks
1263 write-file-hooks))
1264 (done nil))
1265 (while (and hooks
1266 (not (setq done (funcall (car hooks)))))
1267 (setq hooks (cdr hooks)))
1268 ;; If a hook returned t, file is already "written".
1269 (cond ((not done)
1270 (if (not (file-writable-p buffer-file-name))
1271 (let ((dir (file-name-directory buffer-file-name)))
1272 (if (not (file-directory-p dir))
1273 (error "%s is not a directory" dir)
1274 (if (not (file-exists-p buffer-file-name))
1275 (error "Directory %s write-protected" dir)
1276 (if (yes-or-no-p
1277 (format "File %s is write-protected; try to save anyway? "
1278 (file-name-nondirectory
1279 buffer-file-name)))
1280 (setq tempsetmodes t)
1281 (error "Attempt to save to a file which you aren't allowed to write"))))))
1282 (or buffer-backed-up
1283 (setq setmodes (backup-buffer)))
1284 (if file-precious-flag
1285 ;; If file is precious, write temp name, then rename it.
1286 (let ((dir (file-name-directory buffer-file-name))
1287 (realname buffer-file-name)
1288 tempname temp nogood i succeed)
1289 (setq i 0)
1290 (setq nogood t)
1291 ;; Find the temporary name to write under.
1292 (while nogood
1293 (setq tempname (format "%s#tmp#%d" dir i))
1294 (setq nogood (file-exists-p tempname))
1295 (setq i (1+ i)))
1296 (unwind-protect
1297 (progn (clear-visited-file-modtime)
1298 (write-region (point-min) (point-max)
1299 tempname nil realname)
1300 (setq succeed t))
1301 ;; If writing the temp file fails,
1302 ;; delete the temp file.
1303 (or succeed (delete-file tempname)))
1304 ;; Since we have created an entirely new file
1305 ;; and renamed it, make sure it gets the
1306 ;; right permission bits set.
1307 (setq setmodes (file-modes buffer-file-name))
1308 ;; We succeeded in writing the temp file,
1309 ;; so rename it.
1310 (rename-file tempname buffer-file-name t))
1311 ;; If file not writable, see if we can make it writable
1312 ;; temporarily while we write it.
1313 ;; But no need to do so if we have just backed it up
1314 ;; (setmodes is set) because that says we're superseding.
1315 (cond ((and tempsetmodes (not setmodes))
1316 ;; Change the mode back, after writing.
1317 (setq setmodes (file-modes buffer-file-name))
1318 (set-file-modes buffer-file-name 511)))
1319 (write-region (point-min) (point-max)
1320 buffer-file-name nil t)))))
1321 (setq buffer-file-number (nth 10 (file-attributes buffer-file-name)))
1322 (if setmodes
1323 (condition-case ()
1324 (set-file-modes buffer-file-name setmodes)
1325 (error nil))))
1326 ;; If the auto-save file was recent before this command,
1327 ;; delete it now.
1328 (delete-auto-save-file-if-necessary recent-save)
1329 (run-hooks 'after-save-hooks))
1330 (message "(No changes need to be saved)")))
1332 (defun save-some-buffers (&optional arg exiting)
1333 "Save some modified file-visiting buffers. Asks user about each one.
1334 Optional argument (the prefix) non-nil means save all with no questions.
1335 Optional second argument EXITING means ask about certain non-file buffers
1336 as well as about file buffers."
1337 (interactive "P")
1338 (save-window-excursion
1339 (if (zerop (map-y-or-n-p
1340 (function
1341 (lambda (buffer)
1342 (and (buffer-modified-p buffer)
1344 (buffer-file-name buffer)
1345 (and exiting
1346 (progn
1347 (set-buffer buffer)
1348 (and buffer-offer-save (> (buffer-size) 0)))))
1349 (if arg
1351 (if (buffer-file-name buffer)
1352 (format "Save file %s? "
1353 (buffer-file-name buffer))
1354 (format "Save buffer %s? "
1355 (buffer-name buffer)))))))
1356 (function
1357 (lambda (buffer)
1358 (set-buffer buffer)
1359 (save-buffer)))
1360 (buffer-list)
1361 '("buffer" "buffers" "save")
1362 (list (list ?\C-r (lambda (buf)
1363 (view-buffer buf)
1364 (setq view-exit-action
1365 '(lambda (ignore)
1366 (exit-recursive-edit)))
1367 (recursive-edit)
1368 ;; Return nil to ask about BUF again.
1369 nil)
1370 "display the current buffer"))
1372 (message "(No files need saving)"))))
1374 (defun not-modified (&optional arg)
1375 "Mark current buffer as unmodified, not needing to be saved.
1376 With prefix arg, mark buffer as modified, so \\[save-buffer] will save."
1377 (interactive "P")
1378 (message (if arg "Modification-flag set"
1379 "Modification-flag cleared"))
1380 (set-buffer-modified-p arg))
1382 (defun toggle-read-only (&optional arg)
1383 "Change whether this buffer is visiting its file read-only.
1384 With arg, set read-only iff arg is positive."
1385 (interactive "P")
1386 (setq buffer-read-only
1387 (if (null arg)
1388 (not buffer-read-only)
1389 (> (prefix-numeric-value arg) 0)))
1390 ;; Force mode-line redisplay
1391 (set-buffer-modified-p (buffer-modified-p)))
1393 (defun insert-file (filename)
1394 "Insert contents of file FILENAME into buffer after point.
1395 Set mark after the inserted text.
1397 This function is meant for the user to run interactively.
1398 Don't call it from programs! Use `insert-file-contents' instead.
1399 \(Its calling sequence is different; see its documentation)."
1400 (interactive "fInsert file: ")
1401 (let ((tem (insert-file-contents filename)))
1402 (push-mark (+ (point) (car (cdr tem))))))
1404 (defun append-to-file (start end filename)
1405 "Append the contents of the region to the end of file FILENAME.
1406 When called from a function, expects three arguments,
1407 START, END and FILENAME. START and END are buffer positions
1408 saying what text to write."
1409 (interactive "r\nFAppend to file: ")
1410 (write-region start end filename t))
1412 (defun file-newest-backup (filename)
1413 "Return most recent backup file for FILENAME or nil if no backups exist."
1414 (let* ((filename (expand-file-name filename))
1415 (file (file-name-nondirectory filename))
1416 (dir (file-name-directory filename))
1417 (comp (file-name-all-completions file dir))
1418 newest)
1419 (while comp
1420 (setq file (concat dir (car comp))
1421 comp (cdr comp))
1422 (if (and (backup-file-name-p file)
1423 (or (null newest) (file-newer-than-file-p file newest)))
1424 (setq newest file)))
1425 newest))
1427 (defun rename-uniquely ()
1428 "Rename current buffer to a similar name not already taken.
1429 This function is useful for creating multiple shell process buffers
1430 or multiple mail buffers, etc."
1431 (interactive)
1432 (let* ((new-buf (generate-new-buffer (buffer-name)))
1433 (name (buffer-name new-buf)))
1434 (kill-buffer new-buf)
1435 (rename-buffer name)
1436 (set-buffer-modified-p (buffer-modified-p)))) ; force mode line update
1438 (defun make-directory (dir &optional parents)
1439 "Create the directory DIR and any nonexistent parent dirs."
1440 (interactive "FMake directory: \nP")
1441 (let ((handler (find-file-name-handler dir)))
1442 (if handler
1443 (funcall handler 'make-directory dir parents)
1444 (if (not parents)
1445 (make-directory-internal dir)
1446 (let ((dir (directory-file-name (expand-file-name dir)))
1447 create-list)
1448 (while (not (file-exists-p dir))
1449 (setq create-list (cons dir create-list)
1450 dir (directory-file-name (file-name-directory dir))))
1451 (while create-list
1452 (make-directory-internal (car create-list))
1453 (setq create-list (cdr create-list))))))))
1455 (put 'revert-buffer-function 'permanent-local t)
1456 (defvar revert-buffer-function nil
1457 "Function to use to revert this buffer, or nil to do the default.")
1459 (put 'revert-buffer-insert-file-contents-function 'permanent-local t)
1460 (defvar revert-buffer-insert-file-contents-function nil
1461 "Function to use to insert contents when reverting this buffer.
1462 Gets two args, first the nominal file name to use,
1463 and second, t if reading the auto-save file.")
1465 (defun revert-buffer (&optional ignore-auto noconfirm)
1466 "Replace the buffer text with the text of the visited file on disk.
1467 This undoes all changes since the file was visited or saved.
1468 With a prefix argument, offer to revert from latest auto-save file, if
1469 that is more recent than the visited file.
1471 When called from lisp, the first argument is IGNORE-AUTO; only offer
1472 to revert from the auto-save file when this is nil. Note that the
1473 sense of this argument is the reverse of the prefix argument, for the
1474 sake of backward compatibility. IGNORE-AUTO is optional, defaulting
1475 to nil.
1477 Optional second argument NOCONFIRM means don't ask for confirmation at
1478 all.
1480 If the value of `revert-buffer-function' is non-nil, it is called to
1481 do the work."
1482 ;; I admit it's odd to reverse the sense of the prefix argument, but
1483 ;; there is a lot of code out there which assumes that the first
1484 ;; argument should be t to avoid consulting the auto-save file, and
1485 ;; there's no straightforward way to encourage authors to notice a
1486 ;; reversal of the argument sense. So I'm just changing the user
1487 ;; interface, but leaving the programmatic interface the same.
1488 (interactive (list (not prefix-arg)))
1489 (if revert-buffer-function
1490 (funcall revert-buffer-function ignore-auto noconfirm)
1491 (let* ((opoint (point))
1492 (auto-save-p (and (not ignore-auto)
1493 (recent-auto-save-p)
1494 buffer-auto-save-file-name
1495 (file-readable-p buffer-auto-save-file-name)
1496 (y-or-n-p
1497 "Buffer has been auto-saved recently. Revert from auto-save file? ")))
1498 (file-name (if auto-save-p
1499 buffer-auto-save-file-name
1500 buffer-file-name)))
1501 (cond ((null file-name)
1502 (error "Buffer does not seem to be associated with any file"))
1503 ((or noconfirm
1504 (yes-or-no-p (format "Revert buffer from file %s? "
1505 file-name)))
1506 ;; If file was backed up but has changed since,
1507 ;; we shd make another backup.
1508 (and (not auto-save-p)
1509 (not (verify-visited-file-modtime (current-buffer)))
1510 (setq buffer-backed-up nil))
1511 ;; Get rid of all undo records for this buffer.
1512 (or (eq buffer-undo-list t)
1513 (setq buffer-undo-list nil))
1514 (let ((buffer-read-only nil)
1515 ;; Don't make undo records for the reversion.
1516 (buffer-undo-list t))
1517 (if revert-buffer-insert-file-contents-function
1518 (funcall revert-buffer-insert-file-contents-function
1519 file-name auto-save-p)
1520 (if (not (file-exists-p file-name))
1521 (error "File %s no longer exists!" file-name))
1522 ;; Bind buffer-file-name to nil
1523 ;; so that we don't try to lock the file.
1524 (let ((buffer-file-name nil))
1525 (or auto-save-p
1526 (unlock-buffer))
1527 (erase-buffer))
1528 (insert-file-contents file-name (not auto-save-p))))
1529 (goto-char (min opoint (point-max)))
1530 (after-find-file nil nil t)
1531 t)))))
1533 (defun recover-file (file)
1534 "Visit file FILE, but get contents from its last auto-save file."
1535 (interactive
1536 (let ((prompt-file buffer-file-name)
1537 (file-name nil)
1538 (file-dir nil))
1539 (and prompt-file
1540 (setq file-name (file-name-nondirectory prompt-file)
1541 file-dir (file-name-directory prompt-file)))
1542 (list (read-file-name "Recover file: "
1543 file-dir nil nil file-name))))
1544 (setq file (expand-file-name file))
1545 (if (auto-save-file-name-p file) (error "%s is an auto-save file" file))
1546 (let ((file-name (let ((buffer-file-name file))
1547 (make-auto-save-file-name))))
1548 (cond ((not (file-newer-than-file-p file-name file))
1549 (error "Auto-save file %s not current" file-name))
1550 ((save-window-excursion
1551 (if (not (eq system-type 'vax-vms))
1552 (with-output-to-temp-buffer "*Directory*"
1553 (buffer-disable-undo standard-output)
1554 (call-process "ls" nil standard-output nil
1555 (if (file-symlink-p file) "-lL" "-l")
1556 file file-name)))
1557 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
1558 (switch-to-buffer (find-file-noselect file t))
1559 (let ((buffer-read-only nil))
1560 (erase-buffer)
1561 (insert-file-contents file-name nil))
1562 (after-find-file nil nil t))
1563 (t (error "Recover-file cancelled.")))))
1565 (defun kill-some-buffers ()
1566 "For each buffer, ask whether to kill it."
1567 (interactive)
1568 (let ((list (buffer-list)))
1569 (while list
1570 (let* ((buffer (car list))
1571 (name (buffer-name buffer)))
1572 (and (not (string-equal name ""))
1573 (/= (aref name 0) ? )
1574 (yes-or-no-p
1575 (format "Buffer %s %s. Kill? "
1576 name
1577 (if (buffer-modified-p buffer)
1578 "HAS BEEN EDITED" "is unmodified")))
1579 (kill-buffer buffer)))
1580 (setq list (cdr list)))))
1582 (defun auto-save-mode (arg)
1583 "Toggle auto-saving of contents of current buffer.
1584 With prefix argument ARG, turn auto-saving on if positive, else off."
1585 (interactive "P")
1586 (setq buffer-auto-save-file-name
1587 (and (if (null arg)
1588 (not buffer-auto-save-file-name)
1589 (or (eq arg t) (listp arg) (and (integerp arg) (> arg 0))))
1590 (if (and buffer-file-name auto-save-visited-file-name
1591 (not buffer-read-only))
1592 buffer-file-name
1593 (make-auto-save-file-name))))
1594 (if (interactive-p)
1595 (message "Auto-save %s (in this buffer)"
1596 (if buffer-auto-save-file-name "on" "off")))
1597 buffer-auto-save-file-name)
1599 (defun rename-auto-save-file ()
1600 "Adjust current buffer's auto save file name for current conditions.
1601 Also rename any existing auto save file, if it was made in this session."
1602 (let ((osave buffer-auto-save-file-name))
1603 (setq buffer-auto-save-file-name
1604 (make-auto-save-file-name))
1605 (if (and osave buffer-auto-save-file-name
1606 (not (string= buffer-auto-save-file-name buffer-file-name))
1607 (not (string= buffer-auto-save-file-name osave))
1608 (file-exists-p osave)
1609 (recent-auto-save-p))
1610 (rename-file osave buffer-auto-save-file-name t))))
1612 (defun make-auto-save-file-name ()
1613 "Return file name to use for auto-saves of current buffer.
1614 Does not consider `auto-save-visited-file-name' as that variable is checked
1615 before calling this function. You can redefine this for customization.
1616 See also `auto-save-file-name-p'."
1617 (if buffer-file-name
1618 (concat (file-name-directory buffer-file-name)
1620 (file-name-nondirectory buffer-file-name)
1621 "#")
1622 ;; For non-file bfr, use bfr name and Emacs pid.
1623 (expand-file-name (format "#%s#%s#" (buffer-name) (make-temp-name "")))))
1625 (defun auto-save-file-name-p (filename)
1626 "Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'.
1627 FILENAME should lack slashes. You can redefine this for customization."
1628 (string-match "^#.*#$" filename))
1630 (defconst list-directory-brief-switches
1631 (if (eq system-type 'vax-vms) "" "-CF")
1632 "*Switches for list-directory to pass to `ls' for brief listing,")
1634 (defconst list-directory-verbose-switches
1635 (if (eq system-type 'vax-vms)
1636 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)"
1637 "-l")
1638 "*Switches for list-directory to pass to `ls' for verbose listing,")
1640 (defun list-directory (dirname &optional verbose)
1641 "Display a list of files in or matching DIRNAME, a la `ls'.
1642 DIRNAME is globbed by the shell if necessary.
1643 Prefix arg (second arg if noninteractive) means supply -l switch to `ls'.
1644 Actions controlled by variables `list-directory-brief-switches'
1645 and `list-directory-verbose-switches'."
1646 (interactive (let ((pfx current-prefix-arg))
1647 (list (read-file-name (if pfx "List directory (verbose): "
1648 "List directory (brief): ")
1649 nil default-directory nil)
1650 pfx)))
1651 (let ((switches (if verbose list-directory-verbose-switches
1652 list-directory-brief-switches)))
1653 (or dirname (setq dirname default-directory))
1654 (setq dirname (expand-file-name dirname))
1655 (with-output-to-temp-buffer "*Directory*"
1656 (buffer-disable-undo standard-output)
1657 (princ "Directory ")
1658 (princ dirname)
1659 (terpri)
1660 (save-excursion
1661 (set-buffer "*Directory*")
1662 (let ((wildcard (not (file-directory-p dirname))))
1663 (insert-directory dirname switches wildcard (not wildcard)))))))
1665 (defvar insert-directory-program "ls"
1666 "Absolute or relative name of the `ls' program used by `insert-directory'.")
1668 ;; insert-directory
1669 ;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
1670 ;; FULL-DIRECTORY-P is nil.
1671 ;; The single line of output must display FILE's name as it was
1672 ;; given, namely, an absolute path name.
1673 ;; - must insert exactly one line for each file if WILDCARD or
1674 ;; FULL-DIRECTORY-P is t, plus one optional "total" line
1675 ;; before the file lines, plus optional text after the file lines.
1676 ;; Lines are delimited by "\n", so filenames containing "\n" are not
1677 ;; allowed.
1678 ;; File lines should display the basename.
1679 ;; - must be consistent with
1680 ;; - functions dired-move-to-filename, (these two define what a file line is)
1681 ;; dired-move-to-end-of-filename,
1682 ;; dired-between-files, (shortcut for (not (dired-move-to-filename)))
1683 ;; dired-insert-headerline
1684 ;; dired-after-subdir-garbage (defines what a "total" line is)
1685 ;; - variable dired-subdir-regexp
1686 (defun insert-directory (file switches &optional wildcard full-directory-p)
1687 "Insert directory listing for of FILE, formatted according to SWITCHES.
1688 Leaves point after the inserted text.
1689 Optional third arg WILDCARD means treat FILE as shell wildcard.
1690 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
1691 switches do not contain `d', so that a full listing is expected.
1693 This works by running a directory listing program
1694 whose name is in the variable `insert-directory-program'.
1695 If WILDCARD, it also runs the shell specified by `shell-file-name'."
1696 (let ((handler (find-file-name-handler file)))
1697 (if handler
1698 (funcall handler 'insert-directory file switches
1699 wildcard full-directory-p)
1700 (if (eq system-type 'vax-vms)
1701 (vms-read-directory file switches (current-buffer))
1702 (if wildcard
1703 (let ((default-directory (file-name-directory file)))
1704 (call-process shell-file-name nil t nil
1705 "-c" (concat insert-directory-program
1706 " -d " switches " "
1707 (file-name-nondirectory file))))
1708 ;; Chase links till we reach a non-link.
1709 ;; This used to be commented out, but Barry Margolin says:
1710 ;; SunOS 4.1.3 (and SV and POSIX?) lists the link
1711 ;; if we give a link to a directory - yuck!
1712 (let (symlink)
1713 (while (setq symlink (file-symlink-p file))
1714 (setq file symlink)))
1715 (call-process insert-directory-program nil t nil switches file))))))
1717 (defun save-buffers-kill-emacs (&optional arg)
1718 "Offer to save each buffer, then kill this Emacs process.
1719 With prefix arg, silently save all file-visiting buffers, then kill."
1720 (interactive "P")
1721 (save-some-buffers arg t)
1722 (and (or (not (memq t (mapcar (function
1723 (lambda (buf) (and (buffer-file-name buf)
1724 (buffer-modified-p buf))))
1725 (buffer-list))))
1726 (yes-or-no-p "Modified buffers exist; exit anyway? "))
1727 (or (not (fboundp 'process-list))
1728 ;; process-list is not defined on VMS.
1729 (let ((processes (process-list))
1730 active)
1731 (while processes
1732 (and (memq (process-status (car processes)) '(run stop open))
1733 (let ((val (process-kill-without-query (car processes))))
1734 (process-kill-without-query (car processes) val)
1735 val)
1736 (setq active t))
1737 (setq processes (cdr processes)))
1738 (or (not active)
1739 (yes-or-no-p "Active processes exist; kill them and exit anyway? "))))
1740 (kill-emacs)))
1742 (define-key ctl-x-map "\C-f" 'find-file)
1743 (define-key ctl-x-map "\C-q" 'toggle-read-only)
1744 (define-key ctl-x-map "\C-r" 'find-file-read-only)
1745 (define-key ctl-x-map "\C-v" 'find-alternate-file)
1746 (define-key ctl-x-map "\C-s" 'save-buffer)
1747 (define-key ctl-x-map "s" 'save-some-buffers)
1748 (define-key ctl-x-map "\C-w" 'write-file)
1749 (define-key ctl-x-map "i" 'insert-file)
1750 (define-key esc-map "~" 'not-modified)
1751 (define-key ctl-x-map "\C-d" 'list-directory)
1752 (define-key ctl-x-map "\C-c" 'save-buffers-kill-emacs)
1754 (define-key ctl-x-4-map "f" 'find-file-other-window)
1755 (define-key ctl-x-4-map "r" 'find-file-read-only-other-window)
1756 (define-key ctl-x-4-map "\C-f" 'find-file-other-window)
1757 (define-key ctl-x-4-map "b" 'switch-to-buffer-other-window)
1758 (define-key ctl-x-4-map "\C-o" 'display-buffer)
1760 (define-key ctl-x-5-map "b" 'switch-to-buffer-other-frame)
1761 (define-key ctl-x-5-map "f" 'find-file-other-frame)
1762 (define-key ctl-x-5-map "\C-f" 'find-file-other-frame)
1763 (define-key ctl-x-5-map "r" 'find-file-read-only-other-frame)
1765 ;;; files.el ends here