Merge branch 'dev' into path-handling
Conflicts: autoload/vimwiki/base.vim autoload/vimwiki/diary.vim autoload/vimwiki/html.vim autoload/vimwiki/path.vim autoload/vimwiki/tags.vim autoload/vimwiki/u.vim autoload/vimwiki/vars.vim ftplugin/vimwiki.vim plugin/vimwiki.vim
This commit is contained in:
+491
-340
File diff suppressed because it is too large
Load Diff
+82
-65
@@ -1,48 +1,53 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Handle diary notes
|
||||
" Description: Handle diary notes
|
||||
" Home: https://github.com/vimwiki/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) "{{{
|
||||
|
||||
function! s:prefix_zero(num)
|
||||
if a:num < 10
|
||||
return '0'.a:num
|
||||
endif
|
||||
return a:num
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:diary_path(...) "{{{
|
||||
|
||||
function! s:diary_path(...)
|
||||
let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
|
||||
return vimwiki#vars#get_wikilocal('diary_path', idx)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:diary_index(...) "{{{
|
||||
|
||||
function! s:diary_index(...)
|
||||
let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
|
||||
return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).vimwiki#vars#get_wikilocal('ext', idx)
|
||||
endfunction "}}}
|
||||
return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).
|
||||
\ vimwiki#vars#get_wikilocal('ext', idx)
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#diary_date_link(...) "{{{
|
||||
|
||||
function! vimwiki#diary#diary_date_link(...)
|
||||
if a:0
|
||||
return strftime('%Y-%m-%d', a:1)
|
||||
else
|
||||
return strftime('%Y-%m-%d')
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:get_position_links(link) "{{{
|
||||
|
||||
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())
|
||||
let links = map(s:get_diary_files(), 'fnamemodify(v:val, ":t:r")')
|
||||
" include 'today' into links
|
||||
if index(links, vimwiki#diary#diary_date_link()) == -1
|
||||
call add(links, vimwiki#diary#diary_date_link())
|
||||
@@ -51,21 +56,20 @@ function! s:get_position_links(link) "{{{
|
||||
let idx = index(links, a:link)
|
||||
endif
|
||||
return [idx, links]
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
fun! s:get_month_name(month) "{{{
|
||||
|
||||
function! s:get_month_name(month)
|
||||
return vimwiki#vars#get_global('diary_months')[str2nr(a:month)]
|
||||
endfun "}}}
|
||||
endfunction
|
||||
|
||||
" Helpers }}}
|
||||
|
||||
" Diary index stuff {{{
|
||||
fun! s:read_captions(files) "{{{
|
||||
function! s:read_captions(files)
|
||||
let result = {}
|
||||
let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
|
||||
for fl in a:files
|
||||
" remove paths and extensions
|
||||
let fl_key = fnamemodify(fl, ':t:r')
|
||||
let fl_key = substitute(fnamemodify(fl, ':t'), vimwiki#vars#get_wikilocal('ext').'$', '', '')
|
||||
|
||||
if filereadable(fl)
|
||||
for line in readfile(fl, '', s:vimwiki_max_scan_for_caption)
|
||||
@@ -81,9 +85,10 @@ fun! s:read_captions(files) "{{{
|
||||
|
||||
endfor
|
||||
return result
|
||||
endfun "}}}
|
||||
endfunction
|
||||
|
||||
fun! s:get_diary_links() "{{{
|
||||
|
||||
function! s:get_diary_files()
|
||||
let rx = '^\d\{4}-\d\d-\d\d'
|
||||
let s_files = glob(vimwiki#vars#get_wikilocal('diary_path') . '*' . vimwiki#vars#get_wikilocal('ext'))
|
||||
let files = split(s_files, '\n')
|
||||
@@ -92,12 +97,11 @@ fun! s:get_diary_links() "{{{
|
||||
" remove backup files (.wiki~)
|
||||
call filter(files, 'v:val !~# ''.*\~$''')
|
||||
|
||||
let links_with_captions = s:read_captions(files)
|
||||
return files
|
||||
endfunction
|
||||
|
||||
return links_with_captions
|
||||
endfun "}}}
|
||||
|
||||
fun! s:group_links(links) "{{{
|
||||
function! s:group_links(links)
|
||||
let result = {}
|
||||
let p_year = 0
|
||||
let p_month = 0
|
||||
@@ -116,38 +120,45 @@ fun! s:group_links(links) "{{{
|
||||
let p_month = month
|
||||
endfor
|
||||
return result
|
||||
endfun "}}}
|
||||
endfunction
|
||||
|
||||
function! s:sort(lst) "{{{
|
||||
|
||||
function! s:sort(lst)
|
||||
if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc'
|
||||
return reverse(sort(a:lst))
|
||||
else
|
||||
return sort(a:lst)
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:format_diary() "{{{
|
||||
|
||||
function! s:format_diary()
|
||||
let result = []
|
||||
|
||||
let g_files = s:group_links(s:get_diary_links())
|
||||
let links_with_captions = s:read_captions(s:get_diary_files())
|
||||
let g_files = s:group_links(links_with_captions)
|
||||
|
||||
for year in s:sort(keys(g_files))
|
||||
call add(result, '')
|
||||
call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
|
||||
call add(result,
|
||||
\ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
|
||||
|
||||
for month in s:sort(keys(g_files[year]))
|
||||
call add(result, '')
|
||||
call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'), '__Header__', s:get_month_name(month), ''))
|
||||
call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'),
|
||||
\ '__Header__', s:get_month_name(month), ''))
|
||||
|
||||
for [fl, cap] in s:sort(items(g_files[year][month]))
|
||||
if empty(cap)
|
||||
let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate1'), '__LinkUrl__', fl, '')
|
||||
let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
|
||||
\ '__LinkUrl__', fl, '')
|
||||
let entry = substitute(entry, '__LinkDescription__', cap, '')
|
||||
call add(result, repeat(' ', &sw).'* '.entry)
|
||||
call add(result, repeat(' ', vimwiki#lst#get_list_margin()).'* '.entry)
|
||||
else
|
||||
let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate2'), '__LinkUrl__', fl, '')
|
||||
let entry = substitute(vimwiki#vars#get_global('WikiLinkTemplate2'),
|
||||
\ '__LinkUrl__', fl, '')
|
||||
let entry = substitute(entry, '__LinkDescription__', cap, '')
|
||||
call add(result, repeat(' ', &sw).'* '.entry)
|
||||
call add(result, repeat(' ', vimwiki#lst#get_list_margin()).'* '.entry)
|
||||
endif
|
||||
endfor
|
||||
|
||||
@@ -155,11 +166,10 @@ function! s:format_diary() "{{{
|
||||
endfor
|
||||
|
||||
return result
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
" Diary index stuff }}}
|
||||
|
||||
function! vimwiki#diary#make_note(wnum, ...) "{{{
|
||||
function! vimwiki#diary#make_note(wnum, ...)
|
||||
if a:wnum > vimwiki#vars#number_of_wikis()
|
||||
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
|
||||
return
|
||||
@@ -174,10 +184,15 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
|
||||
|
||||
call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('diary_path', idx))
|
||||
|
||||
if a:0 && a:1 == 1
|
||||
let cmd = 'tabedit'
|
||||
else
|
||||
let cmd = 'edit'
|
||||
let cmd = 'edit'
|
||||
if a:0
|
||||
if a:1 == 1
|
||||
let cmd = 'tabedit'
|
||||
elseif a:1 == 2
|
||||
let cmd = 'split'
|
||||
elseif a:1 == 3
|
||||
let cmd = 'vsplit'
|
||||
endif
|
||||
endif
|
||||
if a:0>1
|
||||
let link = 'diary:'.a:2
|
||||
@@ -186,9 +201,10 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
|
||||
endif
|
||||
|
||||
call vimwiki#base#open_link(cmd, link, s:diary_index(idx))
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#goto_diary_index(wnum) "{{{
|
||||
|
||||
function! vimwiki#diary#goto_diary_index(wnum)
|
||||
if a:wnum > vimwiki#vars#number_of_wikis()
|
||||
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
|
||||
return
|
||||
@@ -202,9 +218,10 @@ function! vimwiki#diary#goto_diary_index(wnum) "{{{
|
||||
endif
|
||||
|
||||
call vimwiki#base#edit_file('e', s:diary_index(idx), '')
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#goto_next_day() "{{{
|
||||
|
||||
function! vimwiki#diary#goto_next_day()
|
||||
let link = ''
|
||||
let [idx, links] = s:get_position_links(expand('%:t:r'))
|
||||
|
||||
@@ -222,9 +239,10 @@ function! vimwiki#diary#goto_next_day() "{{{
|
||||
if len(link)
|
||||
call vimwiki#base#open_link(':e ', link)
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#goto_prev_day() "{{{
|
||||
|
||||
function! vimwiki#diary#goto_prev_day()
|
||||
let link = ''
|
||||
let [idx, links] = s:get_position_links(expand('%:t:r'))
|
||||
|
||||
@@ -242,9 +260,10 @@ function! vimwiki#diary#goto_prev_day() "{{{
|
||||
if len(link)
|
||||
call vimwiki#base#open_link(':e ', link)
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#diary#generate_diary_section() "{{{
|
||||
|
||||
function! vimwiki#diary#generate_diary_section()
|
||||
let current_file = vimwiki#path#path_norm(expand("%:p"))
|
||||
let diary_file = vimwiki#path#path_norm(s:diary_index())
|
||||
if vimwiki#path#is_equal(current_file, diary_file)
|
||||
@@ -254,11 +273,11 @@ function! vimwiki#diary#generate_diary_section() "{{{
|
||||
else
|
||||
echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!'
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
" Calendar.vim {{{
|
||||
" Callback function.
|
||||
function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
|
||||
" Callback function for Calendar.vim
|
||||
function! vimwiki#diary#calendar_action(day, month, year, week, dir)
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
|
||||
@@ -278,16 +297,14 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
|
||||
" XXX: Well, +1 is for inconsistent index basing...
|
||||
call vimwiki#diary#make_note(vimwiki#vars#get_bufferlocal('wiki_nr')+1, 0, link)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
" Sign function.
|
||||
function vimwiki#diary#calendar_sign(day, month, year) "{{{
|
||||
|
||||
function vimwiki#diary#calendar_sign(day, month, year)
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
let sfile = vimwiki#vars#get_wikilocal('diary_path') .
|
||||
\ a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
|
||||
return filereadable(expand(sfile))
|
||||
endfunction "}}}
|
||||
|
||||
" Calendar.vim }}}
|
||||
endfunction
|
||||
|
||||
|
||||
+332
-267
File diff suppressed because it is too large
Load Diff
+419
-243
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,17 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Link functions for markdown syntax
|
||||
" Description: Link functions for markdown syntax
|
||||
" Home: https://github.com/vimwiki/vimwiki/
|
||||
|
||||
|
||||
" MISC helper functions {{{
|
||||
function! s:safesubstitute(text, search, replace, mode)
|
||||
" Substitute regexp but do not interpret replace
|
||||
let escaped = escape(a:replace, '\&')
|
||||
return substitute(a:text, a:search, escaped, a:mode)
|
||||
endfunction
|
||||
|
||||
" vimwiki#markdown_base#scan_reflinks
|
||||
function! vimwiki#markdown_base#scan_reflinks() " {{{
|
||||
|
||||
function! vimwiki#markdown_base#scan_reflinks()
|
||||
let mkd_refs = {}
|
||||
" construct list of references using vimgrep
|
||||
try
|
||||
@@ -16,7 +20,7 @@ function! vimwiki#markdown_base#scan_reflinks() " {{{
|
||||
catch /^Vim\%((\a\+)\)\=:E480/ " No Match
|
||||
"Ignore it, and move on to the next file
|
||||
endtry
|
||||
"
|
||||
|
||||
for d in getqflist()
|
||||
let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ')
|
||||
let descr = matchstr(matchline, vimwiki#vars#get_syntaxlocal('rxMkdRefMatchDescr'))
|
||||
@@ -27,12 +31,11 @@ function! vimwiki#markdown_base#scan_reflinks() " {{{
|
||||
endfor
|
||||
call vimwiki#vars#set_bufferlocal('markdown_refs', mkd_refs)
|
||||
return mkd_refs
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" vimwiki#markdown_base#open_reflink
|
||||
" try markdown reference links
|
||||
function! vimwiki#markdown_base#open_reflink(link) " {{{
|
||||
function! vimwiki#markdown_base#open_reflink(link)
|
||||
" echom "vimwiki#markdown_base#open_reflink"
|
||||
let link = a:link
|
||||
let mkd_refs = vimwiki#vars#get_bufferlocal('markdown_refs')
|
||||
@@ -43,70 +46,10 @@ function! vimwiki#markdown_base#open_reflink(link) " {{{
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction " }}}
|
||||
" }}}
|
||||
endfunction
|
||||
|
||||
" WIKI link following functions {{{
|
||||
|
||||
" vimwiki#markdown_base#follow_link
|
||||
function! vimwiki#markdown_base#follow_link(split, ...) "{{{ Parse link at cursor and pass
|
||||
" to VimwikiLinkHandler, or failing that, the default open_link handler
|
||||
" echom "markdown_base#follow_link"
|
||||
|
||||
if 0
|
||||
" Syntax-specific links
|
||||
" XXX: @Stuart: do we still need it?
|
||||
" XXX: @Maxim: most likely! I am still working on a seemless way to
|
||||
" integrate regexp's without complicating syntax/vimwiki.vim
|
||||
else
|
||||
if a:split ==# "split"
|
||||
let cmd = ":split "
|
||||
elseif a:split ==# "vsplit"
|
||||
let cmd = ":vsplit "
|
||||
elseif a:split ==# "tabnew"
|
||||
let cmd = ":tabnew "
|
||||
else
|
||||
let cmd = ":e "
|
||||
endif
|
||||
|
||||
" try WikiLink
|
||||
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')),
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
|
||||
" try WikiIncl
|
||||
if lnk == ""
|
||||
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl')),
|
||||
\ vimwiki#vars#get_global('rxWikiInclMatchUrl'))
|
||||
endif
|
||||
" try Weblink
|
||||
if lnk == ""
|
||||
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink')),
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
|
||||
endif
|
||||
|
||||
if lnk != ""
|
||||
if !VimwikiLinkHandler(lnk)
|
||||
if !vimwiki#markdown_base#open_reflink(lnk)
|
||||
" remove the extension from the filename if exists
|
||||
let lnk = substitute(lnk, vimwiki#vars#get_wikilocal('ext').'$', '', '')
|
||||
call vimwiki#base#open_link(cmd, lnk)
|
||||
endif
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
if a:0 > 0
|
||||
execute "normal! ".a:1
|
||||
else
|
||||
call vimwiki#base#normalize_link(0)
|
||||
endif
|
||||
endif
|
||||
|
||||
endfunction " }}}
|
||||
|
||||
" LINK functions {{{
|
||||
|
||||
" s:normalize_link_syntax_n
|
||||
function! s:normalize_link_syntax_n() " {{{
|
||||
function! s:normalize_link_syntax_n()
|
||||
let lnum = line('.')
|
||||
|
||||
" try WikiIncl
|
||||
@@ -120,27 +63,30 @@ function! s:normalize_link_syntax_n() " {{{
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'))
|
||||
if !empty(lnk)
|
||||
let sub = vimwiki#base#normalize_link_helper(lnk,
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'),
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
|
||||
\ vimwiki#vars#get_syntaxlocal('WikiLink1Template2'))
|
||||
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'), sub)
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
" try WikiLink1: replace with WikiLink0
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1'))
|
||||
if !empty(lnk)
|
||||
let sub = vimwiki#base#normalize_link_helper(lnk,
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'),
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
|
||||
\ vimwiki#vars#get_global('WikiLinkTemplate2'))
|
||||
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), sub)
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
" try Weblink
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'))
|
||||
if !empty(lnk)
|
||||
let sub = vimwiki#base#normalize_link_helper(lnk,
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'), vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr'),
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'),
|
||||
\ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr'),
|
||||
\ vimwiki#vars#get_syntaxlocal('Weblink1Template'))
|
||||
call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'), sub)
|
||||
return
|
||||
@@ -158,10 +104,10 @@ function! s:normalize_link_syntax_n() " {{{
|
||||
return
|
||||
endif
|
||||
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
" s:normalize_link_syntax_v
|
||||
function! s:normalize_link_syntax_v() " {{{
|
||||
|
||||
function! s:normalize_link_syntax_v()
|
||||
let lnum = line('.')
|
||||
let sel_save = &selection
|
||||
let &selection = "old"
|
||||
@@ -172,38 +118,33 @@ function! s:normalize_link_syntax_v() " {{{
|
||||
try
|
||||
norm! gvy
|
||||
let visual_selection = @"
|
||||
let link = substitute(vimwiki#vars#get_syntaxlocal('Weblink1Template'), '__LinkUrl__', '\='."'".visual_selection."'", '')
|
||||
let link = substitute(link, '__LinkDescription__', '\='."'".visual_selection."'", '')
|
||||
let link = s:safesubstitute(vimwiki#vars#get_syntaxlocal('Weblink1Template'),
|
||||
\ '__LinkUrl__', visual_selection, '')
|
||||
let link = s:safesubstitute(link, '__LinkDescription__', visual_selection, '')
|
||||
|
||||
call setreg('"', link, 'v')
|
||||
call setreg('"', substitute(link, '\n', '', ''), visualmode())
|
||||
|
||||
" paste result
|
||||
norm! `>pgvd
|
||||
norm! `>""pgvd
|
||||
|
||||
finally
|
||||
call setreg('"', rv, rt)
|
||||
let &selection = sel_save
|
||||
endtry
|
||||
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
" vimwiki#base#normalize_link
|
||||
function! vimwiki#markdown_base#normalize_link(is_visual_mode) "{{{
|
||||
|
||||
function! vimwiki#markdown_base#normalize_link(is_visual_mode)
|
||||
if 0
|
||||
" Syntax-specific links
|
||||
else
|
||||
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
|
||||
elseif line("'<") == line("'>")
|
||||
" action undefined for multi-line visual mode selections
|
||||
call s:normalize_link_syntax_v()
|
||||
endif
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
" }}}
|
||||
|
||||
" -------------------------------------------------------------------------
|
||||
" Load syntax-specific Wiki functionality
|
||||
" -------------------------------------------------------------------------
|
||||
endfunction
|
||||
|
||||
|
||||
+41
-28
@@ -1,15 +1,15 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Path manipulation functions
|
||||
" Description: Path manipulation functions
|
||||
" Home: https://github.com/vimwiki/vimwiki/
|
||||
|
||||
|
||||
function! vimwiki#path#chomp_slash(str) "{{{
|
||||
function! vimwiki#path#chomp_slash(str)
|
||||
return substitute(a:str, '[/\\]\+$', '', '')
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Define path-compare function, either case-sensitive or not, depending on OS.
|
||||
"{{{ " function! vimwiki#path#is_equal(p1, p2)
|
||||
if vimwiki#u#is_windows()
|
||||
function! vimwiki#path#is_equal(p1, p2)
|
||||
return a:p1 ==? a:p2
|
||||
@@ -18,10 +18,11 @@ else
|
||||
function! vimwiki#path#is_equal(p1, p2)
|
||||
return a:p1 ==# a:p2
|
||||
endfunction
|
||||
endif "}}}
|
||||
endif
|
||||
|
||||
|
||||
" collapse sections like /a/b/../c to /a/c
|
||||
function! vimwiki#path#normalize(path) "{{{
|
||||
function! vimwiki#path#normalize(path)
|
||||
let path = a:path
|
||||
while 1
|
||||
let result = substitute(path, '/[^/]\+/\.\.', '', '')
|
||||
@@ -31,9 +32,10 @@ function! vimwiki#path#normalize(path) "{{{
|
||||
let path = result
|
||||
endwhile
|
||||
return result
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#path#path_norm(path) "{{{
|
||||
|
||||
function! vimwiki#path#path_norm(path)
|
||||
" /-slashes
|
||||
if a:path !~# '^scp:'
|
||||
let path = substitute(a:path, '\', '/', 'g')
|
||||
@@ -44,21 +46,24 @@ function! vimwiki#path#path_norm(path) "{{{
|
||||
else
|
||||
return a:path
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#path#is_link_to_dir(link) "{{{
|
||||
|
||||
function! vimwiki#path#is_link_to_dir(link)
|
||||
" Check if link is to a directory.
|
||||
" It should be ended with \ or /.
|
||||
return a:link =~# '\m[/\\]$'
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#path#abs_path_of_link(link) "{{{
|
||||
|
||||
function! vimwiki#path#abs_path_of_link(link)
|
||||
return vimwiki#path#normalize(expand("%:p:h").'/'.a:link)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" return longest common path prefix of 2 given paths.
|
||||
" '~/home/usrname/wiki', '~/home/usrname/wiki/shmiki' => '~/home/usrname/wiki'
|
||||
function! vimwiki#path#path_common_pfx(path1, path2) "{{{
|
||||
function! vimwiki#path#path_common_pfx(path1, path2)
|
||||
let p1 = split(a:path1, '[/\\]', 1)
|
||||
let p2 = split(a:path2, '[/\\]', 1)
|
||||
|
||||
@@ -72,19 +77,26 @@ function! vimwiki#path#path_common_pfx(path1, path2) "{{{
|
||||
else
|
||||
return join(p1[: idx-1], '/')
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#path#wikify_path(path) "{{{
|
||||
let result = resolve(expand(a:path, ':p'))
|
||||
|
||||
function! vimwiki#path#wikify_path(path)
|
||||
let result = resolve(fnamemodify(a:path, ':p'))
|
||||
if vimwiki#u#is_windows()
|
||||
let result = substitute(result, '\\', '/', 'g')
|
||||
endif
|
||||
let result = vimwiki#path#chomp_slash(result)
|
||||
return result
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#path#current_wiki_file()
|
||||
return vimwiki#path#wikify_path(expand('%:p'))
|
||||
endfunction
|
||||
|
||||
|
||||
" Returns: the relative path from a:dir to a:file
|
||||
function! vimwiki#path#relpath(dir, file) "{{{
|
||||
function! vimwiki#path#relpath(dir, file)
|
||||
let result = []
|
||||
let dir = split(a:dir, '/')
|
||||
let file = split(a:file, '/')
|
||||
@@ -106,12 +118,13 @@ function! vimwiki#path#relpath(dir, file) "{{{
|
||||
let result_path .= '/'
|
||||
endif
|
||||
return result_path
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" If the optional argument provided and nonzero,
|
||||
" it will ask before creating a directory
|
||||
" it will ask before creating a directory
|
||||
" Returns: 1 iff directory exists or successfully created
|
||||
function! vimwiki#path#mkdir(dir_obj, ...) "{{{
|
||||
function! vimwiki#path#mkdir(dir_obj, ...)
|
||||
|
||||
if a:dir_obj.protocoll ==# 'scp'
|
||||
" we can not do much, so let's pretend everything is ok
|
||||
@@ -130,23 +143,23 @@ function! vimwiki#path#mkdir(dir_obj, ...) "{{{
|
||||
let path = iconv(path, &enc, vimwiki#vars#get_global('w32_dir_enc'))
|
||||
endif
|
||||
|
||||
if a:0 && a:1 && input("Vimwiki: Make new directory: "
|
||||
\ .path."\n [y]es/[N]o? ") !~? '^y'
|
||||
if a:0 && a:1 && input("Vimwiki: Make new directory: ".path."\n [y]es/[N]o? ") !~? '^y'
|
||||
return 0
|
||||
endif
|
||||
|
||||
call mkdir(path, "p")
|
||||
return 1
|
||||
endif
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#path#is_absolute(path) "{{{
|
||||
|
||||
function! vimwiki#path#is_absolute(path)
|
||||
if vimwiki#u#is_windows()
|
||||
return a:path =~? '\m^\a:'
|
||||
else
|
||||
return a:path =~# '\m^/\|\~/'
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Combine a directory and a file into one path, doesn't generate duplicate
|
||||
|
||||
@@ -27,6 +27,13 @@ del {text-decoration: line-through; color: #777777;}
|
||||
.tag {background-color: #eeeeee; font-family: monospace; padding: 2px;}
|
||||
|
||||
/* classes for items of todo lists */
|
||||
.rejected {
|
||||
/* list-style: none; */
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAMAAAAMCGV4AAAACXBIWXMAAADFAAAAxQEdzbqoAAAAB3RJTUUH4QgEFhAtuWgv9wAAAPZQTFRFmpqam5iYnJaWnJeXnpSUn5OTopCQpoqKpouLp4iIqIiIrYCAt3V1vW1tv2xsmZmZmpeXnpKS/x4e/x8f/yAg/yIi/yQk/yUl/yYm/ygo/ykp/yws/zAw/zIy/zMz/zQ0/zU1/zY2/zw8/0BA/0ZG/0pK/1FR/1JS/1NT/1RU/1VV/1ZW/1dX/1pa/15e/19f/2Zm/2lp/21t/25u/3R0/3p6/4CA/4GB/4SE/4iI/46O/4+P/52d/6am/6ur/66u/7Oz/7S0/7e3/87O/9fX/9zc/93d/+Dg/+vr/+3t/+/v//Dw//Ly//X1//f3//n5//z8////gzaKowAAAA90Uk5T/Pz8/Pz8/Pz8/Pz8/f39ppQKWQAAAAFiS0dEEnu8bAAAAACuSURBVAhbPY9ZF4FQFEZPSKbIMmWep4gMGTKLkIv6/3/GPbfF97b3w17rA0kQOPgvAeHW6uJ6+5h7HqLdwowgOzejXRXBdx6UdSru216xuOMBHHNU0clTzeSUA6EhF8V8kqroluMiU6HKcuf4phGPr1o2q9kYZWwNq1qfRRmTaXpqsyjj17KkWCxKBUBgXWueHIyiAIg18gsse4KHkLF5IKIY10WQgv7fOy4ST34BRiopZ8WLNrgAAAAASUVORK5CYII=);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 .2em;
|
||||
padding-left: 1.5em;
|
||||
}
|
||||
.done0 {
|
||||
/* list-style: none; */
|
||||
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAA7SURBVCiR7dMxEgAgCANBI3yVRzF5KxNbW6wsuH7LQ2YKQK1mkswBVERYF5Os3UV3gwd/jF2SkXy66gAZkxS6BniubAAAAABJRU5ErkJggg==);
|
||||
|
||||
+46
-44
@@ -1,9 +1,11 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
|
||||
|
||||
let s:TAGS_METADATA_FILE_NAME = '.tags'
|
||||
|
||||
|
||||
|
||||
" Tags metadata in-memory format:
|
||||
" metadata := { 'pagename': [entries, ...] }
|
||||
" entry := { 'tagname':..., 'lineno':..., 'link':... }
|
||||
@@ -19,12 +21,13 @@ let s:TAGS_METADATA_FILE_NAME = '.tags'
|
||||
" an optional field, "vimwiki:". In this field, we encode tab-separated values
|
||||
" of missing parameters -- "pagename" and "link".
|
||||
|
||||
" vimwiki#tags#update_tags
|
||||
|
||||
|
||||
" Update tags metadata.
|
||||
" a:full_rebuild == 1: re-scan entire wiki
|
||||
" a:full_rebuild == 0: only re-scan current page
|
||||
" a:all_files == '': only if the file is newer than .tags
|
||||
function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{
|
||||
function! vimwiki#tags#update_tags(full_rebuild, all_files)
|
||||
let all_files = a:all_files != ''
|
||||
if !a:full_rebuild
|
||||
" Updating for one page (current)
|
||||
@@ -54,7 +57,8 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{
|
||||
endfor
|
||||
call s:write_tags_metadata(metadata)
|
||||
endif
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:page_name(file_obj)
|
||||
let wiki_base_dir = vimwiki#vars#get_wikilocal('path')
|
||||
@@ -62,10 +66,9 @@ function! s:page_name(file_obj)
|
||||
return vimwiki#path#to_string(segment)
|
||||
endfunction
|
||||
|
||||
" s:scan_tags
|
||||
" Scans the list of text lines (argument) and produces tags metadata as a
|
||||
" list of tag entries.
|
||||
function! s:scan_tags(lines, page_name) "{{{
|
||||
|
||||
" Scans the list of text lines (argument) and produces tags metadata as a list of tag entries.
|
||||
function! s:scan_tags(lines, page_name)
|
||||
|
||||
let entries = []
|
||||
|
||||
@@ -140,17 +143,18 @@ function! s:scan_tags(lines, page_name) "{{{
|
||||
|
||||
endfor " loop over lines
|
||||
return entries
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Returns tags metadata file path
|
||||
function! vimwiki#tags#metadata_file_path() abort
|
||||
return vimwiki#path#join(vimwiki#vars#get_wikilocal('path'),
|
||||
\ vimwiki#path#file_segment(s:TAGS_METADATA_FILE_NAME))
|
||||
endfunction
|
||||
|
||||
" vimwiki#tags#metadata_file_path
|
||||
" Returns tags metadata file path object
|
||||
function! vimwiki#tags#metadata_file_path() abort "{{{
|
||||
return vimwiki#path#join(vimwiki#vars#get_wikilocal('path'), vimwiki#path#file_segment(s:TAGS_METADATA_FILE_NAME))
|
||||
endfunction " }}}
|
||||
|
||||
" s:load_tags_metadata
|
||||
" Loads tags metadata from file, returns a dictionary
|
||||
function! s:load_tags_metadata() abort "{{{
|
||||
function! s:load_tags_metadata() abort
|
||||
let metadata_path = vimwiki#tags#metadata_file_path()
|
||||
if !filereadable(metadata_path)
|
||||
return {}
|
||||
@@ -197,29 +201,29 @@ function! s:load_tags_metadata() abort "{{{
|
||||
endif
|
||||
endfor
|
||||
return metadata
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
" s:remove_page_from_tags
|
||||
" Removes all entries for given page from metadata in-place. Returns updated
|
||||
" metadata (just in case).
|
||||
function! s:remove_page_from_tags(metadata, page_name) "{{{
|
||||
function! s:remove_page_from_tags(metadata, page_name)
|
||||
if has_key(a:metadata, a:page_name)
|
||||
call remove(a:metadata, a:page_name)
|
||||
return a:metadata
|
||||
else
|
||||
return a:metadata
|
||||
endif
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
" s:merge_tags
|
||||
" Merges metadata of one file into a:metadata
|
||||
function! s:merge_tags(metadata, pagename, file_metadata) "{{{
|
||||
function! s:merge_tags(metadata, pagename, file_metadata)
|
||||
let metadata = a:metadata
|
||||
let metadata[a:pagename] = a:file_metadata
|
||||
return metadata
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
" s:tags_entry_cmp
|
||||
" Compares two actual lines from tags file. Return value is in strcmp style.
|
||||
" See help on sort() -- that's what this function is going to be used for.
|
||||
" See also s:write_tags_metadata below -- that's where we compose these tags
|
||||
@@ -229,7 +233,7 @@ endfunction " }}}
|
||||
" numbers as strings, not integers, and so, for example, tag at line 14
|
||||
" preceeds the same tag on the same page at line 9. (Because string "14" is
|
||||
" alphabetically 'less than' string "9".)
|
||||
function! s:tags_entry_cmp(i1, i2) "{{{
|
||||
function! s:tags_entry_cmp(i1, i2)
|
||||
let items = []
|
||||
for orig_item in [a:i1, a:i2]
|
||||
let fields = split(orig_item, "\t")
|
||||
@@ -249,11 +253,11 @@ function! s:tags_entry_cmp(i1, i2) "{{{
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
" s:write_tags_metadata
|
||||
" Saves metadata object into a file. Throws exceptions in case of problems.
|
||||
function! s:write_tags_metadata(metadata) "{{{
|
||||
function! s:write_tags_metadata(metadata)
|
||||
let metadata_path = vimwiki#tags#metadata_file_path()
|
||||
let tags = []
|
||||
for pagename in keys(a:metadata)
|
||||
@@ -275,11 +279,11 @@ function! s:write_tags_metadata(metadata) "{{{
|
||||
call sort(tags, "s:tags_entry_cmp")
|
||||
call insert(tags, "!_TAG_FILE_SORTED\t1\t")
|
||||
call writefile(tags, metadata_path)
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
" vimwiki#tags#get_tags
|
||||
" Returns list of unique tags found in the .tags file
|
||||
function! vimwiki#tags#get_tags() "{{{
|
||||
function! vimwiki#tags#get_tags()
|
||||
let metadata = s:load_tags_metadata()
|
||||
let tags = {}
|
||||
for entries in values(metadata)
|
||||
@@ -288,13 +292,13 @@ function! vimwiki#tags#get_tags() "{{{
|
||||
endfor
|
||||
endfor
|
||||
return keys(tags)
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
" vimwiki#tags#generate_tags
|
||||
" Similar to vimwiki#base#generate_links. In the current buffer, appends
|
||||
" tags and references to all their instances. If no arguments (tags) are
|
||||
" specified, outputs all tags.
|
||||
function! vimwiki#tags#generate_tags(...) abort "{{{
|
||||
function! vimwiki#tags#generate_tags(...) abort
|
||||
let need_all_tags = (a:0 == 0)
|
||||
let specific_tags = a:000
|
||||
|
||||
@@ -313,8 +317,7 @@ function! vimwiki#tags#generate_tags(...) abort "{{{
|
||||
endfor
|
||||
|
||||
let lines = []
|
||||
let bullet = repeat(' ', vimwiki#lst#get_list_margin()).
|
||||
\ vimwiki#lst#default_symbol().' '
|
||||
let bullet = repeat(' ', vimwiki#lst#get_list_margin()).vimwiki#lst#default_symbol().' '
|
||||
for tagname in sort(keys(tags_entries))
|
||||
if need_all_tags || index(specific_tags, tagname) != -1
|
||||
call extend(lines, [
|
||||
@@ -322,8 +325,8 @@ function! vimwiki#tags#generate_tags(...) abort "{{{
|
||||
\ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', tagname, ''),
|
||||
\ '' ])
|
||||
for taglink in sort(tags_entries[tagname])
|
||||
call add(lines, bullet .
|
||||
\ substitute(vimwiki#vars#get_global('WikiLinkTemplate1'), '__LinkUrl__', taglink, ''))
|
||||
call add(lines, bullet . substitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
|
||||
\ '__LinkUrl__', taglink, ''))
|
||||
endfor
|
||||
endif
|
||||
endfor
|
||||
@@ -332,15 +335,14 @@ function! vimwiki#tags#generate_tags(...) abort "{{{
|
||||
\ .vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
|
||||
\ .vimwiki#vars#get_syntaxlocal('rxWikiLink').'$\)'
|
||||
|
||||
call vimwiki#base#update_listing_in_buffer(lines, 'Generated Tags', links_rx,
|
||||
\ line('$')+1, 1)
|
||||
endfunction " }}}
|
||||
call vimwiki#base#update_listing_in_buffer(lines, 'Generated Tags', links_rx, line('$')+1, 1)
|
||||
endfunction
|
||||
|
||||
" vimwiki#tags#complete_tags
|
||||
function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort " {{{
|
||||
|
||||
function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort
|
||||
" We can safely ignore args if we use -custom=complete option, Vim engine
|
||||
" will do the job of filtering.
|
||||
let taglist = vimwiki#tags#get_tags()
|
||||
return join(taglist, "\n")
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
|
||||
+149
-119
@@ -1,28 +1,29 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Tables
|
||||
" Description: Tables
|
||||
" | Easily | manageable | text | tables | ! |
|
||||
" |--------|------------|-------|--------|---------|
|
||||
" | Have | fun! | Drink | tea | Period. |
|
||||
"
|
||||
" Home: https://github.com/vimwiki/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
|
||||
|
||||
|
||||
" Misc functions {{{
|
||||
function! s:rxSep() "{{{
|
||||
function! s:rxSep()
|
||||
return vimwiki#vars#get_syntaxlocal('rxTableSep')
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:wide_len(str) "{{{
|
||||
|
||||
function! s:wide_len(str)
|
||||
" vim73 has new function that gives correct string width.
|
||||
if exists("*strdisplaywidth")
|
||||
return strdisplaywidth(a:str)
|
||||
@@ -42,42 +43,49 @@ function! s:wide_len(str) "{{{
|
||||
let &modified = savemodified
|
||||
endif
|
||||
return ret
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:cell_splitter() "{{{
|
||||
|
||||
function! s:cell_splitter()
|
||||
return '\s*'.s:rxSep().'\s*'
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:sep_splitter() "{{{
|
||||
|
||||
function! s:sep_splitter()
|
||||
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 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 "}}}
|
||||
endfunction
|
||||
|
||||
function! s:is_separator_tail(line) "{{{
|
||||
|
||||
function! s:is_separator_tail(line)
|
||||
return a:line =~# '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$'
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:is_last_column(lnum, cnum) "{{{
|
||||
|
||||
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 "}}}
|
||||
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)
|
||||
"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 "}}}
|
||||
return line =~# '^\s*$' ||
|
||||
\ (line =~# '^\s*'.s:rxSep() && line !~# '^\s*'.s:rxSep().'.*'.s:rxSep())
|
||||
endfunction
|
||||
|
||||
function! s:count_separators_up(lnum) "{{{
|
||||
|
||||
function! s:count_separators_up(lnum)
|
||||
let lnum = a:lnum - 1
|
||||
while lnum > 1
|
||||
if !s:is_separator(getline(lnum))
|
||||
@@ -87,9 +95,10 @@ function! s:count_separators_up(lnum) "{{{
|
||||
endwhile
|
||||
|
||||
return (a:lnum-lnum)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:count_separators_down(lnum) "{{{
|
||||
|
||||
function! s:count_separators_down(lnum)
|
||||
let lnum = a:lnum + 1
|
||||
while lnum < line('$')
|
||||
if !s:is_separator(getline(lnum))
|
||||
@@ -99,9 +108,10 @@ function! s:count_separators_down(lnum) "{{{
|
||||
endwhile
|
||||
|
||||
return (lnum-a:lnum)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:create_empty_row(cols) "{{{
|
||||
|
||||
function! s:create_empty_row(cols)
|
||||
let row = s:rxSep()
|
||||
let cell = " ".s:rxSep()
|
||||
|
||||
@@ -110,9 +120,10 @@ function! s:create_empty_row(cols) "{{{
|
||||
endfor
|
||||
|
||||
return row
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:create_row_sep(cols) "{{{
|
||||
|
||||
function! s:create_row_sep(cols)
|
||||
let row = s:rxSep()
|
||||
let cell = "---".s:rxSep()
|
||||
|
||||
@@ -121,9 +132,10 @@ function! s:create_row_sep(cols) "{{{
|
||||
endfor
|
||||
|
||||
return row
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#tbl#get_cells(line) "{{{
|
||||
|
||||
function! vimwiki#tbl#get_cells(line)
|
||||
let result = []
|
||||
let cell = ''
|
||||
let quote = ''
|
||||
@@ -174,13 +186,15 @@ function! vimwiki#tbl#get_cells(line) "{{{
|
||||
call add(result, vimwiki#u#trim(cell.quote, '|'))
|
||||
endif
|
||||
return result
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:col_count(lnum) "{{{
|
||||
|
||||
function! s:col_count(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))
|
||||
return
|
||||
endif
|
||||
@@ -198,9 +212,10 @@ function! s:get_indent(lnum) "{{{
|
||||
endwhile
|
||||
|
||||
return indent
|
||||
endfunction " }}}
|
||||
endfunction
|
||||
|
||||
function! s:get_rows(lnum) "{{{
|
||||
|
||||
function! s:get_rows(lnum)
|
||||
if !s:is_table(getline(a:lnum))
|
||||
return
|
||||
endif
|
||||
@@ -232,9 +247,10 @@ function! s:get_rows(lnum) "{{{
|
||||
endwhile
|
||||
|
||||
return upper_rows + lower_rows
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:get_cell_max_lens(lnum, ...) "{{{
|
||||
|
||||
function! s:get_cell_max_lens(lnum, ...)
|
||||
let max_lens = {}
|
||||
for [lnum, row] in s:get_rows(a:lnum)
|
||||
if s:is_separator(row)
|
||||
@@ -251,9 +267,10 @@ function! s:get_cell_max_lens(lnum, ...) "{{{
|
||||
endfor
|
||||
endfor
|
||||
return max_lens
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:get_aligned_rows(lnum, col1, col2) "{{{
|
||||
|
||||
function! s:get_aligned_rows(lnum, col1, col2)
|
||||
let rows = s:get_rows(a:lnum)
|
||||
let startlnum = rows[0][0]
|
||||
let cells = []
|
||||
@@ -271,10 +288,11 @@ function! s:get_aligned_rows(lnum, col1, col2) "{{{
|
||||
call add(result, [lnum, new_row])
|
||||
endfor
|
||||
return result
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Number of the current column. Starts from 0.
|
||||
function! s:cur_column() "{{{
|
||||
function! s:cur_column()
|
||||
let line = getline('.')
|
||||
if !s:is_table(line)
|
||||
return -1
|
||||
@@ -291,12 +309,10 @@ function! s:cur_column() "{{{
|
||||
endif
|
||||
endwhile
|
||||
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 diff = a:max_len - s:wide_len(a:cell)
|
||||
@@ -306,9 +322,10 @@ function! s:fmt_cell(cell, max_len) "{{{
|
||||
|
||||
let cell .= repeat(' ', diff)
|
||||
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()
|
||||
for idx in range(len(a:cells))
|
||||
if idx == a:col1
|
||||
@@ -326,17 +343,19 @@ function! s:fmt_row(cells, max_lens, col1, col2) "{{{
|
||||
let idx += 1
|
||||
endwhile
|
||||
return new_line
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:fmt_cell_sep(max_len) "{{{
|
||||
|
||||
function! s:fmt_cell_sep(max_len)
|
||||
if a:max_len == 0
|
||||
return repeat('-', 3)
|
||||
else
|
||||
return repeat('-', a:max_len+2)
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:fmt_sep(max_lens, col1, col2) "{{{
|
||||
|
||||
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
|
||||
@@ -347,11 +366,10 @@ function! s:fmt_sep(max_lens, col1, col2) "{{{
|
||||
let new_line .= s:fmt_cell_sep(a:max_lens[idx]).s:rxSep()
|
||||
endfor
|
||||
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>:call vimwiki#tbl#format(line('.'))\<CR>"
|
||||
let cmd .= "\<ESC>0"
|
||||
@@ -364,26 +382,29 @@ function! s:kbd_create_new_row(cols, goto_first) "{{{
|
||||
let cmd .= "a"
|
||||
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! s:kbd_goto_next_row() "{{{
|
||||
|
||||
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 "}}}
|
||||
endfunction
|
||||
|
||||
function! s:kbd_goto_prev_row() "{{{
|
||||
|
||||
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 "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Used in s:kbd_goto_next_col
|
||||
function! vimwiki#tbl#goto_next_col() "{{{
|
||||
function! vimwiki#tbl#goto_next_col()
|
||||
let curcol = virtcol('.')
|
||||
let lnum = line('.')
|
||||
let newcol = s:get_indent(lnum)
|
||||
@@ -396,9 +417,10 @@ function! vimwiki#tbl#goto_next_col() "{{{
|
||||
endfor
|
||||
let newcol += 2 " +2 == 1 separator + 1 space |<space
|
||||
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>"
|
||||
if a:jumpdown
|
||||
let seps = s:count_separators_down(line('.'))
|
||||
@@ -406,10 +428,11 @@ function! s:kbd_goto_next_col(jumpdown) "{{{
|
||||
endif
|
||||
let cmd .= ":call vimwiki#tbl#goto_next_col()\<CR>a"
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Used in s:kbd_goto_prev_col
|
||||
function! vimwiki#tbl#goto_prev_col() "{{{
|
||||
function! vimwiki#tbl#goto_prev_col()
|
||||
let curcol = virtcol('.')
|
||||
let lnum = line('.')
|
||||
let newcol = s:get_indent(lnum)
|
||||
@@ -428,9 +451,10 @@ function! vimwiki#tbl#goto_prev_col() "{{{
|
||||
endfor
|
||||
let newcol += 2 " +2 == 1 separator + 1 space |<space
|
||||
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>"
|
||||
if a:jumpup
|
||||
let seps = s:count_separators_up(line('.'))
|
||||
@@ -442,12 +466,10 @@ function! s:kbd_goto_prev_col(jumpup) "{{{
|
||||
" let cmd .= "a"
|
||||
"echomsg "DEBUG kbd_goto_prev_col> ".cmd
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
"}}}
|
||||
|
||||
" Global functions {{{
|
||||
function! vimwiki#tbl#kbd_cr() "{{{
|
||||
function! vimwiki#tbl#kbd_cr()
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return ""
|
||||
@@ -459,9 +481,10 @@ function! vimwiki#tbl#kbd_cr() "{{{
|
||||
else
|
||||
return s:kbd_goto_next_row()
|
||||
endif
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#tbl#kbd_tab() "{{{
|
||||
|
||||
function! vimwiki#tbl#kbd_tab()
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<Tab>"
|
||||
@@ -475,9 +498,10 @@ function! vimwiki#tbl#kbd_tab() "{{{
|
||||
return s:kbd_create_new_row(cols, 1)
|
||||
endif
|
||||
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('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<S-Tab>"
|
||||
@@ -490,9 +514,10 @@ function! vimwiki#tbl#kbd_shift_tab() "{{{
|
||||
return ""
|
||||
endif
|
||||
return s:kbd_goto_prev_col(is_sep || first)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#tbl#format(lnum, ...) "{{{
|
||||
|
||||
function! vimwiki#tbl#format(lnum, ...)
|
||||
if !(&filetype ==? 'vimwiki')
|
||||
return
|
||||
endif
|
||||
@@ -520,11 +545,12 @@ function! vimwiki#tbl#format(lnum, ...) "{{{
|
||||
let row = indentstring.row
|
||||
call setline(lnum, row)
|
||||
endfor
|
||||
|
||||
let &tw = s:textwidth
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#create(...) "{{{
|
||||
let &tw = s:textwidth
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#tbl#create(...)
|
||||
if a:0 > 1
|
||||
let cols = a:1
|
||||
let rows = a:2
|
||||
@@ -555,19 +581,21 @@ function! vimwiki#tbl#create(...) "{{{
|
||||
for r in range(rows - 1)
|
||||
call add(lines, row)
|
||||
endfor
|
||||
|
||||
call append(line('.'), lines)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#align_or_cmd(cmd) "{{{
|
||||
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 "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#tbl#reset_tw(lnum) "{{{
|
||||
|
||||
function! vimwiki#tbl#reset_tw(lnum)
|
||||
if !(&filetype ==? 'vimwiki')
|
||||
return
|
||||
endif
|
||||
@@ -575,14 +603,14 @@ function! vimwiki#tbl#reset_tw(lnum) "{{{
|
||||
if !s:is_table(line)
|
||||
return
|
||||
endif
|
||||
|
||||
|
||||
let s:textwidth = &tw
|
||||
let &tw = 0
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
" TODO: move_column_left and move_column_right are good candidates to be
|
||||
" refactored.
|
||||
function! vimwiki#tbl#move_column_left() "{{{
|
||||
|
||||
" 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: "
|
||||
|
||||
@@ -598,7 +626,7 @@ function! vimwiki#tbl#move_column_left() "{{{
|
||||
endif
|
||||
|
||||
if cur_col > 0
|
||||
call vimwiki#tbl#format(line('.'), cur_col-1, cur_col)
|
||||
call vimwiki#tbl#format(line('.'), cur_col-1, cur_col)
|
||||
call cursor(line('.'), 1)
|
||||
|
||||
let sep = '\('.s:rxSep().'\).\zs'
|
||||
@@ -608,16 +636,16 @@ function! vimwiki#tbl#move_column_left() "{{{
|
||||
let mpos = match(line, sep, mpos+1)
|
||||
if mpos != -1
|
||||
let col += 1
|
||||
else
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
endif
|
||||
endfunction
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#move_column_right() "{{{
|
||||
function! vimwiki#tbl#move_column_right()
|
||||
|
||||
let line = getline('.')
|
||||
|
||||
@@ -631,7 +659,7 @@ function! vimwiki#tbl#move_column_right() "{{{
|
||||
endif
|
||||
|
||||
if cur_col < s:col_count(line('.'))-1
|
||||
call vimwiki#tbl#format(line('.'), cur_col, cur_col+1)
|
||||
call vimwiki#tbl#format(line('.'), cur_col, cur_col+1)
|
||||
call cursor(line('.'), 1)
|
||||
|
||||
let sep = '\('.s:rxSep().'\).\zs'
|
||||
@@ -641,33 +669,35 @@ function! vimwiki#tbl#move_column_right() "{{{
|
||||
let mpos = match(line, sep, mpos+1)
|
||||
if mpos != -1
|
||||
let col += 1
|
||||
else
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
endif
|
||||
endfunction
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#tbl#get_rows(lnum) "{{{
|
||||
function! vimwiki#tbl#get_rows(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)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#tbl#is_separator(line) "{{{
|
||||
|
||||
function! vimwiki#tbl#is_separator(line)
|
||||
return s:is_separator(a:line)
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#tbl#cell_splitter() "{{{
|
||||
|
||||
function! vimwiki#tbl#cell_splitter()
|
||||
return s:cell_splitter()
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#tbl#sep_splitter() "{{{
|
||||
|
||||
function! vimwiki#tbl#sep_splitter()
|
||||
return s:sep_splitter()
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
"}}}
|
||||
|
||||
+26
-18
@@ -1,9 +1,9 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Utility functions
|
||||
" Description: Utility functions
|
||||
" Home: https://github.com/vimwiki/vimwiki/
|
||||
|
||||
function! vimwiki#u#trim(string, ...) "{{{
|
||||
function! vimwiki#u#trim(string, ...)
|
||||
let chars = ''
|
||||
if a:0 > 0
|
||||
let chars = a:1
|
||||
@@ -11,17 +11,20 @@ function! vimwiki#u#trim(string, ...) "{{{
|
||||
let res = substitute(a:string, '^[[:space:]'.chars.']\+', '', '')
|
||||
let res = substitute(res, '[[:space:]'.chars.']\+$', '', '')
|
||||
return res
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Builtin cursor doesn't work right with unicode characters.
|
||||
function! vimwiki#u#cursor(lnum, cnum) "{{{
|
||||
function! vimwiki#u#cursor(lnum, cnum)
|
||||
exe a:lnum
|
||||
exe 'normal! 0'.a:cnum.'|'
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#u#is_windows() "{{{
|
||||
|
||||
function! vimwiki#u#is_windows()
|
||||
return has("win32") || has("win64") || has("win95") || has("win16")
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#u#is_macos()
|
||||
if has("mac") || has("macunix") || has("gui_mac")
|
||||
@@ -32,27 +35,32 @@ function! vimwiki#u#is_macos()
|
||||
return os == 'Darwin' || os == 'Mac'
|
||||
endfunction
|
||||
|
||||
function! vimwiki#u#count_first_sym(line) "{{{
|
||||
|
||||
function! vimwiki#u#count_first_sym(line)
|
||||
let first_sym = matchstr(a:line, '\S')
|
||||
return len(matchstr(a:line, first_sym.'\+'))
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
function! vimwiki#u#escape(string) "{{{
|
||||
|
||||
function! vimwiki#u#escape(string)
|
||||
return escape(a:string, '~.*[]\^$')
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Load concrete Wiki syntax: sets regexes and templates for headers and links
|
||||
function vimwiki#u#reload_regexes() "{{{
|
||||
function vimwiki#u#reload_regexes()
|
||||
execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'.vim'
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Load syntax-specific functionality
|
||||
function vimwiki#u#reload_regexes_custom() "{{{
|
||||
function vimwiki#u#reload_regexes_custom()
|
||||
execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'_custom.vim'
|
||||
endfunction "}}}
|
||||
endfunction
|
||||
|
||||
|
||||
" Backward compatible version of the built-in function shiftwidth()
|
||||
if exists('*shiftwidth') "{{{
|
||||
if exists('*shiftwidth')
|
||||
func vimwiki#u#sw()
|
||||
return shiftwidth()
|
||||
endfunc
|
||||
@@ -60,7 +68,7 @@ else
|
||||
func vimwiki#u#sw()
|
||||
return &sw
|
||||
endfunc
|
||||
endif "}}}
|
||||
endif
|
||||
|
||||
|
||||
function vimwiki#u#error(message)
|
||||
|
||||
+184
-83
@@ -1,12 +1,33 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: stuff concerning Vimwiki's state
|
||||
" Home: https://github.com/vimwiki/vimwiki/
|
||||
|
||||
|
||||
" copy the user's settings from variables of the form g:vimwiki_<option> into g:vimwiki_global_vars
|
||||
" (or set a default value)
|
||||
|
||||
" ------------------------------------------------------------------------------------------------
|
||||
" This file provides functions to manage the various state variables which are needed during a
|
||||
" Vimwiki session.
|
||||
" They consist of:
|
||||
"
|
||||
" - global variables. These are stored in the dict g:vimwiki_global_vars. They consist mainly of
|
||||
" global user variables and syntax stuff which is the same for every syntax.
|
||||
"
|
||||
" - wiki-local variables. They are stored in g:vimwiki_wikilocal_vars which is a list of
|
||||
" dictionaries. One dict for every registered wiki. The last dictionary contains default values
|
||||
" (used for temporary wikis).
|
||||
"
|
||||
" - syntax variables. Stored in the dict g:vimwiki_syntax_variables which holds all the regexes and
|
||||
" other stuff which is needed for highlighting.
|
||||
"
|
||||
" - buffer-local variables. They are stored as buffer variables directly (b:foo)
|
||||
|
||||
" As a developer, you should, if possible, only use the get_ and set_ functions for these types of
|
||||
" variables, not the underlying dicts!
|
||||
" ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
function! s:populate_global_variables()
|
||||
|
||||
let g:vimwiki_global_vars = {
|
||||
\ 'CJK_length': 0,
|
||||
\ 'auto_chdir': 0,
|
||||
@@ -28,7 +49,9 @@ function! s:populate_global_variables()
|
||||
\ 'html_header_numbering': 0,
|
||||
\ 'html_header_numbering_sym': '',
|
||||
\ 'list_ignore_newline': 1,
|
||||
\ 'text_ignore_newline': 1,
|
||||
\ 'listsyms': ' .oOX',
|
||||
\ 'listsym_rejected': '-',
|
||||
\ 'map_prefix': '<Leader>w',
|
||||
\ 'menu': 'Vimwiki',
|
||||
\ 'table_auto_fmt': 1,
|
||||
@@ -42,6 +65,8 @@ function! s:populate_global_variables()
|
||||
\ 'w32_dir_enc': '',
|
||||
\ }
|
||||
|
||||
" copy the user's settings from variables of the form g:vimwiki_<option> into the dict
|
||||
" g:vimwiki_global_vars (or set a default value)
|
||||
for key in keys(g:vimwiki_global_vars)
|
||||
if exists('g:vimwiki_'.key)
|
||||
let g:vimwiki_global_vars[key] = g:vimwiki_{key}
|
||||
@@ -50,31 +75,31 @@ function! s:populate_global_variables()
|
||||
|
||||
call s:validate_global_settings()
|
||||
|
||||
" non-configurable global variables
|
||||
" non-configurable global variables:
|
||||
|
||||
" Scheme regexes should be defined even if syntax file is not loaded yet cause users should be
|
||||
" Scheme regexes must be defined even if syntax file is not loaded yet cause users should be
|
||||
" able to <leader>w<leader>w without opening any vimwiki file first
|
||||
let g:vimwiki_global_vars['schemes'] = 'wiki\d\+,diary,local'
|
||||
let g:vimwiki_global_vars['web_schemes1'] = 'http,https,file,ftp,gopher,telnet,nntp,ldap,rsync'.
|
||||
let g:vimwiki_global_vars.schemes = 'wiki\d\+,diary,local'
|
||||
let g:vimwiki_global_vars.web_schemes1 = 'http,https,file,ftp,gopher,telnet,nntp,ldap,rsync'.
|
||||
\ ',imap,pop,irc,ircs,cvs,svn,svn+ssh,git,ssh,fish,sftp'
|
||||
let web_schemes2 = 'mailto,news,xmpp,sip,sips,doi,urn,tel'
|
||||
let web_schemes2 = 'mailto,news,xmpp,sip,sips,doi,urn,tel,data'
|
||||
|
||||
let rx_schemes = '\%('.
|
||||
\ join(split(g:vimwiki_global_vars['schemes'], '\s*,\s*'), '\|').'\|'.
|
||||
\ join(split(g:vimwiki_global_vars['web_schemes1'], '\s*,\s*'), '\|').'\|'.
|
||||
\ join(split(g:vimwiki_global_vars.schemes, '\s*,\s*'), '\|').'\|'.
|
||||
\ join(split(g:vimwiki_global_vars.web_schemes1, '\s*,\s*'), '\|').'\|'.
|
||||
\ join(split(web_schemes2, '\s*,\s*'), '\|').
|
||||
\ '\)'
|
||||
|
||||
let g:vimwiki_global_vars['rxSchemeUrl'] = rx_schemes.':.*'
|
||||
let g:vimwiki_global_vars['rxSchemeUrlMatchScheme'] = '\zs'.rx_schemes.'\ze:.*'
|
||||
let g:vimwiki_global_vars['rxSchemeUrlMatchUrl'] = rx_schemes.':\zs.*\ze'
|
||||
let g:vimwiki_global_vars.rxSchemeUrl = rx_schemes.':.*'
|
||||
let g:vimwiki_global_vars.rxSchemeUrlMatchScheme = '\zs'.rx_schemes.'\ze:.*'
|
||||
let g:vimwiki_global_vars.rxSchemeUrlMatchUrl = rx_schemes.':\zs.*\ze'
|
||||
|
||||
" match URL for common protocols; see http://en.wikipedia.org/wiki/URI_scheme
|
||||
" http://tools.ietf.org/html/rfc3986
|
||||
let rxWebProtocols =
|
||||
\ '\%('.
|
||||
\ '\%('.
|
||||
\ '\%('.join(split(g:vimwiki_global_vars['web_schemes1'], '\s*,\s*'), '\|').'\):'.
|
||||
\ '\%('.join(split(g:vimwiki_global_vars.web_schemes1, '\s*,\s*'), '\|').'\):'.
|
||||
\ '\%(//\)'.
|
||||
\ '\)'.
|
||||
\ '\|'.
|
||||
@@ -107,20 +132,20 @@ function! s:populate_global_variables()
|
||||
" non-Ascii characters
|
||||
let g:vimwiki_global_vars.rxWord = '[^[:blank:]!"$%&''()*+,:;<=>?\[\]\\^`{}]\+'
|
||||
|
||||
let g:vimwiki_global_vars.rx_wikilink_prefix1 = g:vimwiki_global_vars.rx_wikilink_prefix . g:vimwiki_global_vars.rxWikiLinkUrl .
|
||||
\ g:vimwiki_global_vars.rx_wikilink_separator
|
||||
let g:vimwiki_global_vars.rx_wikilink_prefix1 = g:vimwiki_global_vars.rx_wikilink_prefix .
|
||||
\ g:vimwiki_global_vars.rxWikiLinkUrl . g:vimwiki_global_vars.rx_wikilink_separator
|
||||
let g:vimwiki_global_vars.rx_wikilink_suffix1 = g:vimwiki_global_vars.rx_wikilink_suffix
|
||||
|
||||
let g:vimwiki_global_vars.rxWikiInclPrefix = '{{'
|
||||
let g:vimwiki_global_vars.rxWikiInclSuffix = '}}'
|
||||
let g:vimwiki_global_vars.rxWikiInclSeparator = '|'
|
||||
" '{{__LinkUrl__}}'
|
||||
let g:vimwiki_global_vars.WikiInclTemplate1 = g:vimwiki_global_vars.rxWikiInclPrefix . '__LinkUrl__'.
|
||||
\ g:vimwiki_global_vars.rxWikiInclSuffix
|
||||
let g:vimwiki_global_vars.WikiInclTemplate1 = g:vimwiki_global_vars.rxWikiInclPrefix
|
||||
\ .'__LinkUrl__'. g:vimwiki_global_vars.rxWikiInclSuffix
|
||||
" '{{__LinkUrl____LinkDescription__}}'
|
||||
let g:vimwiki_global_vars.WikiInclTemplate2 = g:vimwiki_global_vars.rxWikiInclPrefix . '__LinkUrl__'.
|
||||
\ '__LinkDescription__'.
|
||||
\ g:vimwiki_global_vars.rxWikiInclSuffix
|
||||
let g:vimwiki_global_vars.WikiInclTemplate2 = g:vimwiki_global_vars.rxWikiInclPrefix
|
||||
\ . '__LinkUrl__' . g:vimwiki_global_vars.rxWikiInclSeparator . '__LinkDescription__'
|
||||
\ . g:vimwiki_global_vars.rxWikiInclSuffix
|
||||
|
||||
let valid_chars = '[^\\\}]'
|
||||
let g:vimwiki_global_vars.rxWikiInclUrl = valid_chars.'\{-}'
|
||||
@@ -143,14 +168,18 @@ function! s:populate_global_variables()
|
||||
let g:vimwiki_global_vars.rxWikiInclSuffix1 = g:vimwiki_global_vars.rxWikiInclArgs.
|
||||
\ g:vimwiki_global_vars.rxWikiInclSuffix
|
||||
|
||||
let g:vimwiki_global_vars.rxTodo = '\C\%(TODO:\|DONE:\|STARTED:\|FIXME:\|FIXED:\|XXX:\)'
|
||||
let g:vimwiki_global_vars.rxTodo = '\C\<\%(TODO\|DONE\|STARTED\|FIXME\|FIXED\|XXX\)\>'
|
||||
|
||||
" default colors when headers of different levels are highlighted differently
|
||||
" not making it yet another option; needed by ColorScheme autocommand
|
||||
let g:vimwiki_global_vars.hcolor_guifg_light = ['#aa5858', '#507030', '#1030a0', '#103040', '#505050', '#636363']
|
||||
let g:vimwiki_global_vars.hcolor_ctermfg_light = ['DarkRed', 'DarkGreen', 'DarkBlue', 'Black', 'Black', 'Black']
|
||||
let g:vimwiki_global_vars.hcolor_guifg_dark = ['#e08090', '#80e090', '#6090e0', '#c0c0f0', '#e0e0f0', '#f0f0f0']
|
||||
let g:vimwiki_global_vars.hcolor_ctermfg_dark = ['Red', 'Green', 'Blue', 'White', 'White', 'White']
|
||||
let g:vimwiki_global_vars.hcolor_guifg_light = ['#aa5858', '#507030', '#1030a0', '#103040'
|
||||
\ , '#505050', '#636363']
|
||||
let g:vimwiki_global_vars.hcolor_ctermfg_light = ['DarkRed', 'DarkGreen', 'DarkBlue', 'Black'
|
||||
\ , 'Black', 'Black']
|
||||
let g:vimwiki_global_vars.hcolor_guifg_dark = ['#e08090', '#80e090', '#6090e0', '#c0c0f0'
|
||||
\ , '#e0e0f0', '#f0f0f0']
|
||||
let g:vimwiki_global_vars.hcolor_ctermfg_dark = ['Red', 'Green', 'Blue', 'White', 'White'
|
||||
\ , 'White']
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -185,6 +214,7 @@ function! s:populate_wikilocal_options()
|
||||
\ 'automatic_nested_syntaxes': 1,
|
||||
\ 'css_name': 'style.css',
|
||||
\ 'custom_wiki2html': '',
|
||||
\ 'custom_wiki2html_args': '',
|
||||
\ 'diary_header': 'Diary',
|
||||
\ 'diary_index': 'diary',
|
||||
\ 'diary_rel_path': 'diary/',
|
||||
@@ -204,12 +234,22 @@ function! s:populate_wikilocal_options()
|
||||
|
||||
let g:vimwiki_wikilocal_vars = []
|
||||
|
||||
let default_wiki_settings = {}
|
||||
for key in keys(default_values)
|
||||
if exists('g:vimwiki_'.key)
|
||||
let default_wiki_settings[key] = g:vimwiki_{key}
|
||||
else
|
||||
let default_wiki_settings[key] = default_values[key]
|
||||
endif
|
||||
endfor
|
||||
|
||||
" set the wiki-local variables according to g:vimwiki_list (or the default settings)
|
||||
if exists('g:vimwiki_list')
|
||||
for users_options in g:vimwiki_list
|
||||
for users_wiki_settings in g:vimwiki_list
|
||||
let new_wiki_settings = {}
|
||||
for key in keys(default_values)
|
||||
if has_key(users_options, key)
|
||||
let new_wiki_settings[key] = users_options[key]
|
||||
if has_key(users_wiki_settings, key)
|
||||
let new_wiki_settings[key] = users_wiki_settings[key]
|
||||
elseif exists('g:vimwiki_'.key)
|
||||
let new_wiki_settings[key] = g:vimwiki_{key}
|
||||
else
|
||||
@@ -217,24 +257,21 @@ function! s:populate_wikilocal_options()
|
||||
endif
|
||||
endfor
|
||||
|
||||
" is it a temporary wiki? No, it's not.
|
||||
let new_wiki_settings.temp = 0
|
||||
let new_wiki_settings.is_temporary_wiki = 0
|
||||
|
||||
call add(g:vimwiki_wikilocal_vars, new_wiki_settings)
|
||||
endfor
|
||||
else
|
||||
" if the user hasn't registered any wiki, we register one wiki using the default values
|
||||
let new_wiki_settings = deepcopy(default_wiki_settings)
|
||||
let new_wiki_settings.is_temporary_wiki = 0
|
||||
call add(g:vimwiki_wikilocal_vars, new_wiki_settings)
|
||||
endif
|
||||
|
||||
" default values for temporary wikis
|
||||
let temporary_options_dict = {}
|
||||
for key in keys(default_values)
|
||||
if exists('g:vimwiki_'.key)
|
||||
let temporary_options_dict[key] = g:vimwiki_{key}
|
||||
else
|
||||
let temporary_options_dict[key] = default_values[key]
|
||||
endif
|
||||
endfor
|
||||
let temporary_options_dict.temp = 1
|
||||
call add(g:vimwiki_wikilocal_vars, temporary_options_dict)
|
||||
let temporary_wiki_settings = deepcopy(default_wiki_settings)
|
||||
let temporary_wiki_settings.is_temporary_wiki = 1
|
||||
call add(g:vimwiki_wikilocal_vars, temporary_wiki_settings)
|
||||
|
||||
call s:validate_wikilocal_settings()
|
||||
endfunction
|
||||
@@ -263,14 +300,28 @@ function! s:validate_wikilocal_settings()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:normalize_path(path)
|
||||
" trim trailing / and \ because otherwise resolve() doesn't work quite right
|
||||
let path = substitute(a:path, '[/\\]\+$', '', '')
|
||||
if path !~# '^scp:'
|
||||
return resolve(expand(path)).'/'
|
||||
else
|
||||
return path.'/'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#vars#populate_syntax_vars(syntax)
|
||||
if !exists('g:vimwiki_syntax_variables')
|
||||
let g:vimwiki_syntax_variables = {}
|
||||
endif
|
||||
if !has_key(g:vimwiki_syntax_variables, a:syntax)
|
||||
let g:vimwiki_syntax_variables[a:syntax] = {}
|
||||
|
||||
if has_key(g:vimwiki_syntax_variables, a:syntax)
|
||||
return
|
||||
endif
|
||||
|
||||
let g:vimwiki_syntax_variables[a:syntax] = {}
|
||||
|
||||
execute 'runtime! syntax/vimwiki_'.a:syntax.'.vim'
|
||||
|
||||
" generic stuff
|
||||
@@ -278,33 +329,53 @@ function! vimwiki#vars#populate_syntax_vars(syntax)
|
||||
if g:vimwiki_syntax_variables[a:syntax].symH
|
||||
" symmetric headers
|
||||
for i in range(1,6)
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] = repeat(header_symbol, i).' __Header__ '.repeat(header_symbol, i)
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] = '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'.header_symbol.'\{'.i.'}\s*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] = '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'.header_symbol.'\{'.i.'}\s*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] = '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'.header_symbol.'\{1,'.i.'}\s*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] =
|
||||
\ repeat(header_symbol, i).' __Header__ '.repeat(header_symbol, i)
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] =
|
||||
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
|
||||
\ .header_symbol.'\{'.i.'}\s*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] =
|
||||
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
|
||||
\ .header_symbol.'\{'.i.'}\s*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] =
|
||||
\ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']'
|
||||
\ .header_symbol.'\{1,'.i.'}\s*$'
|
||||
endfor
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxHeader = '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*[^'.header_symbol.']\ze\1\s*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxHeader =
|
||||
\ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*[^'.header_symbol.']\ze\1\s*$'
|
||||
else
|
||||
" asymmetric
|
||||
for i in range(1,6)
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] = repeat(header_symbol, i).' __Header__'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] = '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] = '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] = '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] =
|
||||
\ repeat(header_symbol, i).' __Header__'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] =
|
||||
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] =
|
||||
\ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] =
|
||||
\ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*$'
|
||||
endfor
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxHeader = '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*\ze$'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxHeader =
|
||||
\ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*\ze$'
|
||||
endif
|
||||
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxPreStart = '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxPreStart
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxPreEnd = '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxPreEnd.'\s*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxPreStart =
|
||||
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxPreStart
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxPreEnd =
|
||||
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxPreEnd.'\s*$'
|
||||
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxMathStart = '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxMathStart
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxMathEnd = '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxMathEnd.'\s*$'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxMathStart =
|
||||
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxMathStart
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxMathEnd =
|
||||
\ '^\s*'.g:vimwiki_syntax_variables[a:syntax].rxMathEnd.'\s*$'
|
||||
|
||||
" list stuff
|
||||
let g:vimwiki_syntax_variables[a:syntax].rx_bullet_chars = '['.join(g:vimwiki_syntax_variables[a:syntax].bullet_types, '').']\+'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rx_bullet_chars =
|
||||
\ '['.join(g:vimwiki_syntax_variables[a:syntax].bullet_types, '').']\+'
|
||||
|
||||
let g:vimwiki_syntax_variables[a:syntax].multiple_bullet_chars = g:vimwiki_syntax_variables[a:syntax].recurring_bullets ? g:vimwiki_syntax_variables[a:syntax].bullet_types : []
|
||||
let g:vimwiki_syntax_variables[a:syntax].multiple_bullet_chars =
|
||||
\ g:vimwiki_syntax_variables[a:syntax].recurring_bullets
|
||||
\ ? g:vimwiki_syntax_variables[a:syntax].bullet_types : []
|
||||
|
||||
let g:vimwiki_syntax_variables[a:syntax].number_kinds = []
|
||||
let g:vimwiki_syntax_variables[a:syntax].number_divisors = ''
|
||||
@@ -318,9 +389,11 @@ function! vimwiki#vars#populate_syntax_vars(syntax)
|
||||
|
||||
"create regexp for bulleted list items
|
||||
if !empty(g:vimwiki_syntax_variables[a:syntax].bullet_types)
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListBullet = join( map(g:vimwiki_syntax_variables[a:syntax].bullet_types,
|
||||
\'vimwiki#u#escape(v:val).repeat("\\+", g:vimwiki_syntax_variables[a:syntax].recurring_bullets)'
|
||||
\ ) , '\|')
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListBullet =
|
||||
\ join( map(g:vimwiki_syntax_variables[a:syntax].bullet_types,
|
||||
\'vimwiki#u#escape(v:val).'
|
||||
\ .'repeat("\\+", g:vimwiki_syntax_variables[a:syntax].recurring_bullets)'
|
||||
\ ) , '\|')
|
||||
else
|
||||
"regex that matches nothing
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListBullet = '$^'
|
||||
@@ -333,7 +406,8 @@ function! vimwiki#vars#populate_syntax_vars(syntax)
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListNumber .= char_to_rx[type[0]] .
|
||||
\ vimwiki#u#escape(type[1]) . '\|'
|
||||
endfor
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListNumber .= char_to_rx[g:vimwiki_syntax_variables[a:syntax].number_types[-1][0]].
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListNumber .=
|
||||
\ char_to_rx[g:vimwiki_syntax_variables[a:syntax].number_types[-1][0]].
|
||||
\ vimwiki#u#escape(g:vimwiki_syntax_variables[a:syntax].number_types[-1][1]) . '\)'
|
||||
else
|
||||
"regex that matches nothing
|
||||
@@ -341,21 +415,43 @@ function! vimwiki#vars#populate_syntax_vars(syntax)
|
||||
endif
|
||||
|
||||
"the user can set the listsyms as string, but vimwiki needs a list
|
||||
let g:vimwiki_syntax_variables[a:syntax].listsyms_list = split(vimwiki#vars#get_global('listsyms'), '\zs')
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB = '^\s*\%(\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\|\('.g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\)\s'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListItem = g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB . '\+\%(\[\(['.vimwiki#vars#get_global('listsyms').']\)\]\s\)\?'
|
||||
let g:vimwiki_syntax_variables[a:syntax].listsyms_list =
|
||||
\ split(vimwiki#vars#get_global('listsyms'), '\zs')
|
||||
if match(vimwiki#vars#get_global('listsyms'), vimwiki#vars#get_global('listsym_rejected')) != -1
|
||||
echomsg 'Vimwiki Warning: the value of g:vimwiki_listsym_rejected ('''
|
||||
\ . vimwiki#vars#get_global('listsym_rejected')
|
||||
\ . ''') must not be a part of g:vimwiki_listsyms (''' .
|
||||
\ . vimwiki#vars#get_global('listsyms') . ''')'
|
||||
endif
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB =
|
||||
\ '^\s*\%(\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\|\('
|
||||
\ .g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\)\s'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListItem =
|
||||
\ g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB
|
||||
\ . '\+\%(\[\(['.vimwiki#vars#get_global('listsyms')
|
||||
\ . vimwiki#vars#get_global('listsym_rejected').']\)\]\s\)\?'
|
||||
if g:vimwiki_syntax_variables[a:syntax].recurring_bullets
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren = '^\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\s\+\['.g:vimwiki_syntax_variables[a:syntax].listsyms_list[4].'\]\s.*\%(\n\%(\1\%('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\).*\|^$\|\s.*\)\)*'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren =
|
||||
\ '^\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\s\+\[['
|
||||
\ . g:vimwiki_syntax_variables[a:syntax].listsyms_list[-1]
|
||||
\ . vimwiki#vars#get_global('listsym_rejected') . ']\]\s.*\%(\n\%(\1\%('
|
||||
\ .g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\).*\|^$\|\s.*\)\)*'
|
||||
else
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\|'.g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\s\+\['.g:vimwiki_syntax_variables[a:syntax].listsyms_list[4].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren =
|
||||
\ '^\(\s*\)\%('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\|'
|
||||
\ . g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\s\+\[['
|
||||
\ . g:vimwiki_syntax_variables[a:syntax].listsyms_list[-1]
|
||||
\ . vimwiki#vars#get_global('listsym_rejected') . ']\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
|
||||
endif
|
||||
|
||||
" 0. URL : free-standing links: keep URL UR(L) strip trailing punct: URL; URL) UR(L))
|
||||
" let g:vimwiki_rxWeblink = '[\["(|]\@<!'. g:vimwiki_rxWeblinkUrl .
|
||||
" \ '\%([),:;.!?]\=\%([ \t]\|$\)\)\@='
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWeblink = '\<'. g:vimwiki_global_vars.rxWeblinkUrl . '\S*'
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWeblink =
|
||||
\ '\<'. g:vimwiki_global_vars.rxWeblinkUrl . '\S*'
|
||||
" 0a) match URL within URL
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchUrl = g:vimwiki_syntax_variables[a:syntax].rxWeblink
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchUrl =
|
||||
\ g:vimwiki_syntax_variables[a:syntax].rxWeblink
|
||||
" 0b) match DESCRIPTION within URL
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWeblinkMatchDescr = ''
|
||||
|
||||
@@ -375,16 +471,20 @@ function! vimwiki#vars#populate_syntax_vars(syntax)
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWikiLink = g:vimwiki_global_vars.rx_wikilink_prefix.
|
||||
\ g:vimwiki_global_vars.rxWikiLinkUrl.'\%('.g:vimwiki_global_vars.rx_wikilink_separator.
|
||||
\ g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxAnyLink = g:vimwiki_syntax_variables[a:syntax].rxWikiLink.'\|'.
|
||||
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.g:vimwiki_syntax_variables[a:syntax].rxWeblink
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxAnyLink =
|
||||
\ g:vimwiki_syntax_variables[a:syntax].rxWikiLink.'\|'.
|
||||
\ g:vimwiki_global_vars.rxWikiIncl.'\|'.g:vimwiki_syntax_variables[a:syntax].rxWeblink
|
||||
" b) match URL within [[URL|DESCRIPTION]]
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchUrl = g:vimwiki_global_vars.rx_wikilink_prefix.
|
||||
\ '\zs'. g:vimwiki_global_vars.rxWikiLinkUrl.'\ze\%('. g:vimwiki_global_vars.rx_wikilink_separator.
|
||||
\ g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchUrl =
|
||||
\ g:vimwiki_global_vars.rx_wikilink_prefix . '\zs'. g:vimwiki_global_vars.rxWikiLinkUrl
|
||||
\ .'\ze\%('. g:vimwiki_global_vars.rx_wikilink_separator
|
||||
\ . g:vimwiki_global_vars.rxWikiLinkDescr.'\)\?'.g:vimwiki_global_vars.rx_wikilink_suffix
|
||||
" c) match DESCRIPTION within [[URL|DESCRIPTION]]
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchDescr = g:vimwiki_global_vars.rx_wikilink_prefix.
|
||||
\ g:vimwiki_global_vars.rxWikiLinkUrl . g:vimwiki_global_vars.rx_wikilink_separator.'\%('.
|
||||
\ '\zs'. g:vimwiki_global_vars.rxWikiLinkDescr. '\ze\)\?'. g:vimwiki_global_vars.rx_wikilink_suffix
|
||||
let g:vimwiki_syntax_variables[a:syntax].rxWikiLinkMatchDescr =
|
||||
\ g:vimwiki_global_vars.rx_wikilink_prefix . g:vimwiki_global_vars.rxWikiLinkUrl
|
||||
\ . g:vimwiki_global_vars.rx_wikilink_separator.'\%(\zs'
|
||||
\ . g:vimwiki_global_vars.rxWikiLinkDescr. '\ze\)\?'
|
||||
\ . g:vimwiki_global_vars.rx_wikilink_suffix
|
||||
|
||||
if a:syntax ==# 'markdown'
|
||||
call s:populate_extra_markdown_vars()
|
||||
@@ -530,9 +630,10 @@ function! s:populate_extra_markdown_vars()
|
||||
|
||||
let mkd_syntax.rxMkdRef = '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)'.
|
||||
\ mkd_syntax.rxWeblink0
|
||||
let mkd_syntax.rxMkdRefMatchDescr = '\[\zs'.g:vimwiki_global_vars.rxWikiLinkDescr.'\ze]:\%(\s\+\|\n\)'.
|
||||
\ mkd_syntax.rxWeblink0
|
||||
let mkd_syntax.rxMkdRefMatchUrl = '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)\zs'.
|
||||
let mkd_syntax.rxMkdRefMatchDescr =
|
||||
\ '\[\zs'.g:vimwiki_global_vars.rxWikiLinkDescr.'\ze]:\%(\s\+\|\n\)'. mkd_syntax.rxWeblink0
|
||||
let mkd_syntax.rxMkdRefMatchUrl =
|
||||
\ '\['.g:vimwiki_global_vars.rxWikiLinkDescr.']:\%(\s\+\|\n\)\zs'.
|
||||
\ mkd_syntax.rxWeblink0.'\ze'
|
||||
endfunction
|
||||
|
||||
@@ -580,8 +681,6 @@ function! vimwiki#vars#get_bufferlocal(key, ...)
|
||||
\ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr')))
|
||||
elseif a:key ==# 'prev_link'
|
||||
call setbufvar(buffer, 'vimwiki_prev_link', [])
|
||||
elseif a:key ==# 'fs_rescan'
|
||||
call setbufvar(buffer, 'vimwiki_fs_rescan', 0)
|
||||
elseif a:key ==# 'markdown_refs'
|
||||
call setbufvar(buffer, 'vimwiki_markdown_refs', vimwiki#markdown_base#scan_reflinks())
|
||||
else
|
||||
@@ -636,7 +735,9 @@ function! vimwiki#vars#add_temporary_wiki(settings)
|
||||
call s:validate_wikilocal_settings()
|
||||
endfunction
|
||||
|
||||
|
||||
" number of registered wikis + temporary
|
||||
function! vimwiki#vars#number_of_wikis()
|
||||
return len(g:vimwiki_wikilocal_vars) - 1
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user