From f9172be29a699300d6d4fc054e6bb81e93823df3 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 18 Dec 2025 21:46:49 +0000 Subject: [PATCH] Make VC-Dir's 'd' able to delete unregistered files * lisp/vc/vc.el (vc-delete-file): Simplify. * lisp/vc/vc-dir.el (vc-dir-delete-file): Handle deleting unregistered files, too. (vc-dir-menu-map, vc-dir-mode-map): Replace bindings for vc-dir-clean-files with ones for vc-dir-delete-file. * doc/emacs/maintaining.texi (VC Directory Commands): * etc/NEWS: Document the bindings change. --- doc/emacs/maintaining.texi | 5 ++--- etc/NEWS | 7 +++++++ lisp/vc/vc-dir.el | 9 ++++----- lisp/vc/vc.el | 18 +++++++++--------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index cc5e813f018..29e05ba17e5 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -1707,9 +1707,8 @@ Branches}. @item d Delete the marked files, or the current file if no marks -(@code{vc-dir-clean-delete)}. The files will not be marked as -deleted in the version control system, so this function is mostly -useful for unregistered files. +(@code{vc-dir-delete-file)}. If the files are registered, they will be +marked as deleted in the version control system. @end table @cindex stashes in version control diff --git a/etc/NEWS b/etc/NEWS index e90000a9f58..ec3e5c613db 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2501,6 +2501,13 @@ Previously, Emacs would simply refuse to make any changes. You can customize 'vc-dir-allow-mass-mark-changes' to restore the old behavior or dispense with the prompting. ++++ +*** VC Directory's 'd' command can now delete unregistered files too. +Previously, this command could only delete registered files. +To restore the old, more limited behavior, you can do + + (keymap-set vc-dir-mode-map "d" #'vc-dir-clean-files) + --- *** New VC Directory bindings 'z d' and 'D' to delete Git stashes. These correspond to the existing 'z p' to pop a stash and 'P' to pop the diff --git a/lisp/vc/vc-dir.el b/lisp/vc/vc-dir.el index 59aa24460d3..11083878025 100644 --- a/lisp/vc/vc-dir.el +++ b/lisp/vc/vc-dir.el @@ -279,8 +279,8 @@ That is, refreshing the VC-Dir buffer also hides `up-to-date' and '(menu-item "Open File" vc-dir-find-file :help "Find the file on the current line")) (define-key map [delete] - '(menu-item "Delete" vc-dir-clean-files - :help "Delete the unregistered marked files")) + '(menu-item "Delete" vc-dir-delete-files + :help "Delete marked files")) (define-key map [sepvcdet] '("--")) ;; FIXME: This needs a key binding. And maybe a better name ;; ("Insert" like PCL-CVS uses does not sound that great either)... @@ -362,7 +362,7 @@ That is, refreshing the VC-Dir buffer also hides `up-to-date' and ;; bound by `special-mode'. ;; Marking. (define-key map "m" #'vc-dir-mark) - (define-key map "d" #'vc-dir-clean-files) + (define-key map "d" #'vc-dir-delete-file) (define-key map "M" #'vc-dir-mark-all-files) (define-key map "u" #'vc-dir-unmark) (define-key map "U" #'vc-dir-unmark-all-files) @@ -1028,8 +1028,7 @@ tracked by a VCS." The files will also be marked as deleted in the version control system." (interactive) - (mapc #'vc-delete-file (or (vc-dir-marked-files) - (list (vc-dir-current-file))))) + (vc-delete-file (or (vc-dir-marked-files) (vc-dir-current-file)))) (defun vc-dir-find-file () "Find the file on the current line." diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 63215015297..4887df63141 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -4492,10 +4492,8 @@ file names." (dolist (file file-or-files) (let ((buf (get-file-buffer file)) (backend (vc-backend file))) - (unless backend - (error "File %s is not under version control" - (file-name-nondirectory file))) - (unless (vc-find-backend-function backend 'delete-file) + (unless (or (not backend) + (vc-find-backend-function backend 'delete-file)) (error "Deleting files under %s is not supported in VC" backend)) (when (and buf (buffer-modified-p buf)) (error "Please save or undo your changes before deleting %s" file)) @@ -4518,11 +4516,13 @@ file names." (with-current-buffer (or buf (find-file-noselect file)) (let ((backup-inhibited nil)) (backup-buffer)))) - ;; Bind `default-directory' so that the command that the backend - ;; runs to remove the file is invoked in the correct context. - (let ((default-directory (file-name-directory file))) - (vc-call-backend backend 'delete-file file)) - ;; If the backend hasn't deleted the file itself, let's do it for him. + (when backend + ;; Bind `default-directory' so that the command that the backend + ;; runs to remove the file is invoked in the correct context. + (let ((default-directory (file-name-directory file))) + (vc-call-backend backend 'delete-file file))) + ;; For the case of unregistered files, or if the backend didn't + ;; actually delete the file. (when (file-exists-p file) (delete-file file)) ;; Forget what VC knew about the file. (vc-file-clearprops file)