Update cse and dse, add cs$ and ds$ (#351)

This commit is contained in:
Karl Yngve Lervåg 2016-02-13 22:45:14 +01:00
parent afc7a86833
commit daed29fe96
2 changed files with 34 additions and 24 deletions

View File

@ -342,6 +342,8 @@ function! s:init_mappings() " {{{1
call s:map('n', '<localleader>lx', '<plug>(vimtex-reload)') call s:map('n', '<localleader>lx', '<plug>(vimtex-reload)')
call s:map('n', '<localleader>ls', '<plug>(vimtex-toggle-main)') call s:map('n', '<localleader>ls', '<plug>(vimtex-toggle-main)')
call s:map('n', 'ds$', '<plug>(vimtex-env-delete-math)')
call s:map('n', 'cs$', '<plug>(vimtex-env-change-math)')
call s:map('n', 'dse', '<plug>(vimtex-env-delete)') call s:map('n', 'dse', '<plug>(vimtex-env-delete)')
call s:map('n', 'cse', '<plug>(vimtex-env-change)') call s:map('n', 'cse', '<plug>(vimtex-env-change)')
call s:map('n', 'tse', '<plug>(vimtex-env-toggle-star)') call s:map('n', 'tse', '<plug>(vimtex-env-toggle-star)')

View File

@ -27,10 +27,16 @@ endfunction
" }}}1 " }}}1
function! vimtex#env#init_buffer() " {{{1 function! vimtex#env#init_buffer() " {{{1
nnoremap <silent><buffer> <plug>(vimtex-env-delete) nnoremap <silent><buffer> <plug>(vimtex-env-delete)
\ :call vimtex#env#change('')<cr> \ :call vimtex#env#delete('env')<cr>
nnoremap <silent><buffer> <plug>(vimtex-env-change) nnoremap <silent><buffer> <plug>(vimtex-env-change)
\ :call vimtex#env#change_prompt()<cr> \ :call vimtex#env#change_prompt('env')<cr>
nnoremap <silent><buffer> <plug>(vimtex-env-delete-math)
\ :call vimtex#env#delete('env_math')<cr>
nnoremap <silent><buffer> <plug>(vimtex-env-change-math)
\ :call vimtex#env#change_prompt('env_math')<cr>
nnoremap <silent><buffer> <plug>(vimtex-env-toggle-star) nnoremap <silent><buffer> <plug>(vimtex-env-toggle-star)
\ :call vimtex#env#toggle_star()<cr> \ :call vimtex#env#toggle_star()<cr>
@ -38,9 +44,7 @@ endfunction
" }}}1 " }}}1
function! vimtex#env#change(new) " {{{1 function! vimtex#env#change(open, close, new) " {{{1
let [l:open, l:close] = vimtex#delim#get_surrounding('env_all')
" "
" Set target environment " Set target environment
" "
@ -59,27 +63,27 @@ function! vimtex#env#change(new) " {{{1
let l:end = '\end{' . a:new . '}' let l:end = '\end{' . a:new . '}'
endif endif
let l:line = getline(l:open.lnum) let l:line = getline(a:open.lnum)
call setline(l:open.lnum, call setline(a:open.lnum,
\ strpart(l:line, 0, l:open.cnum-1) \ strpart(l:line, 0, a:open.cnum-1)
\ . l:beg \ . l:beg
\ . strpart(l:line, l:open.cnum + len(l:open.match) - 1)) \ . strpart(l:line, a:open.cnum + len(a:open.match) - 1))
let l:c1 = l:close.cnum let l:c1 = a:close.cnum
let l:c2 = l:close.cnum + len(l:close.match) - 1 let l:c2 = a:close.cnum + len(a:close.match) - 1
if l:open.lnum == l:close.lnum if a:open.lnum == a:close.lnum
let n = len(l:beg) - len(l:open.match) let n = len(l:beg) - len(a:open.match)
let l:c1 += n let l:c1 += n
let l:c2 += n let l:c2 += n
let pos = getpos('.') let pos = getpos('.')
if pos[2] > l:open.cnum + len(l:open.match) - 1 if pos[2] > a:open.cnum + len(a:open.match) - 1
let pos[2] += n let pos[2] += n
call setpos('.', pos) call setpos('.', pos)
endif endif
endif endif
let l:line = getline(l:close.lnum) let l:line = getline(a:close.lnum)
call setline(l:close.lnum, call setline(a:close.lnum,
\ strpart(l:line, 0, l:c1-1) . l:end . strpart(l:line, l:c2)) \ strpart(l:line, 0, l:c1-1) . l:end . strpart(l:line, l:c2))
if a:new ==# '' if a:new ==# ''
@ -90,24 +94,28 @@ function! vimtex#env#change(new) " {{{1
endif endif
endfunction endfunction
function! vimtex#env#change_prompt() " {{{1 function! vimtex#env#change_prompt(type) " {{{1
let [l:open, l:close] = vimtex#delim#get_surrounding('env_all') let [l:open, l:close] = vimtex#delim#get_surrounding(a:type)
if empty(l:open) | return | endif if empty(l:open) | return | endif
let l:name = get(l:open, 'name', l:open.is_open let l:name = get(l:open, 'name', l:open.is_open
\ ? l:open.match . ' ... ' . l:open.corr \ ? l:open.match . ' ... ' . l:open.corr
\ : l:open.match . ' ... ' . l:open.corr) \ : l:open.match . ' ... ' . l:open.corr)
call vimtex#echo#status(['Change surrounding environment: ', call vimtex#echo#status(['Change surrounding environment: ',
\ ['VimtexWarning', l:name]]) \ ['VimtexWarning', l:name]])
echohl VimtexMsg echohl VimtexMsg
let l:new_env = input('> ', '', 'customlist,' . s:sidwrap('input_complete')) let l:new_env = input('> ', '', 'customlist,' . s:sidwrap('input_complete'))
echohl None echohl None
if empty(l:new_env) | return | endif
if empty(l:new_env) call vimtex#env#change(l:open, l:close, l:new_env)
return endfunction
else
call vimtex#env#change(l:new_env) function! vimtex#env#delete(type) " {{{1
endif let [l:open, l:close] = vimtex#delim#get_surrounding(a:type)
if empty(l:open) | return | endif
call vimtex#env#change(l:open, l:close, '')
endfunction endfunction
function! vimtex#env#toggle_star() " {{{1 function! vimtex#env#toggle_star() " {{{1