" Adapted from unimpaired.vim by Tim Pope. function! s:DoAction(algorithm,type) let sel_save = &selection let cb_save = &clipboard set selection=inclusive clipboard-=unnamed clipboard-=unnamedplus let reg_save = @@ if a:type =~ '^\d\+$' silent exe 'normal! V'.a:type.'$y' elseif a:type =~ '^.$' silent exe "normal! `<" . a:type . "`>y" elseif a:type == 'line' silent exe "normal! '[V']y" elseif a:type == 'block' silent exe "normal! `[\`]y" else silent exe "normal! `[v`]y" endif let repl = s:{a:algorithm}(@@) if type(repl) == 1 call setreg('@', repl, getregtype('@')) normal! gvp endif let @@ = reg_save let &selection = sel_save let &clipboard = cb_save endfunction function! s:ActionOpfunc(type) return s:DoAction(s:encode_algorithm, a:type) endfunction function! s:ActionSetup(algorithm) let s:encode_algorithm = a:algorithm let &opfunc = matchstr(expand(''), '\d\+_').'ActionOpfunc' endfunction function! MapAction(algorithm, key) exe 'nnoremap actions'.a:algorithm. \' :call ActionSetup("'.a:algorithm.'")g@' exe 'xnoremap actions'.a:algorithm. \' :call DoAction("'.a:algorithm.'",visualmode())' exe 'nnoremap actionsLine'.a:algorithm. \' :call DoAction("'.a:algorithm.'",v:count1)' exe 'nmap '.a:key.' actions'.a:algorithm exe 'xmap '.a:key.' actions'.a:algorithm exe 'nmap '.a:key.a:key[strlen(a:key)-1].' actionsLine'.a:algorithm endfunction if !exists("g:vimspeak_args") let g:vimspeak_args="-k30" endif if !exists("g:vimspeak_speed") let g:vimspeak_speed="-s 300" endif if !exists("g:vimspeak_punct") let g:vimspeak_punct="--punct" endif if !exists("g:vimspeak_enabled") let g:vimspeak_enabled=1 endif let s:is_speaking = 0 function! s:Speak(str) if g:vimspeak_enabled != 1 return endif if s:is_speaking == 1 return endif let s:is_speaking = 1 call job_start(["/bin/sh", "-c", \"espeak". \" ".g:vimspeak_args. \" ".g:vimspeak_speed. \" ".g:vimspeak_punct. \" ".shellescape(a:str). \" >/dev/null 2>&1 /dev/null 2>&1 &"]) endfunction function! s:SpeakSpeed() call inputsave() call s:Speak("set new speed") let speed = input('Set new speed: ') call inputrestore() let g:vimspeak_speed="-s ".speed call s:Speak("set to ".speed) endfunction function! s:SpeakPunct() if g:vimspeak_punct == "--punct" let g:vimspeak_punct="" call s:Speak("punctuation off") else let g:vimspeak_punct="--punct" call s:Speak("punctuation on") endif endfunction function! s:SpeakCommandLine() call s:SpeakCancel() call s:Speak(getcmdline()) endfunction call MapAction('Speak','s') nnoremap St :call SpeakToggle() nnoremap Sc :call SpeakCancel() nnoremap Sl :call Speak("line ".line('.')) nnoremap Ss :call SpeakSpeed() nnoremap Sp :call SpeakPunct() nnoremap Sb :call Speak("file ".bufname("%")) autocmd BufEnter * :call Speak('buffer '.bufname("%")) autocmd BufWritePost * :call Speak('wrote '.bufname("%")) autocmd DirChanged * :call Speak('directory '.getcwd()) autocmd InsertEnter * :call Speak('insert mode') autocmd InsertLeave * :call Speak('normal mode') "autocmd CmdlineEnter * :call Speak('e x command') "autocmd CmdlineLeave * :call Speak('normal mode')