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