all repos — nixfiles @ 558d23085fab11e8f49ae583c71f203279c4e8bc

System and user configuration, managed by nix and home-manager

emacs: don't stop me deleting files which have changes in git
Alan Pearce alan@alanpearce.eu
Mon, 13 May 2024 21:50:56 +0200
commit

558d23085fab11e8f49ae583c71f203279c4e8bc

parent

9525dddaa025a9a779730f029fe39091804bbf83

1 files changed, 11 insertions(+), 1 deletions(-)

jump to
M user/emacs/init.eluser/emacs/init.el
@@ -632,6 +632,16 @@ (global-auto-revert-mode t))) 
 (setq delete-by-moving-to-trash t)
 
+(defun my/delete-file-and-buffer ()
+  "Kill the current buffer and deletes the file it is visiting."
+  (interactive)
+  (let ((filename (buffer-file-name)))
+    (when filename
+      (when (y-or-n-p (format "Are you sure you want to delete %s? " filename))
+        (delete-file filename delete-by-moving-to-trash)
+        (message "Deleted file %s" filename)
+        (kill-buffer)))))
+
 (use-package goto-chg
   :defer 1)
 
@@ -1143,7 +1153,7 @@ "e" '(:keymap envrc-command-map :package envrc)   "fs" #'save-buffer
   "ff" #'find-file
   "fw" #'write-file
-  "fd" #'crux-delete-file-and-buffer
+  "fd" #'my/delete-file-and-buffer
   "fr" #'crux-rename-file-and-buffer
   "gs" #'magit-status
   "gm" #'vc-msg-show