Refactor reporting code.

This commit is contained in:
Israel Chauca Fuentes
2015-01-05 02:16:09 -05:00
parent ac792c01b6
commit 8e30e70bcd
2 changed files with 101 additions and 132 deletions

View File

@@ -525,147 +525,116 @@ function! delimitMate#BS() " {{{
return "\<BS>" . extra return "\<BS>" . extra
endfunction " }}} delimitMate#BS() endfunction " }}} delimitMate#BS()
function! delimitMate#TestMappings() "{{{ function! delimitMate#Test() "{{{
echom 1 %d _
%d " Check for script options:
let options = sort([ let result = [
\ 'apostrophes', \ 'delimitMate Report',
\ 'autoclose', \ '==================',
\ 'balance_matchpairs', \ '',
\ 'jump_expansion', \ '* Options: ( ) default, (g) global, (b) buffer',
\ 'eol_marker', \ '']
\ 'excluded_ft', for option in sort(keys(s:options[bufnr('%')]))
\ 'excluded_regions', if s:exists(option, 'b')
\ 'expand_cr', let scope = '(b)'
\ 'expand_space', elseif s:exists(option, 'g')
\ 'matchpairs', let scope = '(g)'
\ 'nesting_quotes', else
\ 'quotes', let scope = '( )'
\ 'smart_matchpairs', endif
\ 'smart_quotes', call add(result,
\ 'expand_inside_quotes', \ scope . ' delimitMate_' . option
\]) \ . ' = '
let optoutput = ['delimitMate Report', '==================', '', \ . string(s:g(option)))
\ '* Options: ( ) default, (g) global, (b) buffer','']
for option in options
let scope = s:exists(option, 'b') ? 'b'
\ : s:exists(option, 'g') ? 'g' : ' '
call add(optoutput,
\'(' . scope . ')' . ' delimitMate_' . option . ' = ' . string(s:g(option)))
endfor endfor
call append(line('$'), optoutput + ['--------------------','']) call add(result, '')
" Check if mappings were set. {{{ let option = 'delimitMate_excluded_ft'
let imaps = s:g('right_delims') call add(result,
let imaps += ( s:g('autoclose') ? s:g('left_delims') : [] ) \(exists('g:'.option) ? '(g) ' : '( ) g:') . option . ' = '
let imaps += \. string(get(g:, option, '')))
\ s:g('quotes_list') +
\ s:g('apostrophes_list') +
\ ['<BS>', '<S-BS>', '<S-Tab>', '<Esc>', '<C-G>g']
let imaps += ( s:g('expand_cr') ? ['<CR>'] : [] )
let imaps += ( s:g('expand_space') ? ['<Space>'] : [] )
let imappings = [] call add(result, '--------------------')
for map in imaps call add(result, '')
" Check if mappings were set.
let left_delims = s:g('autoclose') ? s:g('left_delims') : []
let special_keys = ['<BS>', '<S-BS>', '<S-Tab>', '<C-G>g']
if s:g('expand_cr')
call add(special_keys, '<CR>')
endif
if s:g('expand_space')
call add(special_keys, '<Space>')
endif
let maps =
\ s:g('right_delims')
\ + left_delims
\ + s:g('quotes_list')
\ + s:g('apostrophes_list')
\ + special_keys
call add(result, '* Mappings:')
call add(result, '')
for map in maps
let output = '' let output = ''
if map == '|' if map == '|'
let map = '<Bar>' let map = '<Bar>'
endif endif
redir => output | execute "verbose imap ".map | redir END redir => output | execute "verbose imap ".map | redir END
let imappings += split(output, '\n') call extend(result, split(output, '\n'))
endfor endfor
unlet! output call add(result, '--------------------')
let output = ['* Mappings:', ''] + imappings + ['--------------------', ''] call add(result, '')
call append('$', output+['* Showcase:', '']) call add(result, '* Showcase:')
" }}} call add(result, '')
if s:g('autoclose') call setline(1, result)
" {{{ call s:test_mappings(s:g('left_delims'), 1)
for i in range(len(s:g('left_delims'))) call s:test_mappings(s:g('quotes_list'), 0)
exec "normal Go0\<C-D>Open: " . s:g('left_delims')[i]. "|"
exec "normal o0\<C-D>Delete: " . s:g('left_delims')[i] . "\<BS>|" let result = []
exec "normal o0\<C-D>Exit: " . s:g('left_delims')[i] . s:g('right_delims')[i] . "|" redir => setoptions
if s:g('expand_space') == 1 echo " * Vim configuration:\<NL>"
exec "normal o0\<C-D>Space: " . s:g('left_delims')[i] . " |" filetype
exec "normal o0\<C-D>Delete space: " . s:g('left_delims')[i] echo ""
\ . " \<BS>|" set
endif version
if s:g('expand_cr') == 1 redir END
exec "normal o0\<C-D>Car return: " . s:g('left_delims')[i] . call extend(result, split(setoptions,"\n"))
\ "\<CR>|" call add(result, '--------------------')
exec "normal Go0\<C-D>Delete car return: " . s:g('left_delims')[i]
\ . "\<CR>0\<C-D>\<BS>|"
endif
call append(line('$'), '')
endfor
for i in range(len(s:g('quotes_list')))
exec "normal Go0\<C-D>Open: " . s:g('quotes_list')[i] . "|"
exec "normal o0\<C-D>Delete: " . s:g('quotes_list')[i] . "\<BS>|"
exec "normal o0\<C-D>Exit: " . s:g('quotes_list')[i] . s:g('quotes_list')[i] . "|"
if s:g('expand_space') == 1
exec "normal o0\<C-D>Space: " . s:g('quotes_list')[i] . " |"
exec "normal o0\<C-D>Delete space: " . s:g('quotes_list')[i]
\ . " \<BS>|"
endif
if s:g('expand_cr') == 1
exec "normal o0\<C-D>Car return: " . s:g('quotes_list')[i]
\ . "\<CR>|"
exec "normal Go0\<C-D>Delete car return: " . s:g('quotes_list')[i]
\ . "\<CR>\<BS>|"
endif
call append(line('$'), '')
endfor
"}}}
else
"{{{
for i in range(len(s:g('left_delims')))
exec "normal GoOpen & close: " . s:g('left_delims')[i]
\ . s:g('right_delims')[i] . "|"
exec "normal oDelete: " . s:g('left_delims')[i]
\ . s:g('right_delims')[i] . "\<BS>|"
exec "normal oExit: " . s:g('left_delims')[i] . s:g('right_delims')[i]
\ . s:g('right_delims')[i] . "|"
if s:g('expand_space') == 1
exec "normal oSpace: " . s:g('left_delims')[i]
\ . s:g('right_delims')[i] . " |"
exec "normal oDelete space: " . s:g('left_delims')[i]
\ . s:g('right_delims')[i] . " \<BS>|"
endif
if s:g('expand_cr') == 1
exec "normal oCar return: " . s:g('left_delims')[i]
\ . s:g('right_delims')[i] . "\<CR>|"
exec "normal GoDelete car return: " . s:g('left_delims')[i]
\ . s:g('right_delims')[i] . "\<CR>\<BS>|"
endif
call append(line('$'), '')
endfor
for i in range(len(s:g('quotes_list')))
exec "normal GoOpen & close: " . s:g('quotes_list')[i]
\ . s:g('quotes_list')[i] . "|"
exec "normal oDelete: " . s:g('quotes_list')[i]
\ . s:g('quotes_list')[i] . "\<BS>|"
exec "normal oExit: " . s:g('quotes_list')[i] . s:g('quotes_list')[i]
\ . s:g('quotes_list')[i] . "|"
if s:g('expand_space') == 1
exec "normal oSpace: " . s:g('quotes_list')[i]
\ . s:g('quotes_list')[i] . " |"
exec "normal oDelete space: " . s:g('quotes_list')[i]
\ . s:g('quotes_list')[i] . " \<BS>|"
endif
if s:g('expand_cr') == 1
exec "normal oCar return: " . s:g('quotes_list')[i]
\ . s:g('quotes_list')[i] . "\<CR>|"
exec "normal GoDelete car return: " . s:g('quotes_list')[i]
\ . s:g('quotes_list')[i] . "\<CR>\<BS>|"
endif
call append(line('$'), '')
endfor
endif "}}}
redir => setoptions | set | filetype | version | redir END
call append(line('$'), split(setoptions,"\n")
\ + ['--------------------'])
setlocal nowrap setlocal nowrap
call append('$', result)
call feedkeys("\<Esc>\<Esc>", 'n') call feedkeys("\<Esc>\<Esc>", 'n')
endfunction "}}} endfunction "}}}
function! s:test_mappings(list, is_matchpair) "{{{
let prefix = "normal Go0\<C-D>"
let last = "|"
let open = s:g('autoclose') ? 'Open: ' : 'Open & close: '
for s in a:list
if a:is_matchpair
let pair = s:g('right_delims')[index(s:g('left_delims'), s)]
else
let pair = s
endif
if !s:g('autoclose')
let s .= pair
endif
exec prefix . open . s . last
exec prefix . "Delete: " . s . "\<BS>" . last
exec prefix . "Exit: " . s . pair . last
if s:g('expand_space')
\ && (a:is_matchpair || s:g('expand_inside_quotes'))
exec prefix . "Space: " . s . " " . last
exec prefix . "Delete space: " . s . " \<BS>" . last
endif
if s:g('expand_cr')
\ && (a:is_matchpair || s:g('expand_inside_quotes'))
exec prefix . "Car return: " . s . "\<CR>" . last
exec prefix . "Delete car return: " . s . "\<CR>0\<C-D>\<BS>" . last
endif
call append('$', '')
endfor
endfunction "}}}
" vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2 " vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2

View File

@@ -202,7 +202,7 @@ function! s:Unmap() " {{{
let b:delimitMate_enabled = 0 let b:delimitMate_enabled = 0
endfunction " }}} s:Unmap() endfunction " }}} s:Unmap()
function! s:TestMappingsDo() "{{{ function! s:test() "{{{
if &modified if &modified
let confirm = input("Modified buffer, type \"yes\" to write and proceed " let confirm = input("Modified buffer, type \"yes\" to write and proceed "
\ . "with test: ") ==? 'yes' \ . "with test: ") ==? 'yes'
@@ -210,7 +210,7 @@ function! s:TestMappingsDo() "{{{
return return
endif endif
endif endif
call delimitMate#TestMappings() call delimitMate#Test()
g/\%^$/d g/\%^$/d
0 0
endfunction "}}} endfunction "}}}
@@ -366,7 +366,7 @@ endfunction "}}}
" Let me refresh without re-loading the buffer: " Let me refresh without re-loading the buffer:
command! -bar DelimitMateReload call s:setup(1) command! -bar DelimitMateReload call s:setup(1)
" Quick test: " Quick test:
command! -bar DelimitMateTest call s:TestMappingsDo() command! -bar DelimitMateTest call s:test()
" Switch On/Off: " Switch On/Off:
command! -bar DelimitMateSwitch call s:setup(2) command! -bar DelimitMateSwitch call s:setup(2)
" Enable mappings: " Enable mappings: