Skip to content

Instantly share code, notes, and snippets.

@hyOzd
Created July 21, 2015 11:55
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyOzd/23b87e96d43bca0f0b52 to your computer and use it in GitHub Desktop.
Save hyOzd/23b87e96d43bca0f0b52 to your computer and use it in GitHub Desktop.
emacs delete current file and close the buffer
;; based on http://emacsredux.com/blog/2013/04/03/delete-file-and-buffer/
(defun delete-file-and-buffer ()
"Kill the current buffer and deletes the file it is visiting."
(interactive)
(let ((filename (buffer-file-name)))
(if filename
(if (y-or-n-p (concat "Do you really want to delete file " filename " ?"))
(progn
(delete-file filename)
(message "Deleted file %s." filename)
(kill-buffer)))
(message "Not a file visiting buffer!"))))
@safijari
Copy link

Hey thanks for this. Very handy.

@hiddink
Copy link

hiddink commented Apr 5, 2022

Thankyous from me also. +1

@baratali
Copy link

thank you!

@domantasburba
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment