From 8d7d568214cff5b9932b5ad1d0aeca39b8798969 Mon Sep 17 00:00:00 2001 From: EinfachToll Date: Mon, 23 Feb 2015 12:10:42 +0100 Subject: [PATCH 1/6] Clean up all file headers - remove author names. There's git blame for this job - change home from code.google to github - add short descriptions --- autoload/vimwiki/base.vim | 4 ++-- autoload/vimwiki/diary.vim | 3 +-- autoload/vimwiki/html.vim | 5 ++--- autoload/vimwiki/lst.vim | 5 ++--- autoload/vimwiki/markdown_base.vim | 3 +-- autoload/vimwiki/path.vim | 5 ++--- autoload/vimwiki/tbl.vim | 3 +-- autoload/vimwiki/u.vim | 5 ++--- ftplugin/vimwiki.vim | 3 +-- plugin/vimwiki.vim | 3 +-- syntax/omnipresent_syntax.vim | 5 ++--- syntax/vimwiki.vim | 3 +-- syntax/vimwiki_default.vim | 5 ++--- syntax/vimwiki_markdown.vim | 5 ++--- syntax/vimwiki_markdown_custom.vim | 4 ++-- syntax/vimwiki_media.vim | 5 ++--- 16 files changed, 26 insertions(+), 40 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index de0d34f..b563265 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1,7 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki autoload plugin file -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Desc: Basic functionality +" Home: https://github.com/vimwiki/vimwiki/ if exists("g:loaded_vimwiki_auto") || &cp finish diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim index 394edab..d131efe 100644 --- a/autoload/vimwiki/diary.vim +++ b/autoload/vimwiki/diary.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki autoload plugin file " Desc: Handle diary notes -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Home: https://github.com/vimwiki/vimwiki/ " Load only once {{{ if exists("g:loaded_vimwiki_diary_auto") || &cp diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim index baa558f..83aa5e5 100644 --- a/autoload/vimwiki/html.vim +++ b/autoload/vimwiki/html.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki autoload plugin file -" Export to HTML -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Desc: Export to HTML +" Home: https://github.com/vimwiki/vimwiki/ " TODO: We need vimwiki abstract syntax tree. If properly designed it wourld " greatly symplify different syntax to HTML generation. diff --git a/autoload/vimwiki/lst.vim b/autoload/vimwiki/lst.vim index 78690ad..db1680a 100644 --- a/autoload/vimwiki/lst.vim +++ b/autoload/vimwiki/lst.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki autoload plugin file -" Everything concerning bulleted and numbered lists and checkboxes -" Author: Daniel Schemala -" Home: http://code.google.com/p/vimwiki/ +" Desc: Everything concerning lists and checkboxes +" Home: https://github.com/vimwiki/vimwiki/ if exists("g:loaded_vimwiki_list_auto") || &cp finish diff --git a/autoload/vimwiki/markdown_base.vim b/autoload/vimwiki/markdown_base.vim index 8082c30..dcfffe9 100644 --- a/autoload/vimwiki/markdown_base.vim +++ b/autoload/vimwiki/markdown_base.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki autoload plugin file " Desc: Link functions for markdown syntax -" Author: Stuart Andrews (.. i.e. don't blame Maxim!) -" Home: http://code.google.com/p/vimwiki/ +" Home: https://github.com/vimwiki/vimwiki/ " MISC helper functions {{{ diff --git a/autoload/vimwiki/path.vim b/autoload/vimwiki/path.vim index ef4b810..71073bd 100644 --- a/autoload/vimwiki/path.vim +++ b/autoload/vimwiki/path.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki autoload plugin file -" Path manipulation functions -" Author: Daniel Schemala -" Home: http://code.google.com/p/vimwiki/ +" Desc: Path manipulation functions +" Home: https://github.com/vimwiki/vimwiki/ function! vimwiki#path#chomp_slash(str) "{{{ diff --git a/autoload/vimwiki/tbl.vim b/autoload/vimwiki/tbl.vim index 8d2432b..d8c1cb3 100644 --- a/autoload/vimwiki/tbl.vim +++ b/autoload/vimwiki/tbl.vim @@ -5,8 +5,7 @@ " |--------|------------|-------|--------|---------| " | Have | fun! | Drink | tea | Period. | " -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Home: https://github.com/vimwiki/vimwiki/ " Load only once {{{ if exists("g:loaded_vimwiki_tbl_auto") || &cp diff --git a/autoload/vimwiki/u.vim b/autoload/vimwiki/u.vim index a80af9b..cfe0f7a 100644 --- a/autoload/vimwiki/u.vim +++ b/autoload/vimwiki/u.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki autoload plugin file -" Utility functions -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Desc: Utility functions +" Home: https://github.com/vimwiki/vimwiki/ function! vimwiki#u#trim(string, ...) "{{{ let chars = '' diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 2364f2c..02d73c0 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -1,7 +1,6 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki filetype plugin file -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Home: https://github.com/vimwiki/vimwiki/ if exists("b:did_ftplugin") finish diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim index df3bac5..53155a6 100644 --- a/plugin/vimwiki.vim +++ b/plugin/vimwiki.vim @@ -1,7 +1,6 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki plugin file -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Home: https://github.com/vimwiki/vimwiki/ " GetLatestVimScripts: 2226 1 :AutoInstall: vimwiki if exists("g:loaded_vimwiki") || &cp diff --git a/syntax/omnipresent_syntax.vim b/syntax/omnipresent_syntax.vim index fac11d9..612e63d 100644 --- a/syntax/omnipresent_syntax.vim +++ b/syntax/omnipresent_syntax.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki syntax file -" Syntax definitions which are always available -" Author: Daniel Schemala -" Home: http://code.google.com/p/vimwiki/ +" Desc: Syntax definitions which are always available +" Home: https://github.com/vimwiki/vimwiki/ " Define Regexes of anchors for every syntax. diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim index edb1cf8..93e780c 100644 --- a/syntax/vimwiki.vim +++ b/syntax/vimwiki.vim @@ -1,7 +1,6 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki syntax file -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Home: https://github.com/vimwiki/vimwiki/ " Quit if syntax file is already loaded if version < 600 diff --git a/syntax/vimwiki_default.vim b/syntax/vimwiki_default.vim index d4b0a6c..6023539 100644 --- a/syntax/vimwiki_default.vim +++ b/syntax/vimwiki_default.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki syntax file -" Default syntax -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Desc: Defines default syntax +" Home: https://github.com/vimwiki/vimwiki/ " text: $ equation_inline $ let g:vimwiki_rxEqIn = '\$[^$`]\+\$' diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim index 82c3a07..31667e2 100644 --- a/syntax/vimwiki_markdown.vim +++ b/syntax/vimwiki_markdown.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki syntax file -" Default syntax -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Desc: Defines markdown syntax +" Home: https://github.com/vimwiki/vimwiki/ " text: $ equation_inline $ let g:vimwiki_rxEqIn = '\$[^$`]\+\$' diff --git a/syntax/vimwiki_markdown_custom.vim b/syntax/vimwiki_markdown_custom.vim index 579001c..b1658fd 100644 --- a/syntax/vimwiki_markdown_custom.vim +++ b/syntax/vimwiki_markdown_custom.vim @@ -1,7 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki syntax file -" Author: Stuart Andrews -" Home: http://code.google.com/p/vimwiki/ +" Desc: Special stuff for markdown syntax +" Home: https://github.com/vimwiki/vimwiki/ " LINKS: assume this is common to all syntaxes "{{{ diff --git a/syntax/vimwiki_media.vim b/syntax/vimwiki_media.vim index 9a85083..37c24db 100644 --- a/syntax/vimwiki_media.vim +++ b/syntax/vimwiki_media.vim @@ -1,8 +1,7 @@ " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " Vimwiki syntax file -" MediaWiki syntax -" Author: Maxim Kim -" Home: http://code.google.com/p/vimwiki/ +" Desc: Defines mediaWiki syntax +" Home: https://github.com/vimwiki/vimwiki/ " text: $ equation_inline $ let g:vimwiki_rxEqIn = '\$[^$`]\+\$' From 6922836a0cbfb7e539bb1cf458eb8f1619d6188f Mon Sep 17 00:00:00 2001 From: EinfachToll Date: Fri, 13 Mar 2015 16:31:15 +0100 Subject: [PATCH 2/6] Wiki links starting with / are always relative to the wiki root Also, links with the file: scheme are absolute iff they start with / or drive letter Ref #105 --- autoload/vimwiki/base.vim | 230 +++++++++++++++++++++++++------------- autoload/vimwiki/path.vim | 5 +- ftplugin/vimwiki.vim | 6 +- plugin/vimwiki.vim | 23 +--- 4 files changed, 160 insertions(+), 104 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index b563265..0b19b35 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -224,6 +224,143 @@ function! vimwiki#base#invsubdir(subdir) " {{{ return substitute(a:subdir, '[^/\.]\+/', '../', 'g') endfunction " }}} + +" Returns: the number of the wiki a file belongs to +function! vimwiki#base#find_wiki(path) "{{{ + let path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(a:path)) + let idx = 0 + while idx < len(g:vimwiki_list) + let idx_path = expand(VimwikiGet('path', idx)) + let idx_path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(idx_path)) + if vimwiki#path#is_equal( + \ vimwiki#path#path_common_pfx(idx_path, path), idx_path) + return idx + endif + let idx += 1 + endwhile + + " an orphan page has been detected + return -1 +endfunction "}}} + + +" THE central function of Vimwiki. Extract infos about the target from a link. +" If the second parameter is present, which should be an absolute file path, it +" is assumed that the link appears in that file. Without it, the current file +" is used. +function! vimwiki#base#resolve_link(link_text, ...) "{{{ + if a:0 + let source_wiki = vimwiki#base#find_wiki(a:1) + let source_file = a:1 + else + let source_wiki = g:vimwiki_current_idx + let source_file = expand('%:p') + endif + + let link_text = a:link_text + + " if link is schemeless add wikiN: scheme + if link_text !~# g:vimwiki_rxSchemeUrl + let link_text = 'wiki'.source_wiki.':'.link_text + endif + + + let link_infos = { + \ 'index': -1, + \ 'scheme': '', + \ 'filename': '', + \ 'anchor': '', + \ } + + + " extract scheme + let link_infos.scheme = matchstr(link_text, g:vimwiki_rxSchemeUrlMatchScheme) + if !(link_infos.scheme =~# '\mwiki\d\+' || link_infos.scheme ==# 'diary' || + \ link_infos.scheme ==# 'local' || link_infos.scheme ==# 'file') + let link_infos.filename = '' " malformed link + return link_infos + endif + let link_text = matchstr(link_text, g:vimwiki_rxSchemeUrlMatchUrl) + + let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' || + \ link_infos.scheme ==# 'diary' + + " extract anchor + if is_wiki_link + let split_lnk = split(link_text, '#', 1) + let link_text = split_lnk[0] + if len(split_lnk) > 1 && split_lnk[-1] != '' + let link_infos.anchor = join(split_lnk[1:], '#') + endif + if link_text == '' " because the link was of the form '#anchor' + let link_text = fnamemodify(source_file, ':p:t:r') + endif + endif + + " check if absolute or relative path + if is_wiki_link && link_text[0] == '/' + let link_text = link_text[1:] + let is_relative = 0 + elseif !is_wiki_link && (link_text[0] == '/' || + \ (link_text =~? '\m^\a:' && vimwiki#u#is_windows())) + let is_relative = 0 + else + let is_relative = 1 + let root_dir = fnamemodify(source_file, ':p:h') . '/' + endif + + + " extract the other items depending on the scheme + if link_infos.scheme =~# '\mwiki\d\+' + let link_infos.index = eval(matchstr(link_infos.scheme, '\D\+\zs\d\+\ze')) + if link_infos.index < 0 || link_infos.index >= len(g:vimwiki_list) + let link_infos.filename = '' + return link_infos + endif + + if !is_relative + let root_dir = VimwikiGet('path', link_infos.index) + endif + + let link_infos.filename = root_dir . link_text + + if vimwiki#path#is_link_to_dir(link_text) + if g:vimwiki_dir_link != '' + let link_infos.filename .= g:vimwiki_dir_link . + \ VimwikiGet('ext', link_infos.index) + endif + else + let link_infos.filename .= VimwikiGet('ext', link_infos.index) + endif + + elseif link_infos.scheme ==# 'diary' + let link_infos.index = source_wiki + + let link_infos.filename = + \ VimwikiGet('path', link_infos.index) . + \ VimwikiGet('diary_rel_path', link_infos.index) . + \ link_text . + \ VimwikiGet('ext', link_infos.index) + elseif (link_infos.scheme ==# 'file' && is_relative) || + \ link_infos.scheme ==# 'local' + let link_infos.filename = root_dir . link_text + else " absolute file link + " collapse repeated leading "/"'s within a link + let link_text = substitute(link_text, '\m^/*', '/', '') + " convert "/~..." into "~..." for fnamemodify + let link_text = substitute(link_text, '\m^/\~', '\~', '') + " convert /C: to C: (or fnamemodify(...":p:h") interpret it as C:\C:) + if vimwiki#u#is_windows() + let link_text = substitute(link_text, '\m^/\ze[[:alpha:]]:', '', '') + endif + let link_infos.filename = link_text + endif + + let link_infos.filename = vimwiki#path#normalize(link_infos.filename) + return link_infos +endfunction "}}} + + " vimwiki#base#resolve_scheme function! vimwiki#base#resolve_scheme(lnk, as_html, ...) " {{{ Resolve scheme let quiet = a:0 && a:1 ? 1 : 0 @@ -405,31 +542,22 @@ endfunction "}}} " vimwiki#base#open_link function! vimwiki#base#open_link(cmd, link, ...) "{{{ - let [idx, scheme, path, subdir, lnk, ext, url, anchor] = - \ vimwiki#base#resolve_scheme(a:link, 0) + let link_infos = vimwiki#base#resolve_link(a:link) - " wikilinks of the form [[#anchor]] - if url == '' && anchor != '' - let lnk = expand('%:t:r') - let url = path.subdir.lnk.ext + if g:vimwiki_debug + echom 'open_link:' string(link_infos) endif - if url == '' - if g:vimwiki_debug - echom 'open_link: idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.', url='.url.', anchor='.anchor - endif + if link_infos.filename == '' echom 'Vimwiki Error: Unable to resolve link!' return endif - let update_prev_link = ( (scheme == '' || scheme =~# 'wiki' || scheme =~# 'diary') - \ && !vimwiki#path#is_equal(lnk, expand('%:t:r')) - \ ? 1 : 0) + let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' + \ || link_infos.scheme =~# 'diary' - let use_system_open = ( - \ scheme == '' || - \ scheme =~# 'wiki' || - \ scheme =~# 'diary' ? 0 : 1) + let update_prev_link = is_wiki_link && + \ !vimwiki#path#is_equal(link_infos.filename, expand('%:p')) let vimwiki_prev_link = [] " update previous link for wiki pages @@ -442,19 +570,15 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{ endif " open/edit - if g:vimwiki_debug - echom 'open_link: idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.', url='.url.'anchor='.anchor - endif - - if use_system_open - call vimwiki#base#system_open_link(url) - else - call vimwiki#base#edit_file(a:cmd, url, anchor, + if is_wiki_link + call vimwiki#base#edit_file(a:cmd, link_infos.filename, link_infos.anchor, \ vimwiki_prev_link, update_prev_link) - if idx != g:vimwiki_current_idx + if link_infos.index != g:vimwiki_current_idx " this call to setup_buffer_state may not be necessary - call vimwiki#base#setup_buffer_state(idx) + call vimwiki#base#setup_buffer_state(link_infos.index) endif + else + call vimwiki#base#system_open_link(link_infos.filename) endif endfunction " }}} @@ -678,50 +802,6 @@ function! s:jump_to_anchor(anchor) "{{{ endfor endfunction "}}} -" Returns: the absolute file path (and possibly an anchor) of the target file, -" if a link with the given link text appears in the given wiki file, which -" belongs to the given wiki nr -function! s:link_target(source_file, wiki_nr, link_text) "{{{ - let [target_idx, scheme, path, subdir, lnk, ext, url, anchor] = - \ vimwiki#base#resolve_scheme(a:link_text, 0, 1) - let source_dir = fnamemodify(a:source_file, ':p:h').'/' - - if lnk =~# '/$' " link to a directory - return [] - elseif url == '' && anchor != '' " only anchor - return [fnamemodify(a:source_file, ':p'), anchor] - elseif scheme ==# 'file' - return [url, ''] - elseif scheme ==# 'local' - return [vimwiki#path#normalize(source_dir.lnk), ''] - elseif target_idx >= len(g:vimwiki_list) " a malformed link - return ['', ''] - elseif scheme !~# '^wiki\d\+\|diary' " unknown scheme - return [] - endif - - if scheme ==# 'diary' - let root_dir = VimwikiGet('path',a:wiki_nr). - \ VimwikiGet('diary_rel_path', a:wiki_nr) - let ext = VimwikiGet('ext', a:wiki_nr) - else - " a schemeless link is like a link to the current wiki - if a:link_text !~# '^wiki\d\+:' - let target_idx = a:wiki_nr - endif - - if target_idx == a:wiki_nr - let root_dir = source_dir - else - let root_dir = VimwikiGet('path', target_idx) - endif - let ext = VimwikiGet('ext', target_idx) - endif - - let target_file = root_dir . lnk . ext - return [vimwiki#path#normalize(target_file), anchor] -endfunction "}}} - " Params: full path to a wiki file and its wiki number " Returns: a list of all links inside the wiki file " Every list item has the form @@ -747,11 +827,9 @@ function! s:get_links(wikifile, idx) "{{{ break endif let link_count += 1 - let target = s:link_target(a:wikifile, a:idx, link_text) - if !empty(target) - call add(target, lnum) - call add(target, col) - call add(links, target) + let target = vimwiki#base#resolve_link(link_text, a:wikifile) + if target.filename != '' + call add(links, [target.filename, target.anchor, lnum, col]) endif endwhile endfor diff --git a/autoload/vimwiki/path.vim b/autoload/vimwiki/path.vim index 71073bd..dcadb38 100644 --- a/autoload/vimwiki/path.vim +++ b/autoload/vimwiki/path.vim @@ -49,10 +49,7 @@ endfunction "}}} function! vimwiki#path#is_link_to_dir(link) "{{{ " Check if link is to a directory. " It should be ended with \ or /. - if a:link =~# '.\+[/\\]$' - return 1 - endif - return 0 + return a:link =~# '\m[/\\]$' endfunction "}}} function! vimwiki#path#abs_path_of_link(link) "{{{ diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 02d73c0..6413d97 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -84,9 +84,9 @@ function! Complete_wikifiles(findstart, base) let segments = split(a:base, '#', 1) let given_wikifile = segments[0] == '' ? expand('%:t:r') : segments[0] - let link_infos = vimwiki#base#resolve_scheme(given_wikifile.'#', 0, 1) - let wikifile = link_infos[6] - let syntax = VimwikiGet('syntax', link_infos[0]) + let link_infos = vimwiki#base#resolve_link(given_wikifile.'#') + let wikifile = link_infos.filename + let syntax = VimwikiGet('syntax', link_infos.index) let anchors = vimwiki#base#get_anchors(wikifile, syntax) let filtered_anchors = [] diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim index 53155a6..09dc6ef 100644 --- a/plugin/vimwiki.vim +++ b/plugin/vimwiki.vim @@ -31,23 +31,6 @@ function! s:default(varname, value) "{{{ endif endfunction "}}} -function! s:find_wiki(path) "{{{ - " XXX: find_wiki() does not (yet) take into consideration the ext - let path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(a:path)) - let idx = 0 - while idx < len(g:vimwiki_list) - let idx_path = expand(VimwikiGet('path', idx)) - let idx_path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(idx_path)) - if vimwiki#path#is_equal( - \ vimwiki#path#path_common_pfx(idx_path, path), idx_path) - return idx - endif - let idx += 1 - endwhile - return -1 - " an orphan page has been detected -endfunction "}}} - function! s:path_html(idx) "{{{ let path_html = VimwikiGet('path_html', a:idx) if !empty(path_html) @@ -114,8 +97,7 @@ function! s:setup_filetype() "{{{ let time0 = reltime() " start the clock "XXX " Find what wiki current buffer belongs to. let path = expand('%:p:h') - " XXX: find_wiki() does not (yet) take into consideration the ext - let idx = s:find_wiki(path) + let idx = vimwiki#base#find_wiki(path) if g:vimwiki_debug == 3 echom " Setup_filetype g:curr_idx=".g:vimwiki_current_idx." find_idx=".idx." b:curr_idx=".s:vimwiki_idx()."" endif @@ -166,8 +148,7 @@ function! s:setup_buffer_enter() "{{{ " buffer's path and ext. " Else set g:vimwiki_current_idx to that wiki index. let path = expand('%:p:h') - " XXX: find_wiki() does not (yet) take into consideration the ext - let idx = s:find_wiki(path) + let idx = vimwiki#base#find_wiki(path) if g:vimwiki_debug ==3 echom " Setup_buffer_enter g:curr_idx=".g:vimwiki_current_idx." find_idx=".idx." b:curr_idx=".s:vimwiki_idx()."" From 4511bf09e6d864561b7f2bb76ec8b4839a564643 Mon Sep 17 00:00:00 2001 From: EinfachToll Date: Tue, 17 Mar 2015 10:33:43 +0100 Subject: [PATCH 3/6] Don't highlight absolute links when 'maxhi' is on Ref #105 --- autoload/vimwiki/base.vim | 33 ++++++++++++++++++++++++++------- ftplugin/vimwiki.vim | 2 +- syntax/vimwiki.vim | 3 ++- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 0b19b35..bdfa364 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -605,7 +605,7 @@ endfunction " }}} " vimwiki#base#generate_links function! vimwiki#base#generate_links() "{{{ - let links = vimwiki#base#get_wikilinks(g:vimwiki_current_idx) + let links = vimwiki#base#get_wikilinks(g:vimwiki_current_idx, 0) call append(line('$'), substitute(g:vimwiki_rxH1_Template, '__Header__', 'Generated Links', '')) @@ -686,9 +686,11 @@ function! s:find_files(wiki_nr, directories_only) return split(globpath(root_directory, pattern), '\n') endfunction -" Returns: a list containing the links to all wiki files for the given wiki -" If the given wiki number is negative, the diary of the current wiki is used -function! vimwiki#base#get_wikilinks(wiki_nr) +" Returns: a list containing the links to get from the current file to all wiki +" files in the given wiki. +" If the given wiki number is negative, the diary of the current wiki is used. +" If also_absolute_links is nonzero, also return links of the form /file +function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links) let files = s:find_files(a:wiki_nr, 0) if a:wiki_nr == g:vimwiki_current_idx let cwd = vimwiki#path#wikify_path(expand('%:p:h')) @@ -703,21 +705,38 @@ function! vimwiki#base#get_wikilinks(wiki_nr) let wikifile = vimwiki#path#relpath(cwd, wikifile) call add(result, wikifile) endfor + if a:also_absolute_links + for wikifile in files + if a:wiki_nr == g:vimwiki_current_idx + let cwd = VimwikiGet('path') + elseif a:wiki_nr < 0 + let cwd = VimwikiGet('path').VimwikiGet('diary_rel_path') + endif + let wikifile = fnamemodify(wikifile, ':r') " strip extension + let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile) + call add(result, wikifile) + endfor + endif return result endfunction -" Returns: a list containing +" Returns: a list containing the links to all directories from the current file function! vimwiki#base#get_wiki_directories(wiki_nr) let dirs = s:find_files(a:wiki_nr, 1) if a:wiki_nr == g:vimwiki_current_idx let cwd = vimwiki#path#wikify_path(expand('%:p:h')) + let root_dir = VimwikiGet('path') else let cwd = VimwikiGet('path', a:wiki_nr) endif let result = ['./'] for wikidir in dirs - let wikidir = vimwiki#path#relpath(cwd, wikidir).'/' - call add(result, wikidir) + let wikidir_relative = vimwiki#path#relpath(cwd, wikidir).'/' + call add(result, wikidir_relative) + if a:wiki_nr == g:vimwiki_current_idx + let wikidir_absolute = '/'.vimwiki#path#relpath(root_dir, wikidir).'/' + call add(result, wikidir_absolute) + endif endfor return result endfunction diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 6413d97..be37263 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -70,7 +70,7 @@ function! Complete_wikifiles(findstart, base) let scheme = '' endif - let links = vimwiki#base#get_wikilinks(wikinumber) + let links = vimwiki#base#get_wikilinks(wikinumber, 0) let result = [] for wikifile in links if wikifile =~ '^'.vimwiki#u#escape(prefix) diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim index 93e780c..4f7642d 100644 --- a/syntax/vimwiki.vim +++ b/syntax/vimwiki.vim @@ -12,7 +12,8 @@ endif "TODO do nothing if ...? (?) let g:starttime = reltime() " start the clock if VimwikiGet('maxhi') - let b:existing_wikifiles = vimwiki#base#get_wikilinks(g:vimwiki_current_idx) + let b:existing_wikifiles = + \ vimwiki#base#get_wikilinks(g:vimwiki_current_idx, 1) let b:existing_wikidirs = \ vimwiki#base#get_wiki_directories(g:vimwiki_current_idx) endif From d20e03d660809743f2b4c568c28dcc9c456dd2b6 Mon Sep 17 00:00:00 2001 From: EinfachToll Date: Thu, 19 Mar 2015 09:05:19 +0100 Subject: [PATCH 4/6] Make absolute wiki links work with wikiN: scheme Ref #105 --- autoload/vimwiki/base.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index bdfa364..40951a9 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -318,7 +318,7 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{ return link_infos endif - if !is_relative + if !is_relative || link_infos.index != source_wiki let root_dir = VimwikiGet('path', link_infos.index) endif From f8235890768ca730a7ff3dda026575adf7162524 Mon Sep 17 00:00:00 2001 From: EinfachToll Date: Thu, 19 Mar 2015 13:22:28 +0100 Subject: [PATCH 5/6] make VimwikiCheckLinks also find nonexisting directories Fix #120 --- autoload/vimwiki/base.vim | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 40951a9..241d634 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -880,11 +880,18 @@ function! vimwiki#base#check_links() "{{{ \'text': "there is no such anchor: ".target_anchor}) endif else - if filereadable(target_file) " maybe it's a non-wiki file - let anchors_of_files[target_file] = [] + if target_file =~ '/$' " maybe it's a link to a directory + if !isdirectory(target_file) + call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col, + \'text': "there is no such directory: ".target_file}) + endif else - call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col, - \'text': "there is no such file: ".target_file}) + if filereadable(target_file) " maybe it's a non-wiki file + let anchors_of_files[target_file] = [] + else + call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col, + \'text': "there is no such file: ".target_file}) + endif endif endif endfor From 4ab0bdf3da09e86fcd0400aaefeff0d7ac2639a9 Mon Sep 17 00:00:00 2001 From: EinfachToll Date: Mon, 23 Mar 2015 13:25:39 +0100 Subject: [PATCH 6/6] Don't trigger QuickFixCmdPost autocmd unnecessarily Fix #121 --- autoload/vimwiki/markdown_base.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/vimwiki/markdown_base.vim b/autoload/vimwiki/markdown_base.vim index dcfffe9..a303de2 100644 --- a/autoload/vimwiki/markdown_base.vim +++ b/autoload/vimwiki/markdown_base.vim @@ -16,7 +16,8 @@ function! vimwiki#markdown_base#scan_reflinks() " {{{ let mkd_refs = {} " construct list of references using vimgrep try - execute 'vimgrep #'.g:vimwiki_rxMkdRef.'#j %' + " Why noautocmd? Because https://github.com/vimwiki/vimwiki/issues/121 + noautocmd execute 'vimgrep #'.g:vimwiki_rxMkdRef.'#j %' catch /^Vim\%((\a\+)\)\=:E480/ " No Match "Ignore it, and move on to the next file endtry