summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2023-08-06 07:00:22 -0400
committerEric S. Raymond <esr@thyrsus.com>2023-08-06 09:31:39 -0400
commit10a7615b5d45bcd909bb03d67423b337dfe93b1e (patch)
tree125c1990b016f37bd7ba200d180d961515f7831c /lisp
parent2924541b8f17e31eea58b231d1af7c0c8844deff (diff)
downloademacs-10a7615b5d45bcd909bb03d67423b337dfe93b1e.tar.gz
emacs-10a7615b5d45bcd909bb03d67423b337dfe93b1e.tar.bz2
emacs-10a7615b5d45bcd909bb03d67423b337dfe93b1e.zip
Separate filename-deletion mechanism from policy.
src/fileio.c: (delete-file-internal) Renamed from delete-file, parallel to delete-directory-internal; policy code moved to Lisp. src/files.el: (delete-file) New function, holds policy logic. calls delete-file-internal. This is a pure refactoring step, delete-file's behavior is unchanged. But the C core is a little simpler now.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/lisp/files.el b/lisp/files.el
index f8867432000..84a8c308b09 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6352,6 +6352,26 @@ non-nil and if FN fails due to a missing file or directory."
(apply fn args)
(file-missing (or no-such (signal (car err) (cdr err))))))
+(defun delete-file (filename &optional trash)
+ "Delete file named FILENAME. If it is a symlink, remove the symlink.
+If file has multiple names, it continues to exist with the other names.q
+TRASH non-nil means to trash the file instead of deleting, provided
+`delete-by-moving-to-trash' is non-nil.
+
+When called interactively, TRASH is t if no prefix argument is given.
+With a prefix argument, TRASH is nil."
+ (interactive (list (read-file-name
+ (if (and delete-by-moving-to-trash (null current-prefix-arg))
+ "Move file to trash: " "Delete file: ")
+ nil default-directory (confirm-nonexistent-file-or-buffer))
+ (null current-prefix-arg)))
+ (if (and (file-directory-p filename) (not (file-symlink-p filename)))
+ (signal 'file-error (list "Removing old name: is a directory" filename)))
+ (let* ((filename (expand-file-name filename)) (handler (find-file-name-handler filename 'delete-file)))
+ (cond (handler (funcall handler 'delete-file filename trash))
+ ((and delete-by-moving-to-trash trash) (move-file-to-trash filename))
+ (t (delete-file-internal filename)))))
+
(defun delete-directory (directory &optional recursive trash)
"Delete the directory named DIRECTORY. Does not follow symlinks.
If RECURSIVE is non-nil, delete files in DIRECTORY as well, with