resolved conflicts in tbl.vim
This commit is contained in:
parent
920f41b318
commit
a74e0821b0
@ -30,7 +30,7 @@ With vimwiki you can:
|
|||||||
* manage todo-lists;
|
* manage todo-lists;
|
||||||
* write documentation.
|
* write documentation.
|
||||||
|
|
||||||
To do a quick start press `<Leader>`ww (this is usually \ww) to go to your index
|
To do a quick start press <Leader>ww (this is usually \ww) to go to your index
|
||||||
wiki file. By default it is located in:
|
wiki file. By default it is located in:
|
||||||
~/vimwiki/index.wiki
|
~/vimwiki/index.wiki
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ normal mode:
|
|||||||
* `<Leader>wd` -- Delete wiki file you are in.
|
* `<Leader>wd` -- Delete wiki file you are in.
|
||||||
* `<Leader>wr` -- Rename wiki file you are in.
|
* `<Leader>wr` -- Rename wiki file you are in.
|
||||||
* `<Enter>` -- Folow/Create wiki link
|
* `<Enter>` -- Folow/Create wiki link
|
||||||
* `<Shift-Enter>` -- Split and follow/create wiki link
|
* `<Shift-Enter>` -- Split and folow/create wiki link
|
||||||
* `<Ctrl-Enter>` -- Vertical split and folow/create wiki link
|
* `<Ctrl-Enter>` -- Vertical split and folow/create wiki link
|
||||||
* `<Backspace>` -- Go back to parent(previous) wiki link
|
* `<Backspace>` -- Go back to parent(previous) wiki link
|
||||||
* `<Tab>` -- Find next wiki link
|
* `<Tab>` -- Find next wiki link
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||||
" Vimwiki autoload plugin file
|
" Vimwiki autoload plugin file
|
||||||
" Desc: Tables
|
" Description: Tables
|
||||||
" | Easily | manageable | text | tables | ! |
|
" | Easily | manageable | text | tables | ! |
|
||||||
" |--------|------------|-------|--------|---------|
|
" |--------|------------|-------|--------|---------|
|
||||||
" | Have | fun! | Drink | tea | Period. |
|
" | Have | fun! | Drink | tea | Period. |
|
||||||
"
|
"
|
||||||
" Author: Maxim Kim <habamax@gmail.com>
|
" Home: https://github.com/vimwiki/vimwiki/
|
||||||
" Home: http://code.google.com/p/vimwiki/
|
|
||||||
|
|
||||||
|
|
||||||
" Load only once {{{
|
|
||||||
if exists("g:loaded_vimwiki_tbl_auto") || &cp
|
if exists("g:loaded_vimwiki_tbl_auto") || &cp
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let g:loaded_vimwiki_tbl_auto = 1
|
let g:loaded_vimwiki_tbl_auto = 1
|
||||||
"}}}
|
|
||||||
|
|
||||||
let s:textwidth = &tw
|
let s:textwidth = &tw
|
||||||
|
|
||||||
|
|
||||||
" Misc functions {{{
|
function! s:rxSep()
|
||||||
function! s:rxSep() "{{{
|
return vimwiki#vars#get_syntaxlocal('rxTableSep')
|
||||||
return g:vimwiki_rxTableSep
|
endfunction
|
||||||
endfunction "}}}
|
|
||||||
|
|
||||||
function! s:wide_len(str) "{{{
|
|
||||||
|
function! s:wide_len(str)
|
||||||
" vim73 has new function that gives correct string width.
|
" vim73 has new function that gives correct string width.
|
||||||
if exists("*strdisplaywidth")
|
if exists("*strdisplaywidth")
|
||||||
return strdisplaywidth(a:str)
|
return strdisplaywidth(a:str)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" get str display width in vim ver < 7.2
|
" get str display width in vim ver < 7.2
|
||||||
if !g:vimwiki_CJK_length
|
if !vimwiki#vars#get_global('CJK_length')
|
||||||
let ret = strlen(substitute(a:str, '.', 'x', 'g'))
|
let ret = strlen(substitute(a:str, '.', 'x', 'g'))
|
||||||
else
|
else
|
||||||
let savemodified = &modified
|
let savemodified = &modified
|
||||||
@ -43,42 +43,49 @@ function! s:wide_len(str) "{{{
|
|||||||
let &modified = savemodified
|
let &modified = savemodified
|
||||||
endif
|
endif
|
||||||
return ret
|
return ret
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:cell_splitter() "{{{
|
|
||||||
|
function! s:cell_splitter()
|
||||||
return '\s*'.s:rxSep().'\s*'
|
return '\s*'.s:rxSep().'\s*'
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:sep_splitter() "{{{
|
|
||||||
|
function! s:sep_splitter()
|
||||||
return '-'.s:rxSep().'-'
|
return '-'.s:rxSep().'-'
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:is_table(line) "{{{
|
|
||||||
return s:is_separator(a:line) || (a:line !~ s:rxSep().s:rxSep() && a:line =~ '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$')
|
|
||||||
endfunction "}}}
|
|
||||||
|
|
||||||
function! s:is_separator(line) "{{{
|
function! s:is_table(line)
|
||||||
return a:line =~ '^\s*'.s:rxSep().'\(--\+'.s:rxSep().'\)\+\s*$'
|
return s:is_separator(a:line) ||
|
||||||
endfunction "}}}
|
\ (a:line !~# s:rxSep().s:rxSep() && a:line =~# '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:is_separator_tail(line) "{{{
|
|
||||||
return a:line =~ '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$'
|
|
||||||
endfunction "}}}
|
|
||||||
|
|
||||||
function! s:is_last_column(lnum, cnum) "{{{
|
function! s:is_separator(line)
|
||||||
|
return a:line =~# '^\s*'.s:rxSep().'\(--\+'.s:rxSep().'\)\+\s*$'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! s:is_separator_tail(line)
|
||||||
|
return a:line =~# '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
function! s:is_last_column(lnum, cnum)
|
||||||
let line = strpart(getline(a:lnum), a:cnum - 1)
|
let line = strpart(getline(a:lnum), a:cnum - 1)
|
||||||
"echomsg "DEBUG is_last_column> ".(line =~ s:rxSep().'\s*$' && line !~ s:rxSep().'.*'.s:rxSep().'\s*$')
|
return line =~# s:rxSep().'\s*$' && line !~# s:rxSep().'.*'.s:rxSep().'\s*$'
|
||||||
return line =~ s:rxSep().'\s*$' && line !~ s:rxSep().'.*'.s:rxSep().'\s*$'
|
endfunction
|
||||||
|
|
||||||
endfunction "}}}
|
|
||||||
|
|
||||||
function! s:is_first_column(lnum, cnum) "{{{
|
function! s:is_first_column(lnum, cnum)
|
||||||
let line = strpart(getline(a:lnum), 0, a:cnum - 1)
|
let line = strpart(getline(a:lnum), 0, a:cnum - 1)
|
||||||
"echomsg "DEBUG is_first_column> ".(line =~ '^\s*'.s:rxSep() && line !~ '^\s*'.s:rxSep().'.*'.s:rxSep())
|
return line =~# '^\s*$' ||
|
||||||
return line =~ '^\s*$' || (line =~ '^\s*'.s:rxSep() && line !~ '^\s*'.s:rxSep().'.*'.s:rxSep())
|
\ (line =~# '^\s*'.s:rxSep() && line !~# '^\s*'.s:rxSep().'.*'.s:rxSep())
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:count_separators_up(lnum) "{{{
|
|
||||||
|
function! s:count_separators_up(lnum)
|
||||||
let lnum = a:lnum - 1
|
let lnum = a:lnum - 1
|
||||||
while lnum > 1
|
while lnum > 1
|
||||||
if !s:is_separator(getline(lnum))
|
if !s:is_separator(getline(lnum))
|
||||||
@ -88,9 +95,10 @@ function! s:count_separators_up(lnum) "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return (a:lnum-lnum)
|
return (a:lnum-lnum)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:count_separators_down(lnum) "{{{
|
|
||||||
|
function! s:count_separators_down(lnum)
|
||||||
let lnum = a:lnum + 1
|
let lnum = a:lnum + 1
|
||||||
while lnum < line('$')
|
while lnum < line('$')
|
||||||
if !s:is_separator(getline(lnum))
|
if !s:is_separator(getline(lnum))
|
||||||
@ -100,9 +108,10 @@ function! s:count_separators_down(lnum) "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return (lnum-a:lnum)
|
return (lnum-a:lnum)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:create_empty_row(cols) "{{{
|
|
||||||
|
function! s:create_empty_row(cols)
|
||||||
let row = s:rxSep()
|
let row = s:rxSep()
|
||||||
let cell = " ".s:rxSep()
|
let cell = " ".s:rxSep()
|
||||||
|
|
||||||
@ -111,9 +120,10 @@ function! s:create_empty_row(cols) "{{{
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
return row
|
return row
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:create_row_sep(cols) "{{{
|
|
||||||
|
function! s:create_row_sep(cols)
|
||||||
let row = s:rxSep()
|
let row = s:rxSep()
|
||||||
let cell = "---".s:rxSep()
|
let cell = "---".s:rxSep()
|
||||||
|
|
||||||
@ -122,9 +132,10 @@ function! s:create_row_sep(cols) "{{{
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
return row
|
return row
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#get_cells(line, ...) "{{{
|
|
||||||
|
function! vimwiki#tbl#get_cells(line, ...)
|
||||||
let result = []
|
let result = []
|
||||||
let state = 'NONE'
|
let state = 'NONE'
|
||||||
let cell_start = 0
|
let cell_start = 0
|
||||||
@ -139,12 +150,12 @@ function! vimwiki#tbl#get_cells(line, ...) "{{{
|
|||||||
for idx in range(quote_start, len)
|
for idx in range(quote_start, len)
|
||||||
" The only way I know Vim can do Unicode...
|
" The only way I know Vim can do Unicode...
|
||||||
let ch = a:line[idx]
|
let ch = a:line[idx]
|
||||||
if state == 'NONE'
|
if state ==# 'NONE'
|
||||||
if ch == '|'
|
if ch == '|'
|
||||||
let cell_start = idx + 1
|
let cell_start = idx + 1
|
||||||
let state = 'CELL'
|
let state = 'CELL'
|
||||||
endif
|
endif
|
||||||
elseif state == 'CELL'
|
elseif state ==# 'CELL'
|
||||||
if ch == '[' || ch == '{'
|
if ch == '[' || ch == '{'
|
||||||
let state = 'BEFORE_QUOTE_START'
|
let state = 'BEFORE_QUOTE_START'
|
||||||
let quote_start = idx
|
let quote_start = idx
|
||||||
@ -158,18 +169,18 @@ function! vimwiki#tbl#get_cells(line, ...) "{{{
|
|||||||
call add(result, cell)
|
call add(result, cell)
|
||||||
let cell_start = idx + 1
|
let cell_start = idx + 1
|
||||||
endif
|
endif
|
||||||
elseif state == 'BEFORE_QUOTE_START'
|
elseif state ==# 'BEFORE_QUOTE_START'
|
||||||
if ch == '[' || ch == '{'
|
if ch == '[' || ch == '{'
|
||||||
let state = 'QUOTE'
|
let state = 'QUOTE'
|
||||||
let quote_start = idx
|
let quote_start = idx
|
||||||
else
|
else
|
||||||
let state = 'CELL'
|
let state = 'CELL'
|
||||||
endif
|
endif
|
||||||
elseif state == 'QUOTE'
|
elseif state ==# 'QUOTE'
|
||||||
if ch == ']' || ch == '}'
|
if ch == ']' || ch == '}'
|
||||||
let state = 'BEFORE_QUOTE_END'
|
let state = 'BEFORE_QUOTE_END'
|
||||||
endif
|
endif
|
||||||
elseif state == 'BEFORE_QUOTE_END'
|
elseif state ==# 'BEFORE_QUOTE_END'
|
||||||
if ch == ']' || ch == '}'
|
if ch == ']' || ch == '}'
|
||||||
let state = 'CELL'
|
let state = 'CELL'
|
||||||
endif
|
endif
|
||||||
@ -181,13 +192,15 @@ function! vimwiki#tbl#get_cells(line, ...) "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return result
|
return result
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:col_count(lnum) "{{{
|
|
||||||
|
function! s:col_count(lnum)
|
||||||
return len(vimwiki#tbl#get_cells(getline(a:lnum)))
|
return len(vimwiki#tbl#get_cells(getline(a:lnum)))
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:get_indent(lnum) "{{{
|
|
||||||
|
function! s:get_indent(lnum)
|
||||||
if !s:is_table(getline(a:lnum))
|
if !s:is_table(getline(a:lnum))
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@ -205,9 +218,10 @@ function! s:get_indent(lnum) "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return indent
|
return indent
|
||||||
endfunction " }}}
|
endfunction
|
||||||
|
|
||||||
function! s:get_rows(lnum, ...) "{{{
|
|
||||||
|
function! s:get_rows(lnum, ...)
|
||||||
if !s:is_table(getline(a:lnum))
|
if !s:is_table(getline(a:lnum))
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@ -245,9 +259,10 @@ function! s:get_rows(lnum, ...) "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return upper_rows + lower_rows
|
return upper_rows + lower_rows
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:get_cell_max_lens(lnum, ...) "{{{
|
|
||||||
|
function! s:get_cell_max_lens(lnum, ...)
|
||||||
let max_lens = {}
|
let max_lens = {}
|
||||||
let rows = a:0 > 2 ? a:3 : s:get_rows(a:lnum)
|
let rows = a:0 > 2 ? a:3 : s:get_rows(a:lnum)
|
||||||
for [lnum, row] in rows
|
for [lnum, row] in rows
|
||||||
@ -265,9 +280,10 @@ function! s:get_cell_max_lens(lnum, ...) "{{{
|
|||||||
endfor
|
endfor
|
||||||
endfor
|
endfor
|
||||||
return max_lens
|
return max_lens
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:get_aligned_rows(lnum, col1, col2, depth) "{{{
|
|
||||||
|
function! s:get_aligned_rows(lnum, col1, col2, depth)
|
||||||
let rows = []
|
let rows = []
|
||||||
let startlnum = 0
|
let startlnum = 0
|
||||||
let cells = []
|
let cells = []
|
||||||
@ -308,10 +324,11 @@ function! s:get_aligned_rows(lnum, col1, col2, depth) "{{{
|
|||||||
call add(result, [lnum, new_row])
|
call add(result, [lnum, new_row])
|
||||||
endfor
|
endfor
|
||||||
return result
|
return result
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" Number of the current column. Starts from 0.
|
" Number of the current column. Starts from 0.
|
||||||
function! s:cur_column() "{{{
|
function! s:cur_column()
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
if !s:is_table(line)
|
if !s:is_table(line)
|
||||||
return -1
|
return -1
|
||||||
@ -328,12 +345,10 @@ function! s:cur_column() "{{{
|
|||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
return col
|
return col
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
" }}}
|
|
||||||
|
|
||||||
" Format functions {{{
|
function! s:fmt_cell(cell, max_len)
|
||||||
function! s:fmt_cell(cell, max_len) "{{{
|
|
||||||
let cell = ' '.a:cell.' '
|
let cell = ' '.a:cell.' '
|
||||||
|
|
||||||
let diff = a:max_len - s:wide_len(a:cell)
|
let diff = a:max_len - s:wide_len(a:cell)
|
||||||
@ -343,9 +358,10 @@ function! s:fmt_cell(cell, max_len) "{{{
|
|||||||
|
|
||||||
let cell .= repeat(' ', diff)
|
let cell .= repeat(' ', diff)
|
||||||
return cell
|
return cell
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:fmt_row(cells, max_lens, col1, col2) "{{{
|
|
||||||
|
function! s:fmt_row(cells, max_lens, col1, col2)
|
||||||
let new_line = s:rxSep()
|
let new_line = s:rxSep()
|
||||||
for idx in range(len(a:cells))
|
for idx in range(len(a:cells))
|
||||||
if idx == a:col1
|
if idx == a:col1
|
||||||
@ -363,17 +379,19 @@ function! s:fmt_row(cells, max_lens, col1, col2) "{{{
|
|||||||
let idx += 1
|
let idx += 1
|
||||||
endwhile
|
endwhile
|
||||||
return new_line
|
return new_line
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:fmt_cell_sep(max_len) "{{{
|
|
||||||
|
function! s:fmt_cell_sep(max_len)
|
||||||
if a:max_len == 0
|
if a:max_len == 0
|
||||||
return repeat('-', 3)
|
return repeat('-', 3)
|
||||||
else
|
else
|
||||||
return repeat('-', a:max_len+2)
|
return repeat('-', a:max_len+2)
|
||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:fmt_sep(max_lens, col1, col2) "{{{
|
|
||||||
|
function! s:fmt_sep(max_lens, col1, col2)
|
||||||
let new_line = s:rxSep()
|
let new_line = s:rxSep()
|
||||||
for idx in range(len(a:max_lens))
|
for idx in range(len(a:max_lens))
|
||||||
if idx == a:col1
|
if idx == a:col1
|
||||||
@ -384,11 +402,10 @@ function! s:fmt_sep(max_lens, col1, col2) "{{{
|
|||||||
let new_line .= s:fmt_cell_sep(a:max_lens[idx]).s:rxSep()
|
let new_line .= s:fmt_cell_sep(a:max_lens[idx]).s:rxSep()
|
||||||
endfor
|
endfor
|
||||||
return new_line
|
return new_line
|
||||||
endfunction "}}}
|
endfunction
|
||||||
"}}}
|
|
||||||
|
|
||||||
" Keyboard functions "{{{
|
|
||||||
function! s:kbd_create_new_row(cols, goto_first) "{{{
|
function! s:kbd_create_new_row(cols, goto_first)
|
||||||
let cmd = "\<ESC>o".s:create_empty_row(a:cols)
|
let cmd = "\<ESC>o".s:create_empty_row(a:cols)
|
||||||
let cmd .= "\<ESC>:call vimwiki#tbl#format(line('.'), 2)\<CR>"
|
let cmd .= "\<ESC>:call vimwiki#tbl#format(line('.'), 2)\<CR>"
|
||||||
let cmd .= "\<ESC>0"
|
let cmd .= "\<ESC>0"
|
||||||
@ -401,26 +418,29 @@ function! s:kbd_create_new_row(cols, goto_first) "{{{
|
|||||||
let cmd .= "a"
|
let cmd .= "a"
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:kbd_goto_next_row() "{{{
|
|
||||||
|
function! s:kbd_goto_next_row()
|
||||||
let cmd = "\<ESC>j"
|
let cmd = "\<ESC>j"
|
||||||
let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>"
|
let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>"
|
||||||
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
|
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
|
||||||
let cmd .= "a"
|
let cmd .= "a"
|
||||||
return cmd
|
return cmd
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:kbd_goto_prev_row() "{{{
|
|
||||||
|
function! s:kbd_goto_prev_row()
|
||||||
let cmd = "\<ESC>k"
|
let cmd = "\<ESC>k"
|
||||||
let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>"
|
let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\<CR>"
|
||||||
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
|
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
|
||||||
let cmd .= "a"
|
let cmd .= "a"
|
||||||
return cmd
|
return cmd
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" Used in s:kbd_goto_next_col
|
" Used in s:kbd_goto_next_col
|
||||||
function! vimwiki#tbl#goto_next_col() "{{{
|
function! vimwiki#tbl#goto_next_col()
|
||||||
let curcol = virtcol('.')
|
let curcol = virtcol('.')
|
||||||
let lnum = line('.')
|
let lnum = line('.')
|
||||||
let newcol = s:get_indent(lnum)
|
let newcol = s:get_indent(lnum)
|
||||||
@ -439,9 +459,10 @@ function! vimwiki#tbl#goto_next_col() "{{{
|
|||||||
endfor
|
endfor
|
||||||
let newcol += 2 " +2 == 1 separator + 1 space |<space
|
let newcol += 2 " +2 == 1 separator + 1 space |<space
|
||||||
call vimwiki#u#cursor(lnum, newcol)
|
call vimwiki#u#cursor(lnum, newcol)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:kbd_goto_next_col(jumpdown) "{{{
|
|
||||||
|
function! s:kbd_goto_next_col(jumpdown)
|
||||||
let cmd = "\<ESC>"
|
let cmd = "\<ESC>"
|
||||||
if a:jumpdown
|
if a:jumpdown
|
||||||
let seps = s:count_separators_down(line('.'))
|
let seps = s:count_separators_down(line('.'))
|
||||||
@ -449,10 +470,11 @@ function! s:kbd_goto_next_col(jumpdown) "{{{
|
|||||||
endif
|
endif
|
||||||
let cmd .= ":call vimwiki#tbl#goto_next_col()\<CR>a"
|
let cmd .= ":call vimwiki#tbl#goto_next_col()\<CR>a"
|
||||||
return cmd
|
return cmd
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" Used in s:kbd_goto_prev_col
|
" Used in s:kbd_goto_prev_col
|
||||||
function! vimwiki#tbl#goto_prev_col() "{{{
|
function! vimwiki#tbl#goto_prev_col()
|
||||||
let curcol = virtcol('.')
|
let curcol = virtcol('.')
|
||||||
let lnum = line('.')
|
let lnum = line('.')
|
||||||
let newcol = s:get_indent(lnum)
|
let newcol = s:get_indent(lnum)
|
||||||
@ -464,7 +486,6 @@ function! vimwiki#tbl#goto_prev_col() "{{{
|
|||||||
endfor
|
endfor
|
||||||
let max_lens = s:get_cell_max_lens(lnum, cells, startlnum, rows)
|
let max_lens = s:get_cell_max_lens(lnum, cells, startlnum, rows)
|
||||||
let prev_cell_len = 0
|
let prev_cell_len = 0
|
||||||
echom string(max_lens)
|
|
||||||
for cell_len in values(max_lens)
|
for cell_len in values(max_lens)
|
||||||
let delta = cell_len + 3 " +3 == 2 spaces + 1 separator |<space>...<space>
|
let delta = cell_len + 3 " +3 == 2 spaces + 1 separator |<space>...<space>
|
||||||
if newcol + delta > curcol-1
|
if newcol + delta > curcol-1
|
||||||
@ -478,9 +499,10 @@ function! vimwiki#tbl#goto_prev_col() "{{{
|
|||||||
endfor
|
endfor
|
||||||
let newcol += 2 " +2 == 1 separator + 1 space |<space
|
let newcol += 2 " +2 == 1 separator + 1 space |<space
|
||||||
call vimwiki#u#cursor(lnum, newcol)
|
call vimwiki#u#cursor(lnum, newcol)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! s:kbd_goto_prev_col(jumpup) "{{{
|
|
||||||
|
function! s:kbd_goto_prev_col(jumpup)
|
||||||
let cmd = "\<ESC>"
|
let cmd = "\<ESC>"
|
||||||
if a:jumpup
|
if a:jumpup
|
||||||
let seps = s:count_separators_up(line('.'))
|
let seps = s:count_separators_up(line('.'))
|
||||||
@ -492,12 +514,10 @@ function! s:kbd_goto_prev_col(jumpup) "{{{
|
|||||||
" let cmd .= "a"
|
" let cmd .= "a"
|
||||||
"echomsg "DEBUG kbd_goto_prev_col> ".cmd
|
"echomsg "DEBUG kbd_goto_prev_col> ".cmd
|
||||||
return cmd
|
return cmd
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
"}}}
|
|
||||||
|
|
||||||
" Global functions {{{
|
function! vimwiki#tbl#kbd_cr()
|
||||||
function! vimwiki#tbl#kbd_cr() "{{{
|
|
||||||
let lnum = line('.')
|
let lnum = line('.')
|
||||||
if !s:is_table(getline(lnum))
|
if !s:is_table(getline(lnum))
|
||||||
return ""
|
return ""
|
||||||
@ -509,9 +529,10 @@ function! vimwiki#tbl#kbd_cr() "{{{
|
|||||||
else
|
else
|
||||||
return s:kbd_goto_next_row()
|
return s:kbd_goto_next_row()
|
||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#kbd_tab() "{{{
|
|
||||||
|
function! vimwiki#tbl#kbd_tab()
|
||||||
let lnum = line('.')
|
let lnum = line('.')
|
||||||
if !s:is_table(getline(lnum))
|
if !s:is_table(getline(lnum))
|
||||||
return "\<Tab>"
|
return "\<Tab>"
|
||||||
@ -525,9 +546,10 @@ function! vimwiki#tbl#kbd_tab() "{{{
|
|||||||
return s:kbd_create_new_row(cols, 1)
|
return s:kbd_create_new_row(cols, 1)
|
||||||
endif
|
endif
|
||||||
return s:kbd_goto_next_col(is_sep || last)
|
return s:kbd_goto_next_col(is_sep || last)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#kbd_shift_tab() "{{{
|
|
||||||
|
function! vimwiki#tbl#kbd_shift_tab()
|
||||||
let lnum = line('.')
|
let lnum = line('.')
|
||||||
if !s:is_table(getline(lnum))
|
if !s:is_table(getline(lnum))
|
||||||
return "\<S-Tab>"
|
return "\<S-Tab>"
|
||||||
@ -540,10 +562,11 @@ function! vimwiki#tbl#kbd_shift_tab() "{{{
|
|||||||
return ""
|
return ""
|
||||||
endif
|
endif
|
||||||
return s:kbd_goto_prev_col(is_sep || first)
|
return s:kbd_goto_prev_col(is_sep || first)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#format(lnum, ...) "{{{
|
|
||||||
if !(&filetype == 'vimwiki')
|
function! vimwiki#tbl#format(lnum, ...)
|
||||||
|
if !(&filetype ==? 'vimwiki')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let line = getline(a:lnum)
|
let line = getline(a:lnum)
|
||||||
@ -577,9 +600,10 @@ function! vimwiki#tbl#format(lnum, ...) "{{{
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
let &tw = s:textwidth
|
let &tw = s:textwidth
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#create(...) "{{{
|
|
||||||
|
function! vimwiki#tbl#create(...)
|
||||||
if a:0 > 1
|
if a:0 > 1
|
||||||
let cols = a:1
|
let cols = a:1
|
||||||
let rows = a:2
|
let rows = a:2
|
||||||
@ -612,18 +636,20 @@ function! vimwiki#tbl#create(...) "{{{
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
call append(line('.'), lines)
|
call append(line('.'), lines)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#align_or_cmd(cmd, ...) "{{{
|
|
||||||
|
function! vimwiki#tbl#align_or_cmd(cmd, ...)
|
||||||
if s:is_table(getline('.'))
|
if s:is_table(getline('.'))
|
||||||
call call('vimwiki#tbl#format', [line('.')] + a:000)
|
call call('vimwiki#tbl#format', [line('.')] + a:000)
|
||||||
else
|
else
|
||||||
exe 'normal! '.a:cmd
|
exe 'normal! '.a:cmd
|
||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#reset_tw(lnum) "{{{
|
|
||||||
if !(&filetype == 'vimwiki')
|
function! vimwiki#tbl#reset_tw(lnum)
|
||||||
|
if !(&filetype ==? 'vimwiki')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let line = getline(a:lnum)
|
let line = getline(a:lnum)
|
||||||
@ -633,11 +659,11 @@ function! vimwiki#tbl#reset_tw(lnum) "{{{
|
|||||||
|
|
||||||
let s:textwidth = &tw
|
let s:textwidth = &tw
|
||||||
let &tw = 0
|
let &tw = 0
|
||||||
endfunction "}}}
|
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() "{{{
|
function! vimwiki#tbl#move_column_left()
|
||||||
|
|
||||||
"echomsg "DEBUG move_column_left: "
|
"echomsg "DEBUG move_column_left: "
|
||||||
|
|
||||||
@ -669,10 +695,10 @@ function! vimwiki#tbl#move_column_left() "{{{
|
|||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
endfunction "}}}
|
|
||||||
|
|
||||||
function! vimwiki#tbl#move_column_right() "{{{
|
function! vimwiki#tbl#move_column_right()
|
||||||
|
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
|
|
||||||
@ -700,29 +726,31 @@ function! vimwiki#tbl#move_column_right() "{{{
|
|||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
endfunction "}}}
|
|
||||||
|
|
||||||
function! vimwiki#tbl#get_rows(lnum) "{{{
|
function! vimwiki#tbl#get_rows(lnum)
|
||||||
return s:get_rows(a:lnum)
|
return s:get_rows(a:lnum)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#is_table(line) "{{{
|
|
||||||
|
function! vimwiki#tbl#is_table(line)
|
||||||
return s:is_table(a:line)
|
return s:is_table(a:line)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#is_separator(line) "{{{
|
|
||||||
|
function! vimwiki#tbl#is_separator(line)
|
||||||
return s:is_separator(a:line)
|
return s:is_separator(a:line)
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#cell_splitter() "{{{
|
|
||||||
|
function! vimwiki#tbl#cell_splitter()
|
||||||
return s:cell_splitter()
|
return s:cell_splitter()
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
function! vimwiki#tbl#sep_splitter() "{{{
|
|
||||||
|
function! vimwiki#tbl#sep_splitter()
|
||||||
return s:sep_splitter()
|
return s:sep_splitter()
|
||||||
endfunction "}}}
|
endfunction
|
||||||
|
|
||||||
"}}}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user