unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56311: [PATCH] new function: delete-visited-file
@ 2022-06-30  4:26 Zachary Kanfer
  2022-06-30  5:30 ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Zachary Kanfer @ 2022-06-30  4:26 UTC (permalink / raw)
  To: 56311


[-- Attachment #1.1: Type: text/plain, Size: 415 bytes --]

When I delete a file, I almost always want the buffer visiting it to go
away also. Why keep it around? So I have to do the following steps:

1. M-x delete-file
2. navigate to the file, select it.
3. C-x k <ret>

So I wrote a function to delete the file a buffer is visiting, and close
the buffer. Now I do everything in a single logical action:

1. M-x delete-visited-file
2. select the buffer.

Patch is attached.

[-- Attachment #1.2: Type: text/html, Size: 513 bytes --]

[-- Attachment #2: 0001-Add-new-function-delete-visited-file.patch --]
[-- Type: text/x-patch, Size: 2336 bytes --]

From 7ce913013a022ec84b11f3abc22bc82e06825f1e Mon Sep 17 00:00:00 2001
From: Zachary Kanfer <zkanfer@gmail.com>
Date: Thu, 30 Jun 2022 00:21:01 -0400
Subject: [PATCH] Add new function delete-visited-file.

* lisp/files.el (delete-visited-file) New command

* doc/emacs/files.texi (Miscellaneous File Operations): Document it.
---
 doc/emacs/files.texi |  2 ++
 etc/NEWS             |  5 +++++
 lisp/files.el        | 11 +++++++++++
 3 files changed, 18 insertions(+)

diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index fa02d264f9..4bfda182b4 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -1930,6 +1930,8 @@ Misc File Ops
 execution permission for the user who owns the file.  It has no effect
 on operating systems that do not support file modes.  @code{chmod} is a
 convenience alias for this function.
+@findex delete-visited-file
+  @kbd{delete-visited-file} deletes the file visited by a buffer, and closes the buffer.
 
 @node Compressed Files
 @section Accessing Compressed Files
diff --git a/etc/NEWS b/etc/NEWS
index ce32542028..b5524d35fd 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -355,6 +355,11 @@ match those regexps will be ignored by 'switch-to-prev-buffer' and
 This command renames the file visited by the current buffer by moving
 it to a new location, and also makes the buffer visit this new file.
 
++++
+** New command 'delete-visited-file'.
+This command deletes the file visited by a buffer, then closes the
+buffer.
+
 ** Menus
 
 ---
diff --git a/lisp/files.el b/lisp/files.el
index 1295c24c93..f5d512d6be 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6267,6 +6267,17 @@ delete-directory
 		  directory-exists))
 	(files--force recursive #'delete-directory-internal directory))))))
 
+(defun delete-visited-file (buffer-name)
+  "Delete the file visited by buffer BUFFER-NAME, then close the buffer."
+  (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))))
+
 (defun file-equal-p (file1 file2)
   "Return non-nil if files FILE1 and FILE2 name the same file.
 If FILE1 or FILE2 does not exist, the return value is unspecified."
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-08-02 11:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30  4:26 bug#56311: [PATCH] new function: delete-visited-file Zachary Kanfer
2022-06-30  5:30 ` Eli Zaretskii
2022-06-30  5:49   ` Sean Whitton
2022-06-30  5:56     ` Eli Zaretskii
2022-06-30  6:20   ` Visuwesh
2022-06-30 10:27     ` Lars Ingebrigtsen
2022-06-30 16:29       ` Sean Whitton
2022-07-01  3:29         ` Zachary Kanfer
2022-07-01  5:57           ` Eli Zaretskii
2022-07-03  5:06             ` Zachary Kanfer
2022-07-03  6:04               ` Eli Zaretskii
2022-08-02 11:12                 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).