Unify path handling -- part 4
This commit is contained in:
parent
f76e75d117
commit
ca07da33c8
@ -302,7 +302,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()).
|
let bullet = repeat(' ', vimwiki#lst#get_list_margin()).
|
||||||
@ -358,7 +358,9 @@ function! vimwiki#base#backlinks() "{{{
|
|||||||
endif
|
endif
|
||||||
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)
|
||||||
@ -387,10 +389,14 @@ 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
|
||||||
|
@ -209,7 +209,7 @@ function! vimwiki#path#dir_obj(dirpath)
|
|||||||
let dirpath = a:dirpath[4:]
|
let dirpath = a:dirpath[4:]
|
||||||
let protocoll = 'scp'
|
let protocoll = 'scp'
|
||||||
else
|
else
|
||||||
let dirpath = resolve(a:dirpath)
|
let dirpath = resolve(fnamemodify(a:dirpath, ':p'))
|
||||||
let protocoll = 'file'
|
let protocoll = 'file'
|
||||||
endif
|
endif
|
||||||
let path = split(vimwiki#path#chomp_slash(dirpath), '\m[/\\]', 1)
|
let path = split(vimwiki#path#chomp_slash(dirpath), '\m[/\\]', 1)
|
||||||
@ -243,6 +243,11 @@ function! vimwiki#path#extension(file_object)
|
|||||||
endfunction
|
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
|
" Returns: the dir of the file object as dir object
|
||||||
function! vimwiki#path#directory_of_file(file_object)
|
function! vimwiki#path#directory_of_file(file_object)
|
||||||
return copy(a:file_object[0])
|
return copy(a:file_object[0])
|
||||||
@ -286,7 +291,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
" Returns a file object made from a dir object plus a file semgent
|
" Returns a file object made from a dir object plus a file semgent
|
||||||
function! vimwiki#path#join(dir_obje, file_segment)
|
function! vimwiki#path#join(dir_obj, file_segment)
|
||||||
let new_dir_object = copy(a:dir_obj)
|
let new_dir_object = copy(a:dir_obj)
|
||||||
let new_dir_object.path += a:file_segment[0]
|
let new_dir_object.path += a:file_segment[0]
|
||||||
return [new_dir_object, a:file_segment[1]]
|
return [new_dir_object, a:file_segment[1]]
|
||||||
@ -378,5 +383,8 @@ endfunction
|
|||||||
|
|
||||||
" Returns: a list of all files somewhere in a:dir_obj with extension a:ext
|
" 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)
|
function! vimwiki#path#files_in_dir_recursive(dir_obj, ext)
|
||||||
let htmlfiles = split(glob(a:path.'**/*.html'), '\n')
|
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
|
endfunction
|
||||||
|
@ -161,7 +161,7 @@ function! s:validate_global_settings()
|
|||||||
for extension in g:vimwiki_global_vars.ext2syntax
|
for extension in g:vimwiki_global_vars.ext2syntax
|
||||||
if extension[0] != '.'
|
if extension[0] != '.'
|
||||||
let g:vimwiki_global_vars.ext2syntax['.'.extension] =
|
let g:vimwiki_global_vars.ext2syntax['.'.extension] =
|
||||||
g:vimwiki_global_vars.ext2syntax[extension]
|
\ g:vimwiki_global_vars.ext2syntax[extension]
|
||||||
call remove(g:vimwiki_global_vars.ext2syntax, extension)
|
call remove(g:vimwiki_global_vars.ext2syntax, extension)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
@ -566,7 +566,7 @@ 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'
|
elseif a:key ==# 'subdir'
|
||||||
call setbufvar(buffer, 'vimwiki_subdir', vimwiki#base#current_subdir())
|
call setbufvar(buffer, 'vimwiki_subdir', vimwiki#base#current_subdir())
|
||||||
elseif a:key ==# 'invsubdir'
|
elseif a:key ==# 'invsubdir'
|
||||||
@ -574,7 +574,7 @@ function! vimwiki#vars#get_bufferlocal(key, ...)
|
|||||||
call setbufvar(buffer, 'vimwiki_invsubdir', vimwiki#base#invsubdir(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')))
|
||||||
|
@ -79,19 +79,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, '^wiki\d:\zs.*')
|
let prefix = matchstr(a:base, '^wiki\d:\zs.*')
|
||||||
let scheme = matchstr(a:base, '^wiki\d:\ze')
|
let scheme = matchstr(a:base, '^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)
|
||||||
@ -104,7 +107,9 @@ 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.path
|
let wikifile = link_infos.path
|
||||||
let syntax = vimwiki#vars#get_wikilocal('syntax', link_infos.index)
|
let syntax = vimwiki#vars#get_wikilocal('syntax', link_infos.index)
|
||||||
@ -661,6 +666,6 @@ endif
|
|||||||
|
|
||||||
" PASTE, CAT URL {{{
|
" PASTE, CAT URL {{{
|
||||||
" html commands
|
" html commands
|
||||||
command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(expand('%:p'))
|
command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(vimwiki#path#current_file())
|
||||||
command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(expand('%:p'))
|
command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(vimwiki#path#current_file())
|
||||||
" }}}
|
" }}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user