comparison lisp/files.el @ 17734:bd60d4318daf

(backup-extract-version-start): New variable. (find-backup-file-namem, backup-extract-version): Rename bv-length to backup-extract-version-start. (file-relative-name): Bind the variable fname.
author Richard M. Stallman <rms@gnu.org>
date Sat, 10 May 1997 05:44:56 +0000
parents a08d96324d4f
children 488536bc29c2
comparison
equal deleted inserted replaced
17733:6d8fecd12940 17734:bd60d4318daf
1902 "Return non-nil if FILE is a backup file name (numeric or not). 1902 "Return non-nil if FILE is a backup file name (numeric or not).
1903 This is a separate function so you can redefine it for customization. 1903 This is a separate function so you can redefine it for customization.
1904 You may need to redefine `file-name-sans-versions' as well." 1904 You may need to redefine `file-name-sans-versions' as well."
1905 (string-match "~\\'" file)) 1905 (string-match "~\\'" file))
1906 1906
1907 (defvar backup-extract-version-start)
1908
1907 ;; This is used in various files. 1909 ;; This is used in various files.
1908 ;; The usage of bv-length is not very clean, 1910 ;; The usage of bv-length is not very clean,
1909 ;; but I can't see a good alternative, 1911 ;; but I can't see a good alternative,
1910 ;; so as of now I am leaving it alone. 1912 ;; so as of now I am leaving it alone.
1911 (defun backup-extract-version (fn) 1913 (defun backup-extract-version (fn)
1912 "Given the name of a numeric backup file, return the backup number. 1914 "Given the name of a numeric backup file, return the backup number.
1913 Uses the free variable `bv-length', whose value should be 1915 Uses the free variable `backup-extract-version-start', whose value should be
1914 the index in the name where the version number begins." 1916 the index in the name where the version number begins."
1915 (if (and (string-match "[0-9]+~$" fn bv-length) 1917 (if (and (string-match "[0-9]+~$" fn backup-extract-version-start)
1916 (= (match-beginning 0) bv-length)) 1918 (= (match-beginning 0) backup-extract-version-start))
1917 (string-to-int (substring fn bv-length -1)) 1919 (string-to-int (substring fn backup-extract-version-start -1))
1918 0)) 1920 0))
1919 1921
1920 ;; I believe there is no need to alter this behavior for VMS; 1922 ;; I believe there is no need to alter this behavior for VMS;
1921 ;; since backup files are not made on VMS, it should not get called. 1923 ;; since backup files are not made on VMS, it should not get called.
1922 (defun find-backup-file-name (fn) 1924 (defun find-backup-file-name (fn)
1929 (if handler 1931 (if handler
1930 (funcall handler 'find-backup-file-name fn) 1932 (funcall handler 'find-backup-file-name fn)
1931 (if (eq version-control 'never) 1933 (if (eq version-control 'never)
1932 (list (make-backup-file-name fn)) 1934 (list (make-backup-file-name fn))
1933 (let* ((base-versions (concat (file-name-nondirectory fn) ".~")) 1935 (let* ((base-versions (concat (file-name-nondirectory fn) ".~"))
1934 (bv-length (length base-versions)) 1936 (backup-extract-version-start (length base-versions))
1935 possibilities 1937 possibilities
1936 (versions nil) 1938 (versions nil)
1937 (high-water-mark 0) 1939 (high-water-mark 0)
1938 (deserve-versions-p nil) 1940 (deserve-versions-p nil)
1939 (number-to-delete 0)) 1941 (number-to-delete 0))
1975 when used with that default directory as the default. 1977 when used with that default directory as the default.
1976 If this is impossible (which can happen on MSDOS and Windows 1978 If this is impossible (which can happen on MSDOS and Windows
1977 when the file name and directory use different drive names) 1979 when the file name and directory use different drive names)
1978 then it returns FILENAME." 1980 then it returns FILENAME."
1979 (save-match-data 1981 (save-match-data
1980 (setq fname (expand-file-name filename) 1982 (let ((fname (expand-file-name filename)))
1981 directory (file-name-as-directory 1983 (setq directory (file-name-as-directory
1982 (expand-file-name (or directory default-directory)))) 1984 (expand-file-name (or directory default-directory))))
1983 ;; On Microsoft OSes, if FILENAME and DIRECTORY have different 1985 ;; On Microsoft OSes, if FILENAME and DIRECTORY have different
1984 ;; drive names, they can't be relative, so return the absolute name. 1986 ;; drive names, they can't be relative, so return the absolute name.
1985 (if (and (or (eq system-type 'ms-dos) 1987 (if (and (or (eq system-type 'ms-dos)
1986 (eq system-type 'windows-nt)) 1988 (eq system-type 'windows-nt))
1987 (not (string-equal (substring fname 0 2) 1989 (not (string-equal (substring fname 0 2)
1988 (substring directory 0 2)))) 1990 (substring directory 0 2))))
1989 filename 1991 filename
1990 (let ((ancestor "")) 1992 (let ((ancestor ""))
1991 (while (not (string-match (concat "^" (regexp-quote directory)) fname)) 1993 (while (not (string-match (concat "^" (regexp-quote directory)) fname))
1992 (setq directory (file-name-directory (substring directory 0 -1)) 1994 (setq directory (file-name-directory (substring directory 0 -1))
1993 ancestor (concat "../" ancestor))) 1995 ancestor (concat "../" ancestor)))
1994 (concat ancestor (substring fname (match-end 0))))))) 1996 (concat ancestor (substring fname (match-end 0))))))))
1995 1997
1996 (defun save-buffer (&optional args) 1998 (defun save-buffer (&optional args)
1997 "Save current buffer in visited file if modified. Versions described below. 1999 "Save current buffer in visited file if modified. Versions described below.
1998 By default, makes the previous version into a backup file 2000 By default, makes the previous version into a backup file
1999 if previously requested or if this is the first save. 2001 if previously requested or if this is the first save.