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

View File

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