From a97af1fb97909bf962cd070bb7c7a99d9f368445 Mon Sep 17 00:00:00 2001 From: ervandew Date: Thu, 4 Nov 2010 22:30:10 -0700 Subject: [PATCH] add option to disable closing delims if open delim added before an alphanumeric --- autoload/delimitMate.vim | 4 +++- doc/delimitMate.txt | 31 +++++++++++++++++++++++++++++++ plugin/delimitMate.vim | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/autoload/delimitMate.vim b/autoload/delimitMate.vim index 01c6021..c649f17 100644 --- a/autoload/delimitMate.vim +++ b/autoload/delimitMate.vim @@ -261,6 +261,8 @@ function! delimitMate#ParenDelim(char) " {{{ if (col) < 0 call setline('.',a:char.line) call insert(b:_l_delimitMate_buffer, a:char) + elseif b:_l_delimitMate_smart_parens && line[col + 1] =~ '[[:alnum:]]' + return '' else "echom string(col).':'.line[:(col)].'|'.line[(col+1):] call setline('.',line[:(col)].a:char.line[(col+1):]) @@ -528,7 +530,7 @@ function! delimitMate#TestMappings() "{{{ endfunction "}}} function! delimitMate#OptionsList() "{{{ - return {'autoclose' : 1,'matchpairs': &matchpairs, 'quotes' : '" '' `', 'nesting_quotes' : [], 'expand_cr' : 0, 'expand_space' : 0, 'smart_quotes' : 1, 'balance_matchpairs' : 0, 'excluded_regions' : 'Comment', 'excluded_ft' : '', 'apostrophes' : ''} + return {'autoclose' : 1,'matchpairs': &matchpairs, 'quotes' : '" '' `', 'nesting_quotes' : [], 'expand_cr' : 0, 'expand_space' : 0, 'smart_quotes' : 1, 'smart_parens' : 1, 'balance_matchpairs' : 0, 'excluded_regions' : 'Comment', 'excluded_ft' : '', 'apostrophes' : ''} endfunction " delimitMate#OptionsList }}} "}}} diff --git a/doc/delimitMate.txt b/doc/delimitMate.txt index 5aa6117..97194c8 100644 --- a/doc/delimitMate.txt +++ b/doc/delimitMate.txt @@ -93,6 +93,8 @@ specific file types, see |delimitMateOptionDetails| for examples. |'delimitMate_smart_quotes'| Turns on/off the "smart quotes" feature. +|'delimitMate_smart_parens'| Turns on/off the "smart parens" feature. + |'delimitMate_balance_matchpairs'|Turns on/off the "balance matching pairs" feature. @@ -211,6 +213,18 @@ e.g.: > let delimitMate_smart_quotes = 0 au FileType tcl let b:delimitMate_smart_quotes = 0 < +------------------------------------------------------------------------------ + *'delimitMate_smart_parens'* + *'b:delimitMate_smart_parens'* +Values: 1 or 0 ~ +Default: 1 ~ + +This option turns on/off the smart parens feature. Read +|delimitMateSmartParens| for details. +e.g.: > + let delimitMate_smart_parens = 0 + au FileType tcl let b:delimitMate_smart_parens = 0 +< ------------------------------------------------------------------------------ *'delimitMate_balance_matchpairs'* *'b:delimitMate_balance_matchpairs'* @@ -375,6 +389,23 @@ e.g. typing at the "|": > " | let i = "| | let i = "|" 'm | I| | I'm| < +------------------------------------------------------------------------------ + 3.4 SMART PARENS *delimitMateSmartParens* + +Like "smart quotes", but applied to parens (as well as [, {, etc.), only +inserting the opening delimiter if preceding an alphanumeric character. This +should cover adding parens, etc around existing words without having to handle +the uncessary closing delimiter. This feature can be disabled by setting the +option +|'delimitMate_smart_parens'| to 0. + +e.g. typing at the "|": > + + What | Before | After + ======================================= + ( | function| | function(|) + ( | |var | (|var +< ------------------------------------------------------------------------------ 3.5 BALANCING MATCHING PAIRS *delimitMateBalance* diff --git a/plugin/delimitMate.vim b/plugin/delimitMate.vim index 169cba3..60b956a 100644 --- a/plugin/delimitMate.vim +++ b/plugin/delimitMate.vim @@ -114,6 +114,8 @@ function! s:init() "{{{ " smart_quotes call s:option_init("smart_quotes", 1) + " smart_parens + call s:option_init("smart_parens", 1) " apostrophes call s:option_init("apostrophes", "")