diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..cdf8546
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2008-2010 Maxim Kim
+ 2013-2017 Daniel Schemala
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index a407040..11d0824 100644
--- a/README.md
+++ b/README.md
@@ -135,6 +135,15 @@ Installation using [Pathogen](http://www.vim.org/scripts/script.php?script_id=23
cd bundle
git clone https://github.com/vimwiki/vimwiki.git
+Installation using [Vim-Plug](https://github.com/junegunn/vim-plug)
+------------------------------------------------------------------------------
+
+Add the following to the plugin-configuration in your vimrc:
+
+ Plug 'vimwiki/vimwiki', { 'branch': 'dev' }
+
+Then run `:PlugInstall`.
+
Installation using [Vundle](https://github.com/VundleVim/Vundle.vim)
------------------------------------------------------------------------------
@@ -146,6 +155,14 @@ Or download the [zip archive](https://github.com/vimwiki/vimwiki/archive/master.
Then launch Vim, run `:Helptags` and then `:help vimwiki` to verify it was installed.
+
+Getting help
+==============================================================================
+
+Have a question? Visit the IRC channel `#vimwiki` on Freenode ([webchat](https://webchat.freenode.net/?channels=#vimwiki))
+or post to the [mailing list](https://groups.google.com/forum/#!forum/vimwiki).
+
+
----
\* Screenshots made with the [solarized colorscheme](https://github.com/altercation/vim-colors-solarized)
and [lightline](https://github.com/itchyny/lightline.vim)
diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
index 0cd537a..3a6e128 100644
--- a/autoload/vimwiki/base.vim
+++ b/autoload/vimwiki/base.vim
@@ -1,4 +1,4 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
+" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file
" Desc: Basic functionality
" Home: https://github.com/vimwiki/vimwiki/
@@ -8,183 +8,43 @@ if exists("g:loaded_vimwiki_auto") || &cp
endif
let g:loaded_vimwiki_auto = 1
-" s:vimwiki_get_known_syntaxes
-function! s:vimwiki_get_known_syntaxes() " {{{
+
+function! s:safesubstitute(text, search, replace, mode)
+ " Substitute regexp but do not interpret replace
+ let escaped = escape(a:replace, '\&')
+ return substitute(a:text, a:search, escaped, a:mode)
+endfunction
+
+
+function! s:vimwiki_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
+ for wiki_nr in range(vimwiki#vars#number_of_wikis())
+ let wiki_syntax = vimwiki#vars#get_wikilocal('syntax', wiki_nr)
+ let syntaxes[wiki_syntax] = 1
endfor
- " append map g:vimwiki_ext2syntax
- for syn in values(g:vimwiki_ext2syntax)
+ " also consider the syntaxes from g:vimwiki_ext2syntax
+ for syn in values(vimwiki#vars#get_global('ext2syntax'))
let syntaxes[syn] = 1
endfor
return keys(syntaxes)
-endfunction " }}}
+endfunction
-" vimwiki#base#apply_wiki_options
-function! vimwiki#base#apply_wiki_options(options) " {{{ Update the current
- " wiki using the options dictionary
- for kk in keys(a:options)
- let g:vimwiki_list[g:vimwiki_current_idx][kk] = a:options[kk]
- endfor
- call Validate_wiki_options(g:vimwiki_current_idx)
- call vimwiki#base#setup_buffer_state(g:vimwiki_current_idx)
-endfunction " }}}
-" vimwiki#base#read_wiki_options
-function! vimwiki#base#read_wiki_options(check) " {{{ Attempt to read wiki
- " 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 g:local_wiki, a message alerts the user that an update has been
- " found and may be applied. If the argument check=1, the user is queried
- " before applying the update to the current wiki's option.
-
- " Save global vimwiki options ... after all, the global list is often
- " initialized for the first time in vimrc files, and we don't want to
- " overwrite !! (not to mention all the other globals ...)
- let l:vimwiki_list = deepcopy(g:vimwiki_list, 1)
- "
- if a:check > 1
- call vimwiki#base#print_wiki_state()
- echo " \n"
- endif
- "
- let g:local_wiki = {}
- let done = 0
- " ... start the wild-goose chase!
- for invsubdir in ['.', '..', '../..', '../../..']
- " other names are possible, but most vimrc files will cause grief!
- for nm in ['vimwiki.vimrc']
- " TODO: use an alternate strategy, instead of source, to read options
- if done
- continue
- endif
- "
- let local_wiki_options_filename = expand('%:p:h').'/'.invsubdir.'/'.nm
- if !filereadable(local_wiki_options_filename)
- continue
- endif
- "
- echo "\nFound file : ".local_wiki_options_filename
- let query = "Vimwiki: Check for options in this file [Y]es/[n]o? "
- if a:check > 0 && input(query) =~? '^n')
- continue
- endif
- "
- try
- execute 'source '.local_wiki_options_filename
- catch
- endtry
- if empty(g:local_wiki)
- continue
- endif
- "
- if a:check > 0
- echo "\n\nFound wiki options\n g:local_wiki = ".string(g:local_wiki)
- let query = "Vimwiki: Apply these options [Y]es/[n]o? "
- if input(query) =~? '^n'
- let g:local_wiki = {}
- continue
- endif
- endif
- "
- " restore global list
- " - this prevents corruption by g:vimwiki_list in options_file
- let g:vimwiki_list = deepcopy(l:vimwiki_list, 1)
- "
- call vimwiki#base#apply_wiki_options(g:local_wiki)
- let done = 1
- endfor
- endfor
- if !done
- "
- " restore global list, if no local options were found
- " - this prevents corruption by g:vimwiki_list in options_file
- let g:vimwiki_list = deepcopy(l:vimwiki_list, 1)
- "
- endif
- if a:check > 1
- echo " \n "
- if done
- call vimwiki#base#print_wiki_state()
- else
- echo "Vimwiki: No options were applied."
- endif
- endif
-endfunction " }}}
-
-" vimwiki#base#setup_buffer_state
-function! vimwiki#base#setup_buffer_state(idx) " {{{ Init page-specific variables
- " Only call this function *after* opening a wiki page.
- if a:idx < 0
- return
- endif
-
- let g:vimwiki_current_idx = a:idx
-
- " The following state depends on the current active wiki page
- let subdir = vimwiki#base#current_subdir(a:idx)
- call VimwikiSet('subdir', subdir, a:idx)
- call VimwikiSet('invsubdir', vimwiki#base#invsubdir(subdir), a:idx)
-
- if g:vimwiki_auto_chdir == 1
- exe 'lcd' VimwikiGet('path')
- endif
-
- " update cache
- call vimwiki#base#cache_buffer_state()
-endfunction " }}}
-
-" vimwiki#base#cache_buffer_state
-function! vimwiki#base#cache_buffer_state() "{{{
- let b:vimwiki_idx = g:vimwiki_current_idx
-endfunction "}}}
-
-" vimwiki#base#recall_buffer_state
-function! vimwiki#base#recall_buffer_state() "{{{
- if !exists('b:vimwiki_idx')
- return 0
- else
- let g:vimwiki_current_idx = b:vimwiki_idx
- return 1
- endif
-endfunction " }}}
-
-" vimwiki#base#print_wiki_state
-function! vimwiki#base#print_wiki_state() "{{{ print wiki options
- " and buffer state variables
- let g_width = 18
- let b_width = 18
- echo "- Wiki Options (idx=".g:vimwiki_current_idx.") -"
- for kk in VimwikiGetOptionNames()
- echo " '".kk."': ".repeat(' ', g_width-len(kk)).string(VimwikiGet(kk))
- endfor
- if !exists('b:vimwiki_list')
- return
- endif
- echo "- Cached Variables -"
- for kk in keys(b:vimwiki_list)
- echo " '".kk."': ".repeat(' ', b_width-len(kk)).string(b:vimwiki_list[kk])
- endfor
-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
" names that are compatible with any external restrictions that they
" encounter (e.g. filesystem, wiki conventions, other syntaxes, ...).
" See: https://github.com/vimwiki-backup/vimwiki/issues/316
- " Change / to [/\\] to allow "Windows paths"
+ " Change / to [/\\] to allow "Windows paths"
return '\V\%('.join(a:files, '\|').'\)\m'
-endfunction "}}}
+endfunction
+
-" vimwiki#base#subdir
"FIXME TODO slow and faulty
-function! vimwiki#base#subdir(path, filename) "{{{
+function! vimwiki#base#subdir(path, filename)
let path = a:path
" ensure that we are not fooled by a symbolic link
"FIXME if we are not "fooled", we end up in a completely different wiki?
@@ -205,58 +65,57 @@ function! vimwiki#base#subdir(path, filename) "{{{
let res = res.'/'
endif
return res
-endfunction "}}}
+endfunction
-" vimwiki#base#current_subdir
-function! vimwiki#base#current_subdir(idx)"{{{
- return vimwiki#base#subdir(VimwikiGet('path', a:idx), expand('%:p'))
-endfunction"}}}
-" vimwiki#base#invsubdir
-function! vimwiki#base#invsubdir(subdir) " {{{
+function! vimwiki#base#current_subdir()
+ return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), expand('%:p'))
+endfunction
+
+
+function! vimwiki#base#invsubdir(subdir)
return substitute(a:subdir, '[^/\.]\+/', '../', 'g')
-endfunction " }}}
+endfunction
-" Returns: the number of the wiki a file belongs to
-function! vimwiki#base#find_wiki(path) "{{{
+" Returns: the number of the wiki a file belongs to or -1 if it doesn't belong
+" to any registered wiki.
+" The path can be the full path or just the directory of the file
+function! vimwiki#base#find_wiki(path)
+ let bestmatch = -1
+ let bestlen = 0
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))
+ for idx in range(vimwiki#vars#number_of_wikis())
+ let idx_path = expand(vimwiki#vars#get_wikilocal('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
+ let common_pfx = vimwiki#path#path_common_pfx(idx_path, path)
+ if vimwiki#path#is_equal(common_pfx, idx_path)
+ if len(common_pfx) > bestlen
+ let bestlen = len(common_pfx)
+ let bestmatch = idx
+ endif
endif
- let idx += 1
- endwhile
+ endfor
- " an orphan page has been detected
- return -1
-endfunction "}}}
+ return bestmatch
+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, ...) "{{{
+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_wiki = vimwiki#vars#get_bufferlocal('wiki_nr')
let source_file = vimwiki#path#current_wiki_file()
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,
@@ -265,21 +124,25 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
\ 'anchor': '',
\ }
-
- " extract scheme
- let link_infos.scheme = matchstr(link_text, g:vimwiki_rxSchemeUrlMatchScheme)
- if link_infos.scheme == '' || link_text == ''
- let link_infos.filename = '' " malformed link
+ if link_text == ''
return link_infos
endif
- if link_infos.scheme !~# '\mwiki\d\+\|diary\|local\|file'
- let link_infos.filename = link_text " unknown scheme, may be a weblink
- 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'
+ let scheme = matchstr(link_text, '^\zs'.vimwiki#vars#get_global('rxSchemes').'\ze:')
+ if scheme == ''
+ let link_infos.scheme = 'wiki'.source_wiki
+ else
+ let link_infos.scheme = scheme
+
+ if link_infos.scheme !~# '\mwiki\d\+\|diary\|local\|file'
+ let link_infos.filename = link_text " unknown scheme, may be a weblink
+ return link_infos
+ endif
+
+ let link_text = matchstr(link_text, '^'.vimwiki#vars#get_global('rxSchemes').':\zs.*\ze')
+ endif
+
+ let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' || link_infos.scheme ==# 'diary'
" extract anchor
if is_wiki_link
@@ -310,36 +173,35 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
" 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)
+ if link_infos.index < 0 || link_infos.index >= vimwiki#vars#number_of_wikis()
let link_infos.filename = ''
return link_infos
endif
if !is_relative || link_infos.index != source_wiki
- let root_dir = VimwikiGet('path', link_infos.index)
+ let root_dir = vimwiki#vars#get_wikilocal('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)
+ if vimwiki#vars#get_global('dir_link') != ''
+ let link_infos.filename .= vimwiki#vars#get_global('dir_link') .
+ \ vimwiki#vars#get_wikilocal('ext', link_infos.index)
endif
else
- let link_infos.filename .= VimwikiGet('ext', link_infos.index)
+ let link_infos.filename .= vimwiki#vars#get_wikilocal('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) .
+ \ vimwiki#vars#get_wikilocal('path', link_infos.index) .
+ \ vimwiki#vars#get_wikilocal('diary_rel_path', link_infos.index) .
\ link_text .
- \ VimwikiGet('ext', link_infos.index)
- elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local')
- \ && is_relative
+ \ vimwiki#vars#get_wikilocal('ext', link_infos.index)
+ elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local') && is_relative
let link_infos.filename = simplify(root_dir . link_text)
else " absolute file link
" collapse repeated leading "/"'s within a link
@@ -351,11 +213,10 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
let link_infos.filename = vimwiki#path#normalize(link_infos.filename)
return link_infos
-endfunction "}}}
+endfunction
-" vimwiki#base#system_open_link
-function! vimwiki#base#system_open_link(url) "{{{
+function! vimwiki#base#system_open_link(url)
" handlers
function! s:win32_handler(url)
"http://vim.wikia.com/wiki/Opening_current_Vim_file_in_your_Windows_browser
@@ -370,7 +231,11 @@ function! vimwiki#base#system_open_link(url) "{{{
else
let url = shellescape(a:url, 1)
endif
- execute 'silent ! start "Title" /B ' . url
+ if &l:shell ==? "powershell"
+ execute 'silent ! start ' . a:url
+ else
+ execute 'silent ! start "Title" /B ' . a:url
+ endif
endfunction
function! s:macunix_handler(url)
call system('open ' . shellescape(a:url).' &')
@@ -391,19 +256,23 @@ function! vimwiki#base#system_open_link(url) "{{{
endif
endtry
echomsg 'Vimwiki Error: Default Vimwiki link handler was unable to open the HTML file!'
-endfunction "}}}
+endfunction
-" vimwiki#base#open_link
-function! vimwiki#base#open_link(cmd, link, ...) "{{{
- let link_infos = vimwiki#base#resolve_link(a:link)
+
+function! vimwiki#base#open_link(cmd, link, ...)
+ let link_infos = {}
+ if a:0
+ let link_infos = vimwiki#base#resolve_link(a:link, a:1)
+ else
+ let link_infos = vimwiki#base#resolve_link(a:link)
+ endif
if link_infos.filename == ''
echomsg 'Vimwiki Error: Unable to resolve link!'
return
endif
- let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+'
- \ || link_infos.scheme =~# 'diary'
+ let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' || link_infos.scheme =~# 'diary'
let update_prev_link = is_wiki_link &&
\ !vimwiki#path#is_equal(link_infos.filename, vimwiki#path#current_wiki_file())
@@ -422,24 +291,21 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{
if is_wiki_link
call vimwiki#base#edit_file(a:cmd, link_infos.filename, link_infos.anchor,
\ vimwiki_prev_link, update_prev_link)
- if link_infos.index != g:vimwiki_current_idx
- " this call to setup_buffer_state may not be necessary
- call vimwiki#base#setup_buffer_state(link_infos.index)
- endif
else
call vimwiki#base#system_open_link(link_infos.filename)
endif
-endfunction " }}}
+endfunction
-" vimwiki#base#get_globlinks_escaped
-function! vimwiki#base#get_globlinks_escaped() abort "{{{only get links from the current dir
+
+function! vimwiki#base#get_globlinks_escaped() abort
+ " only get links from the current dir
" change to the directory of the current file
let orig_pwd = getcwd()
lcd! %:h
- " all path are relative to the current file's location
- let globlinks = glob('*'.VimwikiGet('ext'),1)."\n"
+ " all path are relative to the current file's location
+ let globlinks = glob('*'.vimwiki#vars#get_wikilocal('ext'), 1)."\n"
" remove extensions
- let globlinks = substitute(globlinks, '\'.VimwikiGet('ext').'\ze\n', '', 'g')
+ let globlinks = substitute(globlinks, '\'.vimwiki#vars#get_wikilocal('ext').'\ze\n', '', 'g')
" restore the original working directory
exe 'lcd! '.orig_pwd
" convert to a List
@@ -450,47 +316,46 @@ function! vimwiki#base#get_globlinks_escaped() abort "{{{only get links from the
let globlinks = join(lst, "\n")
" return all escaped links as a single newline-separated string
return globlinks
-endfunction " }}}
+endfunction
-" vimwiki#base#generate_links
-function! vimwiki#base#generate_links() "{{{
+
+function! vimwiki#base#generate_links()
let lines = []
- let links = vimwiki#base#get_wikilinks(g:vimwiki_current_idx, 0)
+ let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0)
call sort(links)
- let bullet = repeat(' ', vimwiki#lst#get_list_margin()).
- \ vimwiki#lst#default_symbol().' '
+ let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' '
for link in links
let abs_filepath = vimwiki#path#abs_path_of_link(link)
if !s:is_diary_file(abs_filepath)
call add(lines, bullet.
- \ substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', '\='."'".link."'", ''))
+ \ s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
+ \ '__LinkUrl__', link, ''))
endif
endfor
let links_rx = '\m^\s*'.vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
- call vimwiki#base#update_listing_in_buffer(lines, 'Generated Links', links_rx,
- \ line('$')+1, 1)
-endfunction " }}}
+ call vimwiki#base#update_listing_in_buffer(lines, 'Generated Links', links_rx, line('$')+1, 1)
+endfunction
-" vimwiki#base#goto
-function! vimwiki#base#goto(...) "{{{
+
+function! vimwiki#base#goto(...)
let key = a:1
let anchor = a:0 > 1 ? a:2 : ''
call vimwiki#base#edit_file(':e',
- \ VimwikiGet('path') . key . VimwikiGet('ext'),
+ \ vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext'),
\ anchor)
-endfunction "}}}
+endfunction
-" vimwiki#base#backlinks
-function! vimwiki#base#backlinks() "{{{
+
+function! vimwiki#base#backlinks()
let current_filename = expand("%:p")
let locations = []
- for idx in range(len(g:vimwiki_list))
- let syntax = VimwikiGet('syntax', idx)
+ for idx in range(vimwiki#vars#number_of_wikis())
+ let syntax = vimwiki#vars#get_wikilocal('syntax', idx)
let wikifiles = vimwiki#base#find_files(idx, 0)
for source_file in wikifiles
let links = s:get_links(source_file, idx)
@@ -510,7 +375,8 @@ function! vimwiki#base#backlinks() "{{{
call setloclist(0, locations, 'r')
lopen
endif
-endfunction "}}}
+endfunction
+
" Returns: a list containing all files of the given wiki as absolute file path.
" If the given wiki number is negative, the diary of the current wiki is used
@@ -518,20 +384,21 @@ endfunction "}}}
function! vimwiki#base#find_files(wiki_nr, directories_only)
let wiki_nr = a:wiki_nr
if wiki_nr >= 0
- let root_directory = VimwikiGet('path', wiki_nr)
+ let root_directory = vimwiki#vars#get_wikilocal('path', wiki_nr)
else
- let root_directory = VimwikiGet('path').VimwikiGet('diary_rel_path')
- let wiki_nr = g:vimwiki_current_idx
+ let root_directory = vimwiki#vars#get_wikilocal('path') .
+ \ vimwiki#vars#get_wikilocal('diary_rel_path')
+ let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
endif
if a:directories_only
let ext = '/'
else
- let ext = VimwikiGet('ext', wiki_nr)
+ let ext = vimwiki#vars#get_wikilocal('ext', wiki_nr)
endif
" if current wiki is temporary -- was added by an arbitrary wiki file then do
" not search wiki files in subdirectories. Or it would hang the system if
" wiki file was created in $HOME or C:/ dirs.
- if VimwikiGet('temp', wiki_nr)
+ if vimwiki#vars#get_wikilocal('is_temporary_wiki', wiki_nr)
let pattern = '*'.ext
else
let pattern = '**/*'.ext
@@ -539,18 +406,19 @@ function! vimwiki#base#find_files(wiki_nr, directories_only)
return split(globpath(root_directory, pattern), '\n')
endfunction
+
" 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 = vimwiki#base#find_files(a:wiki_nr, 0)
- if a:wiki_nr == g:vimwiki_current_idx
+ if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
elseif a:wiki_nr < 0
- let cwd = VimwikiGet('path').VimwikiGet('diary_rel_path')
+ let cwd = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path')
else
- let cwd = VimwikiGet('path', a:wiki_nr)
+ let cwd = vimwiki#vars#get_wikilocal('path', a:wiki_nr)
endif
let result = []
for wikifile in files
@@ -560,10 +428,10 @@ function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
endfor
if a:also_absolute_links
for wikifile in files
- if a:wiki_nr == g:vimwiki_current_idx
- let cwd = VimwikiGet('path')
+ if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
+ let cwd = vimwiki#vars#get_wikilocal('path')
elseif a:wiki_nr < 0
- let cwd = VimwikiGet('path').VimwikiGet('diary_rel_path')
+ let cwd = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path')
endif
let wikifile = fnamemodify(wikifile, ':r') " strip extension
let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile)
@@ -573,20 +441,21 @@ function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
return result
endfunction
+
" Returns: a list containing the links to all directories from the current file
function! vimwiki#base#get_wiki_directories(wiki_nr)
let dirs = vimwiki#base#find_files(a:wiki_nr, 1)
- if a:wiki_nr == g:vimwiki_current_idx
+ if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
- let root_dir = VimwikiGet('path')
+ let root_dir = vimwiki#vars#get_wikilocal('path')
else
- let cwd = VimwikiGet('path', a:wiki_nr)
+ let cwd = vimwiki#vars#get_wikilocal('path', a:wiki_nr)
endif
let result = ['./']
for wikidir in dirs
let wikidir_relative = vimwiki#path#relpath(cwd, wikidir)
call add(result, wikidir_relative)
- if a:wiki_nr == g:vimwiki_current_idx
+ if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
let wikidir_absolute = '/'.vimwiki#path#relpath(root_dir, wikidir)
call add(result, wikidir_absolute)
endif
@@ -594,14 +463,15 @@ function! vimwiki#base#get_wiki_directories(wiki_nr)
return result
endfunction
-function! vimwiki#base#get_anchors(filename, syntax) "{{{
+
+function! vimwiki#base#get_anchors(filename, syntax)
if !filereadable(a:filename)
return []
endif
- let rxheader = g:vimwiki_{a:syntax}_header_search
- let rxbold = g:vimwiki_{a:syntax}_bold_search
- let rxtag = g:vimwiki_{a:syntax}_tag_search
+ let rxheader = vimwiki#vars#get_syntaxlocal('header_search', a:syntax)
+ let rxbold = vimwiki#vars#get_syntaxlocal('bold_search', a:syntax)
+ let rxtag = vimwiki#vars#get_syntaxlocal('tag_search', a:syntax)
let anchor_level = ['', '', '', '', '', '', '']
let anchors = []
@@ -665,47 +535,49 @@ function! vimwiki#base#get_anchors(filename, syntax) "{{{
endfor
return anchors
-endfunction "}}}
+endfunction
-" s:jump_to_anchor
-function! s:jump_to_anchor(anchor) "{{{
+
+function! s:jump_to_anchor(anchor)
let oldpos = getpos('.')
call cursor(1, 1)
let anchor = vimwiki#u#escape(a:anchor)
let segments = split(anchor, '#', 0)
+
for segment in segments
- let anchor_header = substitute(
- \ g:vimwiki_{VimwikiGet('syntax')}_header_match,
- \ '__Header__', "\\='".segment."'", '')
- let anchor_bold = substitute(g:vimwiki_{VimwikiGet('syntax')}_bold_match,
- \ '__Text__', "\\='".segment."'", '')
- let anchor_tag = substitute(g:vimwiki_{VimwikiGet('syntax')}_tag_match,
- \ '__Tag__', "\\='".segment."'", '')
+ let anchor_header = s:safesubstitute(
+ \ vimwiki#vars#get_syntaxlocal('header_match'),
+ \ '__Header__', segment, '')
+ let anchor_bold = s:safesubstitute(
+ \ vimwiki#vars#get_syntaxlocal('bold_match'),
+ \ '__Text__', segment, '')
+ let anchor_tag = s:safesubstitute(
+ \ vimwiki#vars#get_syntaxlocal('tag_match'),
+ \ '__Tag__', segment, '')
- if !search(anchor_tag, 'Wc')
- \ && !search(anchor_header, 'Wc')
- \ && !search(anchor_bold, 'Wc')
+ if !search(anchor_tag, 'Wc') && !search(anchor_header, 'Wc') && !search(anchor_bold, 'Wc')
call setpos('.', oldpos)
break
endif
let oldpos = getpos('.')
endfor
-endfunction "}}}
+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
" [target file, anchor, line number of the link in source file, column number]
-function! s:get_links(wikifile, idx) "{{{
+function! s:get_links(wikifile, idx)
if !filereadable(a:wikifile)
return []
endif
- let syntax = VimwikiGet('syntax', a:idx)
- let rx_link = g:vimwiki_{syntax}_wikilink
+ let syntax = vimwiki#vars#get_wikilocal('syntax', a:idx)
+ let rx_link = vimwiki#vars#get_syntaxlocal('wikilink', syntax)
let links = []
let lnum = 0
@@ -721,22 +593,22 @@ function! s:get_links(wikifile, idx) "{{{
endif
let link_count += 1
let target = vimwiki#base#resolve_link(link_text, a:wikifile)
- if target.filename != '' &&
- \ target.scheme =~# '\mwiki\d\+\|diary\|file\|local'
+ if target.filename != '' && target.scheme =~# '\mwiki\d\+\|diary\|file\|local'
call add(links, [target.filename, target.anchor, lnum, col])
endif
endwhile
endfor
return links
-endfunction "}}}
+endfunction
-function! vimwiki#base#check_links() "{{{
+
+function! vimwiki#base#check_links()
let anchors_of_files = {}
let links_of_files = {}
let errors = []
- for idx in range(len(g:vimwiki_list))
- let syntax = VimwikiGet('syntax', idx)
+ for idx in range(vimwiki#vars#number_of_wikis())
+ let syntax = vimwiki#vars#get_wikilocal('syntax', idx)
let wikifiles = vimwiki#base#find_files(idx, 0)
for wikifile in wikifiles
let links_of_files[wikifile] = s:get_links(wikifile, idx)
@@ -789,9 +661,9 @@ function! vimwiki#base#check_links() "{{{
endfor
" mark every index file as reachable
- for idx in range(len(g:vimwiki_list))
- let index_file = VimwikiGet('path', idx) . VimwikiGet('index', idx) .
- \ VimwikiGet('ext', idx)
+ for idx in range(vimwiki#vars#number_of_wikis())
+ let index_file = vimwiki#vars#get_wikilocal('path', idx) .
+ \ vimwiki#vars#get_wikilocal('index', idx) . vimwiki#vars#get_wikilocal('ext', idx)
if filereadable(index_file)
let reachable_wikifiles[index_file] = 1
endif
@@ -828,19 +700,11 @@ function! vimwiki#base#check_links() "{{{
call setqflist(errors, 'r')
copen
endif
-endfunction "}}}
+endfunction
-" vimwiki#base#edit_file
-function! vimwiki#base#edit_file(command, filename, anchor, ...) "{{{
- " XXX: Should we allow * in filenames!?
- " Maxim: It is allowed, escaping here is for vim to be able to open files
- " which have that symbols.
- " Try to remove * from escaping and open&save :
- " [[testBLAfile]]...
- " then
- " [[test*file]]...
- " you'll have E77: Too many file names
- let fname = escape(a:filename, '% *|#')
+
+function! vimwiki#base#edit_file(command, filename, anchor, ...)
+ let fname = escape(a:filename, '% *|#`')
let dir = fnamemodify(a:filename, ":p:h")
let ok = vimwiki#path#mkdir(dir, 1)
@@ -851,17 +715,33 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) "{{{
return
endif
- " check if the file we want to open is already the current file
+ " Check if the file we want to open is already the current file
" which happens if we jump to an achor in the current file.
" This hack is necessary because apparently Vim messes up the result of
" getpos() directly after this command. Strange.
if !(a:command ==# ':e ' && vimwiki#path#is_equal(a:filename, expand('%:p')))
- execute a:command.' '.fname
+ try
+ if &autowriteall && !&hidden " in this case, the file is saved before switching to the
+ " new buffer. This causes Vim to show two messages in the command line which triggers
+ " the annoying hit-enter prompt. Solution: show no messages at all.
+ silent execute a:command fname
+ else
+ execute a:command fname
+ endif
+ catch /E37:/
+ echomsg 'Vimwiki: The current file is modified. Hint: Take a look at'
+ \ ''':h g:vimwiki_autowriteall'' to see how to save automatically.'
+ return
+ endtry
+
+ " If the opened file was not already loaded by Vim, an autocommand is
+ " triggered at this point
+
" Make sure no other plugin takes ownership over the new file. Vimwiki
" rules them all! Well, except for directories, which may be opened with
" Netrw
if &filetype != 'vimwiki' && fname !~ '\m/$'
- set filetype=vimwiki
+ setfiletype vimwiki
endif
endif
if a:anchor != ''
@@ -872,21 +752,21 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) "{{{
" a:1 -- previous vimwiki link to save
" a:2 -- should we update previous link
if a:0 && a:2 && len(a:1) > 0
- let b:vimwiki_prev_link = a:1
+ call vimwiki#vars#set_bufferlocal('prev_link', a:1)
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)
if match_line == 0
echomsg 'Vimwiki: Wiki link not found'
endif
-endfunction " }}}
+endfunction
+
-" vimwiki#base#matchstr_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 line = getline('.')
let ebeg = -1
@@ -906,10 +786,10 @@ function! vimwiki#base#matchstr_at_cursor(wikiRX) "{{{
else
return ""
endif
-endf "}}}
+endfunction
-" 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 line = getline('.')
let ebeg = -1
@@ -929,27 +809,27 @@ function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) "{{{
let newline = strpart(line, 0, ebeg).a:sub.strpart(line, ebeg+elen)
call setline(line('.'), newline)
endif
-endf "}}}
+endfunction
-" s:print_wiki_list
-function! s:print_wiki_list() "{{{
+
+function! s:print_wiki_list()
let idx = 0
- while idx < len(g:vimwiki_list)
- if idx == g:vimwiki_current_idx
+ while idx < vimwiki#vars#number_of_wikis()
+ if idx == vimwiki#vars#get_bufferlocal('wiki_nr')
let sep = ' * '
echohl PmenuSel
else
let sep = ' '
echohl None
endif
- echo (idx + 1).sep.VimwikiGet('path', idx)
+ echo (idx + 1) . sep . vimwiki#vars#get_wikilocal('path', idx)
let idx += 1
endwhile
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
let has_updates = 0
let dest = []
@@ -966,32 +846,33 @@ function! s:update_wiki_link(fname, old, new) " {{{
call writefile(dest, a:fname)
call delete(a:fname.'#vimwiki_upd#')
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 new_fname = a:new_fname
let old_fname_r = vimwiki#base#apply_template(
- \ g:vimwiki_WikiLinkMatchUrlTemplate, old_fname, '', '')
+ \ vimwiki#vars#get_syntaxlocal('WikiLinkMatchUrlTemplate'), old_fname, '', '')
- let files = split(glob(VimwikiGet('path').a:dir.'*'.VimwikiGet('ext')), '\n')
+ let files = split(glob(vimwiki#vars#get_wikilocal('path').a:dir.'*'.
+ \ vimwiki#vars#get_wikilocal('ext')), '\n')
for fname in files
call s:update_wiki_link(fname, old_fname_r, new_fname)
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 = fnamemodify(result, ":t:r")
let result = substitute(result, "__colon__", ":", "g")
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 = a:old_fname
let new_fname = a:new_fname
@@ -1017,39 +898,40 @@ function! s:update_wiki_links(old_fname, new_fname) " {{{
while idx < len(dirs_keys)
let dir = dirs_keys[idx]
let new_dir = dirs_vals[idx]
- call s:update_wiki_links_dir(dir,
- \ new_dir.old_fname, new_dir.new_fname)
+ call s:update_wiki_links_dir(dir, new_dir.old_fname, new_dir.new_fname)
let idx = idx + 1
endwhile
-endfunction " }}}
+endfunction
-" s:get_wiki_buffers
-function! s:get_wiki_buffers() "{{{
+
+function! s:get_wiki_buffers()
let blist = []
let bcount = 1
while bcount<=bufnr("$")
if bufexists(bcount)
let bname = fnamemodify(bufname(bcount), ":p")
- if bname =~# VimwikiGet('ext')."$"
- let bitem = [bname, getbufvar(bname, "vimwiki_prev_link")]
+ " this may find buffers that are not part of the current wiki, but that
+ " doesn't hurt
+ if bname =~# vimwiki#vars#get_wikilocal('ext')."$"
+ let bitem = [bname, vimwiki#vars#get_bufferlocal('prev_link', bcount)]
call add(blist, bitem)
endif
endif
let bcount = bcount + 1
endwhile
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], '')
if !empty(a:item[1])
- call setbufvar(a:item[0], "vimwiki_prev_link", a:item[1])
+ call vimwiki#vars#set_bufferlocal('prev_link', a:item[1], a:item[0])
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
let ft=toupper(a:filetype)
let group='textGroup'.ft
@@ -1096,14 +978,15 @@ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{
" regular one.
" Perl syntax file has perlFunctionName which is usually has no effect due to
" 'contained' flag. Now we have 'syntax include' that makes all the groups
- " included as 'contained' into specific group.
+ " included as 'contained' into specific group.
" Here perlFunctionName (with quite an angry regexp "\h\w*[^:]") clashes with
" the rest syntax rules as now it has effect being really 'contained'.
" Clear it!
if ft =~? 'perl'
- syntax clear perlFunctionName
+ syntax clear perlFunctionName
endif
-endfunction "}}}
+endfunction
+
" creates or updates auto-generated listings in a wiki file, like TOC, diary
" links, tags list etc.
@@ -1114,7 +997,7 @@ endfunction "}}}
" - if a:create is true, it will be created if it doesn't exist, otherwise it
" will only be updated if it already exists
function! vimwiki#base#update_listing_in_buffer(strings, start_header,
- \ content_regex, default_lnum, create) "{{{
+ \ content_regex, default_lnum, create)
" apparently, Vim behaves strange when files change while in diff mode
if &diff || &readonly
return
@@ -1123,9 +1006,8 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
" check if the listing is already there
let already_there = 0
- let header_rx = '\m^\s*'.
- \ substitute(g:vimwiki_rxH1_Template, '__Header__', a:start_header, '')
- \ .'\s*$'
+ let header_rx = '\m^\s*'.substitute(vimwiki#vars#get_syntaxlocal('rxH1_Template'),
+ \ '__Header__', a:start_header, '') .'\s*$'
let start_lnum = 1
while start_lnum <= line('$')
@@ -1176,8 +1058,8 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
" write new listing
let new_header = whitespaces_in_first_line
- \ . substitute(g:vimwiki_rxH1_Template,
- \ '__Header__', '\='."'".a:start_header."'", '')
+ \ . s:safesubstitute(vimwiki#vars#get_syntaxlocal('rxH1_Template'),
+ \ '__Header__', a:start_header, '')
call append(start_lnum - 1, new_header)
let start_lnum += 1
let lines_diff += 1 + len(a:strings)
@@ -1201,41 +1083,43 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
let winview_save.lnum += lines_diff
endif
call winrestview(winview_save)
-endfunction "}}}
+endfunction
-" WIKI link following functions {{{
-" vimwiki#base#find_next_link
-function! vimwiki#base#find_next_link() "{{{
- call vimwiki#base#search_word(g:vimwiki_rxAnyLink, '')
-endfunction " }}}
-" vimwiki#base#find_prev_link
-function! vimwiki#base#find_prev_link() "{{{
+function! vimwiki#base#find_next_link()
+ call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), '')
+endfunction
+
+
+function! vimwiki#base#find_prev_link()
"Jump 2 times if the cursor is in the middle of a link
if synIDattr(synID(line('.'), col('.'), 0), "name") =~# "VimwikiLink.*" &&
\ synIDattr(synID(line('.'), col('.')-1, 0), "name") =~# "VimwikiLink.*"
- call vimwiki#base#search_word(g:vimwiki_rxAnyLink, 'b')
+ call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), 'b')
endif
- call vimwiki#base#search_word(g:vimwiki_rxAnyLink, 'b')
-endfunction " }}}
+ call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), 'b')
+endfunction
+
+
+function! vimwiki#base#follow_link(split, ...)
+ let reuse_other_split_window = a:0 >= 1 ? a:1 : 0
+ let move_cursor_to_new_window = a:0 >= 2 ? a:2 : 1
-" vimwiki#base#follow_link
-function! vimwiki#base#follow_link(split, reuse, move_cursor, ...) "{{{
" Parse link at cursor and pass to VimwikiLinkHandler, or failing that, the
" default open_link handler
" try WikiLink
- let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink),
- \ g:vimwiki_rxWikiLinkMatchUrl)
+ let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')),
+ \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
" try WikiIncl
if lnk == ""
- let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl),
- \ g:vimwiki_rxWikiInclMatchUrl)
+ let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl')),
+ \ vimwiki#vars#get_global('rxWikiInclMatchUrl'))
endif
" try Weblink
if lnk == ""
- let lnk = matchstr(vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink),
- \ g:vimwiki_rxWeblinkMatchUrl)
+ let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink')),
+ \ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
endif
if lnk != "" " cursor is indeed on a link
@@ -1256,7 +1140,7 @@ function! vimwiki#base#follow_link(split, reuse, move_cursor, ...) "{{{
" if we want to and can reuse a split window, jump to that window and open
" the new file there
- if (a:split ==# 'hsplit' || a:split ==# 'vsplit') && a:reuse
+ if (a:split ==# 'hsplit' || a:split ==# 'vsplit') && reuse_other_split_window
let previous_window_nr = winnr('#')
if previous_window_nr > 0 && previous_window_nr != winnr()
execute previous_window_nr . 'wincmd w'
@@ -1265,7 +1149,7 @@ function! vimwiki#base#follow_link(split, reuse, move_cursor, ...) "{{{
endif
- if VimwikiGet('syntax') == 'markdown'
+ if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
let processed_by_markdown_reflink = vimwiki#markdown_base#open_reflink(lnk)
if processed_by_markdown_reflink
return
@@ -1273,14 +1157,14 @@ function! vimwiki#base#follow_link(split, reuse, move_cursor, ...) "{{{
" remove the extension from the filename if exists, because non-vimwiki
" markdown files usually include the extension in links
- let lnk = substitute(lnk, VimwikiGet('ext').'$', '', '')
+ let lnk = substitute(lnk, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '')
endif
let current_tab_page = tabpagenr()
call vimwiki#base#open_link(cmd, lnk)
- if !a:move_cursor
+ if !move_cursor_to_new_window
if (a:split ==# 'hsplit' || a:split ==# 'vsplit')
execute 'wincmd p'
elseif a:split ==# 'tab'
@@ -1289,36 +1173,36 @@ function! vimwiki#base#follow_link(split, reuse, move_cursor, ...) "{{{
endif
else
- if a:0 > 0
- execute "normal! ".a:1
- else
+ if a:0 >= 3
+ execute "normal! ".a:3
+ else
call vimwiki#base#normalize_link(0)
endif
endif
-endfunction " }}}
+endfunction
-" vimwiki#base#go_back_link
-function! vimwiki#base#go_back_link() "{{{
- if exists("b:vimwiki_prev_link")
+
+function! vimwiki#base#go_back_link()
+ let prev_link = vimwiki#vars#get_bufferlocal('prev_link')
+ if !empty(prev_link)
" go back to saved wiki link
- let prev_word = b:vimwiki_prev_link
- execute ":e ".substitute(prev_word[0], '\s', '\\\0', 'g')
- call setpos('.', prev_word[1])
+ call vimwiki#base#edit_file(':e ', prev_link[0], '')
+ call setpos('.', prev_link[1])
else
" maybe we came here by jumping to a tag -> pop from the tag stack
silent! pop!
endif
-endfunction " }}}
+endfunction
-" vimwiki#base#goto_index
-function! vimwiki#base#goto_index(wnum, ...) "{{{
- if a:wnum > len(g:vimwiki_list)
- echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
+
+function! vimwiki#base#goto_index(wnum, ...)
+ if a:wnum > vimwiki#vars#number_of_wikis()
+ echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in your Vimwiki settings!'
return
endif
" usually a:wnum is greater then 0 but with the following command it is == 0:
- " vim -n -c "exe 'VimwikiIndex' | echo g:vimwiki_current_idx"
+ " vim -n -c ":VimwikiIndex"
if a:wnum > 0
let idx = a:wnum - 1
else
@@ -1326,23 +1210,27 @@ function! vimwiki#base#goto_index(wnum, ...) "{{{
endif
if a:0
- let cmd = 'tabedit'
+ if a:1 == 1
+ let cmd = 'tabedit'
+ elseif a:1 == 2
+ let cmd = 'split'
+ elseif a:1 == 3
+ let cmd = 'vsplit'
+ endif
else
let cmd = 'edit'
endif
- call Validate_wiki_options(idx)
- call vimwiki#base#edit_file(cmd,
- \ VimwikiGet('path', idx).VimwikiGet('index', idx).
- \ VimwikiGet('ext', idx),
- \ '')
- call vimwiki#base#setup_buffer_state(idx)
-endfunction "}}}
+ let index_file = vimwiki#vars#get_wikilocal('path', idx).
+ \ vimwiki#vars#get_wikilocal('index', idx).
+ \ vimwiki#vars#get_wikilocal('ext', idx)
-" vimwiki#base#delete_link
-function! vimwiki#base#delete_link() "{{{
- "" file system funcs
- "" Delete wiki link you are in from filesystem
+ call vimwiki#base#edit_file(cmd, index_file, '')
+endfunction
+
+
+function! vimwiki#base#delete_link()
+ " Delete wiki file you are in from filesystem
let val = input('Delete "'.expand('%').'" [y]es/[N]o? ')
if val !~? '^y'
return
@@ -1362,12 +1250,12 @@ function! vimwiki#base#delete_link() "{{{
if expand('%:p') != ""
execute "e"
endif
-endfunction "}}}
+endfunction
+
-" vimwiki#base#rename_link
" Rename current file, update all links to it
-function! vimwiki#base#rename_link() "{{{
- let subdir = VimwikiGet('subdir')
+function! vimwiki#base#rename_link()
+ let subdir = vimwiki#vars#get_bufferlocal('subdir')
let old_fname = subdir.expand('%:t')
" there is no file (new one maybe)
@@ -1396,24 +1284,23 @@ function! vimwiki#base#rename_link() "{{{
return
endif
- let url = matchstr(new_link, g:vimwiki_rxWikiLinkMatchUrl)
+ let url = matchstr(new_link, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
if url != ''
let new_link = url
endif
-
+
let new_link = subdir.new_link
- let new_fname = VimwikiGet('path').new_link.VimwikiGet('ext')
+ let new_fname = vimwiki#vars#get_wikilocal('path') . new_link . vimwiki#vars#get_wikilocal('ext')
" do not rename if file with such name exists
let fname = glob(new_fname)
if fname != ''
- echomsg 'Vimwiki Error: Cannot rename to "'.new_fname.
- \ '". File with that name exist!'
+ echomsg 'Vimwiki Error: Cannot rename to "'.new_fname.'". File with that name exist!'
return
endif
" rename wiki link file
try
- echomsg 'Vimwiki: Renaming '.VimwikiGet('path').old_fname.' to '.new_fname
+ echomsg 'Vimwiki: Renaming '.vimwiki#vars#get_wikilocal('path').old_fname.' to '.new_fname
let res = rename(expand('%:p'), expand(new_fname))
if res != 0
throw "Cannot rename!"
@@ -1425,8 +1312,7 @@ function! vimwiki#base#rename_link() "{{{
let &buftype="nofile"
- let cur_buffer = [expand('%:p'),
- \getbufvar(expand('%:p'), "vimwiki_prev_link")]
+ let cur_buffer = [expand('%:p'), vimwiki#vars#get_bufferlocal('prev_link')]
let blist = s:get_wiki_buffers()
@@ -1456,73 +1342,79 @@ function! vimwiki#base#rename_link() "{{{
endif
endfor
- call s:open_wiki_buffer([new_fname,
- \ cur_buffer[1]])
+ call s:open_wiki_buffer([new_fname, cur_buffer[1]])
" execute 'bwipeout '.escape(cur_buffer[0], ' ')
echomsg 'Vimwiki: '.old_fname.' is renamed to '.new_fname
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()
let idx = input("Select Wiki (specify number): ")
if idx == ""
return
endif
call vimwiki#base#goto_index(idx)
-endfunction "}}}
-" }}}
+endfunction
-" TEXT OBJECTS functions {{{
-" vimwiki#base#TO_header
-function! vimwiki#base#TO_header(inner, visual) "{{{
- if !search('^\(=\+\).\+\1\s*$', 'bcW')
+function! vimwiki#base#TO_header(inner, including_subheaders, count)
+ let headers = s:collect_headers()
+ if empty(headers)
return
endif
-
- let sel_start = line("'<")
- let sel_end = line("'>")
- let block_start = line(".")
- let advance = 0
- let level = vimwiki#u#count_first_sym(getline('.'))
+ let current_line = line('.')
- let is_header_selected = sel_start == block_start
- \ && sel_start != sel_end
+ let current_header_index = s:current_header(headers, current_line)
- if a:visual && is_header_selected
- if level > 1
- let level -= 1
- call search('^\(=\{'.level.'\}\).\+\1\s*$', 'bcW')
- else
- let advance = 1
- endif
+ if current_header_index < 0
+ return
endif
- normal! V
-
- if a:visual && is_header_selected
- call cursor(sel_end + advance, 0)
- endif
-
- if search('^\(=\{1,'.level.'}\).\+\1\s*$', 'W')
- call cursor(line('.') - 1, 0)
+ " from which to which header
+ if !a:including_subheaders && a:count <= 1
+ let first_line = headers[current_header_index][0]
+ let last_line = current_header_index == len(headers)-1 ? line('$') :
+ \ headers[current_header_index + 1][0] - 1
else
- call cursor(line('$'), 0)
+ let first_header_index = current_header_index
+ for _ in range(a:count - 1)
+ let parent = s:get_another_header(headers, first_header_index, -1, '<')
+ if parent < 0
+ break
+ else
+ let first_header_index = parent
+ endif
+ endfor
+
+ let next_sibling_or_higher = s:get_another_header(headers, first_header_index, +1, '<=')
+
+ let first_line = headers[first_header_index][0]
+ let last_line =
+ \ next_sibling_or_higher >= 0 ? headers[next_sibling_or_higher][0] - 1 : line('$')
endif
- if a:inner && getline(line('.')) =~# '^\s*$'
- let lnum = prevnonblank(line('.') - 1)
- call cursor(lnum, 0)
+ if a:inner
+ let first_line += 1
+ let last_line = prevnonblank(last_line)
endif
-endfunction "}}}
-" vimwiki#base#TO_table_cell
-function! vimwiki#base#TO_table_cell(inner, visual) "{{{
+ if first_line > last_line
+ " this can happen e.g. when doing vih on a header with another header in the very next line
+ return
+ endif
+
+ call cursor(first_line, 1)
+ normal! V
+ call cursor(last_line, 1)
+endfunction
+
+
+function! vimwiki#base#TO_table_cell(inner, visual)
if col('.') == col('$')-1
return
endif
@@ -1566,7 +1458,7 @@ function! vimwiki#base#TO_table_cell(inner, visual) "{{{
" XXX: WORKAROUND.
" if blockwise selection is ended at | character then pressing j to extend
- " selection furhter fails. But if we shake the cursor left and right then
+ " selection further fails. But if we shake the cursor left and right then
" it works.
normal! hl
else
@@ -1584,10 +1476,10 @@ function! vimwiki#base#TO_table_cell(inner, visual) "{{{
normal! 2h
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('.'))
if empty(t_rows)
return
@@ -1699,23 +1591,21 @@ function! vimwiki#base#TO_table_col(inner, visual) "{{{
" expand selection to the bottom line of the table
call vimwiki#u#cursor(t_rows[-1][0], virtcol('.'))
endif
-endfunction "}}}
-" }}}
+endfunction
-" HEADER functions {{{
-" vimwiki#base#AddHeaderLevel
-function! vimwiki#base#AddHeaderLevel() "{{{
+
+function! vimwiki#base#AddHeaderLevel()
let lnum = line('.')
let line = getline(lnum)
- let rxHdr = g:vimwiki_rxH
+ let rxHdr = vimwiki#vars#get_syntaxlocal('rxH')
if line =~# '^\s*$'
return
endif
- if line =~# g:vimwiki_rxHeader
+ if line =~# vimwiki#vars#get_syntaxlocal('rxHeader')
let level = vimwiki#u#count_first_sym(line)
if level < 6
- if g:vimwiki_symH
+ if vimwiki#vars#get_syntaxlocal('symH')
let line = substitute(line, '\('.rxHdr.'\+\).\+\1', rxHdr.'&'.rxHdr, '')
else
let line = substitute(line, '\('.rxHdr.'\+\).\+', rxHdr.'&', '')
@@ -1723,31 +1613,31 @@ function! vimwiki#base#AddHeaderLevel() "{{{
call setline(lnum, line)
endif
else
- let line = substitute(line, '^\s*', '&'.rxHdr.' ', '')
- if g:vimwiki_symH
+ let line = substitute(line, '^\s*', '&'.rxHdr.' ', '')
+ if vimwiki#vars#get_syntaxlocal('symH')
let line = substitute(line, '\s*$', ' '.rxHdr.'&', '')
endif
call setline(lnum, line)
endif
-endfunction "}}}
+endfunction
-" vimwiki#base#RemoveHeaderLevel
-function! vimwiki#base#RemoveHeaderLevel() "{{{
+
+function! vimwiki#base#RemoveHeaderLevel()
let lnum = line('.')
let line = getline(lnum)
- let rxHdr = g:vimwiki_rxH
+ let rxHdr = vimwiki#vars#get_syntaxlocal('rxH')
if line =~# '^\s*$'
return
endif
- if line =~# g:vimwiki_rxHeader
+ if line =~# vimwiki#vars#get_syntaxlocal('rxHeader')
let level = vimwiki#u#count_first_sym(line)
let old = repeat(rxHdr, level)
let new = repeat(rxHdr, level - 1)
let chomp = line =~# rxHdr.'\s'
- if g:vimwiki_symH
+ if vimwiki#vars#get_syntaxlocal('symH')
let line = substitute(line, old, new, 'g')
else
let line = substitute(line, old, new, '')
@@ -1762,39 +1652,147 @@ function! vimwiki#base#RemoveHeaderLevel() "{{{
call setline(lnum, line)
endif
-endfunction " }}}
+endfunction
-" a:create == 1: creates or updates TOC in current file
-" a:create == 0: update if TOC exists
-function! vimwiki#base#table_of_contents(create)
- " collect new headers
+
+
+" Returns all the headers in the current buffer as a list of the form
+" [[line_number, header_level, header_text], [...], [...], ...]
+function! s:collect_headers()
let is_inside_pre_or_math = 0 " 1: inside pre, 2: inside math, 0: outside
let headers = []
- let headers_levels = [['', 0], ['', 0], ['', 0], ['', 0], ['', 0], ['', 0]]
for lnum in range(1, line('$'))
let line_content = getline(lnum)
- if (is_inside_pre_or_math == 1 && line_content =~# g:vimwiki_rxPreEnd) ||
- \ (is_inside_pre_or_math == 2 && line_content =~# g:vimwiki_rxMathEnd)
+ if (is_inside_pre_or_math == 1 && line_content =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')) ||
+ \ (is_inside_pre_or_math == 2 && line_content =~# vimwiki#vars#get_syntaxlocal('rxMathEnd'))
let is_inside_pre_or_math = 0
continue
endif
if is_inside_pre_or_math > 0
continue
endif
- if line_content =~# g:vimwiki_rxPreStart
+ if line_content =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
let is_inside_pre_or_math = 1
continue
endif
- if line_content =~# g:vimwiki_rxMathStart
+ if line_content =~# vimwiki#vars#get_syntaxlocal('rxMathStart')
let is_inside_pre_or_math = 2
continue
endif
- if line_content !~# g:vimwiki_rxHeader
+ if line_content !~# vimwiki#vars#get_syntaxlocal('rxHeader')
continue
endif
- let h_level = vimwiki#u#count_first_sym(line_content)
- let h_text = vimwiki#u#trim(matchstr(line_content, g:vimwiki_rxHeader))
- if h_text ==# g:vimwiki_toc_header " don't include the TOC's header itself
+ let header_level = vimwiki#u#count_first_sym(line_content)
+ let header_text =
+ \ vimwiki#u#trim(matchstr(line_content, vimwiki#vars#get_syntaxlocal('rxHeader')))
+ call add(headers, [lnum, header_level, header_text])
+ endfor
+
+ return headers
+endfunction
+
+
+function! s:current_header(headers, line_number)
+ if empty(a:headers)
+ return -1
+ endif
+
+ if a:line_number >= a:headers[-1][0]
+ return len(a:headers) - 1
+ endif
+
+ let current_header_index = -1
+ while a:headers[current_header_index+1][0] <= a:line_number
+ let current_header_index += 1
+ endwhile
+ return current_header_index
+endfunction
+
+
+function! s:get_another_header(headers, current_index, direction, operation)
+ if empty(a:headers) || a:current_index < 0
+ return -1
+ endif
+ let current_level = a:headers[a:current_index][1]
+ let index = a:current_index + a:direction
+
+ while 1
+ if index < 0 || index >= len(a:headers)
+ return -1
+ endif
+ if eval('a:headers[index][1] ' . a:operation . ' current_level')
+ return index
+ endif
+ let index += a:direction
+ endwhile
+endfunction
+
+
+function! vimwiki#base#goto_parent_header()
+ let headers = s:collect_headers()
+ let current_header_index = s:current_header(headers, line('.'))
+ let parent_header = s:get_another_header(headers, current_header_index, -1, '<')
+ if parent_header >= 0
+ call cursor(headers[parent_header][0], 1)
+ else
+ echo 'Vimwiki: no parent header found'
+ endif
+endfunction
+
+
+function! vimwiki#base#goto_next_header()
+ let headers = s:collect_headers()
+ let current_header_index = s:current_header(headers, line('.'))
+ if current_header_index >= 0 && current_header_index < len(headers) - 1
+ call cursor(headers[current_header_index + 1][0], 1)
+ elseif current_header_index < 0 && !empty(headers) " we're above the first header
+ call cursor(headers[0][0], 1)
+ else
+ echo 'Vimwiki: no next header found'
+ endif
+endfunction
+
+
+function! vimwiki#base#goto_prev_header()
+ let headers = s:collect_headers()
+ let current_header_index = s:current_header(headers, line('.'))
+ " if the cursor already was on a header, jump to the previous one
+ if current_header_index >= 1 && headers[current_header_index][0] == line('.')
+ let current_header_index -= 1
+ endif
+ if current_header_index >= 0
+ call cursor(headers[current_header_index][0], 1)
+ else
+ echo 'Vimwiki: no previous header found'
+ endif
+endfunction
+
+
+function! vimwiki#base#goto_sibling(direction)
+ let headers = s:collect_headers()
+ let current_header_index = s:current_header(headers, line('.'))
+ let next_potential_sibling =
+ \ s:get_another_header(headers, current_header_index, a:direction, '<=')
+ if next_potential_sibling >= 0 && headers[next_potential_sibling][1] ==
+ \ headers[current_header_index][1]
+ call cursor(headers[next_potential_sibling][0], 1)
+ else
+ echo 'Vimwiki: no sibling header found'
+ endif
+endfunction
+
+
+" a:create == 1: creates or updates TOC in current file
+" a:create == 0: update if TOC exists
+function! vimwiki#base#table_of_contents(create)
+ let headers = s:collect_headers()
+ let numbering = vimwiki#vars#get_global('html_header_numbering')
+ let headers_levels = [['', 0], ['', 0], ['', 0], ['', 0], ['', 0], ['', 0]]
+ let complete_header_infos = []
+ for header in headers
+ let h_text = header[2]
+ let h_level = header[1]
+ if h_text ==# vimwiki#vars#get_global('toc_header') " don't include the TOC's header itself
continue
endif
let headers_levels[h_level-1] = [h_text, headers_levels[h_level-1][1]+1]
@@ -1808,184 +1806,185 @@ function! vimwiki#base#table_of_contents(create)
endfor
let h_complete_id .= headers_levels[h_level-1][0]
- if g:vimwiki_html_header_numbering > 0
- \ && g:vimwiki_html_header_numbering <= h_level
- let h_number = join(map(copy(headers_levels[
- \ g:vimwiki_html_header_numbering-1 : h_level-1]), 'v:val[1]'), '.')
- let h_number .= g:vimwiki_html_header_numbering_sym
+ if numbering > 0 && numbering <= h_level
+ let h_number = join(map(copy(headers_levels[numbering-1 : h_level-1]), 'v:val[1]'), '.')
+ let h_number .= vimwiki#vars#get_global('html_header_numbering_sym')
let h_text = h_number.' '.h_text
endif
- call add(headers, [h_level, h_complete_id, h_text])
+ call add(complete_header_infos, [h_level, h_complete_id, h_text])
endfor
let lines = []
let startindent = repeat(' ', vimwiki#lst#get_list_margin())
let indentstring = repeat(' ', vimwiki#u#sw())
let bullet = vimwiki#lst#default_symbol().' '
- for [lvl, link, desc] in headers
+ for [lvl, link, desc] in complete_header_infos
let esc_link = substitute(link, "'", "''", 'g')
let esc_desc = substitute(desc, "'", "''", 'g')
- let link = substitute(g:vimwiki_WikiLinkTemplate2, '__LinkUrl__',
- \ '\='."'".'#'.esc_link."'", '')
- let link = substitute(link, '__LinkDescription__', '\='."'".esc_desc."'", '')
+ let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
+ if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
+ let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
+ endif
+ let link = s:safesubstitute(link_tpl, '__LinkUrl__',
+ \ '#'.esc_link, '')
+ let link = s:safesubstitute(link, '__LinkDescription__', esc_desc, '')
call add(lines, startindent.repeat(indentstring, lvl-1).bullet.link)
endfor
let links_rx = '\m^\s*'.vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
- call vimwiki#base#update_listing_in_buffer(lines, g:vimwiki_toc_header, links_rx,
- \ 1, a:create)
+ call vimwiki#base#update_listing_in_buffer(lines,
+ \ vimwiki#vars#get_global('toc_header'), links_rx, 1, a:create)
endfunction
-"}}}
-" LINK functions {{{
-" vimwiki#base#apply_template
+
" Construct a regular expression matching from template (with special
" characters properly escaped), by substituting rxUrl for __LinkUrl__, rxDesc
" for __LinkDescription__, and rxStyle for __LinkStyle__. The three
" arguments rxUrl, rxDesc, and rxStyle are copied verbatim, without any
" special character escapes or substitutions.
-function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle) "{{{
+function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle)
let lnk = a:template
if a:rxUrl != ""
- let lnk = substitute(lnk, '__LinkUrl__', '\='."'".a:rxUrl."'", 'g')
+ let lnk = s:safesubstitute(lnk, '__LinkUrl__', a:rxUrl, 'g')
endif
if a:rxDesc != ""
- let lnk = substitute(lnk, '__LinkDescription__', '\='."'".a:rxDesc."'", 'g')
+ let lnk = s:safesubstitute(lnk, '__LinkDescription__', a:rxDesc, 'g')
endif
if a:rxStyle != ""
- let lnk = substitute(lnk, '__LinkStyle__', '\='."'".a:rxStyle."'", 'g')
+ let lnk = s:safesubstitute(lnk, '__LinkStyle__', a:rxStyle, 'g')
endif
return lnk
-endfunction " }}}
+endfunction
-" s:clean_url
-function! s:clean_url(url) " {{{
- let url = split(a:url, '/\|=\|-\|&\|?\|\.')
+
+function! s:clean_url(url)
+ " remove protocol and tld
+ let url = substitute(a:url, '^\a\+://', '', '')
+ let url = substitute(url, '^\([^/]\+\).\a\{2,4}/', '\1/', '')
+ let url = split(url, '/\|=\|-\|&\|?\|\.')
let url = filter(url, 'v:val !=# ""')
- let url = filter(url, 'v:val !=# "www"')
- let url = filter(url, 'v:val !=# "com"')
- let url = filter(url, 'v:val !=# "org"')
- let url = filter(url, 'v:val !=# "net"')
- let url = filter(url, 'v:val !=# "edu"')
- let url = filter(url, 'v:val !=# "http\:"')
- let url = filter(url, 'v:val !=# "https\:"')
- let url = filter(url, 'v:val !=# "file\:"')
- let url = filter(url, 'v:val !=# "xml\:"')
+ if url[0] == "www"
+ let url = url[1:]
+ endif
+ if url[-1] =~ '^\(htm\|html\|php\)$'
+ let url = url[0:-2]
+ endif
+ " remove words consisting of only hexadecimal digits or non-word characters
+ let url = filter(url, 'v:val !~ "^\\A\\{4,}$"')
+ let url = filter(url, 'v:val !~ "^\\x\\{4,}$" || v:val !~ "\\d"')
return join(url, " ")
-endfunction " }}}
+endfunction
-" s:is_diary_file
-function! s:is_diary_file(filename) " {{{
+
+function! s:is_diary_file(filename)
let file_path = vimwiki#path#path_norm(a:filename)
- let rel_path = VimwikiGet('diary_rel_path')
- let diary_path = vimwiki#path#path_norm(VimwikiGet('path') . rel_path)
- return rel_path != ''
- \ && file_path =~# '^'.vimwiki#u#escape(diary_path)
-endfunction " }}}
+ let rel_path = vimwiki#vars#get_wikilocal('diary_rel_path')
+ let diary_path = vimwiki#path#path_norm(vimwiki#vars#get_wikilocal('path') . rel_path)
+ return rel_path != '' && file_path =~# '^'.vimwiki#u#escape(diary_path)
+endfunction
-" vimwiki#base#normalize_link_helper
-function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) " {{{
- let str = a:str
- let url = matchstr(str, a:rxUrl)
- let descr = matchstr(str, a:rxDesc)
- let template = a:template
+
+function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template)
+ let url = matchstr(a:str, a:rxUrl)
+ let descr = matchstr(a:str, a:rxDesc)
if descr == ""
let descr = s:clean_url(url)
endif
- let lnk = substitute(template, '__LinkDescription__', '\="'.descr.'"', '')
- let lnk = substitute(lnk, '__LinkUrl__', '\="'.url.'"', '')
+ let lnk = s:safesubstitute(a:template, '__LinkDescription__', descr, '')
+ let lnk = s:safesubstitute(lnk, '__LinkUrl__', url, '')
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 style = matchstr(a:str, a:rxStyle)
- let lnk = substitute(lnk, '__LinkStyle__', '\="'.style.'"', '')
+ let lnk = s:safesubstitute(lnk, '__LinkStyle__', style, '')
return lnk
-endfunction " }}}
+endfunction
-" s:normalize_link_in_diary
-function! s:normalize_link_in_diary(lnk) " {{{
- let link = a:lnk . VimwikiGet('ext')
- let link_wiki = VimwikiGet('path') . '/' . link
- let link_diary = VimwikiGet('path') . '/'
- \ . VimwikiGet('diary_rel_path') . '/' . link
+
+function! s:normalize_link_in_diary(lnk)
+ let link = a:lnk . vimwiki#vars#get_wikilocal('ext')
+ let link_wiki = vimwiki#vars#get_wikilocal('path') . '/' . link
+ let link_diary = vimwiki#vars#get_wikilocal('path') . '/'
+ \ . vimwiki#vars#get_wikilocal('diary_rel_path') . '/' . link
let link_exists_in_diary = filereadable(link_diary)
let link_exists_in_wiki = filereadable(link_wiki)
let link_is_date = a:lnk =~# '\d\d\d\d-\d\d-\d\d'
if ! link_exists_in_wiki || link_exists_in_diary || link_is_date
let str = a:lnk
- let rxUrl = g:vimwiki_rxWord
+ let rxUrl = vimwiki#vars#get_global('rxWord')
let rxDesc = ''
- let template = g:vimwiki_WikiLinkTemplate1
+ let template = vimwiki#vars#get_global('WikiLinkTemplate1')
else
- let depth = len(split(VimwikiGet('diary_rel_path'), '/'))
+ let depth = len(split(vimwiki#vars#get_wikilocal('diary_rel_path'), '/'))
let str = repeat('../', depth) . a:lnk . '|' . a:lnk
let rxUrl = '^.*\ze|'
let rxDesc = '|\zs.*$'
- let template = g:vimwiki_WikiLinkTemplate2
+ let template = vimwiki#vars#get_global('WikiLinkTemplate2')
endif
return vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template)
-endfunction " }}}
+endfunction
-" s:normalize_link_syntax_n
-function! s:normalize_link_syntax_n() " {{{
+
+function! s:normalize_link_syntax_n()
" try WikiLink
- let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiLink)
+ let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink'))
if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk,
- \ g:vimwiki_rxWikiLinkMatchUrl, g:vimwiki_rxWikiLinkMatchDescr,
- \ g:vimwiki_WikiLinkTemplate2)
- call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWikiLink, sub)
+ \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'),
+ \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
+ \ vimwiki#vars#get_global('WikiLinkTemplate2'))
+ call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink'), sub)
return
endif
-
+
" try WikiIncl
- let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWikiIncl)
+ let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl'))
if !empty(lnk)
" NO-OP !!
return
endif
" try Weblink
- let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWeblink)
+ let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'))
if !empty(lnk)
let sub = vimwiki#base#normalize_link_helper(lnk,
- \ lnk, '', g:vimwiki_WikiLinkTemplate2)
- call vimwiki#base#replacestr_at_cursor(g:vimwiki_rxWeblink, sub)
+ \ lnk, '', vimwiki#vars#get_global('WikiLinkTemplate2'))
+ call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'), sub)
return
endif
" try Word (any characters except separators)
" rxWord is less permissive than rxWikiLinkUrl which is used in
" normalize_link_syntax_v
- let lnk = vimwiki#base#matchstr_at_cursor(g:vimwiki_rxWord)
+ let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWord'))
if !empty(lnk)
if s:is_diary_file(expand("%:p"))
let sub = s:normalize_link_in_diary(lnk)
else
let sub = vimwiki#base#normalize_link_helper(lnk,
- \ g:vimwiki_rxWord, '',
- \ g:vimwiki_WikiLinkTemplate1)
+ \ vimwiki#vars#get_global('rxWord'), '',
+ \ vimwiki#vars#get_global('WikiLinkTemplate1'))
endif
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
return
endif
-endfunction " }}}
+endfunction
-" s:normalize_link_syntax_v
-function! s:normalize_link_syntax_v() " {{{
+
+function! s:normalize_link_syntax_v()
let sel_save = &selection
let &selection = "old"
- let rv = @"
- let rt = getregtype('"')
+ let default_register_save = @"
+ let registertype_save = getregtype('"')
try
" Save selected text to register "
@@ -1995,36 +1994,36 @@ function! s:normalize_link_syntax_v() " {{{
if s:is_diary_file(expand("%:p"))
let sub = s:normalize_link_in_diary(@")
else
- let sub = substitute(g:vimwiki_WikiLinkTemplate1,
- \ '__LinkUrl__', '\=' . "'" . @" . "'", '')
+ let sub = s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
+ \ '__LinkUrl__', @", '')
endif
" Put substitution in register " and change text
- call setreg('"', sub, 'v')
+ call setreg('"', substitute(sub, '\n', '', ''), visualmode())
normal! `>""pgvd
finally
- call setreg('"', rv, rt)
+ call setreg('"', default_register_save, registertype_save)
let &selection = sel_save
endtry
-endfunction " }}}
+endfunction
-" vimwiki#base#normalize_link
-function! vimwiki#base#normalize_link(is_visual_mode) "{{{
- if exists('*vimwiki#'.VimwikiGet('syntax').'_base#normalize_link')
+
+function! vimwiki#base#normalize_link(is_visual_mode)
+ if exists('*vimwiki#'.vimwiki#vars#get_wikilocal('syntax').'_base#normalize_link')
" Syntax-specific links
- call vimwiki#{VimwikiGet('syntax')}_base#normalize_link(a:is_visual_mode)
+ call vimwiki#{vimwiki#vars#get_wikilocal('syntax')}_base#normalize_link(a:is_visual_mode)
else
if !a:is_visual_mode
call s:normalize_link_syntax_n()
- elseif visualmode() ==# 'v' && line("'<") == line("'>")
- " action undefined for 'line-wise' or 'multi-line' visual mode selections
+ elseif line("'<") == line("'>")
+ " action undefined for multi-line visual mode selections
call s:normalize_link_syntax_v()
endif
endif
-endfunction "}}}
+endfunction
-" vimwiki#base#detect_nested_syntax
-function! vimwiki#base#detect_nested_syntax() "{{{
+
+function! vimwiki#base#detect_nested_syntax()
let last_word = '\v.*<(\w+)\s*$'
let lines = map(filter(getline(1, "$"), 'v:val =~ "\\%({{{\\|```\\)" && v:val =~ last_word'),
\ 'substitute(v:val, last_word, "\\=submatch(1)", "")')
@@ -2033,26 +2032,20 @@ function! vimwiki#base#detect_nested_syntax() "{{{
let dict[elem] = elem
endfor
return dict
-endfunction "}}}
+endfunction
-" }}}
-" Command completion functions {{{
-
-" vimwiki#base#complete_links_escaped
-function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort " {{{
+function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort
" We can safely ignore args if we use -custom=complete option, Vim engine
" will do the job of filtering.
return vimwiki#base#get_globlinks_escaped()
-endfunction " }}}
+endfunction
-"}}}
" -------------------------------------------------------------------------
" Load syntax-specific Wiki functionality
for s:syn in s:vimwiki_get_known_syntaxes()
execute 'runtime! autoload/vimwiki/'.s:syn.'_base.vim'
-endfor
+endfor
" -------------------------------------------------------------------------
-
diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim
index fcd176a..164211d 100644
--- a/autoload/vimwiki/diary.vim
+++ b/autoload/vimwiki/diary.vim
@@ -1,76 +1,80 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
+" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file
-" Desc: Handle diary notes
+" Description: Handle diary notes
" Home: https://github.com/vimwiki/vimwiki/
-" Load only once {{{
+
if exists("g:loaded_vimwiki_diary_auto") || &cp
finish
endif
let g:loaded_vimwiki_diary_auto = 1
-"}}}
+
let s:vimwiki_max_scan_for_caption = 5
-" Helpers {{{
-function! s:prefix_zero(num) "{{{
+
+function! s:prefix_zero(num)
if a:num < 10
return '0'.a:num
endif
return a:num
-endfunction "}}}
+endfunction
-function! s:get_date_link(fmt) "{{{
- return strftime(a:fmt)
-endfunction "}}}
-function! s:diary_path(...) "{{{
- let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
- return VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx)
-endfunction "}}}
+function! s:diary_path(...)
+ let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
+ return vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx)
+endfunction
-function! s:diary_index(...) "{{{
- let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
- return s:diary_path(idx).VimwikiGet('diary_index', idx).VimwikiGet('ext', idx)
-endfunction "}}}
-function! s:diary_date_link(...) "{{{
- let idx = a:0 == 0 ? g:vimwiki_current_idx : a:1
- return s:get_date_link(VimwikiGet('diary_link_fmt', idx))
-endfunction "}}}
+function! s:diary_index(...)
+ let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
+ return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).
+ \ vimwiki#vars#get_wikilocal('ext', idx)
+endfunction
-function! s:get_position_links(link) "{{{
+
+function! vimwiki#diary#diary_date_link(...)
+ if a:0
+ return strftime('%Y-%m-%d', a:1)
+ else
+ return strftime('%Y-%m-%d')
+ endif
+endfunction
+
+
+function! s:get_position_links(link)
let idx = -1
let links = []
if a:link =~# '^\d\{4}-\d\d-\d\d'
let links = map(s:get_diary_files(), 'fnamemodify(v:val, ":t:r")')
" include 'today' into links
- if index(links, s:diary_date_link()) == -1
- call add(links, s:diary_date_link())
+ if index(links, vimwiki#diary#diary_date_link()) == -1
+ call add(links, vimwiki#diary#diary_date_link())
endif
call sort(links)
let idx = index(links, a:link)
endif
return [idx, links]
-endfunction "}}}
+endfunction
-fun! s:get_month_name(month) "{{{
- return g:vimwiki_diary_months[str2nr(a:month)]
-endfun "}}}
-" Helpers }}}
+function! s:get_month_name(month)
+ return vimwiki#vars#get_global('diary_months')[str2nr(a:month)]
+endfunction
-" Diary index stuff {{{
-fun! s:read_captions(files) "{{{
+
+function! s:read_captions(files)
let result = {}
+ let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
for fl in a:files
" remove paths and extensions
- let fl_key = fnamemodify(fl, ':t:r')
+ let fl_key = substitute(fnamemodify(fl, ':t'), vimwiki#vars#get_wikilocal('ext').'$', '', '')
if filereadable(fl)
for line in readfile(fl, '', s:vimwiki_max_scan_for_caption)
- if line =~# g:vimwiki_rxHeader && !has_key(result, fl_key)
- let result[fl_key] = vimwiki#u#trim(matchstr(line, g:vimwiki_rxHeader))
+ if line =~# rx_header && !has_key(result, fl_key)
+ let result[fl_key] = vimwiki#u#trim(matchstr(line, rx_header))
endif
endfor
endif
@@ -81,11 +85,13 @@ fun! s:read_captions(files) "{{{
endfor
return result
-endfun "}}}
+endfunction
-fun! s:get_diary_files() "{{{
+
+function! s:get_diary_files()
let rx = '^\d\{4}-\d\d-\d\d'
- let s_files = glob(VimwikiGet('path').VimwikiGet('diary_rel_path').'*'.VimwikiGet('ext'))
+ let s_files = glob(vimwiki#vars#get_wikilocal('path').
+ \ vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext'))
let files = split(s_files, '\n')
call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"')
@@ -93,9 +99,10 @@ fun! s:get_diary_files() "{{{
call filter(files, 'v:val !~# ''.*\~$''')
return files
-endfun "}}}
+endfunction
-fun! s:group_links(links) "{{{
+
+function! s:group_links(links)
let result = {}
let p_year = 0
let p_month = 0
@@ -114,83 +121,104 @@ fun! s:group_links(links) "{{{
let p_month = month
endfor
return result
-endfun "}}}
+endfunction
-function! s:sort(lst) "{{{
- if VimwikiGet("diary_sort") ==? 'desc'
+
+function! s:sort(lst)
+ if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc'
return reverse(sort(a:lst))
else
return sort(a:lst)
endif
-endfunction "}}}
+endfunction
-function! s:format_diary() "{{{
+
+function! s:format_diary()
let result = []
-
let links_with_captions = s:read_captions(s:get_diary_files())
let g_files = s:group_links(links_with_captions)
for year in s:sort(keys(g_files))
call add(result, '')
- call add(result, substitute(g:vimwiki_rxH2_Template, '__Header__', year , ''))
+ call add(result,
+ \ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
for month in s:sort(keys(g_files[year]))
call add(result, '')
- call add(result, substitute(g:vimwiki_rxH3_Template, '__Header__', s:get_month_name(month), ''))
+ call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'),
+ \ '__Header__', s:get_month_name(month), ''))
for [fl, cap] in s:sort(items(g_files[year][month]))
- if empty(cap)
- let entry = substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', fl, '')
- let entry = substitute(entry, '__LinkDescription__', cap, '')
- call add(result, repeat(' ', &sw).'* '.entry)
- else
- let entry = substitute(g:vimwiki_WikiLinkTemplate2, '__LinkUrl__', fl, '')
- let entry = substitute(entry, '__LinkDescription__', cap, '')
- call add(result, repeat(' ', &sw).'* '.entry)
+ let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
+
+ if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
+ let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
+
+ if empty(cap) " When using markdown syntax, we should ensure we always have a link description.
+ let cap = fl
+ endif
+ elseif empty(cap)
+ let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
endif
+
+ let entry = substitute(link_tpl, '__LinkUrl__', fl, '')
+ let entry = substitute(entry, '__LinkDescription__', cap, '')
+ call add(result, repeat(' ', vimwiki#lst#get_list_margin()).'* '.entry)
endfor
endfor
endfor
return result
-endfunction "}}}
+endfunction
-" Diary index stuff }}}
-function! vimwiki#diary#make_note(wnum, ...) "{{{
- if a:wnum > len(g:vimwiki_list)
- echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
+" The given wiki number a:wnum is 1 for the first wiki, 2 for the second and so on. This is in
+" contrast to most other places, where counting starts with 0. When a:wnum is 0, the current wiki
+" is used.
+function! vimwiki#diary#make_note(wnum, ...)
+ if a:wnum == 0
+ let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
+ if wiki_nr < 0 " this happens when e.g. VimwikiMakeDiaryNote was called outside a wiki buffer
+ let wiki_nr = 0
+ endif
+ else
+ let wiki_nr = a:wnum - 1
+ endif
+
+ if wiki_nr >= vimwiki#vars#number_of_wikis()
+ echomsg 'Vimwiki Error: Wiki '.wiki_nr.' is not registered in g:vimwiki_list!'
return
endif
" TODO: refactor it. base#goto_index uses the same
- if a:wnum > 0
- let idx = a:wnum - 1
- else
- let idx = 0
- endif
- call vimwiki#path#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx))
+ call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr).
+ \ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr))
- if a:0 && a:1 == 1
- let cmd = 'tabedit'
- else
- let cmd = 'edit'
+ let cmd = 'edit'
+ if a:0
+ if a:1 == 1
+ let cmd = 'tabedit'
+ elseif a:1 == 2
+ let cmd = 'split'
+ elseif a:1 == 3
+ let cmd = 'vsplit'
+ endif
endif
if a:0>1
let link = 'diary:'.a:2
else
- let link = 'diary:'.s:diary_date_link(idx)
+ let link = 'diary:'.vimwiki#diary#diary_date_link()
endif
- call vimwiki#base#open_link(cmd, link, s:diary_index(idx))
- call vimwiki#base#setup_buffer_state(idx)
-endfunction "}}}
+ call vimwiki#base#open_link(cmd, link, s:diary_index(wiki_nr))
+endfunction
-function! vimwiki#diary#goto_diary_index(wnum) "{{{
- if a:wnum > len(g:vimwiki_list)
+
+function! vimwiki#diary#goto_diary_index(wnum)
+ if a:wnum > vimwiki#vars#number_of_wikis()
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
return
endif
@@ -203,10 +231,10 @@ function! vimwiki#diary#goto_diary_index(wnum) "{{{
endif
call vimwiki#base#edit_file('e', s:diary_index(idx), '')
- call vimwiki#base#setup_buffer_state(idx)
-endfunction "}}}
+endfunction
-function! vimwiki#diary#goto_next_day() "{{{
+
+function! vimwiki#diary#goto_next_day()
let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r'))
@@ -218,15 +246,16 @@ function! vimwiki#diary#goto_next_day() "{{{
let link = 'diary:'.links[idx+1]
else
" goto today
- let link = 'diary:'.s:diary_date_link()
+ let link = 'diary:'.vimwiki#diary#diary_date_link()
endif
if len(link)
call vimwiki#base#open_link(':e ', link)
endif
-endfunction "}}}
+endfunction
-function! vimwiki#diary#goto_prev_day() "{{{
+
+function! vimwiki#diary#goto_prev_day()
let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r'))
@@ -238,29 +267,30 @@ function! vimwiki#diary#goto_prev_day() "{{{
let link = 'diary:'.links[idx-1]
else
" goto today
- let link = 'diary:'.s:diary_date_link()
+ let link = 'diary:'.vimwiki#diary#diary_date_link()
endif
if len(link)
call vimwiki#base#open_link(':e ', link)
endif
-endfunction "}}}
+endfunction
-function! vimwiki#diary#generate_diary_section() "{{{
+
+function! vimwiki#diary#generate_diary_section()
let current_file = vimwiki#path#path_norm(expand("%:p"))
let diary_file = vimwiki#path#path_norm(s:diary_index())
if vimwiki#path#is_equal(current_file, diary_file)
- let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.g:vimwiki_rxHeader.'\)'
+ let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)'
call vimwiki#base#update_listing_in_buffer(s:format_diary(),
- \ VimwikiGet('diary_header'), content_rx, line('$')+1, 1)
+ \ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1)
else
echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!'
endif
-endfunction "}}}
+endfunction
-" Calendar.vim {{{
-" Callback function.
-function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
+
+" Callback function for Calendar.vim
+function! vimwiki#diary#calendar_action(day, month, year, week, dir)
let day = s:prefix_zero(a:day)
let month = s:prefix_zero(a:month)
@@ -278,18 +308,15 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
endif
endif
- " XXX: Well, +1 is for inconsistent index basing...
- call vimwiki#diary#make_note(g:vimwiki_current_idx+1, 0, link)
-endfunction "}}}
+ call vimwiki#diary#make_note(0, 0, link)
+endfunction
-" Sign function.
-function vimwiki#diary#calendar_sign(day, month, year) "{{{
+
+function vimwiki#diary#calendar_sign(day, month, year)
let day = s:prefix_zero(a:day)
let month = s:prefix_zero(a:month)
- let sfile = VimwikiGet('path').VimwikiGet('diary_rel_path').
- \ a:year.'-'.month.'-'.day.VimwikiGet('ext')
+ let sfile = vimwiki#vars#get_wikilocal('path').vimwiki#vars#get_wikilocal('diary_rel_path').
+ \ a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
return filereadable(expand(sfile))
-endfunction "}}}
-
-" Calendar.vim }}}
+endfunction
diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim
index 0d52271..bce5465 100644
--- a/autoload/vimwiki/html.vim
+++ b/autoload/vimwiki/html.vim
@@ -1,62 +1,57 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
+" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file
-" Desc: Export to HTML
+" Description: HTML export
" 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.
-"
-" vimwiki -- --> PDF
-" \ /
-" markdown -----> AST -----> HTML
-" / \
-" mediawiki -- --> Latex
-"
-" Load only once {{{
if exists("g:loaded_vimwiki_html_auto") || &cp
finish
endif
let g:loaded_vimwiki_html_auto = 1
-"}}}
-" UTILITY "{{{
-function! s:root_path(subdir) "{{{
+
+function! s:root_path(subdir)
return repeat('../', len(split(a:subdir, '[/\\]')))
-endfunction "}}}
+endfunction
-function! s:syntax_supported() " {{{
- return VimwikiGet('syntax') ==? "default"
-endfunction " }}}
-function! s:remove_blank_lines(lines) " {{{
+function! s:syntax_supported()
+ return vimwiki#vars#get_wikilocal('syntax') ==? "default"
+endfunction
+
+
+function! s:remove_blank_lines(lines)
while !empty(a:lines) && a:lines[-1] =~# '^\s*$'
call remove(a:lines, -1)
endwhile
-endfunction "}}}
+endfunction
-function! s:is_web_link(lnk) "{{{
+
+function! s:is_web_link(lnk)
if a:lnk =~# '^\%(https://\|http://\|www.\|ftp://\|file://\|mailto:\)'
return 1
endif
return 0
-endfunction "}}}
+endfunction
-function! s:is_img_link(lnk) "{{{
+
+function! s:is_img_link(lnk)
if tolower(a:lnk) =~# '\.\%(png\|jpg\|gif\|jpeg\)$'
return 1
endif
return 0
-endfunction "}}}
+endfunction
-function! s:has_abs_path(fname) "{{{
+
+function! s:has_abs_path(fname)
if a:fname =~# '\(^.:\)\|\(^/\)'
return 1
endif
return 0
-endfunction "}}}
+endfunction
-function! s:find_autoload_file(name) " {{{
+
+function! s:find_autoload_file(name)
for path in split(&runtimepath, ',')
let fname = path.'/autoload/vimwiki/'.a:name
if glob(fname) != ''
@@ -64,15 +59,17 @@ function! s:find_autoload_file(name) " {{{
endif
endfor
return ''
-endfunction " }}}
+endfunction
-function! s:default_CSS_full_name(path) " {{{
+
+function! s:default_CSS_full_name(path)
let path = expand(a:path)
- let css_full_name = path.VimwikiGet('css_name')
+ let css_full_name = path . vimwiki#vars#get_wikilocal('css_name')
return css_full_name
-endfunction "}}}
+endfunction
-function! s:create_default_CSS(path) " {{{
+
+function! s:create_default_CSS(path)
let css_full_name = s:default_CSS_full_name(a:path)
if glob(css_full_name) == ""
call vimwiki#path#mkdir(fnamemodify(css_full_name, ':p:h'))
@@ -84,26 +81,28 @@ function! s:create_default_CSS(path) " {{{
endif
endif
return 0
-endfunction "}}}
+endfunction
-function! s:template_full_name(name) "{{{
+
+function! s:template_full_name(name)
if a:name == ''
- let name = VimwikiGet('template_default')
+ let name = vimwiki#vars#get_wikilocal('template_default')
else
let name = a:name
endif
- let fname = expand(VimwikiGet('template_path').
- \ name.VimwikiGet('template_ext'))
+ let fname = expand(vimwiki#vars#get_wikilocal('template_path').
+ \ name . vimwiki#vars#get_wikilocal('template_ext'))
if filereadable(fname)
return fname
else
return ''
endif
-endfunction "}}}
+endfunction
-function! s:get_html_template(template) "{{{
+
+function! s:get_html_template(template)
" TODO: refactor it!!!
let lines=[]
@@ -113,8 +112,7 @@ function! s:get_html_template(template) "{{{
let lines = readfile(template_name)
return lines
catch /E484/
- echomsg 'Vimwiki: HTML template '.template_name.
- \ ' does not exist!'
+ echomsg 'Vimwiki: HTML template '.template_name. ' does not exist!'
endtry
endif
@@ -126,23 +124,22 @@ function! s:get_html_template(template) "{{{
let lines = readfile(default_tpl)
return lines
-endfunction "}}}
+endfunction
-function! s:safe_html_preformatted(line) "{{{
+
+function! s:safe_html_preformatted(line)
let line = substitute(a:line,'<','\<', 'g')
let line = substitute(line,'>','\>', 'g')
return line
-endfunction "}}}
+endfunction
-function! s:safe_html_anchor(string) "{{{
- let string = substitute(a:string, '"', '\"', 'g')
- let string = substitute(string, "'", '\'', 'g')
- let string = substitute(string, '/', '\/', 'g')
- let string = substitute(string, '\t', ' ', 'g') " doesn't work
- return string
-endfunction "}}}
-function! s:safe_html_line(line) "{{{
+function! s:escape_html_attribute(string)
+ return substitute(a:string, '"', '\"', 'g')
+endfunction
+
+
+function! s:safe_html_line(line)
" escape & < > when producing HTML text
" s:lt_pattern, s:gt_pattern depend on g:vimwiki_valid_html_tags
" and are set in vimwiki#html#Wiki2HTML()
@@ -151,20 +148,21 @@ function! s:safe_html_line(line) "{{{
let line = substitute(line,s:gt_pattern,'\>', 'g')
return line
-endfunction "}}}
+endfunction
-function! s:delete_html_files(path) "{{{
+
+function! s:delete_html_files(path)
let htmlfiles = split(glob(a:path.'**/*.html'), '\n')
for fname in htmlfiles
" ignore user html files, e.g. search.html,404.html
- if stridx(g:vimwiki_user_htmls, fnamemodify(fname, ":t")) >= 0
+ if stridx(vimwiki#vars#get_global('user_htmls'), fnamemodify(fname, ":t")) >= 0
continue
endif
" delete if there is no corresponding wiki file
- let subdir = vimwiki#base#subdir(VimwikiGet('path_html'), fname)
- let wikifile = VimwikiGet('path').subdir.
- \fnamemodify(fname, ":t:r").VimwikiGet('ext')
+ let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path_html'), fname)
+ let wikifile = vimwiki#vars#get_wikilocal('path').subdir.
+ \fnamemodify(fname, ":t:r").vimwiki#vars#get_wikilocal('ext')
if filereadable(wikifile)
continue
endif
@@ -175,13 +173,15 @@ function! s:delete_html_files(path) "{{{
echomsg 'Vimwiki Error: Cannot delete '.fname
endtry
endfor
-endfunction "}}}
+endfunction
-function! s:mid(value, cnt) "{{{
+
+function! s:mid(value, cnt)
return strpart(a:value, a:cnt, len(a:value) - 2 * a:cnt)
-endfunction "}}}
+endfunction
-function! s:subst_func(line, regexp, func, ...) " {{{
+
+function! s:subst_func(line, regexp, func, ...)
" Substitute text found by regexp with result of
" func(matched) function.
@@ -201,16 +201,17 @@ function! s:subst_func(line, regexp, func, ...) " {{{
let pos = matchend(a:line, a:regexp, pos)
endfor
return res_line
-endfunction " }}}
+endfunction
-function! s:save_vimwiki_buffer() "{{{
+
+function! s:save_vimwiki_buffer()
if &filetype ==? 'vimwiki' && filewritable(expand('%'))
silent update
endif
-endfunction "}}}
+endfunction
-" get date.
-function! s:process_date(placeholders, default_date) "{{{
+
+function! s:process_date(placeholders, default_date)
if !empty(a:placeholders)
for [placeholder, row, idx] in a:placeholders
let [type, param] = placeholder
@@ -220,10 +221,10 @@ function! s:process_date(placeholders, default_date) "{{{
endfor
endif
return a:default_date
-endfunction "}}}
+endfunction
-" get title.
-function! s:process_title(placeholders, default_title) "{{{
+
+function! s:process_title(placeholders, default_title)
if !empty(a:placeholders)
for [placeholder, row, idx] in a:placeholders
let [type, param] = placeholder
@@ -233,9 +234,10 @@ function! s:process_title(placeholders, default_title) "{{{
endfor
endif
return a:default_title
-endfunction "}}}
+endfunction
-function! s:is_html_uptodate(wikifile) "{{{
+
+function! s:is_html_uptodate(wikifile)
let tpl_time = -1
let tpl_file = s:template_full_name('')
@@ -244,16 +246,17 @@ function! s:is_html_uptodate(wikifile) "{{{
endif
let wikifile = fnamemodify(a:wikifile, ":p")
- let htmlfile = expand(VimwikiGet('path_html').VimwikiGet('subdir').
- \fnamemodify(wikifile, ":t:r").".html")
+ let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') .
+ \ vimwiki#vars#get_bufferlocal('subdir') . fnamemodify(wikifile, ":t:r").".html")
if getftime(wikifile) <= getftime(htmlfile) && tpl_time <= getftime(htmlfile)
return 1
endif
return 0
-endfunction "}}}
+endfunction
-function! s:html_insert_contents(html_lines, content) "{{{
+
+function! s:html_insert_contents(html_lines, content)
let lines = []
for line in a:html_lines
if line =~# '%content%'
@@ -273,22 +276,23 @@ function! s:html_insert_contents(html_lines, content) "{{{
endif
endfor
return lines
-endfunction "}}}
-"}}}
+endfunction
-" INLINE TAGS "{{{
-function! s:tag_eqin(value) "{{{
+
+function! s:tag_eqin(value)
" mathJAX wants \( \) for inline maths
return '\('.s:mid(a:value, 1).'\)'
-endfunction "}}}
+endfunction
-function! s:tag_em(value) "{{{
+
+function! s:tag_em(value)
return ''.s:mid(a:value, 1).''
-endfunction "}}}
+endfunction
-function! s:tag_strong(value, header_ids) "{{{
+
+function! s:tag_strong(value, header_ids)
let text = s:mid(a:value, 1)
- let id = s:safe_html_anchor(text)
+ let id = s:escape_html_attribute(text)
let complete_id = ''
for l in range(6)
if a:header_ids[l][0] != ''
@@ -299,11 +303,12 @@ function! s:tag_strong(value, header_ids) "{{{
let complete_id = complete_id[:-2]
endif
let complete_id .= '-'.id
- return ''.text.''
-endfunction "}}}
+endfunction
-function! s:tag_tags(value, header_ids) "{{{
+
+function! s:tag_tags(value, header_ids)
let complete_id = ''
for level in range(6)
if a:header_ids[level][0] != ''
@@ -313,88 +318,89 @@ function! s:tag_tags(value, header_ids) "{{{
if a:header_ids[5][0] == ''
let complete_id = complete_id[:-2]
endif
- let complete_id = s:safe_html_anchor(complete_id)
+ let complete_id = s:escape_html_attribute(complete_id)
let result = []
for tag in split(a:value, ':')
- let id = s:safe_html_anchor(tag)
+ let id = s:escape_html_attribute(tag)
call add(result, ''.tag.'')
endfor
return join(result)
-endfunction "}}}
+endfunction
-function! s:tag_todo(value) "{{{
+
+function! s:tag_todo(value)
return ''.a:value.''
-endfunction "}}}
+endfunction
-function! s:tag_strike(value) "{{{
+
+function! s:tag_strike(value)
return ''.s:mid(a:value, 2).''
-endfunction "}}}
+endfunction
-function! s:tag_super(value) "{{{
+
+function! s:tag_super(value)
return ''.s:mid(a:value, 1).''
-endfunction "}}}
+endfunction
-function! s:tag_sub(value) "{{{
+
+function! s:tag_sub(value)
return ''.s:mid(a:value, 2).''
-endfunction "}}}
+endfunction
-function! s:tag_code(value) "{{{
+
+function! s:tag_code(value)
return ''.s:safe_html_preformatted(s:mid(a:value, 1)).''
-endfunction "}}}
-
-"function! s:tag_pre(value) "{{{
-" return ''.s:mid(a:value, 3).''
-"endfunction "}}}
-
-"FIXME dead code?
-"function! s:tag_math(value) "{{{
-" return '\['.s:mid(a:value, 3).'\]'
-"endfunction "}}}
+endfunction
-"{{{ v2.0 links
-" match n-th ARG within {{URL[|ARG1|ARG2|...]}} " {{{
+" match n-th ARG within {{URL[|ARG1|ARG2|...]}}
" *c,d,e),...
-function! vimwiki#html#incl_match_arg(nn_index)
- let rx = g:vimwiki_rxWikiInclPrefix. g:vimwiki_rxWikiInclUrl
- let rx = rx. repeat(g:vimwiki_rxWikiInclSeparator. g:vimwiki_rxWikiInclArg, a:nn_index-1)
+function! s:incl_match_arg(nn_index)
+ let rx = vimwiki#vars#get_global('rxWikiInclPrefix'). vimwiki#vars#get_global('rxWikiInclUrl')
+ let rx = rx . repeat(vimwiki#vars#get_global('rxWikiInclSeparator') .
+ \ vimwiki#vars#get_global('rxWikiInclArg'), a:nn_index-1)
if a:nn_index > 0
- let rx = rx. g:vimwiki_rxWikiInclSeparator. '\zs'. g:vimwiki_rxWikiInclArg. '\ze'
+ let rx = rx. vimwiki#vars#get_global('rxWikiInclSeparator'). '\zs' .
+ \ vimwiki#vars#get_global('rxWikiInclArg') . '\ze'
endif
- let rx = rx. g:vimwiki_rxWikiInclArgs. g:vimwiki_rxWikiInclSuffix
+ let rx = rx . vimwiki#vars#get_global('rxWikiInclArgs') .
+ \ vimwiki#vars#get_global('rxWikiInclSuffix')
return rx
endfunction
-"}}}
-function! vimwiki#html#linkify_link(src, descr) "{{{
- let src_str = ' href="'.s:safe_html_anchor(a:src).'"'
+
+function! s:linkify_link(src, descr)
+ let src_str = ' href="'.s:escape_html_attribute(a:src).'"'
let descr = substitute(a:descr,'^\s*\(.*\)\s*$','\1','')
let descr = (descr == "" ? a:src : descr)
- let descr_str = (descr =~# g:vimwiki_rxWikiIncl
- \ ? s:tag_wikiincl(descr)
+ let descr_str = (descr =~# vimwiki#vars#get_global('rxWikiIncl')
+ \ ? s:tag_wikiincl(descr)
\ : descr)
return ''.descr_str.''
-endfunction "}}}
+endfunction
-function! vimwiki#html#linkify_image(src, descr, verbatim_str) "{{{
+
+function! s:linkify_image(src, descr, verbatim_str)
let src_str = ' src="'.a:src.'"'
let descr_str = (a:descr != '' ? ' alt="'.a:descr.'"' : '')
let verbatim_str = (a:verbatim_str != '' ? ' '.a:verbatim_str : '')
return ''
-endfunction "}}}
+endfunction
-function! s:tag_weblink(value) "{{{
+
+function! s:tag_weblink(value)
" Weblink Template -> descr
let str = a:value
- let url = matchstr(str, g:vimwiki_rxWeblinkMatchUrl)
- let descr = matchstr(str, g:vimwiki_rxWeblinkMatchDescr)
- let line = vimwiki#html#linkify_link(url, descr)
+ let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
+ let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr'))
+ let line = s:linkify_link(url, descr)
return line
-endfunction "}}}
+endfunction
-function! s:tag_wikiincl(value) "{{{
+
+function! s:tag_wikiincl(value)
" {{imgurl|arg1|arg2}} -> ???
" {{imgurl}} ->
" {{imgurl|descr|style="A"}} ->
@@ -404,15 +410,14 @@ function! s:tag_wikiincl(value) "{{{
let line = VimwikiWikiIncludeHandler(str)
" otherwise, assume image transclusion
if line == ''
- let url_0 = matchstr(str, g:vimwiki_rxWikiInclMatchUrl)
- let descr = matchstr(str, vimwiki#html#incl_match_arg(1))
- let verbatim_str = matchstr(str, vimwiki#html#incl_match_arg(2))
+ let url_0 = matchstr(str, vimwiki#vars#get_global('rxWikiInclMatchUrl'))
+ let descr = matchstr(str, s:incl_match_arg(1))
+ let verbatim_str = matchstr(str, s:incl_match_arg(2))
let link_infos = vimwiki#base#resolve_link(url_0)
if link_infos.scheme =~# '\mlocal\|wiki\d\+\|diary'
- let url = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'),
- \ link_infos.filename)
+ let url = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'), link_infos.filename)
" strip the .html extension when we have wiki links, so that the user can
" simply write {{image.png}} to include an image from the wiki directory
if link_infos.scheme =~# '\mwiki\d\+\|diary'
@@ -423,12 +428,13 @@ function! s:tag_wikiincl(value) "{{{
endif
let url = escape(url, '#')
- let line = vimwiki#html#linkify_image(url, descr, verbatim_str)
+ let line = s:linkify_image(url, descr, verbatim_str)
endif
return line
-endfunction "}}}
+endfunction
-function! s:tag_wikilink(value) "{{{
+
+function! s:tag_wikilink(value)
" [[url]] -> url
" [[url|descr]] -> descr
" [[url|{{...}}]] -> ...
@@ -437,12 +443,11 @@ function! s:tag_wikilink(value) "{{{
" [[url#a1#a2]] -> url#a1#a2
" [[#a1#a2]] -> #a1#a2
let str = a:value
- let url = matchstr(str, g:vimwiki_rxWikiLinkMatchUrl)
- let descr = matchstr(str, g:vimwiki_rxWikiLinkMatchDescr)
+ let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
+ let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'))
let descr = (substitute(descr,'^\s*\(.*\)\s*$','\1','') != '' ? descr : url)
- let line = VimwikiLinkConverter(url, s:current_wiki_file,
- \ s:current_html_file)
+ let line = VimwikiLinkConverter(url, s:current_wiki_file, s:current_html_file)
if line == ''
let link_infos = vimwiki#base#resolve_link(url, s:current_wiki_file)
@@ -450,8 +455,8 @@ function! s:tag_wikilink(value) "{{{
" external file links are always absolute
let html_link = link_infos.filename
elseif link_infos.scheme ==# 'local'
- let html_link = vimwiki#path#relpath(fnamemodify(s:current_html_file,
- \ ':h'), link_infos.filename)
+ let html_link = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'),
+ \ link_infos.filename)
elseif link_infos.scheme =~# '\mwiki\d\+\|diary'
" wiki links are always relative to the current file
let html_link = vimwiki#path#relpath(
@@ -471,13 +476,12 @@ function! s:tag_wikilink(value) "{{{
let line = html_link
endif
- let line =vimwiki#html#linkify_link(line, descr)
+ let line = s:linkify_link(line, descr)
return line
-endfunction "}}}
-"}}}
+endfunction
-function! s:tag_remove_internal_link(value) "{{{
+function! s:tag_remove_internal_link(value)
let value = s:mid(a:value, 2)
let line = ''
@@ -498,9 +502,10 @@ function! s:tag_remove_internal_link(value) "{{{
let line = value
endif
return line
-endfunction "}}}
+endfunction
-function! s:tag_remove_external_link(value) "{{{
+
+function! s:tag_remove_external_link(value)
let value = s:mid(a:value, 1)
let line = ''
@@ -520,23 +525,25 @@ function! s:tag_remove_external_link(value) "{{{
let line = '['.value.']'
endif
return line
-endfunction "}}}
+endfunction
-function! s:make_tag(line, regexp, func, ...) "{{{
+
+function! s:make_tag(line, regexp, func, ...)
" Make tags for a given matched regexp.
" Exclude preformatted text and href links.
- " FIXME
+ " FIXME
let patt_splitter = '\(`[^`]\+`\)\|'.
- \ '\('.g:vimwiki_rxPreStart.'.\+'.g:vimwiki_rxPreEnd.'\)\|'.
+ \ '\('.vimwiki#vars#get_syntaxlocal('rxPreStart').'.\+'.
+ \ vimwiki#vars#get_syntaxlocal('rxPreEnd').'\)\|'.
\ '\(\)\|'.
\ '\(\)\|'.
\ '\(\)\|'.
- \ '\('.g:vimwiki_rxEqIn.'\)'
+ \ '\('.vimwiki#vars#get_syntaxlocal('rxEqIn').'\)'
"FIXME FIXME !!! these can easily occur on the same line!
"XXX {{{ }}} ??? obsolete
if '`[^`]\+`' ==# a:regexp || '{{{.\+}}}' ==# a:regexp ||
- \ g:vimwiki_rxEqIn ==# a:regexp
+ \ vimwiki#vars#get_syntaxlocal('rxEqIn') ==# a:regexp
let res_line = s:subst_func(a:line, a:regexp, a:func)
else
let pos = 0
@@ -559,92 +566,99 @@ function! s:make_tag(line, regexp, func, ...) "{{{
endfor
endif
return res_line
-endfunction "}}}
+endfunction
-function! s:process_tags_remove_links(line) " {{{
+
+function! s:process_tags_remove_links(line)
let line = a:line
let line = s:make_tag(line, '\[\[.\{-}\]\]', 's:tag_remove_internal_link')
let line = s:make_tag(line, '\[.\{-}\]', 's:tag_remove_external_link')
return line
-endfunction " }}}
+endfunction
-function! s:process_tags_typefaces(line, header_ids) "{{{
+
+function! s:process_tags_typefaces(line, header_ids)
let line = a:line
- let line = s:make_tag(line, g:vimwiki_rxItalic, 's:tag_em')
- let line = s:make_tag(line, g:vimwiki_rxBold, 's:tag_strong', a:header_ids)
- let line = s:make_tag(line, g:vimwiki_rxTodo, 's:tag_todo')
- let line = s:make_tag(line, g:vimwiki_rxDelText, 's:tag_strike')
- let line = s:make_tag(line, g:vimwiki_rxSuperScript, 's:tag_super')
- let line = s:make_tag(line, g:vimwiki_rxSubScript, 's:tag_sub')
- let line = s:make_tag(line, g:vimwiki_rxCode, 's:tag_code')
- let line = s:make_tag(line, g:vimwiki_rxEqIn, 's:tag_eqin')
- let line = s:make_tag(line, g:vimwiki_rxTags, 's:tag_tags', a:header_ids)
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxItalic'), 's:tag_em')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxBold'), 's:tag_strong', a:header_ids)
+ let line = s:make_tag(line, vimwiki#vars#get_global('rxTodo'), 's:tag_todo')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxDelText'), 's:tag_strike')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSuperScript'), 's:tag_super')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSubScript'), 's:tag_sub')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxCode'), 's:tag_code')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxEqIn'), 's:tag_eqin')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxTags'), 's:tag_tags', a:header_ids)
return line
-endfunction " }}}
+endfunction
-function! s:process_tags_links(line) " {{{
+
+function! s:process_tags_links(line)
let line = a:line
- let line = s:make_tag(line, g:vimwiki_rxWikiLink, 's:tag_wikilink')
- let line = s:make_tag(line, g:vimwiki_rxWikiIncl, 's:tag_wikiincl')
- let line = s:make_tag(line, g:vimwiki_rxWeblink, 's:tag_weblink')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWikiLink'), 's:tag_wikilink')
+ let line = s:make_tag(line, vimwiki#vars#get_global('rxWikiIncl'), 's:tag_wikiincl')
+ let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWeblink'), 's:tag_weblink')
return line
-endfunction " }}}
+endfunction
-function! s:process_inline_tags(line, header_ids) "{{{
+
+function! s:process_inline_tags(line, header_ids)
let line = s:process_tags_links(a:line)
let line = s:process_tags_typefaces(line, a:header_ids)
return line
-endfunction " }}}
-"}}}
+endfunction
-" BLOCK TAGS {{{
-function! s:close_tag_pre(pre, ldest) "{{{
+
+function! s:close_tag_pre(pre, ldest)
if a:pre[0]
call insert(a:ldest, "")
return 0
endif
return a:pre
-endfunction "}}}
+endfunction
-function! s:close_tag_math(math, ldest) "{{{
+
+function! s:close_tag_math(math, ldest)
if a:math[0]
call insert(a:ldest, "\\\]")
return 0
endif
return a:math
-endfunction "}}}
+endfunction
-function! s:close_tag_quote(quote, ldest) "{{{
+
+function! s:close_tag_quote(quote, ldest)
if a:quote
call insert(a:ldest, "")
return 0
endif
return a:quote
-endfunction "}}}
+endfunction
-function! s:close_tag_para(para, ldest) "{{{
+
+function! s:close_tag_para(para, ldest)
if a:para
call insert(a:ldest, "
")
return 0
endif
return a:para
-endfunction "}}}
+endfunction
-function! s:close_tag_table(table, ldest, header_ids) "{{{
+
+function! s:close_tag_table(table, ldest, header_ids)
" The first element of table list is a string which tells us if table should be centered.
" The rest elements are rows which are lists of columns:
- " ['center',
+ " ['center',
" [ CELL1, CELL2, CELL3 ],
" [ CELL1, CELL2, CELL3 ],
" [ CELL1, CELL2, CELL3 ],
" ]
" And CELLx is: { 'body': 'col_x', 'rowspan': r, 'colspan': c }
- function! s:sum_rowspan(table) "{{{
+ function! s:sum_rowspan(table)
let table = a:table
" Get max cells
- let max_cells = 0
+ let max_cells = 0
for row in table[1:]
let n_cells = len(row)
if n_cells > max_cells
@@ -670,9 +684,9 @@ function! s:close_tag_table(table, ldest, header_ids) "{{{
endif
endfor
endfor
- endfunction "}}}
+ endfunction
- function! s:sum_colspan(table) "{{{
+ function! s:sum_colspan(table)
for row in a:table[1:]
let cols = 1
@@ -685,19 +699,19 @@ function! s:close_tag_table(table, ldest, header_ids) "{{{
endif
endfor
endfor
- endfunction "}}}
+ endfunction
- function! s:close_tag_row(row, header, ldest, header_ids) "{{{
+ function! s:close_tag_row(row, header, ldest, header_ids)
call add(a:ldest, '
')
- " Set tag element of columns
+ " Set tag element of columns
if a:header
let tag_name = 'th'
else
let tag_name = 'td'
end
- " Close tag of columns
+ " Close tag of columns
for cell in a:row
if cell.rowspan == 0 || cell.colspan == 0
continue
@@ -720,7 +734,7 @@ function! s:close_tag_table(table, ldest, header_ids) "{{{
endfor
call add(a:ldest, '
')
- endfunction "}}}
+ endfunction
let table = a:table
let ldest = a:ldest
@@ -763,24 +777,27 @@ function! s:close_tag_table(table, ldest, header_ids) "{{{
let table = []
endif
return table
-endfunction "}}}
+endfunction
-function! s:close_tag_list(lists, ldest) "{{{
+
+function! s:close_tag_list(lists, ldest)
while len(a:lists)
let item = remove(a:lists, 0)
call insert(a:ldest, item[0])
endwhile
-endfunction "}}}
+endfunction
-function! s:close_tag_def_list(deflist, ldest) "{{{
+
+function! s:close_tag_def_list(deflist, ldest)
if a:deflist
call insert(a:ldest, "")
return 0
endif
return a:deflist
-endfunction "}}}
+endfunction
-function! s:process_tag_pre(line, pre) "{{{
+
+function! s:process_tag_pre(line, pre)
" pre is the list of [is_in_pre, indent_of_pre]
"XXX always outputs a single line or empty list!
let lines = []
@@ -810,9 +827,10 @@ function! s:process_tag_pre(line, pre) "{{{
call add(lines, s:safe_html_preformatted(a:line))
endif
return [processed, lines, pre]
-endfunction "}}}
+endfunction
-function! s:process_tag_math(line, math) "{{{
+
+function! s:process_tag_math(line, math)
" math is the list of [is_in_math, indent_of_math]
let lines = []
let math = a:math
@@ -846,9 +864,10 @@ function! s:process_tag_math(line, math) "{{{
call add(lines, substitute(a:line, '^\s\{'.math[1].'}', '', ''))
endif
return [processed, lines, math]
-endfunction "}}}
+endfunction
-function! s:process_tag_quote(line, quote) "{{{
+
+function! s:process_tag_quote(line, quote)
let lines = []
let quote = a:quote
let processed = 0
@@ -864,25 +883,29 @@ function! s:process_tag_quote(line, quote) "{{{
let quote = 0
endif
return [processed, lines, quote]
-endfunction "}}}
+endfunction
-function! s:process_tag_list(line, lists) "{{{
- function! s:add_checkbox(line, rx_list) "{{{
+function! s:process_tag_list(line, lists)
+
+ function! s:add_checkbox(line, rx_list)
let st_tag = '
'
let chk = matchlist(a:line, a:rx_list)
if !empty(chk) && len(chk[1]) > 0
- let completion = index(g:vimwiki_listsyms_list, chk[1])
- let n = len(g:vimwiki_listsyms_list)
+ let completion = index(vimwiki#vars#get_syntaxlocal('listsyms_list'), chk[1])
+ let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list'))
if completion == 0
let st_tag = '