mirror of
https://github.com/Raimondi/delimitMate.git
synced 2026-05-20 07:19:53 +08:00
Add string next to the closing matchpair when at the eol. Closes #77.
This commit is contained in:
+26
-17
@@ -194,8 +194,8 @@ function! delimitMate#FlushBuffer() " {{{
|
|||||||
return ''
|
return ''
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
function! delimitMate#AddToBuffer(c) "{{{
|
function! delimitMate#AddToBuffer(str) "{{{
|
||||||
call insert(b:_l_delimitMate_buffer, a:c)
|
call insert(b:_l_delimitMate_buffer, a:str)
|
||||||
endfunction "delimitMate#AddToBuffer }}}
|
endfunction "delimitMate#AddToBuffer }}}
|
||||||
|
|
||||||
function! delimitMate#BalancedParens(char) "{{{
|
function! delimitMate#BalancedParens(char) "{{{
|
||||||
@@ -300,6 +300,7 @@ function! delimitMate#ParenDelim(char) " {{{
|
|||||||
endif
|
endif
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
let col = col('.')-2
|
let col = col('.')-2
|
||||||
|
let tail = len(line) == (col + 1) ? b:_l_delimitMate_eol_marker : ''
|
||||||
let left = b:_l_delimitMate_left_delims[index(b:_l_delimitMate_right_delims,a:char)]
|
let left = b:_l_delimitMate_left_delims[index(b:_l_delimitMate_right_delims,a:char)]
|
||||||
let smart_matchpairs = substitute(b:_l_delimitMate_smart_matchpairs, '\\!', left, 'g')
|
let smart_matchpairs = substitute(b:_l_delimitMate_smart_matchpairs, '\\!', left, 'g')
|
||||||
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:char, 'g')
|
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:char, 'g')
|
||||||
@@ -312,8 +313,8 @@ function! delimitMate#ParenDelim(char) " {{{
|
|||||||
call delimitMate#AddToBuffer(a:char)
|
call delimitMate#AddToBuffer(a:char)
|
||||||
else
|
else
|
||||||
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
||||||
call setline('.',line[:(col)].a:char.line[(col+1):])
|
call setline('.',line[:(col)].a:char.tail.line[(col+1):])
|
||||||
call delimitMate#AddToBuffer(a:char)
|
call delimitMate#AddToBuffer(a:char . tail)
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
@@ -439,21 +440,29 @@ endfunction "}}}
|
|||||||
|
|
||||||
function! delimitMate#BS() " {{{
|
function! delimitMate#BS() " {{{
|
||||||
if delimitMate#IsForbidden("")
|
if delimitMate#IsForbidden("")
|
||||||
return "\<BS>"
|
let extra = ''
|
||||||
|
elseif &backspace !~ 'start\|2' && empty(b:_l_delimitMate_buffer)
|
||||||
|
let extra = ''
|
||||||
|
elseif delimitMate#WithinEmptyPair()
|
||||||
|
let extra = delimitMate#Del()
|
||||||
|
elseif delimitMate#IsSpaceExpansion()
|
||||||
|
let extra = delimitMate#Del()
|
||||||
|
elseif delimitMate#IsCRExpansion()
|
||||||
|
let extra = repeat("\<Del>", len(matchstr(getline(line('.') + 1), '^\s*\S')))
|
||||||
|
else
|
||||||
|
let extra = ''
|
||||||
endif
|
endif
|
||||||
if &backspace !~ 'start\|2' && empty(b:_l_delimitMate_buffer)
|
if search('\m\C\%#\%('
|
||||||
return "\<BS>"
|
\ . join(b:_l_delimitMate_right_delims, '\|')
|
||||||
|
\ . '\)'
|
||||||
|
\ . escape(b:_l_delimitMate_eol_marker, '\*.')
|
||||||
|
\ . '$',
|
||||||
|
\ 'cWn')
|
||||||
|
for c in range(len(split(b:_l_delimitMate_eol_marker, '\zs')))
|
||||||
|
let extra .= delimitMate#Del()
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
if delimitMate#WithinEmptyPair()
|
return "\<BS>" . extra
|
||||||
return "\<BS>" . delimitMate#Del()
|
|
||||||
endif
|
|
||||||
if delimitMate#IsSpaceExpansion()
|
|
||||||
return "\<BS>" . delimitMate#Del()
|
|
||||||
endif
|
|
||||||
if delimitMate#IsCRExpansion()
|
|
||||||
return "\<BS>" . repeat("\<Del>", len(matchstr(getline(line('.') + 1), '^\s*\S')))
|
|
||||||
endif
|
|
||||||
return "\<BS>"
|
|
||||||
endfunction " }}} delimitMate#BS()
|
endfunction " }}} delimitMate#BS()
|
||||||
|
|
||||||
function! delimitMate#Del() " {{{
|
function! delimitMate#Del() " {{{
|
||||||
|
|||||||
+15
-1
@@ -103,6 +103,10 @@ specific file types, see |delimitMateOptionDetails| for examples.
|
|||||||
|
|
||||||
|'delimitMate_excluded_ft'| Turns off the script for the given file types.
|
|'delimitMate_excluded_ft'| Turns off the script for the given file types.
|
||||||
|
|
||||||
|
|'delimitMate_eol_marker'| Determines what to insert after the closing
|
||||||
|
matchpair when typing an opening matchpair on
|
||||||
|
the end of the line.
|
||||||
|
|
||||||
|'delimitMate_apostrophes'| Tells delimitMate how it should "fix"
|
|'delimitMate_apostrophes'| Tells delimitMate how it should "fix"
|
||||||
balancing of single quotes when used as
|
balancing of single quotes when used as
|
||||||
apostrophes. NOTE: Not needed any more, kept
|
apostrophes. NOTE: Not needed any more, kept
|
||||||
@@ -269,6 +273,16 @@ only if you don't want any of the features it provides on those file types.
|
|||||||
e.g.: >
|
e.g.: >
|
||||||
let delimitMate_excluded_ft = "mail,txt"
|
let delimitMate_excluded_ft = "mail,txt"
|
||||||
<
|
<
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*'delimitMate_eol_marker'*
|
||||||
|
Values: String. ~
|
||||||
|
Default: Empty. ~
|
||||||
|
|
||||||
|
The contents of this string will be inserted after the closing matchpair when
|
||||||
|
the opening matchapair is inserted at the end of the line.
|
||||||
|
e.g.: >
|
||||||
|
au FileType c,perl let b:delimitMate_eol_marker = ";"
|
||||||
|
<
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*'delimitMate_apostrophes'*
|
*'delimitMate_apostrophes'*
|
||||||
Values: Strings separated by ":". ~
|
Values: Strings separated by ":". ~
|
||||||
@@ -824,4 +838,4 @@ _____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
|
|||||||
__|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_ ~
|
__|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_ ~
|
||||||
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
|
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
|
||||||
|
|
||||||
vim:tw=78:et:ts=2:sw=2:ft=help:norl:formatoptions+=tcroqn:autoindent:
|
vim:tw=78:et:ts=8:sw=2:ft=help:norl:formatoptions+=tcroqn:autoindent:
|
||||||
|
|||||||
@@ -129,6 +129,9 @@ function! s:init() "{{{
|
|||||||
" balance_matchpairs
|
" balance_matchpairs
|
||||||
call s:option_init("balance_matchpairs", 0)
|
call s:option_init("balance_matchpairs", 0)
|
||||||
|
|
||||||
|
" eol marker
|
||||||
|
call s:option_init("eol_marker", "")
|
||||||
|
|
||||||
let b:_l_delimitMate_buffer = []
|
let b:_l_delimitMate_buffer = []
|
||||||
|
|
||||||
endfunction "}}} Init()
|
endfunction "}}} Init()
|
||||||
|
|||||||
@@ -24,3 +24,11 @@ let g:delimitMate_autoclose = 1
|
|||||||
# Handle backspace gracefully.
|
# Handle backspace gracefully.
|
||||||
set backspace=
|
set backspace=
|
||||||
"(\<Esc>a\<BS>x" "(x)"
|
"(\<Esc>a\<BS>x" "(x)"
|
||||||
|
|
||||||
|
# Add semicolon next to the closing paren. Issue #77.
|
||||||
|
new
|
||||||
|
let b:delimitMate_eol_marker = ';'
|
||||||
|
"abc(x" "abc(x);"
|
||||||
|
%d
|
||||||
|
# BS should behave accordingly.
|
||||||
|
"abc(\<BS>" "abc"
|
||||||
|
|||||||
@@ -42,3 +42,9 @@ sub foo {
|
|||||||
}x
|
}x
|
||||||
}
|
}
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
%d
|
||||||
|
call setline(1, "\"{bracketed}")
|
||||||
|
normal A"x
|
||||||
|
================================================================================
|
||||||
|
"{bracketed}"x
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user