commit 37f020d21a2a70e2163eea25dc71bcf4de6be22b
parent 13adbe3510a83a54d09dfcabce3e479ffb260bd2
Author: Rane Brown <ranebrown@users.noreply.github.com>
Date: Sat, 20 Apr 2019 08:28:32 -0700
Omnicompletion fix for Windows (#660)
* Temporary fix for omnicomplete of vimwiki links - #456.
This fixes the omnicomplete of wiki links under Windows which were
not working since paths on Windows use '\' instead of '/'. This is
a temporary fix until path refactoring is done.
* Update changelog with description of fix for #456
Diffstat:
3 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
@@ -486,6 +486,10 @@ function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
let result = []
for wikifile in files
let wikifile = fnamemodify(wikifile, ':r') " strip extension
+ if vimwiki#u#is_windows()
+ " TODO temporary fix see #478
+ let wikifile = substitute(wikifile , '/', '\', 'g')
+ endif
let wikifile = vimwiki#path#relpath(cwd, wikifile)
call add(result, wikifile)
endfor
@@ -497,6 +501,10 @@ function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
let cwd = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path')
endif
let wikifile = fnamemodify(wikifile, ':r') " strip extension
+ if vimwiki#u#is_windows()
+ " TODO temporary fix see #478
+ let wikifile = substitute(wikifile , '/', '\', 'g')
+ endif
let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile)
call add(result, wikifile)
endfor
diff --git a/autoload/vimwiki/path.vim b/autoload/vimwiki/path.vim
@@ -98,14 +98,29 @@ endfunction
" Returns: the relative path from a:dir to a:file
function! vimwiki#path#relpath(dir, file)
let result = []
- let dir = split(a:dir, '/')
- let file = split(a:file, '/')
+ if vimwiki#u#is_windows()
+ " TODO temporary fix see #478
+ " not sure why paths get converted back to using forward slash
+ " when passed to the function in the form C:\path\to\file
+ let dir = substitute(a:dir, '/', '\', 'g')
+ let file = substitute(a:file, '/', '\', 'g')
+ let dir = split(dir, '\')
+ let file = split(file, '\')
+ else
+ let dir = split(a:dir, '/')
+ let file = split(a:file, '/')
+ endif
while (len(dir) > 0 && len(file) > 0) && vimwiki#path#is_equal(dir[0], file[0])
call remove(dir, 0)
call remove(file, 0)
endwhile
if empty(dir) && empty(file)
- return './'
+ if vimwiki#u#is_windows()
+ " TODO temporary fix see #478
+ return '.\'
+ else
+ return './'
+ endif
endif
for segment in dir
let result += ['..']
@@ -113,9 +128,17 @@ function! vimwiki#path#relpath(dir, file)
for segment in file
let result += [segment]
endfor
- let result_path = join(result, '/')
- if a:file =~ '\m/$'
- let result_path .= '/'
+ if vimwiki#u#is_windows()
+ " TODO temporary fix see #478
+ let result_path = join(result, '\')
+ if a:file =~ '\m\\$'
+ let result_path .= '\'
+ endif
+ else
+ let result_path = join(result, '/')
+ if a:file =~ '\m/$'
+ let result_path .= '/'
+ endif
endif
return result_path
endfunction
diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt
@@ -3347,6 +3347,8 @@ Removed:~
*
Fixed:~
+ * Issue #456: Omnicompletion of wikilinks under Windows. Note: this should
+ be considered a temporary fix until #478 is closed.
* Issue #654: Fix `:VimwikiShowVersion` command.
* PR #634: Removed extra newlines that were inserted before/after
generated links.