Discussion:
[emms-help] emms-browser-add-tracks weirdness
Fran Burstall
2018-11-20 23:00:06 UTC
Permalink
I fire emms-smart-browse and, without selecting a region,
hit <return> in front of an album to invoke emms-browser-add-tracks.

What I expect: tracks from that album to be added to the
playlist.

What happens: I get the error "The mark is not set now, so
there is no region" and no tracks added.

Commentary: the error is produced by the

(interactive "r")

form at the start of emms-browser-add-tracks.

It seems that this is not a reliable way to work
with a possibly empty region according to the discussion at

https://stackoverflow.com/questions/13281026/how-to-use-interactive-r-function-in-this-situation

Can anyone else replicate this? If so, I will fix...


---Fran

emms: master
emacs: 26.1
Pierre Neidhardt
2018-11-21 08:52:46 UTC
Permalink
I remember I had this issue a while back, but if I'm not mistaken this has been
fixed.
Are you running Emms 5.1?

Here is the code in 5.1:

--8<---------------cut here---------------start------------->8---
(defun emms-browser-add-tracks (&optional start end)
"Add all tracks at point or in region if active.
When the region is not active, a numeric prefix argument inserts that many
tracks from point.
Return the playlist buffer point-max before adding."
(interactive "r")
(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)))
(first-new-track (with-current-emms-playlist (point-max))))
(when (use-region-p) (goto-char start))
(dotimes (_ count first-new-track)
(let ((bdata (emms-browser-bdata-at-point)))
(when bdata
(emms-browser-playlist-insert-bdata
bdata (emms-browser-bdata-level bdata))
(forward-line))))
(run-hook-with-args 'emms-browser-tracks-added-hook
first-new-track)
(deactivate-mark)
first-new-track))
--8<---------------cut here---------------end--------------->8---

I don't see a problem there, but I could be wrong.
--
Pierre Neidhardt
https://ambrevar.xyz/
Fran Burstall (Gmail)
2018-11-21 09:05:51 UTC
Permalink
Hi,

I am using emms 5.1 (I am tracking master) and the code you show is the
code I see.

The issue arises when (interactive "r") is confronted with nil values for
start and end. I do not understand why this is happening because I can
write test functions where this form does not barf on nil arguments but it
errors out when used by emms-browser-add-tracks.

---Fran
Post by Pierre Neidhardt
I remember I had this issue a while back, but if I'm not mistaken this has been
fixed.
Are you running Emms 5.1?
--8<---------------cut here---------------start------------->8---
(defun emms-browser-add-tracks (&optional start end)
"Add all tracks at point or in region if active.
When the region is not active, a numeric prefix argument inserts that many
tracks from point.
Return the playlist buffer point-max before adding."
(interactive "r")
(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)))
(first-new-track (with-current-emms-playlist (point-max))))
(when (use-region-p) (goto-char start))
(dotimes (_ count first-new-track)
(let ((bdata (emms-browser-bdata-at-point)))
(when bdata
(emms-browser-playlist-insert-bdata
bdata (emms-browser-bdata-level bdata))
(forward-line))))
(run-hook-with-args 'emms-browser-tracks-added-hook
first-new-track)
(deactivate-mark)
first-new-track))
--8<---------------cut here---------------end--------------->8---
I don't see a problem there, but I could be wrong.
--
Pierre Neidhardt
https://ambrevar.xyz/
Fran Burstall (Gmail)
2018-11-21 22:33:24 UTC
Permalink
Post by Fran Burstall (Gmail)
Hi,
I am using emms 5.1 (I am tracking master) and the code you show is
the code I see.
The issue arises when (interactive "r") is confronted with nil values
for start and end. I do not understand why this is happening because
I can write test functions where this form does not barf on nil
arguments but it errors out when used by emms-browser-add-tracks.
---Fran
Does this only happen when the browser buffer is a new one where a
mark/region has never been established? I would assume that once a mark
had been established in the buffer the problem wouldn't show up.
Exactly so: everything works fine once you set a mark. So a minor
irritation rather than a show-stopper.

---Fran
Loading...