mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-06 20:54:31 +08:00
Use s:get() and s:set() instead of the abbreviated forms.
This commit is contained in:
@@ -12,7 +12,7 @@ if !exists('s:options')
|
|||||||
let s:options = {}
|
let s:options = {}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! s:s(name, value, ...) "{{{
|
function! s:set(name, value, ...) "{{{
|
||||||
let scope = a:0 ? a:1 : 's'
|
let scope = a:0 ? a:1 : 's'
|
||||||
let bufnr = bufnr('%')
|
let bufnr = bufnr('%')
|
||||||
if !exists('s:options[bufnr]')
|
if !exists('s:options[bufnr]')
|
||||||
@@ -29,7 +29,7 @@ function! s:s(name, value, ...) "{{{
|
|||||||
exec 'let ' . name . ' = a:value'
|
exec 'let ' . name . ' = a:value'
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:g(name, ...) "{{{
|
function! s:get(name, ...) "{{{
|
||||||
if a:0 == 2
|
if a:0 == 2
|
||||||
return deepcopy(get(a:2, 'delimitMate_' . a:name, a:1))
|
return deepcopy(get(a:2, 'delimitMate_' . a:name, a:1))
|
||||||
elseif a:0 == 1
|
elseif a:0 == 1
|
||||||
@@ -54,7 +54,7 @@ endfunction "}}}
|
|||||||
function! s:is_jump(...) "{{{
|
function! s:is_jump(...) "{{{
|
||||||
" Returns 1 if the next character is a closing delimiter.
|
" Returns 1 if the next character is a closing delimiter.
|
||||||
let char = s:get_char(0)
|
let char = s:get_char(0)
|
||||||
let list = s:g('right_delims') + s:g('quotes_list')
|
let list = s:get('right_delims') + s:get('quotes_list')
|
||||||
|
|
||||||
" Closing delimiter on the right.
|
" Closing delimiter on the right.
|
||||||
if (!a:0 && index(list, char) > -1)
|
if (!a:0 && index(list, char) > -1)
|
||||||
@@ -64,25 +64,25 @@ function! s:is_jump(...) "{{{
|
|||||||
|
|
||||||
" Closing delimiter with space expansion.
|
" Closing delimiter with space expansion.
|
||||||
let nchar = s:get_char(1)
|
let nchar = s:get_char(1)
|
||||||
if !a:0 && s:g('expand_space') && char == " "
|
if !a:0 && s:get('expand_space') && char == " "
|
||||||
if index(list, nchar) > -1
|
if index(list, nchar) > -1
|
||||||
return 2
|
return 2
|
||||||
endif
|
endif
|
||||||
elseif a:0 && s:g('expand_space') && nchar == a:1 && char == ' '
|
elseif a:0 && s:get('expand_space') && nchar == a:1 && char == ' '
|
||||||
return 3
|
return 3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !s:g('jump_expansion')
|
if !s:get('jump_expansion')
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Closing delimiter with CR expansion.
|
" Closing delimiter with CR expansion.
|
||||||
let uchar = matchstr(getline(line('.') + 1), '^\s*\zs\S')
|
let uchar = matchstr(getline(line('.') + 1), '^\s*\zs\S')
|
||||||
if !a:0 && s:g('expand_cr') && char == ""
|
if !a:0 && s:get('expand_cr') && char == ""
|
||||||
if index(list, uchar) > -1
|
if index(list, uchar) > -1
|
||||||
return 4
|
return 4
|
||||||
endif
|
endif
|
||||||
elseif a:0 && s:g('expand_cr') && uchar == a:1
|
elseif a:0 && s:get('expand_cr') && uchar == a:1
|
||||||
return 5
|
return 5
|
||||||
endif
|
endif
|
||||||
return 0
|
return 0
|
||||||
@@ -123,14 +123,14 @@ function! s:is_cr_expansion(...) " {{{
|
|||||||
let nchar = getline(line('.')-1)[-1:]
|
let nchar = getline(line('.')-1)[-1:]
|
||||||
let schar = matchstr(getline(line('.')+1), '^\s*\zs\S')
|
let schar = matchstr(getline(line('.')+1), '^\s*\zs\S')
|
||||||
let isEmpty = a:0 ? getline('.') =~ '^\s*$' : empty(getline('.'))
|
let isEmpty = a:0 ? getline('.') =~ '^\s*$' : empty(getline('.'))
|
||||||
if index(s:g('left_delims'), nchar) > -1
|
if index(s:get('left_delims'), nchar) > -1
|
||||||
\ && index(s:g('left_delims'), nchar)
|
\ && index(s:get('left_delims'), nchar)
|
||||||
\ == index(s:g('right_delims'), schar)
|
\ == index(s:get('right_delims'), schar)
|
||||||
\ && isEmpty
|
\ && isEmpty
|
||||||
return 1
|
return 1
|
||||||
elseif index(s:g('quotes_list'), nchar) > -1
|
elseif index(s:get('quotes_list'), nchar) > -1
|
||||||
\ && index(s:g('quotes_list'), nchar)
|
\ && index(s:get('quotes_list'), nchar)
|
||||||
\ == index(s:g('quotes_list'), schar)
|
\ == index(s:get('quotes_list'), schar)
|
||||||
\ && isEmpty
|
\ && isEmpty
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
@@ -147,14 +147,14 @@ function! s:is_space_expansion() " {{{
|
|||||||
\ == s:get_char(0)
|
\ == s:get_char(0)
|
||||||
\ && s:get_char(-1) == " ")
|
\ && s:get_char(-1) == " ")
|
||||||
|
|
||||||
if index(s:g('left_delims'), pchar) > -1 &&
|
if index(s:get('left_delims'), pchar) > -1 &&
|
||||||
\ index(s:g('left_delims'), pchar)
|
\ index(s:get('left_delims'), pchar)
|
||||||
\ == index(s:g('right_delims'), nchar) &&
|
\ == index(s:get('right_delims'), nchar) &&
|
||||||
\ isSpaces
|
\ isSpaces
|
||||||
return 1
|
return 1
|
||||||
elseif index(s:g('quotes_list'), pchar) > -1 &&
|
elseif index(s:get('quotes_list'), pchar) > -1 &&
|
||||||
\ index(s:g('quotes_list'), pchar)
|
\ index(s:get('quotes_list'), pchar)
|
||||||
\ == index(s:g('quotes_list'), nchar) &&
|
\ == index(s:get('quotes_list'), nchar) &&
|
||||||
\ isSpaces
|
\ isSpaces
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
@@ -165,18 +165,18 @@ endfunction " }}} IsSpaceExpansion()
|
|||||||
function! s:is_empty_matchpair() "{{{
|
function! s:is_empty_matchpair() "{{{
|
||||||
" get char before the cursor.
|
" get char before the cursor.
|
||||||
let open = s:get_char(-1)
|
let open = s:get_char(-1)
|
||||||
let idx = index(s:g('left_delims'), open)
|
let idx = index(s:get('left_delims'), open)
|
||||||
if idx == -1
|
if idx == -1
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
let close = get(s:g('right_delims'), idx, '')
|
let close = get(s:get('right_delims'), idx, '')
|
||||||
return close ==# s:get_char(0)
|
return close ==# s:get_char(0)
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:is_empty_quotes() "{{{
|
function! s:is_empty_quotes() "{{{
|
||||||
" get char before the cursor.
|
" get char before the cursor.
|
||||||
let quote = s:get_char(-1)
|
let quote = s:get_char(-1)
|
||||||
let idx = index(s:g('quotes_list'), quote)
|
let idx = index(s:get('quotes_list'), quote)
|
||||||
if idx == -1
|
if idx == -1
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
@@ -197,11 +197,11 @@ function! s:get_syn_name() "{{{
|
|||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
function! s:is_forbidden(char) "{{{
|
function! s:is_forbidden(char) "{{{
|
||||||
if !s:g('excluded_regions_enabled')
|
if !s:get('excluded_regions_enabled')
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
let region = s:get_syn_name()
|
let region = s:get_syn_name()
|
||||||
return index(s:g('excluded_regions_list'), region) >= 0
|
return index(s:get('excluded_regions_list'), region) >= 0
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:balance_matchpairs(char) "{{{
|
function! s:balance_matchpairs(char) "{{{
|
||||||
@@ -214,7 +214,7 @@ function! s:balance_matchpairs(char) "{{{
|
|||||||
let col = s:cursor_idx() - 1
|
let col = s:cursor_idx() - 1
|
||||||
let col = col >= 0 ? col : 0
|
let col = col >= 0 ? col : 0
|
||||||
let list = split(line, '\zs')
|
let list = split(line, '\zs')
|
||||||
let left = s:g('left_delims')[index(s:g('right_delims'), a:char)]
|
let left = s:get('left_delims')[index(s:get('right_delims'), a:char)]
|
||||||
let right = a:char
|
let right = a:char
|
||||||
let opening = 0
|
let opening = 0
|
||||||
let closing = 0
|
let closing = 0
|
||||||
@@ -243,7 +243,7 @@ endfunction "}}}
|
|||||||
|
|
||||||
function! s:is_smart_quote(char) "{{{
|
function! s:is_smart_quote(char) "{{{
|
||||||
" TODO: Allow using a:char in the pattern.
|
" TODO: Allow using a:char in the pattern.
|
||||||
let tmp = s:g('smart_quotes')
|
let tmp = s:get('smart_quotes')
|
||||||
if empty(tmp)
|
if empty(tmp)
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
@@ -258,11 +258,11 @@ function! s:is_smart_quote(char) "{{{
|
|||||||
endfunction "delimitMate#SmartQuote }}}
|
endfunction "delimitMate#SmartQuote }}}
|
||||||
|
|
||||||
function! delimitMate#Set(...) "{{{
|
function! delimitMate#Set(...) "{{{
|
||||||
return call('s:s', a:000)
|
return call('s:set', a:000)
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! delimitMate#Get(...) "{{{
|
function! delimitMate#Get(...) "{{{
|
||||||
return call('s:g', a:000)
|
return call('s:get', a:000)
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! delimitMate#ShouldJump(...) "{{{
|
function! delimitMate#ShouldJump(...) "{{{
|
||||||
@@ -273,14 +273,14 @@ function! delimitMate#IsEmptyPair(str) "{{{
|
|||||||
if strlen(substitute(a:str, ".", "x", "g")) != 2
|
if strlen(substitute(a:str, ".", "x", "g")) != 2
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
let idx = index(s:g('left_delims'), matchstr(a:str, '^.'))
|
let idx = index(s:get('left_delims'), matchstr(a:str, '^.'))
|
||||||
if idx > -1 &&
|
if idx > -1 &&
|
||||||
\ s:g('right_delims')[idx] == matchstr(a:str, '.$')
|
\ s:get('right_delims')[idx] == matchstr(a:str, '.$')
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
let idx = index(s:g('quotes_list'), matchstr(a:str, '^.'))
|
let idx = index(s:get('quotes_list'), matchstr(a:str, '^.'))
|
||||||
if idx > -1 &&
|
if idx > -1 &&
|
||||||
\ s:g('quotes_list')[idx] == matchstr(a:str, '.$')
|
\ s:get('quotes_list')[idx] == matchstr(a:str, '.$')
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
return 0
|
return 0
|
||||||
@@ -327,25 +327,25 @@ function! delimitMate#SkipDelim(char) "{{{
|
|||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! delimitMate#ParenDelim(right) " {{{
|
function! delimitMate#ParenDelim(right) " {{{
|
||||||
let left = s:g('left_delims')[index(s:g('right_delims'),a:right)]
|
let left = s:get('left_delims')[index(s:get('right_delims'),a:right)]
|
||||||
if s:is_forbidden(a:right)
|
if s:is_forbidden(a:right)
|
||||||
return left
|
return left
|
||||||
endif
|
endif
|
||||||
" Try to balance matchpairs
|
" Try to balance matchpairs
|
||||||
if s:g('balance_matchpairs') &&
|
if s:get('balance_matchpairs') &&
|
||||||
\ s:balance_matchpairs(a:right) < 0
|
\ s:balance_matchpairs(a:right) < 0
|
||||||
return left
|
return left
|
||||||
endif
|
endif
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
let col = col('.')-2
|
let col = col('.')-2
|
||||||
if s:g('smart_matchpairs') != ''
|
if s:get('smart_matchpairs') != ''
|
||||||
let smart_matchpairs = substitute(s:g('smart_matchpairs'), '\\!', left, 'g')
|
let smart_matchpairs = substitute(s:get('smart_matchpairs'), '\\!', left, 'g')
|
||||||
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:right, 'g')
|
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:right, 'g')
|
||||||
if line[col+1:] =~ smart_matchpairs
|
if line[col+1:] =~ smart_matchpairs
|
||||||
return left
|
return left
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let tail = len(line) == (col + 1) ? s:g('eol_marker') : ''
|
let tail = len(line) == (col + 1) ? s:get('eol_marker') : ''
|
||||||
"if (col) < 0
|
"if (col) < 0
|
||||||
" call setline('.',a:right.line)
|
" call setline('.',a:right.line)
|
||||||
"endif
|
"endif
|
||||||
@@ -358,7 +358,7 @@ function! delimitMate#QuoteDelim(char) "{{{
|
|||||||
endif
|
endif
|
||||||
let char_at = s:get_char(0)
|
let char_at = s:get_char(0)
|
||||||
let char_before = s:get_char(-1)
|
let char_before = s:get_char(-1)
|
||||||
let nesting_on = index(s:g('nesting_quotes'), a:char) > -1
|
let nesting_on = index(s:get('nesting_quotes'), a:char) > -1
|
||||||
let left_q = nesting_on ? s:lquote(a:char) : 0
|
let left_q = nesting_on ? s:lquote(a:char) : 0
|
||||||
if nesting_on && left_q > 1
|
if nesting_on && left_q > 1
|
||||||
" Nesting quotes.
|
" Nesting quotes.
|
||||||
@@ -377,18 +377,18 @@ function! delimitMate#QuoteDelim(char) "{{{
|
|||||||
" Seems like a smart quote, insert a single char.
|
" Seems like a smart quote, insert a single char.
|
||||||
return a:char
|
return a:char
|
||||||
elseif (char_before == a:char && char_at != a:char)
|
elseif (char_before == a:char && char_at != a:char)
|
||||||
\ && !empty(s:g('smart_quotes'))
|
\ && !empty(s:get('smart_quotes'))
|
||||||
" Seems like we have an unbalanced quote, insert one quotation
|
" Seems like we have an unbalanced quote, insert one quotation
|
||||||
" mark and jump to the middle.
|
" mark and jump to the middle.
|
||||||
return a:char . "\<Left>"
|
return a:char . "\<Left>"
|
||||||
else
|
else
|
||||||
" Insert a pair and jump to the middle.
|
" Insert a pair and jump to the middle.
|
||||||
let sufix = ''
|
let sufix = ''
|
||||||
if !empty(s:g('eol_marker')) && col('.') - 1 == len(getline('.'))
|
if !empty(s:get('eol_marker')) && col('.') - 1 == len(getline('.'))
|
||||||
let idx = len(s:g('eol_marker')) * -1
|
let idx = len(s:get('eol_marker')) * -1
|
||||||
let marker = getline('.')[idx : ]
|
let marker = getline('.')[idx : ]
|
||||||
let has_marker = marker == s:g('eol_marker')
|
let has_marker = marker == s:get('eol_marker')
|
||||||
let sufix = !has_marker ? s:g('eol_marker') : ''
|
let sufix = !has_marker ? s:get('eol_marker') : ''
|
||||||
endif
|
endif
|
||||||
return a:char . a:char . "\<Left>"
|
return a:char . a:char . "\<Left>"
|
||||||
endif
|
endif
|
||||||
@@ -438,8 +438,8 @@ function! delimitMate#JumpMany() " {{{
|
|||||||
let rights = ""
|
let rights = ""
|
||||||
let found = 0
|
let found = 0
|
||||||
for char in line
|
for char in line
|
||||||
if index(s:g('quotes_list'), char) >= 0 ||
|
if index(s:get('quotes_list'), char) >= 0 ||
|
||||||
\ index(s:g('right_delims'), char) >= 0
|
\ index(s:get('right_delims'), char) >= 0
|
||||||
let rights .= "\<Right>"
|
let rights .= "\<Right>"
|
||||||
let found = 1
|
let found = 1
|
||||||
elseif found == 0
|
elseif found == 0
|
||||||
@@ -461,9 +461,9 @@ function! delimitMate#ExpandReturn() "{{{
|
|||||||
endif
|
endif
|
||||||
let escaped = s:cursor_idx() >= 2
|
let escaped = s:cursor_idx() >= 2
|
||||||
\ && s:get_char(-2) == '\'
|
\ && s:get_char(-2) == '\'
|
||||||
let expand_right_matchpair = s:g('expand_cr') == 2
|
let expand_right_matchpair = s:get('expand_cr') == 2
|
||||||
\ && index(s:g('right_delims'), s:get_char(0)) > -1
|
\ && index(s:get('right_delims'), s:get_char(0)) > -1
|
||||||
let expand_inside_quotes = s:g('expand_inside_quotes')
|
let expand_inside_quotes = s:get('expand_inside_quotes')
|
||||||
\ && s:is_empty_quotes()
|
\ && s:is_empty_quotes()
|
||||||
\ && !escaped
|
\ && !escaped
|
||||||
if !pumvisible()
|
if !pumvisible()
|
||||||
@@ -496,7 +496,7 @@ function! delimitMate#ExpandSpace() "{{{
|
|||||||
endif
|
endif
|
||||||
let escaped = s:cursor_idx() >= 2
|
let escaped = s:cursor_idx() >= 2
|
||||||
\ && s:get_char(-2) == '\'
|
\ && s:get_char(-2) == '\'
|
||||||
let expand_inside_quotes = s:g('expand_inside_quotes')
|
let expand_inside_quotes = s:get('expand_inside_quotes')
|
||||||
\ && s:is_empty_quotes()
|
\ && s:is_empty_quotes()
|
||||||
\ && !escaped
|
\ && !escaped
|
||||||
if s:is_empty_matchpair() || expand_inside_quotes
|
if s:is_empty_matchpair() || expand_inside_quotes
|
||||||
@@ -545,7 +545,7 @@ function! delimitMate#Test() "{{{
|
|||||||
call add(result,
|
call add(result,
|
||||||
\ scope . ' delimitMate_' . option
|
\ scope . ' delimitMate_' . option
|
||||||
\ . ' = '
|
\ . ' = '
|
||||||
\ . string(s:g(option)))
|
\ . string(s:get(option)))
|
||||||
endfor
|
endfor
|
||||||
call add(result, '')
|
call add(result, '')
|
||||||
|
|
||||||
@@ -558,19 +558,19 @@ function! delimitMate#Test() "{{{
|
|||||||
call add(result, '')
|
call add(result, '')
|
||||||
|
|
||||||
" Check if mappings were set.
|
" Check if mappings were set.
|
||||||
let left_delims = s:g('autoclose') ? s:g('left_delims') : []
|
let left_delims = s:get('autoclose') ? s:get('left_delims') : []
|
||||||
let special_keys = ['<BS>', '<S-BS>', '<S-Tab>', '<C-G>g']
|
let special_keys = ['<BS>', '<S-BS>', '<S-Tab>', '<C-G>g']
|
||||||
if s:g('expand_cr')
|
if s:get('expand_cr')
|
||||||
call add(special_keys, '<CR>')
|
call add(special_keys, '<CR>')
|
||||||
endif
|
endif
|
||||||
if s:g('expand_space')
|
if s:get('expand_space')
|
||||||
call add(special_keys, '<Space>')
|
call add(special_keys, '<Space>')
|
||||||
endif
|
endif
|
||||||
let maps =
|
let maps =
|
||||||
\ s:g('right_delims')
|
\ s:get('right_delims')
|
||||||
\ + left_delims
|
\ + left_delims
|
||||||
\ + s:g('quotes_list')
|
\ + s:get('quotes_list')
|
||||||
\ + s:g('apostrophes_list')
|
\ + s:get('apostrophes_list')
|
||||||
\ + special_keys
|
\ + special_keys
|
||||||
|
|
||||||
call add(result, '* Mappings:')
|
call add(result, '* Mappings:')
|
||||||
@@ -589,8 +589,8 @@ function! delimitMate#Test() "{{{
|
|||||||
call add(result, '* Showcase:')
|
call add(result, '* Showcase:')
|
||||||
call add(result, '')
|
call add(result, '')
|
||||||
call setline(1, result)
|
call setline(1, result)
|
||||||
call s:test_mappings(s:g('left_delims'), 1)
|
call s:test_mappings(s:get('left_delims'), 1)
|
||||||
call s:test_mappings(s:g('quotes_list'), 0)
|
call s:test_mappings(s:get('quotes_list'), 0)
|
||||||
|
|
||||||
let result = []
|
let result = []
|
||||||
redir => setoptions
|
redir => setoptions
|
||||||
@@ -610,26 +610,26 @@ endfunction "}}}
|
|||||||
function! s:test_mappings(list, is_matchpair) "{{{
|
function! s:test_mappings(list, is_matchpair) "{{{
|
||||||
let prefix = "normal Go0\<C-D>"
|
let prefix = "normal Go0\<C-D>"
|
||||||
let last = "|"
|
let last = "|"
|
||||||
let open = s:g('autoclose') ? 'Open: ' : 'Open & close: '
|
let open = s:get('autoclose') ? 'Open: ' : 'Open & close: '
|
||||||
for s in a:list
|
for s in a:list
|
||||||
if a:is_matchpair
|
if a:is_matchpair
|
||||||
let pair = s:g('right_delims')[index(s:g('left_delims'), s)]
|
let pair = s:get('right_delims')[index(s:get('left_delims'), s)]
|
||||||
else
|
else
|
||||||
let pair = s
|
let pair = s
|
||||||
endif
|
endif
|
||||||
if !s:g('autoclose')
|
if !s:get('autoclose')
|
||||||
let s .= pair
|
let s .= pair
|
||||||
endif
|
endif
|
||||||
exec prefix . open . s . last
|
exec prefix . open . s . last
|
||||||
exec prefix . "Delete: " . s . "\<BS>" . last
|
exec prefix . "Delete: " . s . "\<BS>" . last
|
||||||
exec prefix . "Exit: " . s . pair . last
|
exec prefix . "Exit: " . s . pair . last
|
||||||
if s:g('expand_space')
|
if s:get('expand_space')
|
||||||
\ && (a:is_matchpair || s:g('expand_inside_quotes'))
|
\ && (a:is_matchpair || s:get('expand_inside_quotes'))
|
||||||
exec prefix . "Space: " . s . " " . last
|
exec prefix . "Space: " . s . " " . last
|
||||||
exec prefix . "Delete space: " . s . " \<BS>" . last
|
exec prefix . "Delete space: " . s . " \<BS>" . last
|
||||||
endif
|
endif
|
||||||
if s:g('expand_cr')
|
if s:get('expand_cr')
|
||||||
\ && (a:is_matchpair || s:g('expand_inside_quotes'))
|
\ && (a:is_matchpair || s:get('expand_inside_quotes'))
|
||||||
exec prefix . "Car return: " . s . "\<CR>" . last
|
exec prefix . "Car return: " . s . "\<CR>" . last
|
||||||
exec prefix . "Delete car return: " . s . "\<CR>0\<C-D>\<BS>" . last
|
exec prefix . "Delete car return: " . s . "\<CR>0\<C-D>\<BS>" . last
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function! s:option_init(name, default) "{{{
|
|||||||
else
|
else
|
||||||
exec "let value = g:delimitMate_" . a:name
|
exec "let value = g:delimitMate_" . a:name
|
||||||
endif
|
endif
|
||||||
call s:s(a:name, value)
|
call s:set(a:name, value)
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:init() "{{{
|
function! s:init() "{{{
|
||||||
@@ -48,8 +48,8 @@ function! s:init() "{{{
|
|||||||
call s:option_init("autoclose", 1)
|
call s:option_init("autoclose", 1)
|
||||||
" matchpairs
|
" matchpairs
|
||||||
call s:option_init("matchpairs", string(&matchpairs)[1:-2])
|
call s:option_init("matchpairs", string(&matchpairs)[1:-2])
|
||||||
call s:option_init("matchpairs_list", map(split(s:g('matchpairs'), ','), 'split(v:val, '':'')'))
|
call s:option_init("matchpairs_list", map(split(s:get('matchpairs'), ','), 'split(v:val, '':'')'))
|
||||||
let pairs = s:g('matchpairs_list')
|
let pairs = s:get('matchpairs_list')
|
||||||
if len(filter(pairs, 'v:val[0] ==# v:val[1]'))
|
if len(filter(pairs, 'v:val[0] ==# v:val[1]'))
|
||||||
echohl ErrorMsg
|
echohl ErrorMsg
|
||||||
echom 'delimitMate: each member of a pair in delimitMate_matchpairs must be different from each other.'
|
echom 'delimitMate: each member of a pair in delimitMate_matchpairs must be different from each other.'
|
||||||
@@ -57,17 +57,17 @@ function! s:init() "{{{
|
|||||||
echohl Normal
|
echohl Normal
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
call s:option_init("left_delims", map(copy(s:g('matchpairs_list')), 'v:val[0]'))
|
call s:option_init("left_delims", map(copy(s:get('matchpairs_list')), 'v:val[0]'))
|
||||||
call s:option_init("right_delims", map(copy(s:g('matchpairs_list')), 'v:val[1]'))
|
call s:option_init("right_delims", map(copy(s:get('matchpairs_list')), 'v:val[1]'))
|
||||||
" quotes
|
" quotes
|
||||||
call s:option_init("quotes", "\" ' `")
|
call s:option_init("quotes", "\" ' `")
|
||||||
call s:option_init("quotes_list",split(s:g('quotes'), '\s\+'))
|
call s:option_init("quotes_list",split(s:get('quotes'), '\s\+'))
|
||||||
" nesting_quotes
|
" nesting_quotes
|
||||||
call s:option_init("nesting_quotes", [])
|
call s:option_init("nesting_quotes", [])
|
||||||
" excluded_regions
|
" excluded_regions
|
||||||
call s:option_init("excluded_regions", "Comment")
|
call s:option_init("excluded_regions", "Comment")
|
||||||
call s:option_init("excluded_regions_list", split(s:g('excluded_regions'), ',\s*'))
|
call s:option_init("excluded_regions_list", split(s:get('excluded_regions'), ',\s*'))
|
||||||
let enabled = len(s:g('excluded_regions_list')) > 0
|
let enabled = len(s:get('excluded_regions_list')) > 0
|
||||||
call s:option_init("excluded_regions_enabled", enabled)
|
call s:option_init("excluded_regions_enabled", enabled)
|
||||||
" expand_space
|
" expand_space
|
||||||
if exists("b:delimitMate_expand_space") && type(b:delimitMate_expand_space) == type("")
|
if exists("b:delimitMate_expand_space") && type(b:delimitMate_expand_space) == type("")
|
||||||
@@ -110,7 +110,7 @@ function! s:init() "{{{
|
|||||||
call s:option_init("smart_matchpairs", '^\%(\w\|\!\|£\|\$\|_\)')
|
call s:option_init("smart_matchpairs", '^\%(\w\|\!\|£\|\$\|_\)')
|
||||||
" smart_quotes
|
" smart_quotes
|
||||||
" XXX: backward compatibility. Ugly, should go the way of the dodo soon.
|
" XXX: backward compatibility. Ugly, should go the way of the dodo soon.
|
||||||
let quotes = escape(join(s:g('quotes_list'), ''), '\-^[]')
|
let quotes = escape(join(s:get('quotes_list'), ''), '\-^[]')
|
||||||
let default_smart_quotes = '\%(\w\|[^[:punct:][:space:]' . quotes . ']\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[^[:space:][:punct:]' . quotes . ']\)'
|
let default_smart_quotes = '\%(\w\|[^[:punct:][:space:]' . quotes . ']\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[^[:space:][:punct:]' . quotes . ']\)'
|
||||||
if exists('g:delimitMate_smart_quotes') && type(g:delimitMate_smart_quotes) == type(0)
|
if exists('g:delimitMate_smart_quotes') && type(g:delimitMate_smart_quotes) == type(0)
|
||||||
if g:delimitMate_smart_quotes
|
if g:delimitMate_smart_quotes
|
||||||
@@ -134,7 +134,7 @@ function! s:init() "{{{
|
|||||||
call s:option_init("smart_quotes", default_smart_quotes)
|
call s:option_init("smart_quotes", default_smart_quotes)
|
||||||
" apostrophes
|
" apostrophes
|
||||||
call s:option_init("apostrophes", "")
|
call s:option_init("apostrophes", "")
|
||||||
call s:option_init("apostrophes_list", split(s:g('apostrophes'), ":\s*"))
|
call s:option_init("apostrophes_list", split(s:get('apostrophes'), ":\s*"))
|
||||||
" tab2exit
|
" tab2exit
|
||||||
call s:option_init("tab2exit", 1)
|
call s:option_init("tab2exit", 1)
|
||||||
" balance_matchpairs
|
" balance_matchpairs
|
||||||
@@ -145,11 +145,11 @@ function! s:init() "{{{
|
|||||||
return 1
|
return 1
|
||||||
endfunction "}}} Init()
|
endfunction "}}} Init()
|
||||||
|
|
||||||
function! s:g(...) " {{{
|
function! s:get(...) " {{{
|
||||||
return call('delimitMate#Get', a:000)
|
return call('delimitMate#Get', a:000)
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
function! s:s(...) " {{{
|
function! s:set(...) " {{{
|
||||||
return call('delimitMate#Set', a:000)
|
return call('delimitMate#Set', a:000)
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ function! s:Map() "{{{
|
|||||||
set keymap=
|
set keymap=
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
silent! doautocmd <nomodeline> User delimitMate_map
|
silent! doautocmd <nomodeline> User delimitMate_map
|
||||||
if s:g('autoclose')
|
if s:get('autoclose')
|
||||||
call s:AutoClose()
|
call s:AutoClose()
|
||||||
else
|
else
|
||||||
call s:NoAutoClose()
|
call s:NoAutoClose()
|
||||||
@@ -181,10 +181,10 @@ endfunction "}}} Map()
|
|||||||
|
|
||||||
function! s:Unmap() " {{{
|
function! s:Unmap() " {{{
|
||||||
let imaps =
|
let imaps =
|
||||||
\ s:g('right_delims', []) +
|
\ s:get('right_delims', []) +
|
||||||
\ s:g('left_delims', []) +
|
\ s:get('left_delims', []) +
|
||||||
\ s:g('quotes_list', []) +
|
\ s:get('quotes_list', []) +
|
||||||
\ s:g('apostrophes_list', []) +
|
\ s:get('apostrophes_list', []) +
|
||||||
\ ['<BS>', '<C-h>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
|
\ ['<BS>', '<C-h>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
|
||||||
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
|
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
|
||||||
\ ['<C-Left>', '<C-Right>'] +
|
\ ['<C-Left>', '<C-Right>'] +
|
||||||
@@ -269,7 +269,7 @@ endfunction "}}}
|
|||||||
|
|
||||||
function! s:NoAutoClose() "{{{
|
function! s:NoAutoClose() "{{{
|
||||||
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
|
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
|
||||||
for delim in s:g('right_delims') + s:g('quotes_list')
|
for delim in s:get('right_delims') + s:get('quotes_list')
|
||||||
if delim == '|'
|
if delim == '|'
|
||||||
let delim = '<Bar>'
|
let delim = '<Bar>'
|
||||||
endif
|
endif
|
||||||
@@ -282,9 +282,9 @@ function! s:AutoClose() "{{{
|
|||||||
" Add matching pair and jump to the midle:
|
" Add matching pair and jump to the midle:
|
||||||
" inoremap <silent> <buffer> ( ()<Left>
|
" inoremap <silent> <buffer> ( ()<Left>
|
||||||
let i = 0
|
let i = 0
|
||||||
while i < len(s:g('matchpairs_list'))
|
while i < len(s:get('matchpairs_list'))
|
||||||
let ld = s:g('left_delims')[i] == '|' ? '<bar>' : s:g('left_delims')[i]
|
let ld = s:get('left_delims')[i] == '|' ? '<bar>' : s:get('left_delims')[i]
|
||||||
let rd = s:g('right_delims')[i] == '|' ? '<bar>' : s:g('right_delims')[i]
|
let rd = s:get('right_delims')[i] == '|' ? '<bar>' : s:get('right_delims')[i]
|
||||||
exec 'inoremap <expr><silent> <Plug>delimitMate' . ld
|
exec 'inoremap <expr><silent> <Plug>delimitMate' . ld
|
||||||
\. ' <SID>TriggerAbb().delimitMate#ParenDelim("' . escape(rd, '|') . '")'
|
\. ' <SID>TriggerAbb().delimitMate#ParenDelim("' . escape(rd, '|') . '")'
|
||||||
exec 'silent! imap <unique> <buffer> '.ld
|
exec 'silent! imap <unique> <buffer> '.ld
|
||||||
@@ -293,7 +293,7 @@ function! s:AutoClose() "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
" Exit from inside the matching pair:
|
" Exit from inside the matching pair:
|
||||||
for delim in s:g('right_delims')
|
for delim in s:get('right_delims')
|
||||||
let delim = delim == '|' ? '<bar>' : delim
|
let delim = delim == '|' ? '<bar>' : delim
|
||||||
exec 'inoremap <expr><silent> <Plug>delimitMate' . delim
|
exec 'inoremap <expr><silent> <Plug>delimitMate' . delim
|
||||||
\. ' <SID>TriggerAbb().delimitMate#JumpOut("\' . delim . '")'
|
\. ' <SID>TriggerAbb().delimitMate#JumpOut("\' . delim . '")'
|
||||||
@@ -303,7 +303,7 @@ function! s:AutoClose() "{{{
|
|||||||
|
|
||||||
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
||||||
" inoremap <silent> <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
|
" inoremap <silent> <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
|
||||||
for delim in s:g('quotes_list')
|
for delim in s:get('quotes_list')
|
||||||
if delim == '|'
|
if delim == '|'
|
||||||
let delim = '<Bar>'
|
let delim = '<Bar>'
|
||||||
endif
|
endif
|
||||||
@@ -315,7 +315,7 @@ function! s:AutoClose() "{{{
|
|||||||
|
|
||||||
" Try to fix the use of apostrophes (kept for backward compatibility):
|
" Try to fix the use of apostrophes (kept for backward compatibility):
|
||||||
" inoremap <silent> <buffer> n't n't
|
" inoremap <silent> <buffer> n't n't
|
||||||
for map in s:g('apostrophes_list')
|
for map in s:get('apostrophes_list')
|
||||||
exec "inoremap <silent> " . map . " " . map
|
exec "inoremap <silent> " . map . " " . map
|
||||||
exec 'silent! imap <unique> <buffer> ' . map . ' <Plug>delimitMate' . map
|
exec 'silent! imap <unique> <buffer> ' . map . ' <Plug>delimitMate' . map
|
||||||
endfor
|
endfor
|
||||||
@@ -339,17 +339,17 @@ function! s:ExtraMappings() "{{{
|
|||||||
endif
|
endif
|
||||||
" Expand return if inside an empty pair:
|
" Expand return if inside an empty pair:
|
||||||
inoremap <expr><silent> <Plug>delimitMateCR <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandReturn()\<CR>"
|
inoremap <expr><silent> <Plug>delimitMateCR <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandReturn()\<CR>"
|
||||||
if s:g('expand_cr') && !hasmapto('<Plug>delimitMateCR', 'i') && maparg('<CR>', 'i') == ''
|
if s:get('expand_cr') && !hasmapto('<Plug>delimitMateCR', 'i') && maparg('<CR>', 'i') == ''
|
||||||
silent! imap <unique> <buffer> <CR> <Plug>delimitMateCR
|
silent! imap <unique> <buffer> <CR> <Plug>delimitMateCR
|
||||||
endif
|
endif
|
||||||
" Expand space if inside an empty pair:
|
" Expand space if inside an empty pair:
|
||||||
inoremap <expr><silent> <Plug>delimitMateSpace <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandSpace()\<CR>"
|
inoremap <expr><silent> <Plug>delimitMateSpace <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandSpace()\<CR>"
|
||||||
if s:g('expand_space') && !hasmapto('<Plug>delimitMateSpace', 'i') && maparg('<Space>', 'i') == ''
|
if s:get('expand_space') && !hasmapto('<Plug>delimitMateSpace', 'i') && maparg('<Space>', 'i') == ''
|
||||||
silent! imap <unique> <buffer> <Space> <Plug>delimitMateSpace
|
silent! imap <unique> <buffer> <Space> <Plug>delimitMateSpace
|
||||||
endif
|
endif
|
||||||
" Jump over any delimiter:
|
" Jump over any delimiter:
|
||||||
inoremap <expr><silent> <Plug>delimitMateS-Tab <SID>TriggerAbb()."\<C-R>=delimitMate#JumpAny()\<CR>"
|
inoremap <expr><silent> <Plug>delimitMateS-Tab <SID>TriggerAbb()."\<C-R>=delimitMate#JumpAny()\<CR>"
|
||||||
if s:g('tab2exit') && !hasmapto('<Plug>delimitMateS-Tab', 'i') && maparg('<S-Tab>', 'i') == ''
|
if s:get('tab2exit') && !hasmapto('<Plug>delimitMateS-Tab', 'i') && maparg('<S-Tab>', 'i') == ''
|
||||||
silent! imap <unique> <buffer> <S-Tab> <Plug>delimitMateS-Tab
|
silent! imap <unique> <buffer> <S-Tab> <Plug>delimitMateS-Tab
|
||||||
endif
|
endif
|
||||||
" Jump over next delimiters
|
" Jump over next delimiters
|
||||||
|
|||||||
Reference in New Issue
Block a user