mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-22 04:01:26 +08:00
Do not expand cr and space inside quotes by default. Close #153.
- Add delimitMate_expand_inside_quotes. - Add tests.
This commit is contained in:
@@ -192,6 +192,27 @@ function! delimitMate#WithinEmptyPair() "{{{
|
|||||||
return delimitMate#IsEmptyPair( char1.char2 )
|
return delimitMate#IsEmptyPair( char1.char2 )
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! delimitMate#WithinEmptyMatchpair() "{{{
|
||||||
|
" get char before the cursor.
|
||||||
|
let open = delimitMate#GetCharFromCursor(-1)
|
||||||
|
let idx = index(s:g('left_delims'), open)
|
||||||
|
if idx == -1
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
let close = get(s:g('right_delims'), idx, '')
|
||||||
|
return close ==# delimitMate#GetCharFromCursor(0)
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! delimitMate#WithinEmptyQuotes() "{{{
|
||||||
|
" get char before the cursor.
|
||||||
|
let quote = delimitMate#GetCharFromCursor(-1)
|
||||||
|
let idx = index(s:g('quotes_list'), quote)
|
||||||
|
if idx == -1
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
return quote ==# delimitMate#GetCharFromCursor(0)
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
function! delimitMate#CursorIdx() "{{{
|
function! delimitMate#CursorIdx() "{{{
|
||||||
let idx = len(split(getline('.')[: col('.') - 1], '\zs')) - 1
|
let idx = len(split(getline('.')[: col('.') - 1], '\zs')) - 1
|
||||||
return idx
|
return idx
|
||||||
@@ -448,10 +469,15 @@ function! delimitMate#ExpandReturn() "{{{
|
|||||||
if delimitMate#IsForbidden("")
|
if delimitMate#IsForbidden("")
|
||||||
return "\<CR>"
|
return "\<CR>"
|
||||||
endif
|
endif
|
||||||
if delimitMate#WithinEmptyPair()
|
let escaped = delimitMate#CursorIdx() >= 2
|
||||||
|
\ && delimitMate#GetCharFromCursor(-2) == '\'
|
||||||
|
if delimitMate#WithinEmptyMatchpair()
|
||||||
|
\ || (s:g('expand_cr') == 2
|
||||||
|
\ && index(s:g('right_delims'), delimitMate#GetCharFromCursor(0)) > -1)
|
||||||
|
\ || (s:g('expand_inside_quotes')
|
||||||
|
\ && delimitMate#WithinEmptyQuotes()
|
||||||
|
\ && !escaped)
|
||||||
" Expand:
|
" Expand:
|
||||||
" Not sure why I used the previous combos, but I'm sure somebody will
|
|
||||||
" tell me about it.
|
|
||||||
" XXX zv prevents breaking expansion with syntax folding enabled by
|
" XXX zv prevents breaking expansion with syntax folding enabled by
|
||||||
" InsertLeave.
|
" InsertLeave.
|
||||||
return "\<Esc>a\<CR>\<Esc>zvO"
|
return "\<Esc>a\<CR>\<Esc>zvO"
|
||||||
@@ -466,7 +492,10 @@ function! delimitMate#ExpandSpace() "{{{
|
|||||||
endif
|
endif
|
||||||
let escaped = delimitMate#CursorIdx() >= 2
|
let escaped = delimitMate#CursorIdx() >= 2
|
||||||
\ && delimitMate#GetCharFromCursor(-2) == '\'
|
\ && delimitMate#GetCharFromCursor(-2) == '\'
|
||||||
if delimitMate#WithinEmptyPair() && !escaped
|
if delimitMate#WithinEmptyMatchpair()
|
||||||
|
\ || (s:g('expand_inside_quotes')
|
||||||
|
\ && delimitMate#WithinEmptyQuotes()
|
||||||
|
\ && !escaped)
|
||||||
" Expand:
|
" Expand:
|
||||||
return "\<Space>\<Space>\<Left>"
|
return "\<Space>\<Space>\<Left>"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ e.g.: >
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*'delimitMate_expand_cr'*
|
*'delimitMate_expand_cr'*
|
||||||
*'b:delimitMate_expand_cr'*
|
*'b:delimitMate_expand_cr'*
|
||||||
Values: 1 or 0 ~
|
Values: 0, 1 or 2 ~
|
||||||
Default: 0 ~
|
Default: 0 ~
|
||||||
|
|
||||||
This option turns on/off the expansion of <CR>. Read |delimitMateExpansion|
|
This option turns on/off the expansion of <CR>. Read |delimitMateExpansion|
|
||||||
@@ -214,6 +214,18 @@ e.g.: >
|
|||||||
let delimitMate_expand_space = 1
|
let delimitMate_expand_space = 1
|
||||||
au FileType tcl let b:delimitMate_expand_space = 1
|
au FileType tcl let b:delimitMate_expand_space = 1
|
||||||
<
|
<
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*'delimitMate_expand_inside_quotes'*
|
||||||
|
*'b:delimitMate_expand_inside_quotes'*
|
||||||
|
Values: 1 or 0 ~
|
||||||
|
Default: 0 ~
|
||||||
|
When this option is set to 1 the expansion of space and cr will also be
|
||||||
|
applied to quotes. Read |delimitMateExpansion| for details.
|
||||||
|
|
||||||
|
e.g.: >
|
||||||
|
let delimitMate_expand_inside_quotes = 1
|
||||||
|
au FileType mail let b:delimitMate_expand_inside_quotes = 1
|
||||||
|
<
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*'delimitMate_jump_expansion'*
|
*'delimitMate_jump_expansion'*
|
||||||
*'b:delimitMate_jump_expansion'*
|
*'b:delimitMate_jump_expansion'*
|
||||||
@@ -369,20 +381,20 @@ you should use <C-]> (read |i_CTRL-]|) to expand them on the go.
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
3.2 EXPANSION OF SPACE AND CAR RETURN *delimitMateExpansion*
|
3.2 EXPANSION OF SPACE AND CAR RETURN *delimitMateExpansion*
|
||||||
|
|
||||||
When the cursor is inside an empty pair of delimiters, <Space> and <CR> can be
|
When the cursor is inside an empty pair of any matchpair, <Space> and <CR> can be
|
||||||
expanded, see |'delimitMate_expand_space'| and
|
expanded, see |'delimitMate_expand_space'| and
|
||||||
|'delimitMate_expand_cr'|:
|
|'delimitMate_expand_cr'|:
|
||||||
|
|
||||||
Expand <Space> to: >
|
Expand <Space> to: >
|
||||||
|
|
||||||
<Space><Space><Left> | You get
|
You start with | You get
|
||||||
====================================
|
==============================
|
||||||
(|) | ( | )
|
(|) | ( | )
|
||||||
<
|
<
|
||||||
Expand <CR> to: >
|
Expand <CR> to: >
|
||||||
|
|
||||||
<CR><CR><Up> | You get
|
You start with | You get
|
||||||
============================
|
==============================
|
||||||
(|) | (
|
(|) | (
|
||||||
| |
|
| |
|
||||||
| )
|
| )
|
||||||
@@ -393,6 +405,15 @@ closing paren/bracket/etc. on the next line, delimitMate will make the cursor
|
|||||||
jump over any whitespace/<CR> and place it after the existing closing
|
jump over any whitespace/<CR> and place it after the existing closing
|
||||||
delimiter instead of inserting a new one.
|
delimiter instead of inserting a new one.
|
||||||
|
|
||||||
|
When |'delimitMate_expand_cr'| is set to 2, the following will also happen: >
|
||||||
|
|
||||||
|
You start with | You get
|
||||||
|
==============================
|
||||||
|
(foo|) | (foo
|
||||||
|
| |
|
||||||
|
| )
|
||||||
|
<
|
||||||
|
|
||||||
Since <Space> and <CR> are used everywhere, I have made the functions involved
|
Since <Space> and <CR> are used everywhere, I have made the functions involved
|
||||||
in expansions global, so they can be used to make custom mappings. Read
|
in expansions global, so they can be used to make custom mappings. Read
|
||||||
|delimitMateFunctions| for more details.
|
|delimitMateFunctions| for more details.
|
||||||
|
|||||||
@@ -108,6 +108,9 @@ function! s:init() "{{{
|
|||||||
endif
|
endif
|
||||||
call s:option_init("expand_cr", 0)
|
call s:option_init("expand_cr", 0)
|
||||||
|
|
||||||
|
" expand_in_quotes
|
||||||
|
call s:option_init('expand_inside_quotes', 0)
|
||||||
|
|
||||||
" jump_expansion
|
" jump_expansion
|
||||||
call s:option_init("jump_expansion", 0)
|
call s:option_init("jump_expansion", 0)
|
||||||
|
|
||||||
@@ -395,4 +398,4 @@ augroup END
|
|||||||
|
|
||||||
let &cpo = save_cpo
|
let &cpo = save_cpo
|
||||||
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
|
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
|
||||||
" vim:foldmethod=marker:foldcolumn=4
|
" vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ let g:delimitMate_autoclose = 0
|
|||||||
"@#\<Left>''x" "@'x'#"
|
"@#\<Left>''x" "@'x'#"
|
||||||
let g:delimitMate_expand_space = 1
|
let g:delimitMate_expand_space = 1
|
||||||
let g:delimitMate_autoclose = 1
|
let g:delimitMate_autoclose = 1
|
||||||
|
"'\<Space>x" "' x'"
|
||||||
|
let g:delimitMate_expand_inside_quotes = 1
|
||||||
"'\<Space>x" "' x '"
|
"'\<Space>x" "' x '"
|
||||||
"'\<Space>\<BS>x" "'x'"
|
"'\<Space>\<BS>x" "'x'"
|
||||||
"abc\\''\<Space>x" "abc\\' x'"
|
"abc\\''\<Space>x" "abc\\' x'"
|
||||||
|
|||||||
@@ -65,3 +65,22 @@ abc {
|
|||||||
x
|
x
|
||||||
}
|
}
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
# expand_cr != 2
|
||||||
|
%d_
|
||||||
|
call setline(1, 'abc(def)')
|
||||||
|
exec "normal $i\<CR>x"
|
||||||
|
================================================================================
|
||||||
|
abc(def
|
||||||
|
x)
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
# expand_cr == 2
|
||||||
|
%d_
|
||||||
|
let delimitMate_expand_cr = 2
|
||||||
|
DelimitMateReload
|
||||||
|
call setline(1, 'abc(def)')
|
||||||
|
exec "normal $i\<CR>x"
|
||||||
|
================================================================================
|
||||||
|
abc(def
|
||||||
|
x
|
||||||
|
)
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user