Fix issue #19 (hard tab indentation)

This commit is contained in:
Junegunn Choi
2013-10-31 11:08:02 +09:00
parent 15bcbc9499
commit 2b119f9bb6
2 changed files with 63 additions and 6 deletions

View File

@@ -65,10 +65,12 @@ let s:shorthand = {
\ } \ }
if exists("*strwidth") 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 else
function! s:strwidth(str) function! s:strwidth(str)
return len(split(a:str, '\zs')) return len(split(a:str, '\zs')) + len(matchstr(a:str, '^\t*')) * (&tabstop - 1)
endfunction endfunction
endif endif
@@ -394,11 +396,13 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
continue continue
endif endif
let indent = match(tokens[0], '^\s*\zs') let indent = s:strwidth(matchstr(tokens[0], '^\s*'))
if min_indent < 0 || indent < min_indent if min_indent < 0 || indent < min_indent
let min_indent = indent let min_indent = indent
endif 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 [pw, tw] = [s:strwidth(prefix), s:strwidth(token)]
let max.indent = max([max.indent, indent]) let max.indent = max([max.indent, indent])
let max.token_len = max([max.token_len, tw]) 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 endif
elseif mode ==? 'r' elseif mode ==? 'r'
let pad = repeat(' ', max.just_len - pw - tw) 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' elseif mode ==? 'c'
let p1 = max.pivot_len - (pw + tw / 2.0) let p1 = max.pivot_len - (pw + tw / 2.0)
let p2 = (max.token_len - 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) else | let p2 = floor(p2)
endif endif
let strip = float2nr(ceil((max.token_len - max.strip_len) / 2.0)) 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) . '$', '', '') let token = substitute(token, repeat(' ', strip) . '$', '', '')
if d.stick_to_left if d.stick_to_left

View File

@@ -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: Execute:
Restore Restore