Merge pull request #6 from vimwiki/dev

Merge from upstream
This commit is contained in:
Michael F. Schönitzer
2017-11-15 16:35:28 +01:00
committed by GitHub
13 changed files with 210 additions and 78 deletions

View File

@ -8,6 +8,13 @@ if exists("g:loaded_vimwiki_auto") || &cp
endif
let g:loaded_vimwiki_auto = 1
" s:safesubstitute
function! s:safesubstitute(text, search, replace, mode) "{{{
" Substitute regexp but do not interpret replace
let escaped = escape(a:replace, '\&')
return substitute(a:text, a:search, escaped, a:mode)
endfunction " }}}
" s:vimwiki_get_known_syntaxes
function! s:vimwiki_get_known_syntaxes() " {{{
" Getting all syntaxes that different wikis could have
@ -465,7 +472,7 @@ function! vimwiki#base#generate_links() "{{{
let abs_filepath = vimwiki#path#abs_path_of_link(link)
if !s:is_diary_file(abs_filepath)
call add(lines, bullet.
\ substitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', '\='."'".link."'", ''))
\ s:safesubstitute(g:vimwiki_WikiLinkTemplate1, '__LinkUrl__', link, ''))
endif
endfor
@ -677,13 +684,13 @@ function! s:jump_to_anchor(anchor) "{{{
let segments = split(anchor, '#', 0)
for segment in segments
let anchor_header = substitute(
let anchor_header = s:safesubstitute(
\ g:vimwiki_{VimwikiGet('syntax')}_header_match,
\ '__Header__', "\\='".segment."'", '')
let anchor_bold = substitute(g:vimwiki_{VimwikiGet('syntax')}_bold_match,
\ '__Text__', "\\='".segment."'", '')
let anchor_tag = substitute(g:vimwiki_{VimwikiGet('syntax')}_tag_match,
\ '__Tag__', "\\='".segment."'", '')
\ '__Header__', segment, '')
let anchor_bold = s:safesubstitute(g:vimwiki_{VimwikiGet('syntax')}_bold_match,
\ '__Text__', segment, '')
let anchor_tag = s:safesubstitute(g:vimwiki_{VimwikiGet('syntax')}_tag_match,
\ '__Tag__', segment, '')
if !search(anchor_tag, 'Wc')
\ && !search(anchor_header, 'Wc')
@ -840,7 +847,7 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) "{{{
" then
" [[test*file]]...
" you'll have E77: Too many file names
let fname = escape(a:filename, '% *|#')
let fname = escape(a:filename, '% *|#`')
let dir = fnamemodify(a:filename, ":p:h")
let ok = vimwiki#path#mkdir(dir, 1)
@ -1176,8 +1183,8 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
" write new listing
let new_header = whitespaces_in_first_line
\ . substitute(g:vimwiki_rxH1_Template,
\ '__Header__', '\='."'".a:start_header."'", '')
\ . s:safesubstitute(g:vimwiki_rxH1_Template,
\ '__Header__', a:start_header, '')
call append(start_lnum - 1, new_header)
let start_lnum += 1
let lines_diff += 1 + len(a:strings)
@ -1273,7 +1280,7 @@ function! vimwiki#base#follow_link(split, reuse, move_cursor, ...) "{{{
" remove the extension from the filename if exists, because non-vimwiki
" markdown files usually include the extension in links
let lnk = substitute(lnk, VimwikiGet('ext').'$', '', '')
let lnk = substitute(lnk, '\'.VimwikiGet('ext').'$', '', '')
endif
let current_tab_page = tabpagenr()
@ -1326,7 +1333,13 @@ function! vimwiki#base#goto_index(wnum, ...) "{{{
endif
if a:0
let cmd = 'tabedit'
if a:1 == 1
let cmd = 'tabedit'
elseif a:1 == 2
let cmd = 'split'
elseif a:1 == 3
let cmd = 'vsplit'
endif
else
let cmd = 'edit'
endif
@ -1826,9 +1839,9 @@ function! vimwiki#base#table_of_contents(create)
for [lvl, link, desc] in headers
let esc_link = substitute(link, "'", "''", 'g')
let esc_desc = substitute(desc, "'", "''", 'g')
let link = substitute(g:vimwiki_WikiLinkTemplate2, '__LinkUrl__',
\ '\='."'".'#'.esc_link."'", '')
let link = substitute(link, '__LinkDescription__', '\='."'".esc_desc."'", '')
let link = s:safesubstitute(g:vimwiki_WikiLinkTemplate2, '__LinkUrl__',
\ '#'.esc_link, '')
let link = s:safesubstitute(link, '__LinkDescription__', esc_desc, '')
call add(lines, startindent.repeat(indentstring, lvl-1).bullet.link)
endfor
@ -1849,13 +1862,13 @@ endfunction
function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle) "{{{
let lnk = a:template
if a:rxUrl != ""
let lnk = substitute(lnk, '__LinkUrl__', '\='."'".a:rxUrl."'", 'g')
let lnk = s:safesubstitute(lnk, '__LinkUrl__', a:rxUrl, 'g')
endif
if a:rxDesc != ""
let lnk = substitute(lnk, '__LinkDescription__', '\='."'".a:rxDesc."'", 'g')
let lnk = s:safesubstitute(lnk, '__LinkDescription__', a:rxDesc, 'g')
endif
if a:rxStyle != ""
let lnk = substitute(lnk, '__LinkStyle__', '\='."'".a:rxStyle."'", 'g')
let lnk = s:safesubstitute(lnk, '__LinkStyle__', a:rxStyle, 'g')
endif
return lnk
endfunction " }}}
@ -1894,8 +1907,8 @@ function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) " {{{
if descr == ""
let descr = s:clean_url(url)
endif
let lnk = substitute(template, '__LinkDescription__', '\="'.descr.'"', '')
let lnk = substitute(lnk, '__LinkUrl__', '\="'.url.'"', '')
let lnk = s:safesubstitute(template, '__LinkDescription__', descr, '')
let lnk = s:safesubstitute(lnk, '__LinkUrl__', url, '')
return lnk
endfunction " }}}
@ -1903,7 +1916,7 @@ endfunction " }}}
function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, template) "{{{
let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template)
let style = matchstr(a:str, a:rxStyle)
let lnk = substitute(lnk, '__LinkStyle__', '\="'.style.'"', '')
let lnk = s:safesubstitute(lnk, '__LinkStyle__', style, '')
return lnk
endfunction " }}}
@ -1995,8 +2008,8 @@ function! s:normalize_link_syntax_v() " {{{
if s:is_diary_file(expand("%:p"))
let sub = s:normalize_link_in_diary(@")
else
let sub = substitute(g:vimwiki_WikiLinkTemplate1,
\ '__LinkUrl__', '\=' . "'" . @" . "'", '')
let sub = s:safesubstitute(g:vimwiki_WikiLinkTemplate1,
\ '__LinkUrl__', @", '')
endif
" Put substitution in register " and change text

View File

@ -65,7 +65,7 @@ fun! s:read_captions(files) "{{{
let result = {}
for fl in a:files
" remove paths and extensions
let fl_key = fnamemodify(fl, ':t:r')
let fl_key = substitute(fnamemodify(fl, ':t'), VimwikiGet('ext').'$', '', '')
if filereadable(fl)
for line in readfile(fl, '', s:vimwiki_max_scan_for_caption)
@ -174,10 +174,15 @@ function! vimwiki#diary#make_note(wnum, ...) "{{{
call vimwiki#path#mkdir(VimwikiGet('path', idx).VimwikiGet('diary_rel_path', idx))
if a:0 && a:1 == 1
let cmd = 'tabedit'
else
let cmd = 'edit'
let cmd = 'edit'
if a:0
if a:1 == 1
let cmd = 'tabedit'
elseif a:1 == 2
let cmd = 'split'
elseif a:1 == 3
let cmd = 'vsplit'
endif
endif
if a:0>1
let link = 'diary:'.a:2

View File

@ -876,6 +876,8 @@ function! s:process_tag_list(line, lists) "{{{
let n = len(g:vimwiki_listsyms_list)
if completion == 0
let st_tag = '<li class="done0">'
elseif completion == -1 && chk[1] == g:vimwiki_listsym_rejected
let st_tag = '<li class="rejected">'
elseif completion > 0 && completion < n
let completion = float2nr(round(completion / (n-1.0) * 3.0 + 0.5 ))
let st_tag = '<li class="done'.completion.'">'

View File

@ -693,6 +693,9 @@ function! s:get_rate(item) "{{{
return -1
endif
let state = a:item.cb
if state == g:vimwiki_listsym_rejected
return -1
endif
let n=len(g:vimwiki_listsyms_list)
return index(g:vimwiki_listsyms_list, state) * 100/(n-1)
endfunction "}}}
@ -735,6 +738,8 @@ function! s:rate_to_state(rate) "{{{
let state = g:vimwiki_listsyms_list[n-1]
elseif a:rate == 0
let state = g:vimwiki_listsyms_list[0]
elseif a:rate == -1
let state = g:vimwiki_listsym_rejected
else
let index = float2nr(ceil(a:rate/100.0*(n-2)))
let state = g:vimwiki_listsyms_list[index]
@ -759,8 +764,11 @@ function! s:update_state(item) "{{{
break
endif
if child_item.cb != ''
let count_children_with_cb += 1
let sum_children_rate += s:get_rate(child_item)
let rate = s:get_rate(child_item)
if rate != -1
let count_children_with_cb += 1
let sum_children_rate += rate
endif
endif
let child_item = s:get_next_child_item(a:item, child_item)
endwhile
@ -835,6 +843,46 @@ function! s:change_cb(from_line, to_line, new_rate) "{{{
endfunction "}}}
"Toggles checkbox between two states in the lines of the given range,
"creates chceckboxes if there aren't any.
function! s:toggle_create_cb(from_line, to_line, state1, state2) "{{{
let from_item = s:get_corresponding_item(a:from_line)
if from_item.type == 0
return
endif
if from_item.cb == ''
"if from_line has no CB, make a CB in every selected line
let parent_items_of_lines = []
for cur_ln in range(from_item.lnum, a:to_line)
let cur_item = s:get_item(cur_ln)
let success = s:create_cb(cur_item)
if success
let cur_parent_item = s:get_parent(cur_item)
if index(parent_items_of_lines, cur_parent_item) == -1
call insert(parent_items_of_lines, cur_parent_item)
endif
endif
endfor
for parent_item in parent_items_of_lines
call s:update_state(parent_item)
endfor
else
"if from_line has CB, toggle it and set all siblings to the same new state
let rate_first_line = s:get_rate(from_item)
let new_rate = rate_first_line == a:state1 ? a:state2 : a:state1
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) "{{{
@ -872,41 +920,13 @@ 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) "{{{
let from_item = s:get_corresponding_item(a:from_line)
if from_item.type == 0
return
endif
if from_item.cb == ''
"if from_line has no CB, make a CB in every selected line
let parent_items_of_lines = []
for cur_ln in range(from_item.lnum, a:to_line)
let cur_item = s:get_item(cur_ln)
let success = s:create_cb(cur_item)
if success
let cur_parent_item = s:get_parent(cur_item)
if index(parent_items_of_lines, cur_parent_item) == -1
call insert(parent_items_of_lines, cur_parent_item)
endif
endif
endfor
for parent_item in parent_items_of_lines
call s:update_state(parent_item)
endfor
else
"if from_line has CB, toggle it and set all siblings to the same new state
let rate_first_line = s:get_rate(from_item)
let new_rate = rate_first_line == 100 ? 0 : 100
call s:change_cb(a:from_line, a:to_line, new_rate)
endif
return s:toggle_create_cb(a:from_line, a:to_line, 100, 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) "{{{
return s:toggle_create_cb(a:from_line, a:to_line, -1, 0)
endfunction "}}}
function! vimwiki#lst#remove_cb(first_line, last_line) "{{{
@ -1553,6 +1573,10 @@ function! vimwiki#lst#setup_marker_infos() "{{{
else
"regex that matches nothing
let g:vimwiki_rxListNumber = '$^'
endif
"the user can set the listsyms as string, but vimwiki needs a list
let g:vimwiki_listsyms_list = split(g:vimwiki_listsyms, '\zs')
if match(g:vimwiki_listsyms, g:vimwiki_listsym_rejected) != -1
echomsg "Warning: g:vimwiki_listsyms and g:vimwiki_listsym_rejected overlap"

View File

@ -6,6 +6,13 @@
" MISC helper functions {{{
" s:safesubstitute
function! s:safesubstitute(text, search, replace, mode) "{{{
" Substitute regexp but do not interpret replace
let escaped = escape(a:replace, '\&')
return substitute(a:text, a:search, escaped, a:mode)
endfunction " }}}
" vimwiki#markdown_base#reset_mkd_refs
function! vimwiki#markdown_base#reset_mkd_refs() "{{{
call VimwikiClear('markdown_refs')
@ -139,8 +146,8 @@ function! s:normalize_link_syntax_v() " {{{
try
norm! gvy
let visual_selection = @"
let link = substitute(g:vimwiki_Weblink1Template, '__LinkUrl__', '\='."'".visual_selection."'", '')
let link = substitute(link, '__LinkDescription__', '\='."'".visual_selection."'", '')
let link = Safesubstitute(g:vimwiki_Weblink1Template, '__LinkUrl__', visual_selection, '')
let link = Safesubstitute(link, '__LinkDescription__', visual_selection, '')
call setreg('"', link, 'v')

View File

@ -27,6 +27,13 @@ del {text-decoration: line-through; color: #777777;}
.tag {background-color: #eeeeee; font-family: monospace; padding: 2px;}
/* classes for items of todo lists */
.rejected {
/* list-style: none; */
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAMAAAAMCGV4AAAACXBIWXMAAADFAAAAxQEdzbqoAAAAB3RJTUUH4QgEFhAtuWgv9wAAAPZQTFRFmpqam5iYnJaWnJeXnpSUn5OTopCQpoqKpouLp4iIqIiIrYCAt3V1vW1tv2xsmZmZmpeXnpKS/x4e/x8f/yAg/yIi/yQk/yUl/yYm/ygo/ykp/yws/zAw/zIy/zMz/zQ0/zU1/zY2/zw8/0BA/0ZG/0pK/1FR/1JS/1NT/1RU/1VV/1ZW/1dX/1pa/15e/19f/2Zm/2lp/21t/25u/3R0/3p6/4CA/4GB/4SE/4iI/46O/4+P/52d/6am/6ur/66u/7Oz/7S0/7e3/87O/9fX/9zc/93d/+Dg/+vr/+3t/+/v//Dw//Ly//X1//f3//n5//z8////gzaKowAAAA90Uk5T/Pz8/Pz8/Pz8/Pz8/f39ppQKWQAAAAFiS0dEEnu8bAAAAACuSURBVAhbPY9ZF4FQFEZPSKbIMmWep4gMGTKLkIv6/3/GPbfF97b3w17rA0kQOPgvAeHW6uJ6+5h7HqLdwowgOzejXRXBdx6UdSru216xuOMBHHNU0clTzeSUA6EhF8V8kqroluMiU6HKcuf4phGPr1o2q9kYZWwNq1qfRRmTaXpqsyjj17KkWCxKBUBgXWueHIyiAIg18gsse4KHkLF5IKIY10WQgv7fOy4ST34BRiopZ8WLNrgAAAAASUVORK5CYII=);
background-repeat: no-repeat;
background-position: 0 .2em;
padding-left: 1.5em;
}
.done0 {
/* list-style: none; */
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAA7SURBVCiR7dMxEgAgCANBI3yVRzF5KxNbW6wsuH7LQ2YKQK1mkswBVERYF5Os3UV3gwd/jF2SkXy66gAZkxS6BniubAAAAABJRU5ErkJggg==);