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