Comment: code and robustify
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Basic functionality
|
||||
" Called by plugin/vimwiki.vim and ftplugin/vimwiki.vim
|
||||
" by global and vimwiki local map and commands
|
||||
" Home: https://github.com/vimwiki/vimwiki/
|
||||
|
||||
" Clause: load only once
|
||||
if exists('g:loaded_vimwiki_auto') || &compatible
|
||||
finish
|
||||
endif
|
||||
@ -12,13 +15,14 @@ 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
|
||||
" Getting all syntaxes that different wikis could have
|
||||
let syntaxes = {}
|
||||
@ -35,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, ...).
|
||||
@ -46,7 +50,8 @@ function! vimwiki#base#file_pattern(files) abort
|
||||
endfunction
|
||||
|
||||
|
||||
"FIXME TODO slow and faulty
|
||||
" TODO move in path
|
||||
" FIXME TODO slow and faulty
|
||||
function! vimwiki#base#subdir(path, filename) abort
|
||||
let path = a:path
|
||||
" ensure that we are not fooled by a symbolic link
|
||||
@ -71,11 +76,13 @@ function! vimwiki#base#subdir(path, filename) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" TODO move in path
|
||||
function! vimwiki#base#current_subdir() abort
|
||||
return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), expand('%:p'))
|
||||
endfunction
|
||||
|
||||
|
||||
" TODO move in path
|
||||
function! vimwiki#base#invsubdir(subdir) abort
|
||||
return substitute(a:subdir, '[^/\.]\+/', '../', 'g')
|
||||
endfunction
|
||||
@ -104,13 +111,14 @@ function! vimwiki#base#find_wiki(path) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" helper: check if a link is a well formed wiki link
|
||||
" Check if a link is a well formed wiki link (Helper)
|
||||
function! s:is_wiki_link(link_infos) abort
|
||||
return a:link_infos.scheme =~# '\mwiki\d\+' || a:link_infos.scheme ==# 'diary'
|
||||
endfunction
|
||||
|
||||
|
||||
" THE central function of Vimwiki. Extract infos about the target from a link.
|
||||
" 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.
|
||||
@ -261,6 +269,7 @@ function! vimwiki#base#resolve_link(link_text, ...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Open Link with OS handler (like gx)
|
||||
function! vimwiki#base#system_open_link(url) abort
|
||||
" handlers
|
||||
function! s:win32_handler(url) abort
|
||||
@ -314,6 +323,7 @@ function! vimwiki#base#system_open_link(url) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Open link with Vim (like :e)
|
||||
function! vimwiki#base#open_link(cmd, link, ...) abort
|
||||
let link_infos = {}
|
||||
if a:0
|
||||
@ -356,6 +366,8 @@ function! vimwiki#base#open_link(cmd, link, ...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Escape global link
|
||||
" Called by command completion
|
||||
function! vimwiki#base#get_globlinks_escaped(...) abort
|
||||
let s_arg_lead = a:0 > 0 ? a:1 : ''
|
||||
" only get links from the current dir
|
||||
@ -381,7 +393,10 @@ function! vimwiki#base#get_globlinks_escaped(...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Optional pattern argument
|
||||
" 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
|
||||
" Get pattern if present
|
||||
" Globlal to script to be passed to closure
|
||||
@ -425,8 +440,8 @@ function! vimwiki#base#generate_links(create, ...) abort
|
||||
return lines
|
||||
endfunction
|
||||
|
||||
" Update buffer with generator super power
|
||||
let links_rx = '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)'
|
||||
|
||||
call vimwiki#base#update_listing_in_buffer(
|
||||
\ GeneratorLinks,
|
||||
\ vimwiki#vars#get_global('links_header'),
|
||||
@ -437,6 +452,8 @@ 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
|
||||
let key = a:0 > 0 ? a:1 : input('Enter name: ')
|
||||
let anchor = a:0 > 1 ? a:2 : ''
|
||||
@ -452,6 +469,8 @@ function! vimwiki#base#goto(...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Jump to previous file (backspace key)
|
||||
" Called: by VimwikiBacklinks (Exported)
|
||||
function! vimwiki#base#backlinks() abort
|
||||
let current_filename = expand('%:p')
|
||||
let locations = []
|
||||
@ -591,24 +610,29 @@ function! vimwiki#base#get_wiki_directories(wiki_nr) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Parse file. Returns list of all anchors
|
||||
function! vimwiki#base#get_anchors(filename, syntax) abort
|
||||
" Clause: if not readable
|
||||
if !filereadable(a:filename)
|
||||
return []
|
||||
endif
|
||||
|
||||
" Get: syntax local variables
|
||||
let rxheader = vimwiki#vars#get_syntaxlocal('header_search', a:syntax)
|
||||
let rxbold = vimwiki#vars#get_syntaxlocal('bold_search', a:syntax)
|
||||
let rxtag = vimwiki#vars#get_syntaxlocal('tag_search', a:syntax)
|
||||
|
||||
" Init:
|
||||
let anchor_level = ['', '', '', '', '', '', '']
|
||||
let anchors = []
|
||||
let current_complete_anchor = ''
|
||||
for line in readfile(a:filename)
|
||||
|
||||
" collect headers
|
||||
for line in readfile(a:filename)
|
||||
" Collect: headers
|
||||
let h_match = matchlist(line, rxheader)
|
||||
if !empty(h_match)
|
||||
let header = vimwiki#u#trim(h_match[2])
|
||||
" Mesure: header level
|
||||
let level = len(h_match[1])
|
||||
call add(anchors, header)
|
||||
let anchor_level[level-1] = header
|
||||
@ -624,12 +648,13 @@ function! vimwiki#base#get_anchors(filename, syntax) abort
|
||||
let current_complete_anchor .= anchor_level[l].'#'
|
||||
endif
|
||||
endfor
|
||||
" TODO: should not that be out of the if branch ?
|
||||
let current_complete_anchor .= header
|
||||
call add(anchors, current_complete_anchor)
|
||||
endif
|
||||
endif
|
||||
|
||||
" collect bold text (there can be several in one line)
|
||||
" Collect: bold text (there can be several in one line)
|
||||
let bold_count = 1
|
||||
while 1
|
||||
let bold_text = matchstr(line, rxbold, 0, bold_count)
|
||||
@ -643,7 +668,7 @@ function! vimwiki#base#get_anchors(filename, syntax) abort
|
||||
let bold_count += 1
|
||||
endwhile
|
||||
|
||||
" collect tags text (there can be several in one line)
|
||||
" Collect: tags text (there can be several in one line)
|
||||
let tag_count = 1
|
||||
while 1
|
||||
let tag_group_text = matchstr(line, rxtag, 0, tag_count)
|
||||
@ -658,13 +683,14 @@ function! vimwiki#base#get_anchors(filename, syntax) abort
|
||||
endfor
|
||||
let tag_count += 1
|
||||
endwhile
|
||||
|
||||
endfor
|
||||
|
||||
return anchors
|
||||
endfunction
|
||||
|
||||
|
||||
" Jump to anchor
|
||||
" Called by edit_file
|
||||
function! s:jump_to_anchor(anchor) abort
|
||||
let oldpos = getpos('.')
|
||||
call cursor(1, 1)
|
||||
@ -674,7 +700,6 @@ function! s:jump_to_anchor(anchor) abort
|
||||
let segments = split(anchor, '#', 0)
|
||||
|
||||
for segment in segments
|
||||
|
||||
let anchor_header = s:safesubstitute(
|
||||
\ vimwiki#vars#get_syntaxlocal('header_match'),
|
||||
\ '__Header__', segment, '')
|
||||
@ -694,8 +719,8 @@ function! s:jump_to_anchor(anchor) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Params: full path to a wiki file and its wiki number
|
||||
" 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
|
||||
@ -735,6 +760,7 @@ function! s:get_links(wikifile, idx) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Check if all wikilinks are reachable. Answer in quickfix
|
||||
function! vimwiki#base#check_links() abort
|
||||
let anchors_of_files = {}
|
||||
let links_of_files = {}
|
||||
@ -748,6 +774,7 @@ function! vimwiki#base#check_links() abort
|
||||
endfor
|
||||
endfor
|
||||
|
||||
" Clean: all links: keep only file links
|
||||
for wikifile in keys(links_of_files)
|
||||
for [target_file, target_anchor, lnum, col] in links_of_files[wikifile]
|
||||
if target_file ==? '' && target_anchor ==? ''
|
||||
@ -776,7 +803,6 @@ function! vimwiki#base#check_links() abort
|
||||
endfor
|
||||
endfor
|
||||
|
||||
|
||||
" Check which wiki files are reachable from at least one of the index files.
|
||||
" First, all index files are marked as reachable. Then, pick a reachable file
|
||||
" and mark all files to which it links as reachable, too. Repeat until the
|
||||
@ -792,7 +818,7 @@ function! vimwiki#base#check_links() abort
|
||||
let reachable_wikifiles[wikifile] = 0
|
||||
endfor
|
||||
|
||||
" mark every index file as reachable
|
||||
" Mark: every index file as reachable
|
||||
for idx in range(vimwiki#vars#number_of_wikis())
|
||||
let index_file = vimwiki#vars#get_wikilocal('path', idx) .
|
||||
\ vimwiki#vars#get_wikilocal('index', idx) . vimwiki#vars#get_wikilocal('ext', idx)
|
||||
@ -801,6 +827,7 @@ function! vimwiki#base#check_links() abort
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Check: if files are reachable (recursively)
|
||||
while 1
|
||||
let next_unvisited_wikifile = ''
|
||||
for wf in keys(reachable_wikifiles)
|
||||
@ -820,12 +847,14 @@ function! vimwiki#base#check_links() abort
|
||||
endfor
|
||||
endwhile
|
||||
|
||||
" Fill: errors
|
||||
for wf in keys(reachable_wikifiles)
|
||||
if reachable_wikifiles[wf] == 0
|
||||
call add(errors, {'text':wf.' is not reachable from the index file'})
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Fill: QuickFix list
|
||||
if empty(errors)
|
||||
echomsg 'Vimwiki: All links are OK'
|
||||
else
|
||||
@ -835,6 +864,7 @@ function! vimwiki#base#check_links() abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Open file (like :e)
|
||||
function! vimwiki#base#edit_file(command, filename, anchor, ...) abort
|
||||
let fname = escape(a:filename, '% *|#`')
|
||||
let dir = fnamemodify(a:filename, ':p:h')
|
||||
@ -888,15 +918,17 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#base#search_word(wikiRx, cmd) abort
|
||||
let match_line = search(a:wikiRx, 's'.a:cmd)
|
||||
" Search for a 1. Pattern (usually a link) with 2. flags
|
||||
" Called by find_prev_link
|
||||
function! vimwiki#base#search_word(wikiRX, flags) abort
|
||||
let match_line = search(a:wikiRX, 's'.a:flags)
|
||||
if match_line == 0
|
||||
echomsg 'Vimwiki: Wiki link not found'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" Returns part of the line that matches wikiRX at cursor
|
||||
" Return: part of the line that matches wikiRX at cursor
|
||||
function! vimwiki#base#matchstr_at_cursor(wikiRX) abort
|
||||
let col = col('.') - 1
|
||||
let line = getline('.')
|
||||
@ -920,11 +952,15 @@ 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
|
||||
" Gather: cursor info
|
||||
let col = col('.') - 1
|
||||
let line = getline('.')
|
||||
let ebeg = -1
|
||||
let cont = match(line, a:wikiRX, 0)
|
||||
|
||||
" Find: link
|
||||
while (ebeg >= 0 || (0 <= cont) && (cont <= col))
|
||||
let contn = matchend(line, a:wikiRX, cont)
|
||||
if (cont <= col) && (col < contn)
|
||||
@ -934,7 +970,9 @@ function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) abort
|
||||
else
|
||||
let cont = match(line, a:wikiRX, contn)
|
||||
endif
|
||||
endwh
|
||||
endwhile
|
||||
|
||||
" Replace: by sub
|
||||
if ebeg >= 0
|
||||
" TODO: There might be problems with Unicode chars...
|
||||
let newline = strpart(line, 0, ebeg).a:sub.strpart(line, ebeg+elen)
|
||||
@ -943,8 +981,10 @@ 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
|
||||
" find the max name length for prettier formatting
|
||||
" Find the max name length for prettier formatting
|
||||
let max_len = 0
|
||||
for idx in range(vimwiki#vars#number_of_wikis())
|
||||
let wname = vimwiki#vars#get_wikilocal('name', idx)
|
||||
@ -953,7 +993,7 @@ function! s:print_wiki_list() abort
|
||||
endif
|
||||
endfor
|
||||
|
||||
" print each wiki, active wiki highlighted and marked with '*'
|
||||
" Print each wiki, active wiki highlighted and marked with '*'
|
||||
for idx in range(vimwiki#vars#number_of_wikis())
|
||||
if idx == vimwiki#vars#get_bufferlocal('wiki_nr')
|
||||
let sep = '*'
|
||||
@ -977,7 +1017,7 @@ function! s:print_wiki_list() abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Update link: in fname.ext
|
||||
" 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
|
||||
@ -1065,6 +1105,8 @@ 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
|
||||
let result = substitute(a:fname, ':', '__colon__', 'g')
|
||||
let result = fnamemodify(result, ':t:r')
|
||||
@ -1073,6 +1115,8 @@ 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
|
||||
let blist = []
|
||||
let bcount = 1
|
||||
@ -1092,6 +1136,8 @@ 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
|
||||
call vimwiki#base#edit_file(':e', a:item[0], '')
|
||||
if !empty(a:item[1])
|
||||
@ -1100,8 +1146,11 @@ 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
|
||||
" From http://vim.wikia.com/wiki/VimTip857
|
||||
" From http://vim.wikia.com/wiki/VimTip857
|
||||
let ft=toupper(a:filetype)
|
||||
let group='textGroup'.ft
|
||||
if exists('b:current_syntax')
|
||||
@ -1164,7 +1213,7 @@ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" creates or updates auto-generated listings in a wiki file, like TOC, diary
|
||||
" 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
|
||||
@ -1172,6 +1221,7 @@ endfunction
|
||||
" 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
|
||||
" Vim behaves strangely when files change while in diff mode
|
||||
@ -1179,7 +1229,7 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header,
|
||||
return
|
||||
endif
|
||||
|
||||
" check if the listing is already there
|
||||
" Check if the listing is already there
|
||||
let already_there = 0
|
||||
|
||||
let header_level = 'rxH' . a:header_level . '_Template'
|
||||
@ -1238,7 +1288,7 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header,
|
||||
|
||||
let start_of_listing = start_lnum
|
||||
|
||||
" write new listing
|
||||
" Write new listing
|
||||
let new_header = whitespaces_in_first_line
|
||||
\ . s:safesubstitute(vimwiki#vars#get_syntaxlocal(header_level),
|
||||
\ '__Header__', a:start_header, '')
|
||||
@ -1258,7 +1308,7 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header,
|
||||
let lines_diff += 1
|
||||
endfor
|
||||
|
||||
" remove empty line if end of file, otherwise append if needed
|
||||
" Remove empty line if end of file, otherwise append if needed
|
||||
if start_lnum == line('$')
|
||||
silent exe 'keepjumps ' . start_lnum.'delete _'
|
||||
elseif start_lnum < line('$') && getline(start_lnum) !~# '\m^\s*$'
|
||||
@ -1278,17 +1328,22 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header,
|
||||
call winrestview(winview_save)
|
||||
endfunction
|
||||
|
||||
|
||||
" Find next task (Exported)
|
||||
function! vimwiki#base#find_next_task() abort
|
||||
let taskRegex = vimwiki#vars#get_syntaxlocal('rxListItemWithoutCB')
|
||||
\ . '\+\(\[ \]\s\+\)\zs'
|
||||
call vimwiki#base#search_word(taskRegex, '')
|
||||
endfunction
|
||||
|
||||
|
||||
" Find next link (Exported)
|
||||
function! vimwiki#base#find_next_link() abort
|
||||
call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), '')
|
||||
endfunction
|
||||
|
||||
|
||||
" Find previous link (Exported)
|
||||
function! vimwiki#base#find_prev_link() abort
|
||||
"Jump 2 times if the cursor is in the middle of a link
|
||||
if synIDattr(synID(line('.'), col('.'), 0), 'name') =~# 'VimwikiLink.*' &&
|
||||
@ -1299,6 +1354,7 @@ function! vimwiki#base#find_prev_link() abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Jump to link target (Enter press, Exported)
|
||||
function! vimwiki#base#follow_link(split, ...) abort
|
||||
let reuse_other_split_window = a:0 >= 1 ? a:1 : 0
|
||||
let move_cursor_to_new_window = a:0 >= 2 ? a:2 : 1
|
||||
@ -1394,8 +1450,9 @@ function! vimwiki#base#follow_link(split, ...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Jump to previous link (Backspace press, Exported)
|
||||
function! vimwiki#base#go_back_link() abort
|
||||
" try pop previous link from buffer list
|
||||
" Try pop previous link from buffer list
|
||||
let prev_links = vimwiki#vars#get_bufferlocal('prev_links')
|
||||
if !empty(prev_links)
|
||||
let prev_link = remove(prev_links, 0)
|
||||
@ -1404,6 +1461,7 @@ function! vimwiki#base#go_back_link() abort
|
||||
let prev_link = []
|
||||
endif
|
||||
|
||||
" Jump to target with edit_file
|
||||
if !empty(prev_link)
|
||||
" go back to saved wiki link
|
||||
call vimwiki#base#edit_file(':e ', prev_link[0], '')
|
||||
@ -1415,8 +1473,8 @@ function! vimwiki#base#go_back_link() abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Goto index file of wiki specified by index
|
||||
function! vimwiki#base#goto_index(wnum, ...) abort
|
||||
|
||||
" if wnum = 0 the current wiki is used
|
||||
if a:wnum == 0
|
||||
let idx = vimwiki#vars#get_bufferlocal('wiki_nr')
|
||||
@ -1452,6 +1510,7 @@ function! vimwiki#base#goto_index(wnum, ...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Delete current wiki file
|
||||
function! vimwiki#base#delete_link() abort
|
||||
" Delete wiki file you are in from filesystem
|
||||
let val = input('Delete "'.expand('%').'" [y]es/[N]o? ')
|
||||
@ -1577,6 +1636,8 @@ 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
|
||||
call s:print_wiki_list()
|
||||
let idx = input('Select Wiki by number and press <Enter> (empty cancels): ')
|
||||
@ -1591,6 +1652,7 @@ 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
|
||||
let headers = s:collect_headers()
|
||||
if empty(headers)
|
||||
@ -1644,6 +1706,7 @@ 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
|
||||
if col('.') == col('$')-1
|
||||
return
|
||||
@ -1709,6 +1772,7 @@ 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
|
||||
let t_rows = vimwiki#tbl#get_rows(line('.'))
|
||||
if empty(t_rows)
|
||||
@ -1824,9 +1888,12 @@ function! vimwiki#base#TO_table_col(inner, visual) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Increase header level (Exported)
|
||||
function! vimwiki#base#AddHeaderLevel(...) abort
|
||||
" Clause, argument must be <= 1
|
||||
" Actually argument is not used :-)
|
||||
if a:1 > 1
|
||||
call vimwiki#base#AddHeaderLevel(a:1 - 1)
|
||||
call vimwiki#base#AddHeaderLevel(1)
|
||||
endif
|
||||
let lnum = line('.')
|
||||
let line = getline(lnum)
|
||||
@ -1855,9 +1922,12 @@ function! vimwiki#base#AddHeaderLevel(...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Decrease header level (Exported)
|
||||
function! vimwiki#base#RemoveHeaderLevel(...) abort
|
||||
" Clause, argument must be <= 1
|
||||
" Actually argument is not used :-)
|
||||
if a:1 > 1
|
||||
call vimwiki#base#RemoveHeaderLevel(a:1 - 1)
|
||||
call vimwiki#base#RemoveHeaderLevel(1)
|
||||
endif
|
||||
let lnum = line('.')
|
||||
let line = getline(lnum)
|
||||
@ -1891,8 +1961,7 @@ function! vimwiki#base#RemoveHeaderLevel(...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
|
||||
" Returns all the headers in the current buffer as a list of the form
|
||||
" Returns: all the headers in the current buffer as a list of the form
|
||||
" [[line_number, header_level, header_text], [...], [...], ...]
|
||||
function! s:collect_headers() abort
|
||||
let is_inside_pre_or_math = 0 " 1: inside pre, 2: inside math, 0: outside
|
||||
@ -1933,6 +2002,8 @@ 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
|
||||
if empty(a:headers)
|
||||
return -1
|
||||
@ -1950,6 +2021,8 @@ function! s:current_header(headers, line_number) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Returns: index of neighbor header
|
||||
" Called: by header cursor movements
|
||||
function! s:get_another_header(headers, current_index, direction, operation) abort
|
||||
if empty(a:headers) || a:current_index < 0
|
||||
return -1
|
||||
@ -1969,6 +2042,7 @@ function! s:get_another_header(headers, current_index, direction, operation) abo
|
||||
endfunction
|
||||
|
||||
|
||||
" Jump to parent header
|
||||
function! vimwiki#base#goto_parent_header() abort
|
||||
let headers = s:collect_headers()
|
||||
let current_header_index = s:current_header(headers, line('.'))
|
||||
@ -1981,6 +2055,7 @@ function! vimwiki#base#goto_parent_header() abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Jump to next header
|
||||
function! vimwiki#base#goto_next_header() abort
|
||||
let headers = s:collect_headers()
|
||||
let current_header_index = s:current_header(headers, line('.'))
|
||||
@ -1994,6 +2069,7 @@ function! vimwiki#base#goto_next_header() abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Jump to previous header
|
||||
function! vimwiki#base#goto_prev_header() abort
|
||||
let headers = s:collect_headers()
|
||||
let current_header_index = s:current_header(headers, line('.'))
|
||||
@ -2009,6 +2085,7 @@ 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
|
||||
let headers = s:collect_headers()
|
||||
let current_header_index = s:current_header(headers, line('.'))
|
||||
@ -2023,6 +2100,7 @@ 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
|
||||
@ -2132,6 +2210,7 @@ function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle, rxExtens
|
||||
endfunction
|
||||
|
||||
|
||||
" Helper: Clean url string
|
||||
function! s:clean_url(url) abort
|
||||
" don't use an extension as part of the description
|
||||
let url = substitute(a:url, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '')
|
||||
@ -2160,6 +2239,8 @@ function! s:clean_url(url) abort
|
||||
return join(url_l, ' ')
|
||||
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
|
||||
@ -2172,6 +2253,7 @@ function! vimwiki#base#is_diary_file(filename, ...) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Treat link string towards normalization
|
||||
function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort
|
||||
let url = matchstr(a:str, a:rxUrl)
|
||||
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' && vimwiki#vars#get_global('markdown_link_ext')
|
||||
@ -2190,6 +2272,7 @@ 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
|
||||
let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template)
|
||||
let style = matchstr(a:str, a:rxStyle)
|
||||
@ -2197,6 +2280,8 @@ function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, t
|
||||
return lnk
|
||||
endfunction
|
||||
|
||||
|
||||
" Normalize link in a diary file
|
||||
function! vimwiki#base#normalize_link_in_diary(lnk) abort
|
||||
let sc = vimwiki#vars#get_wikilocal('links_space_char')
|
||||
let link = a:lnk . vimwiki#vars#get_wikilocal('ext')
|
||||
@ -2233,8 +2318,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
|
||||
|
||||
" try WikiLink
|
||||
let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink'))
|
||||
if !empty(lnk)
|
||||
@ -2276,10 +2361,10 @@ function! s:normalize_link_syntax_n() abort
|
||||
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
|
||||
return
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
|
||||
" Normalize link in visual mode Enter keypress
|
||||
function! s:normalize_link_syntax_v() abort
|
||||
let sel_save = &selection
|
||||
let &selection = 'old'
|
||||
@ -2309,6 +2394,7 @@ function! s:normalize_link_syntax_v() abort
|
||||
endfunction
|
||||
|
||||
|
||||
" Normalize link
|
||||
function! vimwiki#base#normalize_link(is_visual_mode) abort
|
||||
if exists('*vimwiki#'.vimwiki#vars#get_wikilocal('syntax').'_base#normalize_link')
|
||||
" Syntax-specific links
|
||||
@ -2324,6 +2410,8 @@ 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
|
||||
let last_word = '\v.*<(\w+)\s*$'
|
||||
let lines = map(filter(getline(1, '$'), 'v:val =~# "\\%({{{\\|`\\{3,\}\\|\\~\\{3,\}\\)" && v:val =~# last_word'),
|
||||
@ -2336,11 +2424,14 @@ function! vimwiki#base#detect_nested_syntax() abort
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort abort
|
||||
" Complete escaping globlinks
|
||||
function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort
|
||||
return vimwiki#base#get_globlinks_escaped(a:ArgLead)
|
||||
endfunction
|
||||
|
||||
|
||||
" Read caption
|
||||
" Called: by generate_links
|
||||
function! vimwiki#base#read_caption(file) abort
|
||||
let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
|
||||
|
||||
@ -2356,7 +2447,8 @@ function! vimwiki#base#read_caption(file) abort
|
||||
endfunction
|
||||
|
||||
|
||||
" For commands VimwikiSearch and VWS
|
||||
" Search for 1.pattern
|
||||
" Called by commands VimwikiSearch and VWS
|
||||
function! vimwiki#base#search(search_pattern) abort
|
||||
if empty(a:search_pattern)
|
||||
echomsg 'Vimwiki Error: No search pattern given.'
|
||||
@ -2384,6 +2476,8 @@ function! vimwiki#base#search(search_pattern) abort
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
|
||||
" Warn deprecated feature
|
||||
function! vimwiki#base#deprecate(old, new) abort
|
||||
echohl WarningMsg
|
||||
echo a:old 'is deprecated and will be removed in future versions, use' a:new 'instead.'
|
||||
@ -2396,4 +2490,3 @@ for s:syn in s:vimwiki_get_known_syntaxes()
|
||||
execute 'runtime! autoload/vimwiki/'.s:syn.'_base.vim'
|
||||
endfor
|
||||
" -------------------------------------------------------------------------
|
||||
|
||||
|
Reference in New Issue
Block a user