Created
November 22, 2011 03:03
-
-
Save igrep/1384774 to your computer and use it in GitHub Desktop.
Really thin wrapper of MPlayer for Vim editor. ref http://www.mplayerhq.hu/DOCS/tech/slave.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Settings | |
let g:vimplayer_mplayer_extra_options = [] | |
let s:vimplayer_pipe_mplayer = {} | |
function! vimplayer#play(...) abort | |
let vimplayer_filenames = a:000 | |
if !empty(s:vimplayer_pipe_mplayer) "mplayer already playing something | |
call s:vimplayer_pipe_mplayer.stdin.write("quit\n") | |
endif | |
"Building the arugment for vimproc#popen2 | |
let popen_arg = [ g:vimplayer_mplayer_path, '-really-quiet', '-msglevel', 'global=4', '-slave'] | |
call extend(popen_arg, g:vimplayer_mplayer_extra_options) | |
call add(popen_arg, '--') | |
call extend(popen_arg, vimplayer_filenames) | |
let s:vimplayer_pipe_mplayer = vimproc#popen3(popen_arg) | |
return '' | |
endfunction | |
function! s:abort_if_non_mplayer() abort | |
if empty(s:vimplayer_pipe_mplayer) | |
echoerr 'MPlayer is not started yet! Try :VimPlayer <filename>...' | |
endif | |
endfunction | |
function! vimplayer#command(command) abort | |
call s:abort_if_non_mplayer() | |
"see http://www.mplayerhq.hu/DOCS/tech/slave.txt | |
call s:vimplayer_pipe_mplayer.stdin.write(a:command . "\n") | |
return '' | |
endfunction | |
function! vimplayer#get_property(prop_name) abort | |
call s:abort_if_non_mplayer() | |
call s:vimplayer_pipe_mplayer.stdin.write('get_property ' . a:prop_name . "\n") | |
let pos_ans = -1 | |
let output = s:vimplayer_pipe_mplayer.stdout.read_line() | |
return substitute(output, '^ANS_.*=', '', '') | |
endfunction | |
autocmd! VimLeave * call s:vimplayer_pipe_mplayer.stdin.write("quit\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Settings | |
let g:vimplayer_bookmarks_filename = '.vimplayer_bookmarks' | |
"Initial process | |
let s:playing_filepath = vimplayer#get_property('path') | |
let s:saved_position = '' | |
let s:bookmarks_dict = {} | |
if filereadable(g:vimplayer_bookmarks_filename) | |
let s:bookmarks_dict = eval(join(readfile(g:vimplayer_bookmarks_filename, 'b'), '')) | |
if has_key(s:bookmarks_dict, s:playing_filepath) | |
let s:saved_position = s:bookmarks_dict[s:playing_filepath] | |
endif | |
endif | |
function! vimplayer_bookmark#resume() | |
if s:saved_position != '' | |
let command = 'seek ' . s:saved_position . ' 2' | |
call vimplayer#command( command ) | |
else | |
echomsg "You haven't bookmarked any position of " . s:playing_filepath | |
endif | |
endfunction | |
function! vimplayer_bookmark#bookmark() | |
let s:saved_position = vimplayer#get_property('time_pos') | |
let s:bookmarks_dict[s:playing_filepath] = s:saved_position | |
let data_lines = split( string( s:bookmarks_dict ), "\n" ) | |
call writefile( data_lines, g:vimplayer_bookmarks_filename, 'b' ) | |
echo 'Added bookmark at ' . s:saved_position '.' | |
return '' | |
endfunction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let g:vimplayer_loaded = 1 | |
let g:vimplayer_mplayer_path = '/usr/bin/mplayer' | |
command! -nargs=+ -complete=file VimPlayer call vimplayer#play( <f-args> ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
noremap <expr> <F2> vimplayer#command('seek -10') | |
inoremap <expr> <F2> vimplayer#command('seek -10') | |
noremap <expr> <F3> vimplayer#command('pause') | |
inoremap <expr> <F3> vimplayer#command('pause') | |
noremap <expr> <F4> vimplayer#command('seek +10') | |
inoremap <expr> <F4> vimplayer#command('seek +10') | |
noremap <F5> :VimPlayer | |
inoremap <F5> <ESC>:VimPlayer | |
noremap <expr> <F9> vimplayer_bookmark#bookmark() | |
inoremap <expr> <F9> vimplayer_bookmark#bookmark() | |
noremap <expr> <F10> vimplayer_bookmark#resume() | |
inoremap <expr> <F10> vimplayer_bookmark#resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment