$Part2: $ File_is="FILES.EL" $ Check_Sum_is=7329687 $ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY X;; File input and output commands for Emacs X;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc. X X;; This file is part of GNU Emacs. X X;; GNU Emacs is distributed in the hope that it will be useful, X;; but WITHOUT ANY WARRANTY. No author or distributor X;; accepts responsibility to anyone for the consequences of using it X;; or for whether it serves any particular purpose or works at all, X;; unless he says so in writing. Refer to the GNU Emacs General Public X;; License for full details. X X;; Everyone is granted permission to copy, modify and redistribute X;; GNU Emacs, but only under the conditions described in the X;; GNU Emacs General Public License. A copy of this license is X;; supposed to have been given to you along with GNU Emacs so you X;; can know your rights and responsibilities. It should be in a X;; file named COPYING. Among other things, the copyright notice X;; and this notice must be preserved on all copies. X X X(defconst delete-auto-save-files t X "*Non-nil means delete a buffer's auto-save file Xwhen the buffer is saved for real.") X X;;; Turn off backup files on VMS since it has version numbers. X(defconst make-backup-files (not (eq system-type 'vax-vms)) X "*Create a backup of each file when it is saved for the first time. XThis can be done by renaming the file or by copying. X XRenaming means that Emacs renames the existing file so that it is a Xbackup file, then writes the buffer into a new file. Any other names Xthat the old file had will now refer to the backup file. XThe new file is owned by you and its group is defaulted. X XCopying means that Emacs copies the existing file into the backup file, Xthen writes the buffer on top of the existing file. Any other names Xthat the old file had will now refer to the new (edited) file. XThe file's owner and group are unchanged. X XThe choice of renaming or copying is controlled by the variables Xbackup-by-copying, backup-by-copying-when-linked and Xbackup-by-copying-when-mismatch.") X X(defconst backup-by-copying nil X "*Non-nil means always use copying to create backup files. XSee documentation of variable make-backup-files.") X X(defconst backup-by-copying-when-linked nil X "*Non-nil means use copying to create backups for files with multiple names. XThis causes the alternate names to refer to the latest version as edited. XThis variable is relevant only if backup-by-copying is nil.") X X(defconst backup-by-copying-when-mismatch nil X "*Non-nil means create backups by copying if this preserves owner or group. XRenaming may still be used (subject to control of other variables) Xwhen it would not result in changing the owner or group of the file; Xthat is, for files which are owned by you and whose group matches Xthe default for a new file created there by you. XThis variable is relevant only if backup-by-copying is nil.") X X(defconst buffer-offer-save nil X "*Non-nil in a buffer means offer to save the buffer on exit Xeven if the buffer is not visiting a file. Automatically local in Xall buffers.") X(make-variable-buffer-local 'buffer-offer-save) X X(defconst file-precious-flag nil X "*Non-nil means protect against I/O errors while saving files. XSome modes set this non-nil in particular buffers.") X X(defvar version-control nil X "*Control use of version numbers for backup files. Xt means make numeric backup versions unconditionally. Xnil means make them for files that have some already. Xnever means do not make them.") X X(defvar dired-kept-versions 2 X "*When cleaning directory, number of versions to keep.") X X(defvar trim-versions-without-asking nil X "*If true, deletes excess backup versions silently. XOtherwise asks confirmation.") X X(defvar kept-old-versions 2 X "*Number of oldest versions to keep when a new numbered backup is made.") X X(defvar kept-new-versions 2 X "*Number of newest versions to keep when a new numbered backup is made. XIncludes the new backup. Must be > 0") X X(defconst require-final-newline nil X "*t says silently put a newline at the end whenever a file is saved. XNon-nil but not t says ask user whether to add a newline in each such case. Xnil means don't add newlines.") X X(defconst auto-save-default t X "*t says by default do auto-saving of every file-visiting buffer.") X X(defconst auto-save-visited-file-name nil X "*t says auto-save a buffer in the file it is visiting, when practical. XNormally auto-save files are written under other names.") X X(defconst save-abbrevs nil X "*Non-nil means save word abbrevs too when files are saved. XLoading an abbrev file sets this to t.") X X(defconst find-file-run-dired t X "*Non-nil says run dired if find-file is given the name of a directory.") X X(defvar find-file-not-found-hooks nil X "List of functions to be called for find-file on nonexistent file. XThese functions are called as soon as the error is detected. Xbuffer-file-name is already set up. XThe functions are called in the order given, Xuntil one of them returns non-nil.") X X(defvar find-file-hooks nil X "List of functions to be called after a buffer is loaded from a file. XThe buffer's local variables (if any) will have been processed before the Xfunctions are called.") X X(defvar write-file-hooks nil X "List of functions to be called before writing out a buffer to a file. XIf one of them returns non-nil, the file is considered already written Xand the rest are not called.") X X(defconst inhibit-local-variables nil X "*Non-nil means query before obeying a file's local-variables list. XThis applies when the local-variables list is scanned automatically Xafter you find a file. If you explicitly request such a scan with X\\[normal-mode], there is no query, regardless of this variable.") X X;; Avoid losing in versions where CLASH_DETECTION is disabled. X(or (fboundp 'lock-buffer) X (fset 'lock-buffer 'ignore)) X(or (fboundp 'unlock-buffer) X (fset 'unlock-buffer 'ignore)) X`012 X(defun pwd () X "Show the current default directory." X (interactive nil) X (message "Directory %s" default-directory)) X X(defun cd (dir) X "Make DIR become the current buffer's default directory." X (interactive "DChange default directory: ") X (setq dir (expand-file-name dir)) X (if (not (eq system-type 'vax-vms)) X (setq dir (file-name-as-directory dir))) X (if (not (file-directory-p dir)) X (error "%s is not a directory" dir) X (setq default-directory dir)) X (pwd)) X X(defun load-file (file) X "Load the file FILE of Lisp code." X (interactive "fLoad file: ") X (load (expand-file-name file) nil nil t)) X X(defun load-library (library) X "Load the library named LIBRARY. XThis is an interface to the function ``load'." X (interactive "sLoad library: ") X (load library)) X`012 X(defun switch-to-buffer-other-window (buffer) X "Select buffer BUFFER in another window." X (interactive "BSwitch to buffer in other window: ") X (let ((pop-up-windows t)) X (pop-to-buffer buffer t))) X X(defun find-file (filename) X "Edit file FILENAME. XSwitch to a buffer visiting file FILENAME, Xcreating one if none already exists." X (interactive "FFind file: ") X (switch-to-buffer (find-file-noselect filename))) X X(defun find-file-other-window (filename) X "Edit file FILENAME, in another window. XMay create a new window, or reuse an existing one; Xsee the function display-buffer." X (interactive "FFind file in other window: ") X (switch-to-buffer-other-window (find-file-noselect filename))) X X(defun find-file-read-only (filename) X "Edit file FILENAME but don't save without confirmation. XLike find-file but marks buffer as read-only." X (interactive "fFind file read-only: ") X (find-file filename) X (setq buffer-read-only t)) X X(defun find-alternate-file (filename) X "Find file FILENAME, select its buffer, kill previous buffer. XIf the current buffer now contains an empty file that you just visited X\(presumably by mistake), use this command to visit the file you really want." X (interactive "FFind alternate file: ") X (and (buffer-modified-p) X (not buffer-read-only) X (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? " X`009`009`009`009 (buffer-name)))) X (error "Aborted")) X (let ((obuf (current-buffer)) X`009(ofile buffer-file-name) X`009(oname (buffer-name))) X (rename-buffer " **lose**") X (setq buffer-file-name nil) X (unwind-protect X`009(progn X`009 (unlock-buffer) X`009 (find-file filename)) X (cond ((eq obuf (current-buffer)) X`009 (setq buffer-file-name ofile) X`009 (lock-buffer) X`009 (rename-buffer oname)))) X (kill-buffer obuf))) X X(defun create-file-buffer (filename) X "Create a suitably named buffer for visiting FILENAME, and return it. XFILENAME (sans directory) is used unchanged if that name is free; Xotherwise a string <2> or <3> or ... is appended to get an unused name." X (let ((lastname (file-name-nondirectory filename))) X (if (string= lastname "") X`009(setq lastname filename)) X (generate-new-buffer lastname))) X X(defun find-file-noselect (filename &optional nowarn) X "Read file FILENAME into a buffer and return the buffer. XIf a buffer exists visiting FILENAME, return that one, Xbut verify that the file has not changed since visited or saved. XThe buffer is not selected, just returned to the caller." X (setq filename (expand-file-name filename)) X (if (file-directory-p filename) X (if find-file-run-dired X`009 (dired-noselect filename) X`009(error "%s is a directory." filename)) X (let ((buf (get-file-buffer filename)) X`009 error) X (if buf X`009 (or nowarn X`009 (verify-visited-file-modtime buf) X`009 (cond ((not (file-exists-p filename)) X`009`009 (error "File %s no longer exists!" filename)) X`009`009 ((yes-or-no-p X`009`009 (if (buffer-modified-p buf) X "File has changed since last visited or saved. Flush your changes? " X "File has changed since last visited or saved. Read from disk? ")) X`009`009 (save-excursion X`009`009 (set-buffer buf) X`009`009 (revert-buffer t t))))) X`009(save-excursion X`009 (setq buf (create-file-buffer filename)) X`009 (set-buffer buf) X`009 (erase-buffer) X`009 (condition-case () X`009 (insert-file-contents filename t) X`009 (file-error X`009 (setq error t) X`009 ;; Run find-file-not-found-hooks until one returns non-nil. X`009 (let ((hooks find-file-not-found-hooks)) X`009 (while (and hooks X`009`009`009 (not (funcall (car hooks)))) X`009`009 (setq hooks (cdr hooks)))))) X`009 (setq default-directory (file-name-directory filename)) X`009 (after-find-file error (not nowarn)))) X buf))) X`012 X(defun after-find-file (&optional error warn) X "Called after finding a file and by the default revert function. XSets buffer mode, parses local variables. XOptional args ERROR and WARN: ERROR non-nil means there was an Xerror in reading the file. WARN non-nil means warn if there Xexists an auto-save file more recent than the visited file. XFinishes by calling the functions in find-file-hooks." X (setq buffer-read-only (not (file-writable-p buffer-file-name))) X (if noninteractive X nil X (let* (not-serious X`009 (msg X`009 (cond ((not buffer-read-only) X`009`009 (if (and warn X`009`009`009 (file-newer-than-file-p (make-auto-save-file-name) X`009`009`009`009`009`009 buffer-file-name)) X`009`009 "Auto save file is newer; consider M-x recover-file" X`009`009 (setq not-serious t) X`009`009 (if error "(New file)" nil))) X`009`009 ((not error) X`009`009 (setq not-serious t) X`009`009 "File is write protected") X`009`009 ((file-attributes buffer-file-name) X`009`009 "File exists, but is read-protected.") X`009`009 ((file-attributes (directory-file-name default-directory)) X`009`009 "File not found and directory write-protected") X`009`009 (t X`009`009 "File not found and directory doesn't exist")))) X (if msg X`009 (progn X`009 (message msg) X`009 (or not-serious (sit-for 1 t))))) X (if auto-save-default X`009(auto-save-mode t))) X (normal-mode t) X (mapcar 'funcall find-file-hooks)) X X(defun normal-mode (&optional find-file) X "Choose the major mode for this buffer automatically. XAlso sets up any specified local variables of the file. XUses the visited file name, the -*- line, and the local variables spec. X XThis function is called automatically from ``find-file'. In that case, Xif ``inhibit-local-variables' is non-``nil' we require confirmation before Xprocessing a local variables spec. If you run ``normal-mode' explicitly, Xconfirmation is never required." X (interactive) X (or find-file (funcall (or default-major-mode 'fundamental-mode))) X (condition-case err X (set-auto-mode) X (error (message "File mode specification error: %s" X`009`009 (prin1-to-string err)))) X (condition-case err X (hack-local-variables (not find-file)) X (error (message "File local-variables error: %s" X`009`009 (prin1-to-string err))))) X X;(defvar auto-mode-alist ...) now in loaddefs.el X(defun set-auto-mode () X "Select major mode appropriate for current buffer. XMay base decision on visited file name (See variable auto-mode-list) Xor on buffer contents (-*- line or local variables spec), but does not look Xfor the \"mode:\" local variable. For that, use hack-local-variables." X ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- X (let (beg end mode) X (save-excursion X (goto-char (point-min)) X (skip-chars-forward " \t\n") X (if (and (search-forward "-*-" (save-excursion (end-of-line) (point)) t) X`009 (progn X`009`009 (skip-chars-forward " \t") X`009`009 (setq beg (point)) X`009`009 (search-forward "-*-" (save-excursion (end-of-line) (point)) t)) X`009 (progn X`009`009 (forward-char -3) X`009`009 (skip-chars-backward " \t") X`009`009 (setq end (point)) X`009`009 (goto-char beg) X`009`009 (if (search-forward ":" end t) X`009`009 (progn X`009`009 (goto-char beg) X`009`009 (if (let ((case-fold-search t)) X`009`009`009 (search-forward "mode:" end t)) X`009`009`009 (progn X`009`009`009 (skip-chars-forward " \t") X`009`009`009 (setq beg (point)) X`009`009`009 (if (search-forward ";" end t) X`009`009`009`009 (forward-char -1) X`009`009`009 (goto-char end)) X`009`009`009 (skip-chars-backward " \t") X`009`009`009 (setq mode (buffer-substring beg (point)))))) X`009`009 (setq mode (buffer-substring beg end))))) X`009 (funcall (intern (concat (downcase mode) "-mode"))) X`009(let ((alist auto-mode-alist) X`009 (name buffer-file-name)) X`009 (let ((case-fold-search (eq system-type 'vax-vms))) X`009 ;; Remove backup-suffixes from file name. X`009 (setq name (file-name-sans-versions name)) X`009 ;; Find first matching alist entry. X`009 (while (and (not mode) alist) X`009 (if (string-match (car (car alist)) name) X`009`009 (setq mode (cdr (car alist)))) X`009 (setq alist (cdr alist)))) X`009 (if mode (funcall mode))))))) X X(defun hack-local-variables (&optional force) X "Parse, and bind or evaluate as appropriate, any local variables Xfor current buffer." X ;; Look for "Local variables:" line in last page. X (save-excursion X (goto-char (point-max)) X (search-backward "\n\`094L" (max (- (point-max) 3000) (point-min)) 'move) X (if (let ((case-fold-search t)) X`009 (and (search-forward "Local Variables:" nil t) X`009 (or (not inhibit-local-variables) X`009`009 force X`009`009 (y-or-n-p (format"Set local variables as specified at end of %s? " X`009`009`009`009 (file-name-nondirectory buffer-file-name)))))) X`009(let ((continue t) X`009 prefix prefixlen suffix beg) X`009 ;; The prefix is what comes before "local variables:" in its line. X`009 ;; The suffix is what comes after "local variables:" in its line. X`009 (skip-chars-forward " \t") X`009 (or (eolp) X`009 (setq suffix (buffer-substring (point) X`009`009`009`009`009 (progn (end-of-line) (point))))) X`009 (goto-char (match-beginning 0)) X`009 (or (bolp) X`009 (setq prefix X`009`009 (buffer-substring (point) X`009`009`009`009 (progn (beginning-of-line) (point))))) X`009 (if prefix (setq prefixlen (length prefix) X`009`009`009 prefix (regexp-quote prefix))) X`009 (if suffix (setq suffix (regexp-quote suffix))) X`009 (while continue X`009 ;; Look at next local variable spec. X`009 (if selective-display (re-search-forward "[\n\C-m]") X`009 (forward-line 1)) X`009 ;; Skip the prefix, if any. X`009 (if prefix X`009`009(if (looking-at prefix) X`009`009 (forward-char prefixlen) X`009`009 (error "Local variables entry is missing the prefix"))) X`009 ;; Find the variable name; strip whitespace. X`009 (skip-chars-forward " \t") X`009 (setq beg (point)) X`009 (skip-chars-forward "`094:\n") X`009 (if (eolp) (error "Missing colon in local variables entry")) X`009 (skip-chars-backward " \t") X`009 (let* ((str (buffer-substring beg (point))) X`009`009 (var (read str)) X`009`009 val) X`009 ;; Setting variable named "end" means end of list. X`009 (if (string-equal (downcase str) "end") X`009`009 (setq continue nil) X`009`009;; Otherwise read the variable value. X`009`009(skip-chars-forward "`094:") X`009`009(forward-char 1) X`009`009(setq val (read (current-buffer))) X`009`009(skip-chars-backward "\n") X`009`009(skip-chars-forward " \t") X`009`009(or (if suffix (looking-at suffix) (eolp)) X`009`009 (error "Local variables entry is terminated incorrectly")) X`009`009;; Set the variable. "Variables" mode and eval are funny. X`009`009(cond ((eq var 'mode) X`009`009 (funcall (intern (concat (downcase (symbol-name val)) X`009`009`009`009`009`009"-mode")))) X`009`009 ((eq var 'eval) X`009`009 (if (string= (user-login-name) "root") X`009`009`009 (message "Ignoring ``eval:' in file's local variables") X`009`009`009 (eval val))) X`009`009 (t (make-local-variable var) X`009`009`009 (set var val)))))))))) X`012 X(defun set-visited-file-name (filename) X "Change name of file visited in current buffer to FILENAME. XThe next time the buffer is saved it will go in the newly specified file. Xnil or empty string as argument means make buffer not be visiting any file. XRemember to delete the initial contents of the minibuffer Xif you wish to pass an empty string as the argument." X (interactive "FSet visited file name: ") X (if filename X (setq filename X`009 (if (string-equal filename "") X`009`009nil X`009 (expand-file-name filename)))) X (or (equal filename buffer-file-name) X (null filename) X (progn X`009(lock-buffer filename) X`009(unlock-buffer))) X (setq buffer-file-name filename) X (if filename X (let ((new-name (file-name-nondirectory buffer-file-name))) X`009(if (eq system-type 'vax-vms) X`009 (setq new-name (downcase new-name))) X`009(setq default-directory (file-name-directory buffer-file-name)) X`009(or (get-buffer new-name) (rename-buffer new-name)))) X (setq buffer-backed-up nil) X (clear-visited-file-modtime) X (kill-local-variable 'write-file-hooks) X (kill-local-variable 'revert-buffer-function) X ;; Rename the auto-save file to go with the new visited name. X ;; If auto-save was not already on, turn it on if appropriate. X (if buffer-auto-save-file-name X (rename-auto-save-file) X (auto-save-mode (and buffer-file-name auto-save-default))) X (if buffer-file-name X (set-buffer-modified-p t))) X X(defun write-file (filename) X "Write current buffer into file FILENAME. XMakes buffer visit that file, and marks it not modified." X (interactive "FWrite file: ") X (or (null filename) (string-equal filename "") X (set-visited-file-name filename)) X (set-buffer-modified-p t) X (save-buffer)) X`012 X(defun backup-buffer () V "Make a backup of the disk file visited by the current buffer, if appropriat Xe. XThis is normally done before saving the buffer the first time. VIf the value is non-nil, it is the result of ``file-modes' on the original fil Xe; Xthis means that the caller, after saving the buffer, should change the modes Xof the new file to agree with the old modes." X (and make-backup-files X (not buffer-backed-up) X (file-exists-p buffer-file-name) X (memq (aref (elt (file-attributes buffer-file-name) 8) 0) X`009 '(?- ?l)) X (or (< (length buffer-file-name) 5) X`009 (not (string-equal "/tmp/" (substring buffer-file-name 0 5)))) X (condition-case () X`009(let* ((backup-info (find-backup-file-name buffer-file-name)) X`009 (backupname (car backup-info)) X`009 (targets (cdr backup-info)) X`009 setmodes) X;`009 (if (file-directory-p buffer-file-name) X;`009 (error "Cannot save buffer in directory %s" buffer-file-name)) X`009 (condition-case () X`009 (if (or file-precious-flag X`009`009 (file-symlink-p buffer-file-name) X`009`009 backup-by-copying X`009`009 (and backup-by-copying-when-linked X`009`009`009 (> (file-nlinks buffer-file-name) 1)) X`009`009 (and backup-by-copying-when-mismatch X`009`009`009 (let ((attr (file-attributes buffer-file-name))) X`009`009`009 (or (nth 9 attr) X`009`009`009`009 (/= (nth 2 attr) (user-uid)))))) X`009`009 (copy-file buffer-file-name backupname t t) X`009`009(condition-case () X`009`009 (delete-file backupname) X`009`009 (file-error nil)) X`009`009(rename-file buffer-file-name backupname t) X`009`009(setq setmodes (file-modes backupname))) X`009 (file-error X`009 ;; If trouble writing the backup, write it in `126. X`009 (setq backupname (expand-file-name "`126/%backup%`126")) V`009 (message "Cannot write backup file; backing up in `126/%%backup%%`126 X") X`009 (sleep-for 1) X`009 (copy-file buffer-file-name backupname t t))) X`009 (setq buffer-backed-up t) X`009 (if (and targets X`009`009 (or trim-versions-without-asking X`009`009 (y-or-n-p (format "Delete excess backup versions of %s? " X`009`009`009`009`009 buffer-file-name)))) X`009 (while targets X`009`009(condition-case () X`009`009 (delete-file (car targets)) X`009`009 (file-error nil)) X`009`009(setq targets (cdr targets)))) X`009 setmodes) X (file-error nil)))) X X(defun file-name-sans-versions (name) X "Return FILENAME sans backup versions or strings. XThis is a separate procedure so your site-init or startup file can Xredefine it." X (substring name 0 X`009 (if (eq system-type 'vax-vms) X`009`009 (or (string-match ";[0-9]+\\'" name) X`009`009 (string-match ".[0-9]+\\'" name) X`009`009 (length name)) X`009 (or (string-match "\\.`126[0-9]+`126\\'" name) X`009`009 (string-match "`126\\'" name) X`009`009 (length name))))) X X(defun make-backup-file-name (file) X "Create the non-numeric backup file name for FILE. XThis is a separate function so you can redefine it for customization." X (concat file "`126")) X X(defun backup-file-name-p (file) X "Return non-nil if FILE is a backup file name (numeric or not). XThis is a separate function so you can redefine it for customization. XYou may need to redefine file-name-sans-versions as well." X (string-match "`126$" file)) X X;; I believe there is no need to alter this behavior for VMS; X;; since backup files are not made on VMS, it should not get called. X(defun find-backup-file-name (fn) X "Find a file name for a backup file, and suggestions for deletions. XValue is a list whose car is the name for the backup file X and whose cdr is a list of old versions to consider deleting now." X (if (eq version-control 'never) X (list (make-backup-file-name fn)) X (let* ((base-versions (concat (file-name-nondirectory fn) ".`126")) X`009 (bv-length (length base-versions)) X`009 (possibilities (file-name-all-completions X`009`009`009 base-versions X`009`009`009 (file-name-directory fn))) X`009 (versions (sort (mapcar 'backup-extract-version possibilities) X`009`009`009 '<)) X`009 (high-water-mark (apply 'max (cons 0 versions))) X`009 (deserve-versions-p X`009 (or version-control X`009`009(> high-water-mark 0))) X`009 (number-to-delete (- (length versions) X`009`009`009`009kept-old-versions kept-new-versions -1))) X (if (not deserve-versions-p) X`009 (list (make-backup-file-name fn)) X`009(cons (concat fn ".`126" (int-to-string (1+ high-water-mark)) "`126") X`009 (if (> number-to-delete 0) X`009`009 (mapcar (function (lambda (n) X`009`009`009`009 (concat fn ".`126" (int-to-string n) "`126"))) X`009`009`009 (let ((v (nthcdr kept-old-versions versions))) X`009`009`009 (rplacd (nthcdr (1- number-to-delete) v) ()) X`009`009`009 v)))))))) X X(defun backup-extract-version (fn) X (if (and (string-match "[0-9]+`126$" fn bv-length) X`009 (= (match-beginning 0) bv-length)) X (string-to-int (substring fn bv-length -1)) X 0)) X X(defun file-nlinks (filename) X "Return number of names file FILENAME has." X (car (cdr (file-attributes filename)))) X`012 X(defun save-buffer (&optional args) X "Save current buffer in visited file if modified. Versions described below. X XBy default, makes the previous version into a backup file X if previously requested or if this is the first save. XWith 1 or 3 \\[universal-argument]'s, marks this version X to become a backup when the next save is done. XWith 2 or 3 \\[universal-argument]'s, X unconditionally makes the previous version into a backup file. XWith argument of 0, never makes the previous version into a backup file. X XIf a file's name is FOO, the names of its numbered backup versions are V FOO.`126i`126 for various integers i. A non-numbered backup file is called F XOO`126. XNumeric backups (rather than FOO`126) will be made if value of X ``version-control' is not the atom ``never' and either there are already X numeric versions of the file being backed up, or ``version-control' is X non-nil. XWe don't want excessive versions piling up, so there are variables X ``kept-old-versions', which tells Emacs how many oldest versions to keep, X and ``kept-new-versions', which tells how many newest versions to keep. X Defaults are 2 old versions and 2 new. X``dired-kept-versions' controls dired's clean-directory (.) command. XIf ``trim-versions-without-asking' is nil, system will query user X before trimming versions. Otherwise it does it silently." X (interactive "p") X (let ((modp (buffer-modified-p)) X`009(large (> (buffer-size) 50000)) X`009(make-backup-files (and make-backup-files (not (eq args 0))))) X (and modp (memq args '(16 64)) (setq buffer-backed-up nil)) X (if (and modp large) (message "Saving file %s..." (buffer-file-name))) X (basic-save-buffer) X (and modp (memq args '(4 64)) (setq buffer-backed-up nil)))) X X(defun delete-auto-save-file-if-necessary () X "Delete the auto-save filename for the current buffer (if it has one) Xif variable delete-auto-save-files is non-nil." X (and buffer-auto-save-file-name delete-auto-save-files X (progn X`009 (condition-case () X`009 (delete-file buffer-auto-save-file-name) X`009 (file-error nil)) X`009 (set-buffer-auto-saved)))) X X(defun basic-save-buffer () X "Save the current buffer in its visited file, if it has been modified." X (interactive) X (if (buffer-modified-p) X (let (setmodes tempsetmodes) X`009(or buffer-file-name X`009 (progn X`009 (setq buffer-file-name X`009`009 (expand-file-name (read-file-name "File to save in: ") nil) X`009`009 default-directory (file-name-directory buffer-file-name)) X`009 (auto-save-mode auto-save-default))) X`009(if (not (file-writable-p buffer-file-name)) X`009 (if (yes-or-no-p X`009`009 (format "File %s is write-protected; try to save anyway? " X`009`009`009 (file-name-nondirectory buffer-file-name))) X`009`009(setq tempsetmodes t) X`009 (error X "Attempt to save to a file which you aren't allowed to write"))) X`009(or (verify-visited-file-modtime (current-buffer)) X`009 (not (file-exists-p buffer-file-name)) X`009 (yes-or-no-p X`009 "Disk file has changed since visited or saved. Save anyway? ") X`009 (error "Save not confirmed")) X`009(or buffer-backed-up X`009 (setq setmodes (backup-buffer))) X`009(save-restriction X`009 (widen) X`009 (and (> (point-max) 1) X`009 (/= (char-after (1- (point-max))) ?\n) X`009 (or (eq require-final-newline t) X`009`009 (and require-final-newline X`009`009`009(yes-or-no-p X`009`009`009 (format "Buffer %s does not end in newline. Add one? " X`009`009`009`009 (buffer-name))))) X`009 (save-excursion X`009`009 (goto-char (point-max)) X`009`009 (insert ?\n))) X`009 (let ((hooks write-file-hooks) X`009`009(done nil)) X`009 (while (and hooks X`009`009`009(not (setq done (funcall (car hooks))))) X`009 (setq hooks (cdr hooks))) X`009 ;; If a hook returned t, file is already "written". X`009 (cond ((not done) X`009`009 (if file-precious-flag X`009`009 ;; If file is precious, rename it away before X`009`009 ;; overwriting it. X`009`009 (let ((rename t) X`009`009`009 (file (concat buffer-file-name "#"))) X`009`009`009 (condition-case () X`009`009`009 (progn (rename-file buffer-file-name file t) X`009`009`009`009 (setq setmodes (file-modes file))) X`009`009`009 (file-error (setq rename nil))) X`009`009`009 (unwind-protect X`009`009`009 (progn (clear-visited-file-modtime) X`009`009`009`009 (write-region (point-min) (point-max) X`009`009`009`009`009`009 buffer-file-name nil t) X`009`009`009`009 (setq rename nil)) X`009`009`009 ;; If rename is still t, writing failed. X`009`009`009 ;; So rename the old file back to original name, X`009`009`009 (if rename X`009`009`009 (progn X`009`009`009`009 (rename-file file buffer-file-name t) X`009`009`009`009 (clear-visited-file-modtime)) X`009`009`009 ;; Otherwise we don't need the original file, X`009`009`009 ;; so flush it. X`009`009`009 (condition-case () X`009`009`009`009 (delete-file file) X`009`009`009 (error nil))))) X`009`009 ;; If file not writable, see if we can make it writable X`009`009 ;; temporarily while we write it. X`009`009 ;; But no need to do so if we have just backed it up X`009`009 ;; (setmodes is set) because that says we're superseding. X`009`009 (cond ((and tempsetmodes (not setmodes)) X`009`009`009 ;; Change the mode back, after writing. X`009`009`009 (setq setmodes (file-modes buffer-file-name)) X`009`009`009 (set-file-modes buffer-file-name 511))) X`009`009 (write-region (point-min) (point-max) X`009`009`009`009 buffer-file-name nil t))))) X`009 (if setmodes X`009 (condition-case () X`009`009 (set-file-modes buffer-file-name setmodes) X`009`009(error nil)))) X`009(delete-auto-save-file-if-necessary)) X (message "(No changes need to be saved)"))) X X(defun save-some-buffers (&optional arg exiting) X "Save some modified file-visiting buffers. Asks user about each one. XWith argument, saves all with no questions." X (interactive "P") X (let (considered (list (buffer-list))) X (while list X (let ((buffer (car list))) X`009(and (buffer-modified-p buffer) X`009 (save-excursion X`009 (set-buffer buffer) X`009 (and X`009`009(or buffer-file-name X`009`009 (and exiting buffer-offer-save (> (buffer-size) 0))) X`009`009(setq considered t) X`009`009(or arg X`009`009 (y-or-n-p (if buffer-file-name X`009`009`009`009 (format "Save file %s? " X`009`009`009`009`009 buffer-file-name) X`009`009`009`009(format "Save buffer %s? " (buffer-name))))) X`009`009(condition-case () X`009`009 (save-buffer) X`009`009 (error nil)))))) X (setq list (cdr list))) X (and save-abbrevs abbrevs-changed X`009 (progn X`009 (setq considered t) X`009 (if (or arg X`009`009 (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name))) X`009 (write-abbrev-file nil)) X`009 ;; Don't keep bothering user if he says no. X`009 (setq abbrevs-changed nil))) X (if considered X`009(message "") X`009(message "(No files need saving)")))) X`012 X(defun not-modified () X "Mark current buffer as unmodified, not needing to be saved." X (interactive) X (message "Modification-flag cleared") X (set-buffer-modified-p nil)) X X(defun toggle-read-only () X "Change whether this buffer is visiting its file read-only." X (interactive) X (setq buffer-read-only (not buffer-read-only)) X ;; Force mode-line redisplay X (set-buffer-modified-p (buffer-modified-p))) X X(defun insert-file (filename) X "Insert contents of file FILENAME into buffer after point. XSet mark after the inserted text." X (interactive "fInsert file: ") X (let ((tem (insert-file-contents filename))) X (push-mark (+ (point) (car (cdr tem)))))) X X(defun append-to-file (start end filename) X "Append the contents of the region to the end of file FILENAME. XWhen called from a function, expects three arguments, XSTART, END and FILENAME. START and END are buffer positions Xsaying what text to write." X (interactive "r\nFAppend to file: ") X (write-region start end filename t)) X X(defvar revert-buffer-function nil X "Function to use to revert this buffer, or nil to do the default.") X X(defun revert-buffer (&optional arg noconfirm) X "Replace the buffer text with the text of the visited file on disk. XThis undoes all changes since the file was visited or saved. XIf latest auto-save file is more recent than the visited file, Xasks user whether to use that instead. XFirst argument (optional) non-nil means don't offer to use auto-save file. X This is the prefix arg when called interactively. X XSecond argument (optional) non-nil means don't ask for confirmation at all. X XIf revert-buffer-function's value is non-nil, it is called to do the work." X (interactive "P") X (if revert-buffer-function X (funcall revert-buffer-function arg noconfirm) X (let* ((opoint (point)) X`009 (auto-save-p (and (null arg) (recent-auto-save-p) X`009`009`009 buffer-auto-save-file-name X`009`009`009 (file-readable-p buffer-auto-save-file-name) X`009`009`009 (y-or-n-p X "Buffer has been auto-saved recently. Revert from auto-save file? "))) X`009 (file-name (if auto-save-p X`009`009`009 buffer-auto-save-file-name X`009`009`009buffer-file-name))) X (cond ((null file-name) X`009 (error "Buffer does not seem to be associated with any file")) X`009 ((not (file-exists-p file-name)) X`009 (error "File %s no longer exists!" file-name)) X`009 ((or noconfirm X`009`009 (yes-or-no-p (format "Revert buffer from file %s? " X`009`009`009`009 file-name))) X`009 (let ((buffer-read-only nil)) X`009 ;; Bind buffer-file-name to nil X`009 ;; so that we don't try to lock the file. X`009 (let ((buffer-file-name nil)) X`009`009 (or auto-save-p X`009`009 (unlock-buffer)) X`009`009 (erase-buffer)) X`009 (insert-file-contents file-name (not auto-save-p))) X`009 (goto-char (min opoint (point-max))) X`009 (after-find-file nil) X`009 t))))) X X(defun recover-file (file) X "Visit file FILE, but get contents from its last auto-save file." X (interactive "FRecover file: ") X (setq file (expand-file-name file)) X (if (auto-save-file-name-p file) (error "%s is an auto-save file" file)) X (let ((file-name (let ((buffer-file-name file)) X`009`009 (make-auto-save-file-name)))) X (cond ((not (file-newer-than-file-p file-name file)) X`009 (error "Auto-save file %s not current" file-name)) X`009 ((save-window-excursion X`009 (if (not (eq system-type 'vax-vms)) X`009`009 (with-output-to-temp-buffer "*Directory*" X`009`009 (buffer-flush-undo standard-output) X`009`009 (call-process "ls" nil standard-output nil X`009`009`009`009 "-l" file file-name))) X`009 (yes-or-no-p (format "Recover auto save file %s? " file-name))) X`009 (switch-to-buffer (find-file-noselect file t)) X`009 (let ((buffer-read-only nil)) X`009 (erase-buffer) X`009 (insert-file-contents file-name nil)) X`009 (after-find-file nil)) X`009 (t (error "Recover-file cancelled.")))) X (setq buffer-auto-save-file-name nil) X (message "Auto-save off in this buffer till you do M-x auto-save-mode.")) X X(defun kill-some-buffers () X "For each buffer, ask whether to kill it." X (interactive) X (let ((list (buffer-list))) X (while list X (let* ((buffer (car list)) X`009 (name (buffer-name buffer))) X`009(and (not (string-equal name "")) X`009 (/= (aref name 0) ? ) X`009 (yes-or-no-p X`009 (format "Buffer %s %s. Kill? " X`009`009 name X`009`009 (if (buffer-modified-p buffer) X`009`009`009 "HAS BEEN EDITED" "is unmodified"))) X`009 (kill-buffer buffer))) X (setq list (cdr list))))) X`012 X(defun auto-save-mode (arg) X "Toggle auto-saving of contents of current buffer. XWith arg, turn auto-saving on if arg is positive, else off." X (interactive "P") X (setq buffer-auto-save-file-name X (and (if (null arg) X`009`009 (not buffer-auto-save-file-name) X`009 (or (eq arg t) (listp arg) (and (integerp arg) (> arg 0)))) X`009 (if (and buffer-file-name auto-save-visited-file-name X`009`009 (not buffer-read-only)) X`009`009 buffer-file-name X`009 (make-auto-save-file-name)))) X (if (interactive-p) X (message "Auto-save %s (in this buffer)" X`009 (if buffer-auto-save-file-name "on" "off"))) X buffer-auto-save-file-name) X X(defun rename-auto-save-file () X "Adjust current buffer's auto save file name for current conditions. XAlso rename any existing auto save file." X (let ((osave buffer-auto-save-file-name)) X (setq buffer-auto-save-file-name X`009 (make-auto-save-file-name)) X (if (and osave buffer-auto-save-file-name X`009 (not (string= buffer-auto-save-file-name buffer-file-name)) X`009 (not (string= buffer-auto-save-file-name osave)) X`009 (file-exists-p osave)) X`009(rename-file osave buffer-auto-save-file-name t)))) X X(defun make-auto-save-file-name () X "Return file name to use for auto-saves of current buffer. XDoes not consider auto-save-visited-file-name; that is checked Xbefore calling this function. XYou can redefine this for customization. XSee also auto-save-file-name-p." X (if buffer-file-name X (concat (file-name-directory buffer-file-name) X`009 "#" X`009 (file-name-nondirectory buffer-file-name) X`009 "#") X (expand-file-name (concat "#%" (buffer-name) "#")))) X X(defun auto-save-file-name-p (filename) X "Return non-nil if FILENAME can be yielded by make-auto-save-file-name. XFILENAME should lack slashes. XYou can redefine this for customization." X (string-match "`094#.*#$" filename)) X`012 X(defconst list-directory-command X (if (eq system-type 'vax-vms) "DIRECTORY" "ls") X "*Name of host directory lister command.") X X(defconst list-directory-brief-switches X (if (eq system-type 'vax-vms) "" "-CF") X "*Switches for list-directory to pass to host for brief listing,") X X; The VMS verbose switches are a compromise--truncation of the owner field X; is needed to get everything into an 80-char line X(defconst list-directory-verbose-switches X (if (eq system-type 'vax-vms) X`009 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)" "-l") X "*Switches for list-directory to pass to host for verbose listing,") X X(defun list-directory (dirname &optional verbose) X "Display a list of files in or matching DIRNAME, a la ``ls'. XDIRNAME is globbed by the shell if necessary. XPrefix arg (second arg if noninteractive) means supply -l switch to ``ls'. XActions controlled by variables list-directory-brief-switches X and list-directory-verbose-switches." X (interactive (let ((pfx current-prefix-arg)) X`009`009 (list (read-file-name (if pfx "List directory (verbose): " X`009`009`009`009`009 "List directory (brief): ") X`009`009`009`009 nil default-directory nil) X`009`009 pfx))) X (let ((switches (if verbose list-directory-verbose-switches X`009`009 list-directory-brief-switches)) X`009full-dir-p) X (or dirname (setq dirname default-directory)) X (if (not (eq system-type 'vax-vms)) X`009(progn X`009 (if (file-directory-p dirname) X`009 (progn X`009`009(setq full-dir-p t) X`009`009(or (string-match "/$" dirname) X`009`009 (setq dirname (concat dirname "/"))))))) X (setq dirname (expand-file-name dirname)) X (with-output-to-temp-buffer "*Directory*" X (buffer-flush-undo standard-output) X (princ "Directory ") X (princ dirname) X (terpri) X (if (eq system-type 'vax-vms) X`009 (progn X`009 (subprocess-command-to-buffer X`009 (concat list-directory-command " " switches " " dirname) X`009 "*Directory*") X`009 (set-buffer "*Directory*") X`009 (goto-char (point-min)) X`009 (replace-regexp " *$" "")`009;remove all those trailing blanks X`009 ) X`009;; else UNIX style X`009(if full-dir-p X`009 (call-process "ls" nil standard-output nil X`009`009`009 switches dirname) X`009 (let ((default-directory (file-name-directory dirname))) X`009 (call-process shell-file-name nil standard-output nil X`009`009`009 "-c" (concat "exec ls " X`009`009`009`009 switches " " X`009`009`009`009 (file-name-nondirectory dirname))))))))) X X(defun save-buffers-kill-emacs (&optional arg) X "Offer to save each buffer, then kill this Emacs fork. XWith prefix arg, silently save all file-visiting buffers, then kill." X (interactive "P") X (save-some-buffers arg t) X (kill-emacs)) X`012 X(define-key ctl-x-map "\C-f" 'find-file) X(define-key ctl-x-map "\C-q" 'toggle-read-only) X(define-key ctl-x-map "\C-r" 'find-file-read-only) X(define-key ctl-x-map "\C-v" 'find-alternate-file) X(define-key ctl-x-map "\C-s" 'save-buffer) X(define-key ctl-x-map "s" 'save-some-buffers) X(define-key ctl-x-map "\C-w" 'write-file) X(define-key ctl-x-map "i" 'insert-file) X(define-key esc-map "`126" 'not-modified) X(define-key ctl-x-map "\C-d" 'list-directory) X(define-key ctl-x-map "\C-c" 'save-buffers-kill-emacs) X X(defvar ctl-x-4-map (make-keymap) X "Keymap for subcommands of C-x 4") X(fset 'ctl-x-4-prefix ctl-x-4-map) X(define-key ctl-x-map "4" 'ctl-x-4-prefix) X(define-key ctl-x-4-map "f" 'find-file-other-window) X(define-key ctl-x-4-map "\C-f" 'find-file-other-window) X(define-key ctl-x-4-map "b" 'switch-to-buffer-other-window) $ GoSub Convert_File $ Goto Part3