Function: vc-delete-file

vc-delete-file is an autoloaded, interactive and byte-compiled function defined in vc.el.gz.

Signature

(vc-delete-file FILE-OR-FILES)

Documentation

Delete file and mark it as such in the version control system.

If called interactively, read FILE-OR-FILES, defaulting to the current buffer's file name if it's under version control. When called from Lisp, FILE-OR-FILES can be a file name or a list of file names.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc.el.gz
;;;###autoload
(defun vc-delete-file (file-or-files)
  "Delete file and mark it as such in the version control system.
If called interactively, read FILE-OR-FILES, defaulting to the current
buffer's file name if it's under version control.
When called from Lisp, FILE-OR-FILES can be a file name or a list of
file names."
  (interactive (list (read-file-name "VC delete file: " nil
                                     (when (vc-backend buffer-file-name)
                                       buffer-file-name)
                                     t)))
  (setq file-or-files (mapcar #'expand-file-name (ensure-list file-or-files)))
  (dolist (file file-or-files)
    (let ((buf (get-file-buffer file))
          (backend (vc-backend 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))
      (let ((state (vc-state file)))
        (when (eq state 'edited)
          (error "Please commit or undo your changes before deleting %s" file))
        (when (eq state 'conflict)
          (error "Please resolve the conflicts before deleting %s" file)))))
  (unless (y-or-n-p (if (cdr file-or-files)
                        (format "Really want to delete these %d files? "
                                (length file-or-files))
                      (format "Really want to delete %s? "
			      (file-name-nondirectory (car file-or-files)))))
    (error "Abort!"))
  (dolist (file file-or-files)
    (let ((buf (get-file-buffer file))
          (backend (vc-backend file)))
      (unless (or (file-directory-p file) (null make-backup-files)
                  (not (file-exists-p file)))
        (with-current-buffer (or buf (find-file-noselect file))
          (let ((backup-inhibited nil))
	    (backup-buffer))))
      (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)
      ;; Make sure the buffer is deleted and the *vc-dir* buffers are
      ;; updated after this.
      (vc-resynch-buffer file nil t))))