diff options
| author | Juri Linkov | 2019-11-07 01:14:58 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-11-07 01:14:58 +0200 |
| commit | deb61da7a27698ddc0b95ba92d18c20f533bb802 (patch) | |
| tree | 2309fc8637f80d5ba4607f8a5527555e860248d0 | |
| parent | 528485d0172f00e5f0c8ea548013a49964be501b (diff) | |
| download | emacs-deb61da7a27698ddc0b95ba92d18c20f533bb802.tar.gz emacs-deb61da7a27698ddc0b95ba92d18c20f533bb802.zip | |
* lisp/dired-aux.el (dired-vc-rename-file): New defcustom.
(dired-rename-file): Call vc-rename-file when dired-vc-rename-file is non-nil.
* lisp/vc/vc.el (vc-rename-file): Allow renaming added files.
Call vc-file-clearprops on new file too for the case when
old and new files were renamed to each other back and forth.
https://lists.gnu.org/archive/html/emacs-devel/2019-11/msg00069.html
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/dired-aux.el | 17 | ||||
| -rw-r--r-- | lisp/vc/vc.el | 3 |
3 files changed, 21 insertions, 2 deletions
| @@ -846,6 +846,9 @@ directories in the destination. | |||
| 846 | *** The non-nil value of 'dired-dwim-target' uses one of the most recently | 846 | *** The non-nil value of 'dired-dwim-target' uses one of the most recently |
| 847 | visited windows with a Dired buffer instead of the next window. | 847 | visited windows with a Dired buffer instead of the next window. |
| 848 | 848 | ||
| 849 | *** When the new user option 'dired-vc-rename-file' is non-nil, | ||
| 850 | Dired performs file renaming using underlying version control system. | ||
| 851 | |||
| 849 | ** Find-Dired | 852 | ** Find-Dired |
| 850 | 853 | ||
| 851 | *** New user option 'find-dired-refine-function'. | 854 | *** New user option 'find-dired-refine-function'. |
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index b1521ecf018..722d036e3fc 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el | |||
| @@ -1635,11 +1635,26 @@ If `ask', ask for user confirmation." | |||
| 1635 | dired-create-files-failures) | 1635 | dired-create-files-failures) |
| 1636 | (dired-log "Can't set date on %s:\n%s\n" from err)))))) | 1636 | (dired-log "Can't set date on %s:\n%s\n" from err)))))) |
| 1637 | 1637 | ||
| 1638 | (defcustom dired-vc-rename-file nil | ||
| 1639 | "Whether Dired should register file renaming in underlying vc system. | ||
| 1640 | If nil, use default `rename-file'. | ||
| 1641 | If non-nil and the renamed files are under version control, | ||
| 1642 | rename them using `vc-rename-file'." | ||
| 1643 | :type '(choice (const :tag "Use rename-file" nil) | ||
| 1644 | (const :tag "Use vc-rename-file" t)) | ||
| 1645 | :group 'dired | ||
| 1646 | :version "27.1") | ||
| 1647 | |||
| 1638 | ;;;###autoload | 1648 | ;;;###autoload |
| 1639 | (defun dired-rename-file (file newname ok-if-already-exists) | 1649 | (defun dired-rename-file (file newname ok-if-already-exists) |
| 1640 | (dired-handle-overwrite newname) | 1650 | (dired-handle-overwrite newname) |
| 1641 | (dired-maybe-create-dirs (file-name-directory newname)) | 1651 | (dired-maybe-create-dirs (file-name-directory newname)) |
| 1642 | (rename-file file newname ok-if-already-exists) ; error is caught in -create-files | 1652 | (if (and dired-vc-rename-file |
| 1653 | (vc-backend file) | ||
| 1654 | (ignore-errors (vc-responsible-backend newname))) | ||
| 1655 | (vc-rename-file file newname) | ||
| 1656 | ;; error is caught in -create-files | ||
| 1657 | (rename-file file newname ok-if-already-exists)) | ||
| 1643 | ;; Silently rename the visited file of any buffer visiting this file. | 1658 | ;; Silently rename the visited file of any buffer visiting this file. |
| 1644 | (and (get-file-buffer file) | 1659 | (and (get-file-buffer file) |
| 1645 | (with-current-buffer (get-file-buffer file) | 1660 | (with-current-buffer (get-file-buffer file) |
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index c982b0220e3..20056dec7f9 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el | |||
| @@ -2913,11 +2913,12 @@ current buffer's file name if it's under version control." | |||
| 2913 | (when (file-exists-p new) | 2913 | (when (file-exists-p new) |
| 2914 | (error "New file already exists")) | 2914 | (error "New file already exists")) |
| 2915 | (let ((state (vc-state old))) | 2915 | (let ((state (vc-state old))) |
| 2916 | (unless (memq state '(up-to-date edited)) | 2916 | (unless (memq state '(up-to-date edited added)) |
| 2917 | (error "Please %s files before moving them" | 2917 | (error "Please %s files before moving them" |
| 2918 | (if (stringp state) "check in" "update")))) | 2918 | (if (stringp state) "check in" "update")))) |
| 2919 | (vc-call rename-file old new) | 2919 | (vc-call rename-file old new) |
| 2920 | (vc-file-clearprops old) | 2920 | (vc-file-clearprops old) |
| 2921 | (vc-file-clearprops new) | ||
| 2921 | ;; Move the actual file (unless the backend did it already) | 2922 | ;; Move the actual file (unless the backend did it already) |
| 2922 | (when (file-exists-p old) (rename-file old new)) | 2923 | (when (file-exists-p old) (rename-file old new)) |
| 2923 | ;; ?? Renaming a file might change its contents due to keyword expansion. | 2924 | ;; ?? Renaming a file might change its contents due to keyword expansion. |