From b5c9d12e6b9c25a10b078bb51e6fc976dd7afab6 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 26 Sep 2016 15:59:32 +0200 Subject: [PATCH] Add delete-current-buffer-file and bind it --- init.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/init.el b/init.el index 13fde80..d2432b8 100644 --- a/init.el +++ b/init.el @@ -493,3 +493,21 @@ Version 2016-02-16" name (file-name-nondirectory new-name))))))) (global-set-key (kbd "C-x C-r") 'rename-current-buffer-file) + +; Copied from http://whattheemacsd.com/file-defuns.el-02.html +(defun delet-current-buffer-file () + "Removes file connected to current buffer and kills the + buffer." + (interactive) + + (let ((filename (buffer-file-name)) + (name (buffer-name)) + (buffer (current-buffer))) + (if (not (and filename (file-exists-p filename))) + (kill-buffer buffer) + (when (yes-or-no-p "Are you sure you want to remove this file? ") + (delete-file filename) + (kill-buffer buffer) + (message "File '%s' successfully removed" filename))))) + +(global-set-key (kbd "C-x C-d") 'delete-current-buffer-file)