All pastes #1091990 Raw Edit

Miscellany

public text v1 · immutable
#1091990 ·published 2008-08-03 22:24 UTC
rendered paste body
" VIMPD
" MPD client for VIM
" by Skippy the Kangoo <Skippythekangoo AT yahoo DOT fr>
" needed python-mpd library (http://pypi.python.org/pypi/python-mpd/)

if exists('loaded_plugin_vimpd')
    finish
endif
let loaded_plugin_vimpd = 1

if version < 700
    echo "vimpd.vim plugin requires Vim 7 or above" finish
endif

if !has('python')
    s:ErrMsg( "Error: Required vim compiled with +python" )
    finish
endif

python << EOF

import mpd

class MPD(object):

    def __init__(self):
	self.host = "localhost"
	self.port = 6600
	self.client = mpd.MPDClient()

    def connect(self):
	client.connect(host, port)

    def disconnect(self):
	client.disconnect()

    def toggle(self):
	client.toggle()

    def next(self):
	client.next()

    def previous(self):
	client.prev()

mpdClient = MPD()

import vim

def connect():
    try:
	print "Connection en cour..."
	mpdClient.connect()
	print "Connecte au serveur"
    except:
        pass

def disconnect():
    try:
	mpdClient.disconnect()
    except:
	pass

def toggle():
    try:
	mpdClient.toggle()
    except:
	pass

def  next():
    try:
	mpdClient.next()
    except:
	pass

def prev():
    try:
	mpdClient.previous()
    except:
	pass
EOF

fun! MpdConnect()
    python connect()
endfun

fun! MpdDisconnect()
    python disconnect()
endfun

fun! MpdToggle()
    python toggle()
endfun

fun! MpdNext()
    python next()
endfun

fun! MpdPrev()
    Python prev()
endfun

map <F5> <Esc>:call MpdConnect()<CR>