From a1e28c44113207313b8fe598f6d99d9424724f00 Mon Sep 17 00:00:00 2001 From: Jacob Niehus Date: Sat, 1 Aug 2015 20:15:15 -0700 Subject: [PATCH 1/3] Change indent comparison to !~ with explanation Truth table: x x != 0 x !~ 0 0 0 0 1 1 1 '==' 0 1 --- plugin/exchange.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/exchange.vim b/plugin/exchange.vim index 762b189..044cd74 100644 --- a/plugin/exchange.vim +++ b/plugin/exchange.vim @@ -8,7 +8,8 @@ function! s:exchange(x, y, reverse, expand) let selection = &selection set selection=inclusive - let indent = s:get_setting('exchange_indent', 1) != 0 && a:x.type ==# 'V' && a:y.type ==# 'V' + " Compare using =~ because "'==' != 0" returns 0 + let indent = s:get_setting('exchange_indent', 1) !~ 0 && a:x.type ==# 'V' && a:y.type ==# 'V' if indent let xindent = matchstr(getline(nextnonblank(a:y.start.line)), '^\s*') From d54c7e27fe169254299b9972216c1793129f426b Mon Sep 17 00:00:00 2001 From: Jacob Niehus Date: Sat, 1 Aug 2015 20:19:31 -0700 Subject: [PATCH 2/3] Prevent calling setline() incorrectly Automatic re-indenting shouldn't call setline() on a line outside of the exchange region. It currently does so if the exchange region only contains blank lines. --- plugin/exchange.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/exchange.vim b/plugin/exchange.vim index 044cd74..4155d4b 100644 --- a/plugin/exchange.vim +++ b/plugin/exchange.vim @@ -69,6 +69,9 @@ endfunction function! s:reindent(start, lines, new_indent) if s:get_setting('exchange_indent', 1) == '==' let lnum = nextnonblank(a:start) + if lnum == 0 || lnum > a:start + a:lines - 1 + return + endif let line = getline(lnum) execute "silent normal! " . lnum . "G==" let new_indent = matchstr(getline(lnum), '^\s*') From 1ff6e3c65baa6762c8505bfb9ea02900a4bfa590 Mon Sep 17 00:00:00 2001 From: Jacob Niehus Date: Sun, 2 Aug 2015 10:13:13 -0700 Subject: [PATCH 3/3] Fix indentation of return line --- plugin/exchange.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/exchange.vim b/plugin/exchange.vim index 4155d4b..e3491f5 100644 --- a/plugin/exchange.vim +++ b/plugin/exchange.vim @@ -70,7 +70,7 @@ function! s:reindent(start, lines, new_indent) if s:get_setting('exchange_indent', 1) == '==' let lnum = nextnonblank(a:start) if lnum == 0 || lnum > a:start + a:lines - 1 - return + return endif let line = getline(lnum) execute "silent normal! " . lnum . "G=="