Add option delimitMate_insert_eol_marker. Closes #195.

This commit is contained in:
Israel Chauca Fuentes
2015-01-08 17:14:27 -05:00
parent 21a3ade90c
commit e7b4dedb84
4 changed files with 60 additions and 7 deletions

View File

@@ -345,10 +345,11 @@ function! delimitMate#ParenDelim(right) " {{{
return left
endif
endif
let tail = len(line) == (col + 1) ? s:get('eol_marker') : ''
"if (col) < 0
" call setline('.',a:right.line)
"endif
if len(line) == (col + 1) && s:get('insert_eol_marker') == 1
let tail = s:get('eol_marker')
else
let tail = ''
endif
return left . a:right . tail . repeat("\<Left>", len(split(tail, '\zs')) + 1)
endfunction " }}}
@@ -466,11 +467,17 @@ function! delimitMate#ExpandReturn() "{{{
let expand_inside_quotes = s:get('expand_inside_quotes')
\ && s:is_empty_quotes()
\ && !escaped
let is_empty_matchpair = s:is_empty_matchpair()
if !pumvisible( )
\ && (s:is_empty_matchpair()
\ && ( is_empty_matchpair
\ || expand_right_matchpair
\ || expand_inside_quotes)
let val = "\<Esc>a\<CR>"
let val = "\<Esc>a"
if is_empty_matchpair && s:get('insert_eol_marker') == 2
let repeat = search('\s\%#\s', 'bcnW', '.') ? 2 : 1
let val .= repeat("\<Right>", repeat) . s:get('eol_marker') . repeat("\<Left>", repeat + 1)
endif
let val .= "\<CR>"
if &smartindent && !&cindent && !&indentexpr
\ && s:get_char(0) == '}'
" indentation is controlled by 'smartindent', and the first character on

View File

@@ -309,6 +309,21 @@ 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_insert_eol_marker'*
Values: Integer ~
Default: 1 ~
Whether to insert the eol marker (EM) or not. The EM is inserted following
rules:
0 -> never
1 -> when inserting any matchpair
2 -> when expanding car return in matchpair
e.g.: >
au FileType c,perl let b:delimitMate_insert_eol_marker = 2
<
------------------------------------------------------------------------------
*'delimitMate_eol_marker'*
Values: String. ~

View File

@@ -140,6 +140,7 @@ function! s:init() "{{{
" balance_matchpairs
call s:option_init("balance_matchpairs", 0)
" eol marker
call s:option_init("insert_eol_marker", 1)
call s:option_init("eol_marker", "")
" Everything is fine.
return 1

30
test/eol_marker.vim Normal file
View File

@@ -0,0 +1,30 @@
let g:delimitMate_expand_cr = 1
let g:delimitMate_eol_marker = ';'
call vimtest#StartTap()
call vimtap#Plan(6)
" NOTE: Do not forget to update the plan ^
let g:delimitMate_insert_eol_marker = 0
DelimitMateReload
normal i(
call vimtap#Is(getline(1), '()', 'value = 1, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"), '^(\n\s*x\n)$', 'Value = 2, case 2')
let g:delimitMate_insert_eol_marker = 1
DelimitMateReload
%d _
normal i(
call vimtap#Is(getline(1), '();', 'value = 1, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"), '^(\n\s*x\n);$', 'Value = 2, case 2')
%d _
let g:delimitMate_insert_eol_marker = 2
DelimitMateReload
normal i(
call vimtap#Is(getline(1), '()', 'Value = 2, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"), '^(\n\s*x\n);$', 'Value = 2, case 2')
call vimtest#Quit()