From a13130946644a757c2b8847863fd5e3662c07358 Mon Sep 17 00:00:00 2001 From: Tom McDonald Date: Sat, 1 Aug 2015 15:42:45 -0400 Subject: [PATCH] Refactor user setting lookups --- plugin/exchange.vim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugin/exchange.vim b/plugin/exchange.vim index b4fe1db..e39bb5a 100644 --- a/plugin/exchange.vim +++ b/plugin/exchange.vim @@ -8,9 +8,8 @@ function! s:exchange(x, y, reverse, expand) let selection = &selection set selection=inclusive - let indent = (exists("b:exchange_indent") ? (b:exchange_indent !~ 0) : - \ (exists("g:exchange_indent") && (g:exchange_indent !~ 0))) - \ && a:x.type==# 'V' && a:y.type ==# 'V' + let indent = s:get_setting('exchange_indent', 0) != 0 && a:x.type ==# 'V' && a:y.type ==# 'V' + if indent let xindent = matchstr(getline(nextnonblank(a:y.start.line)), '^\s*') let yindent = matchstr(getline(nextnonblank(a:x.start.line)), '^\s*') @@ -67,7 +66,7 @@ function! s:fix_cursor(x, y, reverse) endfunction function! s:reindent(start, lines, new_indent) - if (exists('b:exchange_indent') ? b:exchange_indent : g:exchange_indent) == '==' + if s:get_setting('exchange_indent', 0) == '==' let lnum = nextnonblank(a:start) let line = getline(lnum) execute "silent normal! " . lnum . "G==" @@ -317,6 +316,10 @@ function! s:create_map(mode, lhs, rhs) endif endfunction +function! s:get_setting(setting, default) + return get(b:, a:setting, get(g:, a:setting, a:default)) +endfunction + highlight default link ExchangeRegion IncSearch nnoremap (Exchange) :set operatorfunc=exchange_setg@