Hi Hugo,

>From the docs of `next-line`:

This function is for interactive use only;
>   in Lisp code use ‘forward-line’ instead.


Make this replacement and yr code works (at least for me).

---Fran

PS Zoe and Phoebe H say hi.



On Sun, 19 Dec 2021 at 15:49, <[email protected]> wrote:

> I'm writing a consult-based interface for EMMS. consult--read is a
> function much like completing-read. I want to write a function which
> presents the current playlist in a completing-read like interface, and the
> jumps to the track the user selects. I intend this with embark actions for
> more operations (moving/killing tracks etc.)
>
> So, I need to get a list of tracks in the current playlist, in such a way
> that I can then write a function which plays the selected one. The basic
> data structure of EMMS is a buffer with a list of tracks, so I decided to
> get an alist of track names and the value of point where that track is
> (this makes it pretty simple to write a function which visits the right
> bffer, goes to that char, then plays the track at point). I have this:
>
> ```elisp
> (cl-remove-if
>  (lambda (cell) (null (car cell)))
>  (with-current-buffer emms-playlist-buffer
>    (save-excursion
>      (cl-loop initially do (goto-char (point-min))
>               until (eobp)
>               collect (cons
>                        (emms-track-get (emms-playlist-track-at)
> 'info-title)
>                        (point))
>               do (next-line)))))
> ```
>
> Breaking this down a bit, the idea:
> - in the current playlist buffer (`(with-current-buffer
> emms-playlist-buffer...`)
> - goto to the begining (`initially do (goto-char (point-min))`)
> - push a cons of the track title and value of point into a list, then go
> to the next line (`collect (cons (emms-track-get (emms-playlist-track-at)
> 'info-title) \n do (next-line)`)
> - repeat until end of buffer (`until (eobp)`)
> - Finally, return resuling alist, and remove any cells with a null car
> (`(cl-remove-if (lambda (cell) (null (car cell)))`. This deals with lines
> in the playlist which are not actually tracks (e.g. lines with album art).
>
> This works -- mostly. For some reason, I can run it and get the list I
> expect (of say, the 173 tracks I have in my current playlist right now),
> then run it again and get a much shorter list (of say 97 songs), alway a
> subset of the 'correct' list. In cases of the first kind, my function for
> playing the selected song (goto the char, then play the track at point)
> always works, but in the second case (innacurate list) it often plays the
> wrong track, suggesting that the list is being constructed wrong.
>
> But how? I can't work out what could be different between the two
> invocations -- the difference between then can be literally a few seconds.
> If I then visit the EMMS playlist buffer (say, by runing
> `emms-smart-browse`), the function always works again as expected.
>
> I have two questions then:
> - What is happening with my implementation above? Why does it sometimes
> give me the wrong list?
> - Is there just a better way to achieve what I want? (I want to aviod the
> XY problem -- no point solving problems I don't need to!)
>
> Any help greatly appreciated.
>
> Blue skies, Hugo
>
>
>

Reply via email to