mirror of
https://github.com/junegunn/vim-easy-align.git
synced 2025-11-11 19:33:50 -05:00
Fix issue #19 (hard tab indentation)
This commit is contained in:
@@ -65,10 +65,12 @@ let s:shorthand = {
|
||||
\ }
|
||||
|
||||
if exists("*strwidth")
|
||||
let s:strwidth = function('strwidth')
|
||||
function! s:strwidth(str)
|
||||
return strwidth(a:str) + len(matchstr(a:str, '^\t*')) * (&tabstop - 1)
|
||||
endfunction
|
||||
else
|
||||
function! s:strwidth(str)
|
||||
return len(split(a:str, '\zs'))
|
||||
return len(split(a:str, '\zs')) + len(matchstr(a:str, '^\t*')) * (&tabstop - 1)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
@@ -394,11 +396,13 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
|
||||
continue
|
||||
endif
|
||||
|
||||
let indent = match(tokens[0], '^\s*\zs')
|
||||
let indent = s:strwidth(matchstr(tokens[0], '^\s*'))
|
||||
if min_indent < 0 || indent < min_indent
|
||||
let min_indent = indent
|
||||
endif
|
||||
if mode ==? 'c' | let token .= matchstr(token, '^\s*') | endif
|
||||
if mode ==? 'c'
|
||||
let token .= substitute(matchstr(token, '^\s*'), '\t', repeat(' ', &tabstop), 'g')
|
||||
endif
|
||||
let [pw, tw] = [s:strwidth(prefix), s:strwidth(token)]
|
||||
let max.indent = max([max.indent, indent])
|
||||
let max.token_len = max([max.token_len, tw])
|
||||
@@ -476,7 +480,8 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
|
||||
endif
|
||||
elseif mode ==? 'r'
|
||||
let pad = repeat(' ', max.just_len - pw - tw)
|
||||
let token = pad . token
|
||||
let indent = matchstr(token, '^\s*')
|
||||
let token = indent . pad . s:ltrim(token)
|
||||
elseif mode ==? 'c'
|
||||
let p1 = max.pivot_len - (pw + tw / 2.0)
|
||||
let p2 = (max.token_len - tw) / 2.0
|
||||
@@ -485,7 +490,8 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
|
||||
else | let p2 = floor(p2)
|
||||
endif
|
||||
let strip = float2nr(ceil((max.token_len - max.strip_len) / 2.0))
|
||||
let token = repeat(' ', float2nr(pf1)) .token. repeat(' ', float2nr(p2))
|
||||
let indent = matchstr(token, '^\s*')
|
||||
let token = indent. repeat(' ', float2nr(pf1)) .s:ltrim(token). repeat(' ', float2nr(p2))
|
||||
let token = substitute(token, repeat(' ', strip) . '$', '', '')
|
||||
|
||||
if d.stick_to_left
|
||||
|
||||
@@ -1432,6 +1432,57 @@ Expect:
|
||||
|
||||
###########################################################
|
||||
|
||||
Given (hard-tab indentation (#19)):
|
||||
a=1=3
|
||||
bbb=2=4
|
||||
ccccc=4=5
|
||||
fff=4=6
|
||||
|
||||
Do (Left alignment):
|
||||
vip\<Enter>=
|
||||
|
||||
Expect:
|
||||
a = 1=3
|
||||
bbb = 2=4
|
||||
ccccc = 4=5
|
||||
fff = 4=6
|
||||
|
||||
Do (Right alignment):
|
||||
vip\<Enter>\<Enter>=
|
||||
|
||||
Expect:
|
||||
a = 1=3
|
||||
bbb = 2=4
|
||||
ccccc = 4=5
|
||||
fff = 4=6
|
||||
|
||||
Do (Center alignment):
|
||||
vip\<Enter>\<Enter>\<Enter>=
|
||||
|
||||
Expect:
|
||||
a = 1=3
|
||||
bbb = 2=4
|
||||
ccccc = 4=5
|
||||
fff = 4=6
|
||||
|
||||
Given (hard-tab indentation - dictionary (#19)):
|
||||
ddict={'homePage':'360452',
|
||||
'key':'TEST',
|
||||
'name':'DocumentationAPITestingSpace',
|
||||
'type':'global',
|
||||
'url':'http://localhost:8090/display/TEST'}
|
||||
|
||||
Do (Right alignment):
|
||||
vip\<Enter>\<Enter>:
|
||||
|
||||
Expect:
|
||||
ddict={'homePage': '360452',
|
||||
'key': 'TEST',
|
||||
'name': 'DocumentationAPITestingSpace',
|
||||
'type': 'global',
|
||||
'url': 'http://localhost:8090/display/TEST'}
|
||||
|
||||
###########################################################
|
||||
Execute:
|
||||
Restore
|
||||
|
||||
|
||||
Reference in New Issue
Block a user