Discussion:
[emms-help] [PATCH] Clean up trashing functions and comment bugs
Alejandro Erickson
2016-06-22 22:34:41 UTC
Permalink
(emms-browser-move-files-to-trash) mimics the behaviour
of (emms-browser-delete-files), using (delete-file path t) in order to
ultimately call (move-file-to-trash FILENAME). This allows users to keep
the `delete' functionality of `delete-file` and
`delete-directory` (which can be set to send to trash instead), and also
gives some confidence in the music removal and organisation features of
emms (that they won't accidentally permanently delete music).

Note bug in same function and emms-browser-delete-files, that os
x (darwin) files .DS_Store prevent deletion of empty directories. I
don't know enough elisp to fix this.

Note bug in commented function `de-kill-covers-and-parent`, that it
decides whether or not an album has been deleted based on how many
tracks were deleted. This is obviously going to give both false
positives and false negatives. It should instead check whether there
are non-image files (or .DS_Store) in the directories in question.
---
lisp/emms-browser.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)

diff --git a/lisp/emms-browser.el b/lisp/emms-browser.el
index 23b1495..5efaa1d 100644
--- a/lisp/emms-browser.el
+++ b/lisp/emms-browser.el
@@ -263,6 +263,10 @@
;; The following code will delete covers at the same time, and remove
;; parent directories if they're now empty.

+;; Note that deleting more than one song from an album can result in
+;; deleting its album art too. Conversely, deleting the last song in
+;; an album will not delete the album art.
+
;; (defun de-kill-covers-and-parents (dir tracks)
;; (when (> (length tracks) 1)
;; ;; if we're not deleting an individual file, delete covers too
@@ -412,6 +416,13 @@ Use nil for no sorting."
:group 'emms-browser
:type 'hook)

+(defcustom emms-browser-move-files-to-trash-hook nil
+ "*Hook run after files have been moved to trash.
+This hook can be used to clean up extra files, such as album covers.
+Called once for each directory."
+ :group 'emms-browser
+ :type 'hook)
+
(defcustom emms-browser-delete-files-hook nil
"*Hook run after files have been deleted.
This hook can be used to clean up extra files, such as album covers.
@@ -1353,6 +1364,9 @@ Disabled by default."
(emms-cache-del path))
;; remove empty dirs
(dolist (dir dirs)
+ ;; If os x should check whether the only thing left is .DS_Store directory
+ ;; and delete it if that is the case. Otherwise it prevents the directory
+ ;; from being removed.
(run-hook-with-args 'emms-browser-delete-files-hook dir tracks)
(condition-case nil
(delete-directory dir)
@@ -1363,6 +1377,38 @@ Disabled by default."

(put 'emms-browser-delete-files 'disabled t)

+(defun emms-browser-move-files-to-trash ()
+ "Move all files under point to trash.
+Disabled by default."
+ (interactive)
+ (let ((tracks (emms-browser-tracks-at-point))
+ dirs path)
+ (unless (yes-or-no-p
+ (format "Really permanently move these %d tracks to trash? "
+ (length tracks)))
+ (error "Cancelled!"))
+ (message "Moving files to trash..")
+ (dolist (track tracks)
+ (setq path (emms-track-get track 'name))
+ (delete-file path t)
+ (add-to-list 'dirs (file-name-directory path))
+ (emms-cache-del path))
+ ;; remove empty dirs
+ (dolist (dir dirs)
+ ;; If os x, should check whether the only thing left is .DS_Store directory
+ ;; and delete it if that is the case. Otherwise it prevents the directory
+ ;; from being removed.
+ (run-hook-with-args 'emms-browser-move-files-to-trash-hook dir tracks)
+ (condition-case nil
+ (delete-directory dir nil t)
+ (error nil)))
+ ;; remove the item from the browser
+ (emms-browser-delete-current-node)
+ (message "Moving files to trash..done")))
+
+ ;; disable this function so you have to do an extra confirmation to use it.
+(put 'emms-browser-move-files-to-trash 'disabled t)
+
(defun emms-browser-clear-playlist ()
(interactive)
(with-current-emms-playlist
--
2.8.3
Yoni Rabkin
2016-06-24 21:35:31 UTC
Permalink
Can someone who uses the Browser weigh in on these changes?
--
"Cut your own wood and it will warm you twice"
Alejandro Erickson
2016-06-25 00:33:37 UTC
Permalink
For what it's worth, this doesn't break anything. It just adds the trash
function and hook, mimicking the delete function. Also, it includes some
code-comments on bugs that I don't know how to fix.
Post by Yoni Rabkin
Can someone who uses the Browser weigh in on these changes?
--
"Cut your own wood and it will warm you twice"
--
Dr. Alejandro Erickson
Postdoctoral Research Associate in Computer Science, Durham University, UK
*phone: (+44) **07456794009*
http://alejandroerickson.com
Loading...