Remove recursion not to fail in case of many delimiters (> maxfuncdepth)

This commit is contained in:
Junegunn Choi
2013-10-13 03:31:05 +09:00
parent cb7306341c
commit 256e5b83ab
4 changed files with 50 additions and 21 deletions

View File

@@ -331,7 +331,7 @@ function! s:max(old, new)
endfor endfor
endfunction endfunction
function! s:do_align(modes, all_tokens, all_delims, fl, ll, fc, lc, pattern, nth, function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, pattern, nth,
\ ml, mr, da, indentation, stick_to_left, ignore_unmatched, ignore_groups, recur) \ ml, mr, da, indentation, stick_to_left, ignore_unmatched, ignore_groups, recur)
let mode = a:modes[0] let mode = a:modes[0]
let lines = {} let lines = {}
@@ -392,7 +392,7 @@ function! s:do_align(modes, all_tokens, all_delims, fl, ll, fc, lc, pattern, nth
continue continue
endif endif
let indent = len(matchstr(tokens[0], '^\s\+')) let indent = match(tokens[0], '^\s*\zs')
if min_indent < 0 || indent < min_indent if min_indent < 0 || indent < min_indent
let min_indent = indent let min_indent = indent
endif endif
@@ -527,18 +527,19 @@ function! s:do_align(modes, all_tokens, all_delims, fl, ll, fc, lc, pattern, nth
let tokens[nth] = aligned let tokens[nth] = aligned
" Update the line " Update the line
let newline = s:rtrim(before.join(tokens, '').after) let a:todo[line] = before.join(tokens, '').after
call setline(line, newline)
endfor endfor
if a:nth < max.tokens && (a:recur || len(a:modes) > 1) if a:nth < max.tokens && (a:recur || len(a:modes) > 1)
call s:shift(a:modes, a:recur == 2) call s:shift(a:modes, a:recur == 2)
call s:do_align( return [
\ a:todo,
\ a:modes, a:all_tokens, a:all_delims, \ a:modes, a:all_tokens, a:all_delims,
\ a:fl, a:ll, a:fc, a:lc, a:pattern, \ a:fl, a:ll, a:fc, a:lc, a:pattern,
\ a:nth + 1, a:ml, a:mr, a:da, a:indentation, a:stick_to_left, \ a:nth + 1, a:ml, a:mr, a:da, a:indentation, a:stick_to_left,
\ a:ignore_unmatched, a:ignore_groups, a:recur) \ a:ignore_unmatched, a:ignore_groups, a:recur]
endif endif
return [a:todo]
endfunction endfunction
function! s:input(str, default, vis) function! s:input(str, default, vis)
@@ -905,7 +906,9 @@ function! s:align(bang, first_line, last_line, expr)
let aseq_list = type(aseq) == 1 ? split(tolower(aseq), '\s*') : map(copy(aseq), 'tolower(v:val)') let aseq_list = type(aseq) == 1 ? split(tolower(aseq), '\s*') : map(copy(aseq), 'tolower(v:val)')
let aseq_str = join(aseq_list, '') let aseq_str = join(aseq_list, '')
call s:do_align( let todo = {}
let args = [
\ todo,
\ aseq_list, \ aseq_list,
\ {}, {}, a:first_line, a:last_line, \ {}, {}, a:first_line, a:last_line,
\ bvisual ? min([col("'<"), col("'>")]) : 1, \ bvisual ? min([col("'<"), col("'>")]) : 1,
@@ -919,7 +922,13 @@ function! s:align(bang, first_line, last_line, expr)
\ get(dict, 'stick_to_left', 0), \ get(dict, 'stick_to_left', 0),
\ get(dict, 'ignore_unmatched', get(g:, 'easy_align_ignore_unmatched', 2)), \ get(dict, 'ignore_unmatched', get(g:, 'easy_align_ignore_unmatched', 2)),
\ get(dict, 'ignore_groups', get(dict, 'ignores', s:ignored_syntax())), \ get(dict, 'ignore_groups', get(dict, 'ignores', s:ignored_syntax())),
\ recur) \ recur ]
while len(args) > 1
let args = call('s:do_align', args)
endwhile
for [line, content] in items(todo)
call setline(line, s:rtrim(content))
endfor
let copts = s:compact_options(opts) let copts = s:compact_options(opts)
let nbmode = s:modes(0)[0] let nbmode = s:modes(0)[0]

21
test/fixed.vader Normal file
View File

@@ -0,0 +1,21 @@
Given (Table):
|a|b|c|d|
| -|-|>-|-|
|aaa|bbb|ccc|ddd|
Do (Partial alignment around 1st |):
\<C-V>ljj\<Enter>|
Expect (Right margin should be correctly attached):
| a|b|c|d|
| -|-|>-|-|
| aaa|bbb|ccc|ddd|
Given (empty buffer):
Execute (Aligning lines with many delimiters should not fail):
call visualmode(1)
call setline(1, repeat('|', &maxfuncdepth + 1))
%EasyAlign*|
AssertEqual (&maxfuncdepth + 1) * 3 - 2, len(getline(1))

12
test/fixme.vader Normal file
View File

@@ -0,0 +1,12 @@
# It is currently possible that EasyAlign command incorrectly judges
# that it was executed in block-wise visual mode
Given:
a|b|c
Do (FIXME invalid judgement - block-wise visual mode):
\<C-V>\<Esc>
:%EasyAlign|\<CR>
Expect:
a | b | c

View File

@@ -1283,16 +1283,3 @@ Expect:
a = b = c a = b = c
aabba = bbbbb aabba = bbbbb
Given (Table):
|a|b|c|d|
| -|-|>-|-|
|aaa|bbb|ccc|ddd|
Do (Partial alignment around 1st |):
\<C-V>ljj\<Enter>|
Expect (Right margin correctly attached):
| a|b|c|d|
| -|-|>-|-|
| aaa|bbb|ccc|ddd|