Prettify tbl.vim

This commit is contained in:
Tinmarino 2020-07-21 15:15:56 -04:00
parent dfc5344d0c
commit 667929d3f9

View File

@ -9,6 +9,7 @@
" Clause: Load only once
if exists('g:loaded_vimwiki_tbl_auto') || &compatible
finish
endif
@ -53,12 +54,14 @@ function! s:sep_splitter() abort
endfunction
" Check if param:line is in a table
function! s:is_table(line) abort
return s:is_separator(a:line) ||
\ (a:line !~# s:rxSep().s:rxSep() && a:line =~# '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$')
endfunction
" Check if param:line is a separator (ex: | --- | --- |)
function! s:is_separator(line) abort
return a:line =~# '^\s*'.s:rxSep().'\(:\=--\+:\='.s:rxSep().'\)\+\s*$'
endfunction
@ -668,6 +671,7 @@ endfunction
function! vimwiki#tbl#format(lnum, ...) abort
" Clause in
if !vimwiki#u#ft_is_vw()
return
endif
@ -756,21 +760,19 @@ endfunction
" TODO: move_column_left and move_column_right are good candidates to be refactored.
function! vimwiki#tbl#move_column_left() abort
"echomsg "DEBUG move_column_left: "
" Clause in
let line = getline('.')
if !s:is_table(line)
return
endif
let cur_col = s:cur_column()
if cur_col == -1
return
endif
if cur_col <= 0
return
endif
if cur_col > 0
call vimwiki#tbl#format(line('.'), cur_col-1, cur_col)
call cursor(line('.'), 1)
@ -785,28 +787,28 @@ function! vimwiki#tbl#move_column_left() abort
break
endif
endwhile
endif
endfunction
function! vimwiki#tbl#move_column_right() abort
" Clause in
let line = getline('.')
if !s:is_table(line)
return
endif
let cur_col = s:cur_column()
if cur_col == -1
return
endif
if cur_col >= s:col_count(line('.'))-1
return
endif
if cur_col < s:col_count(line('.'))-1
" Format table && Put cursor on first col
call vimwiki#tbl#format(line('.'), cur_col, cur_col+1)
call cursor(line('.'), 1)
" Change add one to all col
let sep = '\('.s:rxSep().'\).\zs'
let mpos = -1
let col = -1
@ -818,7 +820,6 @@ function! vimwiki#tbl#move_column_right() abort
break
endif
endwhile
endif
endfunction
@ -845,4 +846,3 @@ endfunction
function! vimwiki#tbl#sep_splitter() abort
return s:sep_splitter()
endfunction