faster table format on InsertLeave; faster s:get_rows()

This commit is contained in:
lyokha 2019-03-15 15:31:28 +03:00
parent 07ba7339f1
commit 5e4a89c898
2 changed files with 9 additions and 7 deletions

View File

@ -226,8 +226,7 @@ function! s:get_rows(lnum, ...)
return
endif
let upper_rows = []
let lower_rows = []
let rows = []
let lnum = a:lnum - 1
let depth = a:0 > 0 ? a:1 : 0
@ -235,20 +234,23 @@ function! s:get_rows(lnum, ...)
while lnum >= 1 && (depth == 0 || ldepth < depth)
let line = getline(lnum)
if s:is_table(line)
call add(upper_rows, [lnum, line])
call insert(rows, [lnum, line])
else
break
endif
let lnum -= 1
let ldepth += 1
endwhile
call reverse(upper_rows)
let lnum = a:lnum
while lnum <= line('$')
let line = getline(lnum)
if s:is_table(line)
call add(lower_rows, [lnum, line])
if lnum == a:lnum
let cells = vimwiki#tbl#get_cells(line)
let line = s:fmt_row(cells, repeat([0], len(cells)), 0, 0)
endif
call add(rows, [lnum, line])
else
break
endif
@ -258,7 +260,7 @@ function! s:get_rows(lnum, ...)
let lnum += 1
endwhile
return upper_rows + lower_rows
return rows
endfunction

View File

@ -261,7 +261,7 @@ augroup vimwiki
" Format tables when exit from insert mode. Do not use textwidth to
" autowrap tables.
if vimwiki#vars#get_global('table_auto_fmt')
exe 'autocmd InsertLeave *'.s:ext.' call vimwiki#tbl#format(line("."))'
exe 'autocmd InsertLeave *'.s:ext.' call vimwiki#tbl#format(line("."), 2)'
exe 'autocmd InsertEnter *'.s:ext.' call vimwiki#tbl#reset_tw(line("."))'
endif
if vimwiki#vars#get_global('folding') =~? ':quick$'