New feature reject a item form todo-list
Based on patches of davidlmontgomery.
This commit is contained in:
parent
976cbbcd23
commit
f888773767
@ -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
|
||||
@ -909,6 +917,46 @@ function! vimwiki#lst#toggle_cb(from_line, to_line) "{{{
|
||||
|
||||
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) "{{{
|
||||
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 == -1 ? 0 : -1
|
||||
|
||||
call s:change_cb(a:from_line, a:to_line, new_rate)
|
||||
|
||||
endif
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#lst#remove_cb(first_line, last_line) "{{{
|
||||
let first_item = s:get_corresponding_item(a:first_line)
|
||||
let last_item = s:get_corresponding_item(a:last_line)
|
||||
@ -1549,6 +1597,10 @@ function! vimwiki#lst#setup_marker_infos() "{{{
|
||||
|
||||
"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"
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#lst#TO_list_item(inner, visual) "{{{
|
||||
|
@ -295,6 +295,7 @@ command! -buffer -range -nargs=1 VimwikiChangeSymbolTo call vimwiki#lst#change_m
|
||||
command! -buffer -range -nargs=1 VimwikiListChangeSymbolI call vimwiki#lst#change_marker(<line1>, <line2>, <f-args>, 'i')
|
||||
command! -buffer -nargs=1 VimwikiChangeSymbolInListTo call vimwiki#lst#change_marker_in_list(<f-args>)
|
||||
command! -buffer -range VimwikiToggleListItem call vimwiki#lst#toggle_cb(<line1>, <line2>)
|
||||
command! -buffer -range VimwikiToggleListItemRejected call vimwiki#lst#toggle_rejected_cb(<line1>, <line2>)
|
||||
command! -buffer -range VimwikiIncrementListItem call vimwiki#lst#increment_cb(<line1>, <line2>)
|
||||
command! -buffer -range VimwikiDecrementListItem call vimwiki#lst#decrement_cb(<line1>, <line2>)
|
||||
command! -buffer -range -nargs=+ VimwikiListChangeLvl call vimwiki#lst#change_level(<line1>, <line2>, <f-args>)
|
||||
|
@ -373,6 +373,7 @@ call s:default('hl_cb_checked', 0)
|
||||
call s:default('list_ignore_newline', 1)
|
||||
call s:default('text_ignore_newline', 1)
|
||||
call s:default('listsyms', ' .oOX')
|
||||
call s:default('listsym_rejected', '-')
|
||||
call s:default('use_calendar', 1)
|
||||
call s:default('table_mappings', 1)
|
||||
call s:default('table_auto_fmt', 1)
|
||||
|
@ -79,7 +79,7 @@ let g:vimwiki_rxListDefine = '::\(\s\|$\)'
|
||||
call vimwiki#lst#setup_marker_infos()
|
||||
|
||||
let g:vimwiki_rxListItemWithoutCB = '^\s*\%(\('.g:vimwiki_rxListBullet.'\)\|\('.g:vimwiki_rxListNumber.'\)\)\s'
|
||||
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.']\)\]\s\)\?'
|
||||
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.g:vimwiki_listsym_rejected.']\)\]\s\)\?'
|
||||
let g:vimwiki_rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)\s\+\['.g:vimwiki_listsyms_list[-1].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
|
||||
|
||||
" Preformatted text
|
||||
|
@ -76,7 +76,7 @@ let g:vimwiki_rxListDefine = '::\%(\s\|$\)'
|
||||
call vimwiki#lst#setup_marker_infos()
|
||||
|
||||
let g:vimwiki_rxListItemWithoutCB = '^\s*\%(\('.g:vimwiki_rxListBullet.'\)\|\('.g:vimwiki_rxListNumber.'\)\)\s'
|
||||
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.']\)\]\s\)\?'
|
||||
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.g:vimwiki_listsym_rejected.']\)\]\s\)\?'
|
||||
let g:vimwiki_rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)\s\+\['.g:vimwiki_listsyms_list[-1].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
|
||||
|
||||
" Preformatted text
|
||||
|
@ -57,7 +57,7 @@ let g:vimwiki_rxListDefine = '^\%(;\|:\)\s'
|
||||
call vimwiki#lst#setup_marker_infos()
|
||||
|
||||
let g:vimwiki_rxListItemWithoutCB = '^\s*\%(\('.g:vimwiki_rxListBullet.'\)\|\('.g:vimwiki_rxListNumber.'\)\)\s'
|
||||
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.']\)\]\s\)\?'
|
||||
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.g:vimwiki_listsyms.g:vimwiki_listsym_rejected.']\)\]\s\)\?'
|
||||
let g:vimwiki_rxListItemAndChildren = '^\('.g:vimwiki_rxListBullet.'\)\s\+\['.g:vimwiki_listsyms_list[-1].'\]\s.*\%(\n\%(\1\%('.g:vimwiki_rxListBullet.'\).*\|^$\|\s.*\)\)*'
|
||||
|
||||
" Preformatted text
|
||||
|
Loading…
Reference in New Issue
Block a user