Version 2.0.stu
This release is partly incompatible with 1.2. You should delete previous version of vimwiki before install. = Summary = * Quick page-link creation. * Redesign of link syntaxes (!) * No more CamelCase links. Check the ways to convert them http://goo.gl/15ctX * No more [[link][desc]] links. * No more [http://link description] links. * No more plain image links. Use transclusions. * No more image links identified by extension. Use transclusions. * Interwiki links. * Link schemes. * Transclusions. * Normalize link command. * Improved diary organization and generation. * List manipulation. * Markdown support. * Mathjax support. * Improved handling of special characters and punctuation in filenames and urls. * Back links command: list links referring to the current page. * Highlighting nonexisted links are off by default. * Table syntax change. Row separator uses | instead of +. * Fold multilined list items. * Custom wiki to HTML converters. * Conceal long weblinks. * Option to disable table mappings. For detailed information see issues list on http://code.google.com/p/vimwiki/issues/list
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Tables
|
||||
" | Easily | manageable | text | tables | ! |
|
||||
" |--------+------------+-------+--------+---------|
|
||||
" |--------|------------|-------|--------|---------|
|
||||
" | Have | fun! | Drink | tea | Period. |
|
||||
"
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
@ -16,6 +16,8 @@ let g:loaded_vimwiki_tbl_auto = 1
|
||||
"}}}
|
||||
|
||||
let s:textwidth = &tw
|
||||
let s:rxSep = g:vimwiki_rxTableSep
|
||||
|
||||
|
||||
" Misc functions {{{
|
||||
function! s:wide_len(str) "{{{
|
||||
@ -40,21 +42,37 @@ function! s:wide_len(str) "{{{
|
||||
return ret
|
||||
endfunction "}}}
|
||||
|
||||
function! s:cell_splitter() "{{{
|
||||
return '\s*'.s:rxSep.'\s*'
|
||||
endfunction "}}}
|
||||
|
||||
function! s:sep_splitter() "{{{
|
||||
return '-'.s:rxSep.'-'
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_table(line) "{{{
|
||||
return a:line =~ '^\s*\%(|[^|]\+\)\+|\s*$' || 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*$')
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_separator(line) "{{{
|
||||
return a:line =~ '^\s*[|+]\s*--[-|+]\+'
|
||||
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) "{{{
|
||||
return strpart(getline(a:lnum), a:cnum - 1) =~ '^[^|]*|\s*$'
|
||||
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*$'
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_first_column(lnum, cnum) "{{{
|
||||
let line = strpart(getline(a:lnum), 0, a:cnum - 1)
|
||||
return line =~ '^\s*|[^|]*$' || line =~ '^\s*$'
|
||||
"echomsg "DEBUG is_first_column> ".(line =~ '^\s*'.s:rxSep && line !~ '^\s*'.s:rxSep.'.*'.s:rxSep)
|
||||
return line =~ '^\s*$' || (line =~ '^\s*'.s:rxSep && line !~ '^\s*'.s:rxSep.'.*'.s:rxSep)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:count_separators_up(lnum) "{{{
|
||||
@ -82,11 +100,10 @@ function! s:count_separators_down(lnum) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
function! s:create_empty_row(cols) "{{{
|
||||
let first_cell = "| |"
|
||||
let cell = " |"
|
||||
let row = first_cell
|
||||
let row = s:rxSep
|
||||
let cell = " ".s:rxSep
|
||||
|
||||
for c in range(a:cols - 1)
|
||||
for c in range(a:cols)
|
||||
let row .= cell
|
||||
endfor
|
||||
|
||||
@ -94,36 +111,71 @@ function! s:create_empty_row(cols) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
function! s:create_row_sep(cols) "{{{
|
||||
let first_cell = "|---+"
|
||||
let cell = "---+"
|
||||
let last_cell = "---|"
|
||||
let row = s:rxSep
|
||||
let cell = "---".s:rxSep
|
||||
|
||||
if a:cols < 2
|
||||
return "|---|"
|
||||
endif
|
||||
|
||||
let row = first_cell
|
||||
|
||||
for c in range(a:cols - 2)
|
||||
for c in range(a:cols)
|
||||
let row .= cell
|
||||
endfor
|
||||
|
||||
let row .= last_cell
|
||||
|
||||
return row
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_values(line) "{{{
|
||||
return split(a:line, '\s*|\s*', 1)[1:-2]
|
||||
function! vimwiki#tbl#get_cells(line) "{{{
|
||||
let result = []
|
||||
let cell = ''
|
||||
let quote = ''
|
||||
let state = 'NONE'
|
||||
|
||||
" 'Simple' FSM
|
||||
for idx in range(strlen(a:line))
|
||||
" The only way I know Vim can do Unicode...
|
||||
let ch = a:line[idx]
|
||||
if state == 'NONE'
|
||||
if ch == '|'
|
||||
let state = 'CELL'
|
||||
endif
|
||||
elseif state == 'CELL'
|
||||
if ch == '[' || ch == '{'
|
||||
let state = 'BEFORE_QUOTE_START'
|
||||
let quote = ch
|
||||
elseif ch == '|'
|
||||
call add(result, vimwiki#u#trim(cell))
|
||||
let cell = ""
|
||||
else
|
||||
let cell .= ch
|
||||
endif
|
||||
elseif state == 'BEFORE_QUOTE_START'
|
||||
if ch == '[' || ch == '{'
|
||||
let state = 'QUOTE'
|
||||
let quote .= ch
|
||||
else
|
||||
let state = 'CELL'
|
||||
let cell .= quote.ch
|
||||
let quote = ''
|
||||
endif
|
||||
elseif state == 'QUOTE'
|
||||
if ch == ']' || ch == '}'
|
||||
let state = 'BEFORE_QUOTE_END'
|
||||
endif
|
||||
let quote .= ch
|
||||
elseif state == 'BEFORE_QUOTE_END'
|
||||
if ch == ']' || ch == '}'
|
||||
let state = 'CELL'
|
||||
endif
|
||||
let cell .= quote.ch
|
||||
let quote = ''
|
||||
endif
|
||||
endfor
|
||||
|
||||
if cell.quote != ''
|
||||
call add(result, vimwiki#u#trim(cell.quote, '|'))
|
||||
endif
|
||||
return result
|
||||
endfunction "}}}
|
||||
|
||||
function! s:col_count(lnum) "{{{
|
||||
let line = getline(a:lnum)
|
||||
if !s:is_separator(line)
|
||||
return len(split(line, '\s*|\s*', 1)[1:-2])
|
||||
else
|
||||
return len(split(line, '-+-', 1))
|
||||
endif
|
||||
return len(vimwiki#tbl#get_cells(getline(a:lnum)))
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_indent(lnum) "{{{
|
||||
@ -155,7 +207,7 @@ function! s:get_rows(lnum) "{{{
|
||||
let lower_rows = []
|
||||
|
||||
let lnum = a:lnum - 1
|
||||
while lnum > 1
|
||||
while lnum >= 1
|
||||
let line = getline(lnum)
|
||||
if s:is_table(line)
|
||||
call add(upper_rows, [lnum, line])
|
||||
@ -186,7 +238,7 @@ function! s:get_cell_max_lens(lnum) "{{{
|
||||
if s:is_separator(row)
|
||||
continue
|
||||
endif
|
||||
let cells = s:get_values(row)
|
||||
let cells = vimwiki#tbl#get_cells(row)
|
||||
for idx in range(len(cells))
|
||||
let value = cells[idx]
|
||||
if has_key(max_lens, idx)
|
||||
@ -219,17 +271,13 @@ function! s:cur_column() "{{{
|
||||
if !s:is_table(line)
|
||||
return -1
|
||||
endif
|
||||
if s:is_separator(line)
|
||||
let sep = '[+|]'
|
||||
else
|
||||
let sep = '|'
|
||||
endif
|
||||
" TODO: do we need conditional: if s:is_separator(line)
|
||||
|
||||
let curs_pos = col('.')
|
||||
let mpos = match(line, '|', 0)
|
||||
let mpos = match(line, s:rxSep, 0)
|
||||
let col = -1
|
||||
while mpos < curs_pos && mpos != -1
|
||||
let mpos = match(line, sep, mpos+1)
|
||||
let mpos = match(line, s:rxSep, mpos+1)
|
||||
if mpos != -1
|
||||
let col += 1
|
||||
endif
|
||||
@ -253,8 +301,8 @@ function! s:fmt_cell(cell, max_len) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
function! s:fmt_row(line, max_lens, col1, col2) "{{{
|
||||
let new_line = '|'
|
||||
let cells = s:get_values(a:line)
|
||||
let new_line = s:rxSep
|
||||
let cells = vimwiki#tbl#get_cells(a:line)
|
||||
for idx in range(len(cells))
|
||||
if idx == a:col1
|
||||
let idx = a:col2
|
||||
@ -262,12 +310,12 @@ function! s:fmt_row(line, max_lens, col1, col2) "{{{
|
||||
let idx = a:col1
|
||||
endif
|
||||
let value = cells[idx]
|
||||
let new_line .= s:fmt_cell(value, a:max_lens[idx]).'|'
|
||||
let new_line .= s:fmt_cell(value, a:max_lens[idx]).s:rxSep
|
||||
endfor
|
||||
|
||||
let idx = len(cells)
|
||||
while idx < len(a:max_lens)
|
||||
let new_line .= s:fmt_cell('', a:max_lens[idx]).'|'
|
||||
let new_line .= s:fmt_cell('', a:max_lens[idx]).s:rxSep
|
||||
let idx += 1
|
||||
endwhile
|
||||
return new_line
|
||||
@ -282,17 +330,16 @@ function! s:fmt_cell_sep(max_len) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
function! s:fmt_sep(max_lens, col1, col2) "{{{
|
||||
let sep = '|'
|
||||
let new_line = s:rxSep
|
||||
for idx in range(len(a:max_lens))
|
||||
if idx == a:col1
|
||||
let idx = a:col2
|
||||
elseif idx == a:col2
|
||||
let idx = a:col1
|
||||
endif
|
||||
let sep .= s:fmt_cell_sep(a:max_lens[idx]).'+'
|
||||
let new_line .= s:fmt_cell_sep(a:max_lens[idx]).s:rxSep
|
||||
endfor
|
||||
let sep = substitute(sep, '+$', '|', '')
|
||||
return sep
|
||||
return new_line
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
@ -300,41 +347,94 @@ endfunction "}}}
|
||||
function! s:kbd_create_new_row(cols, goto_first) "{{{
|
||||
let cmd = "\<ESC>o".s:create_empty_row(a:cols)
|
||||
let cmd .= "\<ESC>:call vimwiki#tbl#format(line('.'))\<CR>"
|
||||
let cmd .= "\<ESC>0"
|
||||
if a:goto_first
|
||||
let cmd .= "\<ESC>0:call search('|', 'c', line('.'))\<CR>la"
|
||||
let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'c', line('.'))\<CR>"
|
||||
else
|
||||
let cmd .= "0".(col('.')-1)."lT|a"
|
||||
let cmd .= (col('.')-1)."l"
|
||||
let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\<CR>"
|
||||
endif
|
||||
let cmd .= "a"
|
||||
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
function! s:kbd_goto_next_row() "{{{
|
||||
let cmd = "\<ESC>jt|T|a"
|
||||
let cmd = "\<ESC>j"
|
||||
let cmd .= ":call search('.\\(".s:rxSep."\\)', 'c', line('.'))\<CR>"
|
||||
let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\<CR>"
|
||||
let cmd .= "a"
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
function! s:kbd_goto_prev_row() "{{{
|
||||
let cmd = "\<ESC>jt|T|a"
|
||||
let cmd = "\<ESC>k"
|
||||
let cmd .= ":call search('.\\(".s:rxSep."\\)', 'c', line('.'))\<CR>"
|
||||
let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\<CR>"
|
||||
let cmd .= "a"
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
function! s:kbd_goto_next_col(last) "{{{
|
||||
if a:last
|
||||
" Used in s:kbd_goto_next_col
|
||||
function! vimwiki#tbl#goto_next_col() "{{{
|
||||
let curcol = virtcol('.')
|
||||
let lnum = line('.')
|
||||
let newcol = s:get_indent(lnum)
|
||||
let max_lens = s:get_cell_max_lens(lnum)
|
||||
for cell_len in values(max_lens)
|
||||
if newcol >= curcol-1
|
||||
break
|
||||
endif
|
||||
let newcol += cell_len + 3 " +3 == 2 spaces + 1 separator |<space>...<space>
|
||||
endfor
|
||||
let newcol += 2 " +2 == 1 separator + 1 space |<space
|
||||
call vimwiki#u#cursor(lnum, newcol)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:kbd_goto_next_col(jumpdown) "{{{
|
||||
let cmd = "\<ESC>"
|
||||
if a:jumpdown
|
||||
let seps = s:count_separators_down(line('.'))
|
||||
let cmd = "\<ESC>".seps."j0:call search('|', 'c', line('.'))\<CR>la"
|
||||
else
|
||||
let cmd = "\<ESC>:call search('|', 'c', line('.'))\<CR>la"
|
||||
let cmd .= seps."j0"
|
||||
endif
|
||||
let cmd .= ":call vimwiki#tbl#goto_next_col()\<CR>a"
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
function! s:kbd_goto_prev_col(first) "{{{
|
||||
if a:first
|
||||
" Used in s:kbd_goto_prev_col
|
||||
function! vimwiki#tbl#goto_prev_col() "{{{
|
||||
let curcol = virtcol('.')
|
||||
let lnum = line('.')
|
||||
let newcol = s:get_indent(lnum)
|
||||
let max_lens = s:get_cell_max_lens(lnum)
|
||||
let prev_cell_len = 0
|
||||
echom string(max_lens)
|
||||
for cell_len in values(max_lens)
|
||||
let delta = cell_len + 3 " +3 == 2 spaces + 1 separator |<space>...<space>
|
||||
if newcol + delta > curcol-1
|
||||
let newcol -= (prev_cell_len + 3) " +3 == 2 spaces + 1 separator |<space>...<space>
|
||||
break
|
||||
elseif newcol + delta == curcol-1
|
||||
break
|
||||
endif
|
||||
let prev_cell_len = cell_len
|
||||
let newcol += delta
|
||||
endfor
|
||||
let newcol += 2 " +2 == 1 separator + 1 space |<space
|
||||
call vimwiki#u#cursor(lnum, newcol)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:kbd_goto_prev_col(jumpup) "{{{
|
||||
let cmd = "\<ESC>"
|
||||
if a:jumpup
|
||||
let seps = s:count_separators_up(line('.'))
|
||||
let cmd = "\<ESC>".seps."k$:call search('|', 'b', line('.'))\<CR>la"
|
||||
else
|
||||
let cmd = "\<ESC>2F|la"
|
||||
let cmd .= seps."k"
|
||||
let cmd .= "$"
|
||||
endif
|
||||
let cmd .= ":call vimwiki#tbl#goto_prev_col()\<CR>a"
|
||||
" let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'b', line('.'))\<CR>"
|
||||
" let cmd .= "a"
|
||||
"echomsg "DEBUG kbd_goto_prev_col> ".cmd
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
@ -348,7 +448,7 @@ function! vimwiki#tbl#kbd_cr() "{{{
|
||||
endif
|
||||
|
||||
if s:is_separator(getline(lnum+1)) || !s:is_table(getline(lnum+1))
|
||||
let cols = len(s:get_values(getline(lnum)))
|
||||
let cols = len(vimwiki#tbl#get_cells(getline(lnum)))
|
||||
return s:kbd_create_new_row(cols, 0)
|
||||
else
|
||||
return s:kbd_goto_next_row()
|
||||
@ -362,11 +462,13 @@ function! vimwiki#tbl#kbd_tab() "{{{
|
||||
endif
|
||||
|
||||
let last = s:is_last_column(lnum, col('.'))
|
||||
if last && !s:is_table(getline(lnum+1))
|
||||
let cols = len(s:get_values(getline(lnum)))
|
||||
let is_sep = s:is_separator_tail(getline(lnum))
|
||||
"echomsg "DEBUG kbd_tab> last=".last.", is_sep=".is_sep
|
||||
if (is_sep || last) && !s:is_table(getline(lnum+1))
|
||||
let cols = len(vimwiki#tbl#get_cells(getline(lnum)))
|
||||
return s:kbd_create_new_row(cols, 1)
|
||||
endif
|
||||
return s:kbd_goto_next_col(last)
|
||||
return s:kbd_goto_next_col(is_sep || last)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#kbd_shift_tab() "{{{
|
||||
@ -376,10 +478,12 @@ function! vimwiki#tbl#kbd_shift_tab() "{{{
|
||||
endif
|
||||
|
||||
let first = s:is_first_column(lnum, col('.'))
|
||||
if first && !s:is_table(getline(lnum-1))
|
||||
let is_sep = s:is_separator_tail(getline(lnum))
|
||||
"echomsg "DEBUG kbd_tab> ".first
|
||||
if (is_sep || first) && !s:is_table(getline(lnum-1))
|
||||
return ""
|
||||
endif
|
||||
return s:kbd_goto_prev_col(first)
|
||||
return s:kbd_goto_prev_col(is_sep || first)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#format(lnum, ...) "{{{
|
||||
@ -462,7 +566,12 @@ endfunction "}}}
|
||||
" TODO: move_column_left and move_column_right are good candidates to be
|
||||
" refactored.
|
||||
function! vimwiki#tbl#move_column_left() "{{{
|
||||
if !s:is_table(getline('.'))
|
||||
|
||||
"echomsg "DEBUG move_column_left: "
|
||||
|
||||
let line = getline('.')
|
||||
|
||||
if !s:is_table(line)
|
||||
return
|
||||
endif
|
||||
|
||||
@ -474,16 +583,28 @@ function! vimwiki#tbl#move_column_left() "{{{
|
||||
if cur_col > 0
|
||||
call vimwiki#tbl#format(line('.'), cur_col-1, cur_col)
|
||||
call cursor(line('.'), 1)
|
||||
if !s:is_separator(getline('.'))
|
||||
call search('\%(|[^|]\+\)\{'.(cur_col-1).'}| .', 'eW')
|
||||
else
|
||||
call search('|\%([^+]\++\)\{'.(cur_col-1).'}--', 'eW')
|
||||
endif
|
||||
|
||||
let sep = '\('.s:rxSep.'\).\zs'
|
||||
let mpos = -1
|
||||
let col = -1
|
||||
while col < cur_col-1
|
||||
let mpos = match(line, sep, mpos+1)
|
||||
if mpos != -1
|
||||
let col += 1
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
endif
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#move_column_right() "{{{
|
||||
if !s:is_table(getline('.'))
|
||||
|
||||
let line = getline('.')
|
||||
|
||||
if !s:is_table(line)
|
||||
return
|
||||
endif
|
||||
|
||||
@ -495,16 +616,41 @@ function! vimwiki#tbl#move_column_right() "{{{
|
||||
if cur_col < s:col_count(line('.'))-1
|
||||
call vimwiki#tbl#format(line('.'), cur_col, cur_col+1)
|
||||
call cursor(line('.'), 1)
|
||||
if !s:is_separator(getline('.'))
|
||||
call search('\%(|[^|]\+\)\{'.(cur_col+1).'}| .', 'eW')
|
||||
else
|
||||
call search('|\%([^+]\++\)\{'.(cur_col+1).'}--', 'eW')
|
||||
endif
|
||||
|
||||
let sep = '\('.s:rxSep.'\).\zs'
|
||||
let mpos = -1
|
||||
let col = -1
|
||||
while col < cur_col+1
|
||||
let mpos = match(line, sep, mpos+1)
|
||||
if mpos != -1
|
||||
let col += 1
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
endif
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#get_rows(lnum) "{{{
|
||||
return s:get_rows(a:lnum)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#is_table(line) "{{{
|
||||
return s:is_table(a:line)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#is_separator(line) "{{{
|
||||
return s:is_separator(a:line)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#cell_splitter() "{{{
|
||||
return s:cell_splitter()
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#sep_splitter() "{{{
|
||||
return s:sep_splitter()
|
||||
endfunction "}}}
|
||||
|
||||
"}}}
|
||||
|
Reference in New Issue
Block a user