vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit 29fa4b028b4ee84076ffc88735da1da7eaba026e
parent ffc4e4120813e8000eb51a1852f30421eb31de53
Author: Tinmarino <tinmarino@gmail.com>
Date:   Sun,  3 Jan 2021 20:07:18 -0300

Doc: Indent Docstring inside function

Diffstat:
Mautoload/vimwiki/base.vim | 323++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mautoload/vimwiki/customwiki2html.sh | 17++++++++---------
Mautoload/vimwiki/diary.vim | 52++++++++++++++++++++++++++--------------------------
Mautoload/vimwiki/emoji.vim | 7++++---
Mautoload/vimwiki/html.vim | 4++--
Mautoload/vimwiki/lst.vim | 191++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mautoload/vimwiki/markdown_base.vim | 3+--
Mautoload/vimwiki/path.vim | 48++++++++++++++++++++++++------------------------
Mautoload/vimwiki/tags.vim | 56++++++++++++++++++++++++++++----------------------------
Mautoload/vimwiki/tbl.vim | 13++++++-------
Mautoload/vimwiki/u.vim | 129++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mautoload/vimwiki/vars.vim | 132++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mdoc/design_notes.md | 15+++++++++++++++
Mdoc/vimwiki.txt | 6+++++-
Mftplugin/vimwiki.vim | 30+++++++++++++++---------------
15 files changed, 518 insertions(+), 508 deletions(-)

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