mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-09 10:23:49 -05:00
Fix indentation option to work with hard tabs (#19)
This commit is contained in:
@@ -422,11 +422,11 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
|
||||
if a:nth == 1
|
||||
let idt = d.indentation
|
||||
if idt ==? 'd'
|
||||
let indent = repeat(' ', max.indent)
|
||||
let indent = max.indent
|
||||
elseif idt ==? 's'
|
||||
let indent = repeat(' ', min_indent)
|
||||
let indent = min_indent
|
||||
elseif idt ==? 'n'
|
||||
let indent = ''
|
||||
let indent = 0
|
||||
elseif idt !=? 'k'
|
||||
call s:exit('Invalid indentation: ' . idt)
|
||||
end
|
||||
@@ -439,9 +439,22 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
|
||||
for [line, elems] in items(lines)
|
||||
let [nth, prefix, token, delim] = elems
|
||||
|
||||
let token = substitute(token, '^\s*', indent, '')
|
||||
let tindent = matchstr(token, '^\s*')
|
||||
while 1
|
||||
let len = s:strwidth(tindent)
|
||||
if len < indent
|
||||
let tindent .= repeat(' ', indent - len)
|
||||
break
|
||||
elseif len > indent
|
||||
let tindent = tindent[0 : -2]
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
let token = tindent . s:ltrim(token)
|
||||
if mode ==? 'c'
|
||||
let token = substitute(token, '\s*$', indent, '')
|
||||
let token = substitute(token, '\s*$', repeat(' ', indent), '')
|
||||
endif
|
||||
let [pw, tw] = [s:strwidth(prefix), s:strwidth(token)]
|
||||
let max.token_len = max([max.token_len, tw])
|
||||
|
||||
@@ -1465,6 +1465,24 @@ Expect:
|
||||
ccccc = 4=5
|
||||
fff = 4=6
|
||||
|
||||
Do (Left alignment with shallow indentation):
|
||||
vip\<Enter>\<C-I>=
|
||||
|
||||
Expect:
|
||||
a = 1=3
|
||||
bbb = 2=4
|
||||
ccccc = 4=5
|
||||
fff = 4=6
|
||||
|
||||
Do (Center alignment with deep indentation):
|
||||
vip\<Enter>\<Enter>\<Enter>\<C-I>\<C-I>=
|
||||
|
||||
Expect:
|
||||
a = 1=3
|
||||
bbb = 2=4
|
||||
ccccc = 4=5
|
||||
fff = 4=6
|
||||
|
||||
Given (hard-tab indentation - dictionary (#19)):
|
||||
ddict={'homePage':'360452',
|
||||
'key':'TEST',
|
||||
|
||||
Reference in New Issue
Block a user