Added delete-this-file.

Pascal J. Bourguignon [2017-07-26 10:52]
Added delete-this-file.
Filename
pjb-emacs.el
diff --git a/pjb-emacs.el b/pjb-emacs.el
index e741d54..3792bb3 100644
--- a/pjb-emacs.el
+++ b/pjb-emacs.el
@@ -137,6 +137,7 @@


 (defun recover-this-file ()
+  "Recovers the file of the current buffer, if any."
   (interactive)
   (let ((file-path  (buffer-file-name)))
     (if (and file-path (file-exists-p file-path) (file-regular-p file-path))
@@ -144,6 +145,19 @@
         (message "This buffer has no associated file."))))


+(defun delete-this-file (kill-buffer)
+  "Deletes the file of the current buffer, if any.
+When KILL-BUFFER is true (command prefix), also kills the buffer."
+  (interactive "P")
+  (let ((file-path  (buffer-file-name)))
+    (if (and file-path (file-exists-p file-path) (file-regular-p file-path))
+        (progn
+          (delete-file file-path)
+          (when kill-buffer
+            (kill-buffer)))
+        (message "This buffer has no associated file."))))
+
+
 (defvar buffer-name-map   nil)
 (defvar buffer-list-cache nil)
ViewGit