mirror of
https://github.com/gryf/.vim.git
synced 2025-12-18 12:00:30 +01:00
Update of plugins (vimwiki, ctrlp, syntastic, tagbar, gundo and mark),
added draft syntax file for kickassembler
This commit is contained in:
1502
bundle/git_vimwiki/autoload/vimwiki/base.vim
Normal file
1502
bundle/git_vimwiki/autoload/vimwiki/base.vim
Normal file
File diff suppressed because it is too large
Load Diff
11
bundle/git_vimwiki/autoload/vimwiki/default.tpl
Normal file
11
bundle/git_vimwiki/autoload/vimwiki/default.tpl
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<link rel="Stylesheet" type="text/css" href="%root_path%%css%">
|
||||
<title>%title%</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=%encoding%">
|
||||
</head>
|
||||
<body>
|
||||
%content%
|
||||
</body>
|
||||
</html>
|
||||
358
bundle/git_vimwiki/autoload/vimwiki/diary.vim
Normal file
358
bundle/git_vimwiki/autoload/vimwiki/diary.vim
Normal file
@@ -0,0 +1,358 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Handle diary notes
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
|
||||
" Load only once {{{
|
||||
if exists("g:loaded_vimwiki_diary_auto") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_diary_auto = 1
|
||||
"}}}
|
||||
|
||||
let s:vimwiki_max_scan_for_caption = 5
|
||||
|
||||
" Helpers {{{
|
||||
function! s:prefix_zero(num) "{{{
|
||||
if a:num < 10
|
||||
return '0'.a:num
|
||||
endif
|
||||
return a:num
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_date_link(fmt) "{{{
|
||||
return strftime(a:fmt)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:link_exists(lines, link) "{{{
|
||||
let link_exists = 0
|
||||
for line in a:lines
|
||||
if line =~ escape(a:link, '[]\')
|
||||
let link_exists = 1
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
return link_exists
|
||||
endfunction "}}}
|
||||
|
||||
function! s:diary_path(...) "{{{
|
||||
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
|
||||
return VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:diary_index(...) "{{{
|
||||
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
|
||||
return s:diary_path(idx).VimwikiGet('diary_index', idx).VimwikiGet('ext', idx)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:diary_date_link(...) "{{{
|
||||
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
|
||||
return s:get_date_link(VimwikiGet('diary_link_fmt', idx))
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_position_links(link) "{{{
|
||||
let idx = -1
|
||||
let links = []
|
||||
if a:link =~ '^\d\{4}-\d\d-\d\d'
|
||||
let links = keys(s:get_diary_links())
|
||||
" include 'today' into links
|
||||
if index(links, s:diary_date_link()) == -1
|
||||
call add(links, s:diary_date_link())
|
||||
endif
|
||||
call sort(links)
|
||||
let idx = index(links, a:link)
|
||||
endif
|
||||
return [idx, links]
|
||||
endfunction "}}}
|
||||
|
||||
fun! s:get_month_name(month) "{{{
|
||||
return g:vimwiki_diary_months[str2nr(a:month)]
|
||||
endfun "}}}
|
||||
|
||||
" Helpers }}}
|
||||
|
||||
" Diary index stuff {{{
|
||||
fun! s:read_captions(files) "{{{
|
||||
let result = {}
|
||||
for fl in a:files
|
||||
" remove paths and extensions
|
||||
let fl_key = fnamemodify(fl, ':t:r')
|
||||
|
||||
if filereadable(fl)
|
||||
for line in readfile(fl, '', s:vimwiki_max_scan_for_caption)
|
||||
if line =~ g:vimwiki_rxHeader && !has_key(result, fl_key)
|
||||
let result[fl_key] = vimwiki#u#trim(matchstr(line, g:vimwiki_rxHeader))
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if !has_key(result, fl_key)
|
||||
let result[fl_key] = ''
|
||||
endif
|
||||
|
||||
endfor
|
||||
return result
|
||||
endfun "}}}
|
||||
|
||||
fun! s:get_diary_links(...) "{{{
|
||||
let rx = '^\d\{4}-\d\d-\d\d'
|
||||
let s_files = glob(VimwikiGet('path').VimwikiGet('diary_rel_path').'*'.VimwikiGet('ext'))
|
||||
let files = split(s_files, '\n')
|
||||
call filter(files, 'fnamemodify(v:val, ":t") =~ "'.escape(rx, '\').'"')
|
||||
|
||||
" remove backup files (.wiki~)
|
||||
call filter(files, 'v:val !~ ''.*\~$''')
|
||||
|
||||
if a:0
|
||||
call add(files, a:1)
|
||||
endif
|
||||
let links_with_captions = s:read_captions(files)
|
||||
|
||||
return links_with_captions
|
||||
endfun "}}}
|
||||
|
||||
fun! s:group_links(links) "{{{
|
||||
let result = {}
|
||||
let p_year = 0
|
||||
let p_month = 0
|
||||
for fl in sort(keys(a:links))
|
||||
let year = strpart(fl, 0, 4)
|
||||
let month = strpart(fl, 5, 2)
|
||||
if p_year != year
|
||||
let result[year] = {}
|
||||
let p_month = 0
|
||||
endif
|
||||
if p_month != month
|
||||
let result[year][month] = {}
|
||||
endif
|
||||
let result[year][month][fl] = a:links[fl]
|
||||
let p_year = year
|
||||
let p_month = month
|
||||
endfor
|
||||
return result
|
||||
endfun "}}}
|
||||
|
||||
fun! s:sort(lst) "{{{
|
||||
if VimwikiGet("diary_sort") == 'desc'
|
||||
return reverse(sort(a:lst))
|
||||
else
|
||||
return sort(a:lst)
|
||||
endif
|
||||
endfun "}}}
|
||||
|
||||
fun! s:format_diary(...) "{{{
|
||||
let result = []
|
||||
|
||||
call add(result, substitute(g:vimwiki_rxH1_Template, '__Header__', VimwikiGet('diary_header'), ''))
|
||||
|
||||
if a:0
|
||||
let g_files = s:group_links(s:get_diary_links(a:1))
|
||||
else
|
||||
let g_files = s:group_links(s:get_diary_links())
|
||||
endif
|
||||
|
||||
" for year in s:rev(sort(keys(g_files)))
|
||||
for year in s:sort(keys(g_files))
|
||||
call add(result, '')
|
||||
call add(result, substitute(g:vimwiki_rxH2_Template, '__Header__', year , ''))
|
||||
|
||||
" for month in s:rev(sort(keys(g_files[year])))
|
||||
for month in s:sort(keys(g_files[year]))
|
||||
call add(result, '')
|
||||
call add(result, substitute(g:vimwiki_rxH3_Template, '__Header__', s:get_month_name(month), ''))
|
||||
|
||||
" for [fl, cap] in s:rev(sort(items(g_files[year][month])))
|
||||
for [fl, cap] in s:sort(items(g_files[year][month]))
|
||||
if empty(cap)
|
||||
let entry = substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', fl, '')
|
||||
let entry = substitute(entry, '__LinkDescription__', cap, '')
|
||||
call add(result, repeat(' ', &sw).'* '.entry)
|
||||
else
|
||||
let entry = substitute(g:vimwiki_WikiLinkTemplate2, '__LinkUrl__', fl, '')
|
||||
let entry = substitute(entry, '__LinkDescription__', cap, '')
|
||||
call add(result, repeat(' ', &sw).'* '.entry)
|
||||
endif
|
||||
endfor
|
||||
|
||||
endfor
|
||||
endfor
|
||||
call add(result, '')
|
||||
|
||||
return result
|
||||
endfun "}}}
|
||||
|
||||
function! s:delete_diary_section() "{{{
|
||||
" remove diary section
|
||||
let old_pos = getpos('.')
|
||||
let ln_start = -1
|
||||
let ln_end = -1
|
||||
call cursor(1, 1)
|
||||
if search(substitute(g:vimwiki_rxH1_Template, '__Header__', VimwikiGet('diary_header'), ''), 'Wc')
|
||||
let ln_start = line('.')
|
||||
if search(g:vimwiki_rxH1, 'W')
|
||||
let ln_end = line('.') - 1
|
||||
else
|
||||
let ln_end = line('$')
|
||||
endif
|
||||
endif
|
||||
|
||||
if ln_start < 0 || ln_end < 0
|
||||
call setpos('.', old_pos)
|
||||
return
|
||||
endif
|
||||
|
||||
if !&readonly
|
||||
exe ln_start.",".ln_end."delete _"
|
||||
endif
|
||||
|
||||
call setpos('.', old_pos)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:insert_diary_section() "{{{
|
||||
if !&readonly
|
||||
let ln = line('.')
|
||||
call append(ln, s:format_diary())
|
||||
if ln == 1 && getline(ln) == ''
|
||||
1,1delete
|
||||
endif
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
" Diary index stuff }}}
|
||||
|
||||
function! vimwiki#diary#make_note(wnum, ...) "{{{
|
||||
if a:wnum > len(g:vimwiki_list)
|
||||
echom "vimwiki: Wiki ".a:wnum." is not registered in g:vimwiki_list!"
|
||||
return
|
||||
endif
|
||||
|
||||
" TODO: refactor it. base#goto_index uses the same
|
||||
if a:wnum > 0
|
||||
let idx = a:wnum - 1
|
||||
else
|
||||
let idx = 0
|
||||
endif
|
||||
|
||||
call vimwiki#base#validate_wiki_options(idx)
|
||||
call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx))
|
||||
|
||||
if a:0
|
||||
let cmd = 'tabedit'
|
||||
else
|
||||
let cmd = 'edit'
|
||||
endif
|
||||
if len(a:0)>1
|
||||
let link = 'diary:'.a:2
|
||||
else
|
||||
let link = 'diary:'.s:diary_date_link(idx)
|
||||
endif
|
||||
|
||||
call vimwiki#base#open_link(cmd, link, s:diary_index(idx))
|
||||
call vimwiki#base#setup_buffer_state(idx)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#diary#goto_diary_index(wnum) "{{{
|
||||
if a:wnum > len(g:vimwiki_list)
|
||||
echom "vimwiki: Wiki ".a:wnum." is not registered in g:vimwiki_list!"
|
||||
return
|
||||
endif
|
||||
|
||||
" TODO: refactor it. base#goto_index uses the same
|
||||
if a:wnum > 0
|
||||
let idx = a:wnum - 1
|
||||
else
|
||||
let idx = 0
|
||||
endif
|
||||
|
||||
call vimwiki#base#validate_wiki_options(idx)
|
||||
call vimwiki#base#edit_file('e', s:diary_index(idx))
|
||||
call vimwiki#base#setup_buffer_state(idx)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#diary#goto_next_day() "{{{
|
||||
let link = ''
|
||||
let [idx, links] = s:get_position_links(expand('%:t:r'))
|
||||
|
||||
if idx == (len(links) - 1)
|
||||
return
|
||||
endif
|
||||
|
||||
if idx != -1 && idx < len(links) - 1
|
||||
let link = 'diary:'.links[idx+1]
|
||||
else
|
||||
" goto today
|
||||
let link = 'diary:'.s:diary_date_link()
|
||||
endif
|
||||
|
||||
if len(link)
|
||||
call vimwiki#base#open_link(':e ', link)
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#diary#goto_prev_day() "{{{
|
||||
let link = ''
|
||||
let [idx, links] = s:get_position_links(expand('%:t:r'))
|
||||
|
||||
if idx == 0
|
||||
return
|
||||
endif
|
||||
|
||||
if idx > 0
|
||||
let link = 'diary:'.links[idx-1]
|
||||
else
|
||||
" goto today
|
||||
let link = 'diary:'.s:diary_date_link()
|
||||
endif
|
||||
|
||||
if len(link)
|
||||
call vimwiki#base#open_link(':e ', link)
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#diary#generate_diary_section() "{{{
|
||||
let current_file = vimwiki#u#path_norm(expand("%:p"))
|
||||
let diary_file = vimwiki#u#path_norm(s:diary_index())
|
||||
if current_file == diary_file
|
||||
call s:delete_diary_section()
|
||||
call s:insert_diary_section()
|
||||
else
|
||||
echom "vimwiki: You can generate diary links only in a diary index page!"
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
" Calendar.vim {{{
|
||||
" Callback function.
|
||||
function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
|
||||
let link = a:year.'-'.month.'-'.day
|
||||
if winnr('#') == 0
|
||||
if a:dir == 'V'
|
||||
vsplit
|
||||
else
|
||||
split
|
||||
endif
|
||||
else
|
||||
wincmd p
|
||||
if !&hidden && &modified
|
||||
new
|
||||
endif
|
||||
endif
|
||||
|
||||
" Create diary note for a selected date in default wiki.
|
||||
call vimwiki#diary#make_note(1, 0, link)
|
||||
endfunction "}}}
|
||||
|
||||
" Sign function.
|
||||
function vimwiki#diary#calendar_sign(day, month, year) "{{{
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
let sfile = VimwikiGet('path').VimwikiGet('diary_rel_path').
|
||||
\ a:year.'-'.month.'-'.day.VimwikiGet('ext')
|
||||
return filereadable(expand(sfile))
|
||||
endfunction "}}}
|
||||
|
||||
" Calendar.vim }}}
|
||||
|
||||
1579
bundle/git_vimwiki/autoload/vimwiki/html.vim
Normal file
1579
bundle/git_vimwiki/autoload/vimwiki/html.vim
Normal file
File diff suppressed because it is too large
Load Diff
555
bundle/git_vimwiki/autoload/vimwiki/lst.vim
Normal file
555
bundle/git_vimwiki/autoload/vimwiki/lst.vim
Normal file
@@ -0,0 +1,555 @@
|
||||
" 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 unicode string symbol at index
|
||||
function! s:str_idx(str, idx) "{{{
|
||||
" Unfortunatly vimscript cannot get symbol at index in unicode string such as
|
||||
" '✗○◐●✓'
|
||||
return matchstr(a:str, '\%'.a:idx.'v.')
|
||||
endfunction "}}}
|
||||
|
||||
" Get checkbox regexp
|
||||
function! s:rx_li_symbol(rate) "{{{
|
||||
let result = ''
|
||||
if a:rate == 100
|
||||
let result = s:str_idx(g:vimwiki_listsyms, 5)
|
||||
elseif a:rate == 0
|
||||
let result = s:str_idx(g:vimwiki_listsyms, 1)
|
||||
elseif a:rate >= 67
|
||||
let result = s:str_idx(g:vimwiki_listsyms, 4)
|
||||
elseif a:rate >= 34
|
||||
let result = s:str_idx(g:vimwiki_listsyms, 3)
|
||||
else
|
||||
let result = s:str_idx(g:vimwiki_listsyms, 2)
|
||||
endif
|
||||
|
||||
return '\['.result.'\]'
|
||||
endfunction "}}}
|
||||
|
||||
" Get blank checkbox
|
||||
function! s:blank_checkbox() "{{{
|
||||
return '['.s:str_idx(g:vimwiki_listsyms, 1).'] '
|
||||
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\[.\?\]'
|
||||
endfunction "}}}
|
||||
|
||||
" Get level of the list item.
|
||||
function! s:get_level(lnum) "{{{
|
||||
if VimwikiGet('syntax') == 'media'
|
||||
let level = vimwiki#u#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 lnum != 0 && s:get_level(lnum) >= ind
|
||||
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 lnum != 0 && s:get_level(lnum) >= ind
|
||||
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 = substitute(m, '\s*$', ' ', '').s:blank_checkbox().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#kbd_cr() "{{{
|
||||
" This function is heavily relies on proper 'set comments' option.
|
||||
let cr = "\<CR>"
|
||||
if getline('.') =~ s:rx_cb_list_item()
|
||||
let cr .= s:blank_checkbox()
|
||||
endif
|
||||
return cr
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#lst#kbd_oO(cmd) "{{{
|
||||
" cmd should be 'o' or 'O'
|
||||
|
||||
let l:count = v:count1
|
||||
while l:count > 0
|
||||
|
||||
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 m = matchstr(line, s:rx_list_item())
|
||||
let res = ''
|
||||
if line =~ s:rx_cb_list_item()
|
||||
let res = substitute(m, '\s*$', ' ', '').s:blank_checkbox()
|
||||
elseif line =~ s:rx_list_item()
|
||||
let res = substitute(m, '\s*$', ' ', '')
|
||||
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
|
||||
|
||||
let l:count -= 1
|
||||
endwhile
|
||||
|
||||
startinsert!
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#lst#default_symbol() "{{{
|
||||
" TODO: initialize default symbol from syntax/vimwiki_xxx.vim
|
||||
if VimwikiGet('syntax') == 'default'
|
||||
return '-'
|
||||
else
|
||||
return '*'
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function vimwiki#lst#get_list_margin() "{{{
|
||||
if VimwikiGet('list_margin') < 0
|
||||
return &sw
|
||||
else
|
||||
return VimwikiGet('list_margin')
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function s:get_list_sw() "{{{
|
||||
if VimwikiGet('syntax') == 'media'
|
||||
return 1
|
||||
else
|
||||
return &sw
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function s:get_list_nesting_level(lnum) "{{{
|
||||
if VimwikiGet('syntax') == 'media'
|
||||
if getline(a:lnum) !~ s:rx_list_item()
|
||||
let level = 0
|
||||
else
|
||||
let level = vimwiki#u#count_first_sym(getline(a:lnum)) - 1
|
||||
let level = level < 0 ? 0 : level
|
||||
endif
|
||||
else
|
||||
let level = indent(a:lnum)
|
||||
endif
|
||||
return level
|
||||
endfunction "}}}
|
||||
|
||||
function s:get_list_indent(lnum) "{{{
|
||||
if VimwikiGet('syntax') == 'media'
|
||||
return indent(a:lnum)
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:compose_list_item(n_indent, n_nesting, sym_nest, sym_bullet, li_content, ...) "{{{
|
||||
if a:0
|
||||
let sep = a:1
|
||||
else
|
||||
let sep = ''
|
||||
endif
|
||||
let li_indent = repeat(' ', max([0,a:n_indent])).sep
|
||||
let li_nesting = repeat(a:sym_nest, max([0,a:n_nesting])).sep
|
||||
if len(a:sym_bullet) > 0
|
||||
let li_bullet = a:sym_bullet.' '.sep
|
||||
else
|
||||
let li_bullet = ''.sep
|
||||
endif
|
||||
return li_indent.li_nesting.li_bullet.a:li_content
|
||||
endfunction "}}}
|
||||
|
||||
function s:compose_cb_bullet(prev_cb_bullet, sym) "{{{
|
||||
return a:sym.matchstr(a:prev_cb_bullet, '\S*\zs\s\+.*')
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#lst#change_level(...) "{{{
|
||||
let default_sym = vimwiki#lst#default_symbol()
|
||||
let cmd = '>>'
|
||||
let sym = default_sym
|
||||
|
||||
" parse argument
|
||||
if a:0
|
||||
if a:1 != '<<' && a:1 != '>>'
|
||||
let cmd = '--'
|
||||
let sym = a:1
|
||||
else
|
||||
let cmd = a:1
|
||||
endif
|
||||
endif
|
||||
" is symbol valid
|
||||
if sym.' ' !~ s:rx_cb_list_item() && sym.' ' !~ s:rx_list_item()
|
||||
return
|
||||
endif
|
||||
|
||||
" parsing setup
|
||||
let lnum = line('.')
|
||||
let line = getline('.')
|
||||
|
||||
let list_margin = vimwiki#lst#get_list_margin()
|
||||
let list_sw = s:get_list_sw()
|
||||
let n_nesting = s:get_list_nesting_level(lnum)
|
||||
let n_indent = s:get_list_indent(lnum)
|
||||
|
||||
" remove indent and nesting
|
||||
let li_bullet_and_content = strpart(line, n_nesting + n_indent)
|
||||
|
||||
" list bullet and checkbox
|
||||
let cb_bullet = matchstr(li_bullet_and_content, s:rx_list_item()).
|
||||
\ matchstr(li_bullet_and_content, s:rx_cb_list_item())
|
||||
|
||||
" XXX: it could be not unicode proof --> if checkboxes are set up with unicode syms
|
||||
" content
|
||||
let li_content = strpart(li_bullet_and_content, len(cb_bullet))
|
||||
|
||||
" trim
|
||||
let cb_bullet = vimwiki#u#trim(cb_bullet)
|
||||
let li_content = vimwiki#u#trim(li_content)
|
||||
|
||||
" nesting symbol
|
||||
if VimwikiGet('syntax') == 'media'
|
||||
if len(cb_bullet) > 0
|
||||
let sym_nest = cb_bullet[0]
|
||||
else
|
||||
let sym_nest = sym
|
||||
endif
|
||||
else
|
||||
let sym_nest = ' '
|
||||
endif
|
||||
|
||||
if g:vimwiki_debug
|
||||
echomsg "PARSE: Sw [".list_sw."]"
|
||||
echomsg s:compose_list_item(n_indent, n_nesting, sym_nest, cb_bullet, li_content, '|')
|
||||
endif
|
||||
|
||||
" change level
|
||||
if cmd == '--'
|
||||
let cb_bullet = s:compose_cb_bullet(cb_bullet, sym)
|
||||
if VimwikiGet('syntax') == 'media'
|
||||
let sym_nest = sym
|
||||
endif
|
||||
elseif cmd == '>>'
|
||||
if cb_bullet == ''
|
||||
let cb_bullet = sym
|
||||
else
|
||||
let n_nesting = n_nesting + list_sw
|
||||
endif
|
||||
elseif cmd == '<<'
|
||||
let n_nesting = n_nesting - list_sw
|
||||
if VimwikiGet('syntax') == 'media'
|
||||
if n_nesting < 0
|
||||
let cb_bullet = ''
|
||||
endif
|
||||
else
|
||||
if n_nesting < list_margin
|
||||
let cb_bullet = ''
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let n_nesting = max([0, n_nesting])
|
||||
|
||||
if g:vimwiki_debug
|
||||
echomsg "SHIFT:"
|
||||
echomsg s:compose_list_item(n_indent, n_nesting, sym_nest, cb_bullet, li_content, '|')
|
||||
endif
|
||||
|
||||
" XXX: this is the code that adds the initial indent
|
||||
let add_nesting = VimwikiGet('syntax') != 'media'
|
||||
if n_indent + n_nesting*(add_nesting) < list_margin
|
||||
let n_indent = list_margin - n_nesting*(add_nesting)
|
||||
endif
|
||||
|
||||
if g:vimwiki_debug
|
||||
echomsg "INDENT:"
|
||||
echomsg s:compose_list_item(n_indent, n_nesting, sym_nest, cb_bullet, li_content, '|')
|
||||
endif
|
||||
|
||||
let line = s:compose_list_item(n_indent, n_nesting, sym_nest, cb_bullet, li_content)
|
||||
|
||||
" replace
|
||||
call setline(lnum, line)
|
||||
call cursor(lnum, match(line, '\S') + 1)
|
||||
endfunction "}}}
|
||||
111
bundle/git_vimwiki/autoload/vimwiki/markdown_base.vim
Normal file
111
bundle/git_vimwiki/autoload/vimwiki/markdown_base.vim
Normal file
@@ -0,0 +1,111 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Link functions for markdown syntax
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
|
||||
|
||||
function! s:normalize_link_syntax_n() " {{{
|
||||
let lnum = line('.')
|
||||
|
||||
" try WikiIncl
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl)
|
||||
if !empty(lnk)
|
||||
" NO-OP !!
|
||||
if g:vimwiki_debug > 1
|
||||
echomsg "WikiIncl: ".lnk." Sub: ".lnk
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
" try WikiLink0: replace with WikiLink1
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink0)
|
||||
if !empty(lnk)
|
||||
let sub = vimwiki#base#normalize_link_helper(lnk,
|
||||
\ g:vimwiki_rxWikiLinkMatchUrl, g:vimwiki_rxWikiLinkMatchDescr,
|
||||
\ g:vimwiki_WikiLink1Template2)
|
||||
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWikiLink0, sub)
|
||||
if g:vimwiki_debug > 1
|
||||
echomsg "WikiLink: ".lnk." Sub: ".sub
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
" try WikiLink1: replace with WikiLink0
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink1)
|
||||
if !empty(lnk)
|
||||
let sub = vimwiki#base#normalize_link_helper(lnk,
|
||||
\ g:vimwiki_rxWikiLinkMatchUrl, g:vimwiki_rxWikiLinkMatchDescr,
|
||||
\ g:vimwiki_WikiLinkTemplate2)
|
||||
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWikiLink1, sub)
|
||||
if g:vimwiki_debug > 1
|
||||
echomsg "WikiLink: ".lnk." Sub: ".sub
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
" try Weblink
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink)
|
||||
if !empty(lnk)
|
||||
let sub = vimwiki#base#normalize_link_helper(lnk,
|
||||
\ g:vimwiki_rxWeblinkMatchUrl, g:vimwiki_rxWeblinkMatchDescr,
|
||||
\ g:vimwiki_Weblink1Template)
|
||||
call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWeblink, sub)
|
||||
if g:vimwiki_debug > 1
|
||||
echomsg "WebLink: ".lnk." Sub: ".sub
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
" try Word (any characters except separators)
|
||||
" rxWord is less permissive than rxWikiLinkUrl which is used in
|
||||
" normalize_link_syntax_v
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWord)
|
||||
if !empty(lnk)
|
||||
let sub = vimwiki#base#normalize_link_helper(lnk,
|
||||
\ g:vimwiki_rxWord, '',
|
||||
\ g:vimwiki_WikiLinkTemplate1)
|
||||
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
|
||||
if g:vimwiki_debug > 1
|
||||
echomsg "Word: ".lnk." Sub: ".sub
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
endfunction " }}}
|
||||
|
||||
function! s:normalize_link_syntax_v() " {{{
|
||||
let lnum = line('.')
|
||||
let sel_save = &selection
|
||||
let &selection = "old"
|
||||
let rv = @"
|
||||
let rt = getregtype('"')
|
||||
let done = 0
|
||||
|
||||
try
|
||||
norm! gvy
|
||||
let visual_selection = @"
|
||||
let visual_selection = substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', '\='."'".visual_selection."'", '')
|
||||
|
||||
call setreg('"', visual_selection, 'v')
|
||||
|
||||
" paste result
|
||||
norm! `>pgvd
|
||||
|
||||
finally
|
||||
call setreg('"', rv, rt)
|
||||
let &selection = sel_save
|
||||
endtry
|
||||
|
||||
endfunction " }}}
|
||||
|
||||
" normalize_link
|
||||
function! vimwiki#markdown_base#normalize_link(is_visual_mode) "{{{
|
||||
if !a:is_visual_mode
|
||||
call s:normalize_link_syntax_n()
|
||||
elseif visualmode() ==# 'v' && line("'<") == line("'>")
|
||||
" action undefined for 'line-wise' or 'multi-line' visual mode selections
|
||||
call s:normalize_link_syntax_v()
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
79
bundle/git_vimwiki/autoload/vimwiki/style.css
Normal file
79
bundle/git_vimwiki/autoload/vimwiki/style.css
Normal file
@@ -0,0 +1,79 @@
|
||||
body {font-family: Tahoma, Geneva, sans-serif; margin: 1em 2em 1em 2em; font-size: 100%; line-height: 130%;}
|
||||
h1, h2, h3, h4, h5, h6 {font-family: Trebuchet MS, Helvetica, sans-serif; font-weight: bold; line-height:100%; margin-top: 1.5em; margin-bottom: 0.5em;}
|
||||
h1 {font-size: 2.6em; color: #000000;}
|
||||
h2 {font-size: 2.2em; color: #404040;}
|
||||
h3 {font-size: 1.8em; color: #707070;}
|
||||
h4 {font-size: 1.4em; color: #909090;}
|
||||
h5 {font-size: 1.3em; color: #989898;}
|
||||
h6 {font-size: 1.2em; color: #9c9c9c;}
|
||||
p, pre, blockquote, table, ul, ol, dl {margin-top: 1em; margin-bottom: 1em;}
|
||||
ul ul, ul ol, ol ol, ol ul {margin-top: 0.5em; margin-bottom: 0.5em;}
|
||||
li {margin: 0.3em auto;}
|
||||
ul {margin-left: 2em; padding-left: 0.5em;}
|
||||
dt {font-weight: bold;}
|
||||
img {border: none;}
|
||||
pre {border-left: 1px solid #ccc; margin-left: 2em; padding-left: 0.5em;}
|
||||
blockquote {padding: 0.4em; background-color: #f6f5eb;}
|
||||
th, td {border: 1px solid #ccc; padding: 0.3em;}
|
||||
th {background-color: #f0f0f0;}
|
||||
hr {border: none; border-top: 1px solid #ccc; width: 100%;}
|
||||
del {text-decoration: line-through; color: #777777;}
|
||||
.toc li {list-style-type: none;}
|
||||
.todo {font-weight: bold; background-color: #f0ece8; color: #a03020;}
|
||||
.justleft {text-align: left;}
|
||||
.justright {text-align: right;}
|
||||
.justcenter {text-align: center;}
|
||||
.center {margin-left: auto; margin-right: auto;}
|
||||
|
||||
/* classes for items of todo lists */
|
||||
.done0 {
|
||||
/* list-style: none; */
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAA7SURBVCiR7dMxEgAgCANBI3yVRzF5KxNbW6wsuH7LQ2YKQK1mkswBVERYF5Os3UV3gwd/jF2SkXy66gAZkxS6BniubAAAAABJRU5ErkJggg==);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 .2em;
|
||||
margin-left: -2em;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
.done1 {
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAABtSURBVCiR1ZO7DYAwDER9BDmTeZQMFXmUbGYpOjrEryA0wOvO8itOslFrJYAug5BMM4BeSkmjsrv3aVTa8p48Xw1JSkSsWVUFwD05IqS1tmYzk5zzae9jnVVVzGyXb8sALjse+euRkEzu/uirFomVIdDGOLjuAAAAAElFTkSuQmCC);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 .15em;
|
||||
margin-left: -2em;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
.done2 {
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAB1SURBVCiRzdO5DcAgDAVQGxjAYgTvxlDIu1FTIRYAp8qlFISkSH7l5kk+ZIwxKiI2mIyqWoeILYRgZ7GINDOLjnmF3VqklKCUMgTee2DmM661Qs55iI3Zm/1u5h9sm4ig9z4ERHTFzLyd4G4+nFlVrYg8+qoF/c0kdpeMsmcAAAAASUVORK5CYII=);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 .15em;
|
||||
margin-left: -2em;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
.done3 {
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAABoSURBVCiR7dOxDcAgDATA/0DtUdiKoZC3YhLkHjkVKF3idJHiztKfvrHZWnOSE8Fx95RJzlprimJVnXktvXeY2S0SEZRSAAAbmxnGGKH2I5T+8VfxPhIReQSuuY3XyYWa3T2p6quvOgGrvSFGlewuUAAAAABJRU5ErkJggg==);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 .15em;
|
||||
margin-left: -2em;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
.done4 {
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAQCAYAAAAbBi9cAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAzgAAAM4BlP6ToAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAIISURBVDiNnZQ9SFtRFMd/773kpTaGJoQk1im4VDpWQcTNODhkFBcVTCNCF0NWyeDiIIiCm82QoIMIUkHUxcFBg1SEQoZszSat6cdTn1qNue92CMbEr9Sey+XC/Z/zu+f8h6ukUil3sVg0+M+4cFxk42/jH2wAqqqKSCSiPQdwcHHAnDHH9s/tN1h8V28ETdP+eU8fT9Nt62ancYdIPvJNtsu87bmjrJlrTDVM4RROJs1JrHPrD4Bar7A6cpc54iKOaTdJXCUI2UMVrQZ0Js7YPN18ECKkYNQcJe/OE/4dZsw7VqNXQMvHy3QZXQypQ6ycrtwDjf8aJ+PNEDSCzLpn7+m2pD8ZKHlKarYhy6XjEoCYGcN95qansQeA3fNdki+SaJZGTMQIOoL3W/Z89rxv+tokubNajlvk/vm+LFpF2XnUKZHI0I+QrI7Dw0OZTqdzUkpsM7mZTyfy5OPGyw1tK7AFSvmB/Ks8w8YwbUYbe6/3QEKv0vugfxWPnMLJun+d/kI/WLdizpNjMbAIKrhMF4OuwadBALqqs+RfInwUvuNi+fBd+wjogfogAFVRmffO02q01mZZ0HHdgXIzdz0QQLPezIQygX6llxNKKgOFARYCC49CqhoHIUTlss/Vx2phlYwjw8j1CAlfAiwQiJpiy7o1VHnsG5FISkoJu7Q/2YmmaV+i0ei7v38L2CBguSi5AAAAAElFTkSuQmCC);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 .15em;
|
||||
margin-left: -2em;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Monaco,"Courier New","DejaVu Sans Mono","Bitstream Vera Sans Mono",monospace;
|
||||
-webkit-border-radius: 1px;
|
||||
-moz-border-radius: 1px;
|
||||
border-radius: 1px;
|
||||
-moz-background-clip: padding;
|
||||
-webkit-background-clip: padding-box;
|
||||
background-clip: padding-box;
|
||||
padding: 0px 3px;
|
||||
display: inline-block;
|
||||
color: #52595d;
|
||||
border: 1px solid #ccc;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
656
bundle/git_vimwiki/autoload/vimwiki/tbl.vim
Normal file
656
bundle/git_vimwiki/autoload/vimwiki/tbl.vim
Normal file
@@ -0,0 +1,656 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Tables
|
||||
" | Easily | manageable | text | tables | ! |
|
||||
" |--------|------------|-------|--------|---------|
|
||||
" | Have | fun! | Drink | tea | Period. |
|
||||
"
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
|
||||
" Load only once {{{
|
||||
if exists("g:loaded_vimwiki_tbl_auto") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_tbl_auto = 1
|
||||
"}}}
|
||||
|
||||
let s:textwidth = &tw
|
||||
let s:rxSep = g:vimwiki_rxTableSep
|
||||
|
||||
|
||||
" Misc functions {{{
|
||||
function! s:wide_len(str) "{{{
|
||||
" vim73 has new function that gives correct string width.
|
||||
if exists("*strdisplaywidth")
|
||||
return strdisplaywidth(a:str)
|
||||
endif
|
||||
|
||||
" get str display width in vim ver < 7.2
|
||||
if !g:vimwiki_CJK_length
|
||||
let ret = strlen(substitute(a:str, '.', 'x', 'g'))
|
||||
else
|
||||
let savemodified = &modified
|
||||
let save_cursor = getpos('.')
|
||||
exe "norm! o\<esc>"
|
||||
call setline(line("."), a:str)
|
||||
let ret = virtcol("$") - 1
|
||||
d
|
||||
call setpos('.', save_cursor)
|
||||
let &modified = savemodified
|
||||
endif
|
||||
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 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: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)
|
||||
"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)
|
||||
"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) "{{{
|
||||
let lnum = a:lnum - 1
|
||||
while lnum > 1
|
||||
if !s:is_separator(getline(lnum))
|
||||
break
|
||||
endif
|
||||
let lnum -= 1
|
||||
endwhile
|
||||
|
||||
return (a:lnum-lnum)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:count_separators_down(lnum) "{{{
|
||||
let lnum = a:lnum + 1
|
||||
while lnum < line('$')
|
||||
if !s:is_separator(getline(lnum))
|
||||
break
|
||||
endif
|
||||
let lnum += 1
|
||||
endwhile
|
||||
|
||||
return (lnum-a:lnum)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:create_empty_row(cols) "{{{
|
||||
let row = s:rxSep
|
||||
let cell = " ".s:rxSep
|
||||
|
||||
for c in range(a:cols)
|
||||
let row .= cell
|
||||
endfor
|
||||
|
||||
return row
|
||||
endfunction "}}}
|
||||
|
||||
function! s:create_row_sep(cols) "{{{
|
||||
let row = s:rxSep
|
||||
let cell = "---".s:rxSep
|
||||
|
||||
for c in range(a:cols)
|
||||
let row .= cell
|
||||
endfor
|
||||
|
||||
return row
|
||||
endfunction "}}}
|
||||
|
||||
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) "{{{
|
||||
return len(vimwiki#tbl#get_cells(getline(a:lnum)))
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_indent(lnum) "{{{
|
||||
if !s:is_table(getline(a:lnum))
|
||||
return
|
||||
endif
|
||||
|
||||
let indent = 0
|
||||
|
||||
let lnum = a:lnum - 1
|
||||
while lnum > 1
|
||||
let line = getline(lnum)
|
||||
if !s:is_table(line)
|
||||
let indent = indent(lnum+1)
|
||||
break
|
||||
endif
|
||||
let lnum -= 1
|
||||
endwhile
|
||||
|
||||
return indent
|
||||
endfunction " }}}
|
||||
|
||||
function! s:get_rows(lnum) "{{{
|
||||
if !s:is_table(getline(a:lnum))
|
||||
return
|
||||
endif
|
||||
|
||||
let upper_rows = []
|
||||
let lower_rows = []
|
||||
|
||||
let lnum = a:lnum - 1
|
||||
while lnum >= 1
|
||||
let line = getline(lnum)
|
||||
if s:is_table(line)
|
||||
call add(upper_rows, [lnum, line])
|
||||
else
|
||||
break
|
||||
endif
|
||||
let lnum -= 1
|
||||
endwhile
|
||||
call reverse(upper_rows)
|
||||
|
||||
let lnum = a:lnum
|
||||
while lnum <= line('$')
|
||||
let line = getline(lnum)
|
||||
if s:is_table(line)
|
||||
call add(lower_rows, [lnum, line])
|
||||
else
|
||||
break
|
||||
endif
|
||||
let lnum += 1
|
||||
endwhile
|
||||
|
||||
return upper_rows + lower_rows
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_cell_max_lens(lnum) "{{{
|
||||
let max_lens = {}
|
||||
for [lnum, row] in s:get_rows(a:lnum)
|
||||
if s:is_separator(row)
|
||||
continue
|
||||
endif
|
||||
let cells = vimwiki#tbl#get_cells(row)
|
||||
for idx in range(len(cells))
|
||||
let value = cells[idx]
|
||||
if has_key(max_lens, idx)
|
||||
let max_lens[idx] = max([s:wide_len(value), max_lens[idx]])
|
||||
else
|
||||
let max_lens[idx] = s:wide_len(value)
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
return max_lens
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_aligned_rows(lnum, col1, col2) "{{{
|
||||
let max_lens = s:get_cell_max_lens(a:lnum)
|
||||
let rows = []
|
||||
for [lnum, row] in s:get_rows(a:lnum)
|
||||
if s:is_separator(row)
|
||||
let new_row = s:fmt_sep(max_lens, a:col1, a:col2)
|
||||
else
|
||||
let new_row = s:fmt_row(row, max_lens, a:col1, a:col2)
|
||||
endif
|
||||
call add(rows, [lnum, new_row])
|
||||
endfor
|
||||
return rows
|
||||
endfunction "}}}
|
||||
|
||||
" Number of the current column. Starts from 0.
|
||||
function! s:cur_column() "{{{
|
||||
let line = getline('.')
|
||||
if !s:is_table(line)
|
||||
return -1
|
||||
endif
|
||||
" TODO: do we need conditional: if s:is_separator(line)
|
||||
|
||||
let curs_pos = col('.')
|
||||
let mpos = match(line, s:rxSep, 0)
|
||||
let col = -1
|
||||
while mpos < curs_pos && mpos != -1
|
||||
let mpos = match(line, s:rxSep, mpos+1)
|
||||
if mpos != -1
|
||||
let col += 1
|
||||
endif
|
||||
endwhile
|
||||
return col
|
||||
endfunction "}}}
|
||||
|
||||
" }}}
|
||||
|
||||
" Format functions {{{
|
||||
function! s:fmt_cell(cell, max_len) "{{{
|
||||
let cell = ' '.a:cell.' '
|
||||
|
||||
let diff = a:max_len - s:wide_len(a:cell)
|
||||
if diff == 0 && empty(a:cell)
|
||||
let diff = 1
|
||||
endif
|
||||
|
||||
let cell .= repeat(' ', diff)
|
||||
return cell
|
||||
endfunction "}}}
|
||||
|
||||
function! s:fmt_row(line, max_lens, col1, col2) "{{{
|
||||
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
|
||||
elseif idx == a:col2
|
||||
let idx = a:col1
|
||||
endif
|
||||
let value = cells[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]).s:rxSep
|
||||
let idx += 1
|
||||
endwhile
|
||||
return new_line
|
||||
endfunction "}}}
|
||||
|
||||
function! s:fmt_cell_sep(max_len) "{{{
|
||||
if a:max_len == 0
|
||||
return repeat('-', 3)
|
||||
else
|
||||
return repeat('-', a:max_len+2)
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:fmt_sep(max_lens, col1, col2) "{{{
|
||||
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 new_line .= s:fmt_cell_sep(a:max_lens[idx]).s:rxSep
|
||||
endfor
|
||||
return new_line
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Keyboard functions "{{{
|
||||
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 .= ":call search('\\(".s:rxSep."\\)\\zs', 'c', line('.'))\<CR>"
|
||||
else
|
||||
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>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>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 "}}}
|
||||
|
||||
" 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 .= seps."j0"
|
||||
endif
|
||||
let cmd .= ":call vimwiki#tbl#goto_next_col()\<CR>a"
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
" 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 .= 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 "}}}
|
||||
|
||||
"}}}
|
||||
|
||||
" Global functions {{{
|
||||
function! vimwiki#tbl#kbd_cr() "{{{
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<CR>"
|
||||
endif
|
||||
|
||||
if s:is_separator(getline(lnum+1)) || !s:is_table(getline(lnum+1))
|
||||
let cols = len(vimwiki#tbl#get_cells(getline(lnum)))
|
||||
return s:kbd_create_new_row(cols, 0)
|
||||
else
|
||||
return s:kbd_goto_next_row()
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#kbd_tab() "{{{
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<Tab>"
|
||||
endif
|
||||
|
||||
let last = s:is_last_column(lnum, col('.'))
|
||||
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(is_sep || last)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#kbd_shift_tab() "{{{
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<S-Tab>"
|
||||
endif
|
||||
|
||||
let first = s:is_first_column(lnum, col('.'))
|
||||
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(is_sep || first)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#format(lnum, ...) "{{{
|
||||
let line = getline(a:lnum)
|
||||
if !s:is_table(line)
|
||||
return
|
||||
endif
|
||||
|
||||
if a:0 == 2
|
||||
let col1 = a:1
|
||||
let col2 = a:2
|
||||
else
|
||||
let col1 = 0
|
||||
let col2 = 0
|
||||
endif
|
||||
|
||||
let indent = s:get_indent(a:lnum)
|
||||
|
||||
for [lnum, row] in s:get_aligned_rows(a:lnum, col1, col2)
|
||||
let row = repeat(' ', indent).row
|
||||
call setline(lnum, row)
|
||||
endfor
|
||||
|
||||
let &tw = s:textwidth
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#create(...) "{{{
|
||||
if a:0 > 1
|
||||
let cols = a:1
|
||||
let rows = a:2
|
||||
elseif a:0 == 1
|
||||
let cols = a:1
|
||||
let rows = 2
|
||||
elseif a:0 == 0
|
||||
let cols = 5
|
||||
let rows = 2
|
||||
endif
|
||||
|
||||
if cols < 1
|
||||
let cols = 5
|
||||
endif
|
||||
|
||||
if rows < 1
|
||||
let rows = 2
|
||||
endif
|
||||
|
||||
let lines = []
|
||||
let row = s:create_empty_row(cols)
|
||||
|
||||
call add(lines, row)
|
||||
if rows > 1
|
||||
call add(lines, s:create_row_sep(cols))
|
||||
endif
|
||||
|
||||
for r in range(rows - 1)
|
||||
call add(lines, row)
|
||||
endfor
|
||||
|
||||
call append(line('.'), lines)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#align_or_cmd(cmd) "{{{
|
||||
if s:is_table(getline('.'))
|
||||
call vimwiki#tbl#format(line('.'))
|
||||
else
|
||||
exe 'normal! '.a:cmd
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#reset_tw(lnum) "{{{
|
||||
let line = getline(a:lnum)
|
||||
if !s:is_table(line)
|
||||
return
|
||||
endif
|
||||
|
||||
let s:textwidth = &tw
|
||||
let &tw = 0
|
||||
endfunction "}}}
|
||||
|
||||
" TODO: move_column_left and move_column_right are good candidates to be
|
||||
" refactored.
|
||||
function! vimwiki#tbl#move_column_left() "{{{
|
||||
|
||||
"echomsg "DEBUG move_column_left: "
|
||||
|
||||
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
|
||||
call vimwiki#tbl#format(line('.'), cur_col-1, cur_col)
|
||||
call cursor(line('.'), 1)
|
||||
|
||||
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() "{{{
|
||||
|
||||
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
|
||||
call vimwiki#tbl#format(line('.'), cur_col, cur_col+1)
|
||||
call cursor(line('.'), 1)
|
||||
|
||||
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 "}}}
|
||||
|
||||
"}}}
|
||||
77
bundle/git_vimwiki/autoload/vimwiki/u.vim
Normal file
77
bundle/git_vimwiki/autoload/vimwiki/u.vim
Normal file
@@ -0,0 +1,77 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" Vimwiki autoload plugin file
|
||||
" Utility functions
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
|
||||
function! vimwiki#u#trim(string, ...) "{{{
|
||||
let chars = ''
|
||||
if a:0 > 0
|
||||
let chars = a:1
|
||||
endif
|
||||
let res = substitute(a:string, '^[[:space:]'.chars.']\+', '', '')
|
||||
let res = substitute(res, '[[:space:]'.chars.']\+$', '', '')
|
||||
return res
|
||||
endfunction "}}}
|
||||
|
||||
|
||||
" Builtin cursor doesn't work right with unicode characters.
|
||||
function! vimwiki#u#cursor(lnum, cnum) "{{{
|
||||
exe a:lnum
|
||||
exe 'normal! 0'.a:cnum.'|'
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#u#is_windows() "{{{
|
||||
return has("win32") || has("win64") || has("win95") || has("win16")
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#u#chomp_slash(str) "{{{
|
||||
return substitute(a:str, '[/\\]\+$', '', '')
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#u#time(starttime) "{{{
|
||||
" measure the elapsed time and cut away miliseconds and smaller
|
||||
return matchstr(reltimestr(reltime(a:starttime)),'\d\+\(\.\d\d\)\=')
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#u#path_norm(path) "{{{
|
||||
" /-slashes
|
||||
let path = substitute(a:path, '\', '/', 'g')
|
||||
" treat multiple consecutive slashes as one path separator
|
||||
let path = substitute(path, '/\+', '/', 'g')
|
||||
" ensure that we are not fooled by a symbolic link
|
||||
return resolve(path)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#u#is_link_to_dir(link) "{{{
|
||||
" Check if link is to a directory.
|
||||
" It should be ended with \ or /.
|
||||
if a:link =~ '.\+[/\\]$'
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction " }}}
|
||||
|
||||
function! vimwiki#u#count_first_sym(line) "{{{
|
||||
let first_sym = matchstr(a:line, '\S')
|
||||
return len(matchstr(a:line, first_sym.'\+'))
|
||||
endfunction "}}}
|
||||
|
||||
" return longest common path prefix of 2 given paths.
|
||||
" '~/home/usrname/wiki', '~/home/usrname/wiki/shmiki' => '~/home/usrname/wiki'
|
||||
function! vimwiki#u#path_common_pfx(path1, path2) "{{{
|
||||
let p1 = split(a:path1, '[/\\]', 1)
|
||||
let p2 = split(a:path2, '[/\\]', 1)
|
||||
|
||||
let idx = 0
|
||||
let minlen = min([len(p1), len(p2)])
|
||||
while (idx < minlen) && (p1[idx] ==? p2[idx])
|
||||
let idx = idx + 1
|
||||
endwhile
|
||||
if idx == 0
|
||||
return ''
|
||||
else
|
||||
return join(p1[: idx-1], '/')
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
Reference in New Issue
Block a user