Doc: Indent Docstring inside function

This commit is contained in:
Tinmarino
2021-01-03 20:07:18 -03:00
parent ffc4e41208
commit 29fa4b028b
15 changed files with 518 additions and 508 deletions
+90 -89
View File
@@ -15,15 +15,15 @@ let g:loaded_vimwiki_auto = 1
let g:vimwiki_max_scan_for_caption = 5 let g:vimwiki_max_scan_for_caption = 5
" Substitute regexp but do not interpret replace
function! s:safesubstitute(text, search, replace, mode) abort function! s:safesubstitute(text, search, replace, mode) abort
" Substitute regexp but do not interpret replace
let escaped = escape(a:replace, '\&') let escaped = escape(a:replace, '\&')
return substitute(a:text, a:search, escaped, a:mode) return substitute(a:text, a:search, escaped, a:mode)
endfunction endfunction
" Get all vimwiki known syntaxes
function! s:vimwiki_get_known_syntaxes() abort function! s:vimwiki_get_known_syntaxes() abort
" Get all vimwiki known syntaxes
" Getting all syntaxes that different wikis could have " Getting all syntaxes that different wikis could have
let syntaxes = {} let syntaxes = {}
let syntaxes['default'] = 1 let syntaxes['default'] = 1
@@ -39,8 +39,8 @@ function! s:vimwiki_get_known_syntaxes() abort
endfunction endfunction
" Get search regex from glob()
function! vimwiki#base#file_pattern(files) abort function! vimwiki#base#file_pattern(files) abort
" Get search regex from glob()
" string. Aim to support *all* special characters, forcing the user to choose " string. Aim to support *all* special characters, forcing the user to choose
" names that are compatible with any external restrictions that they " names that are compatible with any external restrictions that they
" encounter (e.g. filesystem, wiki conventions, other syntaxes, ...). " encounter (e.g. filesystem, wiki conventions, other syntaxes, ...).
@@ -50,9 +50,9 @@ function! vimwiki#base#file_pattern(files) abort
endfunction endfunction
function! vimwiki#base#subdir(path, filename) abort
" TODO move in path " TODO move in path
" FIXME TODO slow and faulty " FIXME TODO slow and faulty
function! vimwiki#base#subdir(path, filename) abort
let path = a:path let path = a:path
" ensure that we are not fooled by a symbolic link " ensure that we are not fooled by a symbolic link
"FIXME if we are not "fooled", we end up in a completely different wiki? "FIXME if we are not "fooled", we end up in a completely different wiki?
@@ -76,22 +76,22 @@ function! vimwiki#base#subdir(path, filename) abort
endfunction endfunction
" TODO move in path
function! vimwiki#base#current_subdir() abort function! vimwiki#base#current_subdir() abort
" TODO move in path
return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), expand('%:p')) return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), expand('%:p'))
endfunction endfunction
" TODO move in path
function! vimwiki#base#invsubdir(subdir) abort function! vimwiki#base#invsubdir(subdir) abort
" TODO move in path
return substitute(a:subdir, '[^/\.]\+/', '../', 'g') return substitute(a:subdir, '[^/\.]\+/', '../', 'g')
endfunction endfunction
function! vimwiki#base#find_wiki(path) abort
" Returns: the number of the wiki a file belongs to or -1 if it doesn't belong " Returns: the number of the wiki a file belongs to or -1 if it doesn't belong
" to any registered wiki. " to any registered wiki.
" The path can be the full path or just the directory of the file " The path can be the full path or just the directory of the file
function! vimwiki#base#find_wiki(path) abort
let bestmatch = -1 let bestmatch = -1
let bestlen = 0 let bestlen = 0
let path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(a:path)) let path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(a:path))
@@ -111,18 +111,18 @@ function! vimwiki#base#find_wiki(path) abort
endfunction endfunction
" Check if a link is a well formed wiki link (Helper)
function! s:is_wiki_link(link_infos) abort function! s:is_wiki_link(link_infos) abort
" Check if a link is a well formed wiki link (Helper)
return a:link_infos.scheme =~# '\mwiki\d\+' || a:link_infos.scheme ==# 'diary' return a:link_infos.scheme =~# '\mwiki\d\+' || a:link_infos.scheme ==# 'diary'
endfunction endfunction
function! vimwiki#base#resolve_link(link_text, ...) abort
" Extract infos about the target from a link. " Extract infos about the target from a link.
" THE central function of Vimwiki. " THE central function of Vimwiki.
" If the second parameter is present, which should be an absolute file path, it " 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 assumed that the link appears in that file. Without it, the current file
" is used. " is used.
function! vimwiki#base#resolve_link(link_text, ...) abort
if a:0 if a:0
let source_wiki = vimwiki#base#find_wiki(a:1) let source_wiki = vimwiki#base#find_wiki(a:1)
let source_file = a:1 let source_file = a:1
@@ -278,8 +278,8 @@ function! vimwiki#base#resolve_link(link_text, ...) abort
endfunction endfunction
" Open Link with OS handler (like gx)
function! vimwiki#base#system_open_link(url) abort function! vimwiki#base#system_open_link(url) abort
" Open Link with OS handler (like gx)
" handlers " handlers
function! s:win32_handler(url) abort function! s:win32_handler(url) abort
"Disable shellslash for cmd and command.com, but enable for all other shells "Disable shellslash for cmd and command.com, but enable for all other shells
@@ -332,8 +332,8 @@ function! vimwiki#base#system_open_link(url) abort
endfunction endfunction
" Open link with Vim (like :e)
function! vimwiki#base#open_link(cmd, link, ...) abort function! vimwiki#base#open_link(cmd, link, ...) abort
" Open link with Vim (like :e)
let link_infos = {} let link_infos = {}
if a:0 if a:0
let link_infos = vimwiki#base#resolve_link(a:link, a:1) let link_infos = vimwiki#base#resolve_link(a:link, a:1)
@@ -375,9 +375,9 @@ function! vimwiki#base#open_link(cmd, link, ...) abort
endfunction endfunction
function! vimwiki#base#get_globlinks_escaped(...) abort
" Escape global link " Escape global link
" Called by command completion " Called by command completion
function! vimwiki#base#get_globlinks_escaped(...) abort
let s_arg_lead = a:0 > 0 ? a:1 : '' let s_arg_lead = a:0 > 0 ? a:1 : ''
" only get links from the current dir " only get links from the current dir
" change to the directory of the current file " change to the directory of the current file
@@ -402,11 +402,11 @@ function! vimwiki#base#get_globlinks_escaped(...) abort
endfunction endfunction
" Generate wikilinks in current file function! vimwiki#base#generate_links(create, ...) abort
" Generate: wikilinks in current file
" Called: by command VimwikiGenerateLinks (Exported) " Called: by command VimwikiGenerateLinks (Exported)
" Param: create: <Bool> Create links or not " Param: create: <Bool> Create links or not
" Param: Optional pattern <String> " Param: Optional pattern <String>
function! vimwiki#base#generate_links(create, ...) abort
" Get pattern if present " Get pattern if present
" Globlal to script to be passed to closure " Globlal to script to be passed to closure
if a:0 if a:0
@@ -464,9 +464,9 @@ function! vimwiki#base#generate_links(create, ...) abort
endfunction endfunction
" Jump to other wikifile, specified on command mode
" Called: by command VimwikiGoto (Exported)
function! vimwiki#base#goto(...) abort function! vimwiki#base#goto(...) abort
" Jump: to other wikifile, specified on command mode
" Called: by command VimwikiGoto (Exported)
let key = a:0 > 0 ? a:1 : input('Enter name: ', '', let key = a:0 > 0 ? a:1 : input('Enter name: ', '',
\ 'customlist,vimwiki#base#complete_links_escaped') \ 'customlist,vimwiki#base#complete_links_escaped')
@@ -483,9 +483,9 @@ function! vimwiki#base#goto(...) abort
endfunction endfunction
" Jump to previous file (backspace key)
" Called: by VimwikiBacklinks (Exported)
function! vimwiki#base#backlinks() abort function! vimwiki#base#backlinks() abort
" Jump: to previous file (backspace key)
" Called: by VimwikiBacklinks (Exported)
let current_filename = expand('%:p') let current_filename = expand('%:p')
let locations = [] let locations = []
for idx in range(vimwiki#vars#number_of_wikis()) for idx in range(vimwiki#vars#number_of_wikis())
@@ -517,11 +517,11 @@ function! vimwiki#base#backlinks() abort
endfunction endfunction
function! vimwiki#base#find_files(wiki_nr, directories_only, ...) abort
" Returns: a list containing all files of the given wiki as absolute file path. " 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 " If the given wiki number is negative, the diary of the current wiki is used
" If the second argument is not zero, only directories are found " If the second argument is not zero, only directories are found
" If third argument: pattern to search for " If third argument: pattern to search for
function! vimwiki#base#find_files(wiki_nr, directories_only, ...) abort
let wiki_nr = a:wiki_nr let wiki_nr = a:wiki_nr
if wiki_nr >= 0 if wiki_nr >= 0
let root_directory = vimwiki#vars#get_wikilocal('path', wiki_nr) let root_directory = vimwiki#vars#get_wikilocal('path', wiki_nr)
@@ -558,12 +558,12 @@ function! vimwiki#base#find_files(wiki_nr, directories_only, ...) abort
endfunction endfunction
function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links, pattern) abort
" Returns: a list containing the links to get from the current file to all wiki " Returns: a list containing the links to get from the current file to all wiki
" files in the given wiki. " files in the given wiki.
" If the given wiki number is negative, the diary of the current wiki is used. " If 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 " If also_absolute_links is nonzero, also return links of the form /file
" If pattern is not '', only filepaths matching pattern will be considered " If pattern is not '', only filepaths matching pattern will be considered
function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links, pattern) abort
let files = vimwiki#base#find_files(a:wiki_nr, 0, a:pattern) let files = vimwiki#base#find_files(a:wiki_nr, 0, a:pattern)
if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr') if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
let cwd = vimwiki#path#wikify_path(expand('%:p:h')) let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
@@ -594,8 +594,8 @@ function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links, pattern) abor
endfunction endfunction
" Returns: a list containing the links to all directories from the current file
function! vimwiki#base#get_wiki_directories(wiki_nr) abort function! vimwiki#base#get_wiki_directories(wiki_nr) abort
" Returns: a list containing the links to all directories from the current file
let dirs = vimwiki#base#find_files(a:wiki_nr, 1) let dirs = vimwiki#base#find_files(a:wiki_nr, 1)
if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr') if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
let cwd = vimwiki#path#wikify_path(expand('%:p:h')) let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
@@ -616,9 +616,9 @@ function! vimwiki#base#get_wiki_directories(wiki_nr) abort
endfunction endfunction
function! vimwiki#base#get_anchors(filename, syntax) abort
" Parse file. Returns list of all anchors " Parse file. Returns list of all anchors
" Called: vimwiki#base#check_links() for all wiki files " Called: vimwiki#base#check_links() for all wiki files
function! vimwiki#base#get_anchors(filename, syntax) abort
" Clause: if not readable " Clause: if not readable
if !filereadable(a:filename) if !filereadable(a:filename)
return [] return []
@@ -697,12 +697,12 @@ function! vimwiki#base#get_anchors(filename, syntax) abort
endfunction endfunction
function! vimwiki#base#normalize_anchor(anchor, ...) abort
" Convert: anchor <string> => link in TOC
" Called: vimwiki#base#table_of_contents
" :param: anchor <string> <= Heading line " :param: anchor <string> <= Heading line
" :param: (1) previous_anchors <dic[IN/OUT]> of previous normalized anchor " :param: (1) previous_anchors <dic[IN/OUT]> of previous normalized anchor
" -- to know if must append -2, updated on the fly " -- to know if must append -2, updated on the fly
" Return: anchor <string> => link in TOC
" Called: vimwiki#base#table_of_contents
function! vimwiki#base#normalize_anchor(anchor, ...) abort
" A Trim space " A Trim space
let anchor = vimwiki#u#trim(a:anchor) let anchor = vimwiki#u#trim(a:anchor)
@@ -744,12 +744,12 @@ function! vimwiki#base#normalize_anchor(anchor, ...) abort
endfunction endfunction
function! vimwiki#base#unnormalize_anchor(anchor) abort
" Convert: s_anchor_toc [anchor_re <regex>, anchor_nb <number>, suffix_re <regex>] to look for
" Called: jump_to_anchor
" :param: anchor <string> <= link " :param: anchor <string> <= link
" Return: [anchor_re <regex>, anchor_nb <number>, suffix_re <regex>] to look for
" -- with or without suffix " -- with or without suffix
" -- Ex: ['toto", 2] => search for the second occurrence of toto " -- Ex: ['toto", 2] => search for the second occurrence of toto
" Called: jump_to_anchor
function! vimwiki#base#unnormalize_anchor(anchor) abort
" Note: " Note:
" -- Pandoc keep the '_' in anchor " -- Pandoc keep the '_' in anchor
" -- Done after: Add spaces leading and trailing => Later with the template " -- Done after: Add spaces leading and trailing => Later with the template
@@ -821,9 +821,9 @@ function! vimwiki#base#unnormalize_anchor(anchor) abort
endfunction endfunction
" Jump to anchor, doing the oposite of normalize_anchor
" Called: edit_file
function! s:jump_to_anchor(anchor) abort function! s:jump_to_anchor(anchor) abort
" Jump: to anchor, doing the oposite of normalize_anchor
" Called: edit_file
" Get segments <= anchor " Get segments <= anchor
let anchor = vimwiki#u#escape(a:anchor) let anchor = vimwiki#u#escape(a:anchor)
let segments = split(anchor, '#', 0) let segments = split(anchor, '#', 0)
@@ -844,8 +844,8 @@ function! s:jump_to_anchor(anchor) abort
endfunction endfunction
" Called: jump_to_anchor with suffix and withtou suffix
function! s:jump_to_segment(segment, segment_norm_re, segment_nb) abort function! s:jump_to_segment(segment, segment_norm_re, segment_nb) abort
" Called: jump_to_anchor with suffix and withtou suffix
" Save cursor %% Initialize at top of line " Save cursor %% Initialize at top of line
let oldpos = getpos('.') let oldpos = getpos('.')
call cursor(1, 1) call cursor(1, 1)
@@ -914,11 +914,11 @@ function! s:jump_to_segment(segment, segment_norm_re, segment_nb) abort
endfunction endfunction
" Returns: a list of all links inside the wiki file function! s:get_links(wikifile, idx) abort
" Get: a list of all links inside the wiki file
" Params: full path to a wiki file and its wiki number " Params: full path to a wiki file and its wiki number
" Every list item has the form " Every list item has the form
" [target file, anchor, line number of the link in source file, column number] " [target file, anchor, line number of the link in source file, column number]
function! s:get_links(wikifile, idx) abort
if !filereadable(a:wikifile) if !filereadable(a:wikifile)
return [] return []
endif endif
@@ -955,8 +955,8 @@ function! s:get_links(wikifile, idx) abort
endfunction endfunction
" Check if all wikilinks are reachable. Answer in quickfix
function! vimwiki#base#check_links(range, line1, line2) abort function! vimwiki#base#check_links(range, line1, line2) abort
" Check: if all wikilinks are reachable. Answer in quickfix
if a:range == 0 if a:range == 0
let wiki_list = [vimwiki#vars#get_bufferlocal('wiki_nr')] let wiki_list = [vimwiki#vars#get_bufferlocal('wiki_nr')]
elseif a:range == 1 elseif a:range == 1
@@ -1068,13 +1068,13 @@ function! vimwiki#base#check_links(range, line1, line2) abort
endfunction endfunction
" Open file (like :e) function! vimwiki#base#edit_file(command, filename, anchor, ...) abort
" Edit File: (like :e)
" :param: command <string>: ':e' " :param: command <string>: ':e'
" :param: filename <strign> vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext') " :param: filename <strign> vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext')
" :param: anchor " :param: anchor
" :param: (1) vimwiki_prev_link " :param: (1) vimwiki_prev_link
" :param: (2) vimwiki#u#ft_is_vw() " :param: (2) vimwiki#u#ft_is_vw()
function! vimwiki#base#edit_file(command, filename, anchor, ...) abort
let fname = escape(a:filename, '% *|#`') let fname = escape(a:filename, '% *|#`')
let dir = fnamemodify(a:filename, ':p:h') let dir = fnamemodify(a:filename, ':p:h')
@@ -1120,9 +1120,9 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) abort
endfunction endfunction
function! vimwiki#base#search_word(wikiRX, flags) abort
" Search for a 1. Pattern (usually a link) with 2. flags " Search for a 1. Pattern (usually a link) with 2. flags
" Called by find_prev_link " Called by find_prev_link
function! vimwiki#base#search_word(wikiRX, flags) abort
let match_line = search(a:wikiRX, 's'.a:flags) let match_line = search(a:wikiRX, 's'.a:flags)
if match_line == 0 if match_line == 0
call vimwiki#u#echo('Wiki link not found') call vimwiki#u#echo('Wiki link not found')
@@ -1130,8 +1130,8 @@ function! vimwiki#base#search_word(wikiRX, flags) abort
endfunction endfunction
" Return: part of the line that matches wikiRX at cursor
function! vimwiki#base#matchstr_at_cursor(wikiRX) abort function! vimwiki#base#matchstr_at_cursor(wikiRX) abort
" Return: part of the line that matches wikiRX at cursor
let col = col('.') - 1 let col = col('.') - 1
let line = getline('.') let line = getline('.')
let ebeg = -1 let ebeg = -1
@@ -1154,8 +1154,8 @@ function! vimwiki#base#matchstr_at_cursor(wikiRX) abort
endfunction endfunction
" Replace next 1. wikiRX by 2. sub
function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) abort function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) abort
" Replace next 1. wikiRX by 2. sub
" Gather: cursor info " Gather: cursor info
let col = col('.') - 1 let col = col('.') - 1
let line = getline('.') let line = getline('.')
@@ -1183,9 +1183,9 @@ function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) abort
endfunction endfunction
function! s:print_wiki_list() abort
" Print list of global wiki to user " Print list of global wiki to user
" Called: by ui_select " Called: by ui_select
function! s:print_wiki_list() abort
" Find the max name length for prettier formatting " Find the max name length for prettier formatting
let max_len = 0 let max_len = 0
for idx in range(vimwiki#vars#number_of_wikis()) for idx in range(vimwiki#vars#number_of_wikis())
@@ -1219,11 +1219,11 @@ function! s:print_wiki_list() abort
endfunction endfunction
function! s:update_wiki_link(fname, old, new) abort
" Update link in fname.ext " Update link in fname.ext
" Param: fname: the source file where to change links " Param: fname: the source file where to change links
" Param: old: url regex of old path relative to wiki root " Param: old: url regex of old path relative to wiki root
" Param: new: url string of new path " Param: new: url string of new path
function! s:update_wiki_link(fname, old, new) abort
call vimwiki#u#echo('Updating links in '.a:fname) call vimwiki#u#echo('Updating links in '.a:fname)
let has_updates = 0 let has_updates = 0
let dest = [] let dest = []
@@ -1243,11 +1243,11 @@ function! s:update_wiki_link(fname, old, new) abort
endfunction endfunction
function! s:update_wiki_links(wiki_nr, dir, old_url, new_url) abort
" Update link for all files in dir " Update link for all files in dir
" Param: old_url, new_url: path of the old, new url relative to ... " Param: old_url, new_url: path of the old, new url relative to ...
" Param: dir: directory of the files, relative to wiki_root " Param: dir: directory of the files, relative to wiki_root
" Called: rename_link " Called: rename_link
function! s:update_wiki_links(wiki_nr, dir, old_url, new_url) abort
" Get list of wiki files " Get list of wiki files
let wiki_root = vimwiki#vars#get_wikilocal('path', a:wiki_nr) let wiki_root = vimwiki#vars#get_wikilocal('path', a:wiki_nr)
let fsources = vimwiki#base#find_files(a:wiki_nr, 0) let fsources = vimwiki#base#find_files(a:wiki_nr, 0)
@@ -1312,9 +1312,9 @@ function! s:update_wiki_links(wiki_nr, dir, old_url, new_url) abort
endfunction endfunction
function! s:tail_name(fname) abort
" Get tail of filename " Get tail of filename
" TODO move me in path.vim " TODO move me in path.vim
function! s:tail_name(fname) abort
let result = substitute(a:fname, ':', '__colon__', 'g') let result = substitute(a:fname, ':', '__colon__', 'g')
let result = fnamemodify(result, ':t:r') let result = fnamemodify(result, ':t:r')
let result = substitute(result, '__colon__', ':', 'g') let result = substitute(result, '__colon__', ':', 'g')
@@ -1322,9 +1322,9 @@ function! s:tail_name(fname) abort
endfunction endfunction
function! s:get_wiki_buffers() abort
" Get list of currently open buffer that are wiki files " Get list of currently open buffer that are wiki files
" Called: by rename_link " Called: by rename_link
function! s:get_wiki_buffers() abort
let blist = [] let blist = []
let bcount = 1 let bcount = 1
while bcount<=bufnr('$') while bcount<=bufnr('$')
@@ -1343,9 +1343,9 @@ function! s:get_wiki_buffers() abort
endfunction endfunction
function! s:open_wiki_buffer(item) abort
" Edit wiki file. " Edit wiki file.
" Called: by rename_link: Usefull for buffer commands " Called: by rename_link: Usefull for buffer commands
function! s:open_wiki_buffer(item) abort
call vimwiki#base#edit_file(':e', a:item[0], '') call vimwiki#base#edit_file(':e', a:item[0], '')
if !empty(a:item[1]) if !empty(a:item[1])
call vimwiki#vars#set_bufferlocal('prev_links', a:item[1], a:item[0]) call vimwiki#vars#set_bufferlocal('prev_links', a:item[1], a:item[0])
@@ -1353,10 +1353,10 @@ function! s:open_wiki_buffer(item) abort
endfunction endfunction
function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort
" Helper nested syntax " Helper nested syntax
" Called: by syntax/vimwiki (exported) " Called: by syntax/vimwiki (exported)
" TODO move me out of base " TODO move me out of base
function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort
" From http://vim.wikia.com/wiki/VimTip857 " From http://vim.wikia.com/wiki/VimTip857
let ft=toupper(a:filetype) let ft=toupper(a:filetype)
let group='textGroup'.ft let group='textGroup'.ft
@@ -1420,7 +1420,9 @@ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort
endfunction endfunction
" Create or update auto-generated listings in a wiki file, like TOC, diary function! vimwiki#base#update_listing_in_buffer(Generator, start_header,
\ content_regex, default_lnum, header_level, create) abort
" Create: or update auto-generated listings in a wiki file, like TOC, diary
" links, tags list etc. " links, tags list etc.
" - the listing consists of a header and a list of strings provided by a funcref " - the listing consists of a header and a list of strings provided by a funcref
" - a:content_regex is used to determine how long a potentially existing list is " - a:content_regex is used to determine how long a potentially existing list is
@@ -1429,8 +1431,7 @@ endfunction
" - if a:create is true, it will be created if it doesn't exist, otherwise it " - if a:create is true, it will be created if it doesn't exist, otherwise it
" will only be updated if it already exists " will only be updated if it already exists
" Called: by functions adding listing to buffer (this is an util function) " Called: by functions adding listing to buffer (this is an util function)
function! vimwiki#base#update_listing_in_buffer(Generator, start_header,
\ content_regex, default_lnum, header_level, create) abort
" Clause: Vim behaves strangely when files change while in diff mode " Clause: Vim behaves strangely when files change while in diff mode
if &diff || &readonly if &diff || &readonly
return return
@@ -1545,22 +1546,22 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header,
endfunction endfunction
" Find next task (Exported)
function! vimwiki#base#find_next_task() abort function! vimwiki#base#find_next_task() abort
" Find next task (Exported)
let taskRegex = vimwiki#vars#get_wikilocal('rxListItemWithoutCB') let taskRegex = vimwiki#vars#get_wikilocal('rxListItemWithoutCB')
\ . '\+\(\[ \]\s\+\)\zs' \ . '\+\(\[ \]\s\+\)\zs'
call vimwiki#base#search_word(taskRegex, '') call vimwiki#base#search_word(taskRegex, '')
endfunction endfunction
" Find next link (Exported)
function! vimwiki#base#find_next_link() abort function! vimwiki#base#find_next_link() abort
" Find next link (Exported)
call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), '') call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), '')
endfunction endfunction
" Find previous link (Exported)
function! vimwiki#base#find_prev_link() abort function! vimwiki#base#find_prev_link() abort
" Find previous link (Exported)
"Jump 2 times if the cursor is in the middle of a link "Jump 2 times if the cursor is in the middle of a link
if synIDattr(synID(line('.'), col('.'), 0), 'name') =~# 'VimwikiLink.*' && if synIDattr(synID(line('.'), col('.'), 0), 'name') =~# 'VimwikiLink.*' &&
\ synIDattr(synID(line('.'), col('.')-1, 0), 'name') =~# 'VimwikiLink.*' \ synIDattr(synID(line('.'), col('.')-1, 0), 'name') =~# 'VimwikiLink.*'
@@ -1570,8 +1571,8 @@ function! vimwiki#base#find_prev_link() abort
endfunction endfunction
" Jump to link target (Enter press, Exported)
function! vimwiki#base#follow_link(split, ...) abort function! vimwiki#base#follow_link(split, ...) abort
" Jump to link target (Enter press, Exported)
let reuse_other_split_window = a:0 >= 1 ? a:1 : 0 let reuse_other_split_window = a:0 >= 1 ? a:1 : 0
let move_cursor_to_new_window = a:0 >= 2 ? a:2 : 1 let move_cursor_to_new_window = a:0 >= 2 ? a:2 : 1
@@ -1661,8 +1662,8 @@ function! vimwiki#base#follow_link(split, ...) abort
endfunction endfunction
" Jump to previous link (Backspace press, Exported)
function! vimwiki#base#go_back_link() abort function! vimwiki#base#go_back_link() abort
" Jump to previous link (Backspace press, Exported)
" Try pop previous link from buffer list " Try pop previous link from buffer list
let prev_links = vimwiki#vars#get_bufferlocal('prev_links') let prev_links = vimwiki#vars#get_bufferlocal('prev_links')
if !empty(prev_links) if !empty(prev_links)
@@ -1684,8 +1685,8 @@ function! vimwiki#base#go_back_link() abort
endfunction endfunction
" Goto index file of wiki specified by index
function! vimwiki#base#goto_index(wnum, ...) abort function! vimwiki#base#goto_index(wnum, ...) abort
" Goto index file of wiki specified by index
" if wnum = 0 the current wiki is used " if wnum = 0 the current wiki is used
if a:wnum == 0 if a:wnum == 0
let idx = vimwiki#vars#get_bufferlocal('wiki_nr') let idx = vimwiki#vars#get_bufferlocal('wiki_nr')
@@ -1721,8 +1722,8 @@ function! vimwiki#base#goto_index(wnum, ...) abort
endfunction endfunction
" Delete current wiki file
function! vimwiki#base#delete_link() abort function! vimwiki#base#delete_link() abort
" Delete current wiki file
" Delete wiki file you are in from filesystem " Delete wiki file you are in from filesystem
let val = input('Delete "'.expand('%').'" [y]es/[N]o? ') let val = input('Delete "'.expand('%').'" [y]es/[N]o? ')
if val !~? '^y' if val !~? '^y'
@@ -1746,10 +1747,10 @@ function! vimwiki#base#delete_link() abort
endfunction endfunction
function! s:input_rename_link() abort
" Ask user for a new filepath " Ask user for a new filepath
" Returns: '' if fails " Returns: '' if fails
" Called: rename_link " Called: rename_link
function! s:input_rename_link() abort
" Ask confirmation " Ask confirmation
let val = input('Rename "'.expand('%:t:r').'" [y]es/[N]o? ') let val = input('Rename "'.expand('%:t:r').'" [y]es/[N]o? ')
if val !~? '^y' if val !~? '^y'
@@ -1779,10 +1780,10 @@ function! s:input_rename_link() abort
endfunction endfunction
function! vimwiki#base#rename_link(...) abort
" Rename current file, update all links to it " Rename current file, update all links to it
" Param: [new_filepath <string>] " Param: [new_filepath <string>]
" Exported: VimwikiRenameFile " Exported: VimwikiRenameFile
function! vimwiki#base#rename_link(...) abort
" Get filename and dir relative to wiki root " Get filename and dir relative to wiki root
let subdir = vimwiki#vars#get_bufferlocal('subdir') let subdir = vimwiki#vars#get_bufferlocal('subdir')
" Get old file directory relative to current path " Get old file directory relative to current path
@@ -1902,9 +1903,9 @@ function! vimwiki#base#rename_link(...) abort
endfunction endfunction
function! vimwiki#base#ui_select() abort
" Spawn User Interface to select wiki project " Spawn User Interface to select wiki project
" Called by VimwikiUISelect (Globally Exported) " Called by VimwikiUISelect (Globally Exported)
function! vimwiki#base#ui_select() abort
call s:print_wiki_list() call s:print_wiki_list()
let idx = input('Select Wiki by number and press <Enter> (empty cancels): ') let idx = input('Select Wiki by number and press <Enter> (empty cancels): ')
if idx ==# '' if idx ==# ''
@@ -1918,8 +1919,8 @@ function! vimwiki#base#ui_select() abort
endfunction endfunction
" Jump to next header (Exported for text object)
function! vimwiki#base#TO_header(inner, including_subheaders, count) abort function! vimwiki#base#TO_header(inner, including_subheaders, count) abort
" Jump to next header (Exported for text object)
let headers = s:collect_headers() let headers = s:collect_headers()
if empty(headers) if empty(headers)
return return
@@ -1972,8 +1973,8 @@ function! vimwiki#base#TO_header(inner, including_subheaders, count) abort
endfunction endfunction
" Jump to next table cell (Exported for text object)
function! vimwiki#base#TO_table_cell(inner, visual) abort function! vimwiki#base#TO_table_cell(inner, visual) abort
" Jump to next table cell (Exported for text object)
if col('.') == col('$')-1 if col('.') == col('$')-1
return return
endif endif
@@ -2038,8 +2039,8 @@ function! vimwiki#base#TO_table_cell(inner, visual) abort
endfunction endfunction
" Jump to next table col (Exported for text object)
function! vimwiki#base#TO_table_col(inner, visual) abort function! vimwiki#base#TO_table_col(inner, visual) abort
" Jump to next table col (Exported for text object)
let t_rows = vimwiki#tbl#get_rows(line('.')) let t_rows = vimwiki#tbl#get_rows(line('.'))
if empty(t_rows) if empty(t_rows)
return return
@@ -2154,8 +2155,8 @@ function! vimwiki#base#TO_table_col(inner, visual) abort
endfunction endfunction
" Increase header level (Exported)
function! vimwiki#base#AddHeaderLevel(...) abort function! vimwiki#base#AddHeaderLevel(...) abort
" Increase header level (Exported)
" Clause, argument must be <= 1 " Clause, argument must be <= 1
" Actually argument is not used :-) " Actually argument is not used :-)
if a:1 > 1 if a:1 > 1
@@ -2188,8 +2189,8 @@ function! vimwiki#base#AddHeaderLevel(...) abort
endfunction endfunction
" Decrease header level (Exported)
function! vimwiki#base#RemoveHeaderLevel(...) abort function! vimwiki#base#RemoveHeaderLevel(...) abort
" Decrease header level (Exported)
" Clause, argument must be <= 1 " Clause, argument must be <= 1
" Actually argument is not used :-) " Actually argument is not used :-)
if a:1 > 1 if a:1 > 1
@@ -2227,9 +2228,9 @@ function! vimwiki#base#RemoveHeaderLevel(...) abort
endfunction endfunction
function! s:collect_headers() abort
" Returns: all the headers in the current buffer as a list of the form " Returns: all the headers in the current buffer as a list of the form
" [[line_number, header_level, header_text], [...], [...], ...] " [[line_number, header_level, header_text], [...], [...], ...]
function! s:collect_headers() abort
" Init loop variables " Init loop variables
let is_inside_pre_or_math = 0 " 1: inside pre, 2: inside math, 0: outside let is_inside_pre_or_math = 0 " 1: inside pre, 2: inside math, 0: outside
let headers = [] let headers = []
@@ -2286,9 +2287,9 @@ function! s:collect_headers() abort
endfunction endfunction
function! s:current_header(headers, line_number) abort
" Returns: header index at cursor position " Returns: header index at cursor position
" Called: by header cursor movements " Called: by header cursor movements
function! s:current_header(headers, line_number) abort
if empty(a:headers) if empty(a:headers)
return -1 return -1
endif endif
@@ -2305,9 +2306,9 @@ function! s:current_header(headers, line_number) abort
endfunction endfunction
function! s:clean_header_text(h_text) abort
" Returns: heading with link urls " Returns: heading with link urls
" Called: table_of_content " Called: table_of_content
function! s:clean_header_text(h_text) abort
" Note: I hardcode, who cares ? " Note: I hardcode, who cares ?
let h_text = a:h_text let h_text = a:h_text
@@ -2321,9 +2322,9 @@ function! s:clean_header_text(h_text) abort
endfunction endfunction
function! s:get_another_header(headers, current_index, direction, operation) abort
" Returns: index of neighbor header " Returns: index of neighbor header
" Called: by header cursor movements " Called: by header cursor movements
function! s:get_another_header(headers, current_index, direction, operation) abort
if empty(a:headers) || a:current_index < 0 if empty(a:headers) || a:current_index < 0
return -1 return -1
endif endif
@@ -2342,8 +2343,8 @@ function! s:get_another_header(headers, current_index, direction, operation) abo
endfunction endfunction
" Jump to parent header
function! vimwiki#base#goto_parent_header() abort function! vimwiki#base#goto_parent_header() abort
" Jump to parent header
let headers = s:collect_headers() let headers = s:collect_headers()
let current_header_index = s:current_header(headers, line('.')) let current_header_index = s:current_header(headers, line('.'))
let parent_header = s:get_another_header(headers, current_header_index, -1, '<') let parent_header = s:get_another_header(headers, current_header_index, -1, '<')
@@ -2355,8 +2356,8 @@ function! vimwiki#base#goto_parent_header() abort
endfunction endfunction
" Jump to next header
function! vimwiki#base#goto_next_header() abort function! vimwiki#base#goto_next_header() abort
" Jump to next header
let headers = s:collect_headers() let headers = s:collect_headers()
let current_header_index = s:current_header(headers, line('.')) let current_header_index = s:current_header(headers, line('.'))
if current_header_index >= 0 && current_header_index < len(headers) - 1 if current_header_index >= 0 && current_header_index < len(headers) - 1
@@ -2369,8 +2370,8 @@ function! vimwiki#base#goto_next_header() abort
endfunction endfunction
" Jump to previous header
function! vimwiki#base#goto_prev_header() abort function! vimwiki#base#goto_prev_header() abort
" Jump to previous header
let headers = s:collect_headers() let headers = s:collect_headers()
let current_header_index = s:current_header(headers, line('.')) let current_header_index = s:current_header(headers, line('.'))
" if the cursor already was on a header, jump to the previous one " if the cursor already was on a header, jump to the previous one
@@ -2385,8 +2386,8 @@ function! vimwiki#base#goto_prev_header() abort
endfunction endfunction
" Jump to sibling header, next or previous (with same level)
function! vimwiki#base#goto_sibling(direction) abort function! vimwiki#base#goto_sibling(direction) abort
" Jump to sibling header, next or previous (with same level)
let headers = s:collect_headers() let headers = s:collect_headers()
let current_header_index = s:current_header(headers, line('.')) let current_header_index = s:current_header(headers, line('.'))
let next_potential_sibling = let next_potential_sibling =
@@ -2400,10 +2401,10 @@ function! vimwiki#base#goto_sibling(direction) abort
endfunction endfunction
function! vimwiki#base#table_of_contents(create) abort
" Create buffer TOC (Exported) " Create buffer TOC (Exported)
" a:create == 1: creates or updates TOC in current file " a:create == 1: creates or updates TOC in current file
" a:create == 0: update if TOC exists " a:create == 0: update if TOC exists
function! vimwiki#base#table_of_contents(create) abort
" Gather heading " Gather heading
let headers = s:collect_headers() let headers = s:collect_headers()
let toc_header_text = vimwiki#vars#get_wikilocal('toc_header') let toc_header_text = vimwiki#vars#get_wikilocal('toc_header')
@@ -2508,13 +2509,13 @@ function! vimwiki#base#table_of_contents(create) abort
endfunction endfunction
function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle, rxExtension) abort
" Construct a regular expression matching from template (with special " Construct a regular expression matching from template (with special
" characters properly escaped), by substituting rxUrl for __LinkUrl__, rxDesc " characters properly escaped), by substituting rxUrl for __LinkUrl__, rxDesc
" for __LinkDescription__, rxStyle for __LinkStyle__ and rxExtension for " for __LinkDescription__, rxStyle for __LinkStyle__ and rxExtension for
" __FileExtension__. The four arguments rxUrl, rxDesc, rxStyle and " __FileExtension__. The four arguments rxUrl, rxDesc, rxStyle and
" rxExtension are copied verbatim, without any special character escapes or " rxExtension are copied verbatim, without any special character escapes or
" substitutions. " substitutions.
function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle, rxExtension) abort
let lnk = a:template let lnk = a:template
if a:rxUrl !=? '' if a:rxUrl !=? ''
let lnk = s:safesubstitute(lnk, '__LinkUrl__', a:rxUrl, 'g') let lnk = s:safesubstitute(lnk, '__LinkUrl__', a:rxUrl, 'g')
@@ -2532,8 +2533,8 @@ function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle, rxExtens
endfunction endfunction
" Helper: Clean url string
function! s:clean_url(url) abort function! s:clean_url(url) abort
" Helper: Clean url string
" don't use an extension as part of the description " don't use an extension as part of the description
let url = substitute(a:url, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '') let url = substitute(a:url, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '')
" remove protocol and tld " remove protocol and tld
@@ -2562,10 +2563,10 @@ function! s:clean_url(url) abort
endfunction endfunction
function! vimwiki#base#is_diary_file(filename, ...) abort
" Check if 1.filename is a diary file " Check if 1.filename is a diary file
" An optional second argument allows you to pass in a list of diary files rather " An optional second argument allows you to pass in a list of diary files rather
" than generating a list on each call to the function. " than generating a list on each call to the function.
function! vimwiki#base#is_diary_file(filename, ...) abort
let l:diary_file_paths = a:0 > 0 ? a:1 : vimwiki#diary#get_diary_files() let l:diary_file_paths = a:0 > 0 ? a:1 : vimwiki#diary#get_diary_files()
let l:normalised_file_paths = let l:normalised_file_paths =
\ map(l:diary_file_paths, 'vimwiki#path#normalize(v:val)') \ map(l:diary_file_paths, 'vimwiki#path#normalize(v:val)')
@@ -2577,9 +2578,9 @@ function! vimwiki#base#is_diary_file(filename, ...) abort
endfunction endfunction
function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort
" Treat link string towards normalization " Treat link string towards normalization
" [__LinkDescription__](__LinkUrl__.__FileExtension__) " [__LinkDescription__](__LinkUrl__.__FileExtension__)
function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort
let url = matchstr(a:str, a:rxUrl) let url = matchstr(a:str, a:rxUrl)
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' && vimwiki#vars#get_wikilocal('markdown_link_ext') if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' && vimwiki#vars#get_wikilocal('markdown_link_ext')
" Strip the extension if it exists so it doesn't get added multiple times " Strip the extension if it exists so it doesn't get added multiple times
@@ -2600,8 +2601,8 @@ function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort
endfunction endfunction
" Treat imagelink string towards normalization
function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, template) abort function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, template) abort
" Treat imagelink string towards normalization
let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template) let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template)
let style = matchstr(a:str, a:rxStyle) let style = matchstr(a:str, a:rxStyle)
let lnk = s:safesubstitute(lnk, '__LinkStyle__', style, '') let lnk = s:safesubstitute(lnk, '__LinkStyle__', style, '')
@@ -2609,9 +2610,9 @@ function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, t
endfunction endfunction
function! vimwiki#base#normalize_link_in_diary(lnk) abort
" Normalize link in a diary file " Normalize link in a diary file
" Refactor: in diary " Refactor: in diary
function! vimwiki#base#normalize_link_in_diary(lnk) abort
let sc = vimwiki#vars#get_wikilocal('links_space_char') let sc = vimwiki#vars#get_wikilocal('links_space_char')
let link = a:lnk . vimwiki#vars#get_wikilocal('ext') let link = a:lnk . vimwiki#vars#get_wikilocal('ext')
let link_wiki = substitute(vimwiki#vars#get_wikilocal('path') . '/' . link, '\s', sc, 'g') let link_wiki = substitute(vimwiki#vars#get_wikilocal('path') . '/' . link, '\s', sc, 'g')
@@ -2647,8 +2648,8 @@ function! vimwiki#base#normalize_link_in_diary(lnk) abort
endfunction endfunction
" Normalize link in normal mode Enter keypress
function! s:normalize_link_syntax_n() abort function! s:normalize_link_syntax_n() abort
" Normalize link in normal mode Enter keypress
" try WikiLink " try WikiLink
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')) let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink'))
if !empty(lnk) if !empty(lnk)
@@ -2696,9 +2697,9 @@ function! s:normalize_link_syntax_n() abort
endfunction endfunction
function! s:normalize_link_syntax_v() abort
" TODO mutualize most code with syntax_n " TODO mutualize most code with syntax_n
" Normalize link in visual mode Enter keypress " Normalize link in visual mode Enter keypress
function! s:normalize_link_syntax_v() abort
" Get selection content " Get selection content
let visual_selection = vimwiki#u#get_selection() let visual_selection = vimwiki#u#get_selection()
@@ -2728,8 +2729,8 @@ function! s:normalize_link_syntax_v() abort
endfunction endfunction
" Normalize link (Implemented as a switch function)
function! vimwiki#base#normalize_link(is_visual_mode) abort function! vimwiki#base#normalize_link(is_visual_mode) abort
" Normalize link (Implemented as a switch function)
" If visual mode " If visual mode
if a:is_visual_mode if a:is_visual_mode
return s:normalize_link_syntax_v() return s:normalize_link_syntax_v()
@@ -2745,9 +2746,9 @@ function! vimwiki#base#normalize_link(is_visual_mode) abort
endfunction endfunction
function! vimwiki#base#detect_nested_syntax() abort
" Get nested syntax are present " Get nested syntax are present
" Return: dictionary of syntaxes " Return: dictionary of syntaxes
function! vimwiki#base#detect_nested_syntax() abort
let last_word = '\v.*<(\w+)\s*$' let last_word = '\v.*<(\w+)\s*$'
let lines = map(filter(getline(1, '$'), 'v:val =~# "\\%({{{\\|`\\{3,\}\\|\\~\\{3,\}\\)" && v:val =~# last_word'), let lines = map(filter(getline(1, '$'), 'v:val =~# "\\%({{{\\|`\\{3,\}\\|\\~\\{3,\}\\)" && v:val =~# last_word'),
\ 'substitute(v:val, last_word, "\\=submatch(1)", "")') \ 'substitute(v:val, last_word, "\\=submatch(1)", "")')
@@ -2759,15 +2760,15 @@ function! vimwiki#base#detect_nested_syntax() abort
endfunction endfunction
" Complete escaping globlinks
function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort
" Complete escaping globlinks
return vimwiki#base#get_globlinks_escaped(a:ArgLead) return vimwiki#base#get_globlinks_escaped(a:ArgLead)
endfunction endfunction
function! vimwiki#base#complete_file(ArgLead, CmdLine, CursorPos) abort
" Complete filename relatie to current file " Complete filename relatie to current file
" Called: rename_link " Called: rename_link
function! vimwiki#base#complete_file(ArgLead, CmdLine, CursorPos) abort
" Start from current file " Start from current file
let base_path = expand('%:h') let base_path = expand('%:h')
@@ -2782,9 +2783,9 @@ function! vimwiki#base#complete_file(ArgLead, CmdLine, CursorPos) abort
endfunction endfunction
function! vimwiki#base#read_caption(file) abort
" Read caption " Read caption
" Called: by generate_links " Called: by generate_links
function! vimwiki#base#read_caption(file) abort
let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader') let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
if filereadable(a:file) if filereadable(a:file)
@@ -2799,9 +2800,9 @@ function! vimwiki#base#read_caption(file) abort
endfunction endfunction
function! vimwiki#base#search(search_pattern) abort
" Search for 1.pattern " Search for 1.pattern
" Called by commands VimwikiSearch and VWS " Called by commands VimwikiSearch and VWS
function! vimwiki#base#search(search_pattern) abort
if empty(a:search_pattern) if empty(a:search_pattern)
call vimwiki#u#error('No search pattern given.') call vimwiki#u#error('No search pattern given.')
return return
@@ -2828,8 +2829,8 @@ function! vimwiki#base#search(search_pattern) abort
endtry endtry
endfunction endfunction
" used by function linkify to extract web page <title>
function! s:get_title(match) abort function! s:get_title(match) abort
" used by function linkify to extract web page <title>
" Do not overwrite if g:page_title is already set " Do not overwrite if g:page_title is already set
" when there are multiple <title> tags, only use the first one " when there are multiple <title> tags, only use the first one
" this is a side effect of the substitute's 'n' flag (count number of " this is a side effect of the substitute's 'n' flag (count number of
@@ -2853,8 +2854,8 @@ function! s:get_title(match) abort
let g:page_title = l:title let g:page_title = l:title
endfunction endfunction
" transform the url under the cursor to a wiki link
function! vimwiki#base#linkify() abort function! vimwiki#base#linkify() abort
" Transform: the url under the cursor to a wiki link
let g:page_title = '' let g:page_title = ''
" save existing value of @u and delete url under the cursor into @u " save existing value of @u and delete url under the cursor into @u
+8 -9
View File
@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# #
# This script converts markdown into html, to be used with vimwiki's # This script converts markdown into html, to be used with vimwiki's
@@ -26,10 +26,10 @@
# internal wiki2html converter. # internal wiki2html converter.
# #
MARKDOWN=markdown
MKD2HTML=mkd2html MKD2HTML=mkd2html
# shellcheck disable=SC2034 # FORCE appears unused
FORCE="$1" FORCE="$1"
SYNTAX="$2" SYNTAX="$2"
EXTENSION="$3" EXTENSION="$3"
@@ -37,14 +37,16 @@ OUTPUTDIR="$4"
INPUT="$5" INPUT="$5"
CSSFILE="$6" CSSFILE="$6"
FORCEFLAG=
[ $FORCE -eq 0 ] || { FORCEFLAG="-f"; }; [[ "$SYNTAX" == "markdown" ]] || { echo "Error: Unsupported syntax"; exit 2; };
[ $SYNTAX = "markdown" ] || { echo "Error: Unsupported syntax"; exit -2; };
OUTPUT="$OUTPUTDIR"/$(basename "$INPUT" .$EXTENSION).html OUTPUT="$OUTPUTDIR/$(basename "$INPUT" . "$EXTENSION").html"
# # Method 1: # # Method 1:
# FORCEFLAG=
# (( "$FORCE" == 0 )) || { FORCEFLAG="-f"; };
# MARKDOWN=markdown
#
# # markdown [-d] [-T] [-V] [-b url-base] [-C prefix] [-F bitmap] [-f flags] [-o file] [-s text] [-t text] [textfile] # # markdown [-d] [-T] [-V] [-b url-base] [-C prefix] [-F bitmap] [-f flags] [-o file] [-s text] [-t text] [textfile]
# #
# URLBASE=http://example.com # URLBASE=http://example.com
@@ -57,6 +59,3 @@ OUTPUT="$OUTPUTDIR"/$(basename "$INPUT" .$EXTENSION).html
$MKD2HTML -css "$CSSFILE" "$INPUT" $MKD2HTML -css "$CSSFILE" "$INPUT"
OUTPUTTMP=$(dirname "$INPUT")/$(basename "$INPUT" ."$EXTENSION").html OUTPUTTMP=$(dirname "$INPUT")/$(basename "$INPUT" ."$EXTENSION").html
mv -f "$OUTPUTTMP" "$OUTPUT" mv -f "$OUTPUTTMP" "$OUTPUT"
+21 -21
View File
@@ -11,8 +11,8 @@ endif
let g:loaded_vimwiki_diary_auto = 1 let g:loaded_vimwiki_diary_auto = 1
" Add zero prefix to a number
function! s:prefix_zero(num) abort function! s:prefix_zero(num) abort
" Add zero prefix to a number
if a:num < 10 if a:num < 10
return '0'.a:num return '0'.a:num
endif endif
@@ -20,23 +20,23 @@ function! s:prefix_zero(num) abort
endfunction endfunction
" Return: diary directory path <String>
function! s:diary_path(...) abort function! s:diary_path(...) abort
" Return: diary directory path <String>
let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1 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) return vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx)
endfunction endfunction
" Return: diary index file path <String>
function! s:diary_index(...) abort function! s:diary_index(...) abort
" Return: diary index file path <String>
let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1 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). return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).
\ vimwiki#vars#get_wikilocal('ext', idx) \ vimwiki#vars#get_wikilocal('ext', idx)
endfunction endfunction
" Return: <String> date
function! vimwiki#diary#diary_date_link(...) abort function! vimwiki#diary#diary_date_link(...) abort
" Return: <String> date
if a:0 if a:0
let l:timestamp = a:1 let l:timestamp = a:1
else else
@@ -91,8 +91,8 @@ function! vimwiki#diary#diary_date_link(...) abort
endfunction endfunction
" Return: <int:index, list:links>
function! s:get_position_links(link) abort function! s:get_position_links(link) abort
" Return: <int:index, list:links>
let idx = -1 let idx = -1
let links = [] let links = []
if a:link =~# '^\d\{4}-\d\d-\d\d' if a:link =~# '^\d\{4}-\d\d-\d\d'
@@ -108,14 +108,14 @@ function! s:get_position_links(link) abort
endfunction endfunction
" Convert month: number -> name
function! s:get_month_name(month) abort function! s:get_month_name(month) abort
" Convert month: number -> name
return vimwiki#vars#get_global('diary_months')[str2nr(a:month)] return vimwiki#vars#get_global('diary_months')[str2nr(a:month)]
endfunction endfunction
" Get the first header in the file within the first s:vimwiki_max_scan_for_caption lines.
function! s:get_first_header(fl) abort function! s:get_first_header(fl) abort
" Get the first header in the file within the first s:vimwiki_max_scan_for_caption lines.
let header_rx = vimwiki#vars#get_syntaxlocal('rxHeader') let header_rx = vimwiki#vars#get_syntaxlocal('rxHeader')
for line in readfile(a:fl, '', g:vimwiki_max_scan_for_caption) for line in readfile(a:fl, '', g:vimwiki_max_scan_for_caption)
@@ -127,9 +127,9 @@ function! s:get_first_header(fl) abort
endfunction endfunction
function! s:get_all_headers(fl, maxlevel) abort
" Get a list of all headers in a file up to a given level. " Get a list of all headers in a file up to a given level.
" Return: list whose elements are pairs [level, title] " Return: list whose elements are pairs [level, title]
function! s:get_all_headers(fl, maxlevel) abort
let headers_rx = {} let headers_rx = {}
for i in range(1, a:maxlevel) for i in range(1, a:maxlevel)
let headers_rx[i] = vimwiki#vars#get_syntaxlocal('rxH'.i.'_Text') let headers_rx[i] = vimwiki#vars#get_syntaxlocal('rxH'.i.'_Text')
@@ -147,8 +147,8 @@ function! s:get_all_headers(fl, maxlevel) abort
return headers return headers
endfunction endfunction
" Count headers with level <= maxlevel in a list of [level, title] pairs.
function! s:count_headers_level_less_equal(headers, maxlevel) abort function! s:count_headers_level_less_equal(headers, maxlevel) abort
" Count headers with level <= maxlevel in a list of [level, title] pairs.
let l:count = 0 let l:count = 0
for [header_level, _] in a:headers for [header_level, _] in a:headers
if header_level <= a:maxlevel if header_level <= a:maxlevel
@@ -159,8 +159,8 @@ function! s:count_headers_level_less_equal(headers, maxlevel) abort
endfunction endfunction
" Get the minimum level of any header in a list of [level, title] pairs.
function! s:get_min_header_level(headers) abort function! s:get_min_header_level(headers) abort
" Get the minimum level of any header in a list of [level, title] pairs.
if len(a:headers) == 0 if len(a:headers) == 0
return 0 return 0
endif endif
@@ -172,9 +172,9 @@ function! s:get_min_header_level(headers) abort
endfunction endfunction
function! s:read_captions(files) abort
" Read all cpation in 1. <List>files " Read all cpation in 1. <List>files
" Return: <Dic>: key -> caption " Return: <Dic>: key -> caption
function! s:read_captions(files) abort
let result = {} let result = {}
let caption_level = vimwiki#vars#get_wikilocal('diary_caption_level') let caption_level = vimwiki#vars#get_wikilocal('diary_caption_level')
@@ -215,8 +215,8 @@ function! s:read_captions(files) abort
endfunction endfunction
" Return: <list> diary file names
function! vimwiki#diary#get_diary_files() abort function! vimwiki#diary#get_diary_files() abort
" Return: <list> diary file names
let rx = '^\d\{4}-\d\d-\d\d' let rx = '^\d\{4}-\d\d-\d\d'
let s_files = glob(vimwiki#vars#get_wikilocal('path'). let s_files = glob(vimwiki#vars#get_wikilocal('path').
\ vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext')) \ vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext'))
@@ -230,8 +230,8 @@ function! vimwiki#diary#get_diary_files() abort
endfunction endfunction
" Return: <dic> nested -> links
function! s:group_links(links) abort function! s:group_links(links) abort
" Return: <dic> nested -> links
let result = {} let result = {}
let p_year = 0 let p_year = 0
let p_month = 0 let p_month = 0
@@ -253,8 +253,8 @@ function! s:group_links(links) abort
endfunction endfunction
" Sort list
function! s:sort(lst) abort function! s:sort(lst) abort
" Sort list
if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc' if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc'
return reverse(sort(a:lst)) return reverse(sort(a:lst))
else else
@@ -266,11 +266,11 @@ function! vimwiki#diary#diary_sort(lst) abort
return s:sort(a:lst) return s:sort(a:lst)
endfunction endfunction
function! vimwiki#diary#make_note(wnum, ...) abort
" Create note " Create note
" The given wiki number a:wnum is 1 for the first wiki, 2 for the second and so on. This is in " 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 " contrast to most other places, where counting starts with 0. When a:wnum is 0, the current wiki
" is used. " is used.
function! vimwiki#diary#make_note(wnum, ...) abort
if a:wnum == 0 if a:wnum == 0
let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr') 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 if wiki_nr < 0 " this happens when e.g. VimwikiMakeDiaryNote was called outside a wiki buffer
@@ -308,8 +308,8 @@ function! vimwiki#diary#make_note(wnum, ...) abort
endfunction endfunction
" Jump to diary index of 1. <Int> wikinumber
function! vimwiki#diary#goto_diary_index(wnum) abort function! vimwiki#diary#goto_diary_index(wnum) abort
" Jump to diary index of 1. <Int> wikinumber
" if wnum = 0 the current wiki is used " if wnum = 0 the current wiki is used
if a:wnum == 0 if a:wnum == 0
let idx = vimwiki#vars#get_bufferlocal('wiki_nr') let idx = vimwiki#vars#get_bufferlocal('wiki_nr')
@@ -334,8 +334,8 @@ function! vimwiki#diary#goto_diary_index(wnum) abort
endfunction endfunction
" Jump to next day
function! vimwiki#diary#goto_next_day() abort function! vimwiki#diary#goto_next_day() abort
" Jump to next day
let link = '' let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r')) let [idx, links] = s:get_position_links(expand('%:t:r'))
@@ -356,8 +356,8 @@ function! vimwiki#diary#goto_next_day() abort
endfunction endfunction
" Jump to previous day
function! vimwiki#diary#goto_prev_day() abort function! vimwiki#diary#goto_prev_day() abort
" Jump to previous day
let link = '' let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r')) let [idx, links] = s:get_position_links(expand('%:t:r'))
@@ -378,8 +378,8 @@ function! vimwiki#diary#goto_prev_day() abort
endfunction endfunction
" Create diary index content
function! vimwiki#diary#generate_diary_section() abort function! vimwiki#diary#generate_diary_section() abort
" Create diary index content
let GeneratorDiary = copy(l:) let GeneratorDiary = copy(l:)
function! GeneratorDiary.f() abort function! GeneratorDiary.f() abort
let lines = [] let lines = []
@@ -476,8 +476,8 @@ function! vimwiki#diary#generate_diary_section() abort
endfunction endfunction
" Callback function for Calendar.vim
function! vimwiki#diary#calendar_action(day, month, year, week, dir) abort function! vimwiki#diary#calendar_action(day, month, year, week, dir) abort
" Callback function for Calendar.vim
let day = s:prefix_zero(a:day) let day = s:prefix_zero(a:day)
let month = s:prefix_zero(a:month) let month = s:prefix_zero(a:month)
@@ -499,8 +499,8 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir) abort
endfunction endfunction
" Callback function for Calendar.vim
function! vimwiki#diary#calendar_sign(day, month, year) abort function! vimwiki#diary#calendar_sign(day, month, year) abort
" Callback function for Calendar.vim
let day = s:prefix_zero(a:day) let day = s:prefix_zero(a:day)
let month = s:prefix_zero(a:month) let month = s:prefix_zero(a:month)
let sfile = vimwiki#vars#get_wikilocal('path').vimwiki#vars#get_wikilocal('diary_rel_path'). let sfile = vimwiki#vars#get_wikilocal('path').vimwiki#vars#get_wikilocal('diary_rel_path').
+4 -3
View File
@@ -1759,6 +1759,7 @@ let s:emoji_dic = {}
function! vimwiki#emoji#get_dic() abort function! vimwiki#emoji#get_dic() abort
" Get Dic:
if s:emoji_dic == {} if s:emoji_dic == {}
call extend(s:emoji_dic, s:emoji_multiple) call extend(s:emoji_dic, s:emoji_multiple)
call extend(s:emoji_dic, s:emoji_single) call extend(s:emoji_dic, s:emoji_single)
@@ -1766,17 +1767,17 @@ function! vimwiki#emoji#get_dic() abort
return s:emoji_dic return s:emoji_dic
endfunction endfunction
" Conceal
function! vimwiki#emoji#apply_conceal() abort function! vimwiki#emoji#apply_conceal() abort
" Apply Conceal:
for [name, emoji] in items(s:emoji_single) for [name, emoji] in items(s:emoji_single)
exe 'syn keyword VimwikiEmoji :' . name . ': conceal cchar=' . emoji exe 'syn keyword VimwikiEmoji :' . name . ': conceal cchar=' . emoji
endfor endfor
endfunction endfunction
" Junegunn fuzzy hack
let s:max_score = 1000 let s:max_score = 1000
function! s:score(haystack, needle) abort function! s:score(haystack, needle) abort
" Get Score: Junegunn fuzzy hack
let idx = stridx(a:haystack, a:needle) let idx = stridx(a:haystack, a:needle)
if idx < 0 | return idx | endif if idx < 0 | return idx | endif
if idx == 0 | return s:max_score * 2 | endif if idx == 0 | return s:max_score * 2 | endif
@@ -1785,8 +1786,8 @@ function! s:score(haystack, needle) abort
endfunction endfunction
" Complete
function! vimwiki#emoji#complete(findstart, base) abort function! vimwiki#emoji#complete(findstart, base) abort
" Complete:
" Init full list if must " Init full list if must
if s:emojis == [] if s:emojis == []
let s:emojis = map(sort(keys(vimwiki#emoji#get_dic())), let s:emojis = map(sort(keys(vimwiki#emoji#get_dic())),
+1 -1
View File
@@ -417,9 +417,9 @@ function! s:tag_code(value) abort
endfunction endfunction
function! s:incl_match_arg(nn_index) abort
" match n-th ARG within {{URL[|ARG1|ARG2|...]}} " match n-th ARG within {{URL[|ARG1|ARG2|...]}}
" *c,d,e),... " *c,d,e),...
function! s:incl_match_arg(nn_index) abort
let rx = vimwiki#vars#get_global('rxWikiInclPrefix'). vimwiki#vars#get_global('rxWikiInclUrl') let rx = vimwiki#vars#get_global('rxWikiInclPrefix'). vimwiki#vars#get_global('rxWikiInclUrl')
let rx = rx . repeat(vimwiki#vars#get_global('rxWikiInclSeparator') . let rx = rx . repeat(vimwiki#vars#get_global('rxWikiInclSeparator') .
\ vimwiki#vars#get_global('rxWikiInclArg'), a:nn_index-1) \ vimwiki#vars#get_global('rxWikiInclArg'), a:nn_index-1)
+46 -51
View File
@@ -134,17 +134,17 @@ function! vimwiki#lst#get_list_margin() abort
endfunction endfunction
function! s:text_begin(lnum) abort
" Returns: the column where the text of a line starts (possible list item " Returns: the column where the text of a line starts (possible list item
" markers and checkboxes are skipped) " markers and checkboxes are skipped)
function! s:text_begin(lnum) abort
return s:string_length(matchstr(getline(a:lnum), vimwiki#vars#get_wikilocal('rxListItem'))) return s:string_length(matchstr(getline(a:lnum), vimwiki#vars#get_wikilocal('rxListItem')))
endfunction endfunction
function! s:line_has_marker(lnum) abort
" Returns: 2 if there is a marker and text " Returns: 2 if there is a marker and text
" 1 for a marker and no text " 1 for a marker and no text
" 0 for no marker at all (empty line or only text) " 0 for no marker at all (empty line or only text)
function! s:line_has_marker(lnum) abort
if getline(a:lnum) =~# vimwiki#vars#get_wikilocal('rxListItem').'\s*$' if getline(a:lnum) =~# vimwiki#vars#get_wikilocal('rxListItem').'\s*$'
return 1 return 1
elseif getline(a:lnum) =~# vimwiki#vars#get_wikilocal('rxListItem').'\s*\S' elseif getline(a:lnum) =~# vimwiki#vars#get_wikilocal('rxListItem').'\s*\S'
@@ -155,8 +155,8 @@ function! s:line_has_marker(lnum) abort
endfunction endfunction
" Remove a list item and it's children (recursive)
function! s:remove_including_children(item) abort function! s:remove_including_children(item) abort
" Remove a list item and it's children (recursive)
let num_removed_lines = 1 let num_removed_lines = 1
let child = s:get_first_child(a:item) let child = s:get_first_child(a:item)
while child.type != 0 while child.type != 0
@@ -177,13 +177,13 @@ endfunction
" get properties of a list item " get properties of a list item
" --------------------------------------------------------- " ---------------------------------------------------------
function! s:get_item(lnum) abort
" Returns: the mainly used data structure in this file " Returns: the mainly used data structure in this file
" An item represents a single list item and is a dictionary with the keys " An item represents a single list item and is a dictionary with the keys
" lnum - the line number of the list item " lnum - the line number of the list item
" type - 1 for bulleted item, 2 for numbered item, 0 for a regular line (default) " type - 1 for bulleted item, 2 for numbered item, 0 for a regular line (default)
" mrkr - the concrete marker, e.g. '**' or 'b)' (default '') " mrkr - the concrete marker, e.g. '**' or 'b)' (default '')
" cb - the char in the checkbox or '' if there is no checkbox " cb - the char in the checkbox or '' if there is no checkbox
function! s:get_item(lnum) abort
" Init default " Init default
let item = {'lnum': a:lnum} let item = {'lnum': a:lnum}
let item.type = 0 let item.type = 0
@@ -220,13 +220,14 @@ endfunction
function! s:empty_item() abort function! s:empty_item() abort
" Craft: empty item
return {'type': 0} return {'type': 0}
endfunction endfunction
function! s:get_level(lnum) abort
" Returns: level of the line " Returns: level of the line
" 0 is the 'highest' level " 0 is the 'highest' level
function! s:get_level(lnum) abort
if getline(a:lnum) =~# '^\s*$' if getline(a:lnum) =~# '^\s*$'
return 0 return 0
endif endif
@@ -243,10 +244,10 @@ function! s:get_level(lnum) abort
endfunction endfunction
function! s:guess_kind_of_numbered_item(item) abort
" Returns: 1, a, i, A, I or '' " Returns: 1, a, i, A, I or ''
" If in doubt if alphanumeric character or romanian " If in doubt if alphanumeric character or romanian
" numeral, peek in the previous line " numeral, peek in the previous line
function! s:guess_kind_of_numbered_item(item) abort
if a:item.type != 2 | return '' | endif if a:item.type != 2 | return '' | endif
let number_chars = a:item.mrkr[:-2] let number_chars = a:item.mrkr[:-2]
let divisor = a:item.mrkr[-1:] let divisor = a:item.mrkr[-1:]
@@ -324,8 +325,8 @@ function! s:regexp_of_marker(item) abort
endfunction endfunction
" Returns: Whether or not the checkbox of a list item is [X] or [-]
function! s:is_closed(item) abort function! s:is_closed(item) abort
" Returns: Whether or not the checkbox of a list item is [X] or [-]
let state = a:item.cb let state = a:item.cb
return state ==# vimwiki#vars#get_wikilocal('listsyms_list')[-1] return state ==# vimwiki#vars#get_wikilocal('listsyms_list')[-1]
\ || state ==# vimwiki#vars#get_global('listsym_rejected') \ || state ==# vimwiki#vars#get_global('listsym_rejected')
@@ -335,9 +336,9 @@ endfunction
" functions for navigating between items " functions for navigating between items
" --------------------------------------------------------- " ---------------------------------------------------------
function! s:get_next_list_item(item, ignore_kind) abort
" Returns: the list item after a:item or an empty item " Returns: the list item after a:item or an empty item
" If a:ignore_kind is 1, the markers can differ " If a:ignore_kind is 1, the markers can differ
function! s:get_next_list_item(item, ignore_kind) abort
let org_lvl = s:get_level(a:item.lnum) let org_lvl = s:get_level(a:item.lnum)
if !a:ignore_kind if !a:ignore_kind
let org_regex = s:regexp_of_marker(a:item) let org_regex = s:regexp_of_marker(a:item)
@@ -359,9 +360,9 @@ function! s:get_next_list_item(item, ignore_kind) abort
endfunction endfunction
function! s:get_prev_list_item(item, ignore_kind) abort
" Returns: the list item before a:item or an empty item " Returns: the list item before a:item or an empty item
" If a:ignore_kind is 1, the markers can differ " If a:ignore_kind is 1, the markers can differ
function! s:get_prev_list_item(item, ignore_kind) abort
let org_lvl = s:get_level(a:item.lnum) let org_lvl = s:get_level(a:item.lnum)
if !a:ignore_kind if !a:ignore_kind
let org_regex = s:regexp_of_marker(a:item) let org_regex = s:regexp_of_marker(a:item)
@@ -434,11 +435,11 @@ function! s:get_last_item_in_list(item, ignore_kind) abort
endfunction endfunction
function! s:get_next_line(lnum, ...) abort
" Returns: lnum+1 in most cases, but skips blank lines and preformatted text, " Returns: lnum+1 in most cases, but skips blank lines and preformatted text,
" 0 in case of nonvalid line. " 0 in case of nonvalid line.
" If there is no second argument, 0 is returned at a header, otherwise the " If there is no second argument, 0 is returned at a header, otherwise the
" header is skipped " header is skipped
function! s:get_next_line(lnum, ...) abort
if getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxPreStart') if getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
let cur_ln = a:lnum + 1 let cur_ln = a:lnum + 1
while cur_ln <= line('$') && getline(cur_ln) !~# vimwiki#vars#get_syntaxlocal('rxPreEnd') while cur_ln <= line('$') && getline(cur_ln) !~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
@@ -464,9 +465,9 @@ function! s:get_next_line(lnum, ...) abort
endfunction endfunction
function! s:get_prev_line(lnum) abort
" Returns: lnum-1 in most cases, but skips blank lines and preformatted text " Returns: lnum-1 in most cases, but skips blank lines and preformatted text
" 0 in case of nonvalid line and a header, because a header ends every list " 0 in case of nonvalid line and a header, because a header ends every list
function! s:get_prev_line(lnum) abort
let cur_ln = a:lnum - 1 let cur_ln = a:lnum - 1
if getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd') if getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
@@ -507,10 +508,10 @@ function! s:get_first_child(item) abort
endfunction endfunction
function! s:get_next_child_item(parent, child) abort
" Returns: the next sibling of a:child, given the parent item " Returns: the next sibling of a:child, given the parent item
" Used for iterating over children " Used for iterating over children
" Note: child items do not necessarily have the same indent, i.e. level " Note: child items do not necessarily have the same indent, i.e. level
function! s:get_next_child_item(parent, child) abort
if a:parent.type == 0 | return s:empty_item() | endif if a:parent.type == 0 | return s:empty_item() | endif
let parent_lvl = s:get_level(a:parent.lnum) let parent_lvl = s:get_level(a:parent.lnum)
let cur_ln = s:get_last_line_of_item_incl_children(a:child) let cur_ln = s:get_last_line_of_item_incl_children(a:child)
@@ -556,8 +557,8 @@ function! s:get_parent(item) abort
endfunction endfunction
"Returns: the item above or the item below or an empty item
function! s:get_a_neighbor_item(item) abort function! s:get_a_neighbor_item(item) abort
" Returns: the item above or the item below or an empty item
let prev_item = s:get_prev_list_item(a:item, 1) let prev_item = s:get_prev_list_item(a:item, 1)
if prev_item.type != 0 if prev_item.type != 0
return prev_item return prev_item
@@ -583,9 +584,9 @@ function! s:get_a_neighbor_item_in_column(lnum, column) abort
endfunction endfunction
function! s:get_corresponding_item(lnum) abort
" Returns: the item if there is one in a:lnum " Returns: the item if there is one in a:lnum
" else the multiline item a:lnum belongs to " else the multiline item a:lnum belongs to
function! s:get_corresponding_item(lnum) abort
let item = s:get_item(a:lnum) let item = s:get_item(a:lnum)
if item.type != 0 if item.type != 0
return item return item
@@ -607,8 +608,8 @@ function! s:get_corresponding_item(lnum) abort
endfunction endfunction
"Returns: the last line of a (possibly multiline) item, including all children
function! s:get_last_line_of_item_incl_children(item) abort function! s:get_last_line_of_item_incl_children(item) abort
" Returns: the last line of a (possibly multiline) item, including all children
let cur_ln = a:item.lnum let cur_ln = a:item.lnum
let org_lvl = s:get_level(a:item.lnum) let org_lvl = s:get_level(a:item.lnum)
while 1 while 1
@@ -621,9 +622,9 @@ function! s:get_last_line_of_item_incl_children(item) abort
endfunction endfunction
function! s:get_last_line_of_item(item) abort
" Returns: the last line of a (possibly multiline) item " Returns: the last line of a (possibly multiline) item
" Note: there can be other list items between the first and last line " Note: there can be other list items between the first and last line
function! s:get_last_line_of_item(item) abort
if a:item.type == 0 | return 0 | endif if a:item.type == 0 | return 0 | endif
let org_lvl = s:get_level(a:item.lnum) let org_lvl = s:get_level(a:item.lnum)
let last_corresponding_line = a:item.lnum let last_corresponding_line = a:item.lnum
@@ -650,9 +651,9 @@ endfunction
" renumber list items " renumber list items
" --------------------------------------------------------- " ---------------------------------------------------------
function! s:adjust_numbered_list_below(item, recursive) abort
" Renumbers the current list from a:item on downwards " Renumbers the current list from a:item on downwards
" Returns: the last item that was adjusted " Returns: the last item that was adjusted
function! s:adjust_numbered_list_below(item, recursive) abort
if !(a:item.type == 2 || (a:item.type == 1 && a:recursive)) if !(a:item.type == 2 || (a:item.type == 1 && a:recursive))
return a:item return a:item
endif endif
@@ -702,11 +703,11 @@ function! s:adjust_items_recursively(parent) abort
endfunction endfunction
function! s:adjust_numbered_list(item, ignore_kind, recursive) abort
" Renumbers the list a:item is in. " Renumbers the list a:item is in.
" If a:ignore_kind == 0, only the items which have the same kind of marker as " If a:ignore_kind == 0, only the items which have the same kind of marker as
" a:item are considered, otherwise all items. " a:item are considered, otherwise all items.
" Returns: the last item that was adjusted " Returns: the last item that was adjusted
function! s:adjust_numbered_list(item, ignore_kind, recursive) abort
if !(a:item.type == 2 || (a:item.type == 1 && (a:ignore_kind || a:recursive))) if !(a:item.type == 2 || (a:item.type == 1 && (a:ignore_kind || a:recursive)))
return s:empty_item() return s:empty_item()
end end
@@ -731,9 +732,9 @@ function! s:adjust_numbered_list(item, ignore_kind, recursive) abort
endfunction endfunction
function! vimwiki#lst#adjust_numbered_list() abort
" Renumbers the list the cursor is in " Renumbers the list the cursor is in
" also update its parents checkbox state " also update its parents checkbox state
function! vimwiki#lst#adjust_numbered_list() abort
let cur_item = s:get_corresponding_item(line('.')) let cur_item = s:get_corresponding_item(line('.'))
if cur_item.type == 0 | return | endif if cur_item.type == 0 | return | endif
call s:adjust_numbered_list(cur_item, 1, 0) call s:adjust_numbered_list(cur_item, 1, 0)
@@ -741,9 +742,9 @@ function! vimwiki#lst#adjust_numbered_list() abort
endfunction endfunction
function! vimwiki#lst#adjust_whole_buffer() abort
" Renumbers all lists of the buffer " Renumbers all lists of the buffer
" of course, this might take some seconds " of course, this might take some seconds
function! vimwiki#lst#adjust_whole_buffer() abort
let cur_ln = 1 let cur_ln = 1
while 1 while 1
let cur_item = s:get_item(cur_ln) let cur_item = s:get_item(cur_ln)
@@ -762,8 +763,8 @@ endfunction
" checkbox stuff " checkbox stuff
" --------------------------------------------------------- " ---------------------------------------------------------
"Returns: the rate of checkboxed list item in percent
function! s:get_rate(item) abort function! s:get_rate(item) abort
" Returns: the rate of checkboxed list item in percent
if a:item.type == 0 || a:item.cb ==? '' if a:item.type == 0 || a:item.cb ==? ''
return -1 return -1
endif endif
@@ -776,9 +777,9 @@ function! s:get_rate(item) abort
endfunction endfunction
function! s:set_state(item, new_rate) abort
" Set state of the list item to [ ] or [o] or whatever " Set state of the list item to [ ] or [o] or whatever
" Returns: 1 if the state changed, 0 otherwise " Returns: 1 if the state changed, 0 otherwise
function! s:set_state(item, new_rate) abort
let new_state = s:rate_to_state(a:new_rate) let new_state = s:rate_to_state(a:new_rate)
let old_state = s:rate_to_state(s:get_rate(a:item)) let old_state = s:rate_to_state(s:get_rate(a:item))
if new_state !=# old_state if new_state !=# old_state
@@ -790,10 +791,10 @@ function! s:set_state(item, new_rate) abort
endfunction endfunction
function! s:set_state_plus_children(item, new_rate, ...) abort
" Sets the state of the list item to [ ] or [o] or whatever. Updates the states of its child items. " Sets the state of the list item to [ ] or [o] or whatever. Updates the states of its child items.
" If the new state should be [X] or [-], the state of the current list item is changed to this " If the new state should be [X] or [-], the state of the current list item is changed to this
" state, but if a child item already has [X] or [-] it is left alone. " state, but if a child item already has [X] or [-] it is left alone.
function! s:set_state_plus_children(item, new_rate, ...) abort
let retain_state_if_closed = a:0 > 0 && a:1 > 0 let retain_state_if_closed = a:0 > 0 && a:1 > 0
if !(retain_state_if_closed && (a:new_rate == 100 || a:new_rate == -1) && s:is_closed(a:item)) if !(retain_state_if_closed && (a:new_rate == 100 || a:new_rate == -1) && s:is_closed(a:item))
@@ -849,8 +850,8 @@ function! s:set_state_plus_children(item, new_rate, ...) abort
endfunction endfunction
"Returns: the appropriate symbol for a given percent rate
function! s:rate_to_state(rate) abort function! s:rate_to_state(rate) abort
" Returns: the appropriate symbol for a given percent rate
let listsyms_list = vimwiki#vars#get_wikilocal('listsyms_list') let listsyms_list = vimwiki#vars#get_wikilocal('listsyms_list')
let state = '' let state = ''
let n = len(listsyms_list) let n = len(listsyms_list)
@@ -868,9 +869,8 @@ function! s:rate_to_state(rate) abort
endfunction endfunction
"updates the symbol of a checkboxed item according to the symbols of its
"children
function! s:update_state(item) abort function! s:update_state(item) abort
" Updates the symbol of a checkboxed item according to the symbols of its children
if a:item.type == 0 || a:item.cb ==? '' || vimwiki#vars#get_wikilocal('listsyms_propagate') == 0 if a:item.type == 0 || a:item.cb ==? '' || vimwiki#vars#get_wikilocal('listsyms_propagate') == 0
return return
endif endif
@@ -923,9 +923,9 @@ function! s:set_state_recursively(item, new_rate) abort
endfunction endfunction
function! s:create_cb(item, start_rate) abort
" Creates checkbox in a list item. " Creates checkbox in a list item.
" Returns: 1 if successful " Returns: 1 if successful
function! s:create_cb(item, start_rate) abort
if a:item.type == 0 || a:item.cb !=? '' if a:item.type == 0 || a:item.cb !=? ''
return 0 return 0
endif endif
@@ -950,8 +950,8 @@ function! s:remove_cb(item) abort
endfunction endfunction
" Change state of the checkboxes in the lines of the given range
function! s:change_cb(from_line, to_line, new_rate) abort function! s:change_cb(from_line, to_line, new_rate) abort
" Change state of the checkboxes in the lines of the given range
let from_item = s:get_corresponding_item(a:from_line) let from_item = s:get_corresponding_item(a:from_line)
if from_item.type == 0 if from_item.type == 0
return return
@@ -973,13 +973,12 @@ function! s:change_cb(from_line, to_line, new_rate) abort
for parent_item in parent_items_of_lines for parent_item in parent_items_of_lines
call s:update_state(parent_item) call s:update_state(parent_item)
endfor endfor
endfunction endfunction
function! s:toggle_create_cb(from_line, to_line, state1, state2, start_rate) abort
" Toggles checkbox between two states in the lines of the given range, creates checkboxes (with " Toggles checkbox between two states in the lines of the given range, creates checkboxes (with
" a:start_rate as state) if there aren't any. " a:start_rate as state) if there aren't any.
function! s:toggle_create_cb(from_line, to_line, state1, state2, start_rate) abort
let from_item = s:get_corresponding_item(a:from_line) let from_item = s:get_corresponding_item(a:from_line)
if from_item.type == 0 if from_item.type == 0
return return
@@ -1014,13 +1013,12 @@ function! s:toggle_create_cb(from_line, to_line, state1, state2, start_rate) abo
call s:change_cb(a:from_line, a:to_line, new_rate) call s:change_cb(a:from_line, a:to_line, new_rate)
endif endif
endfunction endfunction
function! vimwiki#lst#decrement_cb(from_line, to_line) abort
" Decrement checkbox between [ ] and [X] " Decrement checkbox between [ ] and [X]
" in the lines of the given range " in the lines of the given range
function! vimwiki#lst#decrement_cb(from_line, to_line) abort
let from_item = s:get_corresponding_item(a:from_line) let from_item = s:get_corresponding_item(a:from_line)
if from_item.type == 0 if from_item.type == 0
return return
@@ -1032,13 +1030,12 @@ function! vimwiki#lst#decrement_cb(from_line, to_line) abort
let new_rate = max([rate_first_line - 100/(n-1)-1, 0]) let new_rate = max([rate_first_line - 100/(n-1)-1, 0])
call s:change_cb(a:from_line, a:to_line, new_rate) call s:change_cb(a:from_line, a:to_line, new_rate)
endfunction endfunction
function! vimwiki#lst#increment_cb(from_line, to_line) abort
" Increment checkbox between [ ] and [X] " Increment checkbox between [ ] and [X]
" in the lines of the given range " in the lines of the given range
function! vimwiki#lst#increment_cb(from_line, to_line) abort
let from_item = s:get_corresponding_item(a:from_line) let from_item = s:get_corresponding_item(a:from_line)
if from_item.type == 0 if from_item.type == 0
return return
@@ -1050,20 +1047,19 @@ function! vimwiki#lst#increment_cb(from_line, to_line) abort
let new_rate = min([rate_first_line + 100/(n-1)+1, 100]) let new_rate = min([rate_first_line + 100/(n-1)+1, 100])
call s:change_cb(a:from_line, a:to_line, new_rate) call s:change_cb(a:from_line, a:to_line, new_rate)
endfunction endfunction
function! vimwiki#lst#toggle_cb(from_line, to_line) abort
" Toggles checkbox between [ ] and [X] or creates one " Toggles checkbox between [ ] and [X] or creates one
" in the lines of the given range " in the lines of the given range
function! vimwiki#lst#toggle_cb(from_line, to_line) abort
return s:toggle_create_cb(a:from_line, a:to_line, 100, 0, 0) return s:toggle_create_cb(a:from_line, a:to_line, 100, 0, 0)
endfunction endfunction
function! vimwiki#lst#toggle_rejected_cb(from_line, to_line) abort
" Toggles checkbox between [ ] and [-] or creates one " Toggles checkbox between [ ] and [-] or creates one
" in the lines of the given range " in the lines of the given range
function! vimwiki#lst#toggle_rejected_cb(from_line, to_line) abort
return s:toggle_create_cb(a:from_line, a:to_line, -1, 0, -1) return s:toggle_create_cb(a:from_line, a:to_line, -1, 0, -1)
endfunction endfunction
@@ -1114,9 +1110,9 @@ function! vimwiki#lst#remove_cb_in_list() abort
endfunction endfunction
function! s:remove_done_in_list(item, recursive) abort
" Iterate over given todo list and remove all task that are done " Iterate over given todo list and remove all task that are done
" If recursive is true, child items will be checked too " If recursive is true, child items will be checked too
function! s:remove_done_in_list(item, recursive) abort
" Clause non-null item type " Clause non-null item type
if a:item.type == 0 if a:item.type == 0
return return
@@ -1151,17 +1147,17 @@ function! s:remove_done_in_list(item, recursive) abort
endfunction endfunction
function! vimwiki#lst#remove_done_in_current_list(recursive) abort
" Iterate over the list that the cursor is positioned in " Iterate over the list that the cursor is positioned in
" and remove all lines of task that are done. " and remove all lines of task that are done.
" If recursive is true, child items will be checked too " If recursive is true, child items will be checked too
function! vimwiki#lst#remove_done_in_current_list(recursive) abort
let item = s:get_corresponding_item(line('.')) let item = s:get_corresponding_item(line('.'))
call s:remove_done_in_list(item, a:recursive) call s:remove_done_in_list(item, a:recursive)
endfunction endfunction
" Remove selected lines if they contain a task that is done
function! vimwiki#lst#remove_done_in_range(first_line, last_line) abort function! vimwiki#lst#remove_done_in_range(first_line, last_line) abort
" Remove selected lines if they contain a task that is done
let first_item = s:get_corresponding_item(a:first_line) let first_item = s:get_corresponding_item(a:first_line)
let last_item = s:get_corresponding_item(a:last_line) let last_item = s:get_corresponding_item(a:last_line)
@@ -1195,12 +1191,12 @@ function! vimwiki#lst#remove_done_in_range(first_line, last_line) abort
endfunction endfunction
function! vimwiki#lst#remove_done(recursive, range, first_line, last_line) abort
" wrapper function to distinguish between function used with a range or not " wrapper function to distinguish between function used with a range or not
" vim 8.0.1089 and newer and corresponding neovim versions allow to use <range> to distinguish if " vim 8.0.1089 and newer and corresponding neovim versions allow to use <range> to distinguish if
" the function has been called with a range. For older versions we use remove_done_in_range if " the function has been called with a range. For older versions we use remove_done_in_range if
" first and last line are identical, which means there was either no range or the range was within " first and last line are identical, which means there was either no range or the range was within
" one line. " one line.
function! vimwiki#lst#remove_done(recursive, range, first_line, last_line) abort
if a:range ==# '<range>' if a:range ==# '<range>'
let range = a:first_line != a:last_line let range = a:first_line != a:last_line
else else
@@ -1269,11 +1265,11 @@ function! s:increase_level(item, by) abort
endfunction endfunction
function! s:indent_cycle_bullets(item, indent_by) abort
" Cycle through the bullet list markers set in " Cycle through the bullet list markers set in
" `bullet_types` based on the indentation level " `bullet_types` based on the indentation level
" TODO there is potential to merge this with the change_marker* funcs further " TODO there is potential to merge this with the change_marker* funcs further
" up if we can make them operate on arbitrary lists of characters " up if we can make them operate on arbitrary lists of characters
function! s:indent_cycle_bullets(item, indent_by) abort
" Clause: Check if should work " Clause: Check if should work
if !vimwiki#vars#get_syntaxlocal('cycle_bullets') || a:item.type != 1 if !vimwiki#vars#get_syntaxlocal('cycle_bullets') || a:item.type != 1
return return
@@ -1287,9 +1283,9 @@ function! s:indent_cycle_bullets(item, indent_by) abort
endfunction endfunction
function! s:indent_line_by(lnum, indent_by) abort
" Add a:indent_by to the current indent " Add a:indent_by to the current indent
"a:indent_by can be negative "a:indent_by can be negative
function! s:indent_line_by(lnum, indent_by) abort
let item = s:get_item(a:lnum) let item = s:get_item(a:lnum)
if a:indent_by > 0 if a:indent_by > 0
call s:increase_level(item, a:indent_by) call s:increase_level(item, a:indent_by)
@@ -1300,8 +1296,8 @@ function! s:indent_line_by(lnum, indent_by) abort
endfunction endfunction
" Change lvl of lines in selection
function! s:change_level(from_line, to_line, direction, plus_children) abort function! s:change_level(from_line, to_line, direction, plus_children) abort
" Change lvl of lines in selection
let from_item = s:get_corresponding_item(a:from_line) let from_item = s:get_corresponding_item(a:from_line)
if from_item.type == 0 if from_item.type == 0
if a:direction ==# 'increase' && a:from_line == a:to_line && empty(getline(a:from_line)) if a:direction ==# 'increase' && a:from_line == a:to_line && empty(getline(a:from_line))
@@ -1385,8 +1381,8 @@ function! vimwiki#lst#change_level(from_line, to_line, direction, plus_children)
endfunction endfunction
"indent line a:lnum to be the continuation of a:prev_item
function! s:indent_multiline(prev_item, lnum) abort function! s:indent_multiline(prev_item, lnum) abort
" Indent line a:lnum to be the continuation of a:prev_item
if a:prev_item.type != 0 if a:prev_item.type != 0
call s:set_indent(a:lnum, s:text_begin(a:prev_item.lnum)) call s:set_indent(a:lnum, s:text_begin(a:prev_item.lnum))
endif endif
@@ -1397,8 +1393,8 @@ endfunction
" change markers of list items " change markers of list items
" --------------------------------------------------------- " ---------------------------------------------------------
"Returns: the position of a marker in g:vimwiki_list_markers
function! s:get_idx_list_markers(item) abort function! s:get_idx_list_markers(item) abort
" Returns: the position of a marker in g:vimwiki_list_markers
if a:item.type == 1 if a:item.type == 1
let m = s:first_char(a:item.mrkr) let m = s:first_char(a:item.mrkr)
else else
@@ -1408,8 +1404,8 @@ function! s:get_idx_list_markers(item) abort
endfunction endfunction
"changes the marker of the given item to the next in g:vimwiki_list_markers
function! s:get_next_mrkr(item) abort function! s:get_next_mrkr(item) abort
" Changes the marker of the given item to the next in g:vimwiki_list_markers
let markers = vimwiki#vars#get_syntaxlocal('list_markers') let markers = vimwiki#vars#get_syntaxlocal('list_markers')
if a:item.type == 0 if a:item.type == 0
let new_mrkr = markers[0] let new_mrkr = markers[0]
@@ -1421,8 +1417,8 @@ function! s:get_next_mrkr(item) abort
endfunction endfunction
"changes the marker of the given item to the previous in g:vimwiki_list_markers
function! s:get_prev_mrkr(item) abort function! s:get_prev_mrkr(item) abort
" Changes the marker of the given item to the previous in g:vimwiki_list_markers
let markers = vimwiki#vars#get_syntaxlocal('list_markers') let markers = vimwiki#vars#get_syntaxlocal('list_markers')
if a:item.type == 0 if a:item.type == 0
return markers[-1] return markers[-1]
@@ -1519,8 +1515,8 @@ function! vimwiki#lst#change_marker_in_list(new_mrkr) abort
endfunction endfunction
"sets kind of the item depending on neighbor items and the parent item
function! s:adjust_mrkr(item) abort function! s:adjust_mrkr(item) abort
" Sets kind of the item depending on neighbor items and the parent item
if a:item.type == 0 || vimwiki#vars#get_syntaxlocal('recurring_bullets') if a:item.type == 0 || vimwiki#vars#get_syntaxlocal('recurring_bullets')
return return
endif endif
@@ -1771,12 +1767,11 @@ function! vimwiki#lst#kbd_cr(normal, just_mrkr) abort
else else
startinsert startinsert
endif endif
endfunction endfunction
"creates a list item in the current line or removes it
function! vimwiki#lst#toggle_list_item() abort function! vimwiki#lst#toggle_list_item() abort
" Creates a list item in the current line or removes it
let cur_col_from_eol = col('$') - col("'^") let cur_col_from_eol = col('$') - col("'^")
let cur_item = s:get_item(line('.')) let cur_item = s:get_item(line('.'))
+1 -2
View File
@@ -34,8 +34,8 @@ function! vimwiki#markdown_base#scan_reflinks() abort
endfunction endfunction
" try markdown reference links
function! vimwiki#markdown_base#open_reflink(link) abort function! vimwiki#markdown_base#open_reflink(link) abort
" try markdown reference links
let link = a:link let link = a:link
let mkd_refs = vimwiki#vars#get_bufferlocal('markdown_refs') let mkd_refs = vimwiki#vars#get_bufferlocal('markdown_refs')
if has_key(mkd_refs, link) if has_key(mkd_refs, link)
@@ -106,7 +106,6 @@ function! s:normalize_link_syntax_n() abort
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub) call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
return return
endif endif
endfunction endfunction
+18 -18
View File
@@ -5,19 +5,19 @@
" Unixify path
function! s:unixify(path) abort function! s:unixify(path) abort
" Unixify Path:
return substitute(a:path, '\', '/', 'g') return substitute(a:path, '\', '/', 'g')
endfunction endfunction
" Windowsify path
function! s:windowsify(path) abort function! s:windowsify(path) abort
" Windowsify Path:
return substitute(a:path, '/', '\', 'g') return substitute(a:path, '/', '\', 'g')
endfunction endfunction
" Define os specific path convertion " Define: os specific path convertion
if vimwiki#u#is_windows() if vimwiki#u#is_windows()
function! s:osxify(path) abort function! s:osxify(path) abort
return s:windowsify(a:path) return s:windowsify(a:path)
@@ -29,8 +29,8 @@ else
endif endif
" Remove last path delimitator (slash or backslash)
function! vimwiki#path#chomp_slash(str) abort function! vimwiki#path#chomp_slash(str) abort
" Remove Delimiter: of last path (slash or backslash)
return substitute(a:str, '[/\\]\+$', '', '') return substitute(a:str, '[/\\]\+$', '', '')
endfunction endfunction
@@ -47,8 +47,8 @@ else
endif endif
" Collapse sections like /a/b/../c to /a/c and /a/b/./c to /a/b/c
function! vimwiki#path#normalize(path) abort function! vimwiki#path#normalize(path) abort
" Collapse Sections: like /a/b/../c to /a/c and /a/b/./c to /a/b/c
let path = a:path let path = a:path
while 1 while 1
let intermediateResult = substitute(path, '/[^/]\+/\.\.', '', '') let intermediateResult = substitute(path, '/[^/]\+/\.\.', '', '')
@@ -62,8 +62,8 @@ function! vimwiki#path#normalize(path) abort
endfunction endfunction
" Normalize path: \ -> / && /// -> / && resolve(symlinks)
function! vimwiki#path#path_norm(path) abort function! vimwiki#path#path_norm(path) abort
" Normalize Path: \ -> / && /// -> / && resolve(symlinks)
" return if scp " return if scp
if a:path =~# '^scp:' | return a:path | endif if a:path =~# '^scp:' | return a:path | endif
" convert backslash to slash " convert backslash to slash
@@ -75,22 +75,22 @@ function! vimwiki#path#path_norm(path) abort
endfunction endfunction
" Check if link is to a directory
function! vimwiki#path#is_link_to_dir(link) abort function! vimwiki#path#is_link_to_dir(link) abort
" Check: if link is to a directory
" It should be ended with \ or /. " It should be ended with \ or /.
return a:link =~# '\m[/\\]$' return a:link =~# '\m[/\\]$'
endfunction endfunction
" Get absolute path <- path relative to current file
function! vimwiki#path#abs_path_of_link(link) abort function! vimwiki#path#abs_path_of_link(link) abort
" Get: absolute path <- path relative to current file
return vimwiki#path#normalize(expand('%:p:h').'/'.a:link) return vimwiki#path#normalize(expand('%:p:h').'/'.a:link)
endfunction endfunction
function! vimwiki#path#path_common_pfx(path1, path2) abort
" Returns: longest common path prefix of 2 given paths. " Returns: longest common path prefix of 2 given paths.
" Ex: '~/home/usrname/wiki', '~/home/usrname/wiki/shmiki' => '~/home/usrname/wiki' " Ex: '~/home/usrname/wiki', '~/home/usrname/wiki/shmiki' => '~/home/usrname/wiki'
function! vimwiki#path#path_common_pfx(path1, path2) abort
let p1 = split(a:path1, '[/\\]', 1) let p1 = split(a:path1, '[/\\]', 1)
let p2 = split(a:path2, '[/\\]', 1) let p2 = split(a:path2, '[/\\]', 1)
@@ -107,8 +107,8 @@ function! vimwiki#path#path_common_pfx(path1, path2) abort
endfunction endfunction
" Convert path -> full resolved slashed path
function! vimwiki#path#wikify_path(path) abort function! vimwiki#path#wikify_path(path) abort
" Convert: path -> full resolved slashed path
let result = resolve(fnamemodify(a:path, ':p')) let result = resolve(fnamemodify(a:path, ':p'))
if vimwiki#u#is_windows() if vimwiki#u#is_windows()
let result = substitute(result, '\\', '/', 'g') let result = substitute(result, '\\', '/', 'g')
@@ -118,14 +118,14 @@ function! vimwiki#path#wikify_path(path) abort
endfunction endfunction
" Return: Current file path relative
function! vimwiki#path#current_wiki_file() abort function! vimwiki#path#current_wiki_file() abort
" Return: Current file path relative
return vimwiki#path#wikify_path(expand('%:p')) return vimwiki#path#wikify_path(expand('%:p'))
endfunction endfunction
" Return: the relative path from a:dir to a:file
function! vimwiki#path#relpath(dir, file) abort function! vimwiki#path#relpath(dir, file) abort
" Return: the relative path from a:dir to a:file
" Check if dir here ('.') -> return file " Check if dir here ('.') -> return file
if empty(a:dir) || a:dir =~# '^\.[/\\]\?$' if empty(a:dir) || a:dir =~# '^\.[/\\]\?$'
return a:file return a:file
@@ -168,11 +168,11 @@ function! vimwiki#path#relpath(dir, file) abort
endfunction endfunction
" Mkdir:
" If the optional argument provided and nonzero,
" it will ask before creating a directory
" Returns: 1 iff directory exists or successfully created
function! vimwiki#path#mkdir(path, ...) abort function! vimwiki#path#mkdir(path, ...) abort
" Mkdir:
" if the optional argument provided and nonzero,
" it will ask before creating a directory
" returns: 1 iff directory exists or successfully created
let path = expand(a:path) let path = expand(a:path)
if path =~# '^scp:' if path =~# '^scp:'
@@ -202,8 +202,8 @@ function! vimwiki#path#mkdir(path, ...) abort
endfunction endfunction
" Check: if path is absolute
function! vimwiki#path#is_absolute(path) abort function! vimwiki#path#is_absolute(path) abort
" Check: if path is absolute
if vimwiki#u#is_windows() if vimwiki#u#is_windows()
return a:path =~? '\m^\a:' return a:path =~? '\m^\a:'
else else
@@ -212,11 +212,11 @@ function! vimwiki#path#is_absolute(path) abort
endfunction endfunction
if vimwiki#u#is_windows()
" Combine: a directory and a file into one path, doesn't generate duplicate " Combine: a directory and a file into one path, doesn't generate duplicate
" path separator in case the directory is also having an ending / or \. This " path separator in case the directory is also having an ending / or \. This
" is because on windows ~\vimwiki//.tags is invalid but ~\vimwiki/.tags is a " is because on windows ~\vimwiki//.tags is invalid but ~\vimwiki/.tags is a
" valid path. " valid path.
if vimwiki#u#is_windows()
function! vimwiki#path#join_path(directory, file) abort function! vimwiki#path#join_path(directory, file) abort
let directory = vimwiki#path#chomp_slash(a:directory) let directory = vimwiki#path#chomp_slash(a:directory)
let file = substitute(a:file, '\m^[\\/]\+', '', '') let file = substitute(a:file, '\m^[\\/]\+', '', '')
+12 -12
View File
@@ -22,11 +22,11 @@
let s:TAGS_METADATA_FILE_NAME = '.vimwiki_tags' let s:TAGS_METADATA_FILE_NAME = '.vimwiki_tags'
function! vimwiki#tags#update_tags(full_rebuild, all_files) abort
" Update tags metadata. " Update tags metadata.
" Param: a:full_rebuild == 1: re-scan entire wiki " Param: a:full_rebuild == 1: re-scan entire wiki
" Param: a:full_rebuild == 0: only re-scan current page " Param: a:full_rebuild == 0: only re-scan current page
" a:all_files == '': only if the file is newer than .tags " a:all_files == '': only if the file is newer than .tags
function! vimwiki#tags#update_tags(full_rebuild, all_files) abort
let all_files = a:all_files !=? '' let all_files = a:all_files !=? ''
if !a:full_rebuild if !a:full_rebuild
" Updating for one page (current) " Updating for one page (current)
@@ -60,16 +60,16 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files) abort
endfunction endfunction
function! s:safesubstitute(text, search, replace, mode) abort
" Substitute regexp but do not interpret replace " Substitute regexp but do not interpret replace
" TODO mutualize with same function in base " TODO mutualize with same function in base
function! s:safesubstitute(text, search, replace, mode) abort
let escaped = escape(a:replace, '\&') let escaped = escape(a:replace, '\&')
return substitute(a:text, a:search, escaped, a:mode) return substitute(a:text, a:search, escaped, a:mode)
endfunction endfunction
" Scan the list of text lines (argument) and produces tags metadata as a list of tag entries.
function! s:scan_tags(lines, page_name) abort function! s:scan_tags(lines, page_name) abort
" Scan the list of text lines (argument) and produces tags metadata as a list of tag entries.
" Code wireframe to scan for headers -- borrowed from " Code wireframe to scan for headers -- borrowed from
" vimwiki#base#get_anchors(), with minor modifications. " vimwiki#base#get_anchors(), with minor modifications.
@@ -155,15 +155,15 @@ function! s:scan_tags(lines, page_name) abort
endfunction endfunction
" Return: tags metadata file path
function! vimwiki#tags#metadata_file_path() abort function! vimwiki#tags#metadata_file_path() abort
" Return: tags metadata file path
return fnamemodify(vimwiki#path#join_path(vimwiki#vars#get_wikilocal('path'), return fnamemodify(vimwiki#path#join_path(vimwiki#vars#get_wikilocal('path'),
\ s:TAGS_METADATA_FILE_NAME), ':p') \ s:TAGS_METADATA_FILE_NAME), ':p')
endfunction endfunction
" Load tags metadata from file, returns a dictionary
function! s:load_tags_metadata() abort function! s:load_tags_metadata() abort
" Load tags metadata from file, returns a dictionary
let metadata_path = vimwiki#tags#metadata_file_path() let metadata_path = vimwiki#tags#metadata_file_path()
if !filereadable(metadata_path) if !filereadable(metadata_path)
return {} return {}
@@ -213,9 +213,9 @@ function! s:load_tags_metadata() abort
endfunction endfunction
function! s:remove_page_from_tags(metadata, page_name) abort
" Remove all entries for given page from metadata in-place. Returns updated " Remove all entries for given page from metadata in-place. Returns updated
" metadata (just in case). " metadata (just in case).
function! s:remove_page_from_tags(metadata, page_name) abort
if has_key(a:metadata, a:page_name) if has_key(a:metadata, a:page_name)
call remove(a:metadata, a:page_name) call remove(a:metadata, a:page_name)
return a:metadata return a:metadata
@@ -225,14 +225,15 @@ function! s:remove_page_from_tags(metadata, page_name) abort
endfunction endfunction
" Merge metadata of one file into a:metadata
function! s:merge_tags(metadata, pagename, file_metadata) abort function! s:merge_tags(metadata, pagename, file_metadata) abort
" Merge metadata of one file into a:metadata
let metadata = a:metadata let metadata = a:metadata
let metadata[a:pagename] = a:file_metadata let metadata[a:pagename] = a:file_metadata
return metadata return metadata
endfunction endfunction
function! s:tags_entry_cmp(i1, i2) abort
" Compare two actual lines from tags file. Return value is in strcmp style. " Compare two actual lines from tags file. Return value is in strcmp style.
" See help on sort() -- that's what this function is going to be used for. " See help on sort() -- that's what this function is going to be used for.
" See also s:write_tags_metadata below -- that's where we compose these tags " See also s:write_tags_metadata below -- that's where we compose these tags
@@ -242,7 +243,6 @@ endfunction
" numbers as strings, not integers, and so, for example, tag at line 14 " numbers as strings, not integers, and so, for example, tag at line 14
" preceeds the same tag on the same page at line 9. (Because string "14" is " preceeds the same tag on the same page at line 9. (Because string "14" is
" alphabetically 'less than' string "9".) " alphabetically 'less than' string "9".)
function! s:tags_entry_cmp(i1, i2) abort
let items = [] let items = []
for orig_item in [a:i1, a:i2] for orig_item in [a:i1, a:i2]
let fields = split(orig_item, "\t") let fields = split(orig_item, "\t")
@@ -265,8 +265,8 @@ function! s:tags_entry_cmp(i1, i2) abort
endfunction endfunction
" Save metadata object into a file. Throws exceptions in case of problems.
function! s:write_tags_metadata(metadata) abort function! s:write_tags_metadata(metadata) abort
" Save metadata object into a file. Throws exceptions in case of problems.
let metadata_path = vimwiki#tags#metadata_file_path() let metadata_path = vimwiki#tags#metadata_file_path()
let tags = [] let tags = []
for pagename in keys(a:metadata) for pagename in keys(a:metadata)
@@ -302,8 +302,8 @@ function! s:write_tags_metadata(metadata) abort
endfunction endfunction
" Return: list of unique tags found in the .tags file
function! vimwiki#tags#get_tags() abort function! vimwiki#tags#get_tags() abort
" Return: list of unique tags found in the .tags file
let metadata = s:load_tags_metadata() let metadata = s:load_tags_metadata()
let tags = {} let tags = {}
for entries in values(metadata) for entries in values(metadata)
@@ -315,11 +315,11 @@ function! vimwiki#tags#get_tags() abort
endfunction endfunction
function! vimwiki#tags#generate_tags(create, ...) abort
" Generate tags in current buffer " Generate tags in current buffer
" Similar to vimwiki#base#generate_links. In the current buffer, appends " Similar to vimwiki#base#generate_links. In the current buffer, appends
" tags and references to all their instances. If no arguments (tags) are " tags and references to all their instances. If no arguments (tags) are
" specified, outputs all tags. " specified, outputs all tags.
function! vimwiki#tags#generate_tags(create, ...) abort
let specific_tags = a:000 let specific_tags = a:000
let header_level = vimwiki#vars#get_global('tags_header_level') let header_level = vimwiki#vars#get_global('tags_header_level')
@@ -408,8 +408,8 @@ function! vimwiki#tags#generate_tags(create, ...) abort
endfunction endfunction
" Complete tags
function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort
" Complete tags
" We can safely ignore args if we use -custom=complete option, Vim engine " We can safely ignore args if we use -custom=complete option, Vim engine
" will do the job of filtering. " will do the job of filtering.
let taglist = vimwiki#tags#get_tags() let taglist = vimwiki#tags#get_tags()
+6 -7
View File
@@ -8,7 +8,6 @@
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" Clause: Load only once " Clause: Load only once
if exists('g:loaded_vimwiki_tbl_auto') || &compatible if exists('g:loaded_vimwiki_tbl_auto') || &compatible
finish finish
@@ -54,15 +53,15 @@ function! s:sep_splitter() abort
endfunction endfunction
" Check if param:line is in a table
function! s:is_table(line) abort function! s:is_table(line) abort
" Check if param:line is in a table
return s:is_separator(a:line) || return s:is_separator(a:line) ||
\ (a:line !~# s:rxSep().s:rxSep() && a:line =~# '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$') \ (a:line !~# s:rxSep().s:rxSep() && a:line =~# '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$')
endfunction endfunction
" Check if param:line is a separator (ex: | --- | --- |)
function! s:is_separator(line) abort function! s:is_separator(line) abort
" Check if param:line is a separator (ex: | --- | --- |)
return a:line =~# '^\s*'.s:rxSep().'\(:\=--\+:\='.s:rxSep().'\)\+\s*$' return a:line =~# '^\s*'.s:rxSep().'\(:\=--\+:\='.s:rxSep().'\)\+\s*$'
endfunction endfunction
@@ -417,8 +416,8 @@ function! s:get_aligned_rows(lnum, col1, col2, depth) abort
endfunction endfunction
" Number of the current column. Starts from 0.
function! s:cur_column() abort function! s:cur_column() abort
" Number of the current column. Starts from 0.
let line = getline('.') let line = getline('.')
if !s:is_table(line) if !s:is_table(line)
return -1 return -1
@@ -542,8 +541,8 @@ function! s:kbd_goto_prev_row() abort
endfunction endfunction
" Used in s:kbd_goto_next_col
function! vimwiki#tbl#goto_next_col() abort function! vimwiki#tbl#goto_next_col() abort
" Used in s:kbd_goto_next_col
let curcol = virtcol('.') let curcol = virtcol('.')
let lnum = line('.') let lnum = line('.')
let depth = 2 let depth = 2
@@ -577,8 +576,8 @@ function! s:kbd_goto_next_col(jumpdown) abort
endfunction endfunction
" Used in s:kbd_goto_prev_col
function! vimwiki#tbl#goto_prev_col() abort function! vimwiki#tbl#goto_prev_col() abort
" Used in s:kbd_goto_prev_col
let curcol = virtcol('.') let curcol = virtcol('.')
let lnum = line('.') let lnum = line('.')
let depth = 2 let depth = 2
@@ -757,8 +756,8 @@ function! vimwiki#tbl#align_or_cmd(cmd, ...) abort
endfunction endfunction
" TODO: move_column_left and move_column_right are good candidates to be refactored.
function! vimwiki#tbl#move_column_left() abort function! vimwiki#tbl#move_column_left() abort
" TODO: move_column_left and move_column_right are good candidates to be refactored.
" Clause in " Clause in
let line = getline('.') let line = getline('.')
if !s:is_table(line) if !s:is_table(line)
+28 -27
View File
@@ -3,11 +3,11 @@
" Description: Utility functions " Description: Utility functions
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
function! vimwiki#u#echo(msg, ...) abort
" Echo: msg " Echo: msg
" :param: (1) <string> highlighting group " :param: (1) <string> highlighting group
" :param: (2) <string> echo suffix (ex: 'n', 'm') " :param: (2) <string> echo suffix (ex: 'n', 'm')
" :param: (3) <string> message prefix, default Vimwiki " :param: (3) <string> message prefix, default Vimwiki
function! vimwiki#u#echo(msg, ...) abort
let hl_group = a:0 > 0 ? a:1 : '' let hl_group = a:0 > 0 ? a:1 : ''
let echo_suffix = a:0 > 1 ? a:2 : '' let echo_suffix = a:0 > 1 ? a:2 : ''
let msg_prefix = a:0 > 2 ? a:3 : 'Vimwiki: ' let msg_prefix = a:0 > 2 ? a:3 : 'Vimwiki: '
@@ -27,34 +27,34 @@ function! vimwiki#u#echo(msg, ...) abort
endif endif
endfunction endfunction
function! vimwiki#u#debug(msg) abort
" Debug: msg " Debug: msg
" let b:vimwiki_debug to trigger " let b:vimwiki_debug to trigger
function! vimwiki#u#debug(msg) abort
if !exists('b:vimwiki_debug') || b:vimwiki_debug == 0 if !exists('b:vimwiki_debug') || b:vimwiki_debug == 0
return return
endif endif
echomsg 'DEBUG: ' . a:msg echomsg 'DEBUG: ' . a:msg
endfunction endfunction
" Warn: msg
function! vimwiki#u#warn(msg) abort function! vimwiki#u#warn(msg) abort
" Warn: msg
call vimwiki#u#echo('Warning: ' . a:msg, 'WarningMsg', '') call vimwiki#u#echo('Warning: ' . a:msg, 'WarningMsg', '')
endfunction endfunction
" Error: msg
function! vimwiki#u#error(msg) abort function! vimwiki#u#error(msg) abort
" Error: msg
call vimwiki#u#echo('Error: ' . a:msg, 'Error', 'msg') call vimwiki#u#echo('Error: ' . a:msg, 'Error', 'msg')
endfunction endfunction
" Warn: deprecated feature: old -> new
function! vimwiki#u#deprecate(old, new) abort function! vimwiki#u#deprecate(old, new) abort
" Warn: deprecated feature: old -> new
call vimwiki#u#warn('Deprecated: ' . a:old . ' is deprecated and ' call vimwiki#u#warn('Deprecated: ' . a:old . ' is deprecated and '
\ . 'will be removed in future versions. Use ' . a:new . ' instead.') \ . 'will be removed in future versions. Use ' . a:new . ' instead.')
endfunction endfunction
function! vimwiki#u#get_selection(...) abort
" Get visual selection text content, optionaly replace its content " Get visual selection text content, optionaly replace its content
" :param: Text to replace selection " :param: Text to replace selection
function! vimwiki#u#get_selection(...) abort
" Copyed from DarkWiiPlayer at stackoverflow " Copyed from DarkWiiPlayer at stackoverflow
" https://stackoverflow.com/a/47051271/2544873 " https://stackoverflow.com/a/47051271/2544873
" Get selection extremity position, " Get selection extremity position,
@@ -101,8 +101,9 @@ function! vimwiki#u#get_selection(...) abort
endfunction endfunction
" Execute: string v:count times
function! vimwiki#u#count_exe(cmd) abort function! vimwiki#u#count_exe(cmd) abort
" Execute: string v:count times
" Called: prefixable mapping
for i in range( max([1, v:count]) ) for i in range( max([1, v:count]) )
exe a:cmd exe a:cmd
endfor endfor
@@ -119,10 +120,10 @@ function! vimwiki#u#sort_len(list) abort
endfunction endfunction
function! vimwiki#u#trim(string, ...) abort
" Trim spaces: leading and trailing " Trim spaces: leading and trailing
" :param: string in " :param: string in
" :param: (1) <string> optional list of character to trim " :param: (1) <string> optional list of character to trim
function! vimwiki#u#trim(string, ...) abort
let chars = '' let chars = ''
if a:0 > 0 if a:0 > 0
let chars = a:1 let chars = a:1
@@ -133,15 +134,15 @@ function! vimwiki#u#trim(string, ...) abort
endfunction endfunction
" Builtin cursor doesn't work right with unicode characters.
function! vimwiki#u#cursor(lnum, cnum) abort function! vimwiki#u#cursor(lnum, cnum) abort
" Builtin cursor doesn't work right with unicode characters.
exe a:lnum exe a:lnum
exe 'normal! 0'.a:cnum.'|' exe 'normal! 0'.a:cnum.'|'
endfunction endfunction
" Returns: OS name, human readable
function! vimwiki#u#os_name() abort function! vimwiki#u#os_name() abort
" Returns: OS name, human readable
if vimwiki#u#is_windows() if vimwiki#u#is_windows()
return 'Windows' return 'Windows'
elseif vimwiki#u#is_macos() elseif vimwiki#u#is_macos()
@@ -152,14 +153,14 @@ function! vimwiki#u#os_name() abort
endfunction endfunction
" Check if OS is windows
function! vimwiki#u#is_windows() abort function! vimwiki#u#is_windows() abort
" Check if OS is windows
return has('win32') || has('win64') || has('win95') || has('win16') return has('win32') || has('win64') || has('win95') || has('win16')
endfunction endfunction
" Check if OS is mac
function! vimwiki#u#is_macos() abort function! vimwiki#u#is_macos() abort
" Check if OS is mac
if has('mac') || has('macunix') || has('gui_mac') if has('mac') || has('macunix') || has('gui_mac')
return 1 return 1
endif endif
@@ -175,26 +176,26 @@ function! vimwiki#u#count_first_sym(line) abort
endfunction endfunction
" Escape string for literal magic regex match
function! vimwiki#u#escape(string) abort function! vimwiki#u#escape(string) abort
" Escape string for literal magic regex match
return escape(a:string, '~.*[]\^$') return escape(a:string, '~.*[]\^$')
endfunction endfunction
" Load concrete Wiki syntax: sets regexes and templates for headers and links
function! vimwiki#u#reload_regexes() abort function! vimwiki#u#reload_regexes() abort
" Load concrete Wiki syntax: sets regexes and templates for headers and links
execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'.vim' execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'.vim'
endfunction endfunction
" Load syntax-specific functionality
function! vimwiki#u#reload_regexes_custom() abort function! vimwiki#u#reload_regexes_custom() abort
" Load syntax-specific functionality
execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'_custom.vim' execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'_custom.vim'
endfunction endfunction
" Backward compatible version of the built-in function shiftwidth()
function! vimwiki#u#sw() abort function! vimwiki#u#sw() abort
" Backward compatible version of the built-in function shiftwidth()
if exists('*shiftwidth') if exists('*shiftwidth')
return shiftwidth() return shiftwidth()
else else
@@ -202,6 +203,7 @@ function! vimwiki#u#sw() abort
endif endif
endfunc endfunc
function! vimwiki#u#map_key(mode, key, plug, ...) abort
" a:mode single character indicating the mode as defined by :h maparg " a:mode single character indicating the mode as defined by :h maparg
" a:key the key sequence to map " a:key the key sequence to map
" a:plug the plug command the key sequence should be mapped to " a:plug the plug command the key sequence should be mapped to
@@ -209,7 +211,6 @@ endfunc
" if a:1==1 then the hasmapto(<Plug>) check is skipped. " if a:1==1 then the hasmapto(<Plug>) check is skipped.
" this can be used to map different keys to the same <Plug> definition " this can be used to map different keys to the same <Plug> definition
" if a:1==2 then the mapping is not <buffer> specific i.e. it is global " if a:1==2 then the mapping is not <buffer> specific i.e. it is global
function! vimwiki#u#map_key(mode, key, plug, ...) abort
if a:0 && a:1 == 2 if a:0 && a:1 == 2
" global mappings " global mappings
if !hasmapto(a:plug, a:mode) && maparg(a:key, a:mode) ==# '' if !hasmapto(a:plug, a:mode) && maparg(a:key, a:mode) ==# ''
@@ -227,11 +228,11 @@ function! vimwiki#u#map_key(mode, key, plug, ...) abort
endfunction endfunction
function! vimwiki#u#is_codeblock(lnum) abort
" Returns: 1 if line is a code block or math block " Returns: 1 if line is a code block or math block
" "
" The last two conditions are needed for this to correctly " The last two conditions are needed for this to correctly
" detect nested syntaxes within code blocks " detect nested syntaxes within code blocks
function! vimwiki#u#is_codeblock(lnum) abort
let syn_g = synIDattr(synID(a:lnum,1,1),'name') let syn_g = synIDattr(synID(a:lnum,1,1),'name')
if syn_g =~# 'Vimwiki\(Pre.*\|IndentedCodeBlock\|Math.*\)' if syn_g =~# 'Vimwiki\(Pre.*\|IndentedCodeBlock\|Math.*\)'
\ || (syn_g !~# 'Vimwiki.*' && syn_g !=? '') \ || (syn_g !~# 'Vimwiki.*' && syn_g !=? '')
@@ -241,10 +242,10 @@ function! vimwiki#u#is_codeblock(lnum) abort
endif endif
endfunction endfunction
function! vimwiki#u#ft_set() abort
" Sets the filetype to vimwiki " Sets the filetype to vimwiki
" If g:vimwiki_filetypes variable is set " If g:vimwiki_filetypes variable is set
" the filetype will be vimwiki.<ft1>.<ft2> etc. " the filetype will be vimwiki.<ft1>.<ft2> etc.
function! vimwiki#u#ft_set() abort
let ftypelist = vimwiki#vars#get_global('filetypes') let ftypelist = vimwiki#vars#get_global('filetypes')
let ftype = 'vimwiki' let ftype = 'vimwiki'
for ftypeadd in ftypelist for ftypeadd in ftypelist
@@ -253,11 +254,11 @@ function! vimwiki#u#ft_set() abort
let &filetype = ftype let &filetype = ftype
endfunction endfunction
function! vimwiki#u#ft_is_vw() abort
" Returns: 1 if filetype is vimwiki, 0 else " Returns: 1 if filetype is vimwiki, 0 else
" If multiple fileytpes are in use 1 is returned only if the " If multiple fileytpes are in use 1 is returned only if the
" first ft is vimwiki which should always be the case unless " first ft is vimwiki which should always be the case unless
" the user manually changes it to something else " the user manually changes it to something else
function! vimwiki#u#ft_is_vw() abort
" Clause: is filetype defined " Clause: is filetype defined
if &filetype ==# '' | return 0 | endif if &filetype ==# '' | return 0 | endif
if split(&filetype, '\.')[0] ==? 'vimwiki' if split(&filetype, '\.')[0] ==? 'vimwiki'
@@ -268,17 +269,17 @@ function! vimwiki#u#ft_is_vw() abort
endfunction endfunction
function! vimwiki#u#get_syntax_dic(...) abort
" Helper: Getter " Helper: Getter
" :param: syntax <string> to retrive, default to current " :param: syntax <string> to retrive, default to current
function! vimwiki#u#get_syntax_dic(...) abort
let syntax = a:0 ? a:1 : vimwiki#vars#get_wikilocal('syntax') let syntax = a:0 ? a:1 : vimwiki#vars#get_wikilocal('syntax')
return g:vimwiki_syntaxlocal_vars[syntax] return g:vimwiki_syntaxlocal_vars[syntax]
endfunction endfunction
" Helper to mutualize
" Called: normalize and unnormalize anchor
function! vimwiki#u#get_punctuation_regex() abort function! vimwiki#u#get_punctuation_regex() abort
" Helper: to mutualize
" Called: normalize and unnormalize anchor
" From: https://gist.github.com/asabaylus/3071099#gistcomment-2563127 " From: https://gist.github.com/asabaylus/3071099#gistcomment-2563127
" Faster " Faster
" Unused now " Unused now
@@ -291,19 +292,19 @@ function! vimwiki#u#get_punctuation_regex() abort
endfunction endfunction
" Faster
function! vimwiki#u#get_punctuation_string() abort function! vimwiki#u#get_punctuation_string() abort
" Faster
" See: https://github.github.com/gfm/#ascii-punctuation-character " See: https://github.github.com/gfm/#ascii-punctuation-character
return '!"#$%&''()*+,-./:;<=>?@\[\\\]^`{}|~' return '!"#$%&''()*+,-./:;<=>?@\[\\\]^`{}|~'
endfunction endfunction
function! vimwiki#u#hi_expand_regex(lst) abort
" Helper: Expand regex from reduced typeface delimiters " Helper: Expand regex from reduced typeface delimiters
" :param: list<list,delimiters>> with reduced regex " :param: list<list,delimiters>> with reduced regex
" Return: list with extended regex delimiters (not inside a word) " Return: list with extended regex delimiters (not inside a word)
" -- [['\*_', '_\*']] -> [['\*_\S\@=', '\S\@<=_\*\%(\s\|$\)\@=']] " -- [['\*_', '_\*']] -> [['\*_\S\@=', '\S\@<=_\*\%(\s\|$\)\@=']]
" See: https://github.github.com/gfm/#left-flanking-delimiter-run " See: https://github.github.com/gfm/#left-flanking-delimiter-run
function! vimwiki#u#hi_expand_regex(lst) abort
let res = [] let res = []
let p = vimwiki#u#get_punctuation_string() let p = vimwiki#u#get_punctuation_string()
for delimiters in a:lst for delimiters in a:lst
@@ -315,13 +316,13 @@ function! vimwiki#u#hi_expand_regex(lst) abort
endfunction endfunction
function! vimwiki#u#hi_tag(tag_pre, tag_post, syntax_group, contains, ...) abort
" Helper: Create highlight region between two tags " Helper: Create highlight region between two tags
" :param: tag <string> example '<b>' " :param: tag <string> example '<b>'
" :param: syntax_group <string> example: VimwikiBold " :param: syntax_group <string> example: VimwikiBold
" :param: contains <string> coma separated and prefixed, default VimwikiHTMLTag " :param: contains <string> coma separated and prefixed, default VimwikiHTMLTag
" :param: (1) <boolean> is contained " :param: (1) <boolean> is contained
" :param: (2) <string> more param ex:oneline " :param: (2) <string> more param ex:oneline
function! vimwiki#u#hi_tag(tag_pre, tag_post, syntax_group, contains, ...) abort
let opt_is_contained = a:0 > 0 && a:1 > 0 ? 'contained ' : '' let opt_is_contained = a:0 > 0 && a:1 > 0 ? 'contained ' : ''
let opt_more = a:0 > 1 ? ' ' . a:2 : '' let opt_more = a:0 > 1 ? ' ' . a:2 : ''
let opt_contains = '' let opt_contains = ''
@@ -340,11 +341,11 @@ function! vimwiki#u#hi_tag(tag_pre, tag_post, syntax_group, contains, ...) abort
endfunction endfunction
function! vimwiki#u#hi_typeface(dic) abort
" Highight typeface: see $VIMRUNTIME/syntax/html.vim " Highight typeface: see $VIMRUNTIME/syntax/html.vim
" -- Basically allow nesting with multiple definition contained " -- Basically allow nesting with multiple definition contained
" :param: dic <dic:list:list> must contain: bold, italic and underline, even if underline is often void, " :param: dic <dic:list:list> must contain: bold, italic and underline, even if underline is often void,
" -- see here for underline not defined: https://stackoverflow.com/questions/3003476 " -- see here for underline not defined: https://stackoverflow.com/questions/3003476
function! vimwiki#u#hi_typeface(dic) abort
" Italic must go before, otherwise single * takes precedence over ** and ** is considered as " Italic must go before, otherwise single * takes precedence over ** and ** is considered as
" -- a void italic. " -- a void italic.
" Note: " Note:
+31 -35
View File
@@ -3,8 +3,6 @@
" Description: Vimwiki variable definition and manipulation " Description: Vimwiki variable definition and manipulation
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" ------------------------------------------------------------------------------------------------ " ------------------------------------------------------------------------------------------------
" This file provides functions to manage the various state variables which are needed during a " This file provides functions to manage the various state variables which are needed during a
" Vimwiki session. " Vimwiki session.
@@ -30,8 +28,8 @@
let s:margin_set_by_user = 0 let s:margin_set_by_user = 0
" Init global and local variables
function! vimwiki#vars#init() abort function! vimwiki#vars#init() abort
" Init global and local variables
" Init && Populate: global variable container " Init && Populate: global variable container
let g:vimwiki_global_vars = {} let g:vimwiki_global_vars = {}
call s:populate_global_variables() call s:populate_global_variables()
@@ -42,13 +40,13 @@ function! vimwiki#vars#init() abort
endfunction endfunction
function! s:check_users_value(key, users_value, value_infos, comes_from_global_variable) abort
" Helper: Check user setting " Helper: Check user setting
" warn user with message if not good type " warn user with message if not good type
" Param: 1: key <string>: varaible name " Param: 1: key <string>: varaible name
" Param: 2: vimwiki_key <obj>: user value " Param: 2: vimwiki_key <obj>: user value
" Param: 3: value_infod <dict>: type and default value " Param: 3: value_infod <dict>: type and default value
" Param: 4: coming from a global variable <bool> " Param: 4: coming from a global variable <bool>
function! s:check_users_value(key, users_value, value_infos, comes_from_global_variable) abort
let type_code_to_name = { let type_code_to_name = {
\ type(0): 'number', \ type(0): 'number',
\ type(''): 'string', \ type(''): 'string',
@@ -106,8 +104,8 @@ function! s:check_users_value(key, users_value, value_infos, comes_from_global_v
endfunction endfunction
" Helper: Treat special variables
function! s:update_key(output_dic, key, old, new) abort function! s:update_key(output_dic, key, old, new) abort
" Helper: Treat special variables
" Set list margin " Set list margin
if a:key ==# 'list_margin' if a:key ==# 'list_margin'
let s:margin_set_by_user = 1 let s:margin_set_by_user = 1
@@ -125,15 +123,13 @@ function! s:update_key(output_dic, key, old, new) abort
endif endif
endfunction endfunction
" ---------------------------------------------------------- " ----------------------------------------------------------
" 1. Global {{{1 " 1. Global {{{1
" ---------------------------------------------------------- " ----------------------------------------------------------
function! s:get_default_global() abort
" Get default wikilocal values " Get default wikilocal values
" Please: keep alphabetical sort " Please: keep alphabetical sort
function! s:get_default_global() abort
return { return {
\ 'CJK_length': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, \ 'CJK_length': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_chdir': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, \ 'auto_chdir': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
@@ -192,17 +188,17 @@ function! s:get_default_global() abort
endfunction endfunction
function! s:populate_global_variables() abort
" Populate global variable <- user & default " Populate global variable <- user & default
" Called: s:vimwiki#vars#init " Called: s:vimwiki#vars#init
function! s:populate_global_variables() abort
call s:read_global_settings_from_user() call s:read_global_settings_from_user()
call s:normalize_global_settings() call s:normalize_global_settings()
call s:internal_global_settings() call s:internal_global_settings()
endfunction endfunction
" Read nromalized settings and create some more usefull variables to use internally
function! s:internal_global_settings() abort function! s:internal_global_settings() abort
" Read nromalized settings and create some more usefull variables to use internally
" non-configurable global variables: " non-configurable global variables:
" Scheme regexes must be defined even if syntax file is not loaded yet cause users should be " Scheme regexes must be defined even if syntax file is not loaded yet cause users should be
@@ -308,8 +304,8 @@ function! s:internal_global_settings() abort
endfunction endfunction
" Extend global dictionary <- default <- user
function! s:extend_global(output_dic, default_dic) abort function! s:extend_global(output_dic, default_dic) abort
" Extend global dictionary <- default <- user
" Note: user_dic is unused here because it comes from g:vimwiki_* vars " Note: user_dic is unused here because it comes from g:vimwiki_* vars
" Copy the user's settings from variables of the form g:vimwiki_<option> into the dict " Copy the user's settings from variables of the form g:vimwiki_<option> into the dict
" g:vimwiki_global_vars (or set a default value) " g:vimwiki_global_vars (or set a default value)
@@ -331,9 +327,9 @@ function! s:extend_global(output_dic, default_dic) abort
endfunction endfunction
function! s:read_global_settings_from_user() abort
" Read user global settings " Read user global settings
" Called: s:populate_global_variables " Called: s:populate_global_variables
function! s:read_global_settings_from_user() abort
let default_dic = s:get_default_global() let default_dic = s:get_default_global()
" Update batch " Update batch
@@ -363,9 +359,9 @@ function! s:read_global_settings_from_user() abort
endfunction endfunction
function! s:normalize_global_settings() abort
" Normalize user global settings " Normalize user global settings
" Called: s:populate_global_variables " Called: s:populate_global_variables
function! s:normalize_global_settings() abort
let keys = keys(g:vimwiki_global_vars.ext2syntax) let keys = keys(g:vimwiki_global_vars.ext2syntax)
for ext in keys for ext in keys
" for convenience, we also allow the term 'mediawiki' " for convenience, we also allow the term 'mediawiki'
@@ -450,9 +446,9 @@ endfunction
" 3. Wiki local {{{1 " 3. Wiki local {{{1
" ---------------------------------------------------------- " ----------------------------------------------------------
function! s:get_default_wikilocal() abort
" Get default wikilocal values " Get default wikilocal values
" Please: keep alphabetical sort " Please: keep alphabetical sort
function! s:get_default_wikilocal() abort
" Build color_tag_template regular expression " Build color_tag_template regular expression
" Must be coherent with VimwikiColorize " Must be coherent with VimwikiColorize
let fg = 'color\s*:\s*__COLORFG__\s*;\s*' let fg = 'color\s*:\s*__COLORFG__\s*;\s*'
@@ -539,8 +535,8 @@ function! s:get_default_wikilocal() abort
\ } \ }
endfunction endfunction
" Extend syntaxlocal dictionary <- global <- user (default for type check)
function! s:extend_local(output_dic, default_dic, global_dic, user_dic) abort function! s:extend_local(output_dic, default_dic, global_dic, user_dic) abort
" Extend syntaxlocal dictionary <- global <- user (default for type check)
" IDEA: can work lazily and not on all wikis at first call " IDEA: can work lazily and not on all wikis at first call
" IDEA: have a special variable for wikitmp " IDEA: have a special variable for wikitmp
for key in keys(a:default_dic) for key in keys(a:default_dic)
@@ -556,9 +552,9 @@ function! s:extend_local(output_dic, default_dic, global_dic, user_dic) abort
endfunction endfunction
function! s:populate_wikilocal_options() abort
" Populate local variable <- user & default " Populate local variable <- user & default
" Called: s:vimwiki#vars#init " Called: s:vimwiki#vars#init
function! s:populate_wikilocal_options() abort
" Retrieve default " Retrieve default
let default_dic = s:get_default_wikilocal() let default_dic = s:get_default_wikilocal()
@@ -589,8 +585,8 @@ function! s:populate_wikilocal_options() abort
endfunction endfunction
" Normalize local settings
function! s:normalize_wikilocal_settings() abort function! s:normalize_wikilocal_settings() abort
" Normalize local settings
for wiki_settings in g:vimwiki_wikilocal_vars for wiki_settings in g:vimwiki_wikilocal_vars
" Check some values individually " Check some values individually
"""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""
@@ -644,9 +640,9 @@ function! s:normalize_wikilocal_settings() abort
endfunction endfunction
function! s:normalize_path(path) abort
" Helper path " Helper path
" TODO move to path: Conflict with: vimwiki#path#path_norm && vimwiki#path#normalize " TODO move to path: Conflict with: vimwiki#path#path_norm && vimwiki#path#normalize
function! s:normalize_path(path) abort
" trim trailing / and \ because otherwise resolve() doesn't work quite right " trim trailing / and \ because otherwise resolve() doesn't work quite right
let path = substitute(a:path, '[/\\]\+$', '', '') let path = substitute(a:path, '[/\\]\+$', '', '')
if path !~# '^scp:' if path !~# '^scp:'
@@ -661,8 +657,8 @@ endfunction
" 2. Syntax specific {{{1 " 2. Syntax specific {{{1
" ---------------------------------------------------------- " ----------------------------------------------------------
" Get default syntaxlocal variable dictionary
function! s:get_default_syntaxlocal() abort function! s:get_default_syntaxlocal() abort
" Get default syntaxlocal variable dictionary
" type, default, min, max, possible_values, min_length " type, default, min, max, possible_values, min_length
return extend(s:get_common_syntaxlocal(), { return extend(s:get_common_syntaxlocal(), {
\ 'bold_match': {'type': type(''), 'default': '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='}, \ 'bold_match': {'type': type(''), 'default': '\%(^\|\s\|[[:punct:]]\)\@<=\*__Text__\*\%([[:punct:]]\|\s\|$\)\@='},
@@ -814,9 +810,9 @@ function! s:get_common_syntaxlocal() abort
endfunction endfunction
function! vimwiki#vars#populate_syntax_vars(syntax) abort
" Populate syntax variable " Populate syntax variable
" Exported: syntax/vimwiki.vim " Exported: syntax/vimwiki.vim
function! vimwiki#vars#populate_syntax_vars(syntax) abort
" TODO refactor <= too big function " TODO refactor <= too big function
" TODO permit user conf in some var like g:vimwiki_syntaxlocal_vars " TODO permit user conf in some var like g:vimwiki_syntaxlocal_vars
" TODO internalize match and search (header and bold) " TODO internalize match and search (header and bold)
@@ -1036,10 +1032,10 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort
endfunction endfunction
function! s:populate_list_vars(wiki) abort
" Populate list variable " Populate list variable
" or how to search and treat list (ex: *,-, 1.) " or how to search and treat list (ex: *,-, 1.)
" TODO this should be syntax_local " TODO this should be syntax_local
function! s:populate_list_vars(wiki) abort
let syntax = a:wiki.syntax let syntax = a:wiki.syntax
let a:wiki.rx_bullet_char = '['.escape(join(a:wiki.bullet_types, ''), ']^-\').']' let a:wiki.rx_bullet_char = '['.escape(join(a:wiki.bullet_types, ''), ']^-\').']'
@@ -1097,8 +1093,8 @@ function! s:populate_list_vars(wiki) abort
endfunction endfunction
" Populate markdown specific syntax variables
function! s:populate_extra_markdown_vars() abort function! s:populate_extra_markdown_vars() abort
" Populate markdown specific syntax variables
let mkd_syntax = g:vimwiki_syntaxlocal_vars['markdown'] let mkd_syntax = g:vimwiki_syntaxlocal_vars['markdown']
" 0a) match [[URL|DESCRIPTION]] " 0a) match [[URL|DESCRIPTION]]
@@ -1269,10 +1265,10 @@ function! s:populate_extra_markdown_vars() abort
endfunction endfunction
function! s:normalize_syntax_settings(syntax) abort
" Normalize syntax setting " Normalize syntax setting
" so that we dont have to branch for the syntax at each operation " so that we dont have to branch for the syntax at each operation
" Called: populate_syntax_vars " Called: populate_syntax_vars
function! s:normalize_syntax_settings(syntax) abort
let syntax_dic = g:vimwiki_syntaxlocal_vars[a:syntax] let syntax_dic = g:vimwiki_syntaxlocal_vars[a:syntax]
" Link1: used when: " Link1: used when:
@@ -1291,12 +1287,12 @@ endfunction
" ---------------------------------------------------------- " ----------------------------------------------------------
function! s:get_anywhere(key, ...) abort
" Get variable anywhere " Get variable anywhere
" Returns: [value, location] where loc=global|wikilocal|syntaxlocal|bufferlocal|none " Returns: [value, location] where loc=global|wikilocal|syntaxlocal|bufferlocal|none
" Called: cmd <- VimwikiVar " Called: cmd <- VimwikiVar
" TODO get more performant approach when this file has been well refactored: " TODO get more performant approach when this file has been well refactored:
" -- calls only the necessary functions and not syntaxlocal anytime " -- calls only the necessary functions and not syntaxlocal anytime
function! s:get_anywhere(key, ...) abort
" Alias common info " Alias common info
let s:syntax = vimwiki#vars#get_wikilocal('syntax') let s:syntax = vimwiki#vars#get_wikilocal('syntax')
let s:wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr') let s:wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
@@ -1392,11 +1388,11 @@ function! s:get_anywhere(key, ...) abort
endfunction endfunction
function! vimwiki#vars#cmd(arg) abort
" Set or Get a vimwiki variable " Set or Get a vimwiki variable
" :param: (1) key <string> [space] value <string> " :param: (1) key <string> [space] value <string>
" -- name of the variable [space] value to evaluate and set the variable " -- name of the variable [space] value to evaluate and set the variable
" Called: VimwikiVar " Called: VimwikiVar
function! vimwiki#vars#cmd(arg) abort
" Get key and value " Get key and value
let sep1 = stridx(a:arg, ' ') let sep1 = stridx(a:arg, ' ')
let sep2 = sep1 let sep2 = sep1
@@ -1528,10 +1524,10 @@ endfunction
" 4. Getter, Setter (exported) {{{1 " 4. Getter, Setter (exported) {{{1
" ---------------------------------------------------------- " ----------------------------------------------------------
function! vimwiki#vars#get_syntaxlocal(key, ...) abort
" Get syntax variable " Get syntax variable
" Param: 1: key (<string>) " Param: 1: key (<string>)
" Param: (2): syntax name (<string> ex:'markdown') " Param: (2): syntax name (<string> ex:'markdown')
function! vimwiki#vars#get_syntaxlocal(key, ...) abort
" Retrieve desired syntax name " Retrieve desired syntax name
if a:0 if a:0
let syntax = a:1 let syntax = a:1
@@ -1549,10 +1545,10 @@ function! vimwiki#vars#get_syntaxlocal(key, ...) abort
endfunction endfunction
function! vimwiki#vars#get_bufferlocal(key, ...) abort
" Return: buffer local variable " Return: buffer local variable
" for the buffer we are currently in or for the given buffer (number or name). " for the buffer we are currently in or for the given buffer (number or name).
" Populate the variable, if it doesn't exist. " Populate the variable, if it doesn't exist.
function! vimwiki#vars#get_bufferlocal(key, ...) abort
let buffer = a:0 ? a:1 : '%' let buffer = a:0 ? a:1 : '%'
" 'get(getbufvar(...' handles vim < v7.3.831 that didn't allow a default value for getbufvar " 'get(getbufvar(...' handles vim < v7.3.831 that didn't allow a default value for getbufvar
@@ -1584,31 +1580,31 @@ function! vimwiki#vars#get_bufferlocal(key, ...) abort
endfunction endfunction
" Set buffer local variable
function! vimwiki#vars#set_bufferlocal(key, value, ...) abort function! vimwiki#vars#set_bufferlocal(key, value, ...) abort
" Set buffer local variable
let buffer = a:0 ? a:1 : '%' let buffer = a:0 ? a:1 : '%'
call setbufvar(buffer, 'vimwiki_' . a:key, a:value) call setbufvar(buffer, 'vimwiki_' . a:key, a:value)
endfunction endfunction
" Return: wiki global variable
function! vimwiki#vars#get_global(key) abort function! vimwiki#vars#get_global(key) abort
" Return: wiki global variable
return g:vimwiki_global_vars[a:key] return g:vimwiki_global_vars[a:key]
endfunction endfunction
" Set global variable
function! vimwiki#vars#set_global(key, value) abort function! vimwiki#vars#set_global(key, value) abort
" Set global variable
let g:vimwiki_global_vars[a:key] = a:value let g:vimwiki_global_vars[a:key] = a:value
return g:vimwiki_global_vars[a:key] return g:vimwiki_global_vars[a:key]
endfunction endfunction
function! vimwiki#vars#get_wikilocal(key, ...) abort
" Return: wiki local named variable " Return: wiki local named variable
" Param: (1): variable name (alias key, <string>) " Param: (1): variable name (alias key, <string>)
" Param: (2): wiki number (<int>). When absent, the wiki of the currently active buffer is " Param: (2): wiki number (<int>). When absent, the wiki of the currently active buffer is
" used " used
function! vimwiki#vars#get_wikilocal(key, ...) abort
if a:0 if a:0
return g:vimwiki_wikilocal_vars[a:1][a:key] return g:vimwiki_wikilocal_vars[a:1][a:key]
else else
@@ -1617,16 +1613,16 @@ function! vimwiki#vars#get_wikilocal(key, ...) abort
endfunction endfunction
" Return: wiki local variable (of default wiki [index -1])
function! vimwiki#vars#get_wikilocal_default(key) abort function! vimwiki#vars#get_wikilocal_default(key) abort
" Return: wiki local variable (of default wiki [index -1])
return g:vimwiki_wikilocal_vars[-1][a:key] return g:vimwiki_wikilocal_vars[-1][a:key]
endfunction endfunction
function! vimwiki#vars#set_wikilocal(key, value, ...) abort
" Set local variable " Set local variable
" Param: (2): wiki number (<int>). When absent, the wiki of the currently active buffer is " Param: (2): wiki number (<int>). When absent, the wiki of the currently active buffer is
" used " used
function! vimwiki#vars#set_wikilocal(key, value, ...) abort
if a:0 if a:0
let wiki_nr = a:1 let wiki_nr = a:1
else else
@@ -1639,8 +1635,8 @@ function! vimwiki#vars#set_wikilocal(key, value, ...) abort
endfunction endfunction
" Append new wiki to wiki list
function! vimwiki#vars#add_temporary_wiki(settings) abort function! vimwiki#vars#add_temporary_wiki(settings) abort
" Append new wiki to wiki list
let new_temp_wiki_settings = copy(g:vimwiki_wikilocal_vars[-1]) let new_temp_wiki_settings = copy(g:vimwiki_wikilocal_vars[-1])
for [key, value] in items(a:settings) for [key, value] in items(a:settings)
let new_temp_wiki_settings[key] = value let new_temp_wiki_settings[key] = value
@@ -1652,7 +1648,7 @@ function! vimwiki#vars#add_temporary_wiki(settings) abort
endfunction endfunction
" Return: number of registered wikis + temporary
function! vimwiki#vars#number_of_wikis() abort function! vimwiki#vars#number_of_wikis() abort
" Return: number of registered wikis + temporary
return len(g:vimwiki_wikilocal_vars) - 1 return len(g:vimwiki_wikilocal_vars) - 1
endfunction endfunction
+15
View File
@@ -4,6 +4,7 @@ This file is meant to document design decisions and algorithms inside Vimwiki
which are too large for code comments, and not necessarily interesting to which are too large for code comments, and not necessarily interesting to
users. Please create a new section to document each behavior. users. Please create a new section to document each behavior.
## Formatting tables ## Formatting tables
In Vimwiki, formatting tables occurs dynamically, when navigating between cells In Vimwiki, formatting tables occurs dynamically, when navigating between cells
@@ -235,4 +236,18 @@ reasons for such a complex system is:
holes" holes"
## Syntax and Highlight
* [Vimwiki syntax specification](./specification.wiki)
* [Syntax region](../syntax/vimwiki.vim)
TODO currently the typeface delmiters are customized that way:
```vim
" Typeface: -> u.vim
let s:typeface_dic = vimwiki#vars#get_syntaxlocal('typeface')
call vimwiki#u#hi_typeface(s:typeface_dic)
```
<!-- vim: set tw=80: --> <!-- vim: set tw=80: -->
+5 -1
View File
@@ -985,7 +985,11 @@ Vimwiki has evolved its own syntax that closely resembles Google's wiki
markup. This syntax is described in detail below. markup. This syntax is described in detail below.
Vimwiki also supports alternative syntaxes, like Markdown and MediaWiki, to Vimwiki also supports alternative syntaxes, like Markdown and MediaWiki, to
varying degrees; see |vimwiki-option-syntax|. Static elements like headers, varying degrees; see |vimwiki-option-syntax|.
The Markdown specification Vimwiki is trying to stick to can be found at:
https://github.github.com/gfm
Static elements like headers,
quotations, and lists are customized in syntax/vimwiki_xxx.vim, where xxx quotations, and lists are customized in syntax/vimwiki_xxx.vim, where xxx
stands for the chosen syntax. stands for the chosen syntax.
+15 -15
View File
@@ -3,7 +3,7 @@
" Home: https://github.com/vimwiki/vimwiki/ " Home: https://github.com/vimwiki/vimwiki/
" Cause: load only onces per buffer " Clause: load only onces per buffer
if exists('b:did_ftplugin') if exists('b:did_ftplugin')
finish finish
endif endif
@@ -20,7 +20,7 @@ setlocal isfname-=[,]
exe 'setlocal tags+=' . escape(vimwiki#tags#metadata_file_path(), ' \|"') exe 'setlocal tags+=' . escape(vimwiki#tags#metadata_file_path(), ' \|"')
" Help for omnicompletion " Helper: for omnicompletion
function! Complete_wikifiles(findstart, base) abort function! Complete_wikifiles(findstart, base) abort
" s:line_context = link | tag | '' " s:line_context = link | tag | ''
if a:findstart == 1 if a:findstart == 1
@@ -121,7 +121,7 @@ function! Complete_wikifiles(findstart, base) abort
endif endif
endfunction endfunction
" Set completion " Set Completion:
setlocal omnifunc=Complete_wikifiles setlocal omnifunc=Complete_wikifiles
if and(vimwiki#vars#get_global('emoji_enable'), 2) != 0 if and(vimwiki#vars#get_global('emoji_enable'), 2) != 0
\ && &completefunc ==# '' \ && &completefunc ==# ''
@@ -129,13 +129,13 @@ if and(vimwiki#vars#get_global('emoji_enable'), 2) != 0
endif endif
" Declare settings necessary for the automatic formatting of lists " Declare Settings: necessary for the automatic formatting of lists
" ------------------------------------------------ " ------------------------------------------------
setlocal autoindent setlocal autoindent
setlocal nosmartindent setlocal nosmartindent
setlocal nocindent setlocal nocindent
" Set comments: to insert and format 'comments' or cheat " Set Comments: to insert and format 'comments' or cheat
" Used to break blockquote prepending one on each new line (see: #915) " Used to break blockquote prepending one on each new line (see: #915)
" B like blank character follow " B like blank character follow
" blockquotes " blockquotes
@@ -151,7 +151,7 @@ for bullet in vimwiki#vars#get_syntaxlocal('bullet_types')
endfor endfor
let &l:comments = comments let &l:comments = comments
" Set format options (:h fo-table) " Set Format Options: (:h fo-table)
" Disable autocomment because, vimwiki does it better " Disable autocomment because, vimwiki does it better
setlocal formatoptions-=r setlocal formatoptions-=r
setlocal formatoptions-=o setlocal formatoptions-=o
@@ -200,7 +200,7 @@ function! VimwikiFoldLevel(lnum) abort
endfunction endfunction
" Declare constants used by VimwikiFoldText " Declare Constants: used by VimwikiFoldText
" use \u2026 and \u21b2 (or \u2424) if enc=utf-8 to save screen space " use \u2026 and \u21b2 (or \u2424) if enc=utf-8 to save screen space
let s:ellipsis = (&encoding ==? 'utf-8') ? "\u2026" : '...' let s:ellipsis = (&encoding ==? 'utf-8') ? "\u2026" : '...'
let s:ell_len = strlen(s:ellipsis) let s:ell_len = strlen(s:ellipsis)
@@ -215,7 +215,7 @@ function! s:shorten_text_simple(text, len) abort
endfunction endfunction
" Shorten text " Shorten Text:
" Called: by VimwikiFoldText " Called: by VimwikiFoldText
" s:shorten_text(text, len) = [string, spare] with "spare" = len-strlen(string) " s:shorten_text(text, len) = [string, spare] with "spare" = len-strlen(string)
" for long enough "text", the string's length is within s:tolerance of "len" " for long enough "text", the string's length is within s:tolerance of "len"
@@ -238,7 +238,7 @@ function! s:shorten_text(text, len) abort
endfunction endfunction
" Fold text chapter " Fold: text chapter
function! VimwikiFoldText() abort function! VimwikiFoldText() abort
let line = getline(v:foldstart) let line = getline(v:foldstart)
let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '') let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '')
@@ -431,7 +431,7 @@ nnoremap <silent><script><buffer> <Plug>VimwikiDiaryNextDay
nnoremap <silent><script><buffer> <Plug>VimwikiDiaryPrevDay nnoremap <silent><script><buffer> <Plug>VimwikiDiaryPrevDay
\ :VimwikiDiaryPrevDay<CR> \ :VimwikiDiaryPrevDay<CR>
" default links key mappings " Declare Map: default links key mappings
if str2nr(vimwiki#vars#get_global('key_mappings').links) if str2nr(vimwiki#vars#get_global('key_mappings').links)
call vimwiki#u#map_key('n', '<CR>', '<Plug>VimwikiFollowLink') call vimwiki#u#map_key('n', '<CR>', '<Plug>VimwikiFollowLink')
call vimwiki#u#map_key('n', '<S-CR>', '<Plug>VimwikiSplitLink') call vimwiki#u#map_key('n', '<S-CR>', '<Plug>VimwikiSplitLink')
@@ -451,7 +451,7 @@ if str2nr(vimwiki#vars#get_global('key_mappings').links)
call vimwiki#u#map_key('n', '<C-Up>', '<Plug>VimwikiDiaryPrevDay') call vimwiki#u#map_key('n', '<C-Up>', '<Plug>VimwikiDiaryPrevDay')
endif endif
" <Plug> lists definitions " Map: <Plug> lists definitions
nnoremap <silent><script><buffer> <Plug>VimwikiNextTask nnoremap <silent><script><buffer> <Plug>VimwikiNextTask
\ :VimwikiNextTask<CR> \ :VimwikiNextTask<CR>
nnoremap <silent><script><buffer> <Plug>VimwikiToggleListItem nnoremap <silent><script><buffer> <Plug>VimwikiToggleListItem
@@ -501,7 +501,7 @@ nnoremap <silent><buffer> <Plug>VimwikiListo
nnoremap <silent><buffer> <Plug>VimwikiListO nnoremap <silent><buffer> <Plug>VimwikiListO
\ :<C-U>call vimwiki#u#count_exe('call vimwiki#lst#kbd_O()')<CR> \ :<C-U>call vimwiki#u#count_exe('call vimwiki#lst#kbd_O()')<CR>
" default lists key mappings " Declare Map: default lists key mappings (again)
if str2nr(vimwiki#vars#get_global('key_mappings').lists) if str2nr(vimwiki#vars#get_global('key_mappings').lists)
call vimwiki#u#map_key('n', 'gnt', '<Plug>VimwikiNextTask') call vimwiki#u#map_key('n', 'gnt', '<Plug>VimwikiNextTask')
call vimwiki#u#map_key('n', '<C-Space>', '<Plug>VimwikiToggleListItem') call vimwiki#u#map_key('n', '<C-Space>', '<Plug>VimwikiToggleListItem')
@@ -673,7 +673,7 @@ onoremap <silent><buffer> <Plug>VimwikiTextObjListSingle
vnoremap <silent><buffer> <Plug>VimwikiTextObjListSingleV vnoremap <silent><buffer> <Plug>VimwikiTextObjListSingleV
\ :<C-U>call vimwiki#lst#TO_list_item(1, 1)<CR> \ :<C-U>call vimwiki#lst#TO_list_item(1, 1)<CR>
" default text object key mappings " Declare Map: default text object key mappings
if str2nr(vimwiki#vars#get_global('key_mappings').text_objs) if str2nr(vimwiki#vars#get_global('key_mappings').text_objs)
call vimwiki#u#map_key('o', 'ah', '<Plug>VimwikiTextObjHeader') call vimwiki#u#map_key('o', 'ah', '<Plug>VimwikiTextObjHeader')
call vimwiki#u#map_key('v', 'ah', '<Plug>VimwikiTextObjHeaderV') call vimwiki#u#map_key('v', 'ah', '<Plug>VimwikiTextObjHeaderV')
@@ -697,7 +697,7 @@ if str2nr(vimwiki#vars#get_global('key_mappings').text_objs)
call vimwiki#u#map_key('v', 'il', '<Plug>VimwikiTextObjListSingleV') call vimwiki#u#map_key('v', 'il', '<Plug>VimwikiTextObjListSingleV')
endif endif
" <Plug> header definitions " Map: <Plug> header definitions
nnoremap <silent><buffer> <Plug>VimwikiAddHeaderLevel nnoremap <silent><buffer> <Plug>VimwikiAddHeaderLevel
\ :<C-U>call vimwiki#base#AddHeaderLevel(v:count)<CR> \ :<C-U>call vimwiki#base#AddHeaderLevel(v:count)<CR>
nnoremap <silent><buffer> <Plug>VimwikiRemoveHeaderLevel nnoremap <silent><buffer> <Plug>VimwikiRemoveHeaderLevel
@@ -713,7 +713,7 @@ nnoremap <silent><buffer> <Plug>VimwikiGoToNextSiblingHeader
nnoremap <silent><buffer> <Plug>VimwikiGoToPrevSiblingHeader nnoremap <silent><buffer> <Plug>VimwikiGoToPrevSiblingHeader
\ :<C-u>call vimwiki#base#goto_sibling(-1)<CR> \ :<C-u>call vimwiki#base#goto_sibling(-1)<CR>
" default header key mappings " Declare Map Header: default header key mappings
if str2nr(vimwiki#vars#get_global('key_mappings').headers) if str2nr(vimwiki#vars#get_global('key_mappings').headers)
call vimwiki#u#map_key('n', '=', '<Plug>VimwikiAddHeaderLevel') call vimwiki#u#map_key('n', '=', '<Plug>VimwikiAddHeaderLevel')
call vimwiki#u#map_key('n', '-', '<Plug>VimwikiRemoveHeaderLevel') call vimwiki#u#map_key('n', '-', '<Plug>VimwikiRemoveHeaderLevel')