4.3BSD/usr/contrib/emacs/lisp/files.elc


(defconst delete-auto-save-files t "*Non-nil means delete a buffer's auto-save file
when the buffer is saved for real.")

(defconst make-backup-files t "*Create a backup of each file when it is saved for the first time.
This can be done by renaming the file or by copying, according to the
values of  backup-by-copying  and   backup-by-copying-when-linked.")

(defconst backup-by-copying nil "*Non-nil means create backups of files by copying rather than by renaming.")

(defconst backup-by-copying-when-linked nil "*Non-nil means create backups of multi-named files by copying
rather than by renaming.
This causes the alternate names to refer to the latest version as edited.")

(defvar version-control nil "*Control use of version numbers for backup files.
t means make numeric backup versions unconditionally.
nil means make them for files that have some already.
never means do not make them.")

(defvar dired-kept-versions 2 "*When cleaning directory, number of versions to keep.")

(defvar trim-versions-without-asking nil "*If true, deletes excess backup versions silently.
Otherwise asks confirmation.")

(defvar kept-old-versions 2 "*Number of oldest versions to keep when a new numbered backup is made.")

(defvar kept-new-versions 2 "*Number of newest versions to keep when a new numbered backup is made.
Includes the new backup.  Must be > 0")

(defconst require-final-newline nil "*t says silently put a newline at the end whenever a file is saved.
Non-nil but not t says ask user whether to add a newline in each such case.
nil means don't add newlines.")

(defconst auto-save-default t "*t says by default do auto-saving of every file-visiting buffer.")

(defconst auto-save-visited-file-name nil "*t says auto-save a buffer in the file it is visiting, when practical.
Normally auto-save files are written under other names.")

(defconst save-abbrevs t "*Non-nil means save word abbrevs too when files are saved.")

(defconst find-file-run-dired t "*Non-nil says run dired if find-file is given the name of a directory.")

(defvar find-file-not-found-hook nil "*If non-nil specifies a function to be called for find-file on nonexistent file.
This function is called as soon as the error is detected.
buffer-file-name is already set up.")

(defvar find-file-hook nil "*If non-nil specifies a function to be called after a buffer
is found or reverted from a file.
The buffer's local variables (if any) will have been processed before the
function is called.")

(defvar write-file-hook nil "*If non-nil specifies a function to be called before writing out a buffer
to a file.")

(or (fboundp (quote lock-buffer)) (fset (quote lock-buffer) (quote ignore)))

(or (fboundp (quote unlock-buffer)) (fset (quote unlock-buffer) (quote ignore)))

(defun pwd nil "\
Show the current default directory." (interactive nil) (byte-code "	\"" [nil default-directory message "Directory %s"] 3))

(defun cd (dir) "\
Make DIR become the current buffer's default directory." (interactive "DChange default directory: ") (byte-code "ˆ!\"P!?#\"& " [dir default-directory nil expand-file-name string-match "/$" "/" file-directory-p error "%s is not a directory" pwd] 6))

(defun switch-to-buffer-other-window (buffer) "\
Select buffer BUFFER in another window." (interactive "BSwitch to buffer in other window: ") (byte-code "È	
	\")" [pop-up-windows t buffer nil pop-to-buffer] 3))

(defun find-file (filename) "\
Edit file FILENAME.
Switch to a buffer visiting file FILENAME,
creating one if none already exists." (interactive "FFind file: ") (byte-code "!!" [filename nil switch-to-buffer find-file-noselect] 3))

(defun find-file-other-window (filename) "\
Edit file FILENAME, in another window.
May create a new window, or reuse an existing one;
see the function display-buffer." (interactive "FFind file in other window: ") (byte-code "!!" [filename nil switch-to-buffer-other-window find-file-noselect] 3))

(defun find-file-read-only (filename) "\
Edit file FILENAME but don't save without confirmation.
Like find-file but marks buffer as read-only." (interactive "fFind file read-only: ") (byte-code "È!
" [filename buffer-read-only t nil find-file] 3))

(defun find-alternate-file (filename) "\
Find file FILENAME, select its buffer, kill previous buffer.
If the current buffer now contains an empty file that you just visited
(presumably by mistake), use this command to visit the file you really want." (interactive "FFind alternate file: ") (byte-code "Ĉ?
!Ĉ \" \"!?\"!p !Ў 
!)	!+" [buffer-file-name obuf ofile oname nil filename error "Non-file buffer" buffer-modified-p yes-or-no-p format "Buffer %s is modified; kill anyway? " buffer-name "Aborted" rename-buffer " **lose**" ((byte-code "p=
 !" [obuf buffer-file-name ofile oname lock-buffer rename-buffer] 3)) unlock-buffer find-file kill-buffer] 12))

(defvar ask-about-buffer-names nil "*Non-nil means ask user for buffer name when there is a conflict.
The default is to generate a unique name with no interaction.")

(defun create-file-buffer (filename) "\
Creates a suitably named buffer for visiting FILENAME, and returns it." (byte-code "	!!
'\"!\"!\")!*!)" [base filename ask-about-buffer-names tem file-name-nondirectory get-buffer get-buffer-create read-string format "Buffer name \"%s\" is in use; type a new name, or Return to clobber: " equal "" generate-new-buffer] 8))

(defun find-file-noselect (filename) "\
Read file FILENAME into a buffer and return the buffer.
If a buffer exists visiting FILENAME, return that one,
but verify that the file has not changed since visited or saved.
The buffer is not selected, just returned to the caller." (byte-code "!	!\"{!
W
!T!?7\"8ņT
!FӂG!?T
q!)x!!
q ڏ!!)
*" [filename find-file-run-dired buf error t nil buffer-file-name find-file-not-found-hook default-directory file-directory-p dired-noselect "%s is a directory." get-file-buffer verify-visited-file-modtime file-exists-p message "Note: file %s no longer exists" yes-or-no-p buffer-modified-p "File has changed since last visited or saved.  Flush your changes? " "File has changed since last visited or saved.  Read from disk? " revert-buffer create-file-buffer expand-file-name erase-buffer (byte-code "	\"" [filename t insert-file-contents] 3) ((file-error (byte-code "	!Ƈ" [error t buffer-file-name filename find-file-not-found-hook funcall nil] 2))) file-name-directory after-find-file] 16))

(defun after-find-file (error) "\
Called after finding a file and by the default revert function.
Sets buffer mode, parses local variables, calls  find-file-hook." (byte-code "	!?
S?!ʂ˂D?*̂D	!4΂D
!>ςDD!R!SÈ " [buffer-read-only buffer-file-name noninteractive nil error default-directory t auto-save-default file-writable-p message "(New file)" "" "File is write protected" file-attributes "File exists, but is read-protected." "File not found and directory write-protected" "File not found and directory doesn't exist" auto-save-mode normal-mode] 7))

(defun normal-mode nil "\
Choose the major mode for this buffer automatically.
Also sets up any specified local variables of the file.
Uses the visited file name, the -*- line, and the local variables spec.
Finishes by calling value of find-file-hook if that's not nil." (interactive) (byte-code "ˆďƏ		!" [err find-file-hook nil (byte-code " " [set-auto-mode] 2) ((error (byte-code "!\"" [err message "Error processing file's mode specifications: %s" prin1-to-string] 4))) (byte-code " " [hack-local-variables] 2) ((error (byte-code "!\"" [err message "Error processing file's local variables: %s" prin1-to-string] 4))) funcall] 3))

(defun set-auto-mode nil "\
Select major mode appropriate for current buffer.
May base decision on visited file name (See variable  auto-mode-list)
or on buffer contents (-*- line or local variables spec), but does not look
for the \"mode:\" local variable. For that, use  hack-local-variables." (byte-code "eb!͊ `)#!`͊ `)#!!`b	#b	#){!`	#k!m	b!`\"|ɂ	\"
!P!!\"\"GO
?

@@\"
@AɈ
A)

!*)+" [beg end mode t case-fold-search alist auto-mode-alist name buffer-file-name nil skip-chars-forward " 	
" search-forward "-*-" end-of-line " 	" forward-char -3 skip-chars-backward ":" "mode:" ";" -1 buffer-substring funcall intern downcase "-mode" 0 string-match "\\.~[0-9]+~\\'" "~\\'"] 25))

(defun hack-local-variables nil "\
Parse, and bind or evaluate as appropriate, any local variables
for current buffer." (byte-code "dbdZe]#	
	#),	l3` `\"!bnF` `\"VG!Wˆg!hˆ(!!
!!ˆ!`!l!ˆ!`\"!	
!\"
#!!p!
!!!l!	=
!!P!!#	=
!#	#	!	
L+i--)" [case-fold-search t nil continue prefix prefixlen suffix beg str var val search-backward "
" 3000 move search-forward "Local Variables:" buffer-substring end-of-line match-beginning 0 beginning-of-line regexp-quote forward-line 1 looking-at forward-char error "Local variables entry is missing the prefix" skip-chars-forward " 	" "^:
" "Missing colon in local variables entry" skip-chars-backward read string-equal downcase "end" "^:" "
" "Local variables entry is terminated incorrectly" mode funcall intern symbol-name "-mode" eval make-local-variable] 37))

(defun set-visited-file-name (filename) "\
Change name of file visited in current buffer to FILENAME.
The next time the buffer is saved it will go in the newly specified file.
nil or empty string as argument means make buffer not be visiting any file." (interactive "FSet visited file name: ") (byte-code "\"	!
\"-?-! L
!
!!I
!!M	 
[
!
h!i" [filename nil buffer-file-name default-directory buffer-backed-up auto-save-default t string-equal "" expand-file-name equal lock-buffer unlock-buffer file-name-directory get-buffer file-name-nondirectory rename-buffer clear-visited-file-modtime auto-save-mode set-buffer-modified-p] 14))

(defun write-file (filename) "\
Write current buffer into file FILENAME.
Makes buffer visit that file, and marks it not modified." (interactive "FWrite file: ") (byte-code "ˆ?\"!	! " [filename t nil string-equal "" set-visited-file-name set-buffer-modified-p save-buffer] 5))

(defun backup-buffer nil "\
Make a backup of the disk file visited by the current buffer.
This is done before saving the buffer the first time." (byte-code "2	?2
!2
!\"H>2
GW+
O\"?2֏" [make-backup-files buffer-backed-up buffer-file-name nil backup-info backupname targets setmodes backup-by-copying backup-by-copying-when-linked t trim-versions-without-asking file-exists-p elt file-attributes 8 0 (45 108) 5 string-equal "/tmp/" (byte-code "	!@A	! 
  	!V,	
#=я	
#
!	S
S	\"!jg؏AVkȈ," [backup-info buffer-file-name backupname targets setmodes backup-by-copying backup-by-copying-when-linked t nil buffer-backed-up trim-versions-without-asking find-backup-file-name file-symlink-p file-nlinks 1 copy-file (byte-code "!" [backupname delete-file] 2) ((file-error (byte-code "" [nil] 1))) rename-file file-modes y-or-n-p format "Delete excess backup versions of %s? " (byte-code "@!" [targets delete-file] 2) ((file-error (byte-code "" [nil] 1)))] 12) ((file-error (byte-code "" [nil] 1)))] 8))

(defun find-backup-file-name (fn) "\
Find a file name for a backup file, and suggestions for deletions.
Value is a list whose car is the name for the backup file
 and whose cdr is a list of old versions to consider deleting now." (byte-code "=
	PC	!P
G
	!\"\"\"
B\"5V
G	
$?O	PC}	T!RV{	
\"S\"
\")\"|B." [version-control fn base-versions bv-length possibilities versions high-water-mark deserve-versions-p number-to-delete kept-old-versions kept-new-versions n v nil never "~" file-name-nondirectory ".~" file-name-all-completions file-name-directory sort mapcar backup-extract-version < apply max 0 - -1 int-to-string (lambda (n) (byte-code "	!R" [fn n ".~" int-to-string "~"] 5)) nthcdr rplacd] 16))

(defun backup-extract-version (fn) (byte-code "	O!" [fn bv-length string-to-int -1] 4))

(defun file-nlinks (filename) "\
Return number of names file FILENAME has." (byte-code "!A@" [filename file-attributes] 2))

(defun save-buffer (&optional args) "\
Save current buffer in visited file if modified.  Versions described below.

With no arg, only backs up if first save or previously motivated.
With 1 or 3 \\[universal-argument]'s, marks this version to be backed up.
With 2 or 3 \\[universal-argument]'s, unconditionally backs up previous version.

If a file's name is FOO, the names of numbered versions are
 FOO.~i~ for various integers i.
Numeric backups (rather than FOO~) will be made if value of
 version-control  is not the atom never and either there are already
 numeric versions of the file being backed up, or  version-control  is
 non-nil.
dired-kept-versions  controls dired's clean-directory (.) command.
We don't want excessive versions piling up, so variables
 kept-old-versions , which tells system how many oldest versions to
 keep, and  kept-new-versions , which tells how many new versions to
 keep, are provided.  Defaults are 2 old versions and 2 new.
If  trim-versions-without-asking  is nil, system will query user
 before trimming versions.  Otherwise it does it silently." (interactive "p") (byte-code "È 	> #	>#)" [modp args buffer-backed-up nil buffer-modified-p (4 64) basic-save-buffer (16 64)] 4))

(defun delete-auto-save-file-if-necessary nil "\
Delete the auto-save filename for the current buffer (if it has one)
if variable  delete-auto-save-files  is non-nil." (byte-code "	ď " [buffer-auto-save-file-name delete-auto-save-files nil (byte-code "!" [buffer-auto-save-file-name delete-file] 2) ((file-error (byte-code "" [nil] 1))) set-buffer-auto-saved] 3))

(defun basic-save-buffer nil "\
Save the current buffer in its visited file, if it has been modified." (interactive) (byte-code "È 
!\"
!
!?:
!\"!4
7!;Èp!R
!?R!R!\\  dVdSf\"
= \"!dbc)!	?
!
\"ed

%揂) *!" [setmodes tempsetmodes buffer-file-name nil default-directory t buffer-backed-up require-final-newline write-file-hook buffer-modified-p expand-file-name read-file-name "File to save in: " file-name-directory file-writable-p yes-or-no-p format "File %s is write-protected; try to save anyway? " file-name-nondirectory error "Attempt to save to a file which you aren't allowed to write" verify-visited-file-modtime file-exists-p "File has changed on disk since last visited or saved.  Save anyway? " "Save not confirmed" backup-buffer widen 1 /= 10 "Buffer %s does not end in newline.  Add one? " buffer-name funcall file-modes set-file-modes 511 write-region (byte-code "	\"" [buffer-file-name setmodes set-file-modes] 3) ((error (byte-code "" [nil] 1))) delete-auto-save-file-if-necessary message "(No changes need to be saved)"] 28))

(defun save-some-buffers (&optional arg) "\
Save some modified file-visiting buffers.  Asks user about each one.
With argument, saves all with no questions." (interactive "P") (byte-code "È 		@ˏ)	ACCC
8\"!C!N!Q!*" [considered list buffer nil t arg save-abbrevs abbrevs-changed abbrev-file-name buffer-list (byte-code "!(!(
(!\"!(q )" [buffer considered t arg buffer-modified-p buffer-file-name y-or-n-p format "Save file %s? " save-buffer] 7) ((error (byte-code "" [nil] 1))) y-or-n-p format "Save abbrevs in %s? " write-abbrev-file message "" "(No files need saving)"] 7))

(defun not-modified nil "\
Mark current buffer as unmodified, not needing to be saved." (interactive) (byte-code "!!" [nil message "Modification-flag cleared" set-buffer-modified-p] 3))

(defun toggle-read-only nil "\
Change whether this buffer is visiting its file read-only." (interactive) (byte-code "? !" [buffer-read-only nil set-buffer-modified-p buffer-modified-p] 3))

(defun insert-file (filename) "\
Insert contents of file FILENAME into buffer after point.
Set mark after the inserted text." (interactive "fInsert file: ") (byte-code "ˆ	!`A@\\!)" [tem filename nil insert-file-contents push-mark] 4))

(defun append-to-file (start end filename) "\
Append the contents of the region to the end of file FILENAME.
When called from a function, expects three arguments,
START, END and FILENAME.  START and END are buffer positions
saying what text to write." (interactive "r
FAppend to file: ") (byte-code "Ĉ	
$" [start end filename t nil write-region] 5))

(defvar revert-buffer-function nil "Function to use to revert this buffer, or nil to do the default.")

(defun revert-buffer (&optional arg) "\
Replace the buffer text with the text of the visited file on disk.
This undoes all changes since the file was visited or saved.
If latest auto-save file is more recent than the visited file,
asks user whether to use that instead, unless a non-nil argument is given.

If revert-buffer-function's value is non-nil, it is called to do the work." (interactive "P") (byte-code "Ȉ
	\"s`	? !%
'?3!r!?A\"r\"!rX  )?\")!	r
d^b+" [revert-buffer-function arg opoint auto-save-p file-name buffer-auto-save-file-name buffer-file-name buffer-read-only nil find-file-hook funcall recent-auto-save-p y-or-n-p "Buffer has been auto-saved recently.  Revert from auto-save file? " error "Buffer does not seem to be associated with any file" file-exists-p "File %s no longer exists!" yes-or-no-p format "Revert buffer from file %s? " unlock-buffer erase-buffer insert-file-contents after-find-file] 14))

(defun recover-file (file) "\
Visit file FILE, then get contents from its last auto-save file." (interactive "FRecover file: ") (byte-code "È! 	!?	\".	\"!. 	\")!)!" [file file-name buffer-read-only nil buffer-auto-save-file-name find-file make-auto-save-file-name file-exists-p error "Auto-save file %s does not exist" yes-or-no-p format "Recover buffer from file %s? " erase-buffer insert-file-contents after-find-file message "Auto-save turned off, for now, in this buffer"] 11))

(defun kill-some-buffers nil "\
For each buffer, ask whether to kill it." (interactive) (byte-code "È B@	!
\"?8
H\"8
	!/ς0#!8	!*A)" [list buffer name nil buffer-list buffer-name string-equal "" /= 0 32 yes-or-no-p format "Buffer %s %s.  Kill? " buffer-modified-p "HAS BEEN EDITED" "is unmodified" kill-buffer] 11))

(defun auto-save-mode (arg) "\
Toggle auto-saving of contents of current buffer.
With arg, turn auto-saving on if arg is positive, else off." (interactive "P") (byte-code "ƈ	?? 	
= 	< 	! 	V6--
?46 " [buffer-auto-save-file-name arg t buffer-file-name auto-save-visited-file-name buffer-read-only nil integerp 0 make-auto-save-file-name] 4))

(defun make-auto-save-file-name nil "\
Return file name to use for auto-saves of current buffer.
Does not consider auto-save-visited-file-name; that is checked
before calling this function.
This is a separate function so your .emacs file or site-init.el can redefine it.
See also auto-save-file-name-p." (byte-code "!!Q P!" [buffer-file-name file-name-directory "#" file-name-nondirectory expand-file-name "#%" buffer-name] 6))

(defun auto-save-file-name-p (filename) "\
Return t if FILENAME can be yielded by make-auto-save-file-name.
FILENAME should lack slashes.
This is a separate function so your .emacs file or site-init.el can redefine it." (byte-code "\"" [filename string-match "^#"] 3))

(defconst list-directory-brief-switches "-CF" "*Switches for list-directory to pass to `ls' for brief listing,")

(defconst list-directory-verbose-switches "-l" "*Switches for list-directory to pass to `ls' for verbose listing,")

(defun list-directory (dirname &optional verbose) "\
Display a list of files in or matching DIRNAME, a la `ls'.
DIRNAME is globbed by the shell if necessary.
Prefix arg (second arg if noninteractive) means supply -l switch to `ls'.
Actions controlled by variables list-directory-brief-switches
 and list-directory-verbose-switches." (interactive (byte-code "	ł

$D)" [pfx current-prefix-arg nil default-directory read-file-name "List directory (verbose): " "List directory (brief): "] 5)) (byte-code "ˆ

			!:
	\"7	P	;ˆ	!	Ґ!!	! j

	&	!

	!R&)*" [pfx current-prefix-arg nil default-directory switches verbose list-directory-verbose-switches list-directory-brief-switches full-dir-p dirname t standard-output shell-file-name file-directory-p string-match "/$" "/" expand-file-name "*Directory*" buffer-flush-undo princ "Directory " terpri call-process "/bin/ls" file-name-directory "-c" "exec /bin/ls " " " file-name-nondirectory] 21))

(defun save-buffers-kill-emacs nil "\
Offer to save each buffer, then kill this Emacs fork." (interactive) (byte-code "  " [nil save-some-buffers kill-emacs] 3))

(define-key ctl-x-map "" (quote find-file))

(define-key ctl-x-map "" (quote toggle-read-only))

(define-key ctl-x-map "" (quote find-file-read-only))

(define-key ctl-x-map "" (quote find-alternate-file))

(define-key ctl-x-map "" (quote save-buffer))

(define-key ctl-x-map "s" (quote save-some-buffers))

(define-key ctl-x-map "" (quote write-file))

(define-key ctl-x-map "i" (quote insert-file))

(define-key esc-map "~" (quote not-modified))

(define-key ctl-x-map "" (quote list-directory))

(define-key ctl-x-map "" (quote save-buffers-kill-emacs))

(defvar ctl-x-4-map (make-keymap) "Keymap for subcommands of C-x 4")

(fset (quote ctl-x-4-prefix) ctl-x-4-map)

(define-key ctl-x-map "4" (quote ctl-x-4-prefix))

(define-key ctl-x-4-map "f" (quote find-file-other-window))

(define-key ctl-x-4-map "" (quote find-file-other-window))

(define-key ctl-x-4-map "b" (quote switch-to-buffer-other-window))