Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gokcehan committed Dec 15, 2017
1 parent 17454ec commit 36f72c3
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 446 deletions.
179 changes: 61 additions & 118 deletions autoload/opex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,152 +13,95 @@ function! s:append(text) abort
call append(line("']"), l:out)
endfunction

function opex#execute_op_ft(type, ...)
if a:0
" select the proper text object
function! s:select(count, type)
if a:count " visual mode
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
execute(&filetype . ' ' . @@)
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
endfunction

function opex#append_op_ft(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
call s:append(execute(&filetype . ' ' . @@))
" restore previous window view
function! s:restore()
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
endfunction

function opex#execute_op_pyx(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
execute('pyx ' . @@)
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
function! opex#execute(type, ...)
call s:select(a:0, a:type)
execute(b:opex_cmd . ' ' . @@)
call s:restore()
endfunction

function opex#append_op_pyx(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
call s:append(execute('pyx ' . @@))
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
function! opex#execute_system(type, ...)
call s:select(a:0, a:type)
call system(@@)
call s:restore()
endfunction

function! opex#execute_op_mz(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
execute('mz ' . @@)
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
function! opex#execute_vim(type, ...)
call s:select(a:0, a:type)
execute(@@)
call s:restore()
endfunction

function! opex#append_op_mz(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
call s:append(execute('mz ' . @@))
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
function! opex#append(type, ...)
call s:select(a:0, a:type)
call s:append(execute(b:opex_cmd . ' ' . @@))
call s:restore()
endfunction

function! opex#execute_op_system(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
call system(@@)
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
function! opex#append_system(type, ...)
call s:select(a:0, a:type)
call s:append(system(@@))
call s:restore()
endfunction

function! opex#append_op_system(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
call s:append(system(@@))
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
function! opex#append_vim(type, ...)
call s:select(a:0, a:type)
call s:append(execute(@@))
call s:restore()
endfunction

function! opex#execute_op_vim(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
endif
execute(@@)
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
endif
function! opex#mappings()
nnoremap <buffer> <silent> <plug>(opex-execute)
\ :<c-u>let b:opex_view = winsaveview()
\ \| let &opfunc=b:opex_execute_func<cr>g@
vnoremap <buffer> <silent> <plug>(opex-execute)
\ :<c-u>call function(b:opex_execute_func)(visualmode(), 1)<cr>
nnoremap <buffer> <silent> <plug>(opex-execute-line)
\ :<c-u>let b:opex_view = winsaveview()
\ \| let &opfunc=b:opex_execute_func
\ \| exe 'normal! 'v:count1.'g@_'<cr>
nnoremap <buffer> <silent> <plug>(opex-append)
\ :<c-u>let b:opex_view = winsaveview()
\ \| let &opfunc=b:opex_append_func<cr>g@
vnoremap <buffer> <silent> <plug>(opex-append)
\ :<c-u>call function(b:opex_append_func)(visualmode(), 1)<cr>
nnoremap <buffer> <silent> <plug>(opex-append-line)
\ :<c-u>let b:opex_view = winsaveview()
\ \| let &opfunc=b:opex_append_func
\ \| exe 'normal! 'v:count1.'g@_'<cr>
endfunction

function! opex#append_op_vim(type, ...)
if a:0
silent exe "normal! gvy"
elseif a:type == 'line'
silent exe "normal! '[V']y"
else
silent exe "normal! `[v`]y"
function! opex#bindings()
if !hasmapto('<plug>(opex-execute)')
nmap gx <plug>(opex-execute)
vmap gx <plug>(opex-execute)
endif
call s:append(execute(@@))
if exists('b:opex_view')
call winrestview(b:opex_view)
unlet b:opex_view
if !hasmapto('<plug>(opex-execute-line)')
nmap gxx <plug>(opex-execute-line)
endif
if !hasmapto('<plug>(opex-append)')
nmap gz <plug>(opex-append)
vmap gz <plug>(opex-append)
endif
if !hasmapto('<plug>(opex-append-line)')
nmap gzz <plug>(opex-append-line)
endif
endfunction
47 changes: 6 additions & 41 deletions ftplugin/lua.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if exists("b:loaded_opex_lua")
if exists('b:loaded_opex_lua')
finish
endif
let b:loaded_opex_lua = 1
Expand All @@ -7,44 +7,9 @@ if !has('lua')
finish
endif

nnoremap <buffer> <silent> <plug>(opex-execute)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#execute_op_ft<cr>g@
let b:opex_cmd = 'lua'
let b:opex_execute_func = 'opex#execute'
let b:opex_append_func = 'opex#append'

vnoremap <buffer> <silent> <plug>(opex-execute)
\ :<c-u>call opex#execute_op_ft(visualmode(), 1)<cr>
nnoremap <buffer> <silent> <plug>(opex-execute-line)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#execute_op_ft
\ \| exe 'normal! 'v:count1.'g@_'<cr>
nnoremap <buffer> <silent> <plug>(opex-append)
\ :<c-u>let b:opex_view = winsaveview()
\ \|set opfunc=opex#append_op_ft<cr>g@
vnoremap <buffer> <silent> <plug>(opex-append)
\ :<c-u>call opex#append_op_ft(visualmode(), 1)<cr>
nnoremap <buffer> <silent> <plug>(opex-append-line)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#append_op_ft
\ \| exe 'normal! 'v:count1.'g@_'<cr>
if !hasmapto('<plug>(opex-execute)')
nmap gx <plug>(opex-execute)
vmap gx <plug>(opex-execute)
endif

if !hasmapto('<plug>(opex-execute-line)')
nmap gxx <plug>(opex-execute-line)
endif

if !hasmapto('<plug>(opex-append)')
nmap gz <plug>(opex-append)
vmap gz <plug>(opex-append)
endif

if !hasmapto('<plug>(opex-append-line)')
nmap gzz <plug>(opex-append-line)
endif
call opex#mappings()
call opex#bindings()
47 changes: 6 additions & 41 deletions ftplugin/perl.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if exists("b:loaded_opex_perl")
if exists('b:loaded_opex_perl')
finish
endif
let b:loaded_opex_perl = 1
Expand All @@ -7,44 +7,9 @@ if !has('perl')
finish
endif

nnoremap <buffer> <silent> <plug>(opex-execute)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#execute_op_ft<cr>g@
let b:opex_cmd = 'perl'
let b:opex_execute_func = 'opex#execute'
let b:opex_append_func = 'opex#append'

vnoremap <buffer> <silent> <plug>(opex-execute)
\ :<c-u>call opex#execute_op_ft(visualmode(), 1)<cr>
nnoremap <buffer> <silent> <plug>(opex-execute-line)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#execute_op_ft
\ \| exe 'normal! 'v:count1.'g@_'<cr>
nnoremap <buffer> <silent> <plug>(opex-append)
\ :<c-u>let b:opex_view = winsaveview()
\ \|set opfunc=opex#append_op_ft<cr>g@
vnoremap <buffer> <silent> <plug>(opex-append)
\ :<c-u>call opex#append_op_ft(visualmode(), 1)<cr>
nnoremap <buffer> <silent> <plug>(opex-append-line)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#append_op_ft
\ \| exe 'normal! 'v:count1.'g@_'<cr>
if !hasmapto('<plug>(opex-execute)')
nmap gx <plug>(opex-execute)
vmap gx <plug>(opex-execute)
endif

if !hasmapto('<plug>(opex-execute-line)')
nmap gxx <plug>(opex-execute-line)
endif

if !hasmapto('<plug>(opex-append)')
nmap gz <plug>(opex-append)
vmap gz <plug>(opex-append)
endif

if !hasmapto('<plug>(opex-append-line)')
nmap gzz <plug>(opex-append-line)
endif
call opex#mappings()
call opex#bindings()
47 changes: 6 additions & 41 deletions ftplugin/python.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if exists("b:loaded_opex_python")
if exists('b:loaded_opex_python')
finish
endif
let b:loaded_opex_python = 1
Expand All @@ -7,44 +7,9 @@ if !has('python') && !has('python3')
finish
endif

nnoremap <buffer> <silent> <plug>(opex-execute)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#execute_op_pyx<cr>g@
let b:opex_cmd = 'pythonx'
let b:opex_execute_func = 'opex#execute'
let b:opex_append_func = 'opex#append'

vnoremap <buffer> <silent> <plug>(opex-execute)
\ :<c-u>call opex#execute_op_pyx(visualmode(), 1)<cr>
nnoremap <buffer> <silent> <plug>(opex-execute-line)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#execute_op_pyx
\ \| exe 'normal! 'v:count1.'g@_'<cr>
nnoremap <buffer> <silent> <plug>(opex-append)
\ :<c-u>let b:opex_view = winsaveview()
\ \|set opfunc=opex#append_op_pyx<cr>g@
vnoremap <buffer> <silent> <plug>(opex-append)
\ :<c-u>call opex#append_op_pyx(visualmode(), 1)<cr>
nnoremap <buffer> <silent> <plug>(opex-append-line)
\ :<c-u>let b:opex_view = winsaveview()
\ \| set opfunc=opex#append_op_pyx
\ \| exe 'normal! 'v:count1.'g@_'<cr>
if !hasmapto('<plug>(opex-execute)')
nmap gx <plug>(opex-execute)
vmap gx <plug>(opex-execute)
endif

if !hasmapto('<plug>(opex-execute-line)')
nmap gxx <plug>(opex-execute-line)
endif

if !hasmapto('<plug>(opex-append)')
nmap gz <plug>(opex-append)
vmap gz <plug>(opex-append)
endif

if !hasmapto('<plug>(opex-append-line)')
nmap gzz <plug>(opex-append-line)
endif
call opex#mappings()
call opex#bindings()
Loading

0 comments on commit 36f72c3

Please sign in to comment.