mirror of
https://github.com/Raimondi/delimitMate.git
synced 2026-01-16 08:06:58 +08:00
Add string next to the closing matchpair when at the eol. Closes #77.
This commit is contained in:
@@ -194,8 +194,8 @@ function! delimitMate#FlushBuffer() " {{{
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#AddToBuffer(c) "{{{
|
||||
call insert(b:_l_delimitMate_buffer, a:c)
|
||||
function! delimitMate#AddToBuffer(str) "{{{
|
||||
call insert(b:_l_delimitMate_buffer, a:str)
|
||||
endfunction "delimitMate#AddToBuffer }}}
|
||||
|
||||
function! delimitMate#BalancedParens(char) "{{{
|
||||
@@ -300,6 +300,7 @@ function! delimitMate#ParenDelim(char) " {{{
|
||||
endif
|
||||
let line = getline('.')
|
||||
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 smart_matchpairs = substitute(b:_l_delimitMate_smart_matchpairs, '\\!', left, 'g')
|
||||
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:char, 'g')
|
||||
@@ -312,8 +313,8 @@ function! delimitMate#ParenDelim(char) " {{{
|
||||
call delimitMate#AddToBuffer(a:char)
|
||||
else
|
||||
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
||||
call setline('.',line[:(col)].a:char.line[(col+1):])
|
||||
call delimitMate#AddToBuffer(a:char)
|
||||
call setline('.',line[:(col)].a:char.tail.line[(col+1):])
|
||||
call delimitMate#AddToBuffer(a:char . tail)
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
@@ -439,21 +440,29 @@ endfunction "}}}
|
||||
|
||||
function! delimitMate#BS() " {{{
|
||||
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
|
||||
if &backspace !~ 'start\|2' && empty(b:_l_delimitMate_buffer)
|
||||
return "\<BS>"
|
||||
if search('\m\C\%#\%('
|
||||
\ . 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
|
||||
if delimitMate#WithinEmptyPair()
|
||||
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>"
|
||||
return "\<BS>" . extra
|
||||
endfunction " }}} delimitMate#BS()
|
||||
|
||||
function! delimitMate#Del() " {{{
|
||||
|
||||
@@ -103,6 +103,10 @@ specific file types, see |delimitMateOptionDetails| for examples.
|
||||
|
||||
|'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"
|
||||
balancing of single quotes when used as
|
||||
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.: >
|
||||
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'*
|
||||
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
|
||||
call s:option_init("balance_matchpairs", 0)
|
||||
|
||||
" eol marker
|
||||
call s:option_init("eol_marker", "")
|
||||
|
||||
let b:_l_delimitMate_buffer = []
|
||||
|
||||
endfunction "}}} Init()
|
||||
|
||||
@@ -24,3 +24,11 @@ let g:delimitMate_autoclose = 1
|
||||
# Handle backspace gracefully.
|
||||
set backspace=
|
||||
"(\<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
|
||||
}
|
||||
--------------------------------------------------------------------------------
|
||||
%d
|
||||
call setline(1, "\"{bracketed}")
|
||||
normal A"x
|
||||
================================================================================
|
||||
"{bracketed}"x
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user