Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add string next to the closing matchpair when at the eol. Closes #77.

  • Loading branch information...
commit b65d719353bb4c358299119cced0bf00f69617bb 1 parent a42dff4
Israel Chauca Fuentes authored
45 autoload/delimitMate.vim
View
@@ -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>"
- endif
- if &backspace !~ 'start\|2' && empty(b:_l_delimitMate_buffer)
- return "\<BS>"
- 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')))
+ 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 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
- return "\<BS>"
+ return "\<BS>" . extra
endfunction " }}} delimitMate#BS()
function! delimitMate#Del() " {{{
16 doc/delimitMate.txt
View
@@ -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
@@ -270,6 +274,16 @@ 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 ":". ~
Default: No longer used. ~
@@ -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:
3  plugin/delimitMate.vim
View
@@ -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()
8 test/autoclose_matchpairs.txt
View
@@ -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"
6 test/expand_cr.txt
View
@@ -42,3 +42,9 @@ sub foo {
}x
}
--------------------------------------------------------------------------------
+%d
+call setline(1, "\"{bracketed}")
+normal A"x
+================================================================================
+"{bracketed}"x
+--------------------------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.