Allow jumping over quote on the right if in ignored syntax group

This commit is contained in:
Israel Chauca Fuentes
2017-02-12 23:48:13 -05:00
parent cb6866f1c3
commit e48ea9f852
2 changed files with 61 additions and 46 deletions

View File

@@ -170,6 +170,10 @@ endfunction
function! delimitMate#TextChangedI(...) "{{{1 function! delimitMate#TextChangedI(...) "{{{1
echom 'TCI: ' . s:info.cur.line echom 'TCI: ' . s:info.cur.line
if pumvisible()
echom 20
return 0
endif
if !s:option('enabled') if !s:option('enabled')
echom 21 echom 21
return return
@@ -231,65 +235,69 @@ endfunction
" vim: sw=2 et " vim: sw=2 et
function! delimitMate#InsertCharPre(str) "{{{1 function! delimitMate#InsertCharPre(str) "{{{1
echom 'ICP ' . string(a:str) . ': ' . get(s:info, 'cur', {'line': ''}).line
if s:info.skip_icp if s:info.skip_icp
" iabbrev fires this event for every char and the trigger " iabbrev fires this event for every char and the trigger
echom 01 echom 01
return 0 return 0
endif endif
if pumvisible()
echom 2
return 0
endif
if s:info.nesting if s:info.nesting
echom 02 echom 03
let s:info.nesting -= 1 let s:info.nesting -= 1
return 0 return 0
endif endif
let s:info.skip_icp = 1 let s:info.skip_icp = 1
if !s:option('enabled') if !s:option('enabled')
echom 03
return 0
endif
let synstack = join(map(synstack(line('.'), col('.')), 'tolower(synIDattr(v:val, "name"))'), ',')
if !empty(filter(s:option('excluded_regions'), 'stridx(synstack, tolower(v:val)) >= 0'))
echom 04 echom 04
return 0 return 0
endif endif
return map(split(a:str, '\zs'), 's:handle_vchar(v:val)') let synstack = join(map(synstack(line('.'), col('.')), 'tolower(synIDattr(v:val, "name"))'), ',')
endfunction let s:info.is_ignored_syn = !empty(filter(s:option('excluded_regions'), 'stridx(synstack, tolower(v:val)) >= 0'))
echom 9
function! s:handle_vchar(str) "{{{1 for char in split(a:str, '\zs')
echom 'ICP ' . string(a:str) . ': ' . get(s:info, 'cur', {'line': ''}).line let keys = ''
let s:info.char = a:str let s:info.char = char
let opts = s:defaults.consolidate() let opts = s:defaults.consolidate()
if s:info.cur.is_escaped() if s:info.cur.is_escaped()
echom 12 echom 12
return return
elseif a:str == ' ' elseif !empty(filter(copy(opts.quotes), 'v:val ==# char'))
echom 13 echom 15
let keys = s:keys4space(s:info, opts) let keys = s:keys4quote(char, s:info, opts)
elseif a:str == "\<C-]>" let s:info.nesting = strchars(matchstr(keys, '^[^[:cntrl:]]*'))
let prev_line = line('.') == 1 ? '' : getline(line('.') - 1) let s:info.nesting = s:info.nesting < 3 ? 0 : s:info.nesting
let next_line = line('.') == line('$') ? '' : getline(line('.') + 1) elseif s:info.is_ignored_syn
echom 14 echom 9
let keys = s:keys4cr(prev_line, next_line, s:info, opts) return
elseif !empty(filter(copy(opts.quotes), 'v:val ==# a:str')) elseif char == ' '
echom 15 echom 13
let keys = s:keys4quote(a:str, s:info, opts) let keys = s:keys4space(s:info, opts)
let s:info.nesting = strchars(matchstr(keys, '^[^[:cntrl:]]*')) elseif char == "\<C-]>"
let s:info.nesting = s:info.nesting < 3 ? 0 : s:info.nesting let prev_line = line('.') == 1 ? '' : getline(line('.') - 1)
elseif !empty(filter(copy(opts.pairs), 'strcharpart(v:val, 0, 1) ==# a:str')) let next_line = line('.') == line('$') ? '' : getline(line('.') + 1)
echom 16 echom 14
let pair = get(filter(copy(opts.pairs), 'strcharpart(v:val, 0, 1) ==# a:str'), 0, '') let keys = s:keys4cr(prev_line, next_line, s:info, opts)
let keys = s:keys4left(a:str, pair, s:info, opts) elseif !empty(filter(copy(opts.pairs), 'strcharpart(v:val, 0, 1) ==# char'))
"echom strtrans(keys) echom 16
"echom string(pair) let pair = get(filter(copy(opts.pairs), 'strcharpart(v:val, 0, 1) ==# char'), 0, '')
elseif !empty(filter(copy(opts.pairs), 'strcharpart(v:val, 1, 1) ==# a:str')) let keys = s:keys4left(char, pair, s:info, opts)
let pair = get(filter(copy(opts.pairs), 'strcharpart(v:val, 1, 1) ==# a:str'), 0, '') "echom strtrans(keys)
let keys = s:keys4right(a:str, pair, s:info, opts) "echom string(pair)
echom 17 elseif !empty(filter(copy(opts.pairs), 'strcharpart(v:val, 1, 1) ==# char'))
echom keys let pair = get(filter(copy(opts.pairs), 'strcharpart(v:val, 1, 1) ==# char'), 0, '')
else let keys = s:keys4right(char, pair, s:info, opts)
echom 18 echom 17
return 0 echom keys
endif else
return feedkeys(keys, 'mti') echom 18
return 0
endif
call feedkeys(keys, 'mti')
endfor
endfunction endfunction
function! s:keys4space(info, opts) "{{{1 function! s:keys4space(info, opts) "{{{1
@@ -377,6 +385,9 @@ function! s:keys4quote(char, info, opts) "{{{1
echom 53 echom 53
return "\<Del>" return "\<Del>"
endif endif
if a:info.is_ignored_syn
return ''
endif
let exprs = a:opts.smart_quotes_base + a:opts.smart_quotes_extra let exprs = a:opts.smart_quotes_base + a:opts.smart_quotes_extra
if a:opts.autoclose && a:opts.smart_quotes if a:opts.autoclose && a:opts.smart_quotes
\&& s:any_is_true(exprs, a:info, a:opts) \&& s:any_is_true(exprs, a:info, a:opts)

View File

@@ -12,7 +12,7 @@
call vimtest#StartTap() call vimtest#StartTap()
call vimtap#Plan(142) call vimtap#Plan(147)
let g:delimitMate_autoclose = 1 let g:delimitMate_autoclose = 1
@@ -99,6 +99,10 @@ iunabb def
set ft=vim set ft=vim
call DMTest_single('', 'i"', '"') call DMTest_single('', 'i"', '"')
syntax on
" Allow quote to exit from string when disabled by syntax group.
call DMTest_quotes("'abc'", "$i'x", "'abc'x")
set ft= set ft=
call vimtest#Quit() call vimtest#Quit()