annotate lisp/mpc.el @ 108033:1545dcb1c3b7

Fix Bug#5840. * icomplete.el (icomplete-completions): Use `non-essential'. * net/tramp.el (tramp-connectable-p): New defun. (tramp-handle-expand-file-name) (tramp-completion-handle-file-name-all-completions) (tramp-completion-handle-file-name-completion): Use it.
author Michael Albinus <albinus@detlef>
date Wed, 21 Apr 2010 21:48:42 +0200
parents d59e6301c2cd
children 417b1e4d63cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 ;;; mpc.el --- A client for the Music Player Daemon -*- coding: utf-8 -*-
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106697
diff changeset
3 ;; Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
4
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Keywords: multimedia
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
9
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13 ;; (at your option) any later version.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
14
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
18 ;; GNU General Public License for more details.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
19
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
23 ;;; Commentary:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
24
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
25 ;; This is an Emacs front end to the Music Player Daemon.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
26
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27 ;; It mostly provides a browser inspired from Rhythmbox for your music
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
28 ;; collection and also allows you to play the music you select. The basic
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 ;; interface is somewhat unusual in that it does not focus on the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30 ;; playlist as much as on the browser.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31 ;; I play albums rather than songs and thus don't have much need for
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 ;; playlists, and it shows. Playlist support exists, but is still limited.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 ;; Bugs:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36 ;; - when reaching end/start of song while ffwd/rewind, it may get wedged,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37 ;; signal an error, ... or when mpc-next/prev is called while ffwd/rewind.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 ;; - MPD errors are not reported to the user.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40 ;; Todo:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
42 ;; - add bindings/buttons/menuentries for the various commands.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
43 ;; - mpc-undo
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
44 ;; - visual feedback for drag'n'drop
106365
06698b91c779 * mpc.el (mpc-intersection, mpc-host, mpc-songs-playlist)
Juanma Barranquero <lekktu@gmail.com>
parents: 106354
diff changeset
45 ;; - display/set `repeat' and `random' state (and maybe also `crossfade').
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
46 ;; - allow multiple *mpc* sessions in the same Emacs to control different mpds.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
47 ;; - look for .folder.png (freedesktop) or folder.jpg (XP) as well.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
48 ;; - fetch album covers and lyrics from the web?
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49 ;; - improve MPC-Status: better volume control, add a way to show/hide the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
50 ;; rest, plus add the buttons currently in the toolbar.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 ;; - improve mpc-songs-mode's header-line column-headings so they can be
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52 ;; dragged to resize.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 ;; - allow selecting several entries by drag-mouse.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 ;; - poll less often
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 ;; - use the `idle' command
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56 ;; - do the time-ticking locally (and sync every once in a while)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57 ;; - look at the end of play time to make sure we notice the end
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58 ;; as soon as possible
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 ;; - better volume widget.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 ;; - add synthesized tags.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 ;; e.g. pseudo-artist = artist + composer + performer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
62 ;; e.g. pseudo-performer = performer or artist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63 ;; e.g. rewrite artist "Foo bar & baz" to "Foo bar".
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
64 ;; e.g. filename regexp -> compilation flag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
65 ;; - window/buffer management.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66 ;; - menubar, tooltips, ...
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 ;; - add mpc-describe-song, mpc-describe-album, ...
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68 ;; - add import/export commands (especially export to an MP3 player).
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 ;; - add a real notion of album (as opposed to just album-name):
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 ;; if all songs with same album-name have same artist -> it's an album
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71 ;; else it's either several albums or a compilation album (or both),
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 ;; in which case we could use heuristics or user provided info:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 ;; - if the user followed the 1-album = 1-dir idea, then we can group songs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 ;; by their directory to create albums.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75 ;; - if a `compilation' flag is available, and if <=1 of the songs have it
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 ;; set, then we can group songs by their artist to create albums.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 ;; - if two songs have the same track-nb and disk-nb, they're not in the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78 ;; same album. So from the set of songs with identical album names, we
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79 ;; can get a lower bound on the number of albums involved, and then see
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 ;; which of those may be non-compilations, etc...
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81 ;; - use a special directory name for compilations.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 ;; - ask the web ;-)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 ;;; Code:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 ;; Prefixes used in this code:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
87 ;; mpc-proc : management of connection (in/out formatting, ...)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
88 ;; mpc-status : auto-updated status info
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89 ;; mpc-volume : stuff handling the volume widget
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
90 ;; mpc-cmd : mpdlib abstraction
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 ;; UI-commands : mpc-
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 ;; internal : mpc--
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 (eval-when-compile (require 'cl))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97 (defgroup mpc ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 "A Client for the Music Player Daemon."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
99 :prefix "mpc-"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
100 :group 'multimedia
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 :group 'applications)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
103 (defcustom mpc-browser-tags '(Genre Artist|Composer|Performer
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
104 Album|Playlist)
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
105 "Tags for which a browser buffer should be created by default."
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
106 ;; FIXME: provide a list of tags, for completion.
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
107 :type '(repeat symbol))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
108
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 ;;; Misc utils ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
110
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
111 (defun mpc-assq-all (key alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
112 (let ((res ()) val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
113 (dolist (elem alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
114 (if (and (eq (car elem) key)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
115 (not (member (setq val (cdr elem)) res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116 (push val res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117 (nreverse res)))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
118
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 (defun mpc-union (&rest lists)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
120 (let ((res (nreverse (pop lists))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121 (dolist (list lists)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 (let ((seen res)) ;Don't remove duplicates within each list.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
123 (dolist (elem list)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
124 (unless (member elem seen) (push elem res)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
125 (nreverse res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
126
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 (defun mpc-intersection (l1 l2 &optional selectfun)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
128 "Return L1 after removing all elements not found in L2.
106365
06698b91c779 * mpc.el (mpc-intersection, mpc-host, mpc-songs-playlist)
Juanma Barranquero <lekktu@gmail.com>
parents: 106354
diff changeset
129 If SELECTFUN is non-nil, elements aren't compared directly, but instead
06698b91c779 * mpc.el (mpc-intersection, mpc-host, mpc-songs-playlist)
Juanma Barranquero <lekktu@gmail.com>
parents: 106354
diff changeset
130 they are passed through SELECTFUN before comparison."
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
131 (let ((res ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
132 (if selectfun (setq l2 (mapcar selectfun l2)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
133 (dolist (elem l1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
134 (when (member (if selectfun (funcall selectfun elem) elem) l2)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
135 (push elem res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
136 (nreverse res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
137
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
138 (defun mpc-event-set-point (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
139 (condition-case nil (posn-set-point (event-end event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
140 (error (condition-case nil (mouse-set-point event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
141 (error nil)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
142
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
143 (defun mpc-compare-strings (str1 str2 &optional ignore-case)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
144 "Compare strings STR1 and STR2.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
145 Contrary to `compare-strings', this tries to get numbers sorted
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
146 numerically rather than lexicographically."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
147 (let ((res (compare-strings str1 nil nil str2 nil nil ignore-case)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
148 (if (not (integerp res)) res
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
149 (let ((index (1- (abs res))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
150 (if (or (>= index (length str1)) (>= index (length str2)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
151 res
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
152 (let ((digit1 (memq (aref str1 index)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
153 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
154 (digit2 (memq (aref str2 index)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
155 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
156 (if digit1
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
157 (if digit2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
158 (let ((num1 (progn (string-match "[0-9]+" str1 index)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
159 (match-string 0 str1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
160 (num2 (progn (string-match "[0-9]+" str2 index)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
161 (match-string 0 str2))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
162 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163 ;; Here we presume that leading zeroes are only used
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164 ;; for same-length numbers. So we'll incorrectly
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 ;; consider that "000" comes after "01", but I don't
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 ;; think it matters.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167 ((< (length num1) (length num2)) (- (abs res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
168 ((> (length num1) (length num2)) (abs res))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 ((< (string-to-number num1) (string-to-number num2))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
170 (- (abs res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 (t (abs res))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 ;; "1a" comes before "10", but "0" comes before "a".
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 (if (and (not (zerop index))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 (memq (aref str1 (1- index))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
176 (abs res)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 (- (abs res))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 (if digit2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 ;; "1a" comes before "10", but "0" comes before "a".
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
180 (if (and (not (zerop index))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
181 (memq (aref str1 (1- index))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
183 (- (abs res))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
184 (abs res))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
185 res))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
186
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187 (defun mpc-string-prefix-p (str1 str2)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
188 ;; FIXME: copied from pcvs-util.el.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
189 "Tell whether STR1 is a prefix of STR2."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
190 (eq t (compare-strings str2 nil (length str1) str1 nil nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
191
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
192 ;; This can speed up mpc--song-search significantly. The table may grow
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
193 ;; very large, tho. It's only bounded by the fact that it gets flushed
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
194 ;; whenever the connection is established; which seems to work OK thanks
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
195 ;; to the fact that MPD tends to disconnect fairly often, although our
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
196 ;; constant polling often prevents disconnection.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 (defvar mpc--find-memoize (make-hash-table :test 'equal)) ;; :weakness t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
198 (defvar mpc-tag nil) (make-variable-buffer-local 'mpc-tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
199
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
200 ;;; Support for the actual connection and MPD command execution ;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
202 (defcustom mpc-host
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
203 (concat (or (getenv "MPD_HOST") "localhost")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
204 (if (getenv "MPD_PORT") (concat ":" (getenv "MPD_PORT"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
205 "Host (and port) where the Music Player Daemon is running.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
206 The format is \"HOST\" or \"HOST:PORT\" where PORT defaults to 6600
106365
06698b91c779 * mpc.el (mpc-intersection, mpc-host, mpc-songs-playlist)
Juanma Barranquero <lekktu@gmail.com>
parents: 106354
diff changeset
207 and HOST defaults to localhost."
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
208 :type 'string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
209
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
210 (defvar mpc-proc nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
211
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
212 (defconst mpc--proc-end-re "^\\(?:OK\\(?: MPD .*\\)?\\|ACK \\(.*\\)\\)\n")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
213
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
214 (put 'mpc-proc-error 'error-conditions '(mpc-proc-error error))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
215 (put 'mpc-proc-error 'error-message "MPD error")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
216
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
217 (defun mpc--debug (format &rest args)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
218 (if (get-buffer "*MPC-debug*")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
219 (with-current-buffer "*MPC-debug*"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
220 (goto-char (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
221 (insert-before-markers ;So it scrolls.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
222 (replace-regexp-in-string "\n" "\n "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
223 (apply 'format format args))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
224 "\n"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
225
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
226 (defun mpc--proc-filter (proc string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
227 (mpc--debug "Receive \"%s\"" string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
228 (with-current-buffer (process-buffer proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
229 (if (process-get proc 'ready)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
230 (if nil ;; (string-match "\\`\\(OK\n\\)+\\'" string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
231 ;; I haven't figured out yet why I get those extraneous OKs,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
232 ;; so I'll just ignore them for now.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
233 nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
234 (delete-process proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
235 (set-process-buffer proc nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
236 (pop-to-buffer (clone-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237 (error "MPD output while idle!?"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
238 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
239 (let ((start (or (marker-position (process-mark proc)) (point-min))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
240 (goto-char start)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
241 (insert string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
242 (move-marker (process-mark proc) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
243 (beginning-of-line)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
244 (when (and (< start (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
245 (re-search-backward mpc--proc-end-re start t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
246 (process-put proc 'ready t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
247 (unless (eq (match-end 0) (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
248 (error "Unexpected trailing text"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
249 (let ((error (match-string 1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
250 (delete-region (point) (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
251 (let ((callback (process-get proc 'callback)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
252 (process-put proc 'callback nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
253 (if error (signal 'mpc-proc-error error))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
254 (funcall callback)))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
255
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
256 (defun mpc--proc-connect (host)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
257 (mpc--debug "Connecting to %s..." host)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
258 (with-current-buffer (get-buffer-create (format " *mpc-%s*" host))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
259 ;; (pop-to-buffer (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
260 (let (proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
261 (while (and (setq proc (get-buffer-process (current-buffer)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
262 (progn ;; (debug)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
263 (delete-process proc)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
264 (erase-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
265 (let ((port 6600))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
266 (when (string-match ":[^.]+\\'" host)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
267 (setq port (substring host (1+ (match-beginning 0))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
268 (setq host (substring host 0 (match-beginning 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
269 (unless (string-match "[^[:digit:]]" port)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
270 (setq port (string-to-number port))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
271 (let* ((coding-system-for-read 'utf-8-unix)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
272 (coding-system-for-write 'utf-8-unix)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
273 (proc (open-network-stream "MPC" (current-buffer) host port)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
274 (when (processp mpc-proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
275 ;; Inherit the properties of the previous connection.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
276 (let ((plist (process-plist mpc-proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
277 (while plist (process-put proc (pop plist) (pop plist)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
278 (mpc-proc-buffer proc 'mpd-commands (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
279 (process-put proc 'callback 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
280 (process-put proc 'ready nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
281 (clrhash mpc--find-memoize)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
282 (set-process-filter proc 'mpc--proc-filter)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
283 (set-process-sentinel proc 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
284 (set-process-query-on-exit-flag proc nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
285 ;; This may be called within a process filter ;-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
286 (with-local-quit (mpc-proc-sync proc))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
287 proc))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
289 (defun mpc--proc-quote-string (s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
290 (if (numberp s) (number-to-string s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
291 (setq s (replace-regexp-in-string "[\"\\]" "\\\\\\&" s))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
292 (if (string-match " " s) (concat "\"" s "\"") s)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
293
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
294 (defconst mpc--proc-alist-to-alists-starters '(file directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
295
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
296 (defun mpc--proc-alist-to-alists (alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
297 (assert (or (null alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
298 (memq (caar alist) mpc--proc-alist-to-alists-starters)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
299 (let ((starter (caar alist))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300 (alists ())
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
301 tmp)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
302 (dolist (pair alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
303 (when (eq (car pair) starter)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
304 (if tmp (push (nreverse tmp) alists))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
305 (setq tmp ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
306 (push pair tmp))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
307 (if tmp (push (nreverse tmp) alists))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
308 (nreverse alists)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
309
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 (defun mpc-proc ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
311 (or (and mpc-proc
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
312 (buffer-live-p (process-buffer mpc-proc))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
313 (not (memq (process-status mpc-proc) '(closed)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
314 mpc-proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
315 (setq mpc-proc (mpc--proc-connect mpc-host))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
316
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
317 (defun mpc-proc-sync (&optional proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
318 "Wait for MPC process until it is idle again.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
319 Return the buffer in which the process is/was running."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
320 (unless proc (setq proc (mpc-proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321 (unwind-protect
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
322 (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
323 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
324 (while (and (not (process-get proc 'ready))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
325 (accept-process-output proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
326 (if (process-get proc 'ready) (process-buffer proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
327 ;; (delete-process proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328 (error "No response from MPD")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
329 (error (message "MPC: %s" err) (signal (car err) (cdr err))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
330 (unless (process-get proc 'ready)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
331 ;; (debug)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
332 (message "Killing hung process")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333 (delete-process proc))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
334
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335 (defun mpc-proc-cmd (cmd &optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
336 "Send command CMD to the MPD server.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
337 If CALLBACK is nil, wait for the command to finish before returning,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
338 otherwise return immediately and call CALLBACK with no argument
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
339 when the command terminates.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
340 CMD can be a string which is passed as-is to MPD or a list of strings
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
341 which will be concatenated with proper quoting before passing them to MPD."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342 (let ((proc (mpc-proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
343 (if (and callback (not (process-get proc 'ready)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
344 (lexical-let ((old (process-get proc 'callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
345 (callback callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
346 (cmd cmd))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
347 (process-put proc 'callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
348 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
349 (funcall old)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
350 (mpc-proc-cmd cmd callback))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
351 ;; Wait for any pending async command to terminate.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
352 (mpc-proc-sync proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
353 (process-put proc 'ready nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
354 (with-current-buffer (process-buffer proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
355 (erase-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
356 (mpc--debug "Send \"%s\"" cmd)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
357 (process-send-string
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
358 proc (concat (if (stringp cmd) cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
359 (mapconcat 'mpc--proc-quote-string cmd " "))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
360 "\n")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
361 (if callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
362 (lexical-let ((buf (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
363 (callback callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
364 (process-put proc 'callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
365 callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
366 ;; (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
367 ;; (funcall callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
368 ;; (prog1 (current-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
369 ;; (set-buffer buf))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
370 ))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
371 ;; If `callback' is nil, we're executing synchronously.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
372 (process-put proc 'callback 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
373 ;; This returns the process's buffer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
374 (mpc-proc-sync proc)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
375
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
376 ;; This function doesn't exist in Emacs-21.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
377 ;; (put 'mpc-proc-cmd-list 'byte-optimizer 'byte-optimize-pure-func)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
378 (defun mpc-proc-cmd-list (cmds)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
379 (concat "command_list_begin\n"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
380 (mapconcat (lambda (cmd)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
381 (if (stringp cmd) cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
382 (mapconcat 'mpc--proc-quote-string cmd " ")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
383 cmds
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
384 "\n")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
385 "\ncommand_list_end"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
386
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
387 (defun mpc-proc-cmd-list-ok ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
388 ;; To implement this, we'll need to tweak the process filter since we'd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
389 ;; then sometimes get "trailing" text after "OK\n".
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
390 (error "Not implemented yet"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
391
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
392 (defun mpc-proc-buf-to-alist (&optional buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393 (with-current-buffer (or buf (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
394 (let ((res ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
395 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
396 (while (re-search-forward "^\\([^:]+\\): \\(.*\\)\n" nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
397 (push (cons (intern (match-string 1)) (match-string 2)) res))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
398 (nreverse res))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
399
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
400 (defun mpc-proc-buf-to-alists (buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
401 (mpc--proc-alist-to-alists (mpc-proc-buf-to-alist buf)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
402
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
403 (defun mpc-proc-cmd-to-alist (cmd &optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404 (if callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
405 (lexical-let ((buf (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
406 (callback callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
407 (mpc-proc-cmd cmd (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
408 (funcall callback (prog1 (mpc-proc-buf-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
409 (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
410 (set-buffer buf))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
411 ;; (lexical-let ((res nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
412 ;; (mpc-proc-cmd-to-alist cmd (lambda (alist) (setq res alist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
413 ;; (mpc-proc-sync)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
414 ;; res)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
415 (mpc-proc-buf-to-alist (mpc-proc-cmd cmd))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
416
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
417 (defun mpc-proc-tag-string-to-sym (tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
418 (intern (capitalize tag)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
419
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
420 (defun mpc-proc-buffer (proc use &optional buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
421 (let* ((bufs (process-get proc 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
422 (buf (cdr (assoc use bufs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
423 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
424 ((and buffer (buffer-live-p buf) (not (eq buffer buf)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
425 (error "Duplicate MPC buffer for %s" use))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
426 (buffer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
427 (if buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
428 (setcdr (assoc use bufs) buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
429 (process-put proc 'buffers (cons (cons use buffer) bufs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
430 (t buf))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
431
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
432 ;;; Support for regularly updated current status information ;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
433
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
434 ;; Exported elements:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
435 ;; `mpc-status' holds the uptodate data.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
436 ;; `mpc-status-callbacks' holds the registered callback functions.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
437 ;; `mpc-status-refresh' forces a refresh of the data.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
438 ;; `mpc-status-stop' stops the automatic updating.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
439
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440 (defvar mpc-status nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441 (defvar mpc-status-callbacks
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
442 '((state . mpc--status-timers-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
443 ;; (song . mpc--queue-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
444 ;; (state . mpc--queue-refresh) ;To detect the end of the last song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
445 (state . mpc--faster-toggle-refresh) ;Only ffwd/rewind while play/pause.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
446 (volume . mpc-volume-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
447 (file . mpc-songpointer-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
448 ;; The song pointer may need updating even if the file doesn't change,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
449 ;; if the same song appears multiple times in a row.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
450 (song . mpc-songpointer-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
451 (updating_db . mpc-updated-db)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
452 (updating_db . mpc--status-timers-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
453 (t . mpc-current-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
454 "Alist associating properties to the functions that care about them.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
455 Each entry has the form (PROP . FUN) where PROP can be t to mean
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
456 to call FUN for any change whatsoever.")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
457
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
458 (defun mpc--status-callback ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
459 (let ((old-status mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
460 ;; Update the alist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
461 (setq mpc-status (mpc-proc-buf-to-alist))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
462 (assert mpc-status)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
463 (unless (equal old-status mpc-status)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
464 ;; Run the relevant refresher functions.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
465 (dolist (pair mpc-status-callbacks)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
466 (when (or (eq t (car pair))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
467 (not (equal (cdr (assq (car pair) old-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
468 (cdr (assq (car pair) mpc-status)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
469 (funcall (cdr pair)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
470
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
471 (defvar mpc--status-timer nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
472 (defun mpc--status-timer-start ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
473 (add-hook 'pre-command-hook 'mpc--status-timer-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
474 (unless mpc--status-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
475 (setq mpc--status-timer (run-with-timer 1 1 'mpc--status-timer-run))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
476 (defun mpc--status-timer-stop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
477 (when mpc--status-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
478 (cancel-timer mpc--status-timer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
479 (setq mpc--status-timer nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
480 (defun mpc--status-timer-run ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
481 (when (process-get (mpc-proc) 'ready)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
482 (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
483 (with-local-quit (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
484 (error (message "MPC: %s" err)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
485
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
486 (defvar mpc--status-idle-timer nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
487 (defun mpc--status-idle-timer-start ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
488 (when mpc--status-idle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
489 ;; Turn it off even if we'll start it again, in case it changes the delay.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
490 (cancel-timer mpc--status-idle-timer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
491 (setq mpc--status-idle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
492 (run-with-idle-timer 1 t 'mpc--status-idle-timer-run))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
493 ;; Typically, the idle timer is started from the mpc--status-callback,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
494 ;; which is run asynchronously while we're already idle (we typically
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
495 ;; just started idling), so the timer itself will only be run the next
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
496 ;; time we idle :-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
497 ;; To work around that, we immediately start the repeat timer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
498 (mpc--status-timer-start))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
499 (defun mpc--status-idle-timer-stop (&optional really)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
500 (when mpc--status-idle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
501 ;; Turn it off even if we'll start it again, in case it changes the delay.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
502 (cancel-timer mpc--status-idle-timer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
503 (setq mpc--status-idle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
504 (unless really
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
505 ;; We don't completely stop the timer, so that if some other MPD
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
506 ;; client starts playback, we may get a chance to notice it.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
507 (run-with-idle-timer 10 t 'mpc--status-idle-timer-run))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
508 (defun mpc--status-idle-timer-run ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
509 (when (process-get (mpc-proc) 'ready)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
510 (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
511 (with-local-quit (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
512 (error (message "MPC: %s" err))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
513 (mpc--status-timer-start))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
514
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
515 (defun mpc--status-timers-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
516 "Start/stop the timers according to whether a song is playing."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
517 (if (or (member (cdr (assq 'state mpc-status)) '("play"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
518 (cdr (assq 'updating_db mpc-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
519 (mpc--status-idle-timer-start)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
520 (mpc--status-idle-timer-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
521 (mpc--status-timer-stop)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
522
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
523 (defun mpc-status-refresh (&optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
524 "Refresh `mpc-status'."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
525 (lexical-let ((cb callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
526 (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
527 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
528 (mpc--status-callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
529 (if cb (funcall cb))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
530
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
531 (defun mpc-status-stop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
532 "Stop the autorefresh of `mpc-status'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
533 This is normally used only when quitting MPC.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
534 Any call to `mpc-status-refresh' may cause it to be restarted."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
535 (setq mpc-status nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
536 (mpc--status-idle-timer-stop 'really)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
537 (mpc--status-timer-stop))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
538
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
539 ;;; A thin layer above the raw protocol commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
540
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
541 ;; (defvar mpc-queue nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
542 ;; (defvar mpc-queue-back nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
543
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
544 ;; (defun mpc--queue-head ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
545 ;; (if (stringp (car mpc-queue)) (car mpc-queue) (cadar mpc-queue)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
546 ;; (defun mpc--queue-pop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
547 ;; (when mpc-queue ;Can be nil if out of sync.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
548 ;; (let ((song (car mpc-queue)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
549 ;; (assert song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
550 ;; (push (if (and (consp song) (cddr song))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551 ;; ;; The queue's first element is itself a list of
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
552 ;; ;; songs, where the first element isn't itself a song
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
553 ;; ;; but a description of the list.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
554 ;; (prog1 (cadr song) (setcdr song (cddr song)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555 ;; (prog1 (if (consp song) (cadr song) song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
556 ;; (setq mpc-queue (cdr mpc-queue))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
557 ;; mpc-queue-back)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
558 ;; (assert (stringp (car mpc-queue-back))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
559
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
560 ;; (defun mpc--queue-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
561 ;; ;; Maintain the queue.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
562 ;; (mpc--debug "mpc--queue-refresh")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
563 ;; (let ((pos (cdr (or (assq 'Pos mpc-status) (assq 'song mpc-status)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
564 ;; (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
565 ;; ((null pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
566 ;; (mpc-cmd-clear 'ignore))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
567 ;; ((or (not (member pos '("0" nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
568 ;; ;; There's only one song in the playlist and we've stopped.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
569 ;; ;; Maybe it's because of some external client that set the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
570 ;; ;; playlist like that and/or manually stopped the playback, but
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
571 ;; ;; it's more likely that we've simply reached the end of
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
572 ;; ;; the song. So remove it.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
573 ;; (and (equal (assq 'state mpc-status) "stop")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
574 ;; (equal (assq 'playlistlength mpc-status) "1")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
575 ;; (setq pos "1")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
576 ;; ;; We're not playing the first song in the queue/playlist any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
577 ;; ;; more, so update the queue.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
578 ;; (dotimes (i (string-to-number pos)) (mpc--queue-pop))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
579 ;; (mpc-proc-cmd (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
580 ;; (make-list (string-to-number pos) "delete 0"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
581 ;; 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
582 ;; (if (not (equal (cdr (assq 'file mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
583 ;; (mpc--queue-head)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
584 ;; (message "MPC's queue is out of sync"))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
585
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
586 (defvar mpc--find-memoize-union-tags nil)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
587
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
588 (defun mpc-cmd-flush (tag value)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
589 (puthash (cons tag value) nil mpc--find-memoize)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
590 (dolist (uniontag mpc--find-memoize-union-tags)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
591 (if (member (symbol-name tag) (split-string (symbol-name uniontag) "|"))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
592 (puthash (cons uniontag value) nil mpc--find-memoize))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
593
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
594
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
595 (defun mpc-cmd-special-tag-p (tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
596 (or (memq tag '(Playlist Search Directory))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
597 (string-match "|" (symbol-name tag))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
598
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
599 (defun mpc-cmd-find (tag value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
600 "Return a list of all songs whose tag TAG has value VALUE.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
601 The songs are returned as alists."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
602 (or (gethash (cons tag value) mpc--find-memoize)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
603 (puthash (cons tag value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
604 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
605 ((eq tag 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
606 ;; Special case for pseudo-tag playlist.
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
607 (let ((l (condition-case err
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
608 (mpc-proc-buf-to-alists
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
609 (mpc-proc-cmd (list "listplaylistinfo" value)))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
610 (mpc-proc-error
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
611 ;; "[50@0] {listplaylistinfo} No such playlist"
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
612 nil)))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
613 (i 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
614 (mapcar (lambda (s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
615 (prog1 (cons (cons 'Pos (number-to-string i)) s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
616 (incf i)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
617 l)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
618 ((eq tag 'Search)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
619 (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
620 (mpc-proc-cmd (list "search" "any" value))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
621 ((eq tag 'Directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
622 (let ((pairs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
623 (mpc-proc-buf-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
624 (mpc-proc-cmd (list "listallinfo" value)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
625 (mpc--proc-alist-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
626 ;; Strip away the `directory' entries.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
627 (delq nil (mapcar (lambda (pair)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
628 (if (eq (car pair) 'directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
629 nil pair))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
630 pairs)))))
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
631 ((string-match "|" (symbol-name tag))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
632 (add-to-list 'mpc--find-memoize-union-tags tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
633 (let ((tag1 (intern (substring (symbol-name tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
634 0 (match-beginning 0))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
635 (tag2 (intern (substring (symbol-name tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
636 (match-end 0)))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
637 (mpc-union (mpc-cmd-find tag1 value)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
638 (mpc-cmd-find tag2 value))))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
639 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
640 (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
641 (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
642 (mpc-proc-cmd (list "find" (symbol-name tag) value)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
643 (mpc-proc-error
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
644 ;; If `tag' is not one of the expected tags, MPD burps
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
645 ;; about not having the relevant table. FIXME: check
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
646 ;; the kind of error.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
647 (error "Unknown tag %s" tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
648 (let ((res ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
649 (setq value (cons tag value))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
650 (dolist (song (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
651 (mpc-proc-cmd "listallinfo")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
652 (if (member value song) (push song res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
653 res)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
654 mpc--find-memoize)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
655
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
656 (defun mpc-cmd-list (tag &optional other-tag value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
657 ;; FIXME: we could also provide a `mpc-cmd-list' alternative which
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
658 ;; doesn't take an "other-tag value" constraint but a "song-list" instead.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
659 ;; That might be more efficient in some cases.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
660 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
661 ((eq tag 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
662 (let ((pls (mpc-assq-all 'playlist (mpc-proc-cmd-to-alist "lsinfo"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
663 (when other-tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
664 (dolist (pl (prog1 pls (setq pls nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
665 (let ((plsongs (mpc-cmd-find 'Playlist pl)))
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
666 (if (not (mpc-cmd-special-tag-p other-tag))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
667 (when (member (cons other-tag value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
668 (apply 'append plsongs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
669 (push pl pls))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
670 ;; Problem N°2: we compute the intersection whereas all
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
671 ;; we care about is whether it's empty. So we could
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
672 ;; speed this up significantly.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
673 ;; We only compare file names, because the full song-entries
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
674 ;; are slightly different (the ones in plsongs include
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
675 ;; position and id info specific to the playlist), and it's
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
676 ;; good enough because this is only used with "search", which
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
677 ;; doesn't pay attention to playlists and URLs anyway.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
678 (let* ((osongs (mpc-cmd-find other-tag value))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
679 (ofiles (mpc-assq-all 'file (apply 'append osongs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
680 (plfiles (mpc-assq-all 'file (apply 'append plsongs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
681 (when (mpc-intersection plfiles ofiles)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
682 (push pl pls)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
683 pls))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
684
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
685 ((eq tag 'Directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
686 (if (null other-tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
687 (apply 'nconc
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
688 (mpc-assq-all 'directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
689 (mpc-proc-buf-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
690 (mpc-proc-cmd "lsinfo")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
691 (mapcar (lambda (dir)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
692 (let ((shortdir
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
693 (if (get-text-property 0 'display dir)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
694 (concat " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
695 (get-text-property 0 'display dir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
696 " ↪ "))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
697 (subdirs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
698 (mpc-assq-all 'directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
699 (mpc-proc-buf-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
700 (mpc-proc-cmd (list "lsinfo" dir))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
701 (dolist (subdir subdirs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
702 (put-text-property 0 (1+ (length dir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
703 'display shortdir
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
704 subdir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
705 subdirs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
706 (process-get (mpc-proc) 'Directory)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
707 ;; If there's an other-tag, then just extract the dir info from the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
708 ;; list of other-tag's songs.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
709 (let* ((other-songs (mpc-cmd-find other-tag value))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
710 (files (mpc-assq-all 'file (apply 'append other-songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
711 (dirs '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
712 (dolist (file files)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
713 (let ((dir (file-name-directory file)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
714 (if (and dir (setq dir (directory-file-name dir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
715 (not (equal dir (car dirs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
716 (push dir dirs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
717 ;; Dirs might have duplicates still.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
718 (setq dirs (delete-dups dirs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
719 (let ((newdirs dirs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
720 (while newdirs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
721 (let ((dir (file-name-directory (pop newdirs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
722 (when (and dir (setq dir (directory-file-name dir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
723 (not (member dir dirs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
724 (push dir newdirs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
725 (push dir dirs)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
726 dirs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
727
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
728 ;; The UI should not provide access to such a thing anyway currently.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
729 ;; But I could imagine adding in the future a browser for the "search"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
730 ;; tag, which would provide things like previous searches. Not sure how
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
731 ;; useful that would be tho.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 ((eq tag 'Search) (error "Not supported"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
733
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
734 ((string-match "|" (symbol-name tag))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
735 (let ((tag1 (intern (substring (symbol-name tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
736 0 (match-beginning 0))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
737 (tag2 (intern (substring (symbol-name tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
738 (match-end 0)))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
739 (mpc-union (mpc-cmd-list tag1 other-tag value)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
740 (mpc-cmd-list tag2 other-tag value))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
741
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
742 ((null other-tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
743 (condition-case nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
744 (mapcar 'cdr (mpc-proc-cmd-to-alist (list "list" (symbol-name tag))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
745 (mpc-proc-error
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
746 ;; If `tag' is not one of the expected tags, MPD burps about not
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
747 ;; having the relevant table.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
748 ;; FIXME: check the kind of error.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
749 (error "MPD does not know this tag %s" tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
750 (mpc-assq-all tag (mpc-proc-cmd-to-alist "listallinfo")))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
751 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
752 (condition-case nil
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
753 (if (mpc-cmd-special-tag-p other-tag)
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
754 (signal 'mpc-proc-error "Not implemented")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
755 (mapcar 'cdr
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
756 (mpc-proc-cmd-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 (list "list" (symbol-name tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
758 (symbol-name other-tag) value))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
759 (mpc-proc-error
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
760 ;; DAMN!! the 3-arg form of `list' is new in 0.12 !!
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
761 ;; FIXME: check the kind of error.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
762 (let ((other-songs (mpc-cmd-find other-tag value)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
763 (mpc-assq-all tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
764 ;; Don't use `nconc' now that mpc-cmd-find may
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
765 ;; return a memoized result.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
766 (apply 'append other-songs))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
767
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
768 (defun mpc-cmd-stop (&optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
769 (mpc-proc-cmd "stop" callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
770
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
771 (defun mpc-cmd-clear (&optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
772 (mpc-proc-cmd "clear" callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
773 ;; (setq mpc-queue-back nil mpc-queue nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
774 )
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
775
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
776 (defun mpc-cmd-pause (&optional arg callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
777 "Pause or resume playback of the queue of songs."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
778 (lexical-let ((cb callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
779 (mpc-proc-cmd (list "pause" arg)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
780 (lambda () (mpc-status-refresh) (if cb (funcall cb))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
781 (unless callback (mpc-proc-sync))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
782
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
783 (defun mpc-cmd-status ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
784 (mpc-proc-cmd-to-alist "status"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
785
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
786 (defun mpc-cmd-play ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
787 (mpc-proc-cmd "play")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
788 (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
789
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
790 (defun mpc-cmd-add (files &optional playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
791 "Add the songs FILES to PLAYLIST.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
792 If PLAYLIST is t or nil or missing, use the main playlist."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
793 (mpc-proc-cmd (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
794 (mapcar (lambda (file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
795 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
796 (list "playlistadd" playlist file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
797 (list "add" file)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
798 files)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
799 (if (stringp playlist)
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
800 (mpc-cmd-flush 'Playlist playlist)))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
801
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
802 (defun mpc-cmd-delete (song-poss &optional playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
803 "Delete the songs at positions SONG-POSS from PLAYLIST.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
804 If PLAYLIST is t or nil or missing, use the main playlist."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
805 (mpc-proc-cmd (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
806 (mapcar (lambda (song-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
807 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
808 (list "playlistdelete" playlist song-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
809 (list "delete" song-pos)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
810 ;; Sort them from last to first, so the renumbering
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
811 ;; caused by the earlier deletions don't affect
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
812 ;; later ones.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
813 (sort song-poss '>))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
814 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
815 (puthash (cons 'Playlist playlist) nil mpc--find-memoize)))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
816
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
817
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
818 (defun mpc-cmd-move (song-poss dest-pos &optional playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
819 (let ((i 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
820 (mpc-proc-cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
821 (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
822 (mapcar (lambda (song-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
823 (if (>= song-pos dest-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
824 ;; positions past dest-pos have been
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
825 ;; shifted by i.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
826 (setq song-pos (+ song-pos i)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
827 (prog1 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
828 (list "playlistmove" playlist song-pos dest-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
829 (list "move" song-pos dest-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
830 (if (< song-pos dest-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
831 ;; This move has shifted dest-pos by 1.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
832 (decf dest-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
833 (incf i)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
834 ;; Sort them from last to first, so the renumbering
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
835 ;; caused by the earlier deletions affect
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
836 ;; later ones a bit less.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
837 (sort song-poss '>))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
838 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
839 (puthash (cons 'Playlist playlist) nil mpc--find-memoize))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
840
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
841 (defun mpc-cmd-update (&optional arg callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
842 (lexical-let ((cb callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
843 (mpc-proc-cmd (if arg (list "update" arg) "update")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
844 (lambda () (mpc-status-refresh) (if cb (funcall cb))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
845 (unless callback (mpc-proc-sync))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
846
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
847 (defun mpc-cmd-tagtypes ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
848 (mapcar 'cdr (mpc-proc-cmd-to-alist "tagtypes")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
849
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
850 ;; This was never integrated into MPD.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
851 ;; (defun mpc-cmd-download (file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
852 ;; (with-current-buffer (generate-new-buffer " *mpc download*")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
853 ;; (set-buffer-multibyte nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
854 ;; (let* ((proc (mpc-proc))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
855 ;; (stdbuf (process-buffer proc))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
856 ;; (markpos (marker-position (process-mark proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
857 ;; (stdcoding (process-coding-system proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
858 ;; (unwind-protect
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
859 ;; (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
860 ;; (set-process-buffer proc (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
861 ;; (set-process-coding-system proc 'binary (cdr stdcoding))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
862 ;; (set-marker (process-mark proc) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
863 ;; (mpc-proc-cmd (list "download" file)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
864 ;; (set-process-buffer proc stdbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
865 ;; (set-marker (process-mark proc) markpos stdbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
866 ;; (set-process-coding-system proc (car stdcoding) (cdr stdcoding)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
867 ;; ;; The command has completed, let's decode.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
868 ;; (goto-char (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
869 ;; (delete-char -1) ;Delete final newline.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
870 ;; (while (re-search-backward "^>" nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
871 ;; (delete-char 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
872 ;; (current-buffer))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
873
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
874 ;;; Misc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
875
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
876 (defcustom mpc-mpd-music-directory nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
877 "Location of MPD's music directory."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
878 :type '(choice (const nil) directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
879
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
880 (defcustom mpc-data-directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
881 (if (and (not (file-directory-p "~/.mpc"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
882 (file-directory-p "~/.emacs.d"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
883 "~/.emacs.d/mpc" "~/.mpc")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
884 "Directory where MPC.el stores auxiliary data."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
885 :type 'directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
886
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
887 (defun mpc-data-directory ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
888 (unless (file-directory-p mpc-data-directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
889 (make-directory mpc-data-directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
890 mpc-data-directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
891
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
892 (defun mpc-file-local-copy (file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
893 ;; Try to set mpc-mpd-music-directory.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
894 (when (and (null mpc-mpd-music-directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
895 (string-match "\\`localhost" mpc-host))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
896 (let ((files '("~/.mpdconf" "/etc/mpd.conf"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
897 file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
898 (while (and files (not file))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
899 (if (file-exists-p (car files)) (setq file (car files)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
900 (setq files (cdr files)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
901 (with-temp-buffer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
902 (ignore-errors (insert-file-contents file))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
903 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
904 (if (re-search-forward "^music_directory[ ]+\"\\([^\"]+\\)\"")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
905 (setq mpc-mpd-music-directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
906 (match-string 1))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
907 ;; Use mpc-mpd-music-directory if applicable, or else try to use the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
908 ;; `download' command, although it's never been accepted in `mpd' :-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
909 (if (and mpc-mpd-music-directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
910 (file-exists-p (expand-file-name file mpc-mpd-music-directory)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
911 (expand-file-name file mpc-mpd-music-directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
912 ;; (let ((aux (expand-file-name (replace-regexp-in-string "[/]" "|" file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
913 ;; (mpc-data-directory))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
914 ;; (unless (file-exists-p aux)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
915 ;; (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
916 ;; (with-local-quit
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
917 ;; (with-current-buffer (mpc-cmd-download file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
918 ;; (write-region (point-min) (point-max) aux)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
919 ;; (kill-buffer (current-buffer))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
920 ;; (mpc-proc-error (message "Download error: %s" err) (setq aux nil))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
921 ;; aux)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
922 ))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
923
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
924 ;;; Formatter ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
925
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
926 (defun mpc-secs-to-time (secs)
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
927 ;; We could use `format-seconds', but it doesn't seem worth the trouble
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
928 ;; because we'd still need to check (>= secs (* 60 100)) since the special
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
929 ;; %z only allows us to drop the large units for small values but
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
930 ;; not to drop the small units for large values.
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
931 (if (stringp secs) (setq secs (string-to-number secs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
932 (if (>= secs (* 60 100)) ;More than 100 minutes.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
933 (format "%dh%02d" ;"%d:%02d:%02d"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
934 (/ secs 3600) (% (/ secs 60) 60)) ;; (% secs 60)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
935 (format "%d:%02d" (/ secs 60) (% secs 60))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
936
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
937 (defvar mpc-tempfiles nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
938 (defconst mpc-tempfiles-reftable (make-hash-table :weakness 'key))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
939
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
940 (defun mpc-tempfiles-clean ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
941 (let ((live ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
942 (maphash (lambda (k v) (push v live)) mpc-tempfiles-reftable)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
943 (dolist (f mpc-tempfiles)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
944 (unless (member f live) (ignore-errors (delete-file f))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
945 (setq mpc-tempfiles live)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
946
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
947 (defun mpc-tempfiles-add (key file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
948 (mpc-tempfiles-clean)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
949 (puthash key file mpc-tempfiles-reftable)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
950 (push file mpc-tempfiles))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
951
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
952 (defun mpc-format (format-spec info &optional hscroll)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
953 "Format the INFO according to FORMAT-SPEC, inserting the result at point."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
954 (let* ((pos 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
955 (start (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
956 (col (if hscroll (- hscroll) 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
957 (insert (lambda (str)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
958 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
959 ((>= col 0) (insert str))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
960 (t (insert (substring str (min (length str) (- col))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
961 (pred nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
962 (while (string-match "%\\(?:%\\|\\(-\\)?\\([0-9]+\\)?{\\([[:alpha:]][[:alnum:]]*\\)\\(?:-\\([^}]+\\)\\)?}\\)" format-spec pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
963 (let ((pre-text (substring format-spec pos (match-beginning 0))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
964 (funcall insert pre-text)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
965 (setq col (+ col (string-width pre-text))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
966 (setq pos (match-end 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
967 (if (null (match-end 3))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
968 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
969 (funcall insert "%")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
970 (setq col (+ col 1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
971 (let* ((size (match-string 2 format-spec))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
972 (tag (intern (match-string 3 format-spec)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
973 (post (match-string 4 format-spec))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
974 (right-align (match-end 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
975 (text
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
976 (if (eq info 'self) (symbol-name tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
977 (case tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
978 ((Time Duration)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
979 (let ((time (cdr (or (assq 'time info) (assq 'Time info)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
980 (setq pred (list nil)) ;Just assume it's never eq.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
981 (when time
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
982 (mpc-secs-to-time (if (and (eq tag 'Duration)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
983 (string-match ":" time))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
984 (substring time (match-end 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
985 time)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
986 (Cover
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
987 (let* ((dir (file-name-directory (cdr (assq 'file info))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
988 (cover (concat dir "cover.jpg"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
989 (file (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
990 (mpc-file-local-copy cover)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
991 (error (message "MPC: %s" err))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
992 image)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
993 ;; (debug)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
994 (push `(equal ',dir (file-name-directory (cdr (assq 'file info)))) pred)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
995 (if (null file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
996 ;; Make sure we return something on which we can
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
997 ;; place the `mpc-pred' property, as
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
998 ;; a negative-cache. We could also use
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
999 ;; a default cover.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1000 (progn (setq size nil) " ")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1001 (if (null size) (setq image (create-image file))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1002 (let ((tempfile (make-temp-file "mpc" nil ".jpg")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1003 (call-process "convert" nil nil nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1004 "-scale" size file tempfile)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1005 (setq image (create-image tempfile))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1006 (mpc-tempfiles-add image tempfile)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1007 (setq size nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1008 (propertize dir 'display image))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1009 (t (let ((val (cdr (assq tag info))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1010 ;; For Streaming URLs, there's no other info
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1011 ;; than the URL in `file'. Pretend it's in `Title'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1012 (when (and (null val) (eq tag 'Title))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1013 (setq val (cdr (assq 'file info))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1014 (push `(equal ',val (cdr (assq ',tag info))) pred)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1015 val)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1016 (space (when size
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1017 (setq size (string-to-number size))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1018 (propertize " " 'display
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1019 (list 'space :align-to (+ col size)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1020 (textwidth (if text (string-width text) 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1021 (postwidth (if post (string-width post) 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1022 (when text
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1023 (let ((display
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1024 (if (and size
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1025 (> (+ postwidth textwidth) size))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1026 ;; This doesn't even obey double-width chars :-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1027 (propertize
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1028 (if (zerop (- size postwidth 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1029 (substring text 0 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1030 (concat (substring text 0 (- size postwidth textwidth 1)) "…"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1031 'help-echo text)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1032 text)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1033 (when (memq tag '(Artist Album Composer)) ;FIXME: wrong list.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1034 (setq display
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1035 (propertize display
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1036 'mouse-face 'highlight
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1037 'follow-link t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1038 'keymap `(keymap
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1039 (mouse-2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1040 . (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1041 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1042 (mpc-constraints-push 'noerror)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1043 (mpc-constraints-restore
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1044 ',(list (list tag text)))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1045 (funcall insert
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1046 (concat (when size
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1047 (propertize " " 'display
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1048 (list 'space :align-to
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1049 (+ col
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1050 (if (and size right-align)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1051 (- size postwidth textwidth)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1052 0)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1053 display post))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1054 (if (null size) (setq col (+ col textwidth postwidth))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1055 (insert space)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1056 (setq col (+ col size))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1057 (put-text-property start (point) 'mpc-pred
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1058 `(lambda (info) (and ,@(nreverse pred))))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1059
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1060 ;;; The actual UI code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1061
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1062 (defvar mpc-mode-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1063 (let ((map (make-keymap)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1064 (suppress-keymap map)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1065 ;; (define-key map "\e" 'mpc-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1066 (define-key map "q" 'mpc-quit)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1067 (define-key map "\r" 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1068 (define-key map [(shift return)] 'mpc-select-toggle)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1069 (define-key map [mouse-2] 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1070 (define-key map [S-mouse-2] 'mpc-select-extend)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1071 (define-key map [C-mouse-2] 'mpc-select-toggle)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1072 (define-key map [drag-mouse-2] 'mpc-drag-n-drop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1073 ;; We use `always' because a binding to t is like a binding to nil.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1074 (define-key map [follow-link] 'always)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1075 ;; Doesn't work because the first click changes the buffer, so the second
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1076 ;; is applied elsewhere :-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1077 ;; (define-key map [(double mouse-2)] 'mpc-play-at-point)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1078 (define-key map "p" 'mpc-pause)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1079 map))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1080
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1081 (easy-menu-define mpc-mode-menu mpc-mode-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1082 "Menu for MPC.el."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1083 '("MPC.el"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1084 ["Add new browser" mpc-tagbrowser]
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1085 ["Update DB" mpc-update]
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1086 ["Quit" mpc-quit]))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1087
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1088 (defvar mpc-tool-bar-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1089 (let ((map (make-sparse-keymap)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1090 (tool-bar-local-item "mpc/prev" 'mpc-prev 'prev map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1091 :enable '(not (equal (cdr (assq 'state mpc-status)) "stop")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1092 ;; FIXME: how can we bind it to the down-event?
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1093 (tool-bar-local-item "mpc/rewind" 'mpc-rewind 'rewind map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1094 :enable '(not (equal (cdr (assq 'state mpc-status)) "stop"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1095 :button '(:toggle . (and mpc--faster-toggle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1096 (not mpc--faster-toggle-forward))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1097 ;; We could use a single toggle command for pause/play, with 2 different
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1098 ;; icons depending on whether or not it's selected, but then it'd have
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1099 ;; to be a toggle-button, thus displayed depressed in one of the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1100 ;; two states :-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1101 (tool-bar-local-item "mpc/pause" 'mpc-pause 'pause map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1102 :visible '(equal (cdr (assq 'state mpc-status)) "play")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1103 :help "Pause/play")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1104 (tool-bar-local-item "mpc/play" 'mpc-play 'play map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1105 :visible '(not (equal (cdr (assq 'state mpc-status)) "play"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1106 :help "Play/pause")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1107 ;; FIXME: how can we bind it to the down-event?
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1108 (tool-bar-local-item "mpc/ffwd" 'mpc-ffwd 'ffwd map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1109 :enable '(not (equal (cdr (assq 'state mpc-status)) "stop"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1110 :button '(:toggle . (and mpc--faster-toggle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1111 mpc--faster-toggle-forward)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1112 (tool-bar-local-item "mpc/next" 'mpc-next 'next map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1113 :enable '(not (equal (cdr (assq 'state mpc-status)) "stop")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1114 (tool-bar-local-item "mpc/stop" 'mpc-stop 'stop map)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1115 (tool-bar-local-item "mpc/add" 'mpc-playlist-add 'add map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1116 :help "Append to the playlist")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1117 map))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1118
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1119 (define-derived-mode mpc-mode fundamental-mode "MPC"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1120 "Major mode for the features common to all buffers of MPC."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1121 (buffer-disable-undo)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1122 (setq buffer-read-only t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1123 (set (make-local-variable 'tool-bar-map) mpc-tool-bar-map)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1124 (set (make-local-variable 'truncate-lines) t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1125
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1126 ;;; The mpc-status-mode buffer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1127
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1128 (define-derived-mode mpc-status-mode mpc-mode "MPC-Status"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1129 "Major mode to display MPC status info."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1130 (set (make-local-variable 'mode-line-format)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1131 '("%e" mode-line-frame-identification mode-line-buffer-identification))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1132 (set (make-local-variable 'window-area-factor) 3)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1133 (set (make-local-variable 'header-line-format) '("MPC " mpc-volume)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1134
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1135 (defvar mpc-status-buffer-format
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1136 '("%-5{Time} / %{Duration} %2{Disc--}%4{Track}" "%{Title}" "%{Album}" "%{Artist}" "%128{Cover}"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1137
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1138 (defun mpc-status-buffer-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1139 (let ((buf (mpc-proc-buffer (mpc-proc) 'status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1140 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1141 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1142 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1143 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1144 (when (assq 'file mpc-status)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1145 (let ((inhibit-read-only t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1146 (dolist (spec mpc-status-buffer-format)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1147 (let ((pred (get-text-property (point) 'mpc-pred)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1148 (if (and pred (funcall pred mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1149 (forward-line)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1150 (delete-region (point) (line-beginning-position 2))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1151 (ignore-errors (mpc-format spec mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1152 (insert "\n"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1153 (unless (eobp) (delete-region (point) (point-max))))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1154
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1155 (defun mpc-status-buffer-show ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1156 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1157 (let* ((buf (mpc-proc-buffer (mpc-proc) 'status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1158 (songs-buf (mpc-proc-buffer (mpc-proc) 'songs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1159 (songs-win (if songs-buf (get-buffer-window songs-buf 0))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1160 (unless (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1161 (setq buf (get-buffer-create "*MPC-Status*"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1162 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1163 (mpc-status-mode))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1164 (mpc-proc-buffer (mpc-proc) 'status buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1165 (if (null songs-win) (pop-to-buffer buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1166 (let ((win (split-window songs-win 20 t)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1167 (set-window-dedicated-p songs-win nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1168 (set-window-buffer songs-win buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1169 (set-window-dedicated-p songs-win 'soft)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1170
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1171 ;;; Selection management;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1172
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1173 (defvar mpc-separator-ol nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1174
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1175 (defvar mpc-select nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1176 (make-variable-buffer-local 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1177
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1178 (defmacro mpc-select-save (&rest body)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1179 "Execute BODY and restore the selection afterwards."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1180 (declare (indent 0) (debug t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1181 `(let ((selection (mpc-select-get-selection))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1182 (position (cons (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1183 (line-beginning-position) (line-end-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1184 (current-column))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1185 ,@body
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1186 (mpc-select-restore selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1187 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1188 (if (re-search-forward
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1189 (concat "^" (regexp-quote (car position)) "$")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1190 (if (overlayp mpc-separator-ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1191 (overlay-end mpc-separator-ol))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1192 t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1193 (move-to-column (cdr position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1194 (let ((win (get-buffer-window (current-buffer) 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1195 (if win (set-window-point win (point))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1196
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1197 (defun mpc-select-get-selection ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1198 (mapcar (lambda (ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1199 (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1200 (overlay-start ol) (1- (overlay-end ol))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1201 mpc-select))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1202
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1203 (defun mpc-select-restore (selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1204 ;; Restore the selection. I.e. move the overlays back to their
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1205 ;; corresponding location. Actually which overlay is used for what
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1206 ;; doesn't matter.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1207 (mapc 'delete-overlay mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1208 (setq mpc-select nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1209 (dolist (elem selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1210 ;; After an update, some elements may have disappeared.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1211 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1212 (when (re-search-forward
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1213 (concat "^" (regexp-quote elem) "$") nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1214 (mpc-select-make-overlay)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1215 (when mpc-tag (mpc-tagbrowser-all-select))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1216 (beginning-of-line))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1217
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1218 (defun mpc-select-make-overlay ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1219 (assert (not (get-char-property (point) 'mpc-select)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1220 (let ((ol (make-overlay
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1221 (line-beginning-position) (line-beginning-position 2))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1222 (overlay-put ol 'mpc-select t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1223 (overlay-put ol 'face 'region)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1224 (overlay-put ol 'evaporate t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1225 (push ol mpc-select)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1226
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1227 (defun mpc-select (&optional event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1228 "Select the tag value at point."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1229 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1230 (mpc-event-set-point event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1231 (if (and (bolp) (eobp)) (forward-line -1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1232 (mapc 'delete-overlay mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1233 (setq mpc-select nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1234 (if (mpc-tagbrowser-all-p)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1235 nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1236 (mpc-select-make-overlay))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1237 (when mpc-tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1238 (mpc-tagbrowser-all-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1239 (mpc-selection-refresh)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1240
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1241 (defun mpc-select-toggle (&optional event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1242 "Toggle the selection of the tag value at point."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1243 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1244 (mpc-event-set-point event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1245 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1246 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1247 ;; The line is already selected: deselect it.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1248 ((get-char-property (point) 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1249 (let ((ols nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1250 (dolist (ol mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1251 (if (and (<= (overlay-start ol) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1252 (> (overlay-end ol) (point)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1253 (delete-overlay ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1254 (push ol ols)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1255 (assert (= (1+ (length ols)) (length mpc-select)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1256 (setq mpc-select ols)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1257 ;; We're trying to select *ALL* additionally to others.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1258 ((mpc-tagbrowser-all-p) nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1259 ;; Select the current line.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1260 (t (mpc-select-make-overlay))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1261 (when mpc-tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1262 (mpc-tagbrowser-all-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1263 (mpc-selection-refresh)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1264
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1265 (defun mpc-select-extend (&optional event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1266 "Extend the selection up to point."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1267 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1268 (mpc-event-set-point event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1269 (if (null mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1270 ;; If nothing's selected yet, fallback to selecting the elem at point.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1271 (mpc-select event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1272 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1273 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1274 ;; The line is already in a selected area; truncate the area.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1275 ((get-char-property (point) 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1276 (let ((before 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1277 (after 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1278 (mid (line-beginning-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1279 start end)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1280 (while (and (zerop (forward-line 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1281 (get-char-property (point) 'mpc-select))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1282 (setq end (1+ (point)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1283 (incf after))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1284 (goto-char mid)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1285 (while (and (zerop (forward-line -1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1286 (get-char-property (point) 'mpc-select))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1287 (setq start (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1288 (incf before))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1289 (if (and (= after 0) (= before 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1290 ;; Shortening an already minimum-size region: do nothing.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1291 nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1292 (if (> after before)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1293 (setq end mid)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1294 (setq start (1+ mid)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1295 (let ((ols '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1296 (dolist (ol mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1297 (if (and (>= (overlay-start ol) start)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1298 (< (overlay-start ol) end))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1299 (delete-overlay ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1300 (push ol ols)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1301 (setq mpc-select (nreverse ols))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1302 ;; Extending a prior area. Look for the closest selection.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1303 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1304 (when (mpc-tagbrowser-all-p)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1305 (forward-line 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1306 (let ((before 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1307 (count 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1308 (dir 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1309 (start (line-beginning-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1310 (while (and (zerop (forward-line 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1311 (not (get-char-property (point) 'mpc-select)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1312 (incf count))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1313 (unless (get-char-property (point) 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1314 (setq count nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1315 (goto-char start)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1316 (while (and (zerop (forward-line -1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1317 (not (get-char-property (point) 'mpc-select)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1318 (incf before))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1319 (unless (get-char-property (point) 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1320 (setq before nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1321 (when (and before (or (null count) (< before count)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1322 (setq count before)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1323 (setq dir -1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1324 (goto-char start)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1325 (dotimes (i (1+ (or count 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1326 (mpc-select-make-overlay)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1327 (forward-line dir))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1328 (when mpc-tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1329 (mpc-tagbrowser-all-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1330 (mpc-selection-refresh))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1331
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1332 ;;; Constraint sets ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1333
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1334 (defvar mpc--song-search nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1335
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1336 (defun mpc-constraints-get-current (&optional avoid-buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1337 "Return currently selected set of constraints.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1338 If AVOID-BUF is non-nil, it specifies a buffer which should be ignored
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1339 when constructing the set of constraints."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1340 (let ((constraints (if mpc--song-search `((Search ,mpc--song-search))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1341 tag select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1342 (dolist (buf (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1343 (setq buf (cdr buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1344 (when (and (setq tag (buffer-local-value 'mpc-tag buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1345 (not (eq buf avoid-buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1346 (setq select
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1347 (with-current-buffer buf (mpc-select-get-selection))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1348 (push (cons tag select) constraints)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1349 constraints))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1350
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1351 (defun mpc-constraints-restore (constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1352 (let ((search (assq 'Search constraints)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1353 (setq mpc--song-search (cadr search))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1354 (when search (setq constraints (delq search constraints))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1355 (dolist (buf (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1356 (setq buf (cdr buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1357 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1358 (let* ((tag (buffer-local-value 'mpc-tag buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1359 (constraint (assq tag constraints)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1360 (when tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1361 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1362 (mpc-select-restore (cdr constraint)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1363 (mpc-selection-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1364
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1365 ;; I don't get the ring.el code. I think it doesn't do what I need, but
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1366 ;; then I don't understand when what it does would be useful.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1367 (defun mpc-ring-make (size) (cons 0 (cons 0 (make-vector size nil))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1368 (defun mpc-ring-push (ring val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1369 (aset (cddr ring) (car ring) val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1370 (setcar (cdr ring) (max (cadr ring) (1+ (car ring))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1371 (setcar ring (mod (1+ (car ring)) (length (cddr ring)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1372 (defun mpc-ring-pop (ring)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1373 (setcar ring (mod (1- (car ring)) (cadr ring)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1374 (aref (cddr ring) (car ring)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1375
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1376 (defvar mpc-constraints-ring (mpc-ring-make 10))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1377
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1378 (defun mpc-constraints-push (&optional noerror)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1379 "Push the current selection on the ring for later."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1380 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1381 (let ((constraints (mpc-constraints-get-current)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1382 (if (null constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1383 (unless noerror (error "No selection to push"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1384 (mpc-ring-push mpc-constraints-ring constraints))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1385
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1386 (defun mpc-constraints-pop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1387 "Recall the most recently pushed selection."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1388 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1389 (let ((constraints (mpc-ring-pop mpc-constraints-ring)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1390 (if (null constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1391 (error "No selection to return to")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1392 (mpc-constraints-restore constraints))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1393
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1394 ;;; The TagBrowser mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1395
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1396 (defconst mpc-tagbrowser-all-name (propertize "*ALL*" 'face 'italic))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1397 (defvar mpc-tagbrowser-all-ol nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1398 (make-variable-buffer-local 'mpc-tagbrowser-all-ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1399 (defvar mpc-tag-name nil) (make-variable-buffer-local 'mpc-tag-name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1400 (defun mpc-tagbrowser-all-p ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1401 (and (eq (point-min) (line-beginning-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1402 (equal mpc-tagbrowser-all-name
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1403 (buffer-substring (point-min) (line-end-position)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1404
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1405 (define-derived-mode mpc-tagbrowser-mode mpc-mode '("MPC-" mpc-tag-name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1406 (set (make-local-variable 'mode-line-process) '("" mpc-tag-name))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1407 (set (make-local-variable 'mode-line-format) nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1408 (set (make-local-variable 'header-line-format) '("" mpc-tag-name ;; "s"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1409 ))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1410 (set (make-local-variable 'buffer-undo-list) t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1411 )
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1412
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1413 (defun mpc-tagbrowser-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1414 (mpc-select-save
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1415 (widen)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1416 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1417 (assert (looking-at (regexp-quote mpc-tagbrowser-all-name)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1418 (forward-line 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1419 (let ((inhibit-read-only t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1420 (delete-region (point) (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1421 (dolist (val (mpc-cmd-list mpc-tag)) (insert val "\n")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1422 (set-buffer-modified-p nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1423 (mpc-reorder))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1424
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1425 (defun mpc-updated-db ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1426 ;; FIXME: This is not asynchronous, but is run from a process filter.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1427 (unless (assq 'updating_db mpc-status)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1428 (clrhash mpc--find-memoize)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1429 (dolist (buf (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1430 (setq buf (cdr buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1431 (when (buffer-local-value 'mpc-tag buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1432 (with-current-buffer buf (with-local-quit (mpc-tagbrowser-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1433 (with-local-quit (mpc-songs-refresh))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1434
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1435 (defun mpc-tagbrowser-tag-name (tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1436 (cond
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1437 ((string-match "|" (symbol-name tag))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1438 (let ((tag1 (intern (substring (symbol-name tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1439 0 (match-beginning 0))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1440 (tag2 (intern (substring (symbol-name tag)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1441 (match-end 0)))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1442 (concat (mpc-tagbrowser-tag-name tag1)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1443 " | "
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1444 (mpc-tagbrowser-tag-name tag2))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1445 ((string-match "y\\'" (symbol-name tag))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1446 (concat (substring (symbol-name tag) 0 -1) "ies"))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1447 (t (concat (symbol-name tag) "s"))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1448
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1449 (defun mpc-tagbrowser-buf (tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1450 (let ((buf (mpc-proc-buffer (mpc-proc) tag)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1451 (if (buffer-live-p buf) buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1452 (setq buf (get-buffer-create (format "*MPC %ss*" tag)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1453 (mpc-proc-buffer (mpc-proc) tag buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1454 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1455 (let ((inhibit-read-only t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1456 (erase-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1457 (if (member tag '(Directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1458 (mpc-tagbrowser-dir-mode)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1459 (mpc-tagbrowser-mode))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1460 (insert mpc-tagbrowser-all-name "\n"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1461 (forward-line -1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1462 (setq mpc-tag tag)
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1463 (setq mpc-tag-name (mpc-tagbrowser-tag-name tag))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1464 (mpc-tagbrowser-all-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1465 (mpc-tagbrowser-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1466 buf))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1467
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1468 (defvar tag-browser-tagtypes
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1469 (lazy-completion-table tag-browser-tagtypes
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1470 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1471 (append '("Playlist" "Directory")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1472 (mpc-cmd-tagtypes)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1473
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1474 (defun mpc-tagbrowser (tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1475 "Create a new browser for TAG."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1476 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1477 (list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1478 (let ((completion-ignore-case t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1479 (intern
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1480 (completing-read "Tag: " tag-browser-tagtypes nil 'require-match)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1481 (let* ((newbuf (mpc-tagbrowser-buf tag))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1482 (win (get-buffer-window newbuf 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1483 (if win (select-window win)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1484 (if (with-current-buffer (window-buffer (selected-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1485 (derived-mode-p 'mpc-tagbrowser-mode))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1486 (setq win (selected-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1487 ;; Find a tagbrowser-mode buffer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1488 (let ((buffers (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1489 buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1490 (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1491 (and buffers
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1492 (not (and (buffer-live-p (setq buffer (cdr (pop buffers))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1493 (with-current-buffer buffer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1494 (derived-mode-p 'mpc-tagbrowser-mode))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1495 (setq win (get-buffer-window buffer 0))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1496 (if (not win)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1497 (pop-to-buffer newbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1498 (setq win (split-window win nil 'horiz))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1499 (set-window-buffer win newbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1500 (set-window-dedicated-p win 'soft)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1501 (select-window win)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1502 (balance-windows-area)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1503
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1504 (defun mpc-tagbrowser-all-select ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1505 "Select the special *ALL* entry if no other is selected."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1506 (if mpc-select
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1507 (delete-overlay mpc-tagbrowser-all-ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1508 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1509 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1510 (if mpc-tagbrowser-all-ol
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1511 (move-overlay mpc-tagbrowser-all-ol
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1512 (point) (line-beginning-position 2))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1513 (let ((ol (make-overlay (point) (line-beginning-position 2))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1514 (overlay-put ol 'face 'region)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1515 (overlay-put ol 'evaporate t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1516 (set (make-local-variable 'mpc-tagbrowser-all-ol) ol))))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1517
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1518 ;; (defvar mpc-constraints nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1519 (defun mpc-separator (active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1520 ;; Place a separator mark.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1521 (unless mpc-separator-ol
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1522 (set (make-local-variable 'mpc-separator-ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1523 (make-overlay (point) (point)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1524 (overlay-put mpc-separator-ol 'after-string
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1525 (propertize "\n"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1526 'face '(:height 0.05 :inverse-video t))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1527 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1528 (forward-line 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1529 (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1530 (and (member (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1531 (line-beginning-position) (line-end-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1532 active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1533 (zerop (forward-line 1))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1534 (if (or (eobp) (null active))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1535 (delete-overlay mpc-separator-ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1536 (move-overlay mpc-separator-ol (1- (point)) (point))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1537
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1538 (defun mpc-sort (active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1539 ;; Sort the active elements at the front.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1540 (let ((inhibit-read-only t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1541 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1542 (if (mpc-tagbrowser-all-p) (forward-line 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1543 (condition-case nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1544 (sort-subr nil 'forward-line 'end-of-line
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1545 nil nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1546 (lambda (s1 s2)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1547 (setq s1 (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1548 (car s1) (cdr s1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1549 (setq s2 (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1550 (car s2) (cdr s2)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1551 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1552 ((member s1 active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1553 (if (member s2 active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1554 (let ((cmp (mpc-compare-strings s1 s2 t)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1555 (and (numberp cmp) (< cmp 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1556 t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1557 ((member s2 active) nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1558 (t (let ((cmp (mpc-compare-strings s1 s2 t)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1559 (and (numberp cmp) (< cmp 0)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1560 ;; The comparison predicate arg is new in Emacs-22.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1561 (wrong-number-of-arguments
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1562 (sort-subr nil 'forward-line 'end-of-line
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1563 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1564 (let ((name (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1565 (point) (line-end-position))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1566 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1567 ((member name active) (concat "1" name))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1568 (t (concat "2" "name"))))))))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1569
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1570 (defvar mpc--changed-selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1571
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1572 (defun mpc-reorder (&optional nodeactivate)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1573 "Reorder entries based on thre currently active selections.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1574 I.e. split the current browser buffer into a first part containing the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1575 entries included in the selection, then a separator, and then the entries
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1576 not included in the selection.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1577 Return non-nil if a selection was deactivated."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1578 (mpc-select-save
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1579 (let ((constraints (mpc-constraints-get-current (current-buffer)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1580 (active 'all))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1581 ;; (unless (equal constraints mpc-constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1582 ;; (set (make-local-variable 'mpc-constraints) constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1583 (dolist (cst constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1584 (let ((vals (apply 'mpc-union
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1585 (mapcar (lambda (val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1586 (mpc-cmd-list mpc-tag (car cst) val))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1587 (cdr cst)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1588 (setq active
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1589 (if (listp active) (mpc-intersection active vals) vals))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1590
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1591 (when (and (listp active))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1592 ;; Remove the selections if they are all in conflict with
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1593 ;; other constraints.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1594 (let ((deactivate t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1595 (dolist (sel selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1596 (when (member sel active) (setq deactivate nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1597 (when deactivate
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1598 ;; Variable declared/used by `mpc-select-save'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1599 (when selection
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1600 (setq mpc--changed-selection t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1601 (unless nodeactivate
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1602 (setq selection nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1603 (mapc 'delete-overlay mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1604 (setq mpc-select nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1605 (mpc-tagbrowser-all-select)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1606
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1607 ;; FIXME: This `mpc-sort' takes a lot of time. Maybe we should
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1608 ;; be more clever and presume the buffer is mostly sorted already.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1609 (mpc-sort (if (listp active) active))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1610 (mpc-separator (if (listp active) active)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1611
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1612 (defun mpc-selection-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1613 (let ((mpc--changed-selection t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1614 (while mpc--changed-selection
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1615 (setq mpc--changed-selection nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1616 (dolist (buf (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1617 (setq buf (cdr buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1618 (when (and (buffer-local-value 'mpc-tag buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1619 (not (eq buf (current-buffer))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1620 (with-current-buffer buf (mpc-reorder)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1621 ;; FIXME: reorder the current buffer last and prevent deactivation,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1622 ;; since whatever selection we made here is the most recent one
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1623 ;; and should hence take precedence.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1624 (when mpc-tag (mpc-reorder 'nodeactivate))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1625 ;; FIXME: comment?
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1626 (if (and mpc--song-search mpc--changed-selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1627 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1628 (setq mpc--song-search nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1629 (mpc-selection-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1630 (mpc-songs-refresh))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1631
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1632 ;;; Hierarchical tagbrowser ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1633 ;; Todo:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1634 ;; - Add a button on each dir to open/close it (?)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1635 ;; - add the parent dir on the previous line, greyed-out, if it's not
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1636 ;; present (because we're in the non-selected part and the parent is
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1637 ;; in the selected part).
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1638
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1639 (defvar mpc-tagbrowser-dir-mode-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1640 (let ((map (make-sparse-keymap)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1641 (set-keymap-parent map mpc-tagbrowser-mode-map)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1642 (define-key map [?\M-\C-m] 'mpc-tagbrowser-dir-toggle)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1643 map))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1644
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1645 ;; (defvar mpc-tagbrowser-dir-keywords
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1646 ;; '(mpc-tagbrowser-dir-hide-prefix))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1647
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1648 (define-derived-mode mpc-tagbrowser-dir-mode mpc-tagbrowser-mode '("MPC-" mpc-tag-name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1649 ;; (set (make-local-variable 'font-lock-defaults)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1650 ;; '(mpc-tagbrowser-dir-keywords t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1651 )
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1652
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1653 ;; (defun mpc-tagbrowser-dir-hide-prefix (limit)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1654 ;; (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1655 ;; (let ((prev (buffer-substring (line-beginning-position 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1656 ;; (line-end-position 0))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1657 ;; (
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1658
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1659 (defun mpc-tagbrowser-dir-toggle (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1660 "Open or close the element at point."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1661 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1662 (mpc-event-set-point event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1663 (let ((name (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1664 (line-end-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1665 (prop (intern mpc-tag)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1666 (if (not (member name (process-get (mpc-proc) prop)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1667 (process-put (mpc-proc) prop
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1668 (cons name (process-get (mpc-proc) prop)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1669 (let ((new (delete name (process-get (mpc-proc) prop))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1670 (setq name (concat name "/"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1671 (process-put (mpc-proc) prop
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1672 (delq nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1673 (mapcar (lambda (x)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1674 (if (mpc-string-prefix-p name x)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1675 nil x))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1676 new)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1677 (mpc-tagbrowser-refresh)))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1678
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1679
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1680 ;;; Playlist management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1681
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1682 (defvar mpc-songs-playlist nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1683 "Name of the currently selected playlist, if any.
106365
06698b91c779 * mpc.el (mpc-intersection, mpc-host, mpc-songs-playlist)
Juanma Barranquero <lekktu@gmail.com>
parents: 106354
diff changeset
1684 A value of t means the main playlist.")
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1685 (make-variable-buffer-local 'mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1686
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1687 (defun mpc-playlist-create (name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1688 "Save current playlist under name NAME."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1689 (interactive "sPlaylist name: ")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1690 (mpc-proc-cmd (list "save" name))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1691 (let ((buf (mpc-proc-buffer (mpc-proc) 'Playlist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1692 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1693 (with-current-buffer buf (mpc-tagbrowser-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1694
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1695 (defun mpc-playlist-destroy (name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1696 "Delete playlist named NAME."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1697 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1698 (list (completing-read "Delete playlist: " (mpc-cmd-list 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1699 nil 'require-match)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1700 (mpc-proc-cmd (list "rm" name))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1701 (let ((buf (mpc-proc-buffer (mpc-proc) 'Playlist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1702 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1703 (with-current-buffer buf (mpc-tagbrowser-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1704
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1705 (defun mpc-playlist-rename (oldname newname)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1706 "Rename playlist OLDNAME to NEWNAME."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1707 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1708 (let* ((oldname (if (and (eq mpc-tag 'Playlist) (null current-prefix-arg))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1709 (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1710 (line-end-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1711 (completing-read "Rename playlist: "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1712 (mpc-cmd-list 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1713 nil 'require-match)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1714 (newname (read-string (format "Rename '%s' to: " oldname))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1715 (if (zerop (length newname))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1716 (error "Aborted")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1717 (list oldname newname))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1718 (mpc-proc-cmd (list "rename" oldname newname))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1719 (let ((buf (mpc-proc-buffer (mpc-proc) 'Playlist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1720 (if (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1721 (with-current-buffer buf (mpc-tagbrowser-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1722
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1723 (defun mpc-playlist ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1724 "Show the current playlist."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1725 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1726 (mpc-constraints-push 'noerror)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1727 (mpc-constraints-restore '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1728
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1729 (defun mpc-playlist-add ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1730 "Add the selection to the playlist."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1731 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1732 (let ((songs (mapcar #'car (mpc-songs-selection))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1733 (mpc-cmd-add songs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1734 (message "Appended %d songs" (length songs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1735 ;; Return the songs added. Used in `mpc-play'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1736 songs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1737
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1738 (defun mpc-playlist-delete ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1739 "Remove the selected songs from the playlist."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1740 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1741 (unless mpc-songs-playlist
106697
ac408704629c lisp/*: Fix typos in docstrings and messages.
Juanma Barranquero <lekktu@gmail.com>
parents: 106365
diff changeset
1742 (error "The selected songs aren't part of a playlist"))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1743 (let ((song-poss (mapcar #'cdr (mpc-songs-selection))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1744 (mpc-cmd-delete song-poss mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1745 (mpc-songs-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1746 (message "Deleted %d songs" (length song-poss))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1747
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1748 ;;; Volume management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1749
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1750 (defvar mpc-volume-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1751 (let ((map (make-sparse-keymap)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1752 (define-key map [down-mouse-1] 'mpc-volume-mouse-set)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1753 (define-key map [mouse-1] 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1754 (define-key map [header-line down-mouse-1] 'mpc-volume-mouse-set)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1755 (define-key map [header-line mouse-1] 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1756 (define-key map [mode-line down-mouse-1] 'mpc-volume-mouse-set)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1757 (define-key map [mode-line mouse-1] 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1758 map))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1759
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1760 (defvar mpc-volume nil) (put 'mpc-volume 'risky-local-variable t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1761
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1762 (defun mpc-volume-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1763 ;; Maintain the volume.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1764 (setq mpc-volume
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1765 (mpc-volume-widget
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1766 (string-to-number (cdr (assq 'volume mpc-status))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1767
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1768 (defvar mpc-volume-step 5)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1769
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1770 (defun mpc-volume-mouse-set (&optional event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1771 "Change volume setting."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1772 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1773 (let* ((posn (event-start event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1774 (diff
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1775 (if (memq (if (stringp (car-safe (posn-object posn)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1776 (aref (car (posn-object posn)) (cdr (posn-object posn)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1777 (with-current-buffer (window-buffer (posn-window posn))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1778 (char-after (posn-point posn))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1779 '(?◁ ?<))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1780 (- mpc-volume-step) mpc-volume-step))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1781 (newvol (+ (string-to-number (cdr (assq 'volume mpc-status))) diff)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1782 (mpc-proc-cmd (list "setvol" newvol) 'mpc-status-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1783 (message "Set MPD volume to %s%%" newvol)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1784
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1785 (defun mpc-volume-widget (vol &optional size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1786 (unless size (setq size 12.5))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1787 (let ((scaledvol (* (/ vol 100.0) size)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1788 ;; (message "Volume sizes: %s - %s" (/ vol fact) (/ (- 100 vol) fact))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1789 (list (propertize "<" ;; "◁"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1790 ;; 'face 'default
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1791 'keymap mpc-volume-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1792 'face '(:box (:line-width -2 :style pressed-button))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1793 'mouse-face '(:box (:line-width -2 :style released-button)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1794 " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1795 (propertize "a"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1796 'display (list 'space :width scaledvol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1797 'face '(:inverse-video t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1798 :box (:line-width -2 :style released-button)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1799 (propertize "a"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1800 'display (list 'space :width (- size scaledvol))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1801 'face '(:box (:line-width -2 :style released-button)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1802 " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1803 (propertize ">" ;; "▷"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1804 ;; 'face 'default
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1805 'keymap mpc-volume-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1806 'face '(:box (:line-width -2 :style pressed-button))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1807 'mouse-face '(:box (:line-width -2 :style released-button))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1808
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1809 ;;; MPC songs mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1810
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1811 (defvar mpc-current-song nil) (put 'mpc-current-song 'risky-local-variable t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1812 (defvar mpc-current-updating nil) (put 'mpc-current-updating 'risky-local-variable t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1813 (defvar mpc-songs-format-description nil) (put 'mpc-songs-format-description 'risky-local-variable t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1814
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1815 (defvar mpc-previous-window-config nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1816
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1817 (defvar mpc-songs-mode-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1818 (let ((map (make-sparse-keymap)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1819 (set-keymap-parent map mpc-mode-map)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1820 (define-key map [remap mpc-select] 'mpc-songs-jump-to)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1821 map))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1822
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1823 (defvar mpc-songpointer-set-visible nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1824
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1825 (defvar mpc-songs-hashcons (make-hash-table :test 'equal :weakness t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1826 "Make song file name objects unique via hash consing.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1827 This is used so that they can be compared with `eq', which is needed for
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1828 `text-property-any'.")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1829 (defun mpc-songs-hashcons (name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1830 (or (gethash name mpc-songs-hashcons) (puthash name name mpc-songs-hashcons)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1831 (defcustom mpc-songs-format "%2{Disc--}%3{Track} %-5{Time} %25{Title} %20{Album} %20{Artist} %10{Date}"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1832 "Format used to display each song in the list of songs."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1833 :type 'string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1834
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1835 (defvar mpc-songs-totaltime)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1836
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1837 (defun mpc-songs-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1838 (let ((buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1839 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1840 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1841 (let ((constraints (mpc-constraints-get-current (current-buffer)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1842 (dontsort nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1843 (inhibit-read-only t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1844 (totaltime 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1845 (curline (cons (count-lines (point-min)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1846 (line-beginning-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1847 (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1848 (line-end-position))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1849 active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1850 (setq mpc-songs-playlist nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1851 (if (null constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1852 ;; When there are no constraints, rather than show the list of
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1853 ;; all songs (which could take a while to download and
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1854 ;; format), we show the current playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1855 ;; FIXME: it would be good to be able to show the complete
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1856 ;; list, but that would probably require us to format it
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1857 ;; on-the-fly to make it bearable.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1858 (setq dontsort t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1859 mpc-songs-playlist t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1860 active (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1861 (mpc-proc-cmd "playlistinfo")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1862 (dolist (cst constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1863 (if (and (eq (car cst) 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1864 (= 1 (length (cdr cst))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1865 (setq mpc-songs-playlist (cadr cst)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1866 ;; We don't do anything really special here for playlists,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1867 ;; because it's unclear what's a correct "union" of playlists.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1868 (let ((vals (apply 'mpc-union
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1869 (mapcar (lambda (val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1870 (mpc-cmd-find (car cst) val))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1871 (cdr cst)))))
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1872 (setq active (cond
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1873 ((null active)
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1874 (if (eq (car cst) 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1875 (setq dontsort t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1876 vals)
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1877 ((or dontsort
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1878 ;; Try to preserve ordering and
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1879 ;; repetitions from playlists.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1880 (not (eq (car cst) 'Playlist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1881 (mpc-intersection active vals
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1882 (lambda (x) (assq 'file x))))
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1883 (t
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1884 (setq dontsort t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1885 (mpc-intersection vals active
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1886 (lambda (x)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1887 (assq 'file x)))))))))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1888 (mpc-select-save
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1889 (erase-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1890 ;; Sorting songs is surprisingly difficult: when comparing two
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1891 ;; songs with the same album name but different artist name, you
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1892 ;; have to know whether these are two different albums (with the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1893 ;; same name) or a single album (typically a compilation).
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1894 ;; I punt on it and just use file-name sorting, which does the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1895 ;; right thing if your library is properly arranged.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1896 (dolist (song (if dontsort active
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1897 (sort active
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1898 (lambda (song1 song2)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1899 (let ((cmp (mpc-compare-strings
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1900 (cdr (assq 'file song1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1901 (cdr (assq 'file song2)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1902 (and (integerp cmp) (< cmp 0)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1903 (incf totaltime (string-to-number (or (cdr (assq 'Time song)) "0")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1904 (mpc-format mpc-songs-format song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1905 (delete-char (- (skip-chars-backward " "))) ;Remove trailing space.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1906 (insert "\n")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1907 (put-text-property
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1908 (line-beginning-position 0) (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1909 'mpc-file (mpc-songs-hashcons (cdr (assq 'file song))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1910 (let ((pos (assq 'Pos song)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1911 (if pos
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1912 (put-text-property
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1913 (line-beginning-position 0) (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1914 'mpc-file-pos (string-to-number (cdr pos)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1915 ))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1916 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1917 (forward-line (car curline))
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1918 (if (or (search-forward (cdr curline) nil t)
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1919 (search-backward (cdr curline) nil t))
107541
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1920 (beginning-of-line)
d59e6301c2cd Add "union tags" in mpc.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 106815
diff changeset
1921 (goto-char (point-min)))
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1922 (set (make-local-variable 'mpc-songs-totaltime)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1923 (unless (zerop totaltime)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1924 (list " " (mpc-secs-to-time totaltime))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1925 ))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1926 (let ((mpc-songpointer-set-visible t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1927 (mpc-songpointer-refresh)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1928
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1929 (defun mpc-songs-search (string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1930 "Filter songs to those who include STRING in their metadata."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1931 (interactive "sSearch for: ")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1932 (setq mpc--song-search
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1933 (if (zerop (length string)) nil string))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1934 (let ((mpc--changed-selection t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1935 (while mpc--changed-selection
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1936 (setq mpc--changed-selection nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1937 (dolist (buf (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1938 (setq buf (cdr buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1939 (when (buffer-local-value 'mpc-tag buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1940 (with-current-buffer buf (mpc-reorder))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1941 (mpc-songs-refresh))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1942
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1943 (defun mpc-songs-kill-search ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1944 "Turn off the current search restriction."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1945 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1946 (mpc-songs-search nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1947
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1948 (defun mpc-songs-selection ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1949 "Return the list of songs currently selected."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1950 (let ((buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1951 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1952 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1953 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1954 (let ((files ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1955 (if mpc-select
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1956 (dolist (ol mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1957 (push (cons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1958 (get-text-property (overlay-start ol) 'mpc-file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1959 (get-text-property (overlay-start ol) 'mpc-file-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1960 files))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1961 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1962 (while (not (eobp))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1963 (push (cons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1964 (get-text-property (point) 'mpc-file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1965 (get-text-property (point) 'mpc-file-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1966 files)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1967 (forward-line 1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1968 (nreverse files)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1969
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1970 (defun mpc-songs-jump-to (song-file &optional posn)
106365
06698b91c779 * mpc.el (mpc-intersection, mpc-host, mpc-songs-playlist)
Juanma Barranquero <lekktu@gmail.com>
parents: 106354
diff changeset
1971 "Jump to song SONG-FILE; interactively, this is the song at point."
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1972 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1973 (let* ((event last-nonmenu-event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1974 (posn (event-end event)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1975 (with-selected-window (posn-window posn)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1976 (goto-char (posn-point posn))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1977 (list (get-text-property (point) 'mpc-file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1978 posn))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1979 (let* ((plbuf (mpc-proc-cmd "playlist"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1980 (re (concat "^\\([0-9]+\\):" (regexp-quote song-file) "$"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1981 (sn (with-current-buffer plbuf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1982 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1983 (when (re-search-forward re nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1984 (match-string 1)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1985 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1986 ((null sn) (error "This song is not in the playlist"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1987 ((null (with-current-buffer plbuf (re-search-forward re nil t)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1988 ;; song-file only appears once in the playlist: no ambiguity,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1989 ;; we're good to go!
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1990 (mpc-proc-cmd (list "play" sn)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1991 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1992 ;; The song appears multiple times in the playlist. If the current
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1993 ;; buffer holds not only the destination song but also the current
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1994 ;; song, then we will move in the playlist to the same relative
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1995 ;; position as in the buffer. Otherwise, we will simply choose the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1996 ;; song occurrence closest to the current song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1997 (with-selected-window (posn-window posn)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1998 (let* ((cur (and (markerp overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1999 (marker-position overlay-arrow-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2000 (dest (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2001 (goto-char (posn-point posn))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2002 (line-beginning-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2003 (lines (when cur (* (if (< cur dest) 1 -1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2004 (count-lines cur dest)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2005 (with-current-buffer plbuf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2006 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2007 ;; Start the search from the current song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2008 (forward-line (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2009 (or (cdr (assq 'song mpc-status)) "0")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2010 ;; If the current song is also displayed in the buffer,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2011 ;; then try to move to the same relative position.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2012 (if lines (forward-line lines))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2013 ;; Now search the closest occurrence.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2014 (let* ((next (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2015 (when (re-search-forward re nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2016 (cons (point) (match-string 1)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2017 (prev (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2018 (when (re-search-backward re nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2019 (cons (point) (match-string 1)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2020 (sn (cdr (if (and next prev)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2021 (if (< (- (car next) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2022 (- (point) (car prev)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2023 next prev)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2024 (or next prev)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2025 (assert sn)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2026 (mpc-proc-cmd (concat "play " sn))))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2027
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2028 (define-derived-mode mpc-songs-mode mpc-mode "MPC-song"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2029 (setq mpc-songs-format-description
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2030 (with-temp-buffer (mpc-format mpc-songs-format 'self) (buffer-string)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2031 (set (make-local-variable 'header-line-format)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2032 ;; '("MPC " mpc-volume " " mpc-current-song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2033 (list (propertize " " 'display '(space :align-to 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2034 ;; 'mpc-songs-format-description
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2035 '(:eval
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2036 (let ((hscroll (window-hscroll)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2037 (with-temp-buffer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2038 (mpc-format mpc-songs-format 'self hscroll)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2039 ;; That would be simpler than the hscroll handling in
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2040 ;; mpc-format, but currently move-to-column does not
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2041 ;; recognize :space display properties.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2042 ;; (move-to-column hscroll)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2043 ;; (delete-region (point-min) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2044 (buffer-string))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2045 (set (make-local-variable 'mode-line-format)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2046 '("%e" mode-line-frame-identification mode-line-buffer-identification
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2047 #(" " 0 3
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2048 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2049 mode-line-position
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2050 #(" " 0 2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2051 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2052 mpc-songs-totaltime
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2053 mpc-current-updating
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2054 #(" " 0 2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2055 (help-echo "mouse-1: Select (drag to resize)\nmouse-2: Make current window occupy the whole frame\nmouse-3: Remove current window from display"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2056 (mpc--song-search
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2057 (:propertize
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2058 ("Search=\"" mpc--song-search "\"")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2059 help-echo "mouse-2: kill this search"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2060 follow-link t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2061 mouse-face mode-line-highlight
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2062 keymap (keymap (mode-line keymap
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2063 (mouse-2 . mpc-songs-kill-search))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2064 (:propertize "NoSearch"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2065 help-echo "mouse-2: set a search restriction"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2066 follow-link t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2067 mouse-face mode-line-highlight
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2068 keymap (keymap (mode-line keymap (mouse-2 . mpc-songs-search)))))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2069
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2070 ;; (set (make-local-variable 'mode-line-process)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2071 ;; '("" ;; mpc-volume " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2072 ;; mpc-songs-totaltime
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2073 ;; mpc-current-updating))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2074 )
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2075
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2076 (defun mpc-songpointer-set (pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2077 (let* ((win (get-buffer-window (current-buffer) t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2078 (visible (when win
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2079 (or mpc-songpointer-set-visible
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2080 (and (markerp overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2081 (eq (marker-buffer overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2082 (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2083 (<= (window-start win) overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2084 (< overlay-arrow-position (window-end win)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2085 (unless (local-variable-p 'overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2086 (set (make-local-variable 'overlay-arrow-position) (make-marker)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2087 (move-marker overlay-arrow-position pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2088 ;; If the arrow was visible, try to keep it that way.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2089 (if (and visible pos
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2090 (or (> (window-start win) pos) (>= pos (window-end win t))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2091 (set-window-point win pos))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2092
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2093 (defun mpc-songpointer-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2094 (let ((buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2095 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2096 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2097 (let* ((pos (text-property-any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2098 (point-min) (point-max)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2099 'mpc-file (mpc-songs-hashcons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2100 (cdr (assq 'file mpc-status)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2101 (other (when pos
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2102 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2103 (goto-char pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2104 (text-property-any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2105 (line-beginning-position 2) (point-max)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2106 'mpc-file (mpc-songs-hashcons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2107 (cdr (assq 'file mpc-status))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2108 (if other
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2109 ;; The song appears multiple times in the buffer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2110 ;; We need to be careful to choose the right occurrence.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2111 (mpc-proc-cmd "playlist" 'mpc-songpointer-refresh-hairy)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2112 (mpc-songpointer-set pos)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2113
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2114 (defun mpc-songpointer-context (size plbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2115 (with-current-buffer plbuf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2116 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2117 (forward-line (string-to-number (or (cdr (assq 'song mpc-status)) "0")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2118 (let ((context-before '())
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2119 (context-after '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2120 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2121 (dotimes (i size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2122 (when (re-search-backward "^[0-9]+:\\(.*\\)" nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2123 (push (mpc-songs-hashcons (match-string 1)) context-before))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2124 ;; Skip the actual current song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2125 (forward-line 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2126 (dotimes (i size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2127 (when (re-search-forward "^[0-9]+:\\(.*\\)" nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2128 (push (mpc-songs-hashcons (match-string 1)) context-after)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2129 ;; If there isn't `size' context, then return nil.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2130 (unless (and (< (length context-before) size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2131 (< (length context-after) size))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2132 (cons (nreverse context-before) (nreverse context-after))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2133
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2134 (defun mpc-songpointer-score (context pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2135 (let ((count 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2136 (goto-char pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2137 (dolist (song (car context))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2138 (and (zerop (forward-line -1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2139 (eq (get-text-property (point) 'mpc-file) song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2140 (incf count)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2141 (goto-char pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2142 (dolist (song (cdr context))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2143 (and (zerop (forward-line 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2144 (eq (get-text-property (point) 'mpc-file) song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2145 (incf count)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2146 count))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2147
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2148 (defun mpc-songpointer-refresh-hairy ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2149 ;; Based on the complete playlist, we should figure out where in the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2150 ;; song buffer is the currently playing song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2151 (let ((plbuf (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2152 (buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2153 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2154 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2155 (let* ((context-size 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2156 (context '(() . ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2157 (pos (text-property-any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2158 (point-min) (point-max)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2159 'mpc-file (mpc-songs-hashcons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2160 (cdr (assq 'file mpc-status)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2161 (score 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2162 (other pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2163 (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2164 (setq other
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2165 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2166 (goto-char other)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2167 (text-property-any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2168 (line-beginning-position 2) (point-max)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2169 'mpc-file (mpc-songs-hashcons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2170 (cdr (assq 'file mpc-status))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2171 ;; There is an `other' contestant.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2172 (let ((other-score (mpc-songpointer-score context other)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2173 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2174 ;; `other' is worse: try the next one.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2175 ((< other-score score) nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2176 ;; `other' is better: remember it and then search further.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2177 ((> other-score score)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2178 (setq pos other)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2179 (setq score other-score))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2180 ;; Both are equal and increasing the context size won't help.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2181 ;; Arbitrarily choose one of the two and keep looking
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2182 ;; for a better match.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2183 ((< score context-size) nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2184 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2185 ;; Score is equal and increasing context might help: try it.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2186 (incf context-size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2187 (let ((new-context
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2188 (mpc-songpointer-context context-size plbuf)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2189 (if (null new-context)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2190 ;; There isn't more context: choose one arbitrarily
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2191 ;; and keep looking for a better match elsewhere.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2192 (decf context-size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2193 (setq context new-context)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2194 (setq score (mpc-songpointer-score context pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2195 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2196 (goto-char other)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2197 ;; Go back one line so we find `other' again.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2198 (setq other (line-beginning-position 0)))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2199 (mpc-songpointer-set pos))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2200
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2201 (defun mpc-current-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2202 ;; Maintain the current data.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2203 (mpc-status-buffer-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2204 (setq mpc-current-updating
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2205 (if (assq 'updating_db mpc-status) " Updating-DB"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2206 (ignore-errors
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2207 (setq mpc-current-song
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2208 (when (assq 'file mpc-status)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2209 (concat " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2210 (mpc-secs-to-time (cdr (assq 'time mpc-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2211 " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2212 (cdr (assq 'Title mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2213 " ("
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2214 (cdr (assq 'Artist mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2215 " / "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2216 (cdr (assq 'Album mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2217 ")"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2218 (force-mode-line-update t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2219
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2220 (defun mpc-songs-buf ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2221 (let ((buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2222 (if (buffer-live-p buf) buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2223 (with-current-buffer (setq buf (get-buffer-create "*MPC-Songs*"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2224 (mpc-proc-buffer (mpc-proc) 'songs buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2225 (mpc-songs-mode)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2226 buf))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2227
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2228 (defun mpc-update ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2229 "Tell MPD to refresh its database."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2230 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2231 (mpc-cmd-update))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2232
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2233 (defun mpc-quit ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2234 "Quit Music Player Daemon."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2235 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2236 (let* ((proc mpc-proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2237 (bufs (mapcar 'cdr (if proc (process-get proc 'buffers))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2238 (wins (mapcar (lambda (buf) (get-buffer-window buf 0)) bufs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2239 (song-buf (mpc-songs-buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2240 frames)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2241 ;; Collect all the frames where MPC buffers appear.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2242 (dolist (win wins)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2243 (when (and win (not (memq (window-frame win) frames)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2244 (push (window-frame win) frames)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2245 (if (and frames song-buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2246 (with-current-buffer song-buf mpc-previous-window-config))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2247 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2248 (select-frame (car frames))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2249 (set-window-configuration
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2250 (with-current-buffer song-buf mpc-previous-window-config)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2251 ;; Now delete the ones that show nothing else than MPC buffers.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2252 (dolist (frame frames)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2253 (let ((delete t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2254 (dolist (win (window-list frame))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2255 (unless (memq (window-buffer win) bufs) (setq delete nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2256 (if delete (ignore-errors (delete-frame frame))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2257 ;; Then kill the buffers.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2258 (mapc 'kill-buffer bufs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2259 (mpc-status-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2260 (if proc (delete-process proc))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2261
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2262 (defun mpc-stop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2263 "Stop playing the current queue of songs."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2264 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2265 (mpc-cmd-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2266 (mpc-cmd-clear)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2267 (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2268
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2269 (defun mpc-pause ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2270 "Pause playing."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2271 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2272 (mpc-cmd-pause "1"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2273
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2274 (defun mpc-resume ()
106365
06698b91c779 * mpc.el (mpc-intersection, mpc-host, mpc-songs-playlist)
Juanma Barranquero <lekktu@gmail.com>
parents: 106354
diff changeset
2275 "Resume playing."
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2276 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2277 (mpc-cmd-pause "0"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2278
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2279 (defun mpc-play ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2280 "Start playing whatever is selected."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2281 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2282 (if (member (cdr (assq 'state (mpc-cmd-status))) '("pause"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2283 (mpc-resume)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2284 ;; When playing the playlist ends, the playlist isn't cleared, but the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2285 ;; user probably doesn't want to re-listen to it before getting to
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2286 ;; listen to what he just selected.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2287 ;; (if (member (cdr (assq 'state (mpc-cmd-status))) '("stop"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2288 ;; (mpc-cmd-clear))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2289 ;; Actually, we don't use mpc-play to append to the playlist any more,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2290 ;; so we can just always empty the playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2291 (mpc-cmd-clear)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2292 (if (mpc-playlist-add)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2293 (if (member (cdr (assq 'state (mpc-cmd-status))) '("stop"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2294 (mpc-cmd-play))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2295 (error "Don't know what to play"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2296
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2297 (defun mpc-next ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2298 "Jump to the next song in the queue."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2299 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2300 (mpc-proc-cmd "next")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2301 (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2302
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2303 (defun mpc-prev ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2304 "Jump to the beginning of the current song, or to the previous song."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2305 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2306 (let ((time (cdr (assq 'time mpc-status))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2307 ;; Here we rely on the fact that string-to-number silently ignores
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2308 ;; everything after a non-digit char.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2309 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2310 ;; Go back to the beginning of current song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2311 ((and time (> (string-to-number time) 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2312 (mpc-proc-cmd (list "seekid" (cdr (assq 'songid mpc-status)) 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2313 ;; We're at the beginning of the first song of the playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2314 ;; Fetch the previous one from `mpc-queue-back'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2315 ;; ((and (zerop (string-to-number (cdr (assq 'song mpc-status))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2316 ;; mpc-queue-back)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2317 ;; ;; Because we use cmd-list rather than cmd-play, the queue is not
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2318 ;; ;; automatically updated.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2319 ;; (let ((prev (pop mpc-queue-back)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2320 ;; (push prev mpc-queue)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2321 ;; (mpc-proc-cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2322 ;; (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2323 ;; (list (list "add" prev)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2324 ;; (list "move" (cdr (assq 'playlistlength mpc-status)) "0")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2325 ;; "previous")))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2326 ;; We're at the beginning of a song, but not the first one.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2327 (t (mpc-proc-cmd "previous")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2328 (mpc-status-refresh)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2329
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2330 (defvar mpc-last-seek-time '(0 . 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2331
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2332 (defun mpc--faster (event speedup step)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2333 "Fast forward."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2334 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2335 (let ((repeat-delay (/ (abs (float step)) speedup)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2336 (if (not (memq 'down (event-modifiers event)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2337 (let* ((currenttime (float-time))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2338 (last-time (- currenttime (car mpc-last-seek-time))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2339 (if (< last-time (* 0.9 repeat-delay))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2340 nil ;; Trottle
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2341 (let* ((status (if (< last-time 1.0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2342 mpc-status (mpc-cmd-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2343 (songid (cdr (assq 'songid status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2344 (time (if songid
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2345 (if (< last-time 1.0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2346 (cdr mpc-last-seek-time)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2347 (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2348 (cdr (assq 'time status)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2349 (setq mpc-last-seek-time
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2350 (cons currenttime (setq time (+ time step))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2351 (mpc-proc-cmd (list "seekid" songid time)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2352 'mpc-status-refresh))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2353 (let ((status (mpc-cmd-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2354 (lexical-let* ((songid (cdr (assq 'songid status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2355 (step step)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2356 (time (if songid (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2357 (cdr (assq 'time status))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2358 (let ((timer (run-with-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2359 t repeat-delay
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2360 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2361 (mpc-proc-cmd (list "seekid" songid
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2362 (setq time (+ time step)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2363 'mpc-status-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2364 (while (mouse-movement-p
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2365 (event-basic-type (setq event (read-event)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2366 (cancel-timer timer)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2367
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2368 (defvar mpc--faster-toggle-timer nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2369 (defun mpc--faster-stop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2370 (when mpc--faster-toggle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2371 (cancel-timer mpc--faster-toggle-timer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2372 (setq mpc--faster-toggle-timer nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2373
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2374 (defun mpc--faster-toggle-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2375 (if (equal (cdr (assq 'state mpc-status)) "stop")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2376 (mpc--faster-stop)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2377
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2378 (defun mpc--songduration ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2379 (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2380 (let ((s (cdr (assq 'time mpc-status))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2381 (if (not (string-match ":" s))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2382 (error "Unexpected time format %S" s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2383 (substring s (match-end 0))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2384
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2385 (defvar mpc--faster-toggle-forward nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2386 (defvar mpc--faster-acceleration 0.5)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2387 (defun mpc--faster-toggle (speedup step)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2388 (setq speedup (float speedup))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2389 (if mpc--faster-toggle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2390 (mpc--faster-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2391 (mpc-status-refresh) (mpc-proc-sync)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2392 (lexical-let* ((speedup speedup)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2393 songid ;The ID of the currently ffwd/rewinding song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2394 songnb ;The position of that song in the playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2395 songduration ;The duration of that song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2396 songtime ;The time of the song last time we ran.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2397 oldtime ;The timeoftheday last time we ran.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2398 prevsongid) ;The song we're in the process leaving.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2399 (let ((fun
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2400 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2401 (let ((newsongid (cdr (assq 'songid mpc-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2402 (newsongnb (cdr (assq 'song mpc-status))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2403
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2404 (if (and (equal prevsongid newsongid)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2405 (not (equal prevsongid songid)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2406 ;; We left prevsongid and came back to it. Pretend it
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2407 ;; didn't happen.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2408 (setq newsongid songid))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2409
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2410 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2411 ((null newsongid) (mpc--faster-stop))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2412 ((not (equal songid newsongid))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2413 ;; We jumped to another song: reset.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2414 (setq songid newsongid)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2415 (setq songtime (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2416 (cdr (assq 'time mpc-status))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2417 (setq songduration (mpc--songduration))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2418 (setq oldtime (float-time)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2419 ((and (>= songtime songduration) mpc--faster-toggle-forward)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2420 ;; Skip to the beginning of the next song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2421 (if (not (equal (cdr (assq 'state mpc-status)) "play"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2422 (mpc-proc-cmd "next" 'mpc-status-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2423 ;; If we're playing, this is done automatically, so we
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2424 ;; don't need to do anything, or rather we *shouldn't*
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2425 ;; do anything otherwise there's a race condition where
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2426 ;; we could skip straight to the next next song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2427 nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2428 ((and (<= songtime 0) (not mpc--faster-toggle-forward))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2429 ;; Skip to the end of the previous song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2430 (setq prevsongid songid)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2431 (mpc-proc-cmd "previous"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2432 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2433 (mpc-status-refresh
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2434 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2435 (setq songid (cdr (assq 'songid mpc-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2436 (setq songtime (setq songduration (mpc--songduration)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2437 (setq oldtime (float-time))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2438 (mpc-proc-cmd (list "seekid" songid songtime)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2439 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2440 (setq speedup (+ speedup mpc--faster-acceleration))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2441 (let ((newstep
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2442 (truncate (* speedup (- (float-time) oldtime)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2443 (if (<= newstep 1) (setq newstep 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2444 (setq oldtime (+ oldtime (/ newstep speedup)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2445 (if (not mpc--faster-toggle-forward)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2446 (setq newstep (- newstep)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2447 (setq songtime (min songduration (+ songtime newstep)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2448 (unless (>= songtime songduration)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2449 (condition-case nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2450 (mpc-proc-cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2451 (list "seekid" songid songtime)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2452 'mpc-status-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2453 (mpc-proc-error (mpc-status-refresh)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2454 (setq songnb newsongnb)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2455 (setq mpc--faster-toggle-forward (> step 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2456 (funcall fun) ;Initialize values.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2457 (setq mpc--faster-toggle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2458 (run-with-timer t 0.3 fun))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2459
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2460
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2461
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2462 (defvar mpc-faster-speedup 8)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2463
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2464 (defun mpc-ffwd (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2465 "Fast forward."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2466 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2467 ;; (mpc--faster event 4.0 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2468 (mpc--faster-toggle mpc-faster-speedup 1))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2469
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2470 (defun mpc-rewind (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2471 "Fast rewind."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2472 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2473 ;; (mpc--faster event 4.0 -1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2474 (mpc--faster-toggle mpc-faster-speedup -1))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2475
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2476
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2477 (defun mpc-play-at-point (&optional event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2478 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2479 (mpc-select event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2480 (mpc-play))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2481
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2482 ;; (defun mpc-play-tagval ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2483 ;; "Play all the songs of the tag at point."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2484 ;; (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2485 ;; (let* ((val (buffer-substring (line-beginning-position) (line-end-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2486 ;; (songs (mapcar 'cdar
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2487 ;; (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2488 ;; (mpc-proc-cmd (list "find" mpc-tag val))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2489 ;; (mpc-cmd-add songs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2490 ;; (if (member (cdr (assq 'state (mpc-cmd-status))) '("stop"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2491 ;; (mpc-cmd-play))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2492
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2493 ;;; Drag'n'drop support ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2494 ;; Todo:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2495 ;; the main thing to do here, is to provide visual feedback during the drag:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2496 ;; - change the mouse-cursor.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2497 ;; - highlight/select the source and the current destination.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2498
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2499 (defun mpc-drag-n-drop (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2500 "DWIM for a drag EVENT."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2501 (interactive "e")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2502 (let* ((start (event-start event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2503 (end (event-end event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2504 (start-buf (window-buffer (posn-window start)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2505 (end-buf (window-buffer (posn-window end)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2506 (songs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2507 (with-current-buffer start-buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2508 (goto-char (posn-point start))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2509 (if (get-text-property (point) 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2510 ;; FIXME: actually we should only consider the constraints
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2511 ;; corresponding to the selection in this particular buffer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2512 (mpc-songs-selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2513 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2514 ((and (derived-mode-p 'mpc-songs-mode)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2515 (get-text-property (point) 'mpc-file))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2516 (list (cons (get-text-property (point) 'mpc-file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2517 (get-text-property (point) 'mpc-file-pos))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2518 ((and mpc-tag (not (mpc-tagbrowser-all-p)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2519 (mapcar (lambda (song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2520 (list (cdr (assq 'file song))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2521 (mpc-cmd-find
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2522 mpc-tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2523 (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2524 (line-end-position)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2525 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2526 (error "Unsupported starting position for drag'n'drop gesture")))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2527 (with-current-buffer end-buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2528 (goto-char (posn-point end))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2529 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2530 ((eq mpc-tag 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2531 ;; Adding elements to a named playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2532 (let ((playlist (if (or (mpc-tagbrowser-all-p)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2533 (and (bolp) (eolp)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2534 (error "Not a playlist")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2535 (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2536 (line-end-position)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2537 (mpc-cmd-add (mapcar 'car songs) playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2538 (message "Added %d songs to %s" (length songs) playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2539 (if (member playlist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2540 (cdr (assq 'Playlist (mpc-constraints-get-current))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2541 (mpc-songs-refresh))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2542 ((derived-mode-p 'mpc-songs-mode)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2543 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2544 ((null mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2545 (error "The songs shown do not belong to a playlist"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2546 ((eq start-buf end-buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2547 ;; Moving songs within the shown playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2548 (let ((dest-pos (get-text-property (point) 'mpc-file-pos)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2549 (mpc-cmd-move (mapcar 'cdr songs) dest-pos mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2550 (message "Moved %d songs" (length songs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2551 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2552 ;; Adding songs to the shown playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2553 (let ((dest-pos (get-text-property (point) 'mpc-file-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2554 (pl (if (stringp mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2555 (mpc-cmd-find 'Playlist mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2556 (mpc-proc-cmd-to-alist "playlist"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2557 ;; MPD's protocol does not let us add songs at a particular
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2558 ;; position in a playlist, so we first have to add them to the
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2559 ;; end, and then move them to their final destination.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2560 (mpc-cmd-add (mapcar 'car songs) mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2561 (mpc-cmd-move (let ((poss '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2562 (dotimes (i (length songs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2563 (push (+ i (length pl)) poss))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2564 (nreverse poss)) dest-pos mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2565 (message "Added %d songs" (length songs)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2566 (mpc-songs-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2567 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2568 (error "Unsupported drag'n'drop gesture"))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2569
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2570 ;;; Toplevel ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2571
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2572 (defcustom mpc-frame-alist '((name . "MPC") (tool-bar-lines . 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2573 (font . "Sans"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2574 "Alist of frame parameters for the MPC frame."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2575 :type 'alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2576
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2577 ;;;###autoload
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2578 (defun mpc ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2579 "Main entry point for MPC."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2580 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2581 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2582 (if current-prefix-arg
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2583 (setq mpc-host (read-string "MPD host and port: " nil nil mpc-host)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2584 nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2585 (let* ((song-buf (mpc-songs-buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2586 (song-win (get-buffer-window song-buf 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2587 (if song-win
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2588 (select-window song-win)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2589 (if (or (window-dedicated-p (selected-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2590 (window-minibuffer-p))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2591 (ignore-errors (select-frame (make-frame mpc-frame-alist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2592 (with-current-buffer song-buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2593 (set (make-local-variable 'mpc-previous-window-config)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2594 (current-window-configuration))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2595 (let* ((win1 (selected-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2596 (win2 (split-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2597 (tags mpc-browser-tags))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2598 (unless tags (error "Need at least one entry in `mpc-browser-tags'"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2599 (set-window-buffer win2 song-buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2600 (set-window-dedicated-p win2 'soft)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2601 (mpc-status-buffer-show)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2602 (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2603 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2604 (set-window-buffer win1 (mpc-tagbrowser-buf (pop tags)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2605 (set-window-dedicated-p win1 'soft)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2606 tags)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2607 (setq win1 (split-window win1 nil 'horiz)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2608 (balance-windows-area))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2609 (mpc-songs-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2610 (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2611
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2612 (provide 'mpc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2613
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2614 ;; arch-tag: 4794b2f5-59e6-4f26-b695-650b3e002f37
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2615 ;;; mpc.el ends here