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.
This commit is contained in:
Sean Whitton 2025-12-18 21:46:49 +00:00
parent 1cd6428bce
commit f9172be29a
4 changed files with 22 additions and 17 deletions

View file

@ -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

View file

@ -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

View file

@ -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."

View file

@ -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)