* NEW: Issue 41: Table cell and column text objects. See `vimwiki-text-objects`. * NEW: Issue 42: Commands to move table columns left and right. See `:VimwikiTableMoveColumnLeft` and `:VimwikiTableMoveColumnRight`. * NEW: Issue 44: `<S-Tab>` should move cursor to the previous table cell. * NEW: Issue 45: It should be possible to indent tables. Indented tables are centered in html. * NEW: Issue 46: Do not htmlize some wiki pages (blacklist). New placeholder is added: `%nohtml`. See `vimwiki-nohtml`. * FIX: Issue 47: Lists aren't HTMLized properly. * FIX: Issue 48: With autochdir it is impossible to have path_html such as `d:\vimwiki\html\` * FIX: Issue 49: Table is not HTMLized properly at the end of wiki page. * FIX: Issue 50: Inline formatting is not performed in table cells. * FIX: Issue 51: Cannot insert '-' (minus) into table cells of the first column. * FIX: Issue 52: Table cell width is incorrect when double wide characters are used (ie. Chinese). Check `g:vimwiki_CJK_length`. * NEW: Issue 53: Wiki markup can not nested. (Use links and inline markup in Headers). * NEW: Issue 54: Highlight for placeholders. * NEW: Issue 56: Directory indexes. See `g:vimwiki_dir_link` option and `:VimwikiGenerateLinks` command. * NEW: Issue 58: Html new lines with `<br />`. Could be inserted with `<S-CR>` in insert mode. * FIX: Issue 59: List item's text can't be started from `*`. * NEW: Issue 60: Links inside completed gtd-items. * NEW: Issue 61: Headers numbering. See `g:vimwiki_html_header_numbering` and `g:vimwiki_html_header_numbering_sym` options. * FIX: Issue 63: Table cannot have leading empty cells in html. * FIX: Issue 65: Table separator is not htmlized right if on top of the table. * FIX: Issue 66: Table empty cells are very small in html. * FIX: Issue 67: Wrong html conversion of multilined list item with bold text on the start of next line. * FIX: Issue 68: auto-indent problem with langmap. * FIX: Issue 73: Link navigation by Tab. "Escaped" wiki-word should be skipped for navigation with `<tab>`. * FIX: Issue 75: `code` syntax doesn't display correctly in toc. * FIX: Issue 77: Diary index only showing link to today's diary entry file for extensions other than '.wiki'. * FIX: Issue 79: Further calendar.vim integration -- add sign to calendar date if it has corresponding diary page. * FIX: Issue 80: Debian Lenny GUI Vim 7.2 has problems with toggling inner todo list items. * FIX: Issue 81: Don't convert `WikiWord` as a link in html when `let g:vimwiki_camel_case = 0`
363 lines
8.6 KiB
VimL
363 lines
8.6 KiB
VimL
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
|
" Vimwiki autoload plugin file
|
|
" Todo lists related stuff here.
|
|
" Author: Maxim Kim <habamax@gmail.com>
|
|
" Home: http://code.google.com/p/vimwiki/
|
|
|
|
if exists("g:loaded_vimwiki_list_auto") || &cp
|
|
finish
|
|
endif
|
|
let g:loaded_vimwiki_lst_auto = 1
|
|
|
|
" Script variables {{{
|
|
let s:rx_li_box = '\[.\?\]'
|
|
" }}}
|
|
|
|
" Script functions {{{
|
|
|
|
" Get checkbox regexp
|
|
function! s:rx_li_symbol(rate) "{{{
|
|
let result = ''
|
|
if a:rate == 100
|
|
let result = g:vimwiki_listsyms[4]
|
|
elseif a:rate == 0
|
|
let result = g:vimwiki_listsyms[0]
|
|
elseif a:rate >= 67
|
|
let result = g:vimwiki_listsyms[3]
|
|
elseif a:rate >= 34
|
|
let result = g:vimwiki_listsyms[2]
|
|
else
|
|
let result = g:vimwiki_listsyms[1]
|
|
endif
|
|
|
|
return '\['.result.'\]'
|
|
endfunction "}}}
|
|
|
|
" Get regexp of the list item.
|
|
function! s:rx_list_item() "{{{
|
|
return '\('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)'
|
|
endfunction "}}}
|
|
|
|
" Get regexp of the list item with checkbox.
|
|
function! s:rx_cb_list_item() "{{{
|
|
" return s:rx_list_item().'\s*\zs\[.\?\]'
|
|
return s:rx_list_item().'\s*\zs\[.\?\]'
|
|
endfunction "}}}
|
|
|
|
" Get level of the list item.
|
|
function! s:get_level(lnum) "{{{
|
|
if VimwikiGet('syntax') == 'media'
|
|
let level = vimwiki#count_first_sym(getline(a:lnum))
|
|
else
|
|
let level = indent(a:lnum)
|
|
endif
|
|
return level
|
|
endfunction "}}}
|
|
|
|
" Get previous list item.
|
|
" Returns: line number or 0.
|
|
function! s:prev_list_item(lnum) "{{{
|
|
let c_lnum = a:lnum - 1
|
|
while c_lnum >= 1
|
|
let line = getline(c_lnum)
|
|
if line =~ s:rx_list_item()
|
|
return c_lnum
|
|
endif
|
|
if line =~ '^\s*$'
|
|
return 0
|
|
endif
|
|
let c_lnum -= 1
|
|
endwhile
|
|
return 0
|
|
endfunction "}}}
|
|
|
|
" Get next list item in the list.
|
|
" Returns: line number or 0.
|
|
function! s:next_list_item(lnum) "{{{
|
|
let c_lnum = a:lnum + 1
|
|
while c_lnum <= line('$')
|
|
let line = getline(c_lnum)
|
|
if line =~ s:rx_list_item()
|
|
return c_lnum
|
|
endif
|
|
if line =~ '^\s*$'
|
|
return 0
|
|
endif
|
|
let c_lnum += 1
|
|
endwhile
|
|
return 0
|
|
endfunction "}}}
|
|
|
|
" Find next list item in the buffer.
|
|
" Returns: line number or 0.
|
|
function! s:find_next_list_item(lnum) "{{{
|
|
let c_lnum = a:lnum + 1
|
|
while c_lnum <= line('$')
|
|
let line = getline(c_lnum)
|
|
if line =~ s:rx_list_item()
|
|
return c_lnum
|
|
endif
|
|
let c_lnum += 1
|
|
endwhile
|
|
return 0
|
|
endfunction "}}}
|
|
|
|
" Set state of the list item on line number "lnum" to [ ] or [x]
|
|
function! s:set_state(lnum, rate) "{{{
|
|
let line = getline(a:lnum)
|
|
let state = s:rx_li_symbol(a:rate)
|
|
let line = substitute(line, s:rx_li_box, state, '')
|
|
call setline(a:lnum, line)
|
|
endfunction "}}}
|
|
|
|
" Get state of the list item on line number "lnum"
|
|
function! s:get_state(lnum) "{{{
|
|
let state = 0
|
|
let line = getline(a:lnum)
|
|
let opt = matchstr(line, s:rx_cb_list_item())
|
|
if opt =~ s:rx_li_symbol(100)
|
|
let state = 100
|
|
elseif opt =~ s:rx_li_symbol(0)
|
|
let state = 0
|
|
elseif opt =~ s:rx_li_symbol(25)
|
|
let state = 25
|
|
elseif opt =~ s:rx_li_symbol(50)
|
|
let state = 50
|
|
elseif opt =~ s:rx_li_symbol(75)
|
|
let state = 75
|
|
endif
|
|
return state
|
|
endfunction "}}}
|
|
|
|
" Returns 1 if there is checkbox on a list item, 0 otherwise.
|
|
function! s:is_cb_list_item(lnum) "{{{
|
|
return getline(a:lnum) =~ s:rx_cb_list_item()
|
|
endfunction "}}}
|
|
|
|
" Returns start line number of list item, 0 if it is not a list.
|
|
function! s:is_list_item(lnum) "{{{
|
|
let c_lnum = a:lnum
|
|
while c_lnum >= 1
|
|
let line = getline(c_lnum)
|
|
if line =~ s:rx_list_item()
|
|
return c_lnum
|
|
endif
|
|
if line =~ '^\s*$'
|
|
return 0
|
|
endif
|
|
if indent(c_lnum) > indent(a:lnum)
|
|
return 0
|
|
endif
|
|
let c_lnum -= 1
|
|
endwhile
|
|
return 0
|
|
endfunction "}}}
|
|
|
|
" Returns char column of checkbox. Used in parent/child checks.
|
|
function! s:get_li_pos(lnum) "{{{
|
|
return stridx(getline(a:lnum), '[')
|
|
endfunction "}}}
|
|
|
|
" Returns list of line numbers of parent and all its child items.
|
|
function! s:get_child_items(lnum) "{{{
|
|
let result = []
|
|
let lnum = a:lnum
|
|
let p_pos = s:get_level(lnum)
|
|
|
|
" add parent
|
|
call add(result, lnum)
|
|
|
|
let lnum = s:next_list_item(lnum)
|
|
while lnum != 0 && s:is_list_item(lnum) && s:get_level(lnum) > p_pos
|
|
call add(result, lnum)
|
|
let lnum = s:next_list_item(lnum)
|
|
endwhile
|
|
|
|
return result
|
|
endfunction "}}}
|
|
|
|
" Returns list of line numbers of all items of the same level.
|
|
function! s:get_sibling_items(lnum) "{{{
|
|
let result = []
|
|
let lnum = a:lnum
|
|
let ind = s:get_level(lnum)
|
|
|
|
while s:get_level(lnum) >= ind &&
|
|
\ lnum != 0
|
|
|
|
if s:get_level(lnum) == ind && s:is_cb_list_item(lnum)
|
|
call add(result, lnum)
|
|
endif
|
|
let lnum = s:next_list_item(lnum)
|
|
endwhile
|
|
|
|
let lnum = s:prev_list_item(a:lnum)
|
|
while s:get_level(lnum) >= ind &&
|
|
\ lnum != 0
|
|
|
|
if s:get_level(lnum) == ind && s:is_cb_list_item(lnum)
|
|
call add(result, lnum)
|
|
endif
|
|
let lnum = s:prev_list_item(lnum)
|
|
endwhile
|
|
|
|
return result
|
|
endfunction "}}}
|
|
|
|
" Returns line number of the parent of lnum item
|
|
function! s:get_parent_item(lnum) "{{{
|
|
let lnum = a:lnum
|
|
let ind = s:get_level(lnum)
|
|
|
|
let lnum = s:prev_list_item(lnum)
|
|
while lnum != 0 && s:is_list_item(lnum) && s:get_level(lnum) >= ind
|
|
let lnum = s:prev_list_item(lnum)
|
|
endwhile
|
|
|
|
if s:is_cb_list_item(lnum)
|
|
return lnum
|
|
else
|
|
return a:lnum
|
|
endif
|
|
endfunction "}}}
|
|
|
|
" Creates checkbox in a list item.
|
|
function! s:create_cb_list_item(lnum) "{{{
|
|
let line = getline(a:lnum)
|
|
let m = matchstr(line, s:rx_list_item())
|
|
if m != ''
|
|
let li_content = substitute(strpart(line, len(m)), '^\s*', '', '')
|
|
let line = m.'[ ] '.li_content
|
|
call setline(a:lnum, line)
|
|
endif
|
|
endfunction "}}}
|
|
|
|
" Tells if all of the sibling list items are checked or not.
|
|
function! s:all_siblings_checked(lnum) "{{{
|
|
let result = 0
|
|
let cnt = 0
|
|
let siblings = s:get_sibling_items(a:lnum)
|
|
for lnum in siblings
|
|
let cnt += s:get_state(lnum)
|
|
endfor
|
|
let result = cnt/len(siblings)
|
|
return result
|
|
endfunction "}}}
|
|
|
|
" Creates checkbox on a list item if there is no one.
|
|
function! s:TLI_create_checkbox(lnum) "{{{
|
|
if a:lnum && !s:is_cb_list_item(a:lnum)
|
|
if g:vimwiki_auto_checkbox
|
|
call s:create_cb_list_item(a:lnum)
|
|
endif
|
|
return 1
|
|
endif
|
|
return 0
|
|
endfunction "}}}
|
|
|
|
" Switch state of the child list items.
|
|
function! s:TLI_switch_child_state(lnum) "{{{
|
|
let current_state = s:get_state(a:lnum)
|
|
if current_state == 100
|
|
let new_state = 0
|
|
else
|
|
let new_state = 100
|
|
endif
|
|
for lnum in s:get_child_items(a:lnum)
|
|
call s:set_state(lnum, new_state)
|
|
endfor
|
|
endfunction "}}}
|
|
|
|
" Switch state of the parent list items.
|
|
function! s:TLI_switch_parent_state(lnum) "{{{
|
|
let c_lnum = a:lnum
|
|
while s:is_cb_list_item(c_lnum)
|
|
let parent_lnum = s:get_parent_item(c_lnum)
|
|
if parent_lnum == c_lnum
|
|
break
|
|
endif
|
|
call s:set_state(parent_lnum, s:all_siblings_checked(c_lnum))
|
|
|
|
let c_lnum = parent_lnum
|
|
endwhile
|
|
endfunction "}}}
|
|
|
|
function! s:TLI_toggle(lnum) "{{{
|
|
if !s:TLI_create_checkbox(a:lnum)
|
|
call s:TLI_switch_child_state(a:lnum)
|
|
endif
|
|
call s:TLI_switch_parent_state(a:lnum)
|
|
endfunction "}}}
|
|
|
|
" Script functions }}}
|
|
|
|
" Toggle list item between [ ] and [X]
|
|
function! vimwiki_lst#ToggleListItem(line1, line2) "{{{
|
|
let line1 = a:line1
|
|
let line2 = a:line2
|
|
|
|
if line1 != line2 && !s:is_list_item(line1)
|
|
let line1 = s:find_next_list_item(line1)
|
|
endif
|
|
|
|
let c_lnum = line1
|
|
while c_lnum != 0 && c_lnum <= line2
|
|
let li_lnum = s:is_list_item(c_lnum)
|
|
|
|
if li_lnum
|
|
let li_level = s:get_level(li_lnum)
|
|
if c_lnum == line1
|
|
let start_li_level = li_level
|
|
endif
|
|
|
|
if li_level <= start_li_level
|
|
call s:TLI_toggle(li_lnum)
|
|
let start_li_level = li_level
|
|
endif
|
|
endif
|
|
|
|
let c_lnum = s:find_next_list_item(c_lnum)
|
|
endwhile
|
|
|
|
endfunction "}}}
|
|
|
|
function! vimwiki_lst#insertCR() "{{{
|
|
" This function is heavily relies on proper 'set comments' option.
|
|
let cr = "\<CR>"
|
|
if getline('.') =~ s:rx_cb_list_item()
|
|
let cr .= '[ ] '
|
|
endif
|
|
return cr
|
|
endfunction "}}}
|
|
|
|
function! vimwiki_lst#insertOo(cmd) "{{{
|
|
" cmd should be 'o' or 'O'
|
|
|
|
let beg_lnum = foldclosed('.')
|
|
let end_lnum = foldclosedend('.')
|
|
if end_lnum != -1 && a:cmd ==# 'o'
|
|
let lnum = end_lnum
|
|
let line = getline(beg_lnum)
|
|
else
|
|
let line = getline('.')
|
|
let lnum = line('.')
|
|
endif
|
|
|
|
let res = ''
|
|
if line =~ s:rx_cb_list_item()
|
|
let res = matchstr(line, s:rx_list_item()).'[ ] '
|
|
elseif line =~ s:rx_list_item()
|
|
let res = matchstr(line, s:rx_list_item())
|
|
elseif &autoindent || &smartindent
|
|
let res = matchstr(line, '^\s*')
|
|
endif
|
|
if a:cmd ==# 'o'
|
|
call append(lnum, res)
|
|
call cursor(lnum + 1, col('$'))
|
|
else
|
|
call append(lnum - 1, res)
|
|
call cursor(lnum, col('$'))
|
|
endif
|
|
endfunction "}}}
|
|
|