From 21697776b497d4cc14520a11272223048960c240 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 13 Sep 2014 19:54:49 +0900 Subject: [PATCH] Allow recursive alignment (*, **) in blockwise-visual mode Recursive alignment in blockwise-visual mode will align around all the delimiters found after the start of the block. This behavior is inconsistent with non-recursive alignment where the delimiters after the end of the block are ignored. Making it respect the end of the block is non-trivial and may not be intuitive as each alignment will change the position of the delimiters inside the block and some of them will end up beyond the scope of the block. --- autoload/easy_align.vim | 18 +++++------------- test/blockwise.vader | 22 ++++++++++++++++++++++ test/include/setup.vader | 1 + 3 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 test/blockwise.vader diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index 846dc71..dbaa73f 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -617,7 +617,7 @@ function! s:shift_opts(opts, key, vals) endif endfunction -function! s:interactive(range, modes, n, d, opts, rules, vis, live) +function! s:interactive(range, modes, n, d, opts, rules, vis, live, bvis) let mode = s:shift(a:modes, 1) let n = a:n let d = a:d @@ -637,7 +637,7 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live) let rdrw = 1 endif if a:live && !empty(d) - let output = s:process(a:range, mode, n, d, s:normalize_options(opts), regx, a:rules, 0) + let output = s:process(a:range, mode, n, d, s:normalize_options(opts), regx, a:rules, a:bvis) let &undolevels = &undolevels " Break undo block call s:update_lines(output.todo) let undo = 1 @@ -1033,15 +1033,11 @@ function! s:process(range, mode, n, ch, opts, regexp, rules, bvis) \ get(dict, 'align', recur == 2 ? s:alternating_modes(a:mode) : a:mode), \ recur) - if recur && a:bvis - call s:exit('Recursive alignment is not supported in blockwise-visual mode') - endif - let args = [ \ {}, split(mode_sequence, '\zs'), \ {}, {}, a:range[0], a:range[1], - \ a:bvis ? min([col("'<"), col("'>")]) : 1, - \ a:bvis ? max([col("'<"), col("'>")]) : 0, + \ a:bvis ? min([col("'<"), col("'>")]) : 1, + \ (!recur && a:bvis) ? max([col("'<"), col("'>")]) : 0, \ nth, recur, dict ] while len(args) > 1 let args = call('s:do_align', args) @@ -1078,10 +1074,6 @@ function! s:align(bang, live, visualmode, first_line, last_line, expr) let modes = s:interactive_modes(a:bang) let mode = modes[0] - if bvis && a:live - call s:exit('Live mode is not supported in blockwise-visual mode') - endif - let rules = s:easy_align_delimiters_default if exists('g:easy_align_delimiters') let rules = extend(copy(rules), g:easy_align_delimiters) @@ -1095,7 +1087,7 @@ function! s:align(bang, live, visualmode, first_line, last_line, expr) if bypass_fold | let &l:foldmethod = 'manual' | endif if empty(n) && empty(ch) || a:live - let [mode, n, ch, opts, regexp] = s:interactive(range, copy(modes), n, ch, opts, rules, vis, a:live) + let [mode, n, ch, opts, regexp] = s:interactive(range, copy(modes), n, ch, opts, rules, vis, a:live, bvis) endif if !a:live diff --git a/test/blockwise.vader b/test/blockwise.vader new file mode 100644 index 0000000..ed158c2 --- /dev/null +++ b/test/blockwise.vader @@ -0,0 +1,22 @@ +Include: include/setup.vader + +Given clojure: + (def world [[1 1 1 1 1] + [999 999 999 999 1] + [1 1 1 1 1] + [1 999 999 999 999] + [1 1 1 1 1]]) + +Do (Recursive alignment in blockwise-visual mode): + f[; + \G + \*\ + +Expect clojure: + (def world [[1 1 1 1 1] + [999 999 999 999 1] + [1 1 1 1 1] + [1 999 999 999 999] + [1 1 1 1 1]]) + +Include: include/teardown.vader diff --git a/test/include/setup.vader b/test/include/setup.vader index 00610c9..ef1b919 100644 --- a/test/include/setup.vader +++ b/test/include/setup.vader @@ -30,3 +30,4 @@ Execute (Clean up test environment): nmap A (EasyAlign) vmap . (EasyAlignRepeat) + silent! call plug#load('vim-easy-align')