bongo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bongo-devel] Re: bongo-locate


From: Daniel Jensen
Subject: [bongo-devel] Re: bongo-locate
Date: Sun, 11 Feb 2007 15:45:55 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.92 (gnu/linux)

Daniel Brockman <address@hidden> writes:

> Dieter Deyke <address@hidden> writes:
>
>> Sometimes I want to listen to a song or group of songs
>> where the filename contains a certain substring, or
>> multiple substrings.  I have written a function called
>> bongo-locate which does that for me.
>
> Cool!  That's a useful feature.  Thanks.
>
> It would make sense to have this command on `i l', but then
> `bongo-insert-playlist-contents' would have to move to `i p'.
> (At least I think that's where we'd want to move it.)
>
> Objections?  Agreements?

I don't object to a `bongo-locate' command, but I'd like to see this
and the playlist commands refactored. They all insert tracks based on
another list of files. The locate command need not create a temporary
file, it can output to a temp buffer.

I suggest a new command, `bongo-insert-buffer'.

I didn't touch `bongo-insert-pls-playlist-contents', because that one
is a bit complex, but here are versions of `bongo-locate' and
`bongo-insert-m3u-playlist-contents' using a new command
`bongo-insert-buffer'. I haven't tested this much at all, though.


(defun bongo-insert-buffer (buffer)
  "In a Bongo buffer, insert the contents of BUFFER.
The buffer should contain a list of file names or URIs."
  (interactive "b")
  (with-bongo-buffer
    (let ((beginning (point))
          (bongo-buffer (current-buffer)))
      (with-current-buffer buffer
        (save-excursion
          (goto-char (point-min))
          (while (not (eobp))
            (let ((string (buffer-substring (point) (point-at-eol))))
              (with-current-buffer bongo-buffer
                (if (bongo-uri-p string)
                    (bongo-insert-uri string)
                  (bongo-insert-file (expand-file-name string)))))
            (forward-line 1))))
      (bongo-maybe-join-inserted-tracks beginning (point)))))

; Maybe let `bongo-insert-buffer' handle other Bongo buffers as well.

(defun bongo-insert-m3u-playlist-contents (file-name)
  "Insert the contents of M3U playlist FILE-NAME."
  (interactive "fInsert contents of M3U playlist file: ")
  (with-temp-buffer
    (let ((coding-system-for-read
           (if (string-equal (file-name-extension file-name) "m3u8")
               'utf-8
             coding-system-for-read)))
      (let* ((absolute-file-name (car (insert-file-contents file-name)))
               (default-directory (file-name-directory absolute-file-name)))
        (goto-char (point-min))
        (flush-lines "^#")
        (bongo-insert-buffer (current-buffer))))))

(defun bongo-locate (args)
  (interactive "sSubstrings: ")
  (with-temp-buffer
    (shell-command (concat bongo-locate-command " " args) t)
    (let ((buffer (current-buffer))
          (inhibit-read-only t))
      (with-current-buffer (get-buffer-create "*Bongo Locate*")
        (unless (bongo-buffer-p)
          (bongo-library-mode))
        (erase-buffer)
        (bongo-insert-buffer buffer)
        (switch-to-buffer (current-buffer))))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]