Here's a emacs lisp command that deletes the current file.
(defun delete-current-file (ξno-backup-p) "Delete the file associated with the current buffer. Also close the current buffer. If no file is associated, just close buffer without prompt for save. A backup file is created with filename appended “~‹date time stamp›~”. Existing file of the same name is overwritten. when called with `universal-argument', don't create backup." (interactive "P") (let (fName) (when (buffer-file-name) ; buffer is associated with a file (setq fName (buffer-file-name)) (save-buffer fName) (if ξno-backup-p (progn ) (copy-file fName (concat fName "~" (format-time-string "%Y%m%d_%H%M%S") "~") t) ) (delete-file fName) (message "「%s」 deleted." fName) ) (kill-buffer (current-buffer)) ) )
Here's some basic explanation:
(interactive "P")sets emacs to pass on “universal-argument” to your function. 〔☛ Emacs Lisp: Writing Command to Accept universal-argument〕
(buffer-file-name)gets the file name. If the buffer isn't associated with a file, then