1
0
Fork 0
Browse Source

Fix a few bugs

master
Gavin Howard 2 years ago
parent
commit
15c6ee0380
Signed by: gavin
GPG Key ID: C08038BDF280D33E
  1. 31
      autoload/spacealign.vim

31
autoload/spacealign.vim

@ -35,7 +35,6 @@ function! spacealign#replaceCinoptions()
let s:cinoptions = &cinoptions
let s:tcinoptions = spacealign#replaceCino(s:cinoptions, 'n', '-s')
let s:tcinoptions = spacealign#replaceCino(s:tcinoptions, '=', '0')
let s:tcinoptions = spacealign#replaceCino(s:tcinoptions, 'l', '1')
endfunction
function! spacealign#cind(idx, val)
@ -87,9 +86,7 @@ function! spacealign#findTabs(lnum, cin1, cin2, curpos, linestop, ignoreempty)
return [cindiff, linestop]
endif
call setpos('.', a:curpos)
execute 'normal! ^'
if line[col(".") - 1] == "}"
if match(line, '^\s*}$') != -1
return [a:cin1 / &tabstop + cindiff, linestop]
endif
@ -142,18 +139,20 @@ function! spacealign#align(first, last, ignoreempty)
for lidx in idxs
let lineno = linerange[lidx]
let line = getline(lineno)
if a:ignoreempty && len(line) == 0
continue
endif
let cin1 = list1[lidx]
let cin2 = list2[lidx]
let curtabs = cin1 / tabstp
let curtabs = len(matchstr(line, '^\t*'))
let curpos[1] = lineno
let [ntabs, linestop] = spacealign#findTabs(lineno, cin1, cin2, curpos, linestop, a:ignoreempty)
if !a:ignoreempty && (ntabs == -1 || ntabs == curtabs)
continue
endif
let nspaces = cin1 - ntabs * tabstp
if ntabs != oldntabs
@ -166,8 +165,7 @@ function! spacealign#align(first, last, ignoreempty)
let sspaces = strpart(s:spaces, 0, nspaces)
endif
let line = getline(lineno)
let cleanLine = substitute(line, '^\(\s\| \)\+', '', '')
let cleanLine = substitute(line, '^\s\+', '', '')
call setline(lineno, stabs . sspaces . cleanLine)
endfor
@ -179,6 +177,10 @@ endfunction
function! spacealign#insertTab(lnum)
if s:cinoptions != &cinoptions
call spacealign#replaceCinoptions()
endif
let savecursor = getcurpos()
let line = getline(a:lnum)
let retval = len(line) > savecursor[2]
@ -196,8 +198,11 @@ function! spacealign#insertTab(lnum)
let scol = savecursor[2]
let idx = savecursor[2] - 1
let cin = cindent(a:lnum)
let [expectedtabs, linestop] = spacealign#findTabs(a:lnum, cin, curpos, 0, 1)
let cin1 = cindent(a:lnum)
let &cinoptions = s:tcinoptions
let cin2 = cindent(a:lnum)
let [expectedtabs, linestop] = spacealign#findTabs(a:lnum, cin1, cin2, curpos, 0, 1)
let ntabs = len(matchstr(line, "^[\t]*", 0))
let nspaces = len(matchstr(line, "^[\t]*[ ]*", 0)) - ntabs

Loading…
Cancel
Save