annotate lisp/mpc.el @ 107055:db607be637e8

update tags
author convert-repo
date Sat, 30 Jan 2010 00:00:58 +0000
parents 1d1d5d9bd884
children d59e6301c2cd 376148b31b5e
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 ;;; Backward compatibility.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 ;; This code is meant for Emacs-CVS, so to get it to run on anything else,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
99 ;; we need to define some more things.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
100
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 (unless (fboundp 'tool-bar-local-item)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102 (defun tool-bar-local-item (icon def key map &rest props)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103 (define-key-after map (vector key)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
104 `(menu-item ,(symbol-name key) ,def
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
105 :image ,(find-image
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
106 `((:type xpm :file ,(concat icon ".xpm"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
107 ,@props))))
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 (unless (fboundp 'process-put)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
110 (defconst mpc-process-hash (make-hash-table :weakness 'key))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
111 (defun process-put (proc prop val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
112 (let ((sym (gethash proc mpc-process-hash)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
113 (unless sym
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
114 (setq sym (puthash proc (make-symbol "mpc-proc-sym") mpc-process-hash)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
115 (put sym prop val)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
116 (defun process-get (proc prop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117 (let ((sym (gethash proc mpc-process-hash)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 (when sym (get sym prop))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 (defun process-plist (proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
120 (let ((sym (gethash proc mpc-process-hash)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121 (when sym (symbol-plist sym)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 (unless (fboundp 'with-local-quit)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
123 (defmacro with-local-quit (&rest body)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
124 `(condition-case nil (let ((inhibit-quit nil)) ,@body)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
125 (quit (setq quit-flag t) nil))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
126 (unless (fboundp 'balance-windows-area)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 (defalias 'balance-windows-area 'balance-windows))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
128 (unless (fboundp 'posn-object) (defalias 'posn-object 'ignore))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
129 (unless (fboundp 'buffer-local-value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
130 (defun buffer-local-value (var buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
131 (with-current-buffer buf (symbol-value var))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
132
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
133
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
134 ;;; Main code starts here.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
135
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
136 (defgroup mpc ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
137 "A Client for the Music Player Daemon."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
138 :prefix "mpc-"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
139 :group 'multimedia
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
140 :group 'applications)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
141
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
142 (defcustom mpc-browser-tags '(Genre Artist Album Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
143 "Tags for which a browser buffer should be created by default."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
144 :type '(repeat string))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
145
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
146 ;;; Misc utils ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
147
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
148 (defun mpc-assq-all (key alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
149 (let ((res ()) val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
150 (dolist (elem alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
151 (if (and (eq (car elem) key)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
152 (not (member (setq val (cdr elem)) res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
153 (push val res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
154 (nreverse res)))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
155
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
156 (defun mpc-union (&rest lists)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
157 (let ((res (nreverse (pop lists))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
158 (dolist (list lists)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
159 (let ((seen res)) ;Don't remove duplicates within each list.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
160 (dolist (elem list)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
161 (unless (member elem seen) (push elem res)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
162 (nreverse res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164 (defun mpc-intersection (l1 l2 &optional selectfun)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 "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
166 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
167 they are passed through SELECTFUN before comparison."
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
168 (let ((res ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 (if selectfun (setq l2 (mapcar selectfun l2)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
170 (dolist (elem l1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 (when (member (if selectfun (funcall selectfun elem) elem) l2)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 (push elem res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 (nreverse res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 (defun mpc-event-set-point (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
176 (condition-case nil (posn-set-point (event-end event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 (error (condition-case nil (mouse-set-point event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 (error nil)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
180 (defun mpc-compare-strings (str1 str2 &optional ignore-case)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
181 "Compare strings STR1 and STR2.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182 Contrary to `compare-strings', this tries to get numbers sorted
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
183 numerically rather than lexicographically."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
184 (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
185 (if (not (integerp res)) res
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
186 (let ((index (1- (abs res))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187 (if (or (>= index (length str1)) (>= index (length str2)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
188 res
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
189 (let ((digit1 (memq (aref str1 index)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
190 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
191 (digit2 (memq (aref str2 index)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
192 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
193 (if digit1
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
194 (if digit2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
195 (let ((num1 (progn (string-match "[0-9]+" str1 index)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
196 (match-string 0 str1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 (num2 (progn (string-match "[0-9]+" str2 index)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
198 (match-string 0 str2))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
199 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
200 ;; Here we presume that leading zeroes are only used
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201 ;; for same-length numbers. So we'll incorrectly
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
202 ;; consider that "000" comes after "01", but I don't
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
203 ;; think it matters.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
204 ((< (length num1) (length num2)) (- (abs res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
205 ((> (length num1) (length num2)) (abs res))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
206 ((< (string-to-number num1) (string-to-number num2))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
207 (- (abs res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
208 (t (abs res))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
209 ;; "1a" comes before "10", but "0" comes before "a".
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
210 (if (and (not (zerop index))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
211 (memq (aref str1 (1- index))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
212 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
213 (abs res)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
214 (- (abs res))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
215 (if digit2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
216 ;; "1a" comes before "10", but "0" comes before "a".
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
217 (if (and (not (zerop index))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
218 (memq (aref str1 (1- index))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
219 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
220 (- (abs res))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
221 (abs res))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
222 res))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
223
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
224 (defun mpc-string-prefix-p (str1 str2)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
225 ;; FIXME: copied from pcvs-util.el.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
226 "Tell whether STR1 is a prefix of STR2."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
227 (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
228
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
229 ;; 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
230 ;; 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
231 ;; 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
232 ;; 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
233 ;; constant polling often prevents disconnection.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
234 (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
235 (defvar mpc-tag nil) (make-variable-buffer-local 'mpc-tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
236
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237 ;;; Support for the actual connection and MPD command execution ;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
238
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
239 (defcustom mpc-host
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
240 (concat (or (getenv "MPD_HOST") "localhost")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
241 (if (getenv "MPD_PORT") (concat ":" (getenv "MPD_PORT"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
242 "Host (and port) where the Music Player Daemon is running.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
243 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
244 and HOST defaults to localhost."
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
245 :type 'string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
246
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
247 (defvar mpc-proc nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
248
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
249 (defconst mpc--proc-end-re "^\\(?:OK\\(?: MPD .*\\)?\\|ACK \\(.*\\)\\)\n")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
250
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
251 (put 'mpc-proc-error 'error-conditions '(mpc-proc-error error))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
252 (put 'mpc-proc-error 'error-message "MPD error")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
253
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
254 (defun mpc--debug (format &rest args)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
255 (if (get-buffer "*MPC-debug*")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
256 (with-current-buffer "*MPC-debug*"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
257 (goto-char (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
258 (insert-before-markers ;So it scrolls.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
259 (replace-regexp-in-string "\n" "\n "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
260 (apply 'format format args))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
261 "\n"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
262
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
263 (defun mpc--proc-filter (proc string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
264 (mpc--debug "Receive \"%s\"" string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
265 (with-current-buffer (process-buffer proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
266 (if (process-get proc 'ready)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
267 (if nil ;; (string-match "\\`\\(OK\n\\)+\\'" string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
268 ;; 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
269 ;; so I'll just ignore them for now.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
270 nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
271 (delete-process proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
272 (set-process-buffer proc nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
273 (pop-to-buffer (clone-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
274 (error "MPD output while idle!?"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
275 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
276 (let ((start (or (marker-position (process-mark proc)) (point-min))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
277 (goto-char start)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
278 (insert string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
279 (move-marker (process-mark proc) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
280 (beginning-of-line)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
281 (when (and (< start (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
282 (re-search-backward mpc--proc-end-re start t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
283 (process-put proc 'ready t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
284 (unless (eq (match-end 0) (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
285 (error "Unexpected trailing text"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
286 (let ((error (match-string 1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
287 (delete-region (point) (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288 (let ((callback (process-get proc 'callback)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
289 (process-put proc 'callback nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
290 (if error (signal 'mpc-proc-error error))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
291 (funcall callback)))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
292
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
293 (defun mpc--proc-connect (host)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
294 (mpc--debug "Connecting to %s..." host)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
295 (with-current-buffer (get-buffer-create (format " *mpc-%s*" host))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
296 ;; (pop-to-buffer (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
297 (let (proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
298 (while (and (setq proc (get-buffer-process (current-buffer)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
299 (progn ;; (debug)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300 (delete-process proc)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
301 (erase-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
302 (let ((port 6600))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
303 (when (string-match ":[^.]+\\'" host)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
304 (setq port (substring host (1+ (match-beginning 0))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
305 (setq host (substring host 0 (match-beginning 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
306 (unless (string-match "[^[:digit:]]" port)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
307 (setq port (string-to-number port))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
308 (let* ((coding-system-for-read 'utf-8-unix)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
309 (coding-system-for-write 'utf-8-unix)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 (proc (open-network-stream "MPC" (current-buffer) host port)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
311 (when (processp mpc-proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
312 ;; Inherit the properties of the previous connection.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
313 (let ((plist (process-plist mpc-proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
314 (while plist (process-put proc (pop plist) (pop plist)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
315 (mpc-proc-buffer proc 'mpd-commands (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
316 (process-put proc 'callback 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
317 (process-put proc 'ready nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
318 (clrhash mpc--find-memoize)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
319 (set-process-filter proc 'mpc--proc-filter)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
320 (set-process-sentinel proc 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321 (set-process-query-on-exit-flag proc nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
322 ;; This may be called within a process filter ;-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
323 (with-local-quit (mpc-proc-sync proc))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
324 proc))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
325
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
326 (defun mpc--proc-quote-string (s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
327 (if (numberp s) (number-to-string s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328 (setq s (replace-regexp-in-string "[\"\\]" "\\\\\\&" s))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
329 (if (string-match " " s) (concat "\"" s "\"") s)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
330
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
331 (defconst mpc--proc-alist-to-alists-starters '(file directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
332
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333 (defun mpc--proc-alist-to-alists (alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
334 (assert (or (null alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335 (memq (caar alist) mpc--proc-alist-to-alists-starters)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
336 (let ((starter (caar alist))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
337 (alists ())
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
338 tmp)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
339 (dolist (pair alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
340 (when (eq (car pair) starter)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
341 (if tmp (push (nreverse tmp) alists))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342 (setq tmp ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
343 (push pair tmp))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
344 (if tmp (push (nreverse tmp) alists))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
345 (nreverse alists)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
346
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
347 (defun mpc-proc ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
348 (or (and mpc-proc
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
349 (buffer-live-p (process-buffer mpc-proc))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
350 (not (memq (process-status mpc-proc) '(closed)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
351 mpc-proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
352 (setq mpc-proc (mpc--proc-connect mpc-host))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
353
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
354 (defun mpc-proc-sync (&optional proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
355 "Wait for MPC process until it is idle again.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
356 Return the buffer in which the process is/was running."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
357 (unless proc (setq proc (mpc-proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
358 (unwind-protect
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
359 (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
360 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
361 (while (and (not (process-get proc 'ready))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
362 (accept-process-output proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
363 (if (process-get proc 'ready) (process-buffer proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
364 ;; (delete-process proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
365 (error "No response from MPD")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
366 (error (message "MPC: %s" err) (signal (car err) (cdr err))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
367 (unless (process-get proc 'ready)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
368 ;; (debug)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
369 (message "Killing hung process")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
370 (delete-process proc))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
371
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
372 (defun mpc-proc-cmd (cmd &optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
373 "Send command CMD to the MPD server.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
374 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
375 otherwise return immediately and call CALLBACK with no argument
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
376 when the command terminates.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
377 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
378 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
379 (let ((proc (mpc-proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
380 (if (and callback (not (process-get proc 'ready)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
381 (lexical-let ((old (process-get proc 'callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
382 (callback callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
383 (cmd cmd))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
384 (process-put proc 'callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
385 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
386 (funcall old)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
387 (mpc-proc-cmd cmd callback))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
388 ;; Wait for any pending async command to terminate.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
389 (mpc-proc-sync proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
390 (process-put proc 'ready nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
391 (with-current-buffer (process-buffer proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
392 (erase-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393 (mpc--debug "Send \"%s\"" cmd)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
394 (process-send-string
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
395 proc (concat (if (stringp cmd) cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
396 (mapconcat 'mpc--proc-quote-string cmd " "))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
397 "\n")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
398 (if callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
399 (lexical-let ((buf (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
400 (callback callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
401 (process-put proc 'callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
402 callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
403 ;; (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
404 ;; (funcall callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
405 ;; (prog1 (current-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
406 ;; (set-buffer buf))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
407 ))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
408 ;; If `callback' is nil, we're executing synchronously.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
409 (process-put proc 'callback 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
410 ;; This returns the process's buffer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
411 (mpc-proc-sync proc)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
412
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
413 ;; This function doesn't exist in Emacs-21.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
414 ;; (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
415 (defun mpc-proc-cmd-list (cmds)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
416 (concat "command_list_begin\n"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
417 (mapconcat (lambda (cmd)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
418 (if (stringp cmd) cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
419 (mapconcat 'mpc--proc-quote-string cmd " ")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
420 cmds
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
421 "\n")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
422 "\ncommand_list_end"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
423
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
424 (defun mpc-proc-cmd-list-ok ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
425 ;; 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
426 ;; then sometimes get "trailing" text after "OK\n".
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
427 (error "Not implemented yet"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
428
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
429 (defun mpc-proc-buf-to-alist (&optional buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
430 (with-current-buffer (or buf (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
431 (let ((res ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
432 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
433 (while (re-search-forward "^\\([^:]+\\): \\(.*\\)\n" nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
434 (push (cons (intern (match-string 1)) (match-string 2)) res))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
435 (nreverse res))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
436
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
437 (defun mpc-proc-buf-to-alists (buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
438 (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
439
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440 (defun mpc-proc-cmd-to-alist (cmd &optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441 (if callback
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
442 (lexical-let ((buf (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
443 (callback callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
444 (mpc-proc-cmd cmd (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
445 (funcall callback (prog1 (mpc-proc-buf-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
446 (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
447 (set-buffer buf))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
448 ;; (lexical-let ((res nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
449 ;; (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
450 ;; (mpc-proc-sync)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
451 ;; res)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
452 (mpc-proc-buf-to-alist (mpc-proc-cmd cmd))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
453
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
454 (defun mpc-proc-tag-string-to-sym (tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
455 (intern (capitalize tag)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
456
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
457 (defun mpc-proc-buffer (proc use &optional buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
458 (let* ((bufs (process-get proc 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
459 (buf (cdr (assoc use bufs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
460 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
461 ((and buffer (buffer-live-p buf) (not (eq buffer buf)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
462 (error "Duplicate MPC buffer for %s" use))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
463 (buffer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
464 (if buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
465 (setcdr (assoc use bufs) buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
466 (process-put proc 'buffers (cons (cons use buffer) bufs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
467 (t buf))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
468
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
469 ;;; Support for regularly updated current status information ;;;;;;;;;;;;;;;
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 ;; Exported elements:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
472 ;; `mpc-status' holds the uptodate data.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
473 ;; `mpc-status-callbacks' holds the registered callback functions.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
474 ;; `mpc-status-refresh' forces a refresh of the data.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
475 ;; `mpc-status-stop' stops the automatic updating.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
476
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
477 (defvar mpc-status nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
478 (defvar mpc-status-callbacks
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
479 '((state . mpc--status-timers-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
480 ;; (song . mpc--queue-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
481 ;; (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
482 (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
483 (volume . mpc-volume-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
484 (file . mpc-songpointer-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
485 ;; 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
486 ;; if the same song appears multiple times in a row.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
487 (song . mpc-songpointer-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
488 (updating_db . mpc-updated-db)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
489 (updating_db . mpc--status-timers-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
490 (t . mpc-current-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
491 "Alist associating properties to the functions that care about them.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
492 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
493 to call FUN for any change whatsoever.")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
494
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
495 (defun mpc--status-callback ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
496 (let ((old-status mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
497 ;; Update the alist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
498 (setq mpc-status (mpc-proc-buf-to-alist))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
499 (assert mpc-status)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
500 (unless (equal old-status mpc-status)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
501 ;; Run the relevant refresher functions.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
502 (dolist (pair mpc-status-callbacks)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
503 (when (or (eq t (car pair))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
504 (not (equal (cdr (assq (car pair) old-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
505 (cdr (assq (car pair) mpc-status)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
506 (funcall (cdr pair)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
507
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
508 (defvar mpc--status-timer nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
509 (defun mpc--status-timer-start ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
510 (add-hook 'pre-command-hook 'mpc--status-timer-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
511 (unless mpc--status-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
512 (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
513 (defun mpc--status-timer-stop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
514 (when mpc--status-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
515 (cancel-timer mpc--status-timer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
516 (setq mpc--status-timer nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
517 (defun mpc--status-timer-run ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
518 (when (process-get (mpc-proc) 'ready)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
519 (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
520 (with-local-quit (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
521 (error (message "MPC: %s" err)))))
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 (defvar mpc--status-idle-timer nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
524 (defun mpc--status-idle-timer-start ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
525 (when mpc--status-idle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
526 ;; 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
527 (cancel-timer mpc--status-idle-timer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
528 (setq mpc--status-idle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
529 (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
530 ;; 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
531 ;; 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
532 ;; 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
533 ;; time we idle :-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
534 ;; To work around that, we immediately start the repeat timer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
535 (mpc--status-timer-start))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
536 (defun mpc--status-idle-timer-stop (&optional really)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
537 (when mpc--status-idle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
538 ;; 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
539 (cancel-timer mpc--status-idle-timer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
540 (setq mpc--status-idle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
541 (unless really
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
542 ;; 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
543 ;; 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
544 (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
545 (defun mpc--status-idle-timer-run ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
546 (when (process-get (mpc-proc) 'ready)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
547 (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
548 (with-local-quit (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
549 (error (message "MPC: %s" err))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
550 (mpc--status-timer-start))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
552 (defun mpc--status-timers-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
553 "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
554 (if (or (member (cdr (assq 'state mpc-status)) '("play"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555 (cdr (assq 'updating_db mpc-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
556 (mpc--status-idle-timer-start)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
557 (mpc--status-idle-timer-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
558 (mpc--status-timer-stop)))
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-status-refresh (&optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
561 "Refresh `mpc-status'."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
562 (lexical-let ((cb callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
563 (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
564 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
565 (mpc--status-callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
566 (if cb (funcall cb))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
567
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
568 (defun mpc-status-stop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
569 "Stop the autorefresh of `mpc-status'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
570 This is normally used only when quitting MPC.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
571 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
572 (setq mpc-status nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
573 (mpc--status-idle-timer-stop 'really)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
574 (mpc--status-timer-stop))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
575
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
576 ;;; A thin layer above the raw protocol commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
577
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
578 ;; (defvar mpc-queue nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
579 ;; (defvar mpc-queue-back nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
580
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
581 ;; (defun mpc--queue-head ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
582 ;; (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
583 ;; (defun mpc--queue-pop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
584 ;; (when mpc-queue ;Can be nil if out of sync.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
585 ;; (let ((song (car mpc-queue)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
586 ;; (assert song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
587 ;; (push (if (and (consp song) (cddr song))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
588 ;; ;; The queue's first element is itself a list of
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
589 ;; ;; songs, where the first element isn't itself a song
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
590 ;; ;; but a description of the list.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
591 ;; (prog1 (cadr song) (setcdr song (cddr song)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
592 ;; (prog1 (if (consp song) (cadr song) song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
593 ;; (setq mpc-queue (cdr mpc-queue))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
594 ;; mpc-queue-back)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
595 ;; (assert (stringp (car mpc-queue-back))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
596
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
597 ;; (defun mpc--queue-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
598 ;; ;; Maintain the queue.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
599 ;; (mpc--debug "mpc--queue-refresh")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
600 ;; (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
601 ;; (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
602 ;; ((null pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
603 ;; (mpc-cmd-clear 'ignore))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
604 ;; ((or (not (member pos '("0" nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
605 ;; ;; 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
606 ;; ;; 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
607 ;; ;; playlist like that and/or manually stopped the playback, but
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
608 ;; ;; 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
609 ;; ;; the song. So remove it.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
610 ;; (and (equal (assq 'state mpc-status) "stop")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
611 ;; (equal (assq 'playlistlength mpc-status) "1")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
612 ;; (setq pos "1")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
613 ;; ;; 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
614 ;; ;; more, so update the queue.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
615 ;; (dotimes (i (string-to-number pos)) (mpc--queue-pop))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
616 ;; (mpc-proc-cmd (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
617 ;; (make-list (string-to-number pos) "delete 0"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
618 ;; 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
619 ;; (if (not (equal (cdr (assq 'file mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
620 ;; (mpc--queue-head)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
621 ;; (message "MPC's queue is out of sync"))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
622
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
623 (defun mpc-cmd-find (tag value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
624 "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
625 The songs are returned as alists."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
626 (or (gethash (cons tag value) mpc--find-memoize)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
627 (puthash (cons tag value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
628 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
629 ((eq tag 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
630 ;; Special case for pseudo-tag playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
631 (let ((l (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
632 (mpc-proc-cmd (list "listplaylistinfo" value))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
633 (i 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
634 (mapcar (lambda (s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
635 (prog1 (cons (cons 'Pos (number-to-string i)) s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
636 (incf i)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
637 l)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
638 ((eq tag 'Search)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
639 (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
640 (mpc-proc-cmd (list "search" "any" value))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
641 ((eq tag 'Directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
642 (let ((pairs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
643 (mpc-proc-buf-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
644 (mpc-proc-cmd (list "listallinfo" value)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
645 (mpc--proc-alist-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
646 ;; Strip away the `directory' entries.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
647 (delq nil (mapcar (lambda (pair)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
648 (if (eq (car pair) 'directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
649 nil pair))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
650 pairs)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
651 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
652 (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
653 (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
654 (mpc-proc-cmd (list "find" (symbol-name tag) value)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
655 (mpc-proc-error
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
656 ;; 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
657 ;; about not having the relevant table. FIXME: check
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
658 ;; the kind of error.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
659 (error "Unknown tag %s" tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
660 (let ((res ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
661 (setq value (cons tag value))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
662 (dolist (song (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
663 (mpc-proc-cmd "listallinfo")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
664 (if (member value song) (push song res)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
665 res)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
666 mpc--find-memoize)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
667
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
668 (defun mpc-cmd-list (tag &optional other-tag value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
669 ;; 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
670 ;; 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
671 ;; That might be more efficient in some cases.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
672 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
673 ((eq tag 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
674 (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
675 (when other-tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
676 (dolist (pl (prog1 pls (setq pls nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
677 (let ((plsongs (mpc-cmd-find 'Playlist pl)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
678 (if (not (member other-tag '(Playlist Search Directory)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
679 (when (member (cons other-tag value)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
680 (apply 'append plsongs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
681 (push pl pls))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
682 ;; Problem N°2: we compute the intersection whereas all
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
683 ;; 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
684 ;; speed this up significantly.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
685 ;; We only compare file names, because the full song-entries
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
686 ;; are slightly different (the ones in plsongs include
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
687 ;; 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
688 ;; good enough because this is only used with "search", which
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
689 ;; doesn't pay attention to playlists and URLs anyway.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
690 (let* ((osongs (mpc-cmd-find other-tag value))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
691 (ofiles (mpc-assq-all 'file (apply 'append osongs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
692 (plfiles (mpc-assq-all 'file (apply 'append plsongs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
693 (when (mpc-intersection plfiles ofiles)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
694 (push pl pls)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
695 pls))
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 ((eq tag 'Directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
698 (if (null other-tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
699 (apply 'nconc
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
700 (mpc-assq-all 'directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
701 (mpc-proc-buf-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
702 (mpc-proc-cmd "lsinfo")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
703 (mapcar (lambda (dir)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
704 (let ((shortdir
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
705 (if (get-text-property 0 'display dir)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
706 (concat " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
707 (get-text-property 0 'display dir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
708 " ↪ "))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
709 (subdirs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
710 (mpc-assq-all 'directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
711 (mpc-proc-buf-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
712 (mpc-proc-cmd (list "lsinfo" dir))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
713 (dolist (subdir subdirs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
714 (put-text-property 0 (1+ (length dir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
715 'display shortdir
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
716 subdir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
717 subdirs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
718 (process-get (mpc-proc) 'Directory)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
719 ;; 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
720 ;; list of other-tag's songs.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
721 (let* ((other-songs (mpc-cmd-find other-tag value))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
722 (files (mpc-assq-all 'file (apply 'append other-songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
723 (dirs '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
724 (dolist (file files)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
725 (let ((dir (file-name-directory file)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
726 (if (and dir (setq dir (directory-file-name dir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
727 (not (equal dir (car dirs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
728 (push dir dirs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
729 ;; Dirs might have duplicates still.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
730 (setq dirs (delete-dups dirs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
731 (let ((newdirs dirs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 (while newdirs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
733 (let ((dir (file-name-directory (pop newdirs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
734 (when (and dir (setq dir (directory-file-name dir))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
735 (not (member dir dirs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
736 (push dir newdirs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
737 (push dir dirs)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
738 dirs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
739
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
740 ;; 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
741 ;; 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
742 ;; 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
743 ;; useful that would be tho.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
744 ((eq tag 'Search) (error "Not supported"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
745
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
746 ((null other-tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
747 (condition-case nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
748 (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
749 (mpc-proc-error
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
750 ;; 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
751 ;; having the relevant table.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
752 ;; FIXME: check the kind of error.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
753 (error "MPD does not know this tag %s" tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
754 (mpc-assq-all tag (mpc-proc-cmd-to-alist "listallinfo")))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
755 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
756 (condition-case nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 (if (member other-tag '(Search Playlist Directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
758 (signal 'mpc-proc-error "Not implemented")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
759 (mapcar 'cdr
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
760 (mpc-proc-cmd-to-alist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
761 (list "list" (symbol-name tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
762 (symbol-name other-tag) value))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
763 (mpc-proc-error
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
764 ;; 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
765 ;; FIXME: check the kind of error.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
766 (let ((other-songs (mpc-cmd-find other-tag value)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
767 (mpc-assq-all tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
768 ;; Don't use `nconc' now that mpc-cmd-find may
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
769 ;; return a memoized result.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
770 (apply 'append other-songs))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
771
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
772 (defun mpc-cmd-stop (&optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
773 (mpc-proc-cmd "stop" callback))
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 (defun mpc-cmd-clear (&optional callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
776 (mpc-proc-cmd "clear" callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
777 ;; (setq mpc-queue-back nil mpc-queue nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
778 )
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
779
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
780 (defun mpc-cmd-pause (&optional arg callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
781 "Pause or resume playback of the queue of songs."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
782 (lexical-let ((cb callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
783 (mpc-proc-cmd (list "pause" arg)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
784 (lambda () (mpc-status-refresh) (if cb (funcall cb))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
785 (unless callback (mpc-proc-sync))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
786
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
787 (defun mpc-cmd-status ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
788 (mpc-proc-cmd-to-alist "status"))
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-play ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
791 (mpc-proc-cmd "play")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
792 (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
793
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
794 (defun mpc-cmd-add (files &optional playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
795 "Add the songs FILES to PLAYLIST.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
796 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
797 (mpc-proc-cmd (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
798 (mapcar (lambda (file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
799 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
800 (list "playlistadd" playlist file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
801 (list "add" file)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
802 files)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
803 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
804 (puthash (cons 'Playlist playlist) nil mpc--find-memoize)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
805
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
806 (defun mpc-cmd-delete (song-poss &optional playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
807 "Delete the songs at positions SONG-POSS from PLAYLIST.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
808 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
809 (mpc-proc-cmd (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
810 (mapcar (lambda (song-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
811 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
812 (list "playlistdelete" playlist song-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
813 (list "delete" song-pos)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
814 ;; Sort them from last to first, so the renumbering
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
815 ;; caused by the earlier deletions don't affect
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
816 ;; later ones.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
817 (sort song-poss '>))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
818 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
819 (puthash (cons 'Playlist playlist) nil mpc--find-memoize)))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
820
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
821
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
822 (defun mpc-cmd-move (song-poss dest-pos &optional playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
823 (let ((i 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
824 (mpc-proc-cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
825 (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
826 (mapcar (lambda (song-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
827 (if (>= song-pos dest-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
828 ;; positions past dest-pos have been
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
829 ;; shifted by i.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
830 (setq song-pos (+ song-pos i)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
831 (prog1 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
832 (list "playlistmove" playlist song-pos dest-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
833 (list "move" song-pos dest-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
834 (if (< song-pos dest-pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
835 ;; This move has shifted dest-pos by 1.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
836 (decf dest-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
837 (incf i)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
838 ;; Sort them from last to first, so the renumbering
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
839 ;; caused by the earlier deletions affect
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
840 ;; later ones a bit less.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
841 (sort song-poss '>))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
842 (if (stringp playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
843 (puthash (cons 'Playlist playlist) nil mpc--find-memoize))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
844
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
845 (defun mpc-cmd-update (&optional arg callback)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
846 (lexical-let ((cb callback))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
847 (mpc-proc-cmd (if arg (list "update" arg) "update")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
848 (lambda () (mpc-status-refresh) (if cb (funcall cb))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
849 (unless callback (mpc-proc-sync))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
850
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
851 (defun mpc-cmd-tagtypes ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
852 (mapcar 'cdr (mpc-proc-cmd-to-alist "tagtypes")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
853
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
854 ;; This was never integrated into MPD.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
855 ;; (defun mpc-cmd-download (file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
856 ;; (with-current-buffer (generate-new-buffer " *mpc download*")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
857 ;; (set-buffer-multibyte nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
858 ;; (let* ((proc (mpc-proc))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
859 ;; (stdbuf (process-buffer proc))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
860 ;; (markpos (marker-position (process-mark proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
861 ;; (stdcoding (process-coding-system proc)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
862 ;; (unwind-protect
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
863 ;; (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
864 ;; (set-process-buffer proc (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
865 ;; (set-process-coding-system proc 'binary (cdr stdcoding))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
866 ;; (set-marker (process-mark proc) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
867 ;; (mpc-proc-cmd (list "download" file)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
868 ;; (set-process-buffer proc stdbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
869 ;; (set-marker (process-mark proc) markpos stdbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
870 ;; (set-process-coding-system proc (car stdcoding) (cdr stdcoding)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
871 ;; ;; The command has completed, let's decode.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
872 ;; (goto-char (point-max))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
873 ;; (delete-char -1) ;Delete final newline.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
874 ;; (while (re-search-backward "^>" nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
875 ;; (delete-char 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
876 ;; (current-buffer))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
877
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
878 ;;; Misc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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-mpd-music-directory nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
881 "Location of MPD's music directory."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
882 :type '(choice (const nil) directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
883
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
884 (defcustom mpc-data-directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
885 (if (and (not (file-directory-p "~/.mpc"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
886 (file-directory-p "~/.emacs.d"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
887 "~/.emacs.d/mpc" "~/.mpc")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
888 "Directory where MPC.el stores auxiliary data."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
889 :type 'directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
890
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
891 (defun mpc-data-directory ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
892 (unless (file-directory-p mpc-data-directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
893 (make-directory mpc-data-directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
894 mpc-data-directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
895
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
896 (defun mpc-file-local-copy (file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
897 ;; Try to set mpc-mpd-music-directory.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
898 (when (and (null mpc-mpd-music-directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
899 (string-match "\\`localhost" mpc-host))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
900 (let ((files '("~/.mpdconf" "/etc/mpd.conf"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
901 file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
902 (while (and files (not file))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
903 (if (file-exists-p (car files)) (setq file (car files)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
904 (setq files (cdr files)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
905 (with-temp-buffer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
906 (ignore-errors (insert-file-contents file))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
907 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
908 (if (re-search-forward "^music_directory[ ]+\"\\([^\"]+\\)\"")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
909 (setq mpc-mpd-music-directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
910 (match-string 1))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
911 ;; 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
912 ;; `download' command, although it's never been accepted in `mpd' :-(
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
913 (if (and mpc-mpd-music-directory
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
914 (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
915 (expand-file-name file mpc-mpd-music-directory)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
916 ;; (let ((aux (expand-file-name (replace-regexp-in-string "[/]" "|" file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
917 ;; (mpc-data-directory))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
918 ;; (unless (file-exists-p aux)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
919 ;; (condition-case err
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
920 ;; (with-local-quit
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
921 ;; (with-current-buffer (mpc-cmd-download file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
922 ;; (write-region (point-min) (point-max) aux)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
923 ;; (kill-buffer (current-buffer))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
924 ;; (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
925 ;; aux)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
926 ))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
927
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
928 ;;; Formatter ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
929
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
930 (defun mpc-secs-to-time (secs)
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
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1435 (defun mpc-tagbrowser-buf (tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1436 (let ((buf (mpc-proc-buffer (mpc-proc) tag)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1437 (if (buffer-live-p buf) buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1438 (setq buf (get-buffer-create (format "*MPC %ss*" tag)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1439 (mpc-proc-buffer (mpc-proc) tag buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1440 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1441 (let ((inhibit-read-only t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1442 (erase-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1443 (if (member tag '(Directory))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1444 (mpc-tagbrowser-dir-mode)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1445 (mpc-tagbrowser-mode))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1446 (insert mpc-tagbrowser-all-name "\n"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1447 (forward-line -1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1448 (setq mpc-tag tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1449 (setq mpc-tag-name
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1450 (if (string-match "y\\'" (symbol-name tag))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1451 (concat (substring (symbol-name tag) 0 -1) "ies")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1452 (concat (symbol-name tag) "s")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1453 (mpc-tagbrowser-all-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1454 (mpc-tagbrowser-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1455 buf))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1456
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1457 (defvar tag-browser-tagtypes
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1458 (lazy-completion-table tag-browser-tagtypes
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1459 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1460 (append '("Playlist" "Directory")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1461 (mpc-cmd-tagtypes)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1462
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1463 (defun mpc-tagbrowser (tag)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1464 "Create a new browser for TAG."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1465 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1466 (list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1467 (let ((completion-ignore-case t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1468 (intern
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1469 (completing-read "Tag: " tag-browser-tagtypes nil 'require-match)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1470 (let* ((newbuf (mpc-tagbrowser-buf tag))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1471 (win (get-buffer-window newbuf 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1472 (if win (select-window win)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1473 (if (with-current-buffer (window-buffer (selected-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1474 (derived-mode-p 'mpc-tagbrowser-mode))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1475 (setq win (selected-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1476 ;; Find a tagbrowser-mode buffer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1477 (let ((buffers (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1478 buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1479 (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1480 (and buffers
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1481 (not (and (buffer-live-p (setq buffer (cdr (pop buffers))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1482 (with-current-buffer buffer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1483 (derived-mode-p 'mpc-tagbrowser-mode))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1484 (setq win (get-buffer-window buffer 0))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1485 (if (not win)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1486 (pop-to-buffer newbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1487 (setq win (split-window win nil 'horiz))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1488 (set-window-buffer win newbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1489 (set-window-dedicated-p win 'soft)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1490 (select-window win)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1491 (balance-windows-area)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1492
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1493 (defun mpc-tagbrowser-all-select ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1494 "Select the special *ALL* entry if no other is selected."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1495 (if mpc-select
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1496 (delete-overlay mpc-tagbrowser-all-ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1497 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1498 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1499 (if mpc-tagbrowser-all-ol
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1500 (move-overlay mpc-tagbrowser-all-ol
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1501 (point) (line-beginning-position 2))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1502 (let ((ol (make-overlay (point) (line-beginning-position 2))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1503 (overlay-put ol 'face 'region)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1504 (overlay-put ol 'evaporate t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1505 (set (make-local-variable 'mpc-tagbrowser-all-ol) ol))))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1506
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1507 ;; (defvar mpc-constraints nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1508 (defun mpc-separator (active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1509 ;; Place a separator mark.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1510 (unless mpc-separator-ol
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1511 (set (make-local-variable 'mpc-separator-ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1512 (make-overlay (point) (point)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1513 (overlay-put mpc-separator-ol 'after-string
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1514 (propertize "\n"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1515 'face '(:height 0.05 :inverse-video t))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1516 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1517 (forward-line 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1518 (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1519 (and (member (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1520 (line-beginning-position) (line-end-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1521 active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1522 (zerop (forward-line 1))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1523 (if (or (eobp) (null active))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1524 (delete-overlay mpc-separator-ol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1525 (move-overlay mpc-separator-ol (1- (point)) (point))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1526
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1527 (defun mpc-sort (active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1528 ;; Sort the active elements at the front.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1529 (let ((inhibit-read-only t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1530 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1531 (if (mpc-tagbrowser-all-p) (forward-line 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1532 (condition-case nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1533 (sort-subr nil 'forward-line 'end-of-line
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1534 nil nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1535 (lambda (s1 s2)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1536 (setq s1 (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1537 (car s1) (cdr s1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1538 (setq s2 (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1539 (car s2) (cdr s2)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1540 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1541 ((member s1 active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1542 (if (member s2 active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1543 (let ((cmp (mpc-compare-strings s1 s2 t)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1544 (and (numberp cmp) (< cmp 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1545 t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1546 ((member s2 active) nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1547 (t (let ((cmp (mpc-compare-strings s1 s2 t)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1548 (and (numberp cmp) (< cmp 0)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1549 ;; The comparison predicate arg is new in Emacs-22.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1550 (wrong-number-of-arguments
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1551 (sort-subr nil 'forward-line 'end-of-line
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1552 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1553 (let ((name (buffer-substring-no-properties
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1554 (point) (line-end-position))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1555 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1556 ((member name active) (concat "1" name))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1557 (t (concat "2" "name"))))))))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1558
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1559 (defvar mpc--changed-selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1560
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1561 (defun mpc-reorder (&optional nodeactivate)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1562 "Reorder entries based on thre currently active selections.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1563 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
1564 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
1565 not included in the selection.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1566 Return non-nil if a selection was deactivated."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1567 (mpc-select-save
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1568 (let ((constraints (mpc-constraints-get-current (current-buffer)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1569 (active 'all))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1570 ;; (unless (equal constraints mpc-constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1571 ;; (set (make-local-variable 'mpc-constraints) constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1572 (dolist (cst constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1573 (let ((vals (apply 'mpc-union
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1574 (mapcar (lambda (val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1575 (mpc-cmd-list mpc-tag (car cst) val))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1576 (cdr cst)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1577 (setq active
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1578 (if (listp active) (mpc-intersection active vals) vals))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1579
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1580 (when (and (listp active))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1581 ;; Remove the selections if they are all in conflict with
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1582 ;; other constraints.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1583 (let ((deactivate t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1584 (dolist (sel selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1585 (when (member sel active) (setq deactivate nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1586 (when deactivate
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1587 ;; Variable declared/used by `mpc-select-save'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1588 (when selection
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1589 (setq mpc--changed-selection t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1590 (unless nodeactivate
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1591 (setq selection nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1592 (mapc 'delete-overlay mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1593 (setq mpc-select nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1594 (mpc-tagbrowser-all-select)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1595
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1596 ;; 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
1597 ;; 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
1598 (mpc-sort (if (listp active) active))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1599 (mpc-separator (if (listp active) active)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1600
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1601 (defun mpc-selection-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1602 (let ((mpc--changed-selection t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1603 (while mpc--changed-selection
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1604 (setq mpc--changed-selection nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1605 (dolist (buf (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1606 (setq buf (cdr buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1607 (when (and (buffer-local-value 'mpc-tag buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1608 (not (eq buf (current-buffer))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1609 (with-current-buffer buf (mpc-reorder)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1610 ;; FIXME: reorder the current buffer last and prevent deactivation,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1611 ;; 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
1612 ;; and should hence take precedence.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1613 (when mpc-tag (mpc-reorder 'nodeactivate))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1614 ;; FIXME: comment?
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1615 (if (and mpc--song-search mpc--changed-selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1616 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1617 (setq mpc--song-search nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1618 (mpc-selection-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1619 (mpc-songs-refresh))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1620
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1621 ;;; Hierarchical tagbrowser ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1622 ;; Todo:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1623 ;; - Add a button on each dir to open/close it (?)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1624 ;; - 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
1625 ;; 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
1626 ;; in the selected part).
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1627
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1628 (defvar mpc-tagbrowser-dir-mode-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1629 (let ((map (make-sparse-keymap)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1630 (set-keymap-parent map mpc-tagbrowser-mode-map)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1631 (define-key map [?\M-\C-m] 'mpc-tagbrowser-dir-toggle)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1632 map))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1633
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1634 ;; (defvar mpc-tagbrowser-dir-keywords
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1635 ;; '(mpc-tagbrowser-dir-hide-prefix))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1636
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1637 (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
1638 ;; (set (make-local-variable 'font-lock-defaults)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1639 ;; '(mpc-tagbrowser-dir-keywords t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1640 )
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1641
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1642 ;; (defun mpc-tagbrowser-dir-hide-prefix (limit)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1643 ;; (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1644 ;; (let ((prev (buffer-substring (line-beginning-position 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1645 ;; (line-end-position 0))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1646 ;; (
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 (defun mpc-tagbrowser-dir-toggle (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1649 "Open or close the element at point."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1650 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1651 (mpc-event-set-point event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1652 (let ((name (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1653 (line-end-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1654 (prop (intern mpc-tag)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1655 (if (not (member name (process-get (mpc-proc) prop)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1656 (process-put (mpc-proc) prop
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1657 (cons name (process-get (mpc-proc) prop)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1658 (let ((new (delete name (process-get (mpc-proc) prop))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1659 (setq name (concat name "/"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1660 (process-put (mpc-proc) prop
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1661 (delq nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1662 (mapcar (lambda (x)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1663 (if (mpc-string-prefix-p name x)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1664 nil x))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1665 new)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1666 (mpc-tagbrowser-refresh)))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1667
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1668
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1669 ;;; Playlist management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1670
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1671 (defvar mpc-songs-playlist nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1672 "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
1673 A value of t means the main playlist.")
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1674 (make-variable-buffer-local 'mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1675
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1676 (defun mpc-playlist-create (name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1677 "Save current playlist under name NAME."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1678 (interactive "sPlaylist name: ")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1679 (mpc-proc-cmd (list "save" name))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1680 (let ((buf (mpc-proc-buffer (mpc-proc) 'Playlist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1681 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1682 (with-current-buffer buf (mpc-tagbrowser-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1683
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1684 (defun mpc-playlist-destroy (name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1685 "Delete playlist named NAME."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1686 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1687 (list (completing-read "Delete playlist: " (mpc-cmd-list 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1688 nil 'require-match)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1689 (mpc-proc-cmd (list "rm" name))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1690 (let ((buf (mpc-proc-buffer (mpc-proc) 'Playlist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1691 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1692 (with-current-buffer buf (mpc-tagbrowser-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1693
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1694 (defun mpc-playlist-rename (oldname newname)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1695 "Rename playlist OLDNAME to NEWNAME."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1696 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1697 (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
1698 (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1699 (line-end-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1700 (completing-read "Rename playlist: "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1701 (mpc-cmd-list 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1702 nil 'require-match)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1703 (newname (read-string (format "Rename '%s' to: " oldname))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1704 (if (zerop (length newname))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1705 (error "Aborted")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1706 (list oldname newname))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1707 (mpc-proc-cmd (list "rename" oldname newname))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1708 (let ((buf (mpc-proc-buffer (mpc-proc) 'Playlist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1709 (if (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1710 (with-current-buffer buf (mpc-tagbrowser-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1711
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1712 (defun mpc-playlist ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1713 "Show the current playlist."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1714 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1715 (mpc-constraints-push 'noerror)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1716 (mpc-constraints-restore '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1717
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1718 (defun mpc-playlist-add ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1719 "Add the selection to the playlist."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1720 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1721 (let ((songs (mapcar #'car (mpc-songs-selection))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1722 (mpc-cmd-add songs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1723 (message "Appended %d songs" (length songs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1724 ;; Return the songs added. Used in `mpc-play'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1725 songs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1726
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1727 (defun mpc-playlist-delete ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1728 "Remove the selected songs from the playlist."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1729 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1730 (unless mpc-songs-playlist
106697
ac408704629c lisp/*: Fix typos in docstrings and messages.
Juanma Barranquero <lekktu@gmail.com>
parents: 106365
diff changeset
1731 (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
1732 (let ((song-poss (mapcar #'cdr (mpc-songs-selection))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1733 (mpc-cmd-delete song-poss mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1734 (mpc-songs-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1735 (message "Deleted %d songs" (length song-poss))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1736
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1737 ;;; Volume management ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1738
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1739 (defvar mpc-volume-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1740 (let ((map (make-sparse-keymap)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1741 (define-key map [down-mouse-1] 'mpc-volume-mouse-set)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1742 (define-key map [mouse-1] 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1743 (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
1744 (define-key map [header-line mouse-1] 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1745 (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
1746 (define-key map [mode-line mouse-1] 'ignore)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1747 map))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1748
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1749 (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
1750
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1751 (defun mpc-volume-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1752 ;; Maintain the volume.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1753 (setq mpc-volume
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1754 (mpc-volume-widget
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1755 (string-to-number (cdr (assq 'volume mpc-status))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1756
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1757 (defvar mpc-volume-step 5)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1758
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1759 (defun mpc-volume-mouse-set (&optional event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1760 "Change volume setting."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1761 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1762 (let* ((posn (event-start event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1763 (diff
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1764 (if (memq (if (stringp (car-safe (posn-object posn)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1765 (aref (car (posn-object posn)) (cdr (posn-object posn)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1766 (with-current-buffer (window-buffer (posn-window posn))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1767 (char-after (posn-point posn))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1768 '(?◁ ?<))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1769 (- mpc-volume-step) mpc-volume-step))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1770 (newvol (+ (string-to-number (cdr (assq 'volume mpc-status))) diff)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1771 (mpc-proc-cmd (list "setvol" newvol) 'mpc-status-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1772 (message "Set MPD volume to %s%%" newvol)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1773
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1774 (defun mpc-volume-widget (vol &optional size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1775 (unless size (setq size 12.5))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1776 (let ((scaledvol (* (/ vol 100.0) size)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1777 ;; (message "Volume sizes: %s - %s" (/ vol fact) (/ (- 100 vol) fact))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1778 (list (propertize "<" ;; "◁"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1779 ;; 'face 'default
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1780 'keymap mpc-volume-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1781 'face '(:box (:line-width -2 :style pressed-button))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1782 'mouse-face '(:box (:line-width -2 :style released-button)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1783 " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1784 (propertize "a"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1785 'display (list 'space :width scaledvol)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1786 'face '(:inverse-video t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1787 :box (:line-width -2 :style released-button)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1788 (propertize "a"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1789 'display (list 'space :width (- size scaledvol))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1790 'face '(:box (:line-width -2 :style released-button)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1791 " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1792 (propertize ">" ;; "▷"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1793 ;; 'face 'default
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1794 'keymap mpc-volume-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1795 'face '(:box (:line-width -2 :style pressed-button))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1796 'mouse-face '(:box (:line-width -2 :style released-button))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1797
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1798 ;;; MPC songs mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1799
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1800 (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
1801 (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
1802 (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
1803
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1804 (defvar mpc-previous-window-config nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1805
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1806 (defvar mpc-songs-mode-map
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1807 (let ((map (make-sparse-keymap)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1808 (set-keymap-parent map mpc-mode-map)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1809 (define-key map [remap mpc-select] 'mpc-songs-jump-to)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1810 map))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1811
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1812 (defvar mpc-songpointer-set-visible nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1813
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1814 (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
1815 "Make song file name objects unique via hash consing.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1816 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
1817 `text-property-any'.")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1818 (defun mpc-songs-hashcons (name)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1819 (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
1820 (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
1821 "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
1822 :type 'string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1823
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1824 (defvar mpc-songs-totaltime)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1825
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1826 (defun mpc-songs-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1827 (let ((buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1828 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1829 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1830 (let ((constraints (mpc-constraints-get-current (current-buffer)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1831 (dontsort nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1832 (inhibit-read-only t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1833 (totaltime 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1834 (curline (cons (count-lines (point-min)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1835 (line-beginning-position))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1836 (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1837 (line-end-position))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1838 active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1839 (setq mpc-songs-playlist nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1840 (if (null constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1841 ;; 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
1842 ;; all songs (which could take a while to download and
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1843 ;; format), we show the current playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1844 ;; 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
1845 ;; list, but that would probably require us to format it
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1846 ;; on-the-fly to make it bearable.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1847 (setq dontsort t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1848 mpc-songs-playlist t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1849 active (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1850 (mpc-proc-cmd "playlistinfo")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1851 (dolist (cst constraints)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1852 (if (and (eq (car cst) 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1853 (= 1 (length (cdr cst))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1854 (setq mpc-songs-playlist (cadr cst)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1855 ;; We don't do anything really special here for playlists,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1856 ;; 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
1857 (let ((vals (apply 'mpc-union
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1858 (mapcar (lambda (val)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1859 (mpc-cmd-find (car cst) val))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1860 (cdr cst)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1861 (setq active (if (null active)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1862 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1863 (if (eq (car cst) 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1864 (setq dontsort t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1865 vals)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1866 (if (or dontsort
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1867 ;; Try to preserve ordering and
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1868 ;; repetitions from playlists.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1869 (not (eq (car cst) 'Playlist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1870 (mpc-intersection active vals
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1871 (lambda (x) (assq 'file x)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1872 (setq dontsort t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1873 (mpc-intersection vals active
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1874 (lambda (x) (assq 'file x)))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1875 (mpc-select-save
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1876 (erase-buffer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1877 ;; Sorting songs is surprisingly difficult: when comparing two
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1878 ;; 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
1879 ;; 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
1880 ;; same name) or a single album (typically a compilation).
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1881 ;; 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
1882 ;; right thing if your library is properly arranged.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1883 (dolist (song (if dontsort active
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1884 (sort active
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1885 (lambda (song1 song2)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1886 (let ((cmp (mpc-compare-strings
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1887 (cdr (assq 'file song1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1888 (cdr (assq 'file song2)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1889 (and (integerp cmp) (< cmp 0)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1890 (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
1891 (mpc-format mpc-songs-format song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1892 (delete-char (- (skip-chars-backward " "))) ;Remove trailing space.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1893 (insert "\n")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1894 (put-text-property
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1895 (line-beginning-position 0) (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1896 'mpc-file (mpc-songs-hashcons (cdr (assq 'file song))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1897 (let ((pos (assq 'Pos song)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1898 (if pos
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1899 (put-text-property
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1900 (line-beginning-position 0) (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1901 'mpc-file-pos (string-to-number (cdr pos)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1902 ))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1903 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1904 (forward-line (car curline))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1905 (when (or (search-forward (cdr curline) nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1906 (search-backward (cdr curline) nil t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1907 (beginning-of-line))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1908 (set (make-local-variable 'mpc-songs-totaltime)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1909 (unless (zerop totaltime)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1910 (list " " (mpc-secs-to-time totaltime))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1911 ))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1912 (let ((mpc-songpointer-set-visible t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1913 (mpc-songpointer-refresh)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1914
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1915 (defun mpc-songs-search (string)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1916 "Filter songs to those who include STRING in their metadata."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1917 (interactive "sSearch for: ")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1918 (setq mpc--song-search
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1919 (if (zerop (length string)) nil string))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1920 (let ((mpc--changed-selection t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1921 (while mpc--changed-selection
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1922 (setq mpc--changed-selection nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1923 (dolist (buf (process-get (mpc-proc) 'buffers))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1924 (setq buf (cdr buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1925 (when (buffer-local-value 'mpc-tag buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1926 (with-current-buffer buf (mpc-reorder))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1927 (mpc-songs-refresh))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
1928
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1929 (defun mpc-songs-kill-search ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1930 "Turn off the current search restriction."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1931 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1932 (mpc-songs-search nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1933
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1934 (defun mpc-songs-selection ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1935 "Return the list of songs currently selected."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1936 (let ((buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1937 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1938 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1939 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1940 (let ((files ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1941 (if mpc-select
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1942 (dolist (ol mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1943 (push (cons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1944 (get-text-property (overlay-start ol) 'mpc-file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1945 (get-text-property (overlay-start ol) 'mpc-file-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1946 files))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1947 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1948 (while (not (eobp))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1949 (push (cons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1950 (get-text-property (point) 'mpc-file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1951 (get-text-property (point) 'mpc-file-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1952 files)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1953 (forward-line 1)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1954 (nreverse files)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1955
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1956 (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
1957 "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
1958 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1959 (let* ((event last-nonmenu-event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1960 (posn (event-end event)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1961 (with-selected-window (posn-window posn)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1962 (goto-char (posn-point posn))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1963 (list (get-text-property (point) 'mpc-file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1964 posn))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1965 (let* ((plbuf (mpc-proc-cmd "playlist"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1966 (re (concat "^\\([0-9]+\\):" (regexp-quote song-file) "$"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1967 (sn (with-current-buffer plbuf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1968 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1969 (when (re-search-forward re nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1970 (match-string 1)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1971 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1972 ((null sn) (error "This song is not in the playlist"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1973 ((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
1974 ;; song-file only appears once in the playlist: no ambiguity,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1975 ;; we're good to go!
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1976 (mpc-proc-cmd (list "play" sn)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1977 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1978 ;; 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
1979 ;; 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
1980 ;; 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
1981 ;; 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
1982 ;; song occurrence closest to the current song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1983 (with-selected-window (posn-window posn)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1984 (let* ((cur (and (markerp overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1985 (marker-position overlay-arrow-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1986 (dest (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1987 (goto-char (posn-point posn))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1988 (line-beginning-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1989 (lines (when cur (* (if (< cur dest) 1 -1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1990 (count-lines cur dest)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1991 (with-current-buffer plbuf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1992 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1993 ;; Start the search from the current song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1994 (forward-line (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1995 (or (cdr (assq 'song mpc-status)) "0")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1996 ;; If the current song is also displayed in the buffer,
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1997 ;; then try to move to the same relative position.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1998 (if lines (forward-line lines))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1999 ;; Now search the closest occurrence.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2000 (let* ((next (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2001 (when (re-search-forward re nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2002 (cons (point) (match-string 1)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2003 (prev (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2004 (when (re-search-backward re nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2005 (cons (point) (match-string 1)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2006 (sn (cdr (if (and next prev)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2007 (if (< (- (car next) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2008 (- (point) (car prev)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2009 next prev)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2010 (or next prev)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2011 (assert sn)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2012 (mpc-proc-cmd (concat "play " sn))))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2013
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2014 (define-derived-mode mpc-songs-mode mpc-mode "MPC-song"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2015 (setq mpc-songs-format-description
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2016 (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
2017 (set (make-local-variable 'header-line-format)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2018 ;; '("MPC " mpc-volume " " mpc-current-song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2019 (list (propertize " " 'display '(space :align-to 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2020 ;; 'mpc-songs-format-description
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2021 '(:eval
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2022 (let ((hscroll (window-hscroll)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2023 (with-temp-buffer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2024 (mpc-format mpc-songs-format 'self hscroll)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2025 ;; That would be simpler than the hscroll handling in
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2026 ;; mpc-format, but currently move-to-column does not
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2027 ;; recognize :space display properties.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2028 ;; (move-to-column hscroll)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2029 ;; (delete-region (point-min) (point))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2030 (buffer-string))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2031 (set (make-local-variable 'mode-line-format)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2032 '("%e" mode-line-frame-identification mode-line-buffer-identification
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2033 #(" " 0 3
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2034 (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
2035 mode-line-position
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2036 #(" " 0 2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2037 (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
2038 mpc-songs-totaltime
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2039 mpc-current-updating
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2040 #(" " 0 2
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2041 (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
2042 (mpc--song-search
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2043 (:propertize
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2044 ("Search=\"" mpc--song-search "\"")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2045 help-echo "mouse-2: kill this search"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2046 follow-link t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2047 mouse-face mode-line-highlight
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2048 keymap (keymap (mode-line keymap
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2049 (mouse-2 . mpc-songs-kill-search))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2050 (:propertize "NoSearch"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2051 help-echo "mouse-2: set a search restriction"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2052 follow-link t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2053 mouse-face mode-line-highlight
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2054 keymap (keymap (mode-line keymap (mouse-2 . mpc-songs-search)))))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2055
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2056 ;; (set (make-local-variable 'mode-line-process)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2057 ;; '("" ;; mpc-volume " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2058 ;; mpc-songs-totaltime
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2059 ;; mpc-current-updating))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2060 )
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2061
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2062 (defun mpc-songpointer-set (pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2063 (let* ((win (get-buffer-window (current-buffer) t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2064 (visible (when win
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2065 (or mpc-songpointer-set-visible
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2066 (and (markerp overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2067 (eq (marker-buffer overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2068 (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2069 (<= (window-start win) overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2070 (< overlay-arrow-position (window-end win)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2071 (unless (local-variable-p 'overlay-arrow-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2072 (set (make-local-variable 'overlay-arrow-position) (make-marker)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2073 (move-marker overlay-arrow-position pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2074 ;; 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
2075 (if (and visible pos
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2076 (or (> (window-start win) pos) (>= pos (window-end win t))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2077 (set-window-point win pos))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2078
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2079 (defun mpc-songpointer-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2080 (let ((buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2081 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2082 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2083 (let* ((pos (text-property-any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2084 (point-min) (point-max)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2085 'mpc-file (mpc-songs-hashcons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2086 (cdr (assq 'file mpc-status)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2087 (other (when pos
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2088 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2089 (goto-char pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2090 (text-property-any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2091 (line-beginning-position 2) (point-max)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2092 'mpc-file (mpc-songs-hashcons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2093 (cdr (assq 'file mpc-status))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2094 (if other
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2095 ;; The song appears multiple times in the buffer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2096 ;; We need to be careful to choose the right occurrence.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2097 (mpc-proc-cmd "playlist" 'mpc-songpointer-refresh-hairy)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2098 (mpc-songpointer-set pos)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2099
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2100 (defun mpc-songpointer-context (size plbuf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2101 (with-current-buffer plbuf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2102 (goto-char (point-min))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2103 (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
2104 (let ((context-before '())
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2105 (context-after '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2106 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2107 (dotimes (i size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2108 (when (re-search-backward "^[0-9]+:\\(.*\\)" nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2109 (push (mpc-songs-hashcons (match-string 1)) context-before))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2110 ;; Skip the actual current song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2111 (forward-line 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2112 (dotimes (i size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2113 (when (re-search-forward "^[0-9]+:\\(.*\\)" nil t)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2114 (push (mpc-songs-hashcons (match-string 1)) context-after)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2115 ;; If there isn't `size' context, then return nil.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2116 (unless (and (< (length context-before) size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2117 (< (length context-after) size))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2118 (cons (nreverse context-before) (nreverse context-after))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2119
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2120 (defun mpc-songpointer-score (context pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2121 (let ((count 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2122 (goto-char pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2123 (dolist (song (car context))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2124 (and (zerop (forward-line -1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2125 (eq (get-text-property (point) 'mpc-file) song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2126 (incf count)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2127 (goto-char pos)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2128 (dolist (song (cdr context))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2129 (and (zerop (forward-line 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2130 (eq (get-text-property (point) 'mpc-file) song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2131 (incf count)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2132 count))
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-refresh-hairy ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2135 ;; 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
2136 ;; song buffer is the currently playing song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2137 (let ((plbuf (current-buffer))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2138 (buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2139 (when (buffer-live-p buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2140 (with-current-buffer buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2141 (let* ((context-size 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2142 (context '(() . ()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2143 (pos (text-property-any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2144 (point-min) (point-max)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2145 'mpc-file (mpc-songs-hashcons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2146 (cdr (assq 'file mpc-status)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2147 (score 0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2148 (other pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2149 (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2150 (setq other
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2151 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2152 (goto-char other)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2153 (text-property-any
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2154 (line-beginning-position 2) (point-max)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2155 'mpc-file (mpc-songs-hashcons
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2156 (cdr (assq 'file mpc-status))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2157 ;; There is an `other' contestant.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2158 (let ((other-score (mpc-songpointer-score context other)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2159 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2160 ;; `other' is worse: try the next one.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2161 ((< other-score score) nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2162 ;; `other' is better: remember it and then search further.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2163 ((> other-score score)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2164 (setq pos other)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2165 (setq score other-score))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2166 ;; 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
2167 ;; Arbitrarily choose one of the two and keep looking
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2168 ;; for a better match.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2169 ((< score context-size) nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2170 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2171 ;; Score is equal and increasing context might help: try it.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2172 (incf context-size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2173 (let ((new-context
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2174 (mpc-songpointer-context context-size plbuf)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2175 (if (null new-context)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2176 ;; There isn't more context: choose one arbitrarily
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2177 ;; and keep looking for a better match elsewhere.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2178 (decf context-size)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2179 (setq context new-context)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2180 (setq score (mpc-songpointer-score context pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2181 (save-excursion
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2182 (goto-char other)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2183 ;; Go back one line so we find `other' again.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2184 (setq other (line-beginning-position 0)))))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2185 (mpc-songpointer-set pos))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2186
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2187 (defun mpc-current-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2188 ;; Maintain the current data.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2189 (mpc-status-buffer-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2190 (setq mpc-current-updating
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2191 (if (assq 'updating_db mpc-status) " Updating-DB"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2192 (ignore-errors
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2193 (setq mpc-current-song
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2194 (when (assq 'file mpc-status)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2195 (concat " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2196 (mpc-secs-to-time (cdr (assq 'time mpc-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2197 " "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2198 (cdr (assq 'Title mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2199 " ("
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2200 (cdr (assq 'Artist mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2201 " / "
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2202 (cdr (assq 'Album mpc-status))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2203 ")"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2204 (force-mode-line-update t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2205
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2206 (defun mpc-songs-buf ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2207 (let ((buf (mpc-proc-buffer (mpc-proc) 'songs)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2208 (if (buffer-live-p buf) buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2209 (with-current-buffer (setq buf (get-buffer-create "*MPC-Songs*"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2210 (mpc-proc-buffer (mpc-proc) 'songs buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2211 (mpc-songs-mode)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2212 buf))))
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 (defun mpc-update ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2215 "Tell MPD to refresh its database."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2216 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2217 (mpc-cmd-update))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2218
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2219 (defun mpc-quit ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2220 "Quit Music Player Daemon."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2221 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2222 (let* ((proc mpc-proc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2223 (bufs (mapcar 'cdr (if proc (process-get proc 'buffers))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2224 (wins (mapcar (lambda (buf) (get-buffer-window buf 0)) bufs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2225 (song-buf (mpc-songs-buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2226 frames)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2227 ;; Collect all the frames where MPC buffers appear.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2228 (dolist (win wins)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2229 (when (and win (not (memq (window-frame win) frames)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2230 (push (window-frame win) frames)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2231 (if (and frames song-buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2232 (with-current-buffer song-buf mpc-previous-window-config))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2233 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2234 (select-frame (car frames))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2235 (set-window-configuration
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2236 (with-current-buffer song-buf mpc-previous-window-config)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2237 ;; 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
2238 (dolist (frame frames)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2239 (let ((delete t))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2240 (dolist (win (window-list frame))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2241 (unless (memq (window-buffer win) bufs) (setq delete nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2242 (if delete (ignore-errors (delete-frame frame))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2243 ;; Then kill the buffers.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2244 (mapc 'kill-buffer bufs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2245 (mpc-status-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2246 (if proc (delete-process proc))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2247
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2248 (defun mpc-stop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2249 "Stop playing the current queue of songs."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2250 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2251 (mpc-cmd-stop)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2252 (mpc-cmd-clear)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2253 (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2254
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2255 (defun mpc-pause ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2256 "Pause playing."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2257 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2258 (mpc-cmd-pause "1"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2259
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2260 (defun mpc-resume ()
106365
06698b91c779 * mpc.el (mpc-intersection, mpc-host, mpc-songs-playlist)
Juanma Barranquero <lekktu@gmail.com>
parents: 106354
diff changeset
2261 "Resume playing."
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2262 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2263 (mpc-cmd-pause "0"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2264
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2265 (defun mpc-play ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2266 "Start playing whatever is selected."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2267 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2268 (if (member (cdr (assq 'state (mpc-cmd-status))) '("pause"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2269 (mpc-resume)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2270 ;; 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
2271 ;; 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
2272 ;; listen to what he just selected.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2273 ;; (if (member (cdr (assq 'state (mpc-cmd-status))) '("stop"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2274 ;; (mpc-cmd-clear))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2275 ;; 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
2276 ;; so we can just always empty the playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2277 (mpc-cmd-clear)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2278 (if (mpc-playlist-add)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2279 (if (member (cdr (assq 'state (mpc-cmd-status))) '("stop"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2280 (mpc-cmd-play))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2281 (error "Don't know what to play"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2282
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2283 (defun mpc-next ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2284 "Jump to the next song in the queue."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2285 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2286 (mpc-proc-cmd "next")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2287 (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2288
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2289 (defun mpc-prev ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2290 "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
2291 (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2292 (let ((time (cdr (assq 'time mpc-status))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2293 ;; 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
2294 ;; everything after a non-digit char.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2295 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2296 ;; Go back to the beginning of current song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2297 ((and time (> (string-to-number time) 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2298 (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
2299 ;; 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
2300 ;; Fetch the previous one from `mpc-queue-back'.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2301 ;; ((and (zerop (string-to-number (cdr (assq 'song mpc-status))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2302 ;; mpc-queue-back)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2303 ;; ;; 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
2304 ;; ;; automatically updated.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2305 ;; (let ((prev (pop mpc-queue-back)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2306 ;; (push prev mpc-queue)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2307 ;; (mpc-proc-cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2308 ;; (mpc-proc-cmd-list
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2309 ;; (list (list "add" prev)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2310 ;; (list "move" (cdr (assq 'playlistlength mpc-status)) "0")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2311 ;; "previous")))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2312 ;; 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
2313 (t (mpc-proc-cmd "previous")))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2314 (mpc-status-refresh)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2315
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2316 (defvar mpc-last-seek-time '(0 . 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2317
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2318 (defun mpc--faster (event speedup step)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2319 "Fast forward."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2320 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2321 (let ((repeat-delay (/ (abs (float step)) speedup)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2322 (if (not (memq 'down (event-modifiers event)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2323 (let* ((currenttime (float-time))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2324 (last-time (- currenttime (car mpc-last-seek-time))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2325 (if (< last-time (* 0.9 repeat-delay))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2326 nil ;; Trottle
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2327 (let* ((status (if (< last-time 1.0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2328 mpc-status (mpc-cmd-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2329 (songid (cdr (assq 'songid status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2330 (time (if songid
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2331 (if (< last-time 1.0)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2332 (cdr mpc-last-seek-time)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2333 (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2334 (cdr (assq 'time status)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2335 (setq mpc-last-seek-time
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2336 (cons currenttime (setq time (+ time step))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2337 (mpc-proc-cmd (list "seekid" songid time)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2338 'mpc-status-refresh))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2339 (let ((status (mpc-cmd-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2340 (lexical-let* ((songid (cdr (assq 'songid status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2341 (step step)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2342 (time (if songid (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2343 (cdr (assq 'time status))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2344 (let ((timer (run-with-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2345 t repeat-delay
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2346 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2347 (mpc-proc-cmd (list "seekid" songid
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2348 (setq time (+ time step)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2349 'mpc-status-refresh)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2350 (while (mouse-movement-p
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2351 (event-basic-type (setq event (read-event)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2352 (cancel-timer timer)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2353
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2354 (defvar mpc--faster-toggle-timer nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2355 (defun mpc--faster-stop ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2356 (when mpc--faster-toggle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2357 (cancel-timer mpc--faster-toggle-timer)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2358 (setq mpc--faster-toggle-timer nil)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2359
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2360 (defun mpc--faster-toggle-refresh ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2361 (if (equal (cdr (assq 'state mpc-status)) "stop")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2362 (mpc--faster-stop)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2363
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2364 (defun mpc--songduration ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2365 (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2366 (let ((s (cdr (assq 'time mpc-status))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2367 (if (not (string-match ":" s))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2368 (error "Unexpected time format %S" s)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2369 (substring s (match-end 0))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2370
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2371 (defvar mpc--faster-toggle-forward nil)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2372 (defvar mpc--faster-acceleration 0.5)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2373 (defun mpc--faster-toggle (speedup step)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2374 (setq speedup (float speedup))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2375 (if mpc--faster-toggle-timer
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 (mpc-status-refresh) (mpc-proc-sync)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2378 (lexical-let* ((speedup speedup)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2379 songid ;The ID of the currently ffwd/rewinding song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2380 songnb ;The position of that song in the playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2381 songduration ;The duration of that song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2382 songtime ;The time of the song last time we ran.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2383 oldtime ;The timeoftheday last time we ran.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2384 prevsongid) ;The song we're in the process leaving.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2385 (let ((fun
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2386 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2387 (let ((newsongid (cdr (assq 'songid mpc-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2388 (newsongnb (cdr (assq 'song mpc-status))))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2389
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2390 (if (and (equal prevsongid newsongid)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2391 (not (equal prevsongid songid)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2392 ;; We left prevsongid and came back to it. Pretend it
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2393 ;; didn't happen.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2394 (setq newsongid songid))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2395
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2396 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2397 ((null newsongid) (mpc--faster-stop))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2398 ((not (equal songid newsongid))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2399 ;; We jumped to another song: reset.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2400 (setq songid newsongid)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2401 (setq songtime (string-to-number
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2402 (cdr (assq 'time mpc-status))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2403 (setq songduration (mpc--songduration))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2404 (setq oldtime (float-time)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2405 ((and (>= songtime songduration) mpc--faster-toggle-forward)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2406 ;; Skip to the beginning of the next song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2407 (if (not (equal (cdr (assq 'state mpc-status)) "play"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2408 (mpc-proc-cmd "next" 'mpc-status-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2409 ;; If we're playing, this is done automatically, so we
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2410 ;; 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
2411 ;; do anything otherwise there's a race condition where
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2412 ;; we could skip straight to the next next song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2413 nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2414 ((and (<= songtime 0) (not mpc--faster-toggle-forward))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2415 ;; Skip to the end of the previous song.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2416 (setq prevsongid songid)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2417 (mpc-proc-cmd "previous"
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2418 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2419 (mpc-status-refresh
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2420 (lambda ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2421 (setq songid (cdr (assq 'songid mpc-status)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2422 (setq songtime (setq songduration (mpc--songduration)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2423 (setq oldtime (float-time))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2424 (mpc-proc-cmd (list "seekid" songid songtime)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2425 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2426 (setq speedup (+ speedup mpc--faster-acceleration))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2427 (let ((newstep
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2428 (truncate (* speedup (- (float-time) oldtime)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2429 (if (<= newstep 1) (setq newstep 1))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2430 (setq oldtime (+ oldtime (/ newstep speedup)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2431 (if (not mpc--faster-toggle-forward)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2432 (setq newstep (- newstep)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2433 (setq songtime (min songduration (+ songtime newstep)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2434 (unless (>= songtime songduration)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2435 (condition-case nil
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2436 (mpc-proc-cmd
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2437 (list "seekid" songid songtime)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2438 'mpc-status-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2439 (mpc-proc-error (mpc-status-refresh)))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2440 (setq songnb newsongnb)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2441 (setq mpc--faster-toggle-forward (> step 0))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2442 (funcall fun) ;Initialize values.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2443 (setq mpc--faster-toggle-timer
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2444 (run-with-timer t 0.3 fun))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2445
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2446
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2447
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2448 (defvar mpc-faster-speedup 8)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2449
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2450 (defun mpc-ffwd (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2451 "Fast forward."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2452 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2453 ;; (mpc--faster event 4.0 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2454 (mpc--faster-toggle mpc-faster-speedup 1))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2455
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2456 (defun mpc-rewind (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2457 "Fast rewind."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2458 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2459 ;; (mpc--faster event 4.0 -1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2460 (mpc--faster-toggle mpc-faster-speedup -1))
106354
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2461
de269b2f72b3 Delete trailing whitespace.
Chong Yidong <cyd@stupidchicken.com>
parents: 106342
diff changeset
2462
106342
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2463 (defun mpc-play-at-point (&optional event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2464 (interactive (list last-nonmenu-event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2465 (mpc-select event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2466 (mpc-play))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2467
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2468 ;; (defun mpc-play-tagval ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2469 ;; "Play all the songs of the tag at point."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2470 ;; (interactive)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2471 ;; (let* ((val (buffer-substring (line-beginning-position) (line-end-position)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2472 ;; (songs (mapcar 'cdar
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2473 ;; (mpc-proc-buf-to-alists
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2474 ;; (mpc-proc-cmd (list "find" mpc-tag val))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2475 ;; (mpc-cmd-add songs)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2476 ;; (if (member (cdr (assq 'state (mpc-cmd-status))) '("stop"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2477 ;; (mpc-cmd-play))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2478
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2479 ;;; Drag'n'drop support ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2480 ;; Todo:
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2481 ;; 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
2482 ;; - change the mouse-cursor.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2483 ;; - highlight/select the source and the current destination.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2484
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2485 (defun mpc-drag-n-drop (event)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2486 "DWIM for a drag EVENT."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2487 (interactive "e")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2488 (let* ((start (event-start event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2489 (end (event-end event))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2490 (start-buf (window-buffer (posn-window start)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2491 (end-buf (window-buffer (posn-window end)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2492 (songs
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2493 (with-current-buffer start-buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2494 (goto-char (posn-point start))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2495 (if (get-text-property (point) 'mpc-select)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2496 ;; FIXME: actually we should only consider the constraints
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2497 ;; corresponding to the selection in this particular buffer.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2498 (mpc-songs-selection)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2499 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2500 ((and (derived-mode-p 'mpc-songs-mode)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2501 (get-text-property (point) 'mpc-file))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2502 (list (cons (get-text-property (point) 'mpc-file)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2503 (get-text-property (point) 'mpc-file-pos))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2504 ((and mpc-tag (not (mpc-tagbrowser-all-p)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2505 (mapcar (lambda (song)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2506 (list (cdr (assq 'file song))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2507 (mpc-cmd-find
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2508 mpc-tag
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2509 (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2510 (line-end-position)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2511 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2512 (error "Unsupported starting position for drag'n'drop gesture")))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2513 (with-current-buffer end-buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2514 (goto-char (posn-point end))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2515 (cond
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2516 ((eq mpc-tag 'Playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2517 ;; Adding elements to a named playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2518 (let ((playlist (if (or (mpc-tagbrowser-all-p)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2519 (and (bolp) (eolp)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2520 (error "Not a playlist")
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2521 (buffer-substring (line-beginning-position)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2522 (line-end-position)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2523 (mpc-cmd-add (mapcar 'car songs) playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2524 (message "Added %d songs to %s" (length songs) playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2525 (if (member playlist
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2526 (cdr (assq 'Playlist (mpc-constraints-get-current))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2527 (mpc-songs-refresh))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2528 ((derived-mode-p 'mpc-songs-mode)
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 ((null mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2531 (error "The songs shown do not belong to a playlist"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2532 ((eq start-buf end-buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2533 ;; Moving songs within the shown playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2534 (let ((dest-pos (get-text-property (point) 'mpc-file-pos)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2535 (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
2536 (message "Moved %d songs" (length songs))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2537 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2538 ;; Adding songs to the shown playlist.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2539 (let ((dest-pos (get-text-property (point) 'mpc-file-pos))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2540 (pl (if (stringp mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2541 (mpc-cmd-find 'Playlist mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2542 (mpc-proc-cmd-to-alist "playlist"))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2543 ;; 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
2544 ;; 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
2545 ;; end, and then move them to their final destination.
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2546 (mpc-cmd-add (mapcar 'car songs) mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2547 (mpc-cmd-move (let ((poss '()))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2548 (dotimes (i (length songs))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2549 (push (+ i (length pl)) poss))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2550 (nreverse poss)) dest-pos mpc-songs-playlist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2551 (message "Added %d songs" (length songs)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2552 (mpc-songs-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2553 (t
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2554 (error "Unsupported drag'n'drop gesture"))))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2555
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2556 ;;; Toplevel ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2557
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2558 (defcustom mpc-frame-alist '((name . "MPC") (tool-bar-lines . 1)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2559 (font . "Sans"))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2560 "Alist of frame parameters for the MPC frame."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2561 :type 'alist)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2562
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2563 ;;;###autoload
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2564 (defun mpc ()
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2565 "Main entry point for MPC."
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2566 (interactive
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2567 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2568 (if current-prefix-arg
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2569 (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
2570 nil))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2571 (let* ((song-buf (mpc-songs-buf))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2572 (song-win (get-buffer-window song-buf 0)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2573 (if song-win
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2574 (select-window song-win)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2575 (if (or (window-dedicated-p (selected-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2576 (window-minibuffer-p))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2577 (ignore-errors (select-frame (make-frame mpc-frame-alist)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2578 (with-current-buffer song-buf
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2579 (set (make-local-variable 'mpc-previous-window-config)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2580 (current-window-configuration))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2581 (let* ((win1 (selected-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2582 (win2 (split-window))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2583 (tags mpc-browser-tags))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2584 (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
2585 (set-window-buffer win2 song-buf)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2586 (set-window-dedicated-p win2 'soft)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2587 (mpc-status-buffer-show)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2588 (while
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2589 (progn
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2590 (set-window-buffer win1 (mpc-tagbrowser-buf (pop tags)))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2591 (set-window-dedicated-p win1 'soft)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2592 tags)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2593 (setq win1 (split-window win1 nil 'horiz)))))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2594 (balance-windows-area))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2595 (mpc-songs-refresh)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2596 (mpc-status-refresh))
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2597
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2598 (provide 'mpc)
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2599
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2600 ;; arch-tag: 4794b2f5-59e6-4f26-b695-650b3e002f37
d810540a6f2b * mpc.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2601 ;;; mpc.el ends here