Version 2.0.1.stu

* Follow (i.e. open target of) markdown reference-style links.
  * Bug fixes.
This commit is contained in:
Maxim Kim 2012-07-07 00:00:00 +00:00 committed by Able Scraper
parent d5a6d097da
commit d19cc85a71
9 changed files with 422 additions and 99 deletions

View File

@ -8,19 +8,16 @@ if exists("g:loaded_vimwiki_auto") || &cp
endif endif
let g:loaded_vimwiki_auto = 1 let g:loaded_vimwiki_auto = 1
" -------------------------------------------------------------------------
" Load syntax-specific Wiki functionality
execute 'runtime! autoload/vimwiki/'.VimwikiGet('syntax').'_base.vim'
" -------------------------------------------------------------------------
" MISC helper functions {{{ " MISC helper functions {{{
" s:normalize_path
function! s:normalize_path(path) "{{{ function! s:normalize_path(path) "{{{
let g:VimwikiLog.normalize_path += 1 "XXX let g:VimwikiLog.normalize_path += 1 "XXX
" resolve doesn't work quite right with symlinks ended with / or \ " resolve doesn't work quite right with symlinks ended with / or \
return resolve(expand(substitute(a:path, '[/\\]\+$', '', ''))).'/' return resolve(expand(substitute(a:path, '[/\\]\+$', '', ''))).'/'
endfunction "}}} endfunction "}}}
" s:path_html
function! s:path_html(idx) "{{{ function! s:path_html(idx) "{{{
let path_html = VimwikiGet('path_html', a:idx) let path_html = VimwikiGet('path_html', a:idx)
if !empty(path_html) if !empty(path_html)
@ -32,8 +29,41 @@ function! s:path_html(idx) "{{{
endif endif
endfunction "}}} endfunction "}}}
function! vimwiki#base#get_known_extensions() " {{{
" Getting all extensions that different wikis could have
let extensions = {}
for wiki in g:vimwiki_list
if has_key(wiki, 'ext')
let extensions[wiki.ext] = 1
else
let extensions['.wiki'] = 1
endif
endfor
" append map g:vimwiki_ext2syntax
for ext in keys(g:vimwiki_ext2syntax)
let extensions[ext] = 1
endfor
return keys(extensions)
endfunction " }}}
function! vimwiki#base#get_known_syntaxes() " {{{
" Getting all syntaxes that different wikis could have
let syntaxes = {}
let syntaxes['default'] = 1
for wiki in g:vimwiki_list
if has_key(wiki, 'syntax')
let syntaxes[wiki.syntax] = 1
endif
endfor
" append map g:vimwiki_ext2syntax
for syn in values(g:vimwiki_ext2syntax)
let syntaxes[syn] = 1
endfor
return keys(syntaxes)
endfunction " }}}
" }}} " }}}
" vimwiki#base#apply_wiki_options
function! vimwiki#base#apply_wiki_options(options) " {{{ Update the current function! vimwiki#base#apply_wiki_options(options) " {{{ Update the current
" wiki using the options dictionary " wiki using the options dictionary
for kk in keys(a:options) for kk in keys(a:options)
@ -43,6 +73,7 @@ function! vimwiki#base#apply_wiki_options(options) " {{{ Update the current
call vimwiki#base#setup_buffer_state(g:vimwiki_current_idx) call vimwiki#base#setup_buffer_state(g:vimwiki_current_idx)
endfunction " }}} endfunction " }}}
" vimwiki#base#read_wiki_options
function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
" options from the current page's directory, or its ancesters. If a file " options from the current page's directory, or its ancesters. If a file
" named vimwiki.vimrc is found, which declares a wiki-options dictionary " named vimwiki.vimrc is found, which declares a wiki-options dictionary
@ -55,7 +86,7 @@ function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
" overwrite !! (not to mention all the other globals ...) " overwrite !! (not to mention all the other globals ...)
let l:vimwiki_list = deepcopy(g:vimwiki_list, 1) let l:vimwiki_list = deepcopy(g:vimwiki_list, 1)
" "
if a:check if a:check > 1
call vimwiki#base#print_wiki_state() call vimwiki#base#print_wiki_state()
echo " \n" echo " \n"
endif endif
@ -67,7 +98,7 @@ function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
" other names are possible, but most vimrc files will cause grief! " other names are possible, but most vimrc files will cause grief!
for nm in ['vimwiki.vimrc'] for nm in ['vimwiki.vimrc']
" TODO: use an alternate strategy, instead of source, to read options " TODO: use an alternate strategy, instead of source, to read options
if done | if done
continue continue
endif endif
" "
@ -78,7 +109,7 @@ function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
" "
echo "\nFound file : ".local_wiki_options_filename echo "\nFound file : ".local_wiki_options_filename
let query = "Vimwiki: Check for options in this file [Y]es/[n]o? " let query = "Vimwiki: Check for options in this file [Y]es/[n]o? "
if a:check && (tolower(input(query)) !~ "y") if a:check > 0 && (tolower(input(query)) !~ "y")
continue continue
endif endif
" "
@ -90,7 +121,7 @@ function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
continue continue
endif endif
" "
if a:check if a:check > 0
echo "\n\nFound wiki options\n g:local_wiki = ".string(g:local_wiki) echo "\n\nFound wiki options\n g:local_wiki = ".string(g:local_wiki)
let query = "Vimwiki: Apply these options [Y]es/[n]o? " let query = "Vimwiki: Apply these options [Y]es/[n]o? "
if tolower(input(query)) !~ "y" if tolower(input(query)) !~ "y"
@ -114,7 +145,7 @@ function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
let g:vimwiki_list = deepcopy(l:vimwiki_list, 1) let g:vimwiki_list = deepcopy(l:vimwiki_list, 1)
" "
endif endif
if a:check if a:check > 1
echo " \n " echo " \n "
if done if done
call vimwiki#base#print_wiki_state() call vimwiki#base#print_wiki_state()
@ -124,6 +155,7 @@ function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
endif endif
endfunction " }}} endfunction " }}}
" vimwiki#base#validate_wiki_options
function! vimwiki#base#validate_wiki_options(idx) " {{{ Validate wiki options function! vimwiki#base#validate_wiki_options(idx) " {{{ Validate wiki options
" Only call this function *before* opening a wiki page. " Only call this function *before* opening a wiki page.
" "
@ -144,6 +176,7 @@ function! vimwiki#base#validate_wiki_options(idx) " {{{ Validate wiki options
"" call vimwiki#base#cache_buffer_state() "" call vimwiki#base#cache_buffer_state()
endfunction " }}} endfunction " }}}
" vimwiki#base#setup_buffer_state
function! vimwiki#base#setup_buffer_state(idx) " {{{ Init page-specific variables function! vimwiki#base#setup_buffer_state(idx) " {{{ Init page-specific variables
" Only call this function *after* opening a wiki page. " Only call this function *after* opening a wiki page.
if a:idx < 0 if a:idx < 0
@ -162,6 +195,7 @@ function! vimwiki#base#setup_buffer_state(idx) " {{{ Init page-specific variable
call vimwiki#base#cache_buffer_state() call vimwiki#base#cache_buffer_state()
endfunction " }}} endfunction " }}}
" vimwiki#base#cache_buffer_state
function! vimwiki#base#cache_buffer_state() "{{{ function! vimwiki#base#cache_buffer_state() "{{{
if !exists('g:vimwiki_current_idx') && g:vimwiki_debug if !exists('g:vimwiki_current_idx') && g:vimwiki_debug
echo "[Vimwiki Internal Error]: Missing global state variable: 'g:vimwiki_current_idx'" echo "[Vimwiki Internal Error]: Missing global state variable: 'g:vimwiki_current_idx'"
@ -169,6 +203,7 @@ function! vimwiki#base#cache_buffer_state() "{{{
let b:vimwiki_idx = g:vimwiki_current_idx let b:vimwiki_idx = g:vimwiki_current_idx
endfunction "}}} endfunction "}}}
" vimwiki#base#recall_buffer_state
function! vimwiki#base#recall_buffer_state() "{{{ function! vimwiki#base#recall_buffer_state() "{{{
if !exists('b:vimwiki_idx') if !exists('b:vimwiki_idx')
if g:vimwiki_debug if g:vimwiki_debug
@ -181,6 +216,7 @@ function! vimwiki#base#recall_buffer_state() "{{{
endif endif
endfunction " }}} endfunction " }}}
" vimwiki#base#print_wiki_state
function! vimwiki#base#print_wiki_state() "{{{ print wiki options function! vimwiki#base#print_wiki_state() "{{{ print wiki options
" and buffer state variables " and buffer state variables
let g_width = 18 let g_width = 18
@ -198,6 +234,7 @@ function! vimwiki#base#print_wiki_state() "{{{ print wiki options
endfor endfor
endfunction "}}} endfunction "}}}
" vimwiki#base#mkdir
" If the optional argument 'confirm' == 1 is provided, " If the optional argument 'confirm' == 1 is provided,
" vimwiki#base#mkdir will ask before creating a directory " vimwiki#base#mkdir will ask before creating a directory
function! vimwiki#base#mkdir(path, ...) "{{{ function! vimwiki#base#mkdir(path, ...) "{{{
@ -213,9 +250,9 @@ function! vimwiki#base#mkdir(path, ...) "{{{
call mkdir(path, "p") call mkdir(path, "p")
endif endif
return 1 return 1
endfunction endfunction " }}}
" }}}
" vimwiki#base#file_pattern
function! vimwiki#base#file_pattern(files) "{{{ Get search regex from glob() function! vimwiki#base#file_pattern(files) "{{{ Get search regex from glob()
" string. Aim to support *all* special characters, forcing the user to choose " string. Aim to support *all* special characters, forcing the user to choose
" names that are compatible with any external restrictions that they " names that are compatible with any external restrictions that they
@ -231,18 +268,18 @@ function! vimwiki#base#file_pattern(files) "{{{ Get search regex from glob()
" "
let pattern = vimwiki#base#branched_pattern(a:files,"\n") let pattern = vimwiki#base#branched_pattern(a:files,"\n")
return '\V'.pattern.'\m' return '\V'.pattern.'\m'
endfunction endfunction "}}}
"}}}
" vimwiki#base#branched_pattern
function! vimwiki#base#branched_pattern(string,separator) "{{{ get search regex function! vimwiki#base#branched_pattern(string,separator) "{{{ get search regex
" from a string-list; separators assumed at start and end as well " from a string-list; separators assumed at start and end as well
let pattern = substitute(a:string, a:separator, '\\|','g') let pattern = substitute(a:string, a:separator, '\\|','g')
let pattern = substitute(pattern, '\%^\\|', '\\%(','') let pattern = substitute(pattern, '\%^\\|', '\\%(','')
let pattern = substitute(pattern,'\\|\%$', '\\)','') let pattern = substitute(pattern,'\\|\%$', '\\)','')
return pattern return pattern
endfunction endfunction "}}}
"}}}
" vimwiki#base#subdir
"FIXME TODO slow and faulty "FIXME TODO slow and faulty
function! vimwiki#base#subdir(path, filename)"{{{ function! vimwiki#base#subdir(path, filename)"{{{
let g:VimwikiLog.subdir += 1 "XXX let g:VimwikiLog.subdir += 1 "XXX
@ -264,17 +301,18 @@ function! vimwiki#base#subdir(path, filename)"{{{
return res return res
endfunction "}}} endfunction "}}}
" vimwiki#base#current_subdir
function! vimwiki#base#current_subdir(idx)"{{{ function! vimwiki#base#current_subdir(idx)"{{{
return vimwiki#base#subdir(VimwikiGet('path', a:idx), expand('%:p')) return vimwiki#base#subdir(VimwikiGet('path', a:idx), expand('%:p'))
endfunction"}}} endfunction"}}}
" vimwiki#base#invsubdir
function! vimwiki#base#invsubdir(subdir) " {{{ function! vimwiki#base#invsubdir(subdir) " {{{
return substitute(a:subdir, '[^/\.]\+/', '../', 'g') return substitute(a:subdir, '[^/\.]\+/', '../', 'g')
endfunction " }}} endfunction " }}}
" vimwiki#base#resolve_scheme
function! vimwiki#base#resolve_scheme(lnk, as_html) " {{{ Resolve scheme function! vimwiki#base#resolve_scheme(lnk, as_html) " {{{ Resolve scheme
" - Only return non-negative index when valid wiki link found
"
" if link is schemeless add wikiN: scheme " if link is schemeless add wikiN: scheme
let lnk = a:lnk let lnk = a:lnk
let is_schemeless = lnk !~ g:vimwiki_rxSchemeUrl let is_schemeless = lnk !~ g:vimwiki_rxSchemeUrl
@ -392,6 +430,7 @@ function! vimwiki#base#resolve_scheme(lnk, as_html) " {{{ Resolve scheme
return [idx, scheme, path, subdir, lnk, ext, url] return [idx, scheme, path, subdir, lnk, ext, url]
endfunction "}}} endfunction "}}}
" vimwiki#base#system_open_link
function! vimwiki#base#system_open_link(url) "{{{ function! vimwiki#base#system_open_link(url) "{{{
" handlers " handlers
function! s:win32_handler(url) function! s:win32_handler(url)
@ -420,6 +459,7 @@ function! vimwiki#base#system_open_link(url) "{{{
echomsg 'Default Vimwiki link handler was unable to open the HTML file!' echomsg 'Default Vimwiki link handler was unable to open the HTML file!'
endfunction "}}} endfunction "}}}
" vimwiki#base#open_link
function! vimwiki#base#open_link(cmd, link, ...) "{{{ function! vimwiki#base#open_link(cmd, link, ...) "{{{
let [idx, scheme, path, subdir, lnk, ext, url] = let [idx, scheme, path, subdir, lnk, ext, url] =
\ vimwiki#base#resolve_scheme(a:link, 0) \ vimwiki#base#resolve_scheme(a:link, 0)
@ -467,9 +507,9 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{
call vimwiki#base#setup_buffer_state(idx) call vimwiki#base#setup_buffer_state(idx)
endif endif
endif endif
endfunction endfunction " }}}
" }}}
" vimwiki#base#generate_links
function! vimwiki#base#generate_links() "{{{only get links from the current dir function! vimwiki#base#generate_links() "{{{only get links from the current dir
" change to the directory of the current file " change to the directory of the current file
let orig_pwd = getcwd() let orig_pwd = getcwd()
@ -497,6 +537,7 @@ function! vimwiki#base#generate_links() "{{{only get links from the current dir
endfor endfor
endfunction " }}} endfunction " }}}
" vimwiki#base#goto
function! vimwiki#base#goto(key) "{{{ function! vimwiki#base#goto(key) "{{{
call vimwiki#base#edit_file(':e', call vimwiki#base#edit_file(':e',
\ VimwikiGet('path'). \ VimwikiGet('path').
@ -504,6 +545,7 @@ function! vimwiki#base#goto(key) "{{{
\ VimwikiGet('ext')) \ VimwikiGet('ext'))
endfunction "}}} endfunction "}}}
" vimwiki#base#backlinks
function! vimwiki#base#backlinks() "{{{ function! vimwiki#base#backlinks() "{{{
execute 'lvimgrep "\%(^\|[[:blank:][:punct:]]\)'. execute 'lvimgrep "\%(^\|[[:blank:][:punct:]]\)'.
\ expand("%:t:r"). \ expand("%:t:r").
@ -511,11 +553,12 @@ function! vimwiki#base#backlinks() "{{{
\ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') \ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ')
endfunction "}}} endfunction "}}}
" vimwiki#base#get_links
function! vimwiki#base#get_links(pat) "{{{ return string-list for files function! vimwiki#base#get_links(pat) "{{{ return string-list for files
" in the current wiki matching the pattern "pat" " in the current wiki matching the pattern "pat"
" search all wiki files (or directories) in wiki 'path' and its subdirs. " search all wiki files (or directories) in wiki 'path' and its subdirs.
let time1 = reltime() " start the clock XXX let time1 = reltime() " start the clock
" XXX: " XXX:
" if maxhi = 1 and <leader>w<leader>w before loading any vimwiki file " if maxhi = 1 and <leader>w<leader>w before loading any vimwiki file
@ -586,6 +629,7 @@ function! vimwiki#base#get_links(pat) "{{{ return string-list for files
return globlinks return globlinks
endfunction "}}} endfunction "}}}
" vimwiki#base#edit_file
function! vimwiki#base#edit_file(command, filename, ...) "{{{ function! vimwiki#base#edit_file(command, filename, ...) "{{{
" XXX: Should we allow * in filenames!? " XXX: Should we allow * in filenames!?
" Maxim: It is allowed, escaping here is for vim to be able to open files " Maxim: It is allowed, escaping here is for vim to be able to open files
@ -610,17 +654,17 @@ function! vimwiki#base#edit_file(command, filename, ...) "{{{
if a:0 && a:2 && len(a:1) > 0 if a:0 && a:2 && len(a:1) > 0
let b:vimwiki_prev_link = a:1 let b:vimwiki_prev_link = a:1
endif endif
endfunction endfunction " }}}
" }}}
" vimwiki#base#search_word
function! vimwiki#base#search_word(wikiRx, cmd) "{{{ function! vimwiki#base#search_word(wikiRx, cmd) "{{{
let match_line = search(a:wikiRx, 's'.a:cmd) let match_line = search(a:wikiRx, 's'.a:cmd)
if match_line == 0 if match_line == 0
echomsg 'vimwiki: Wiki link not found.' echomsg 'vimwiki: Wiki link not found.'
endif endif
endfunction endfunction " }}}
" }}}
" vimwiki#base#matchstr_at_cursor
" Returns part of the line that matches wikiRX at cursor " Returns part of the line that matches wikiRX at cursor
function! vimwiki#base#matchstr_at_cursor(wikiRX) "{{{ function! vimwiki#base#matchstr_at_cursor(wikiRX) "{{{
let col = col('.') - 1 let col = col('.') - 1
@ -644,6 +688,7 @@ function! vimwiki#base#matchstr_at_cursor(wikiRX) "{{{
endif endif
endf "}}} endf "}}}
" vimwiki#base#replacestr_at_cursor
function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) "{{{ function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) "{{{
let col = col('.') - 1 let col = col('.') - 1
let line = getline('.') let line = getline('.')
@ -666,6 +711,7 @@ function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) "{{{
endif endif
endf "}}} endf "}}}
" s:print_wiki_list
function! s:print_wiki_list() "{{{ function! s:print_wiki_list() "{{{
let idx = 0 let idx = 0
while idx < len(g:vimwiki_list) while idx < len(g:vimwiki_list)
@ -680,9 +726,9 @@ function! s:print_wiki_list() "{{{
let idx += 1 let idx += 1
endwhile endwhile
echohl None echohl None
endfunction endfunction " }}}
" }}}
" s:update_wiki_link
function! s:update_wiki_link(fname, old, new) " {{{ function! s:update_wiki_link(fname, old, new) " {{{
echo "Updating links in ".a:fname echo "Updating links in ".a:fname
let has_updates = 0 let has_updates = 0
@ -700,9 +746,9 @@ function! s:update_wiki_link(fname, old, new) " {{{
call writefile(dest, a:fname) call writefile(dest, a:fname)
call delete(a:fname.'#vimwiki_upd#') call delete(a:fname.'#vimwiki_upd#')
endif endif
endfunction endfunction " }}}
" }}}
" s:update_wiki_links_dir
function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{ function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{
let old_fname = substitute(a:old_fname, '[/\\]', '[/\\\\]', 'g') let old_fname = substitute(a:old_fname, '[/\\]', '[/\\\\]', 'g')
let new_fname = a:new_fname let new_fname = a:new_fname
@ -718,9 +764,9 @@ function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{
for fname in files for fname in files
call s:update_wiki_link(fname, old_fname_r, new_fname_r) call s:update_wiki_link(fname, old_fname_r, new_fname_r)
endfor endfor
endfunction endfunction " }}}
" }}}
" s:tail_name
function! s:tail_name(fname) "{{{ function! s:tail_name(fname) "{{{
let result = substitute(a:fname, ":", "__colon__", "g") let result = substitute(a:fname, ":", "__colon__", "g")
let result = fnamemodify(result, ":t:r") let result = fnamemodify(result, ":t:r")
@ -728,6 +774,7 @@ function! s:tail_name(fname) "{{{
return result return result
endfunction "}}} endfunction "}}}
" s:update_wiki_links
function! s:update_wiki_links(old_fname, new_fname) " {{{ function! s:update_wiki_links(old_fname, new_fname) " {{{
let old_fname = s:tail_name(a:old_fname) let old_fname = s:tail_name(a:old_fname)
let new_fname = s:tail_name(a:new_fname) let new_fname = s:tail_name(a:new_fname)
@ -760,6 +807,7 @@ function! s:update_wiki_links(old_fname, new_fname) " {{{
endwhile endwhile
endfunction " }}} endfunction " }}}
" s:get_wiki_buffers
function! s:get_wiki_buffers() "{{{ function! s:get_wiki_buffers() "{{{
let blist = [] let blist = []
let bcount = 1 let bcount = 1
@ -776,6 +824,7 @@ function! s:get_wiki_buffers() "{{{
return blist return blist
endfunction " }}} endfunction " }}}
" s:open_wiki_buffer
function! s:open_wiki_buffer(item) "{{{ function! s:open_wiki_buffer(item) "{{{
call vimwiki#base#edit_file(':e', a:item[0]) call vimwiki#base#edit_file(':e', a:item[0])
if !empty(a:item[1]) if !empty(a:item[1])
@ -783,6 +832,7 @@ function! s:open_wiki_buffer(item) "{{{
endif endif
endfunction " }}} endfunction " }}}
" vimwiki#base#nested_syntax
function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{{ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{{
" From http://vim.wikia.com/wiki/VimTip857 " From http://vim.wikia.com/wiki/VimTip857
let ft=toupper(a:filetype) let ft=toupper(a:filetype)
@ -799,8 +849,9 @@ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{
" let b:skip_set_iskeyword = 1 " let b:skip_set_iskeyword = 1
let is_keyword = &iskeyword let is_keyword = &iskeyword
execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
try try
" keep going even if syntax file is not found
execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim' execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
catch catch
endtry endtry
@ -833,28 +884,28 @@ endfunction "}}}
" }}} " }}}
" WIKI link following functions {{{ " WIKI link following functions {{{
" vimwiki#base#find_next_link
function! vimwiki#base#find_next_link() "{{{ function! vimwiki#base#find_next_link() "{{{
call vimwiki#base#search_word(g:vimwiki_rxAnyLink, '') call vimwiki#base#search_word(g:vimwiki_rxAnyLink, '')
endfunction endfunction " }}}
" }}}
" vimwiki#base#find_prev_link
function! vimwiki#base#find_prev_link() "{{{ function! vimwiki#base#find_prev_link() "{{{
call vimwiki#base#search_word(g:vimwiki_rxAnyLink, 'b') call vimwiki#base#search_word(g:vimwiki_rxAnyLink, 'b')
endfunction endfunction " }}}
" }}}
" follow_link " vimwiki#base#follow_link
function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pass function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pass
" to VimwikiLinkHandler, or failing that, the default open_link handler " to VimwikiLinkHandler, or failing that, the default open_link handler
if exists('*vimwiki#base_'.VimwikiGet('syntax').'#follow_link') if exists('*vimwiki#'.VimwikiGet('syntax').'_base#follow_link')
" Syntax-specific links " Syntax-specific links
" XXX: @Stuart: do we still need it? " XXX: @Stuart: do we still need it?
" XXX: @Maxim: most likely! I am still working on a seemless way to " XXX: @Maxim: most likely! I am still working on a seemless way to
" integrate regexp's without complicating syntax/vimwiki.vim " integrate regexp's without complicating syntax/vimwiki.vim
if a:0 if a:0
call vimwiki#base_{VimwikiGet('syntax')}#follow_link(a:split, a:1) call vimwiki#{VimwikiGet('syntax')}_base#follow_link(a:split, a:1)
else else
call vimwiki#base_{VimwikiGet('syntax')}#follow_link(a:split) call vimwiki#{VimwikiGet('syntax')}_base#follow_link(a:split)
endif endif
else else
if a:split == "split" if a:split == "split"
@ -897,6 +948,7 @@ function! vimwiki#base#follow_link(split, ...) "{{{ Parse link at cursor and pas
endfunction " }}} endfunction " }}}
" vimwiki#base#go_back_link
function! vimwiki#base#go_back_link() "{{{ function! vimwiki#base#go_back_link() "{{{
if exists("b:vimwiki_prev_link") if exists("b:vimwiki_prev_link")
" go back to saved wiki link " go back to saved wiki link
@ -906,6 +958,7 @@ function! vimwiki#base#go_back_link() "{{{
endif endif
endfunction " }}} endfunction " }}}
" vimwiki#base#goto_index
function! vimwiki#base#goto_index(wnum, ...) "{{{ function! vimwiki#base#goto_index(wnum, ...) "{{{
if a:wnum > len(g:vimwiki_list) if a:wnum > len(g:vimwiki_list)
echom "vimwiki: Wiki ".a:wnum." is not registered in g:vimwiki_list!" echom "vimwiki: Wiki ".a:wnum." is not registered in g:vimwiki_list!"
@ -937,6 +990,7 @@ function! vimwiki#base#goto_index(wnum, ...) "{{{
call vimwiki#base#setup_buffer_state(idx) call vimwiki#base#setup_buffer_state(idx)
endfunction "}}} endfunction "}}}
" vimwiki#base#delete_link
function! vimwiki#base#delete_link() "{{{ function! vimwiki#base#delete_link() "{{{
"" file system funcs "" file system funcs
"" Delete wiki link you are in from filesystem "" Delete wiki link you are in from filesystem
@ -961,6 +1015,7 @@ function! vimwiki#base#delete_link() "{{{
endif endif
endfunction "}}} endfunction "}}}
" vimwiki#base#rename_link
function! vimwiki#base#rename_link() "{{{ function! vimwiki#base#rename_link() "{{{
"" Rename wiki link, update all links to renamed WikiWord "" Rename wiki link, update all links to renamed WikiWord
let subdir = VimwikiGet('subdir') let subdir = VimwikiGet('subdir')
@ -1061,6 +1116,7 @@ function! vimwiki#base#rename_link() "{{{
let &more = setting_more let &more = setting_more
endfunction " }}} endfunction " }}}
" vimwiki#base#ui_select
function! vimwiki#base#ui_select() "{{{ function! vimwiki#base#ui_select() "{{{
call s:print_wiki_list() call s:print_wiki_list()
let idx = input("Select Wiki (specify number): ") let idx = input("Select Wiki (specify number): ")
@ -1068,12 +1124,12 @@ function! vimwiki#base#ui_select() "{{{
return return
endif endif
call vimwiki#base#goto_index(idx) call vimwiki#base#goto_index(idx)
endfunction endfunction "}}}
"}}}
" }}} " }}}
" TEXT OBJECTS functions {{{ " TEXT OBJECTS functions {{{
" vimwiki#base#TO_header
function! vimwiki#base#TO_header(inner, visual) "{{{ function! vimwiki#base#TO_header(inner, visual) "{{{
if !search('^\(=\+\).\+\1\s*$', 'bcW') if !search('^\(=\+\).\+\1\s*$', 'bcW')
return return
@ -1114,9 +1170,9 @@ function! vimwiki#base#TO_header(inner, visual) "{{{
let lnum = prevnonblank(line('.') - 1) let lnum = prevnonblank(line('.') - 1)
call cursor(lnum, 0) call cursor(lnum, 0)
endif endif
endfunction endfunction "}}}
"}}}
" vimwiki#base#TO_table_cell
function! vimwiki#base#TO_table_cell(inner, visual) "{{{ function! vimwiki#base#TO_table_cell(inner, visual) "{{{
if col('.') == col('$')-1 if col('.') == col('$')-1
return return
@ -1181,6 +1237,7 @@ function! vimwiki#base#TO_table_cell(inner, visual) "{{{
endif endif
endfunction "}}} endfunction "}}}
" vimwiki#base#TO_table_col
function! vimwiki#base#TO_table_col(inner, visual) "{{{ function! vimwiki#base#TO_table_col(inner, visual) "{{{
let t_rows = vimwiki#tbl#get_rows(line('.')) let t_rows = vimwiki#tbl#get_rows(line('.'))
if empty(t_rows) if empty(t_rows)
@ -1297,6 +1354,7 @@ endfunction "}}}
" }}} " }}}
" HEADER functions {{{ " HEADER functions {{{
" vimwiki#base#AddHeaderLevel
function! vimwiki#base#AddHeaderLevel() "{{{ function! vimwiki#base#AddHeaderLevel() "{{{
let lnum = line('.') let lnum = line('.')
let line = getline(lnum) let line = getline(lnum)
@ -1322,9 +1380,9 @@ function! vimwiki#base#AddHeaderLevel() "{{{
endif endif
call setline(lnum, line) call setline(lnum, line)
endif endif
endfunction endfunction "}}}
"}}}
" vimwiki#base#RemoveHeaderLevel
function! vimwiki#base#RemoveHeaderLevel() "{{{ function! vimwiki#base#RemoveHeaderLevel() "{{{
let lnum = line('.') let lnum = line('.')
let line = getline(lnum) let line = getline(lnum)
@ -1355,12 +1413,12 @@ function! vimwiki#base#RemoveHeaderLevel() "{{{
call setline(lnum, line) call setline(lnum, line)
endif endif
endfunction endfunction " }}}
" }}}
"}}} "}}}
" LINK functions {{{ " LINK functions {{{
" Construct a regular expression matching from template (with special " vimwiki#base#apply_template
" Construct a regular expression matching from template (with special
" characters properly escaped), by substituting rxUrl for __LinkUrl__, rxDesc " characters properly escaped), by substituting rxUrl for __LinkUrl__, rxDesc
" for __LinkDescription__, and rxStyle for __LinkStyle__. The three " for __LinkDescription__, and rxStyle for __LinkStyle__. The three
" arguments rxUrl, rxDesc, and rxStyle are copied verbatim, without any " arguments rxUrl, rxDesc, and rxStyle are copied verbatim, without any
@ -1378,9 +1436,9 @@ function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle) "{{{
let lnk = substitute(lnk, '__LinkStyle__', '\='."'".a:rxStyle."'", '') let lnk = substitute(lnk, '__LinkStyle__', '\='."'".a:rxStyle."'", '')
endif endif
return lnk return lnk
endfunction endfunction " }}}
" }}}
" s:clean_url
function! s:clean_url(url) " {{{ function! s:clean_url(url) " {{{
let url = split(a:url, '/\|=\|-\|&\|?\|\.') let url = split(a:url, '/\|=\|-\|&\|?\|\.')
let url = filter(url, 'v:val != ""') let url = filter(url, 'v:val != ""')
@ -1396,6 +1454,7 @@ function! s:clean_url(url) " {{{
return join(url, " ") return join(url, " ")
endfunction " }}} endfunction " }}}
" vimwiki#base#normalize_link_helper
function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) " {{{ function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) " {{{
let str = a:str let str = a:str
let url = matchstr(str, a:rxUrl) let url = matchstr(str, a:rxUrl)
@ -1409,6 +1468,7 @@ function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) " {{{
return lnk return lnk
endfunction " }}} endfunction " }}}
" vimwiki#base#normalize_imagelink_helper
function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, template) "{{{ function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, template) "{{{
let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template) let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template)
let style = matchstr(str, a:rxStyle) let style = matchstr(str, a:rxStyle)
@ -1416,6 +1476,7 @@ function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, t
return lnk return lnk
endfunction " }}} endfunction " }}}
" s:normalize_link_syntax_n
function! s:normalize_link_syntax_n() " {{{ function! s:normalize_link_syntax_n() " {{{
let lnum = line('.') let lnum = line('.')
@ -1459,6 +1520,7 @@ function! s:normalize_link_syntax_n() " {{{
endfunction " }}} endfunction " }}}
" s:normalize_link_syntax_v
function! s:normalize_link_syntax_v() " {{{ function! s:normalize_link_syntax_v() " {{{
let lnum = line('.') let lnum = line('.')
let sel_save = &selection let sel_save = &selection
@ -1484,7 +1546,7 @@ function! s:normalize_link_syntax_v() " {{{
endfunction " }}} endfunction " }}}
" normalize_link " vimwiki#base#normalize_link
function! vimwiki#base#normalize_link(is_visual_mode) "{{{ function! vimwiki#base#normalize_link(is_visual_mode) "{{{
if exists('*vimwiki#'.VimwikiGet('syntax').'_base#normalize_link') if exists('*vimwiki#'.VimwikiGet('syntax').'_base#normalize_link')
" Syntax-specific links " Syntax-specific links
@ -1500,3 +1562,12 @@ function! vimwiki#base#normalize_link(is_visual_mode) "{{{
endfunction "}}} endfunction "}}}
" }}} " }}}
" -------------------------------------------------------------------------
" Load syntax-specific Wiki functionality
for syn in vimwiki#base#get_known_syntaxes()
execute 'runtime! autoload/vimwiki/'.syn.'_base.vim'
endfor
" -------------------------------------------------------------------------

View File

@ -237,12 +237,12 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
call vimwiki#base#validate_wiki_options(idx) call vimwiki#base#validate_wiki_options(idx)
call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx)) call vimwiki#base#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx))
if a:0 if a:0 && a:1 == 1
let cmd = 'tabedit' let cmd = 'tabedit'
else else
let cmd = 'edit' let cmd = 'edit'
endif endif
if len(a:0)>1 if a:0>1
let link = 'diary:'.a:2 let link = 'diary:'.a:2
else else
let link = 'diary:'.s:diary_date_link(idx) let link = 'diary:'.s:diary_date_link(idx)

View File

@ -422,6 +422,13 @@ function! s:tag_wikiincl(value) "{{{
if g:vimwiki_debug > 1 if g:vimwiki_debug > 1
echom '{{idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.'}}' echom '{{idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.'}}'
endif endif
" Issue 343: Image transclusions: schemeless links have .html appended.
" If link is schemeless pass it as it is
if scheme == ''
let url = lnk
endif
let url = escape(url, '#') let url = escape(url, '#')
let line = vimwiki#html#linkify_image(url, descr, verbatim_str) let line = vimwiki#html#linkify_image(url, descr, verbatim_str)
return line return line

View File

@ -1,10 +1,190 @@
" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79 " vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
" Vimwiki autoload plugin file " Vimwiki autoload plugin file
" Desc: Link functions for markdown syntax " Desc: Link functions for markdown syntax
" Author: Maxim Kim <habamax@gmail.com> " Author: Stuart Andrews <stu.andrews@gmail.com> (.. i.e. don't blame Maxim!)
" Home: http://code.google.com/p/vimwiki/ " Home: http://code.google.com/p/vimwiki/
" MISC helper functions {{{
" vimwiki#markdown_base#reset_mkd_refs
function! vimwiki#markdown_base#reset_mkd_refs() "{{{
call VimwikiClear('markdown_refs')
endfunction "}}}
" vimwiki#markdown_base#scan_reflinks
function! vimwiki#markdown_base#scan_reflinks() " {{{
let mkd_refs = {}
" construct list of references using vimgrep
try
execute 'vimgrep #'.g:vimwiki_rxMkdRef.'#j %'
catch /^Vim\%((\a\+)\)\=:E480/ " No Match
"Ignore it, and move on to the next file
endtry
"
for d in getqflist()
let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ')
let descr = matchstr(matchline, g:vimwiki_rxMkdRefMatchDescr)
let url = matchstr(matchline, g:vimwiki_rxMkdRefMatchUrl)
if descr != '' && url != ''
let mkd_refs[descr] = url
endif
endfor
call VimwikiSet('markdown_refs', mkd_refs)
return mkd_refs
endfunction "}}}
" vimwiki#markdown_base#get_reflinks
function! vimwiki#markdown_base#get_reflinks() " {{{
let done = 1
try
let mkd_refs = VimwikiGet('markdown_refs')
catch
" work-around hack
let done = 0
" ... the following command does not work inside catch block !?
" > let mkd_refs = vimwiki#markdown_base#scan_reflinks()
endtry
if !done
let mkd_refs = vimwiki#markdown_base#scan_reflinks()
endif
return mkd_refs
endfunction "}}}
" vimwiki#markdown_base#open_reflink
" try markdown reference links
function! vimwiki#markdown_base#open_reflink(link) " {{{
" echom "vimwiki#markdown_base#open_reflink"
let link = a:link
let mkd_refs = vimwiki#markdown_base#get_reflinks()
if has_key(mkd_refs, link)
let url = mkd_refs[link]
call vimwiki#base#system_open_link(url)
return 1
else
return 0
endif
endfunction " }}}
" s:normalize_path
" s:path_html
" vimwiki#base#apply_wiki_options
" vimwiki#base#read_wiki_options
" vimwiki#base#validate_wiki_options
" vimwiki#base#setup_buffer_state
" vimwiki#base#cache_buffer_state
" vimwiki#base#recall_buffer_state
" vimwiki#base#print_wiki_state
" vimwiki#base#mkdir
" vimwiki#base#file_pattern
" vimwiki#base#branched_pattern
" vimwiki#base#subdir
" vimwiki#base#current_subdir
" vimwiki#base#invsubdir
" vimwiki#base#resolve_scheme
" vimwiki#base#system_open_link
" vimwiki#base#open_link
" vimwiki#base#generate_links
" vimwiki#base#goto
" vimwiki#base#backlinks
" vimwiki#base#get_links
" vimwiki#base#edit_file
" vimwiki#base#search_word
" vimwiki#base#matchstr_at_cursor
" vimwiki#base#replacestr_at_cursor
" s:print_wiki_list
" s:update_wiki_link
" s:update_wiki_links_dir
" s:tail_name
" s:update_wiki_links
" s:get_wiki_buffers
" s:open_wiki_buffer
" vimwiki#base#nested_syntax
" }}}
" WIKI link following functions {{{
" vimwiki#base#find_next_link
" vimwiki#base#find_prev_link
" vimwiki#base#follow_link
function! vimwiki#markdown_base#follow_link(split, ...) "{{{ Parse link at cursor and pass
" to VimwikiLinkHandler, or failing that, the default open_link handler
" echom "markdown_base#follow_link"
if 0
" Syntax-specific links
" XXX: @Stuart: do we still need it?
" XXX: @Maxim: most likely! I am still working on a seemless way to
" integrate regexp's without complicating syntax/vimwiki.vim
else
if a:split == "split"
let cmd = ":split "
elseif a:split == "vsplit"
let cmd = ":vsplit "
elseif a:split == "tabnew"
let cmd = ":tabnew "
else
let cmd = ":e "
endif
" try WikiLink
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink),
\ g:vimwiki_rxWikiLinkMatchUrl)
" try WikiIncl
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl),
\ g:vimwiki_rxWikiInclMatchUrl)
endif
" try Weblink
if lnk == ""
let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink),
\ g:vimwiki_rxWeblinkMatchUrl)
endif
if lnk != ""
if !VimwikiLinkHandler(lnk)
if !vimwiki#markdown_base#open_reflink(lnk)
call vimwiki#base#open_link(cmd, lnk)
endif
endif
return
endif
if a:0 > 0
execute "normal! ".a:1
else
call vimwiki#base#normalize_link(0)
endif
endif
endfunction " }}}
" vimwiki#base#go_back_link
" vimwiki#base#goto_index
" vimwiki#base#delete_link
" vimwiki#base#rename_link
" vimwiki#base#ui_select
" TEXT OBJECTS functions {{{
" vimwiki#base#TO_header
" vimwiki#base#TO_table_cell
" vimwiki#base#TO_table_col
" }}}
" HEADER functions {{{
" vimwiki#base#AddHeaderLevel
" vimwiki#base#RemoveHeaderLevel
"}}}
" LINK functions {{{
" vimwiki#base#apply_template
" s:clean_url
" vimwiki#base#normalize_link_helper
" vimwiki#base#normalize_imagelink_helper
" s:normalize_link_syntax_n
function! s:normalize_link_syntax_n() " {{{ function! s:normalize_link_syntax_n() " {{{
let lnum = line('.') let lnum = line('.')
@ -74,6 +254,7 @@ function! s:normalize_link_syntax_n() " {{{
endfunction " }}} endfunction " }}}
" s:normalize_link_syntax_v
function! s:normalize_link_syntax_v() " {{{ function! s:normalize_link_syntax_v() " {{{
let lnum = line('.') let lnum = line('.')
let sel_save = &selection let sel_save = &selection
@ -99,13 +280,23 @@ function! s:normalize_link_syntax_v() " {{{
endfunction " }}} endfunction " }}}
" normalize_link " vimwiki#base#normalize_link
function! vimwiki#markdown_base#normalize_link(is_visual_mode) "{{{ function! vimwiki#markdown_base#normalize_link(is_visual_mode) "{{{
if !a:is_visual_mode if 0
call s:normalize_link_syntax_n() " Syntax-specific links
elseif visualmode() ==# 'v' && line("'<") == line("'>") else
" action undefined for 'line-wise' or 'multi-line' visual mode selections if !a:is_visual_mode
call s:normalize_link_syntax_v() call s:normalize_link_syntax_n()
elseif visualmode() ==# 'v' && line("'<") == line("'>")
" action undefined for 'line-wise' or 'multi-line' visual mode selections
call s:normalize_link_syntax_v()
endif
endif endif
endfunction "}}} endfunction "}}}
" }}}
" -------------------------------------------------------------------------
" Load syntax-specific Wiki functionality
" -------------------------------------------------------------------------

View File

@ -9,7 +9,7 @@
|___| |___| |_| |_||__| |__||___| |___| |_||___| ~ |___| |___| |_| |_||__| |__||___| |___| |_||___| ~
Version: 2.0 'stu' Version: 2.0.1 'stu'
============================================================================== ==============================================================================
CONTENTS *vimwiki-contents* CONTENTS *vimwiki-contents*
@ -610,10 +610,10 @@ Markdown Links~
These links are only available for Markdown syntax. See These links are only available for Markdown syntax. See
http://daringfireball.net/projects/markdown/syntax#link. http://daringfireball.net/projects/markdown/syntax#link.
Inline links: > Inline link: >
[Looks like this](URL) [Looks like this](URL)
Image links: > Image link: >
![Looks like this](URL) ![Looks like this](URL)
The URL can be anything recognized by vimwiki as a raw URL. The URL can be anything recognized by vimwiki as a raw URL.
@ -623,10 +623,26 @@ Reference-style links: >
a) [Link Name][Id] a) [Link Name][Id]
b) [Id][], using the "implicit link name" shortcut b) [Id][], using the "implicit link name" shortcut
Vimwiki treats reference style links just like default "Wikilinks". In the Reference style links must always include *two* consecutive pairs of
current implementation: the Id field must be a valid wiki page name, [-brackets, and field entries can not use "[" or "]".
reference style links must always include *two* consecutive pairs of
[-brackets, and entries can not use "[" or "]".
NOTE: (in Vimwiki's current implementation) Reference-style links are a hybrid
of Vimwiki's default "Wikilink" and the tradition reference-style link.
If the Id is defined elsewhere in the source, as per the Markdown standard: >
[Id]: URL
then the URL is opened with the system default handler. Otherwise, Vimwiki
treats the reference-sytle link as a Wikilink, interpreting the Id field as a
wiki page name.
Highlighting of existing links when |vimwiki-option-maxhi| is activated
identifies links whose Id field is not defined, either as a reference-link or
as a wiki page.
To scan the page for new or changed definitions for reference-links, simply
re-open the page ":e<CR>".
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
@ -1193,21 +1209,21 @@ Use the :VimwikiTable command to create a default table with 5 columns and 2
rows: > rows: >
| | | | | | | | | | | |
|---+---+---+---+---| |---|---|---|---|---|
| | | | | | | | | | | |
< <
Tables are auto-formattable. Let's add some text into first cell: > Tables are auto-formattable. Let's add some text into first cell: >
| First Name | | | | | | First Name | | | | |
|---+---+---+---+---| |---|---|---|---|---|
| | | | | | | | | | | |
< <
Whenever you press <TAB>, <CR> or leave Insert mode, the table is formatted: > Whenever you press <TAB>, <CR> or leave Insert mode, the table is formatted: >
| First Name | | | | | | First Name | | | | |
|------------+---+---+---+---| |------------|---|---|---|---|
| | | | | | | | | | | |
< <
@ -1215,7 +1231,7 @@ You can easily create nice-looking text tables, just press <TAB> and enter new
values: > values: >
| First Name | Last Name | Age | City | e-mail | | First Name | Last Name | Age | City | e-mail |
|------------+------------+-----+----------+----------------------| |------------|------------|-----|----------|----------------------|
| Vladislav | Pokrishkin | 31 | Moscow | vlad_pok@smail.com | | Vladislav | Pokrishkin | 31 | Moscow | vlad_pok@smail.com |
| James | Esfandiary | 27 | Istanbul | esfandiary@tmail.com | | James | Esfandiary | 27 | Istanbul | esfandiary@tmail.com |
< <
@ -2170,10 +2186,16 @@ Vim plugins: http://www.vim.org/scripts/script.php?script_id=2226
============================================================================== ==============================================================================
14. Changelog *vimwiki-changelog* 14. Changelog *vimwiki-changelog*
2.0.1 'stu'~
* Follow (i.e. open target of) markdown reference-style links.
* Bug fixes.
2.0 'stu'~ 2.0 'stu'~
This release is partly incompatible with previous. This release is partly incompatible with previous.
*
Summary ~ Summary ~
* Quick page-link creation. * Quick page-link creation.

View File

@ -195,7 +195,10 @@ function! s:setup_buffer_enter() "{{{
" Settings foldmethod, foldexpr and foldtext are local to window. Thus in a " Settings foldmethod, foldexpr and foldtext are local to window. Thus in a
" new tab with the same buffer folding is reset to vim defaults. So we " new tab with the same buffer folding is reset to vim defaults. So we
" insist vimwiki folding here. " insist vimwiki folding here.
if g:vimwiki_folding == 1 && &fdm != 'expr' if g:vimwiki_folding == 2 && &fdm != 'expr'
" User-defined fold-expression, and fold-text
endif
if g:vimwiki_folding == 1
setlocal fdm=expr setlocal fdm=expr
setlocal foldexpr=VimwikiFoldLevel(v:lnum) setlocal foldexpr=VimwikiFoldLevel(v:lnum)
setlocal foldtext=VimwikiFoldText() setlocal foldtext=VimwikiFoldText()
@ -295,6 +298,19 @@ function! VimwikiSet(option, value, ...) "{{{
let b:vimwiki_list[a:option] = a:value let b:vimwiki_list[a:option] = a:value
endif endif
endfunction "}}}
" Clear option for current wiki or if third parameter exists for
" wiki with a given index.
" Currently, only works if option was previously saved in the buffer local
" dictionary, that acts as a cache.
function! VimwikiClear(option, ...) "{{{
let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
if exists('b:vimwiki_list') && has_key(b:vimwiki_list, a:option)
call remove(b:vimwiki_list, a:option)
endif
endfunction "}}} endfunction "}}}
" }}} " }}}
@ -415,19 +431,7 @@ call s:default('rxSchemeUrlMatchUrl', rxSchemes.':\zs.*\ze')
"}}} "}}}
" AUTOCOMMANDS for all known wiki extensions {{{ " AUTOCOMMANDS for all known wiki extensions {{{
" Getting all extensions that different wikis could have let extensions = vimwiki#base#get_known_extensions()
let extensions = {}
for wiki in g:vimwiki_list
if has_key(wiki, 'ext')
let extensions[wiki.ext] = 1
else
let extensions['.wiki'] = 1
endif
endfor
" append map g:vimwiki_ext2syntax
for ext in keys(g:vimwiki_ext2syntax)
let extensions[ext] = 1
endfor
augroup filetypedetect augroup filetypedetect
" clear FlexWiki's stuff " clear FlexWiki's stuff
@ -436,7 +440,7 @@ augroup end
augroup vimwiki augroup vimwiki
autocmd! autocmd!
for ext in keys(extensions) for ext in extensions
exe 'autocmd BufEnter *'.ext.' call s:setup_buffer_reenter()' exe 'autocmd BufEnter *'.ext.' call s:setup_buffer_reenter()'
exe 'autocmd BufWinEnter *'.ext.' call s:setup_buffer_enter()' exe 'autocmd BufWinEnter *'.ext.' call s:setup_buffer_enter()'
exe 'autocmd BufLeave,BufHidden *'.ext.' call s:setup_buffer_leave()' exe 'autocmd BufLeave,BufHidden *'.ext.' call s:setup_buffer_leave()'

View File

@ -300,8 +300,10 @@ endfor
" }}} " }}}
" concealed chars " {{{ " concealed chars " {{{
let cchar = ''
if exists("+conceallevel") if exists("+conceallevel")
syntax conceal on syntax conceal on
let cchar = ' cchar=~ '
endif endif
syntax spell toplevel syntax spell toplevel
@ -329,9 +331,9 @@ execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclPrefix1.'/'.options
execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclSuffix1.'/'.options execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclSuffix1.'/'.options
" A shortener for long URLs: LinkRest (a middle part of the URL) is concealed " A shortener for long URLs: LinkRest (a middle part of the URL) is concealed
execute 'syn match VimwikiLinkRest contained `\%(///\=[^/ \t]\+/\)\zs\S\{' execute 'syn match VimwikiLinkRest `\%(///\=[^/ \t]\+/\)\zs\S\{'
\.g:vimwiki_url_mingain.',}\ze\%([/#?]\w\|\S\{' \.g:vimwiki_url_mingain.',}\ze\%([/#?]\w\|\S\{'
\.g:vimwiki_url_maxsave.'}\)` cchar=~ '.options \.g:vimwiki_url_maxsave.'}\)`'.cchar.options
execute 'syn match VimwikiEqInChar contained /'.g:vimwiki_char_eqin.'/' execute 'syn match VimwikiEqInChar contained /'.g:vimwiki_char_eqin.'/'
execute 'syn match VimwikiBoldChar contained /'.g:vimwiki_char_bold.'/' execute 'syn match VimwikiBoldChar contained /'.g:vimwiki_char_bold.'/'
@ -586,12 +588,13 @@ if !empty(nested)
\ '^\s*'.g:vimwiki_rxPreStart.'\%(.*[[:blank:][:punct:]]\)\?'. \ '^\s*'.g:vimwiki_rxPreStart.'\%(.*[[:blank:][:punct:]]\)\?'.
\ hl_syntax.'\%([[:blank:][:punct:]].*\)\?', \ hl_syntax.'\%([[:blank:][:punct:]].*\)\?',
\ '^\s*'.g:vimwiki_rxPreEnd, 'VimwikiPre') \ '^\s*'.g:vimwiki_rxPreEnd, 'VimwikiPre')
" call vimwiki#base#nested_syntax(vim_syntax,
" \ '^\s*{{\$\%(.*[[:blank:][:punct:]]\)\?'.
" \ hl_syntax.'\%([[:blank:][:punct:]].*\)\?',
" \ '^\s*}}\$', 'VimwikiMath')
endfor endfor
endif endif
" LaTeX
call vimwiki#base#nested_syntax('tex',
\ '^\s*'.g:vimwiki_rxMathStart.'\%(.*[[:blank:][:punct:]]\)\?'.
\ '\%([[:blank:][:punct:]].*\)\?',
\ '^\s*'.g:vimwiki_rxMathEnd, 'VimwikiMath')
"}}} "}}}
let timeend = vimwiki#u#time(starttime) "XXX let timeend = vimwiki#u#time(starttime) "XXX

View File

@ -83,7 +83,7 @@ let g:vimwiki_rxPreStart = '```'
let g:vimwiki_rxPreEnd = '```' let g:vimwiki_rxPreEnd = '```'
" Math block " Math block
let g:vimwiki_rxMathStart = '{{\$' let g:vimwiki_rxMathStart = '\$\$'
let g:vimwiki_rxMathEnd = '}}\$' let g:vimwiki_rxMathEnd = '\$\$'
let g:vimwiki_rxComment = '^\s*%%.*$' let g:vimwiki_rxComment = '^\s*%%.*$'

View File

@ -101,7 +101,6 @@ let g:vimwiki_rxWikiLinkMatchDescr = ''.
\ g:vimwiki_rxWikiLink1MatchDescr \ g:vimwiki_rxWikiLink1MatchDescr
" }}} " }}}
" LINKS: setup of wikiincl regexps {{{ " LINKS: setup of wikiincl regexps {{{
" }}} " }}}
@ -182,6 +181,15 @@ let g:vimwiki_rxAnyLink = g:vimwiki_rxWikiLink.'\|'.
" }}} " }}}
" LINKS: setup wikilink1 reference link definitions {{{
let g:vimwiki_rxMkdRef = '\['.g:vimwiki_rxWikiLinkDescr.']:\%(\s\+\|\n\)'.
\ g:vimwiki_rxWeblink0
let g:vimwiki_rxMkdRefMatchDescr = '\[\zs'.g:vimwiki_rxWikiLinkDescr.'\ze]:\%(\s\+\|\n\)'.
\ g:vimwiki_rxWeblink0
let g:vimwiki_rxMkdRefMatchUrl = '\['.g:vimwiki_rxWikiLinkDescr.']:\%(\s\+\|\n\)\zs'.
\ g:vimwiki_rxWeblink0.'\ze'
" }}}
" }}} end of Links " }}} end of Links
" LINKS: highlighting is complicated due to "nonexistent" links feature {{{ " LINKS: highlighting is complicated due to "nonexistent" links feature {{{
@ -214,6 +222,11 @@ function! s:wrap_wikilink1_rx(target) "{{{
\ g:vimwiki_rxWikiLink1InvalidSuffix \ g:vimwiki_rxWikiLink1InvalidSuffix
endfunction "}}} endfunction "}}}
function! s:existing_mkd_refs() "{{{
call vimwiki#markdown_base#reset_mkd_refs()
return "\n".join(keys(vimwiki#markdown_base#get_reflinks()), "\n")."\n"
endfunction "}}}
function! s:highlight_existing_links() "{{{ function! s:highlight_existing_links() "{{{
" Wikilink1 " Wikilink1
" Conditional highlighting that depends on the existence of a wiki file or " Conditional highlighting that depends on the existence of a wiki file or
@ -222,8 +235,11 @@ function! s:highlight_existing_links() "{{{
let safe_links = vimwiki#base#file_pattern(b:existing_wikifiles) let safe_links = vimwiki#base#file_pattern(b:existing_wikifiles)
" Wikilink1 Dirs set up upon BufEnter (see plugin/...) " Wikilink1 Dirs set up upon BufEnter (see plugin/...)
let safe_dirs = vimwiki#base#file_pattern(b:existing_wikidirs) let safe_dirs = vimwiki#base#file_pattern(b:existing_wikidirs)
" Ref links are cached
let safe_reflinks = vimwiki#base#file_pattern(s:existing_mkd_refs())
" match [URL]
" match [URL][]
let target = vimwiki#base#apply_template(g:vimwiki_WikiLink1Template1, let target = vimwiki#base#apply_template(g:vimwiki_WikiLink1Template1,
\ safe_links, g:vimwiki_rxWikiLink1Descr, '') \ safe_links, g:vimwiki_rxWikiLink1Descr, '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
@ -232,7 +248,7 @@ function! s:highlight_existing_links() "{{{
\ safe_links, g:vimwiki_rxWikiLink1Descr, '') \ safe_links, g:vimwiki_rxWikiLink1Descr, '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DIRURL] " match [DIRURL][]
let target = vimwiki#base#apply_template(g:vimwiki_WikiLink1Template1, let target = vimwiki#base#apply_template(g:vimwiki_WikiLink1Template1,
\ safe_dirs, g:vimwiki_rxWikiLink1Descr, '') \ safe_dirs, g:vimwiki_rxWikiLink1Descr, '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
@ -240,6 +256,15 @@ function! s:highlight_existing_links() "{{{
let target = vimwiki#base#apply_template(g:vimwiki_WikiLink1Template2, let target = vimwiki#base#apply_template(g:vimwiki_WikiLink1Template2,
\ safe_dirs, g:vimwiki_rxWikiLink1Descr, '') \ safe_dirs, g:vimwiki_rxWikiLink1Descr, '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1') call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [MKDREF][]
let target = vimwiki#base#apply_template(g:vimwiki_WikiLink1Template1,
\ safe_reflinks, g:vimwiki_rxWikiLink1Descr, '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
" match [DESCRIPTION][MKDREF]
let target = vimwiki#base#apply_template(g:vimwiki_WikiLink1Template2,
\ safe_reflinks, g:vimwiki_rxWikiLink1Descr, '')
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
endfunction "}}} endfunction "}}}