diff options
| author | Richard M. Stallman | 1995-01-12 21:05:07 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-01-12 21:05:07 +0000 |
| commit | eb650569ae9eb775958120be180c0e00f38d46d8 (patch) | |
| tree | e7a196564b4f8d08c4460b71b6e323030c0b17da /lisp | |
| parent | dae0ae5d73e9d23017cfb69d6d4688816322e2e2 (diff) | |
| download | emacs-eb650569ae9eb775958120be180c0e00f38d46d8.tar.gz emacs-eb650569ae9eb775958120be180c0e00f38d46d8.zip | |
(find-backup-file-name): Run a file name handler.
(backup-buffer): Do nothing if backup-info is nil.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/files.el | 192 |
1 files changed, 99 insertions, 93 deletions
diff --git a/lisp/files.el b/lisp/files.el index 21c2bf6c2fe..e36072dca51 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1364,63 +1364,64 @@ the modes of the new file to agree with the old modes." | |||
| 1364 | targets (cdr backup-info)) | 1364 | targets (cdr backup-info)) |
| 1365 | ;;; (if (file-directory-p buffer-file-name) | 1365 | ;;; (if (file-directory-p buffer-file-name) |
| 1366 | ;;; (error "Cannot save buffer in directory %s" buffer-file-name)) | 1366 | ;;; (error "Cannot save buffer in directory %s" buffer-file-name)) |
| 1367 | (condition-case () | 1367 | (if backup-info |
| 1368 | (let ((delete-old-versions | 1368 | (condition-case () |
| 1369 | ;; If have old versions to maybe delete, | 1369 | (let ((delete-old-versions |
| 1370 | ;; ask the user to confirm now, before doing anything. | 1370 | ;; If have old versions to maybe delete, |
| 1371 | ;; But don't actually delete til later. | 1371 | ;; ask the user to confirm now, before doing anything. |
| 1372 | (and targets | 1372 | ;; But don't actually delete til later. |
| 1373 | (or (eq delete-old-versions t) (eq delete-old-versions nil)) | 1373 | (and targets |
| 1374 | (or delete-old-versions | 1374 | (or (eq delete-old-versions t) (eq delete-old-versions nil)) |
| 1375 | (y-or-n-p (format "Delete excess backup versions of %s? " | 1375 | (or delete-old-versions |
| 1376 | real-file-name)))))) | 1376 | (y-or-n-p (format "Delete excess backup versions of %s? " |
| 1377 | ;; Actually write the back up file. | 1377 | real-file-name)))))) |
| 1378 | (condition-case () | 1378 | ;; Actually write the back up file. |
| 1379 | (if (or file-precious-flag | 1379 | (condition-case () |
| 1380 | ; (file-symlink-p buffer-file-name) | 1380 | (if (or file-precious-flag |
| 1381 | backup-by-copying | 1381 | ; (file-symlink-p buffer-file-name) |
| 1382 | (and backup-by-copying-when-linked | 1382 | backup-by-copying |
| 1383 | (> (file-nlinks real-file-name) 1)) | 1383 | (and backup-by-copying-when-linked |
| 1384 | (and backup-by-copying-when-mismatch | 1384 | (> (file-nlinks real-file-name) 1)) |
| 1385 | (let ((attr (file-attributes real-file-name))) | 1385 | (and backup-by-copying-when-mismatch |
| 1386 | (or (nth 9 attr) | 1386 | (let ((attr (file-attributes real-file-name))) |
| 1387 | (not (file-ownership-preserved-p real-file-name)))))) | 1387 | (or (nth 9 attr) |
| 1388 | (condition-case () | 1388 | (not (file-ownership-preserved-p real-file-name)))))) |
| 1389 | (copy-file real-file-name backupname t t) | 1389 | (condition-case () |
| 1390 | (file-error | 1390 | (copy-file real-file-name backupname t t) |
| 1391 | ;; If copying fails because file BACKUPNAME | 1391 | (file-error |
| 1392 | ;; is not writable, delete that file and try again. | 1392 | ;; If copying fails because file BACKUPNAME |
| 1393 | (if (and (file-exists-p backupname) | 1393 | ;; is not writable, delete that file and try again. |
| 1394 | (not (file-writable-p backupname))) | 1394 | (if (and (file-exists-p backupname) |
| 1395 | (delete-file backupname)) | 1395 | (not (file-writable-p backupname))) |
| 1396 | (copy-file real-file-name backupname t t))) | 1396 | (delete-file backupname)) |
| 1397 | ;; rename-file should delete old backup. | 1397 | (copy-file real-file-name backupname t t))) |
| 1398 | (rename-file real-file-name backupname t) | 1398 | ;; rename-file should delete old backup. |
| 1399 | (setq setmodes (file-modes backupname))) | 1399 | (rename-file real-file-name backupname t) |
| 1400 | (file-error | 1400 | (setq setmodes (file-modes backupname))) |
| 1401 | ;; If trouble writing the backup, write it in ~. | 1401 | (file-error |
| 1402 | (setq backupname (expand-file-name "~/%backup%~")) | 1402 | ;; If trouble writing the backup, write it in ~. |
| 1403 | (message "Cannot write backup file; backing up in ~/%%backup%%~") | 1403 | (setq backupname (expand-file-name "~/%backup%~")) |
| 1404 | (sleep-for 1) | 1404 | (message "Cannot write backup file; backing up in ~/%%backup%%~") |
| 1405 | (condition-case () | 1405 | (sleep-for 1) |
| 1406 | (copy-file real-file-name backupname t t) | 1406 | (condition-case () |
| 1407 | (file-error | 1407 | (copy-file real-file-name backupname t t) |
| 1408 | ;; If copying fails because file BACKUPNAME | 1408 | (file-error |
| 1409 | ;; is not writable, delete that file and try again. | 1409 | ;; If copying fails because file BACKUPNAME |
| 1410 | (if (and (file-exists-p backupname) | 1410 | ;; is not writable, delete that file and try again. |
| 1411 | (not (file-writable-p backupname))) | 1411 | (if (and (file-exists-p backupname) |
| 1412 | (delete-file backupname)) | 1412 | (not (file-writable-p backupname))) |
| 1413 | (copy-file real-file-name backupname t t))))) | 1413 | (delete-file backupname)) |
| 1414 | (setq buffer-backed-up t) | 1414 | (copy-file real-file-name backupname t t))))) |
| 1415 | ;; Now delete the old versions, if desired. | 1415 | (setq buffer-backed-up t) |
| 1416 | (if delete-old-versions | 1416 | ;; Now delete the old versions, if desired. |
| 1417 | (while targets | 1417 | (if delete-old-versions |
| 1418 | (condition-case () | 1418 | (while targets |
| 1419 | (delete-file (car targets)) | 1419 | (condition-case () |
| 1420 | (file-error nil)) | 1420 | (delete-file (car targets)) |
| 1421 | (setq targets (cdr targets)))) | 1421 | (file-error nil)) |
| 1422 | setmodes) | 1422 | (setq targets (cdr targets)))) |
| 1423 | (file-error nil))))) | 1423 | setmodes) |
| 1424 | (file-error nil)))))) | ||
| 1424 | 1425 | ||
| 1425 | (defun file-name-sans-versions (name &optional keep-backup-version) | 1426 | (defun file-name-sans-versions (name &optional keep-backup-version) |
| 1426 | "Return FILENAME sans backup versions or strings. | 1427 | "Return FILENAME sans backup versions or strings. |
| @@ -1506,43 +1507,48 @@ the index in the name where the version number begins." | |||
| 1506 | (defun find-backup-file-name (fn) | 1507 | (defun find-backup-file-name (fn) |
| 1507 | "Find a file name for a backup file, and suggestions for deletions. | 1508 | "Find a file name for a backup file, and suggestions for deletions. |
| 1508 | Value is a list whose car is the name for the backup file | 1509 | Value is a list whose car is the name for the backup file |
| 1509 | and whose cdr is a list of old versions to consider deleting now." | 1510 | and whose cdr is a list of old versions to consider deleting now. |
| 1510 | (if (eq version-control 'never) | 1511 | If the value is nil, don't make a backup." |
| 1511 | (list (make-backup-file-name fn)) | 1512 | (let ((handler (find-file-name-handler fn 'find-backup-file-name))) |
| 1512 | (let* ((base-versions (concat (file-name-nondirectory fn) ".~")) | 1513 | ;; Run a handler for this function so that ange-ftp can refuse to do it. |
| 1513 | (bv-length (length base-versions)) | 1514 | (if handler |
| 1514 | possibilities | 1515 | (funcall handler 'find-backup-file-name fn) |
| 1515 | (versions nil) | 1516 | (if (eq version-control 'never) |
| 1516 | (high-water-mark 0) | ||
| 1517 | (deserve-versions-p nil) | ||
| 1518 | (number-to-delete 0)) | ||
| 1519 | (condition-case () | ||
| 1520 | (setq possibilities (file-name-all-completions | ||
| 1521 | base-versions | ||
| 1522 | (file-name-directory fn)) | ||
| 1523 | versions (sort (mapcar | ||
| 1524 | (function backup-extract-version) | ||
| 1525 | possibilities) | ||
| 1526 | '<) | ||
| 1527 | high-water-mark (apply 'max 0 versions) | ||
| 1528 | deserve-versions-p (or version-control | ||
| 1529 | (> high-water-mark 0)) | ||
| 1530 | number-to-delete (- (length versions) | ||
| 1531 | kept-old-versions kept-new-versions -1)) | ||
| 1532 | (file-error | ||
| 1533 | (setq possibilities nil))) | ||
| 1534 | (if (not deserve-versions-p) | ||
| 1535 | (list (make-backup-file-name fn)) | 1517 | (list (make-backup-file-name fn)) |
| 1536 | (cons (concat fn ".~" (int-to-string (1+ high-water-mark)) "~") | 1518 | (let* ((base-versions (concat (file-name-nondirectory fn) ".~")) |
| 1537 | (if (and (> number-to-delete 0) | 1519 | (bv-length (length base-versions)) |
| 1538 | ;; Delete nothing if there is overflow | 1520 | possibilities |
| 1539 | ;; in the number of versions to keep. | 1521 | (versions nil) |
| 1540 | (>= (+ kept-new-versions kept-old-versions -1) 0)) | 1522 | (high-water-mark 0) |
| 1541 | (mapcar (function (lambda (n) | 1523 | (deserve-versions-p nil) |
| 1542 | (concat fn ".~" (int-to-string n) "~"))) | 1524 | (number-to-delete 0)) |
| 1543 | (let ((v (nthcdr kept-old-versions versions))) | 1525 | (condition-case () |
| 1544 | (rplacd (nthcdr (1- number-to-delete) v) ()) | 1526 | (setq possibilities (file-name-all-completions |
| 1545 | v)))))))) | 1527 | base-versions |
| 1528 | (file-name-directory fn)) | ||
| 1529 | versions (sort (mapcar | ||
| 1530 | (function backup-extract-version) | ||
| 1531 | possibilities) | ||
| 1532 | '<) | ||
| 1533 | high-water-mark (apply 'max 0 versions) | ||
| 1534 | deserve-versions-p (or version-control | ||
| 1535 | (> high-water-mark 0)) | ||
| 1536 | number-to-delete (- (length versions) | ||
| 1537 | kept-old-versions kept-new-versions -1)) | ||
| 1538 | (file-error | ||
| 1539 | (setq possibilities nil))) | ||
| 1540 | (if (not deserve-versions-p) | ||
| 1541 | (list (make-backup-file-name fn)) | ||
| 1542 | (cons (concat fn ".~" (int-to-string (1+ high-water-mark)) "~") | ||
| 1543 | (if (and (> number-to-delete 0) | ||
| 1544 | ;; Delete nothing if there is overflow | ||
| 1545 | ;; in the number of versions to keep. | ||
| 1546 | (>= (+ kept-new-versions kept-old-versions -1) 0)) | ||
| 1547 | (mapcar (function (lambda (n) | ||
| 1548 | (concat fn ".~" (int-to-string n) "~"))) | ||
| 1549 | (let ((v (nthcdr kept-old-versions versions))) | ||
| 1550 | (rplacd (nthcdr (1- number-to-delete) v) ()) | ||
| 1551 | v)))))))))) | ||
| 1546 | 1552 | ||
| 1547 | (defun file-nlinks (filename) | 1553 | (defun file-nlinks (filename) |
| 1548 | "Return number of names file FILENAME has." | 1554 | "Return number of names file FILENAME has." |