From f43fbf5c39982c21e552bfa96fe14aa4b814cc20 Mon Sep 17 00:00:00 2001 From: Mountain Man <43313373+MountainMan1312@users.noreply.github.com> Date: Tue, 30 May 2023 20:01:34 -0400 Subject: Add function to kill buffer after deleting file --- init.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/init.el b/init.el index af221ef..b9a5528 100644 --- a/init.el +++ b/init.el @@ -570,6 +570,30 @@ (global-auto-revert-mode t) +;; --------------------------------- +;; Delete files +;; ------------ +;; Make deleting files a lot more +;; convenient. +;; --------------------------------- + +;; It's possible to delete a file +;; and forget about it, then save +;; buffer again. This function kills +;; the buffer after deleting the +;; file. +(defun mm/delete-visited-file (buffer-name) + "Delete the file visited by BUFFER-NAME." + (interactive "bDelete file visited by buffer ") + (let* ((buffer (get-buffer buffer-name)) + (filename (buffer-file-name buffer))) + (when buffer + (when (and filename + (file-exists-p filename)) + (delete-file filename)) + (kill-buffer buffer)))) + + ;; --------------------------------- ;; Project management ;; ------------------ -- cgit v1.2.3