diff --git a/autoload/delimitMate.vim b/autoload/delimitMate.vim index 3d9a720..e6e3a0c 100644 --- a/autoload/delimitMate.vim +++ b/autoload/delimitMate.vim @@ -12,32 +12,20 @@ if !exists('s:options') let s:options = {} endif -function! s:set(name, value, ...) "{{{ - let scope = a:0 ? a:1 : 's' +function! s:set(name, value) "{{{ let bufnr = bufnr('%') - if !exists('s:options[bufnr]') + if !has_key(s:options, bufnr) let s:options[bufnr] = {} endif - if scope == 's' - let name = 's:options.' . bufnr . '.' . a:name - else - let name = scope . ':delimitMate_' . a:name - if exists('name') - exec 'unlet! ' . name - endif - endif - exec 'let ' . name . ' = a:value' + let s:options[bufnr][a:name] = a:value endfunction "}}} -function! s:get(name, ...) "{{{ - if a:0 == 2 - return deepcopy(get(a:2, 'delimitMate_' . a:name, a:1)) - elseif a:0 == 1 - let bufoptions = get(s:options, bufnr('%'), {}) - return deepcopy(get(bufoptions, a:name, a:1)) - else - return deepcopy(eval('s:options.' . bufnr('%') . '.' . a:name)) +function! s:get(...) "{{{ + let options = deepcopy(eval('s:options.' . bufnr('%'))) + if a:0 + return options[a:1] endif + return options endfunction "}}} function! s:exists(name, ...) "{{{ diff --git a/plugin/delimitMate.vim b/plugin/delimitMate.vim index cf16fe8..46964ee 100644 --- a/plugin/delimitMate.vim +++ b/plugin/delimitMate.vim @@ -29,15 +29,14 @@ let delimitMate_version = "2.8" " Functions: {{{ function! s:option_init(name, default) "{{{ - let b = exists("b:delimitMate_" . a:name) - let g = exists("g:delimitMate_" . a:name) + let opt_name = "delimitMate_" . a:name " Find value to use. - if !b && !g + if !has_key(b:, opt_name) && !has_key(g:, opt_name) let value = a:default - elseif b - exec "let value = b:delimitMate_" . a:name + elseif has_key(b:, opt_name) + let value = b:[opt_name] else - exec "let value = g:delimitMate_" . a:name + let value = g:[opt_name] endif call s:set(a:name, value) endfunction "}}} @@ -48,8 +47,8 @@ function! s:init() "{{{ call s:option_init("autoclose", 1) " matchpairs call s:option_init("matchpairs", string(&matchpairs)[1:-2]) - call s:option_init("matchpairs_list", map(split(s:get('matchpairs'), '.:.\zs,\ze.:.'), 'split(v:val, ''^.\zs:\ze.$'')')) - let pairs = s:get('matchpairs_list') + call s:option_init("matchpairs_list", map(split(s:get('matchpairs', ''), '.:.\zs,\ze.:.'), 'split(v:val, ''^.\zs:\ze.$'')')) + let pairs = s:get('matchpairs_list', []) if len(filter(pairs, 'v:val[0] ==# v:val[1]')) echohl ErrorMsg echom 'delimitMate: each member of a pair in delimitMate_matchpairs must be different from each other.' @@ -57,17 +56,17 @@ function! s:init() "{{{ echohl Normal return 0 endif - call s:option_init("left_delims", map(copy(s:get('matchpairs_list')), 'v:val[0]')) - call s:option_init("right_delims", map(copy(s:get('matchpairs_list')), 'v:val[1]')) + call s:option_init("left_delims", map(copy(s:get('matchpairs_list', [])), 'v:val[0]')) + call s:option_init("right_delims", map(copy(s:get('matchpairs_list', [])), 'v:val[1]')) " quotes call s:option_init("quotes", "\" ' `") - call s:option_init("quotes_list",split(s:get('quotes'), '\s\+')) + call s:option_init("quotes_list",split(s:get('quotes', ''), '\s\+')) " nesting_quotes call s:option_init("nesting_quotes", []) " excluded_regions call s:option_init("excluded_regions", "Comment") - call s:option_init("excluded_regions_list", split(s:get('excluded_regions'), ',\s*')) - let enabled = len(s:get('excluded_regions_list')) > 0 + call s:option_init("excluded_regions_list", split(s:get('excluded_regions', ''), ',\s*')) + let enabled = len(s:get('excluded_regions_list', [])) > 0 call s:option_init("excluded_regions_enabled", enabled) " expand_space if exists("b:delimitMate_expand_space") && type(b:delimitMate_expand_space) == type("") @@ -110,7 +109,7 @@ function! s:init() "{{{ call s:option_init("smart_matchpairs", '^\%(\w\|\!\|[£$]\|[^[:punct:][:space:]]\)') " smart_quotes " XXX: backward compatibility. Ugly, should go the way of the dodo soon. - let quotes = escape(join(s:get('quotes_list'), ''), '\-^[]') + let quotes = escape(join(s:get('quotes_list', []), ''), '\-^[]') let default_smart_quotes = '\%(\w\|[^[:punct:][:space:]' . quotes . ']\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[^[:space:][:punct:]' . quotes . ']\)' if exists('g:delimitMate_smart_quotes') && type(g:delimitMate_smart_quotes) == type(0) if g:delimitMate_smart_quotes @@ -134,7 +133,7 @@ function! s:init() "{{{ call s:option_init("smart_quotes", default_smart_quotes) " apostrophes call s:option_init("apostrophes", "") - call s:option_init("apostrophes_list", split(s:get('apostrophes'), ":\s*")) + call s:option_init("apostrophes_list", split(s:get('apostrophes', ''), ":\s*")) " tab2exit call s:option_init("tab2exit", 1) " balance_matchpairs @@ -146,9 +145,10 @@ function! s:init() "{{{ return 1 endfunction "}}} Init() -function! s:get(...) " {{{ - return call('delimitMate#Get', a:000) -endfunction " }}} +function! s:get(name, default) "{{{ + let bufoptions = delimitMate#Get() + return get(bufoptions, a:name, a:default) +endfunction "}}} function! s:set(...) " {{{ return call('delimitMate#Set', a:000) @@ -164,7 +164,7 @@ function! s:Map() "{{{ set keymap= set cpo&vim silent! doautocmd User delimitMate_map - if s:get('autoclose') + if s:get('autoclose', 1) call s:AutoClose() else call s:NoAutoClose() @@ -270,7 +270,7 @@ endfunction "}}} function! s:NoAutoClose() "{{{ " inoremap ) =delimitMate#SkipDelim('\)') - for delim in s:get('right_delims') + s:get('quotes_list') + for delim in s:get('right_delims', []) + s:get('quotes_list', []) if delim == '|' let delim = '' endif @@ -283,9 +283,9 @@ function! s:AutoClose() "{{{ " Add matching pair and jump to the midle: " inoremap ( () let i = 0 - while i < len(s:get('matchpairs_list')) - let ld = s:get('left_delims')[i] == '|' ? '' : s:get('left_delims')[i] - let rd = s:get('right_delims')[i] == '|' ? '' : s:get('right_delims')[i] + while i < len(s:get('matchpairs_list', [])) + let ld = s:get('left_delims', [])[i] == '|' ? '' : s:get('left_delims', [])[i] + let rd = s:get('right_delims', [])[i] == '|' ? '' : s:get('right_delims', [])[i] exec 'inoremap delimitMate' . ld \. ' TriggerAbb().delimitMate#ParenDelim("' . escape(rd, '|') . '")' exec 'silent! imap '.ld @@ -294,7 +294,7 @@ function! s:AutoClose() "{{{ endwhile " Exit from inside the matching pair: - for delim in s:get('right_delims') + for delim in s:get('right_delims', []) let delim = delim == '|' ? '' : delim exec 'inoremap delimitMate' . delim \. ' TriggerAbb().delimitMate#JumpOut("\' . delim . '")' @@ -304,7 +304,7 @@ function! s:AutoClose() "{{{ " Add matching quote and jump to the midle, or exit if inside a pair of matching quotes: " inoremap " =delimitMate#QuoteDelim("\"") - for delim in s:get('quotes_list') + for delim in s:get('quotes_list', []) if delim == '|' let delim = '' endif @@ -316,7 +316,7 @@ function! s:AutoClose() "{{{ " Try to fix the use of apostrophes (kept for backward compatibility): " inoremap n't n't - for map in s:get('apostrophes_list') + for map in s:get('apostrophes_list', []) exec "inoremap " . map . " " . map exec 'silent! imap ' . map . ' delimitMate' . map endfor @@ -340,17 +340,17 @@ function! s:ExtraMappings() "{{{ endif " Expand return if inside an empty pair: inoremap delimitMateCR TriggerAbb()."\=delimitMate#ExpandReturn()\" - if s:get('expand_cr') && !hasmapto('delimitMateCR', 'i') && maparg('', 'i') == '' + if s:get('expand_cr', 0) && !hasmapto('delimitMateCR', 'i') && maparg('', 'i') == '' silent! imap delimitMateCR endif " Expand space if inside an empty pair: inoremap delimitMateSpace TriggerAbb()."\=delimitMate#ExpandSpace()\" - if s:get('expand_space') && !hasmapto('delimitMateSpace', 'i') && maparg('', 'i') == '' + if s:get('expand_space', 0) && !hasmapto('delimitMateSpace', 'i') && maparg('', 'i') == '' silent! imap delimitMateSpace endif " Jump over any delimiter: inoremap delimitMateS-Tab TriggerAbb()."\=delimitMate#JumpAny()\" - if s:get('tab2exit') && !hasmapto('delimitMateS-Tab', 'i') && maparg('', 'i') == '' + if s:get('tab2exit', 0) && !hasmapto('delimitMateS-Tab', 'i') && maparg('', 'i') == '' silent! imap delimitMateS-Tab endif " Jump over next delimiters