mirror of
https://github.com/Raimondi/delimitMate.git
synced 2026-01-26 12:56:59 +08:00
Add expand_cr
This commit is contained in:
@@ -5,6 +5,7 @@ let s:defaults.delimitMate_quotes = ['"', "'", '`']
|
||||
let s:defaults.delimitMate_enabled = 1
|
||||
let s:defaults.delimitMate_autoclose = 1
|
||||
let s:defaults.delimitMate_expand_space = 0
|
||||
let s:defaults.delimitMate_expand_cr = 0
|
||||
let s:defaults.delimitMate_jump_expansion = 0
|
||||
let s:defaults.delimitMate_expand_inside_quotes = 0
|
||||
let s:defaults.delimitMate_smart_pairs = 1
|
||||
@@ -104,6 +105,8 @@ function! s:get_info(...) "{{{1
|
||||
let d.line = getline('.')
|
||||
let d.col = col('.')
|
||||
let d.lnum = line('.')
|
||||
let d.prev_line = line('.') == 1 ? '' : getline(line('.') - 1)
|
||||
let d.next_line = line('.') == line('$') ? '' : getline(line('.') + 1)
|
||||
endif
|
||||
let d.ahead = len(d.line) >= d.col ? d.line[d.col - 1 : ] : ''
|
||||
let d.behind = d.col >= 2 ? d.line[: d.col - 2] : ''
|
||||
@@ -168,29 +171,53 @@ function! delimitMate#TextChangedI(...) "{{{1
|
||||
echom 21
|
||||
return
|
||||
endif
|
||||
if s:info.cur.lnum != s:info.prev.lnum
|
||||
if s:info.cur.lnum == s:info.prev.lnum + 1
|
||||
\&& s:info.prev.behind ==# s:info.cur.prev_line
|
||||
\&& s:info.prev.ahead ==# s:info.cur.ahead
|
||||
\&& s:info.cur.behind =~ '^\s*$'
|
||||
" CR
|
||||
echom 22
|
||||
return feedkeys(s:keys4cr(s:info, s:defaults.consolidate()), 'tni')
|
||||
endif
|
||||
if s:info.cur.lnum == s:info.prev.lnum - 1
|
||||
\&& s:info.prev.prev_line ==# s:info.cur.line
|
||||
\&& s:info.prev.next_line ==# s:info.cur.next_line
|
||||
let pair = filter(s:option('pairs'), 's:info.cur.p_char . matchstr(s:info.cur.next_line, "^\\s*\\zs\\S") ==# v:val')
|
||||
echom 23
|
||||
if s:option('expand_cr') && !empty(pair)
|
||||
echom "23.1"
|
||||
return feedkeys("\<Del>")
|
||||
endif
|
||||
let quote = filter(s:option('quotes'), 's:info.cur.p_char . matchstr(s:info.cur.next_line, "^\\s*\\zs\\S") ==# v:val.v:val')
|
||||
if s:option('expand_cr') && s:option('expand_inside_quotes') && !empty(quote)
|
||||
echom "23.2"
|
||||
return feedkeys("\<Del>")
|
||||
endif
|
||||
return
|
||||
endif
|
||||
if s:info.cur.lnum != s:info.prev.lnum
|
||||
echom 24
|
||||
return
|
||||
endif
|
||||
if s:info.prev.col - s:info.cur.col != len(s:info.prev.p_char)
|
||||
echom 23
|
||||
echom 25
|
||||
return
|
||||
endif
|
||||
if len(s:info.prev.line) == len(s:info.cur.line)
|
||||
echom 24
|
||||
echom 26
|
||||
return
|
||||
endif
|
||||
echom s:info.prev.around
|
||||
let pair = filter(s:option('pairs'), 'v:val ==# (s:info.cur.p_char . matchstr(s:info.cur.ahead, "^\\s\\zs\\S"))')
|
||||
let quotes = filter(s:option('quotes'), 'v:val . v:val ==# (s:info.cur.p_char . matchstr(s:info.cur.ahead, "^\\s\\zs\\S"))')
|
||||
if s:option('expand_space') && (!empty(pair) || (s:option('expand_inside_quotes') && !empty(quotes)))
|
||||
echom 25
|
||||
echom 27
|
||||
return feedkeys("\<Del>", 'tni')
|
||||
endif
|
||||
let pair = filter(s:option('pairs'), 'v:val ==# s:info.prev.around')
|
||||
let quote = filter(s:option('quotes'), 'v:val . v:val ==# s:info.prev.around')
|
||||
if empty(pair) && empty(quote)
|
||||
echom 26
|
||||
echom 28
|
||||
return
|
||||
endif
|
||||
echom 29
|
||||
@@ -233,8 +260,10 @@ function! s:handle_vchar(str) "{{{1
|
||||
echom 13
|
||||
let keys = s:keys4space(s:info, opts)
|
||||
elseif a:str == "\<C-]>"
|
||||
let prev_line = line('.') == 1 ? '' : getline(line('.') - 1)
|
||||
let next_line = line('.') == line('$') ? '' : getline(line('.') + 1)
|
||||
echom 14
|
||||
return 0
|
||||
let keys = s:keys4cr(prev_line, next_line, s:info, opts)
|
||||
elseif !empty(filter(copy(opts.quotes), 'v:val ==# a:str'))
|
||||
echom 15
|
||||
let keys = s:keys4quote(a:str, s:info, opts)
|
||||
@@ -352,6 +381,18 @@ function! s:keys4quote(char, info, opts) "{{{1
|
||||
endfunction
|
||||
|
||||
function! s:keys4cr(info, opts) "{{{1
|
||||
if a:opts.expand_cr
|
||||
\&& !empty(filter(copy(a:opts.pairs), 'v:val ==# a:info.prev.around'))
|
||||
" Empty pair
|
||||
echom 71
|
||||
return "\<Up>\<End>\<CR>"
|
||||
endif
|
||||
if a:opts.expand_cr && a:opts.expand_inside_quotes
|
||||
\&& !empty(filter(copy(a:opts.quotes), 'v:val.v:val ==# a:info.prev.around'))
|
||||
" Empty pair
|
||||
echom 72
|
||||
return "\<Up>\<End>\<CR>"
|
||||
endif
|
||||
echom 79
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
@@ -14,27 +14,25 @@ call vimtest#StartTap()
|
||||
call vimtap#Plan(25)
|
||||
|
||||
let g:delimitMate_expand_cr = 1
|
||||
DelimitMateReload
|
||||
"let g:delimitMate_eol_marker = ';'
|
||||
filetype indent on
|
||||
set bs=2 et sts=4 sw=4 ft=javascript
|
||||
call DMTest_single('$(document).ready(function() {})',
|
||||
\ "\<Esc>31|i\<CR>x\<Esc>",
|
||||
\ "31|i\<CR>x",
|
||||
\ ["$(document).ready(function() {", " x", "})"])
|
||||
|
||||
" Issue #95
|
||||
new
|
||||
let b:delimitMate_jump_expansion = 1
|
||||
DelimitMateReload
|
||||
call DMTest_single('', "(\<CR>test)x",
|
||||
call DMTest_single('', "i(\<CR>test)x",
|
||||
\ ['(', 'test', ')x'])
|
||||
|
||||
" Remove CR expansion on BS
|
||||
call DMTest_single('', "(\<CR>\<BS>x",
|
||||
call DMTest_single('', "i(\<CR>\<BS>x",
|
||||
\ ['(x)'])
|
||||
|
||||
" Consider indentation with BS inside an empty CR expansion.
|
||||
call DMTest_single('', "( \<CR>\<BS>\<BS>x", '(x)')
|
||||
call DMTest_single('', "i( \<CR>\<BS>\<BS>x", '(x)')
|
||||
|
||||
" Conflict with indentation settings (cindent). Issue #95
|
||||
se cindent
|
||||
@@ -44,7 +42,7 @@ call DMTest_single(
|
||||
\ ' ',
|
||||
\ ' }',
|
||||
\ '}'],
|
||||
\ "\<Esc>3G8|a}x",
|
||||
\ "i\<Esc>3G8|a}x",
|
||||
\ ['sub foo {',
|
||||
\ ' while (1) {',
|
||||
\ ' ',
|
||||
@@ -62,33 +60,31 @@ set foldmethod=marker
|
||||
set foldmarker={,}
|
||||
set foldlevel=0
|
||||
set backspace=2
|
||||
call DMTest_single('', "abc {\<CR>x",
|
||||
call DMTest_single('', "iabc {\<CR>x",
|
||||
\['abc {',
|
||||
\ ' x',
|
||||
\ '}'])
|
||||
|
||||
" expand_cr != 2
|
||||
call DMTest_single('abc(def)', "\<Esc>$i\<CR>x",
|
||||
call DMTest_single('abc(def)', "i\<Esc>$i\<CR>x",
|
||||
\ ['abc(def',
|
||||
\ ' x)'])
|
||||
|
||||
" expand_cr == 2
|
||||
let delimitMate_expand_cr = 2
|
||||
DelimitMateReload
|
||||
call DMTest_single('abc(def)', "\<Esc>$i\<CR>x", ['abc(def', ' x', ' )'])
|
||||
call DMTest_single('abc(def)', "i\<Esc>$i\<CR>x", ['abc(def', ' x', ' )'])
|
||||
|
||||
" Play nice with smartindent
|
||||
set all&
|
||||
set smartindent
|
||||
call DMTest_single('', "\<Esc>$i{\<CR>x", ['{', ' x', '}'])
|
||||
call DMTest_single('', "i\<Esc>$i{\<CR>x", ['{', ' x', '}'])
|
||||
|
||||
call DMTest_quotes('', "' x", "' x'")
|
||||
call DMTest_quotes('', "i' x", "' x'")
|
||||
|
||||
call DMTest_quotes('', "'\<CR>x", ["'", "x'"])
|
||||
call DMTest_quotes('', "i'\<CR>x", ["'", "x'"])
|
||||
|
||||
let delimitMate_expand_inside_quotes = 1
|
||||
DelimitMateReload
|
||||
|
||||
call DMTest_quotes('', "'\<CR>x", ["'", "x", "'"])
|
||||
call DMTest_quotes('', "i'\<CR>x", ["'", "x", "'"])
|
||||
|
||||
call vimtest#Quit()
|
||||
|
||||
Reference in New Issue
Block a user