aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorPierre Neidhardt <ambrevar@gmail.com>2018-04-09 16:03:16 +0530
committerPierre Neidhardt <ambrevar@gmail.com>2018-04-09 23:09:34 +0530
commitd4ba37fcab1ad377319c52a8131de32cf9d306d7 (patch)
tree3ff856658c3bebf973270a6c17220a21414d6cf5 /lisp
parent2bc4236bb1b1cf1605ea155fb8d22c6b2ab06283 (diff)
* lisp/emms-browser.el: Support region and prefix arg from emms-browser-remove-tracks
Diffstat (limited to 'lisp')
-rw-r--r--lisp/emms-browser.el49
1 files changed, 33 insertions, 16 deletions
diff --git a/lisp/emms-browser.el b/lisp/emms-browser.el
index 4079181..41d6ad1 100644
--- a/lisp/emms-browser.el
+++ b/lisp/emms-browser.el
@@ -1390,28 +1390,47 @@ Return the playlist buffer point-max before adding."
(emms-browser-view-in-dired (car (emms-browser-bdata-data bdata))))
(emms-browser-view-in-dired (emms-browser-bdata-at-point))))
-(defun emms-browser-remove-tracks (&optional delete)
+(defun emms-browser-remove-tracks (&optional delete start end)
"Remove all tracks at point or in region if active.
Unless DELETE is non-nil or with prefix argument, this only acts on the browser,
files are untouched.
If caching is enabled, files are removed from the cache as well.
-When the region is not active, a numeric prefix argument inserts that many
-tracks from point."
- (interactive "P")
- (let ((tracks (emms-browser-tracks-at-point))
- dirs path)
+When the region is not active, a numeric prefix argument remove that many
+tracks from point, it does not delete files."
+ (interactive "P\nr")
+ (let ((count (cond
+ ((use-region-p)
+ (1+ (- (line-number-at-pos end) (line-number-at-pos start))))
+ ((numberp current-prefix-arg)
+ current-prefix-arg)
+ (t 1)))
+ dirs path tracks)
+ ;; If numeric prefix argument, never delete files.
+ (when (numberp delete) (setq delete nil))
(when delete
+ (save-mark-and-excursion
+ (when (use-region-p) (goto-char start))
+ (let ((lines (min count (- (line-number-at-pos (point-max)) (line-number-at-pos (point))))))
+ (dotimes (_ lines)
+ ;; TODO: Test this!
+ (setq tracks (append tracks (emms-browser-tracks-at-point)))
+ (forward-line))))
(unless (yes-or-no-p
- (format "Really permanently delete these %d tracks? "
- (length tracks)))
+ (format "Really permanently delete these %d tracks? " (length tracks)))
(error "Cancelled!"))
(message "Deleting files..."))
- (dolist (track tracks)
- (setq path (emms-track-get track 'name))
- (when delete
- (delete-file path))
- (add-to-list 'dirs (file-name-directory path))
- (emms-cache-del path))
+ (when (use-region-p) (goto-char start))
+ (dotimes (_ count)
+ (dolist (track (emms-browser-tracks-at-point))
+ (setq path (emms-track-get track 'name))
+ (when delete
+ (delete-file path))
+ (add-to-list 'dirs (file-name-directory path))
+ (emms-cache-del path))
+ ;; remove the item from the browser
+ (when (emms-browser-tracks-at-point)
+ (emms-browser-delete-current-node)))
+ (deactivate-mark)
;; remove empty dirs
(when delete
(dolist (dir dirs)
@@ -1419,8 +1438,6 @@ tracks from point."
(condition-case nil
(delete-directory dir)
(error nil))))
- ;; remove the item from the browser
- (emms-browser-delete-current-node)
(when delete
(message "Deleting files...done"))))