11 Commits

Author SHA1 Message Date
EinfachToll 86289a8493 Merge branch 'dev' into path-handling
Conflicts:
	autoload/vimwiki/base.vim
	autoload/vimwiki/diary.vim
	autoload/vimwiki/vars.vim
	ftplugin/vimwiki.vim
2019-01-28 07:30:08 +01:00
EinfachToll 1cffbdbf3d Fix: Don't double a ' character in header in TOC
When building the TOC, every ' in a header got doubled. According to git blame, I did this doubling explicitely, but I have no idea why I did this.
2019-01-25 16:45:11 +01:00
Ben 28675698ad Added syntax documentation to README.md
Currently, there is no easy way for a new user of this plugin to discover how to change the syntax. Markdown is favored by many in the community because it is more widely used than Vimwiki's default syntax and is therefore a more portable option. This configuration should be presented much more openly.
2019-01-20 19:55:14 +01:00
EinfachToll fdc367f725 Check all user settings for correct type, range etc. 2019-01-19 21:05:27 +01:00
EinfachToll e45380e3d2 Unify path handling -- part 6 2018-05-15 20:47:12 +02:00
EinfachToll 21e65cf4da Unify path handling -- part 5 2018-04-30 21:27:00 +02:00
EinfachToll b1393a34f7 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
2018-04-25 21:46:00 +02:00
EinfachToll ca07da33c8 Unify path handling -- part 4 2018-04-25 18:02:23 +02:00
EinfachToll f76e75d117 Unify path handling -- part 3 2018-02-22 08:21:23 +01:00
EinfachToll 12d6265193 Unify path handling -- part 2 2017-11-08 21:56:59 +01:00
EinfachToll 8d0d1561c5 Unify path handling 2017-04-16 16:41:43 +02:00
11 changed files with 798 additions and 445 deletions
+13
View File
@@ -105,6 +105,19 @@ Commands
* `:Vimwiki2HTML` -- Convert current wiki link to HTML * `:Vimwiki2HTML` -- Convert current wiki link to HTML
* `:VimwikiAll2HTML` -- Convert all your wiki links to HTML * `:VimwikiAll2HTML` -- Convert all your wiki links to HTML
* `:help vimwiki-commands` -- list all commands * `:help vimwiki-commands` -- list all commands
* `:help vimwiki` -- General vimwiki help docs
Changing Wiki Syntax
------------------------------------------------------------------------------
Vimwiki currently ships with 3 syntaxes: Vimwiki (default), Markdown (markdown), and MediaWiki (media)
If you would prefer to use either Markdown or MediaWiki syntaxes, set the following option in your .vimrc:
```
let g:vimwiki_list = [{'path': '~/vimwiki/',
\ 'syntax': 'markdown', 'ext': '.md'}]
```
Installation Installation
+89 -107
View File
@@ -43,55 +43,17 @@ function! vimwiki#base#file_pattern(files)
endfunction endfunction
"FIXME TODO slow and faulty
function! vimwiki#base#subdir(path, filename)
let path = a:path
" ensure that we are not fooled by a symbolic link
"FIXME if we are not "fooled", we end up in a completely different wiki?
if a:filename !~# '^scp:'
let filename = resolve(a:filename)
else
let filename = a:filename
endif
let idx = 0
"FIXME this can terminate in the middle of a path component!
while path[idx] ==? filename[idx]
let idx = idx + 1
endwhile
let p = split(strpart(filename, idx), '[/\\]')
let res = join(p[:-2], '/')
if len(res) > 0
let res = res.'/'
endif
return res
endfunction
function! vimwiki#base#current_subdir()
return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), expand('%:p'))
endfunction
function! vimwiki#base#invsubdir(subdir)
return substitute(a:subdir, '[^/\.]\+/', '../', 'g')
endfunction
" Returns: the number of the wiki a file belongs to or -1 if it doesn't belong " Returns: the number of the wiki a file belongs to or -1 if it doesn't belong
" to any registered wiki. " to any registered wiki.
" The path can be the full path or just the directory of the file function! vimwiki#base#find_wiki(file)
function! vimwiki#base#find_wiki(path)
let bestmatch = -1 let bestmatch = -1
let bestlen = 0 let bestlen = 0
let path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(a:path))
for idx in range(vimwiki#vars#number_of_wikis()) for idx in range(vimwiki#vars#number_of_wikis())
let idx_path = expand(vimwiki#vars#get_wikilocal('path', idx)) let wiki_path = expand(vimwiki#vars#get_wikilocal('path', idx))
let idx_path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(idx_path)) let common_prefix = vimwiki#path#path_common_pfx(wiki_path, a:file)
let common_pfx = vimwiki#path#path_common_pfx(idx_path, path) if vimwiki#path#is_equal(common_prefix, wiki_path)
if vimwiki#path#is_equal(common_pfx, idx_path) if len(common_prefix) > bestlen
if len(common_pfx) > bestlen let bestlen = len(common_prefix)
let bestlen = len(common_pfx)
let bestmatch = idx let bestmatch = idx
endif endif
endif endif
@@ -101,10 +63,9 @@ function! vimwiki#base#find_wiki(path)
endfunction endfunction
" THE central function of Vimwiki. Extract infos about the target from a link. " Extract infos about the target from a link. If the second parameter is present, which should be a
" If the second parameter is present, which should be an absolute file path, it " file object, it is assumed that the link appears in that file. Without it, the current file is
" is assumed that the link appears in that file. Without it, the current file " used.
" is used.
function! vimwiki#base#resolve_link(link_text, ...) function! vimwiki#base#resolve_link(link_text, ...)
if a:0 if a:0
let source_wiki = vimwiki#base#find_wiki(a:1) let source_wiki = vimwiki#base#find_wiki(a:1)
@@ -118,13 +79,16 @@ function! vimwiki#base#resolve_link(link_text, ...)
let link_infos = { let link_infos = {
\ 'index': -1, \ 'index': 0,
\ 'scheme': '', \ 'scheme': '',
\ 'filename': '', \ 'is_file': 0, " 1 for a file, 0 for a URL (e.g. when the link was [[http://foo.bar]]),
\ " -1 if the whole link was malformed
\ 'target': '', " this is a file or dir object if is_file == 1, otherwise a string
\ 'anchor': '', \ 'anchor': '',
\ } \ }
if link_text == '' if link_text == ''
let link_infos.is_file = -1
return link_infos return link_infos
endif endif
@@ -135,10 +99,14 @@ function! vimwiki#base#resolve_link(link_text, ...)
let link_infos.scheme = scheme let link_infos.scheme = scheme
if link_infos.scheme !~# '\mwiki\d\+\|diary\|local\|file' if link_infos.scheme !~# '\mwiki\d\+\|diary\|local\|file'
let link_infos.filename = link_text " unknown scheme, may be a weblink " unknown scheme, may be a weblink
let link_infos.is_file = 0
let link_infos.target = link_text
return link_infos return link_infos
endif endif
let link_infos.is_file = 1
let link_text = matchstr(link_text, '^'.vimwiki#vars#get_global('rxSchemes').':\zs.*\ze') let link_text = matchstr(link_text, '^'.vimwiki#vars#get_global('rxSchemes').':\zs.*\ze')
endif endif
@@ -152,10 +120,12 @@ function! vimwiki#base#resolve_link(link_text, ...)
let link_infos.anchor = join(split_lnk[1:], '#') let link_infos.anchor = join(split_lnk[1:], '#')
endif endif
if link_text == '' " because the link was of the form '#anchor' if link_text == '' " because the link was of the form '#anchor'
let link_text = fnamemodify(source_file, ':p:t:r') let link_text = vimwiki#path#filename_without_extension(source_file)
endif endif
endif endif
let link_tail = vimwiki#path#file_segment(link_text)
" check if absolute or relative path " check if absolute or relative path
if is_wiki_link && link_text[0] == '/' if is_wiki_link && link_text[0] == '/'
if link_text != '/' if link_text != '/'
@@ -166,7 +136,7 @@ function! vimwiki#base#resolve_link(link_text, ...)
let is_relative = 0 let is_relative = 0
else else
let is_relative = 1 let is_relative = 1
let root_dir = fnamemodify(source_file, ':p:h') . '/' let root_dir = vimwiki#path#directory_of_file(source_file)
endif endif
@@ -174,45 +144,52 @@ function! vimwiki#base#resolve_link(link_text, ...)
if link_infos.scheme =~# '\mwiki\d\+' if link_infos.scheme =~# '\mwiki\d\+'
let link_infos.index = eval(matchstr(link_infos.scheme, '\D\+\zs\d\+\ze')) let link_infos.index = eval(matchstr(link_infos.scheme, '\D\+\zs\d\+\ze'))
if link_infos.index < 0 || link_infos.index >= vimwiki#vars#number_of_wikis() if link_infos.index < 0 || link_infos.index >= vimwiki#vars#number_of_wikis()
let link_infos.is_file = -1
let link_infos.index = -1 let link_infos.index = -1
let link_infos.filename = ''
return link_infos return link_infos
endif endif
if !is_relative || link_infos.index != source_wiki if link_text[0] == '/' || link_infos.index != source_wiki
let root_dir = vimwiki#vars#get_wikilocal('path', link_infos.index) let root_dir = vimwiki#vars#get_wikilocal('path', link_infos.index)
endif if link_text != '/'
let link_text = link_text[1:]
let link_infos.filename = root_dir . link_text
if vimwiki#path#is_link_to_dir(link_text)
if vimwiki#vars#get_global('dir_link') != ''
let link_infos.filename .= vimwiki#vars#get_global('dir_link') .
\ vimwiki#vars#get_wikilocal('ext', link_infos.index)
endif endif
else else
let link_infos.filename .= vimwiki#vars#get_wikilocal('ext', link_infos.index) let root_dir = vimwiki#path#directory_of_file(source_file)
endif
if link_text =~# '\m[/\\]$'
if vimwiki#vars#get_global('dir_link') == ''
let target_dir = vimwiki#path#dir_segment(link_text)
let link_infos.target = vimwiki#path#join_dir(root_dir, target_dir)
else
let link_text .= vimwiki#vars#get_global('dir_link') .
\ vimwiki#vars#get_wikilocal('ext', link_infos.index)
let target_file = vimwiki#path#file_segment(link_text)
let link_infos.target = vimwiki#path#join(root_dir, target_file)
endif
else
let link_text .= vimwiki#vars#get_wikilocal('ext', link_infos.index)
let target_file = vimwiki#path#file_segment(link_text)
let link_infos.target = vimwiki#path#join(root_dir, target_file)
endif endif
elseif link_infos.scheme ==# 'diary' elseif link_infos.scheme ==# 'diary'
let link_infos.index = source_wiki let link_infos.index = source_wiki
let link_infos.filename = let root_dir = vimwiki#vars#get_wikilocal('diary_path', link_infos.index)
\ vimwiki#vars#get_wikilocal('path', link_infos.index) . let target_file = vimwiki#path#file_segment(link_text .
\ vimwiki#vars#get_wikilocal('diary_rel_path', link_infos.index) . \ vimwiki#vars#get_wikilocal('ext', link_infos.index))
\ link_text . let link_infos.target = vimwiki#path#join(root_dir, target_file)
\ vimwiki#vars#get_wikilocal('ext', link_infos.index) elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local') &&
elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local') && is_relative \ vimwiki#path#is_absolute(link_text)
let link_infos.filename = simplify(root_dir . link_text) let link_infos.target = vimwiki#path#file_obj(link_text)
else " absolute file link else " relative file link
" collapse repeated leading "/"'s within a link let root_dir = vimwiki#path#directory_of_file(source_file)
let link_text = substitute(link_text, '\m^/\+', '/', '') let target_file = vimwiki#path#file_segment(link_text)
" expand ~/ let link_infos.target = vimwiki#path#join(root_dir, target_file)
let link_text = fnamemodify(link_text, ':p')
let link_infos.filename = simplify(link_text)
endif endif
let link_infos.filename = vimwiki#path#normalize(link_infos.filename)
return link_infos return link_infos
endfunction endfunction
@@ -278,7 +255,7 @@ function! vimwiki#base#open_link(cmd, link, ...)
let link_infos = vimwiki#base#resolve_link(a:link) let link_infos = vimwiki#base#resolve_link(a:link)
endif endif
if link_infos.filename == '' if link_infos.is_file == -1
if link_infos.index == -1 if link_infos.index == -1
echomsg 'Vimwiki Error: No registered wiki ''' . link_infos.scheme . '''.' echomsg 'Vimwiki Error: No registered wiki ''' . link_infos.scheme . '''.'
else else
@@ -290,7 +267,7 @@ function! vimwiki#base#open_link(cmd, link, ...)
let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' || link_infos.scheme =~# 'diary' let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' || link_infos.scheme =~# 'diary'
let update_prev_link = is_wiki_link && let update_prev_link = is_wiki_link &&
\ !vimwiki#path#is_equal(link_infos.filename, vimwiki#path#current_wiki_file()) \ !vimwiki#path#is_equal(link_infos.target, vimwiki#path#current_wiki_file())
let vimwiki_prev_link = [] let vimwiki_prev_link = []
" update previous link for wiki pages " update previous link for wiki pages
@@ -304,10 +281,10 @@ function! vimwiki#base#open_link(cmd, link, ...)
" open/edit " open/edit
if is_wiki_link if is_wiki_link
call vimwiki#base#edit_file(a:cmd, link_infos.filename, link_infos.anchor, call vimwiki#base#edit_file(a:cmd, link_infos.target, link_infos.anchor,
\ vimwiki_prev_link, update_prev_link) \ vimwiki_prev_link, update_prev_link)
else else
call vimwiki#base#system_open_link(link_infos.filename) call vimwiki#base#system_open_link(link_infos.target)
endif endif
endfunction endfunction
@@ -337,7 +314,7 @@ endfunction
function! vimwiki#base#generate_links() function! vimwiki#base#generate_links()
let lines = [] let lines = []
let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0) let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0, 0)
call sort(links) call sort(links)
let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' ' let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' '
@@ -393,7 +370,9 @@ function! vimwiki#base#backlinks()
endfunction endfunction
" Returns: a list containing all files of the given wiki as absolute file path.
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX kann das weg?
" Returns: a list containing all files of the given wiki as file objects.
" If the given wiki number is negative, the diary of the current wiki is used " If the given wiki number is negative, the diary of the current wiki is used
" If the second argument is not zero, only directories are found " If the second argument is not zero, only directories are found
function! vimwiki#base#find_files(wiki_nr, directories_only) function! vimwiki#base#find_files(wiki_nr, directories_only)
@@ -401,8 +380,7 @@ function! vimwiki#base#find_files(wiki_nr, directories_only)
if wiki_nr >= 0 if wiki_nr >= 0
let root_directory = vimwiki#vars#get_wikilocal('path', wiki_nr) let root_directory = vimwiki#vars#get_wikilocal('path', wiki_nr)
else else
let root_directory = vimwiki#vars#get_wikilocal('path') . let root_directory = vimwiki#vars#get_wikilocal('diary_path')
\ vimwiki#vars#get_wikilocal('diary_rel_path')
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr') let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
endif endif
if a:directories_only if a:directories_only
@@ -424,14 +402,18 @@ endfunction
" Returns: a list containing the links to get from the current file to all wiki " Returns: a list containing the links to get from the current file to all wiki
" files in the given wiki. " files in the given wiki.
" If the given wiki number is negative, the diary of the current wiki is used. " If a:diary_only is nonzero, the diary of the wiki is used.
" If also_absolute_links is nonzero, also return links of the form /file " If a:also_absolute_links is nonzero, also return links of the form /file.
function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links) function! vimwiki#base#get_wikilinks(wiki_nr, diary_only, also_absolute_links)
let files = vimwiki#base#find_files(a:wiki_nr, 0) if a:diary_only
let files = vimwiki#path#files_in_dir_recursive(vimwiki#vars#get_wikilocal('diary_path'))
else
let files = vimwiki#path#files_in_dir_recursive(vimwiki#vars#get_wikilocal('path'))
endif
if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr') if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
let cwd = vimwiki#path#wikify_path(expand('%:p:h')) let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
elseif a:wiki_nr < 0 elseif a:wiki_nr < 0
let cwd = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path') let cwd = vimwiki#vars#get_wikilocal('diary_path')
else else
let cwd = vimwiki#vars#get_wikilocal('path', a:wiki_nr) let cwd = vimwiki#vars#get_wikilocal('path', a:wiki_nr)
endif endif
@@ -446,7 +428,7 @@ function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr') if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
let cwd = vimwiki#vars#get_wikilocal('path') let cwd = vimwiki#vars#get_wikilocal('path')
elseif a:wiki_nr < 0 elseif a:wiki_nr < 0
let cwd = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path') let cwd = vimwiki#vars#get_wikilocal('diary_path')
endif endif
let wikifile = fnamemodify(wikifile, ':r') " strip extension let wikifile = fnamemodify(wikifile, ':r') " strip extension
let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile) let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile)
@@ -608,7 +590,7 @@ function! s:get_links(wikifile, idx)
endif endif
let link_count += 1 let link_count += 1
let target = vimwiki#base#resolve_link(link_text, a:wikifile) let target = vimwiki#base#resolve_link(link_text, a:wikifile)
if target.filename != '' && target.scheme =~# '\mwiki\d\+\|diary\|file\|local' if target.is_file != -1 && target.scheme =~# '\mwiki\d\+\|diary\|file\|local'
call add(links, [target.filename, target.anchor, lnum, col]) call add(links, [target.filename, target.anchor, lnum, col])
endif endif
endwhile endwhile
@@ -1856,15 +1838,14 @@ function! vimwiki#base#table_of_contents(create)
let indentstring = repeat(' ', vimwiki#u#sw()) let indentstring = repeat(' ', vimwiki#u#sw())
let bullet = vimwiki#lst#default_symbol().' ' let bullet = vimwiki#lst#default_symbol().' '
for [lvl, link, desc] in complete_header_infos for [lvl, link, desc] in complete_header_infos
let esc_link = substitute(link, "'", "''", 'g')
let esc_desc = substitute(desc, "'", "''", 'g')
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
if vimwiki#vars#get_wikilocal('syntax') == 'markdown' if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template') let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
else
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
endif endif
let link = s:safesubstitute(link_tpl, '__LinkUrl__', let link = s:safesubstitute(link_tpl, '__LinkUrl__',
\ '#'.esc_link, '') \ '#'.link, '')
let link = s:safesubstitute(link, '__LinkDescription__', esc_desc, '') let link = s:safesubstitute(link, '__LinkDescription__', desc, '')
call add(lines, startindent.repeat(indentstring, lvl-1).bullet.link) call add(lines, startindent.repeat(indentstring, lvl-1).bullet.link)
endfor endfor
@@ -1916,11 +1897,11 @@ endfunction
function! s:is_diary_file(filename) function! s:is_diary_file(filename)
let file_path = vimwiki#path#path_norm(a:filename) let file_path = vimwiki#path#path_norm(a:filename)
let rel_path = vimwiki#vars#get_wikilocal('diary_rel_path') let diary_path = vimwiki#path#path_norm(vimwiki#vars#get_wikilocal('diary_path'))
let diary_path = vimwiki#path#path_norm(vimwiki#vars#get_wikilocal('path') . rel_path) return !vimwiki#path#equal(vimwiki#vars#get_wikilocal('path'),
return rel_path != '' && file_path =~# '^'.vimwiki#u#escape(diary_path) \ vimwiki#vars#get_wikilocal('diary_path'))
endfunction \ && file_path =~# '^'.vimwiki#u#escape(diary_path)
endfunction " }}}
function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template)
let url = matchstr(a:str, a:rxUrl) let url = matchstr(a:str, a:rxUrl)
@@ -1945,8 +1926,7 @@ endfunction
function! s:normalize_link_in_diary(lnk) function! s:normalize_link_in_diary(lnk)
let link = a:lnk . vimwiki#vars#get_wikilocal('ext') let link = a:lnk . vimwiki#vars#get_wikilocal('ext')
let link_wiki = vimwiki#vars#get_wikilocal('path') . '/' . link let link_wiki = vimwiki#vars#get_wikilocal('path') . '/' . link
let link_diary = vimwiki#vars#get_wikilocal('path') . '/' let link_diary = vimwiki#vars#get_wikilocal('diary_path') . '/' . link
\ . vimwiki#vars#get_wikilocal('diary_rel_path') . '/' . link
let link_exists_in_diary = filereadable(link_diary) let link_exists_in_diary = filereadable(link_diary)
let link_exists_in_wiki = filereadable(link_wiki) let link_exists_in_wiki = filereadable(link_wiki)
let link_is_date = a:lnk =~# '\d\d\d\d-\d\d-\d\d' let link_is_date = a:lnk =~# '\d\d\d\d-\d\d-\d\d'
@@ -1957,8 +1937,10 @@ function! s:normalize_link_in_diary(lnk)
let rxDesc = '' let rxDesc = ''
let template = vimwiki#vars#get_global('WikiLinkTemplate1') let template = vimwiki#vars#get_global('WikiLinkTemplate1')
elseif link_exists_in_wiki elseif link_exists_in_wiki
let depth = len(split(vimwiki#vars#get_wikilocal('diary_rel_path'), '/')) let relative_link =
let str = repeat('../', depth) . a:lnk . '|' . a:lnk \ vimwiki#path#relpath(vimwiki#vars#get_wikilocal('diary_path'),
\ vimwiki#vars#get_wikilocal('path'))
let str = relative_link . a:lnk . '|' . a:lnk
let rxUrl = '^.*\ze|' let rxUrl = '^.*\ze|'
let rxDesc = '|\zs.*$' let rxDesc = '|\zs.*$'
let template = vimwiki#vars#get_global('WikiLinkTemplate2') let template = vimwiki#vars#get_global('WikiLinkTemplate2')
+4 -6
View File
@@ -23,7 +23,7 @@ endfunction
function! s:diary_path(...) function! s:diary_path(...)
let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1 let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
return vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx) return vimwiki#vars#get_wikilocal('diary_path', idx)
endfunction endfunction
@@ -90,8 +90,7 @@ endfunction
function! s:get_diary_files() function! s:get_diary_files()
let rx = '^\d\{4}-\d\d-\d\d' let rx = '^\d\{4}-\d\d-\d\d'
let s_files = glob(vimwiki#vars#get_wikilocal('path'). let s_files = glob(vimwiki#vars#get_wikilocal('diary_path') . '*' . vimwiki#vars#get_wikilocal('ext'))
\ vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext'))
let files = split(s_files, '\n') let files = split(s_files, '\n')
call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"') call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"')
@@ -194,8 +193,7 @@ function! vimwiki#diary#make_note(wnum, ...)
" TODO: refactor it. base#goto_index uses the same " TODO: refactor it. base#goto_index uses the same
call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr). call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('diary_path', wiki_nr))
\ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr))
let cmd = 'edit' let cmd = 'edit'
if a:0 if a:0
@@ -320,7 +318,7 @@ endfunction
function vimwiki#diary#calendar_sign(day, month, year) function vimwiki#diary#calendar_sign(day, month, year)
let day = s:prefix_zero(a:day) let day = s:prefix_zero(a:day)
let month = s:prefix_zero(a:month) let month = s:prefix_zero(a:month)
let sfile = vimwiki#vars#get_wikilocal('path').vimwiki#vars#get_wikilocal('diary_rel_path'). let sfile = vimwiki#vars#get_wikilocal('diary_path') .
\ a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext') \ a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
return filereadable(expand(sfile)) return filereadable(expand(sfile))
endfunction endfunction
+136 -193
View File
@@ -10,8 +10,8 @@ endif
let g:loaded_vimwiki_html_auto = 1 let g:loaded_vimwiki_html_auto = 1
function! s:root_path(subdir) function! s:path_from_subdir_to_root(subdir)
return repeat('../', len(split(a:subdir, '[/\\]'))) return vimwiki#path#relpath(a:subdir, vimwiki#vars#get_wikilocal('path_html'))
endfunction endfunction
@@ -43,87 +43,67 @@ function! s:is_img_link(lnk)
endfunction endfunction
function! s:has_abs_path(fname) function! s:corresponding_html_file(wiki_file)
if a:fname =~# '\(^.:\)\|\(^/\)' let relative_wiki_path = vimwiki#path#subtract(vimwiki#vars#get_wikilocal('path'), a:wiki_file)
let html_file = vimwiki#path#join(vimwiki#vars#get_wikilocal('path_html'), relative_wiki_path)
let html_file = vimwiki#path#set_extension(html_file, 'html')
return html_file
endfunction
function! s:corresponding_wiki_file(html_file)
let html_path = vimwiki#path#subtract(vimwiki#vars#get_wikilocal('path_html'), a:html_file)
let wiki_file = vimwiki#path#join(vimwiki#vars#get_wikilocal('path'), html_path)
let wiki_file = vimwiki#path#set_extension(wiki_file, vimwiki#vars#get_wikilocal('ext'))
return wiki_file
endfunction
function! s:default_CSS_full_name()
return vimwiki#path#join(vimwiki#vars#get_wikilocal('path_html'),
\ vimwiki#vars#get_wikilocal('css_name'))
endfunction
" Returns: 1 if it was created, 0 if it already existed
function! s:create_default_CSS()
let css_full_name = s:default_CSS_full_name()
if vimwiki#path#exists(css_full_name)
return 0
else
let default_css = vimwiki#path#find_autoload_file('style.css')
call vimwiki#path#copy_file(default_css, css_full_name)
return 1 return 1
endif endif
return 0
endfunction
function! s:find_autoload_file(name)
for path in split(&runtimepath, ',')
let fname = path.'/autoload/vimwiki/'.a:name
if glob(fname) != ''
return fname
endif
endfor
return ''
endfunction
function! s:default_CSS_full_name(path)
let path = expand(a:path)
let css_full_name = path . vimwiki#vars#get_wikilocal('css_name')
return css_full_name
endfunction
function! s:create_default_CSS(path)
let css_full_name = s:default_CSS_full_name(a:path)
if glob(css_full_name) == ""
call vimwiki#path#mkdir(fnamemodify(css_full_name, ':p:h'))
let default_css = s:find_autoload_file('style.css')
if default_css != ''
let lines = readfile(default_css)
call writefile(lines, css_full_name)
return 1
endif
endif
return 0
endfunction endfunction
function! s:template_full_name(name) function! s:template_full_name(name)
if a:name == '' let filename = vimwiki#path#file_segment(name . vimwiki#vars#get_wikilocal('template_ext'))
let name = vimwiki#vars#get_wikilocal('template_default') let template_file = vimwiki#path#join(vimwiki#vars#get_wikilocal('template_path'), filename)
else return template_file
let name = a:name
endif
let fname = expand(vimwiki#vars#get_wikilocal('template_path').
\ name . vimwiki#vars#get_wikilocal('template_ext'))
if filereadable(fname)
return fname
else
return ''
endif
endfunction endfunction
function! s:get_html_template(template) function! s:get_html_template(template_name)
" TODO: refactor it!!! if a:template_name != ''
let lines=[] let template_file = s:template_full_name(a:template)
if a:template != ''
let template_name = s:template_full_name(a:template)
try try
let lines = readfile(template_name) let lines = readfile(vimwiki#path#to_string(template_file))
return lines return lines
catch /E484/ catch /E484/
echomsg 'Vimwiki: HTML template '.template_name. ' does not exist!' echomsg 'Vimwiki: HTML template '.vimwiki#path#to_string(template_file). ' does not exist!'
endtry endtry
return []
else
let default_template_file =
\ s:template_full_name(vimwiki#vars#get_wikilocal('template_default'))
if !vimwiki#path#exists(default_template_file)
let default_template_file = vimwiki#path#find_autoload_file('default.tpl')
endif
let lines = readfile(default_tpl)
return lines
endif endif
let default_tpl = s:template_full_name('')
if default_tpl == ''
let default_tpl = s:find_autoload_file('default.tpl')
endif
let lines = readfile(default_tpl)
return lines
endfunction endfunction
@@ -151,26 +131,25 @@ function! s:safe_html_line(line)
endfunction endfunction
function! s:delete_html_files(path) function! s:delete_html_files()
let htmlfiles = split(glob(a:path.'**/*.html'), '\n') let htmlfiles =
for fname in htmlfiles \ vimwiki#path#files_in_dir_recursive(vimwiki#vars#get_wikilocal('path_html'), 'html')
for html_file in htmlfiles
" ignore user html files, e.g. search.html,404.html " ignore user html files, e.g. search.html,404.html
if stridx(vimwiki#vars#get_global('user_htmls'), fnamemodify(fname, ":t")) >= 0 if index(vimwiki#vars#get_global('user_htmls'), vimwiki#path#filename(html_file)) >= 0
continue continue
endif endif
" delete if there is no corresponding wiki file " delete if there is no corresponding wiki file
let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path_html'), fname) if vimwiki#path#exists(s:corresponding_wiki_file(html_file))
let wikifile = vimwiki#vars#get_wikilocal('path').subdir.
\fnamemodify(fname, ":t:r").vimwiki#vars#get_wikilocal('ext')
if filereadable(wikifile)
continue continue
endif endif
try try
call delete(fname) call delete(vimwiki#path#to_string(html_file))
catch catch
echomsg 'Vimwiki Error: Cannot delete '.fname echomsg 'Vimwiki Error: Cannot delete '.vimwiki#path#to_string(html_file)
endtry endtry
endfor endfor
endfunction endfunction
@@ -231,21 +210,15 @@ endfunction
function! s:is_html_uptodate(wikifile) function! s:is_html_uptodate(wikifile)
let tpl_time = -1 let htmlfile_ftime = getftime(vimwiki#path#to_string(s:corresponding_html_file(a:wikifile)))
let tpl_file = s:template_full_name('') " The HTML file should also be considered out of date if the default template has been changed in
if tpl_file != '' " the meantime. This is not completely correct, because the wiki file could use a template which
let tpl_time = getftime(tpl_file) " is not the default one. But it's better than nothing.
endif let tpl_file = s:template_full_name(vimwiki#vars#get_wikilocal('template_default'))
let tpl_time = getftime(tpl_file)
let wikifile = fnamemodify(a:wikifile, ":p") return getftime(wikifile) <= htmlfile_ftime && tpl_time <= htmlfile_ftime
let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') .
\ vimwiki#vars#get_bufferlocal('subdir') . fnamemodify(wikifile, ":t:r").".html")
if getftime(wikifile) <= getftime(htmlfile) && tpl_time <= getftime(htmlfile)
return 1
endif
return 0
endfunction endfunction
@@ -410,17 +383,18 @@ function! s:tag_wikiincl(value)
let link_infos = vimwiki#base#resolve_link(url_0) let link_infos = vimwiki#base#resolve_link(url_0)
if link_infos.scheme =~# '\mlocal\|wiki\d\+\|diary' if link_infos.scheme =~# '\mlocal\|wiki\d\+\|diary'
let url = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'), link_infos.filename) let url = vimwiki#path#relpath(vimwiki#path#directory_of_file(s:current_html_file),
\ link_infos.target)
" strip the .html extension when we have wiki links, so that the user can " strip the .html extension when we have wiki links, so that the user can
" simply write {{image.png}} to include an image from the wiki directory " simply write {{image.png}} to include an image from the wiki directory
if link_infos.scheme =~# '\mwiki\d\+\|diary' if link_infos.scheme =~# '\mwiki\d\+\|diary'
let url = fnamemodify(url, ':r') let url = vimwiki#path#filename_without_extension(url)
endif endif
else else
let url = link_infos.filename let url = link_infos.target
endif endif
let url = escape(url, '#') let url = escape(vimwiki#path#to_string(url), '#')
let line = s:linkify_image(url, descr, verbatim_str) let line = s:linkify_image(url, descr, verbatim_str)
endif endif
return line return line
@@ -447,20 +421,17 @@ function! s:tag_wikilink(value)
if link_infos.scheme ==# 'file' if link_infos.scheme ==# 'file'
" external file links are always absolute " external file links are always absolute
let html_link = link_infos.filename let html_link = vimwiki#path#to_string(link_infos.target)
elseif link_infos.scheme ==# 'local' elseif link_infos.scheme ==# 'local'
let html_link = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'), let html_link = vimwiki#path#to_string(vimwiki#path#relpath(
\ link_infos.filename) \ vimwiki#path#directory_of_file(s:current_html_file), link_infos.target))
elseif link_infos.scheme =~# '\mwiki\d\+\|diary' elseif link_infos.scheme =~# '\mwiki\d\+\|diary'
" wiki links are always relative to the current file " wiki links are always relative to the current file
let html_link = vimwiki#path#relpath( let target_html_file = s:corresponding_html_file(link_infos.target)
\ fnamemodify(s:current_wiki_file, ':h'), let html_link = vimwiki#path#to_string(vimwiki#path#relpath(
\ fnamemodify(link_infos.filename, ':r')) \ vimwiki#path#directory_of_file(s:current_html_file), target_html_file))
if html_link !~ '\m/$'
let html_link .= '.html'
endif
else " other schemes, like http, are left untouched else " other schemes, like http, are left untouched
let html_link = link_infos.filename let html_link = link_infos.target
endif endif
if link_infos.anchor != '' if link_infos.anchor != ''
@@ -1392,57 +1363,61 @@ endfunction
function! s:use_custom_wiki2html() function! s:use_custom_wiki2html()
let custom_wiki2html = vimwiki#vars#get_wikilocal('custom_wiki2html') let custom_wiki2html = vimwiki#vars#get_wikilocal('custom_wiki2html')
return !empty(custom_wiki2html) && return vimwiki#path#is_executable(custom_wiki2html)
\ (s:file_exists(custom_wiki2html) || s:binary_exists(custom_wiki2html))
endfunction endfunction
function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) function! s:call_custom_wiki2HTML(output_dir, wikifile, force)
call vimwiki#path#mkdir(a:path) call vimwiki#path#mkdir(a:output_dir)
echomsg system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '.
\ a:force. ' '. let arguments = [
\ vimwiki#vars#get_wikilocal('syntax'). ' '. \ a:force,
\ strpart(vimwiki#vars#get_wikilocal('ext'), 1). ' '. \ vimwiki#vars#get_wikilocal('syntax'),
\ shellescape(a:path). ' '. \ strpart(vimwiki#vars#get_wikilocal('ext'), 1),
\ shellescape(a:wikifile). ' '. \ vimwiki#path#to_string(a:output_dir),
\ shellescape(s:default_CSS_full_name(a:path)). ' '. \ vimwiki#path#to_string(a:wikifile),
\ (len(vimwiki#vars#get_wikilocal('template_path')) > 1 ? \ vimwiki#path#to_string(s:default_CSS_full_name()),
\ shellescape(expand(vimwiki#vars#get_wikilocal('template_path'))) : '-'). ' '. \ vimwiki#path#to_string(vimwiki#vars#get_wikilocal('template_path')),
\ (len(vimwiki#vars#get_wikilocal('template_default')) > 0 ? \ vimwiki#vars#get_wikilocal('template_default'),
\ vimwiki#vars#get_wikilocal('template_default') : '-'). ' '. \ vimwiki#vars#get_wikilocal('template_ext'),
\ (len(vimwiki#vars#get_wikilocal('template_ext')) > 0 ? \ vimwiki#path#to_string(s:path_from_subdir_to_root(a:output_dir)),
\ vimwiki#vars#get_wikilocal('template_ext') : '-'). ' '. \ vimwiki#vars#get_wikilocal('custom_wiki2html_args')
\ (len(vimwiki#vars#get_bufferlocal('subdir')) > 0 ? \ ]
\ shellescape(s:root_path(vimwiki#vars#get_bufferlocal('subdir'))) : '-'). ' '.
\ (len(vimwiki#vars#get_wikilocal('custom_wiki2html_args')) > 0 ? for i in range(len(arguments))
\ vimwiki#vars#get_wikilocal('custom_wiki2html_args') : '-')) if arguments[i] =~# '\m^\s*$'
let arguments[i] = '-'
endif
let arguments[i] = shellescape(arguments[i])
endfor
echomsg system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '. join(arguments, ' '))
endfunction endfunction
function! s:convert_file(path_html, wikifile) function! s:convert_file(wikifile)
let done = 0 let done = 0
let wikifile = fnamemodify(a:wikifile, ":p") let html_file = s:corresponding_html_file(a:wikifile)
let path_html = expand(a:path_html).vimwiki#vars#get_bufferlocal('subdir')
let htmlfile = fnamemodify(wikifile, ":t:r").'.html'
" the currently processed file name is needed when processing links " the currently processed file name is needed when processing links
" yeah yeah, shame on me for using (quasi-) global variables " yeah yeah, shame on me for using (quasi-) global variables
let s:current_wiki_file = wikifile let s:current_wiki_file = a:wikifile
let s:current_html_file = path_html . htmlfile let s:current_html_file = html_file
let output_dir = vimwiki#path#directory_of_file(html_file)
if s:use_custom_wiki2html() if s:use_custom_wiki2html()
let force = 1 let force = 1
call vimwiki#html#CustomWiki2HTML(path_html, wikifile, force) call s:call_custom_wiki2HTML(output_dir, wikifile, force)
let done = 1 let done = 1
endif endif
if s:syntax_supported() && done == 0 if s:syntax_supported() && done == 0
let lsource = readfile(wikifile) let lsource = readfile(vimwiki#path#to_string(a:wikifile))
let ldest = [] let ldest = []
call vimwiki#path#mkdir(path_html) call vimwiki#path#mkdir(output_dir)
" nohtml placeholder -- to skip html generation. " nohtml placeholder -- to skip html generation.
let nohtml = 0 let nohtml = 0
@@ -1508,7 +1483,7 @@ function! s:convert_file(path_html, wikifile)
if nohtml if nohtml
echon "\r"."%nohtml placeholder found" echon "\r"."%nohtml placeholder found"
return '' return vimwiki#path#null_file()
endif endif
call s:remove_blank_lines(ldest) call s:remove_blank_lines(ldest)
@@ -1525,7 +1500,7 @@ function! s:convert_file(path_html, wikifile)
call s:close_tag_table(state.table, lines, state.header_ids) call s:close_tag_table(state.table, lines, state.header_ids)
call extend(ldest, lines) call extend(ldest, lines)
let title = s:process_title(placeholders, fnamemodify(a:wikifile, ":t:r")) let title = s:process_title(placeholders, vimwiki#path#filename(a:wikifile))
let date = s:process_date(placeholders, strftime('%Y-%m-%d')) let date = s:process_date(placeholders, strftime('%Y-%m-%d'))
let html_lines = s:get_html_template(template_name) let html_lines = s:get_html_template(template_name)
@@ -1534,10 +1509,9 @@ function! s:convert_file(path_html, wikifile)
call map(html_lines, 'substitute(v:val, "%title%", "'. title .'", "g")') call map(html_lines, 'substitute(v:val, "%title%", "'. title .'", "g")')
call map(html_lines, 'substitute(v:val, "%date%", "'. date .'", "g")') call map(html_lines, 'substitute(v:val, "%date%", "'. date .'", "g")')
call map(html_lines, 'substitute(v:val, "%root_path%", "'. call map(html_lines, 'substitute(v:val, "%root_path%", "'.
\ s:root_path(vimwiki#vars#get_bufferlocal('subdir')) .'", "g")') \ s:path_from_subdir_to_root(output_dir) .'", "g")')
let css_name = expand(vimwiki#vars#get_wikilocal('css_name')) let css_name = vimwiki#path#to_string(vimwiki#vars#get_wikilocal('css_name'))
let css_name = substitute(css_name, '\', '/', 'g')
call map(html_lines, 'substitute(v:val, "%css%", "'. css_name .'", "g")') call map(html_lines, 'substitute(v:val, "%css%", "'. css_name .'", "g")')
let enc = &fileencoding let enc = &fileencoding
@@ -1548,30 +1522,30 @@ function! s:convert_file(path_html, wikifile)
let html_lines = s:html_insert_contents(html_lines, ldest) " %contents% let html_lines = s:html_insert_contents(html_lines, ldest) " %contents%
call writefile(html_lines, path_html.htmlfile) call writefile(html_lines, vimwiki#path#to_string(html_file))
let done = 1 let done = 1
endif endif
if done == 0 if done == 0
echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax' echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax'
return '' return vimwiki#path#null_file()
endif endif
return path_html.htmlfile return html_file
endfunction endfunction
function! vimwiki#html#Wiki2HTML(path_html, wikifile) function! vimwiki#html#Wiki2HTML(wikifile)
let result = s:convert_file(a:path_html, a:wikifile) let result = s:convert_file(a:wikifile)
if result != '' if !vimwiki#path#is_null(result)
call s:create_default_CSS(a:path_html) call s:create_default_CSS()
endif endif
return result return result
endfunction endfunction
function! vimwiki#html#WikiAll2HTML(path_html) function! vimwiki#html#WikiAll2HTML()
if !s:syntax_supported() && !s:use_custom_wiki2html() if !s:syntax_supported() && !s:use_custom_wiki2html()
echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax' echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax'
return return
@@ -1587,76 +1561,45 @@ function! vimwiki#html#WikiAll2HTML(path_html)
endtry endtry
let &eventignore = save_eventignore let &eventignore = save_eventignore
let path_html = expand(a:path_html) let path_html = vimwiki#vars#get_wikilocal('path_html')
call vimwiki#path#mkdir(path_html) call vimwiki#path#mkdir(path_html)
echomsg 'Vimwiki: Deleting non-wiki html files ...' echomsg 'Vimwiki: Deleting non-wiki html files ...'
call s:delete_html_files(path_html) call s:delete_html_files()
echomsg 'Vimwiki: Converting wiki to html files ...' echomsg 'Vimwiki: Converting wiki to html files ...'
let setting_more = &more let setting_more = &more
setlocal nomore setlocal nomore
" temporarily adjust current_subdir global state variable let wikifiles = vimwiki#path#files_in_dir_recursive(vimwiki#vars#get_wikilocal('path'),
let current_subdir = vimwiki#vars#get_bufferlocal('subdir') \ vimwiki#vars#get_wikilocal('ext'))
let current_invsubdir = vimwiki#vars#get_bufferlocal('invsubdir')
let wikifiles = split(glob(vimwiki#vars#get_wikilocal('path').'**/*'.
\ vimwiki#vars#get_wikilocal('ext')), '\n')
for wikifile in wikifiles for wikifile in wikifiles
let wikifile = fnamemodify(wikifile, ":p")
" temporarily adjust 'subdir' and 'invsubdir' state variables
let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), wikifile)
call vimwiki#vars#set_bufferlocal('subdir', subdir)
call vimwiki#vars#set_bufferlocal('invsubdir', vimwiki#base#invsubdir(subdir))
if !s:is_html_uptodate(wikifile) if !s:is_html_uptodate(wikifile)
echomsg 'Vimwiki: Processing '.wikifile echomsg 'Vimwiki: Processing '.vimwiki#path#to_string(wikifile)
call s:convert_file(wikifile)
call s:convert_file(path_html, wikifile)
else else
echomsg 'Vimwiki: Skipping '.wikifile echomsg 'Vimwiki: Skipping '.vimwiki#path#to_string(wikifile)
endif endif
endfor endfor
" reset 'subdir' state variable
call vimwiki#vars#set_bufferlocal('subdir', current_subdir)
call vimwiki#vars#set_bufferlocal('invsubdir', current_invsubdir)
let created = s:create_default_CSS(path_html) let created = s:create_default_CSS()
if created if created
echomsg 'Vimwiki: Default style.css has been created' echomsg 'Vimwiki: Default style.css has been created'
endif endif
echomsg 'Vimwiki: HTML exported to '.path_html echomsg 'Vimwiki: HTML exported to '.vimwiki#path#to_string(path_html)
echomsg 'Vimwiki: Done!' echomsg 'Vimwiki: Done!'
let &more = setting_more let &more = setting_more
endfunction endfunction
function! s:file_exists(fname)
return !empty(getftype(expand(a:fname)))
endfunction
function! s:binary_exists(fname)
return executable(expand(a:fname))
endfunction
function! s:get_wikifile_url(wikifile)
return vimwiki#vars#get_wikilocal('path_html') .
\ vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), a:wikifile).
\ fnamemodify(a:wikifile, ":t:r").'.html'
endfunction
function! vimwiki#html#PasteUrl(wikifile) function! vimwiki#html#PasteUrl(wikifile)
execute 'r !echo file://'.s:get_wikifile_url(a:wikifile) execute 'r !echo file://'.s:corresponding_html_file(a:wikifile)
endfunction endfunction
function! vimwiki#html#CatUrl(wikifile) function! vimwiki#html#CatUrl(wikifile)
execute '!echo file://'.s:get_wikifile_url(a:wikifile) execute '!echo file://'.s:corresponding_html_file(a:wikifile)
endfunction endfunction
+275 -15
View File
@@ -49,13 +49,6 @@ function! vimwiki#path#path_norm(path)
endfunction endfunction
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
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) return vimwiki#path#normalize(expand("%:p:h").'/'.a:link)
endfunction endfunction
@@ -124,22 +117,21 @@ endfunction
" If the optional argument provided and nonzero, " 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 " Returns: 1 iff directory exists or successfully created
function! vimwiki#path#mkdir(path, ...) function! vimwiki#path#mkdir(dir_obj, ...)
let path = expand(a:path)
if path =~# '^scp:' if a:dir_obj.protocoll ==# 'scp'
" we can not do much, so let's pretend everything is ok " we can not do much, so let's pretend everything is ok
return 1 return 1
endif endif
if isdirectory(path) if vimwiki#path#exists(a:dir_obj)
return 1 return 1
else else
if !exists("*mkdir") if !exists("*mkdir")
return 0 return 0
endif endif
let path = vimwiki#path#chomp_slash(path) let path = vimwiki#path#to_string(a:dir_obj)
if vimwiki#u#is_windows() && !empty(vimwiki#vars#get_global('w32_dir_enc')) if vimwiki#u#is_windows() && !empty(vimwiki#vars#get_global('w32_dir_enc'))
let path = iconv(path, &enc, vimwiki#vars#get_global('w32_dir_enc')) let path = iconv(path, &enc, vimwiki#vars#get_global('w32_dir_enc'))
endif endif
@@ -154,11 +146,11 @@ function! vimwiki#path#mkdir(path, ...)
endfunction endfunction
function! vimwiki#path#is_absolute(path) function! vimwiki#path#is_absolute(path_string)
if vimwiki#u#is_windows() if vimwiki#u#is_windows()
return a:path =~? '\m^\a:' return a:path_string =~? '\m^\a:'
else else
return a:path =~# '\m^/\|\~/' return a:path_string =~# '\m^/\|\~/'
endif endif
endfunction endfunction
@@ -181,3 +173,271 @@ else
endfunction endfunction
endif endif
"----------------------------------------------------------
" Path manipulation, i.e. functions which do stuff with the paths of (not necessarily existing) files
"----------------------------------------------------------
" The used data types are
"
" - directory object:
" - used for an absolute path to a directory
" - internally, it is a dictionary with the following entries:
" - 'protocoll' -- how to access the file. Supported are 'scp' or 'file'
" - 'is_unix' -- 1 if it's supposed to be a unix-like path
" - 'path' -- a list containing the directory names starting at the root
" - file object:
" - for an absolute path to a file
" - internally a list [dir_obj, file name]
" - file segment:
" - for a relative path to a file or a part of an absolute path
" - internally a list where the first element is a list of directory names and the second the
" file name
" - directory segment:
" - for a relative path to a directory or a part of an absolute path
" - internally a list of directory names
" create and return a file object from a string. It is assumed that the given
" path is absolute and points to a file (not a directory)
function! vimwiki#path#file_obj(filepath)
if a:filepath == ''
return vimwiki#path#null_file()
else
let filename = fnamemodify(a:filepath, ':p:t')
let path = fnamemodify(a:filepath, ':p:h')
return [vimwiki#path#dir_obj(path), filename]
endif
endfunction
function! vimwiki#path#null_file()
return []
endfunction
function! vimwiki#path#is_null(file)
return empty(a:file)
endfunction
" create and return a dir object from a string. The given path should be
" absolute and point to a directory.
function! vimwiki#path#dir_obj(dirpath)
if a:dirpath =~# '^scp:'
let dirpath = a:dirpath[4:]
let protocoll = 'scp'
else
let dirpath = resolve(fnamemodify(a:dirpath, ':p'))
let protocoll = 'file'
endif
let path = split(vimwiki#path#chomp_slash(dirpath), '\m[/\\]', 1)
let is_unix = dirpath[0] ==# '/'
let result = {
\ 'is_unix' : is_unix,
\ 'protocoll' : protocoll,
\ 'path' : path,
\}
return result
endfunction
" Assume it is not an absolute path
function! vimwiki#path#file_segment(path_segment)
let filename = fnamemodify(a:path_segment, ':t')
let path = fnamemodify(a:path_segment, ':h')
let path_list = (path ==# '.' ? [] : split(path, '\m[/\\]', 1))
return [path_list, filename]
endfunction
" Assume it is not an absolute path
function! vimwiki#path#dir_segment(path_segment)
return split(a:path_segment, '\m[/\\]', 1)
endfunction
function! vimwiki#path#extension(file_object)
return fnamemodify(a:file_object[1], ':e')
endfunction
function! vimwiki#path#set_extension(file_obj, new_ext)
let new_filename = vimwiki#path#filename_without_extension(a:file_obj) . '.' . a:new_ext
let a:file_obj[1] = new_filename
return a:file_obj
endfunction
function! vimwiki#path#filename_without_extension(file_object)
return fnamemodify(a:file_object[1], ':r')
endfunction
" Returns: the dir of the file object as dir object
function! vimwiki#path#directory_of_file(file_object)
return copy(a:file_object[0])
endfunction
" Returns: the file_obj's file name as a string
function! vimwiki#path#filename(file_object)
return a:file_object[1]
endfunction
" Returns: the dir_obj, file_obj, file segment or dir segment as string, ready
" to be used with the regular path handling functions in Vim
function! vimwiki#path#to_string(obj)
if type(a:obj) == 4 " dir object
let separator = a:obj.is_unix ? '/' : '\'
let address = join(dir_obj.path, separator) . separator
return address
elseif type(a:obj[0]) == 4 " file object
let dir_obj = type(a:obj) == 4 ? a:obj : a:obj[0]
let separator = a:obj[0].is_unix ? '/' : '\'
let address = join(a:obj[0].path, separator) . separator . a:obj[1]
return address
elseif type(a:obj[0]) == 3 " file segment
" XXX: what about the separator?
return join(a:obj[0], '/') . '/' . a:obj[1]
elseif type(a:obj[0]) == 1 " directory segment
return join(a:obj, '/') . '/'
else
call vimwiki#u#error('Invalid argument ' . string(a:obj))
endif
endfunction
" Returns: the given a:dir_obj with a:str appended to the dir name
function! vimwiki#path#append_to_dirname(dir_obj, str)
let a:dir_obj.path[-1] .= a:str
return a:dir_obj
endfunction
" Returns a file object made from a dir object plus a file semgent
function! vimwiki#path#join(dir_obj, file_segment)
let new_dir_object = copy(a:dir_obj)
let new_dir_object.path += a:file_segment[0]
return [new_dir_object, a:file_segment[1]]
endfunction
" Returns a dir object made from a dir object plus a dir semgent
function! vimwiki#path#join_dir(dir_path, dir_segment)
let new_dir_object = copy(a:dir_path)
let new_dir_object.path += a:dir_segment
return new_dir_object
endfunction
" returns the file segment fs, so that join(dir, fs) == file
" we just assume the file is somewhere in dir
function! vimwiki#path#subtract(dir_object, file_object)
let path_rest = a:file_object[0].path[len(a:dir_object.path):]
return [path_rest, file_object[1]]
endfunction
" Returns: the relative path from a:dir to a:file
" XXX wenn die beiden identisch sind, sollte . rauskommen
function! vimwiki#path#relpath(dir1_object, dir2_object)
let dir1_path = copy(a:dir1_object.path)
let dir2_path = copy(a:dir2_object.path)
let result_path = []
while (len(dir) > 0 && len(file) > 0) && vimwiki#path#is_equal(dir1_path[0], dir2_path[0])
call remove(dir1_path, 0)
call remove(dir2_path, 0)
endwhile
for segment in dir1_path
let result += ['..']
endfor
for segment in dir2_path
let result += [segment]
endfor
let result = {
\ 'is_unix' : a:dir1_object.is_unix,
\ 'protocoll' : a:dir1_object.protocoll,
\ 'path' : result_path,
\}
return result
endfunction
function! vimwiki#path#is_file_in_dir(file, dir)
let file_path_segments = a:file[0].path
let dir_path_segments = a:dir.path
if len(dir_path_segments) > len(file_path_segments)
return 0
endif
for i in range(len(a:dir.path))
if !vimwiki#path#is_equal(a:dir.path[i], file_path_segments[i])
return 0
endif
endfor
return 1
endfunction
"-----------------
" File manipulation, i.e. do stuff with actually existing files
"-----------------
function! vimwiki#path#current_file()
return vimwiki#path#file_obj(expand('%:p'))
endfunction
function! vimwiki#path#exists(object)
if type(a:object) == 4
return isdirectory(vimwiki#path#to_string(a:object))
else
if vimwiki#path#is_null(a:object)
return 0
endif
" glob() checks whether or not a file exists (readable or writable)
return glob(vimwiki#path#to_string(a:object)) != ''
endif
endfunction
function! vimwiki#path#is_executable(file)
return vimwiki#path#exists(a:file) && executable(vimwiki#path#to_string(a:file))
endfunction
" this must be outside a function, because only outside a function <sfile> expands
" to the directory where this file is in
let s:vimwiki_autoload_dir = expand('<sfile>:p:h')
function! vimwiki#path#find_autoload_file(filename)
let autoload_dir = vimwiki#path#dir_obj(s:vimwiki_autoload_dir)
let filename_obj = vimwiki#path#file_segment(a:filename)
let file = vimwiki#path#join(autoload_dir, filename_obj)
if !vimwiki#path#exists(file)
echom 'Vimwiki Error: ' . vimwiki#path#to_string(file) . ' not found'
endif
return file
endfunction
function! vimwiki#path#copy_file(file_obj, dir_obj)
call vimwiki#path#mkdir(a:dir_obj)
let new_file = deepcopy(a:file_obj)
let new_file[0] = copy(a:dir_obj)
let lines = readfile(vimwiki#path#to_string(a:file_obj))
let ok = writefile(lines, vimwiki#path#to_string(new_file))
if ok < 0
call vimwiki#u#error('Could not write ' . vimwiki#path#to_string(new_file))
endif
endfunction
" Returns: a list of all files somewhere in a:dir_obj with extension a:ext
function! vimwiki#path#files_in_dir_recursive(dir_obj, ext)
let separator = a:dir_obj.is_unix ? '/' : '\'
let glob_expression = vimwiki#path#to_string(a:dir_obj) . '**' . separator . '*.' . a:ext
let file_strings = split(glob(glob_expression), '\n')
return map(file_strings, 'vimwiki#path#file_obj(v:val)')
endfunction
+14 -8
View File
@@ -31,7 +31,7 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files)
let all_files = a:all_files != '' let all_files = a:all_files != ''
if !a:full_rebuild if !a:full_rebuild
" Updating for one page (current) " Updating for one page (current)
let page_name = vimwiki#vars#get_bufferlocal('subdir') . expand('%:t:r') let page_name = s:page_name(vimwiki#path#current_file())
" Collect tags in current file " Collect tags in current file
let tags = s:scan_tags(getline(1, '$'), page_name) let tags = s:scan_tags(getline(1, '$'), page_name)
" Load metadata file " Load metadata file
@@ -44,13 +44,12 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files)
call s:write_tags_metadata(metadata) call s:write_tags_metadata(metadata)
else " full rebuild else " full rebuild
let files = vimwiki#base#find_files(vimwiki#vars#get_bufferlocal('wiki_nr'), 0) let files = vimwiki#base#find_files(vimwiki#vars#get_bufferlocal('wiki_nr'), 0)
let wiki_base_dir = vimwiki#vars#get_wikilocal('path') let tags_file_last_modification =
let tags_file_last_modification = getftime(vimwiki#tags#metadata_file_path()) \ getftime(vimwiki#path#to_string(vimwiki#tags#metadata_file_path()))
let metadata = s:load_tags_metadata() let metadata = s:load_tags_metadata()
for file in files for file in files
if all_files || getftime(file) >= tags_file_last_modification if all_files || getftime(vimwiki#path#to_string(file)) >= tags_file_last_modification
let subdir = vimwiki#base#subdir(wiki_base_dir, file) let page_name = s:page_name(file)
let page_name = subdir . fnamemodify(file, ':t:r')
let tags = s:scan_tags(readfile(file), page_name) let tags = s:scan_tags(readfile(file), page_name)
let metadata = s:remove_page_from_tags(metadata, page_name) let metadata = s:remove_page_from_tags(metadata, page_name)
let metadata = s:merge_tags(metadata, page_name, tags) let metadata = s:merge_tags(metadata, page_name, tags)
@@ -61,6 +60,13 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files)
endfunction endfunction
function! s:page_name(file_obj)
let wiki_base_dir = vimwiki#vars#get_wikilocal('path')
let segment = vimwiki#path#subtract(wiki_base_dir, a:file_obj)
return vimwiki#path#to_string(segment)
endfunction
" Scans the list of text lines (argument) and produces tags metadata as a list of tag entries. " Scans the list of text lines (argument) and produces tags metadata as a list of tag entries.
function! s:scan_tags(lines, page_name) function! s:scan_tags(lines, page_name)
@@ -142,8 +148,8 @@ endfunction
" Returns tags metadata file path " Returns tags metadata file path
function! vimwiki#tags#metadata_file_path() abort function! vimwiki#tags#metadata_file_path() abort
return fnamemodify(vimwiki#path#join_path(vimwiki#vars#get_wikilocal('path'), return vimwiki#path#join(vimwiki#vars#get_wikilocal('path'),
\ s:TAGS_METADATA_FILE_NAME), ':p') \ vimwiki#path#file_segment(s:TAGS_METADATA_FILE_NAME))
endfunction endfunction
+4
View File
@@ -70,3 +70,7 @@ else
endfunc endfunc
endif endif
function vimwiki#u#error(message)
echom 'Vimwiki Error: ' . a:message
endfunction
+230 -87
View File
@@ -13,7 +13,7 @@
" global user variables and syntax stuff which is the same for every syntax. " 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 " - 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 " dictionaries, one dict for every registered wiki. The last dictionary contains default values
" (used for temporary wikis). " (used for temporary wikis).
" "
" - syntax variables. Stored in the dict g:vimwiki_syntax_variables which holds all the regexes and " - syntax variables. Stored in the dict g:vimwiki_syntax_variables which holds all the regexes and
@@ -28,50 +28,10 @@
function! s:populate_global_variables() function! s:populate_global_variables()
let g:vimwiki_global_vars = { let g:vimwiki_global_vars = {}
\ 'CJK_length': 0,
\ 'auto_chdir': 0,
\ 'autowriteall': 1,
\ 'conceallevel': 2,
\ 'diary_months':
\ {
\ 1: 'January', 2: 'February', 3: 'March',
\ 4: 'April', 5: 'May', 6: 'June',
\ 7: 'July', 8: 'August', 9: 'September',
\ 10: 'October', 11: 'November', 12: 'December'
\ },
\ 'dir_link': '',
\ 'ext2syntax': {},
\ 'folding': '',
\ 'global_ext': 1,
\ 'hl_cb_checked': 0,
\ 'hl_headers': 0,
\ '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,
\ 'table_mappings': 1,
\ 'toc_header': 'Contents',
\ 'url_maxsave': 15,
\ 'use_calendar': 1,
\ 'use_mouse': 0,
\ 'user_htmls': '',
\ 'valid_html_tags': 'b,i,s,u,sub,sup,kbd,br,hr,div,center,strong,em',
\ 'w32_dir_enc': '',
\ }
" copy the user's settings from variables of the form g:vimwiki_<option> into the dict call s:read_global_settings_from_user()
" g:vimwiki_global_vars (or set a default value) call s:normalize_global_settings()
for key in keys(g:vimwiki_global_vars)
if exists('g:vimwiki_'.key)
let g:vimwiki_global_vars[key] = g:vimwiki_{key}
endif
endfor
" non-configurable global variables: " non-configurable global variables:
@@ -179,31 +139,141 @@ function! s:populate_global_variables()
endfunction endfunction
function! s:read_global_settings_from_user()
let global_settings = {
\ 'CJK_length': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_chdir': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'autowriteall': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'conceallevel': {'type': type(0), 'default': 2, 'min': 0, 'max': 3},
\ 'diary_months': {'type': type({}), 'default':
\ {
\ 1: 'January', 2: 'February', 3: 'March',
\ 4: 'April', 5: 'May', 6: 'June',
\ 7: 'July', 8: 'August', 9: 'September',
\ 10: 'October', 11: 'November', 12: 'December'
\ }},
\ 'dir_link': {'type': type(''), 'default': ''},
\ 'ext2syntax': {'type': type({}), 'default': {}},
\ 'folding': {'type': type(''), 'default': '', 'possible_values': ['', 'expr', 'syntax',
\ 'list', 'custom', ':quick', 'expr:quick', 'syntax:quick', 'list:quick',
\ 'custom:quick']},
\ 'global_ext': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'hl_cb_checked': {'type': type(0), 'default': 0, 'min': 0, 'max': 2},
\ 'hl_headers': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'html_header_numbering': {'type': type(0), 'default': 0, 'min': 0, 'max': 6},
\ 'html_header_numbering_sym': {'type': type(''), 'default': ''},
\ 'list_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'text_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'listsyms': {'type': type(''), 'default': ' .oOX', 'min_length': 2},
\ 'listsym_rejected': {'type': type(''), 'default': '-', 'length': 1},
\ 'map_prefix': {'type': type(''), 'default': '<Leader>w'},
\ 'menu': {'type': type(''), 'default': 'Vimwiki'},
\ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'table_mappings': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'toc_header': {'type': type(''), 'default': 'Contents', 'min_length': 1},
\ 'url_maxsave': {'type': type(0), 'default': 15, 'min': 0},
\ 'use_calendar': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'use_mouse': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'user_htmls': {'type': type(''), 'default': ''},
\ 'valid_html_tags': {'type': type(''), 'default':
\ 'b,i,s,u,sub,sup,kbd,br,hr,div,center,strong,em'},
\ 'w32_dir_enc': {'type': type(''), 'default': ''},
\ }
" 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(global_settings)
if exists('g:vimwiki_'.key)
let users_value = g:vimwiki_{key}
let value_infos = global_settings[key]
call s:check_users_value(key, users_value, value_infos, 1)
let g:vimwiki_global_vars[key] = users_value
else
let g:vimwiki_global_vars[key] = global_settings[key].default
endif
endfor
" validate some settings individually
let key = 'diary_months'
let users_value = g:vimwiki_global_vars[key]
for month in range(1, 12)
if !has_key(users_value, month) || type(users_value[month]) != type('') ||
\ empty(users_value[month])
echom printf('Vimwiki Error: The provided value ''%s'' of the option ''g:vimwiki_%s'' is'
\ . ' invalid. See '':h g:vimwiki_%s''.', string(users_value), key, key)
break
endif
endfor
let key = 'ext2syntax'
let users_value = g:vimwiki_global_vars[key]
for ext in keys(users_value)
if empty(ext) || index(['markdown', 'media', 'mediawiki', 'default'], users_value[ext]) == -1
echom printf('Vimwiki Error: The provided value ''%s'' of the option ''g:vimwiki_%s'' is'
\ . ' invalid. See '':h g:vimwiki_%s''.', string(users_value), key, key)
break
endif
endfor
endfunction
function! s:normalize_global_settings()
let g:vimwiki_global_vars.dir_link =
\ vimwiki#path#file_segment(g:vimwiki_global_vars.dir_link)
let keys = keys(g:vimwiki_global_vars.ext2syntax)
for ext in keys
" ensure the file extensions in ext2syntax start with a dot
if ext[0] != '.'
let new_ext = '.' . ext
let g:vimwiki_global_vars.ext2syntax[new_ext] = g:vimwiki_global_vars.ext2syntax[ext]
call remove(g:vimwiki_global_vars.ext2syntax, ext)
endif
" for convenience, we also allow the term 'mediawiki'
if g:vimwiki_global_vars.ext2syntax[ext] ==# 'mediawiki'
let g:vimwiki_global_vars.ext2syntax[ext] = 'media'
endif
endfor
let new_user_htmls = []
for file_name in split(g:vimwiki_global_vars.user_htmls, ',')
let trimmed = vimwiki#u#trim(file_name)
call add(new_user_htmls, vimwiki#path#file_segment(trimmed))
endfor
let g:vimwiki_global_vars.user_htmls = new_user_htmls
endfunction
function! s:populate_wikilocal_options() function! s:populate_wikilocal_options()
let default_values = { let default_values = {
\ 'auto_diary_index': 0, \ 'auto_diary_index': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_export': 0, \ 'auto_export': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_tags': 0, \ 'auto_tags': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_toc': 0, \ 'auto_toc': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'automatic_nested_syntaxes': 1, \ 'automatic_nested_syntaxes': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'css_name': 'style.css', \ 'css_name': {'type': type(''), 'default': 'style.css', 'min_length': 1},
\ 'custom_wiki2html': '', \ 'custom_wiki2html': {'type': type(''), 'default': ''},
\ 'custom_wiki2html_args': '', \ 'custom_wiki2html_args': {'type': type(''), 'default': ''},
\ 'diary_header': 'Diary', \ 'diary_header': {'type': type(''), 'default': 'Diary', 'min_length': 1},
\ 'diary_index': 'diary', \ 'diary_index': {'type': type(''), 'default': 'diary', 'min_length': 1},
\ 'diary_rel_path': 'diary/', \ 'diary_rel_path': {'type': type(''), 'default': 'diary/', 'min_length': 1},
\ 'diary_sort': 'desc', \ 'diary_sort': {'type': type(''), 'default': 'desc', 'possible_values': ['asc', 'desc']},
\ 'ext': '.wiki', \ 'ext': {'type': type(''), 'default': '.wiki', 'min_length': 1},
\ 'index': 'index', \ 'index': {'type': type(''), 'default': 'index', 'min_length': 1},
\ 'list_margin': -1, \ 'list_margin': {'type': type(0), 'default': -1, 'min': -1},
\ 'maxhi': 0, \ 'maxhi': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'nested_syntaxes': {}, \ 'nested_syntaxes': {'type': type({}), 'default': {}},
\ 'path': $HOME . '/vimwiki/', \ 'path': {'type': type(''), 'default': $HOME . '/vimwiki/', 'min_length': 1},
\ 'path_html': '', \ 'path_html': {'type': type(''), 'default': ''},
\ 'syntax': 'default', \ 'syntax': {'type': type(''), 'default': 'default',
\ 'template_default': 'default', \ 'possible_values': ['default', 'markdown', 'media', 'mediawiki']},
\ 'template_ext': '.tpl', \ 'template_default': {'type': type(''), 'default': 'default', 'min_length': 1},
\ 'template_path': $HOME . '/vimwiki/templates/', \ 'template_ext': {'type': type(''), 'default': '.tpl'},
\ 'template_path': {'type': type(''), 'default': $HOME . '/vimwiki/templates/'},
\ } \ }
let g:vimwiki_wikilocal_vars = [] let g:vimwiki_wikilocal_vars = []
@@ -211,9 +281,10 @@ function! s:populate_wikilocal_options()
let default_wiki_settings = {} let default_wiki_settings = {}
for key in keys(default_values) for key in keys(default_values)
if exists('g:vimwiki_'.key) if exists('g:vimwiki_'.key)
call s:check_users_value(key, g:vimwiki_{key}, default_values[key], 1)
let default_wiki_settings[key] = g:vimwiki_{key} let default_wiki_settings[key] = g:vimwiki_{key}
else else
let default_wiki_settings[key] = default_values[key] let default_wiki_settings[key] = default_values[key].default
endif endif
endfor endfor
@@ -223,11 +294,10 @@ function! s:populate_wikilocal_options()
let new_wiki_settings = {} let new_wiki_settings = {}
for key in keys(default_values) for key in keys(default_values)
if has_key(users_wiki_settings, key) if has_key(users_wiki_settings, key)
call s:check_users_value(key, users_wiki_settings[key], default_values[key], 0)
let new_wiki_settings[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 else
let new_wiki_settings[key] = default_values[key] let new_wiki_settings[key] = default_wiki_settings[key]
endif endif
endfor endfor
@@ -247,29 +317,107 @@ function! s:populate_wikilocal_options()
let temporary_wiki_settings.is_temporary_wiki = 1 let temporary_wiki_settings.is_temporary_wiki = 1
call add(g:vimwiki_wikilocal_vars, temporary_wiki_settings) call add(g:vimwiki_wikilocal_vars, temporary_wiki_settings)
call s:validate_settings() " check some values individually
let key = 'nested_syntaxes'
for wiki_settings in g:vimwiki_wikilocal_vars
let users_value = wiki_settings[key]
for keyword in keys(users_value)
if type(keyword) != type('') || empty(keyword) || type(users_value[keyword]) != type('') ||
\ empty(users_value[keyword])
echom printf('Vimwiki Error: The provided value ''%s'' of the option ''g:vimwiki_%s'' is'
\ . ' invalid. See '':h g:vimwiki_%s''.', string(users_value), key, key)
break
endif
endfor
endfor
call s:normalize_wikilocal_settings()
endfunction endfunction
function! s:validate_settings() function! s:check_users_value(key, users_value, value_infos, comes_from_global_variable)
let type_code_to_name = {
\ type(0): 'number',
\ type(''): 'string',
\ type([]): 'list',
\ type({}): 'dictionary'}
let setting_origin = a:comes_from_global_variable ?
\ printf('''g:vimwiki_%s''', a:key) :
\ printf('''%s'' in g:vimwiki_list', a:key)
if has_key(a:value_infos, 'type') && type(a:users_value) != a:value_infos.type
echom printf('Vimwiki Error: The provided value of the option %s is a %s, ' .
\ 'but expected is a %s. See '':h g:vimwiki_%s''.', setting_origin,
\ type_code_to_name[type(a:users_value)], type_code_to_name[a:value_infos.type], a:key)
endif
if a:value_infos.type == type(0) && has_key(a:value_infos, 'min') &&
\ a:users_value < a:value_infos.min
echom printf('Vimwiki Error: The provided value ''%i'' of the option %s is'
\ . ' too small. The minimum value is %i. See '':h g:vimwiki_%s''.', a:users_value,
\ setting_origin, a:value_infos.min, a:key)
endif
if a:value_infos.type == type(0) && has_key(a:value_infos, 'max') &&
\ a:users_value > a:value_infos.max
echom printf('Vimwiki Error: The provided value ''%i'' of the option %s is'
\ . ' too large. The maximum value is %i. See '':h g:vimwiki_%s''.', a:users_value,
\ setting_origin, a:value_infos.max, a:key)
endif
if has_key(a:value_infos, 'possible_values') &&
\ index(a:value_infos.possible_values, a:users_value) == -1
echom printf('Vimwiki Error: The provided value ''%s'' of the option %s is'
\ . ' invalid. Allowed values are %s. See ''g:vimwiki_%s''.', a:users_value,
\ setting_origin, string(a:value_infos.possible_values), a:key)
endif
if a:value_infos.type == type('') && has_key(a:value_infos, 'length') &&
\ strwidth(a:users_value) != a:value_infos.length
echom printf('Vimwiki Error: The provided value ''%s'' of the option %s must'
\ . ' contain exactly %i character(s) but has %i. See '':h g:vimwiki_%s''.',
\ a:users_value, setting_origin, a:value_infos.length, strwidth(a:users_value), a:key)
endif
if a:value_infos.type == type('') && has_key(a:value_infos, 'min_length') &&
\ strwidth(a:users_value) < a:value_infos.min_length
echom printf('Vimwiki Error: The provided value ''%s'' of the option %s must'
\ . ' have at least %d character(s) but has %d. See '':h g:vimwiki_%s''.', a:users_value,
\ setting_origin, a:value_infos.min_length, strwidth(a:users_value), a:key)
endif
endfunction
function! s:normalize_wikilocal_settings()
for wiki_settings in g:vimwiki_wikilocal_vars for wiki_settings in g:vimwiki_wikilocal_vars
let wiki_settings['path'] = s:normalize_path(wiki_settings['path']) let wiki_settings.css_name = vimwiki#path#file_segment(wiki_settings.css_name)
let wiki_settings.custom_wiki2html = vimwiki#path#file_object(wiki_settings.custom_wiki2html)
let wiki_settings['path'] = vimwiki#path#dir_obj(wiki_settings['path'])
let path_html = wiki_settings['path_html'] let path_html = wiki_settings['path_html']
if !empty(path_html) if !empty(path_html)
let wiki_settings['path_html'] = s:normalize_path(path_html) let wiki_settings['path_html'] = vimwiki#path#dir_obj(path_html)
else else
let wiki_settings['path_html'] = s:normalize_path( let wiki_settings['path_html'] = vimwiki#path#append_to_dirname(wiki_settings['path'],
\ substitute(wiki_settings['path'], '[/\\]\+$', '', '').'_html/') \ '_html')
endif endif
let wiki_settings['template_path'] = s:normalize_path(wiki_settings['template_path']) let wiki_settings['template_path'] = vimwiki#path#dir_obj(wiki_settings['template_path'])
let wiki_settings['diary_rel_path'] = s:normalize_path(wiki_settings['diary_rel_path']) let wiki_settings['diary_path'] = vimwiki#path#join_dir(wiki_settings['path'],
\ vimwiki#path#dir_segment(wiki_settings['diary_rel_path']))
let ext = wiki_settings['ext'] let ext = wiki_settings['ext']
if !empty(ext) && ext[0] != '.' if !empty(ext) && ext[0] != '.'
let wiki_settings['ext'] = '.' . ext let wiki_settings['ext'] = '.' . ext
endif endif
" for convenience, we also allow the term 'mediawiki'
if wiki_settings.syntax ==# 'mediawiki'
let wiki_settings.syntax = 'media'
endif
endfor endfor
endfunction endfunction
@@ -641,15 +789,10 @@ function! vimwiki#vars#get_bufferlocal(key, ...)
if type(value) != 1 || value !=# '/\/\' if type(value) != 1 || value !=# '/\/\'
return value return value
elseif a:key ==# 'wiki_nr' elseif a:key ==# 'wiki_nr'
call setbufvar(buffer, 'vimwiki_wiki_nr', vimwiki#base#find_wiki(expand('%:p'))) call setbufvar(buffer, 'vimwiki_wiki_nr', vimwiki#base#find_wiki(vimwiki#path#current_file()))
elseif a:key ==# 'subdir'
call setbufvar(buffer, 'vimwiki_subdir', vimwiki#base#current_subdir())
elseif a:key ==# 'invsubdir'
let subdir = vimwiki#vars#get_bufferlocal('subdir')
call setbufvar(buffer, 'vimwiki_invsubdir', vimwiki#base#invsubdir(subdir))
elseif a:key ==# 'existing_wikifiles' elseif a:key ==# 'existing_wikifiles'
call setbufvar(buffer, 'vimwiki_existing_wikifiles', call setbufvar(buffer, 'vimwiki_existing_wikifiles',
\ vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 1)) \ vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0, 1))
elseif a:key ==# 'existing_wikidirs' elseif a:key ==# 'existing_wikidirs'
call setbufvar(buffer, 'vimwiki_existing_wikidirs', call setbufvar(buffer, 'vimwiki_existing_wikidirs',
\ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr'))) \ vimwiki#base#get_wiki_directories(vimwiki#vars#get_bufferlocal('wiki_nr')))
@@ -706,7 +849,7 @@ function! vimwiki#vars#add_temporary_wiki(settings)
let new_temp_wiki_settings[key] = value let new_temp_wiki_settings[key] = value
endfor endfor
call insert(g:vimwiki_wikilocal_vars, new_temp_wiki_settings, -1) call insert(g:vimwiki_wikilocal_vars, new_temp_wiki_settings, -1)
call s:validate_settings() call s:normalize_wikilocal_settings()
endfunction endfunction
+5 -4
View File
@@ -2548,11 +2548,11 @@ A second example handles a new scheme, "vfile:", which behaves similar to
return 0 return 0
endif endif
let link_infos = vimwiki#base#resolve_link(link) let link_infos = vimwiki#base#resolve_link(link)
if link_infos.filename == '' if link_infos.is_file == -1
echomsg 'Vimwiki Error: Unable to resolve link!' echomsg 'Vimwiki Error: Unable to resolve link!'
return 0 return 0
else else
exe 'tabnew ' . fnameescape(link_infos.filename) exe 'tabnew ' . fnameescape(vimwiki#path#to_string(link_infos.target))
return 1 return 1
endif endif
endfunction endfunction
@@ -2577,11 +2577,12 @@ right place. >
function! VimwikiLinkConverter(link, source_wiki_file, target_html_file) function! VimwikiLinkConverter(link, source_wiki_file, target_html_file)
if a:link =~# '^local:' if a:link =~# '^local:'
let link_infos = vimwiki#base#resolve_link(a:link) let link_infos = vimwiki#base#resolve_link(a:link)
let target_file = vimwiki#path#to_string(link_infos.target)
let html_link = vimwiki#path#relpath( let html_link = vimwiki#path#relpath(
\ fnamemodify(a:source_wiki_file, ':h'), link_infos.filename) \ fnamemodify(a:source_wiki_file, ':h'), target_file)
let relative_link = let relative_link =
\ fnamemodify(a:target_html_file, ':h') . '/' . html_link \ fnamemodify(a:target_html_file, ':h') . '/' . html_link
call system('cp ' . fnameescape(link_infos.filename) . call system('cp ' . fnameescape(target_file) .
\ ' ' . fnameescape(relative_link)) \ ' ' . fnameescape(relative_link))
return html_link return html_link
endif endif
+20 -18
View File
@@ -19,7 +19,7 @@ endif
execute 'setlocal suffixesadd='.vimwiki#vars#get_wikilocal('ext') execute 'setlocal suffixesadd='.vimwiki#vars#get_wikilocal('ext')
setlocal isfname-=[,] setlocal isfname-=[,]
exe "setlocal tags+=" . escape(vimwiki#tags#metadata_file_path(), ' \|"') exe "setlocal tags+=" . escape(vimwiki#path#to_string(vimwiki#tags#metadata_file_path()), ' \|"')
@@ -68,19 +68,22 @@ function! Complete_wikifiles(findstart, base)
if wikinumber >= vimwiki#vars#number_of_wikis() if wikinumber >= vimwiki#vars#number_of_wikis()
return [] return []
endif endif
let diary = 0
let prefix = matchstr(a:base, '\m^wiki\d\+:\zs.*') let prefix = matchstr(a:base, '\m^wiki\d\+:\zs.*')
let scheme = matchstr(a:base, '\m^wiki\d\+:\ze') let scheme = matchstr(a:base, '\m^wiki\d\+:\ze')
elseif a:base =~# '^diary:' elseif a:base =~# '^diary:'
let wikinumber = -1 let wikinumber = vimwiki#vars#get_bufferlocal('wiki_nr')
let diary = 1
let prefix = matchstr(a:base, '^diary:\zs.*') let prefix = matchstr(a:base, '^diary:\zs.*')
let scheme = matchstr(a:base, '^diary:\ze') let scheme = matchstr(a:base, '^diary:\ze')
else " current wiki else " current wiki
let wikinumber = vimwiki#vars#get_bufferlocal('wiki_nr') let wikinumber = vimwiki#vars#get_bufferlocal('wiki_nr')
let diary = 0
let prefix = a:base let prefix = a:base
let scheme = '' let scheme = ''
endif endif
let links = vimwiki#base#get_wikilinks(wikinumber, 1) let links = vimwiki#base#get_wikilinks(wikinumber, diary, 1)
let result = [] let result = []
for wikifile in links for wikifile in links
if wikifile =~ '^'.vimwiki#u#escape(prefix) if wikifile =~ '^'.vimwiki#u#escape(prefix)
@@ -93,9 +96,11 @@ function! Complete_wikifiles(findstart, base)
" we look for anchors in the given wikifile " we look for anchors in the given wikifile
let segments = split(a:base, '#', 1) let segments = split(a:base, '#', 1)
let given_wikifile = segments[0] == '' ? expand('%:t:r') : segments[0] let given_wikifile = segments[0] == '' ?
\ vimwiki#path#filename_without_extension(vimwiki#path#current_file())
\ : segments[0]
let link_infos = vimwiki#base#resolve_link(given_wikifile.'#') let link_infos = vimwiki#base#resolve_link(given_wikifile.'#')
let wikifile = link_infos.filename let wikifile = link_infos.target
let syntax = vimwiki#vars#get_wikilocal('syntax', link_infos.index) let syntax = vimwiki#vars#get_wikilocal('syntax', link_infos.index)
let anchors = vimwiki#base#get_anchors(wikifile, syntax) let anchors = vimwiki#base#get_anchors(wikifile, syntax)
@@ -237,19 +242,18 @@ endfunction
command! -buffer Vimwiki2HTML command! -buffer Vimwiki2HTML
\ if filewritable(expand('%')) | silent noautocmd w | endif \ if filewritable(expand('%')) | silent noautocmd w | endif
\ <bar> \ <bar>
\ let res = vimwiki#html#Wiki2HTML(expand(vimwiki#vars#get_wikilocal('path_html')), \ let res = vimwiki#html#Wiki2HTML(vimwiki#path#current_file())
\ expand('%'))
\ <bar> \ <bar>
\ if res != '' | echo 'Vimwiki: HTML conversion is done, output: ' \ if !vimwiki#path#is_null(res) | echo 'Vimwiki: HTML conversion is done, output: '
\ . expand(vimwiki#vars#get_wikilocal('path_html')) | endif \ . vimwiki#path#to_string(vimwiki#vars#get_wikilocal('path_html')) | endif
command! -buffer Vimwiki2HTMLBrowse command! -buffer Vimwiki2HTMLBrowse
\ if filewritable(expand('%')) | silent noautocmd w | endif \ if filewritable(expand('%')) | silent noautocmd w | endif
\ <bar> \ <bar>
\ call vimwiki#base#system_open_link(vimwiki#html#Wiki2HTML( \ let result = vimwiki#html#Wiki2HTML(vimwiki#path#current_file())
\ expand(vimwiki#vars#get_wikilocal('path_html')), \ <bar>
\ expand('%'))) \ if !vimwiki#path#is_null(result) | call vimwiki#base#system_open_link(result) | endif
command! -buffer VimwikiAll2HTML command! -buffer VimwikiAll2HTML
\ call vimwiki#html#WikiAll2HTML(expand(vimwiki#vars#get_wikilocal('path_html'))) \ call vimwiki#html#WikiAll2HTML()
command! -buffer VimwikiTOC call vimwiki#base#table_of_contents(1) command! -buffer VimwikiTOC call vimwiki#base#table_of_contents(1)
@@ -272,10 +276,10 @@ command! -buffer -nargs=0 VimwikiBacklinks call vimwiki#base#backlinks()
command! -buffer -nargs=0 VWB call vimwiki#base#backlinks() command! -buffer -nargs=0 VWB call vimwiki#base#backlinks()
exe 'command! -buffer -nargs=* VimwikiSearch lvimgrep <args> '. exe 'command! -buffer -nargs=* VimwikiSearch lvimgrep <args> '.
\ escape(vimwiki#vars#get_wikilocal('path').'**/*'.vimwiki#vars#get_wikilocal('ext'), ' ') \ escape(vimwiki#path#to_string(vimwiki#vars#get_wikilocal('path')).'**/*'.vimwiki#vars#get_wikilocal('ext'), ' ')
exe 'command! -buffer -nargs=* VWS lvimgrep <args> '. exe 'command! -buffer -nargs=* VWS lvimgrep <args> '.
\ escape(vimwiki#vars#get_wikilocal('path').'**/*'.vimwiki#vars#get_wikilocal('ext'), ' ') \ escape(vimwiki#path#to_string(vimwiki#vars#get_wikilocal('path')).'**/*'.vimwiki#vars#get_wikilocal('ext'), ' ')
command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links_escaped command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links_escaped
\ VimwikiGoto call vimwiki#base#goto(<f-args>) \ VimwikiGoto call vimwiki#base#goto(<f-args>)
@@ -677,9 +681,7 @@ nnoremap <silent><buffer> <Plug>VimwikiGoToPrevSiblingHeader :
if vimwiki#vars#get_wikilocal('auto_export') if vimwiki#vars#get_wikilocal('auto_export')
" Automatically generate HTML on page write. " Automatically generate HTML on page write.
augroup vimwiki augroup vimwiki
au BufWritePost <buffer> au BufWritePost <buffer> call vimwiki#html#Wiki2HTML(vimwiki#path#current_file())
\ call vimwiki#html#Wiki2HTML(expand(vimwiki#vars#get_wikilocal('path_html')),
\ expand('%'))
augroup END augroup END
endif endif
+8 -7
View File
@@ -31,7 +31,7 @@ function! s:setup_buffer_leave()
let &autowriteall = s:vimwiki_autowriteall_saved let &autowriteall = s:vimwiki_autowriteall_saved
if vimwiki#vars#get_global('menu') != "" if !empty(vimwiki#vars#get_global('menu'))
exe 'nmenu disable '.vimwiki#vars#get_global('menu').'.Table' exe 'nmenu disable '.vimwiki#vars#get_global('menu').'.Table'
endif endif
endfunction endfunction
@@ -39,8 +39,9 @@ endfunction
" create a new temporary wiki for the current buffer " create a new temporary wiki for the current buffer
function! s:create_temporary_wiki() function! s:create_temporary_wiki()
let path = expand('%:p:h') let current_file = vimwiki#path#current_file()
let ext = '.'.expand('%:e') let path = vimwiki#path#directory_of_file(current_file)
let ext = '.'.vimwiki#path#extension(current_file)
let syntax_mapping = vimwiki#vars#get_global('ext2syntax') let syntax_mapping = vimwiki#vars#get_global('ext2syntax')
if has_key(syntax_mapping, ext) if has_key(syntax_mapping, ext)
@@ -147,7 +148,7 @@ function! s:set_global_options()
let s:vimwiki_autowriteall_saved = &autowriteall let s:vimwiki_autowriteall_saved = &autowriteall
let &autowriteall = vimwiki#vars#get_global('autowriteall') let &autowriteall = vimwiki#vars#get_global('autowriteall')
if vimwiki#vars#get_global('menu') !=# '' if !empty(vimwiki#vars#get_global('menu'))
exe 'nmenu enable '.vimwiki#vars#get_global('menu').'.Table' exe 'nmenu enable '.vimwiki#vars#get_global('menu').'.Table'
endif endif
endfunction endfunction
@@ -183,7 +184,7 @@ function! s:set_windowlocal_options()
endif endif
if vimwiki#vars#get_global('auto_chdir') if vimwiki#vars#get_global('auto_chdir')
exe 'lcd' vimwiki#vars#get_wikilocal('path') exe 'lcd' vimwiki#path#to_string(vimwiki#vars#get_wikilocal('path'))
endif endif
endfunction endfunction
@@ -338,8 +339,8 @@ nnoremap <unique><script> <Plug>VimwikiMakeTomorrowDiaryNote
function! s:build_menu(topmenu) function! s:build_menu(topmenu)
for idx in range(vimwiki#vars#number_of_wikis()) for idx in range(vimwiki#vars#number_of_wikis())
let norm_path = fnamemodify(vimwiki#vars#get_wikilocal('path', idx), ':h:t') let norm_path = vimwiki#path#to_string(vimwiki#vars#get_wikilocal('path', idx))
let norm_path = escape(norm_path, '\ \.') let norm_path = escape(norm_path, '\ .')
execute 'menu '.a:topmenu.'.Open\ index.'.norm_path. execute 'menu '.a:topmenu.'.Open\ index.'.norm_path.
\ ' :call vimwiki#base#goto_index('.(idx+1).')<CR>' \ ' :call vimwiki#base#goto_index('.(idx+1).')<CR>'
execute 'menu '.a:topmenu.'.Open/Create\ diary\ note.'.norm_path. execute 'menu '.a:topmenu.'.Open/Create\ diary\ note.'.norm_path.