Skip to content

Instantly share code, notes, and snippets.

@mwilliams
Created December 8, 2009 20:59
Show Gist options
  • Select an option

  • Save mwilliams/251994 to your computer and use it in GitHub Desktop.

Select an option

Save mwilliams/251994 to your computer and use it in GitHub Desktop.
;;; DELETE CURRENT FILE
;;; Bound to C-k
(defun ido-delete-file-at-head ()
"Delete the file at the head of `ido-matches'.
If cursor is not at the end of the user input, delete to end of input."
(interactive)
(if (not (eobp))
(delete-region (point) (line-end-position))
(let ((enable-recursive-minibuffers t)
(file (ido-name (car ido-matches))))
(if file
(setq file (concat ido-current-directory file)))
(when (and file
(file-exists-p file)
(not (file-directory-p file))
(file-writable-p ido-current-directory)
(yes-or-no-p (concat "Delete " file "? ")))
(delete-file file)
;; Check if file still exists.
(if (file-exists-p file)
;; file could not be deleted
(setq ido-rescan t)
;; else file was killed so remove name from list.
(setq ido-cur-list (delq (car ido-matches) ido-cur-list)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment