From f88877376732804ad9ed3adcccfb83302c21bd0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=2E=20Sch=C3=B6nitzer?= Date: Sat, 15 Jul 2017 23:35:48 +0200 Subject: [PATCH] New feature reject a item form todo-list Based on patches of davidlmontgomery. --- autoload/vimwiki/lst.vim | 56 +++++++++++++++++++++++++++++++++++-- ftplugin/vimwiki.vim | 1 + plugin/vimwiki.vim | 1 + syntax/vimwiki_default.vim | 2 +- syntax/vimwiki_markdown.vim | 2 +- syntax/vimwiki_media.vim | 2 +- 6 files changed, 59 insertions(+), 5 deletions(-) diff --git a/autoload/vimwiki/lst.vim b/autoload/vimwiki/lst.vim index adaee22..a94373c 100644 --- a/autoload/vimwiki/lst.vim +++ b/autoload/vimwiki/lst.vim @@ -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) "{{{ diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index a2d6d3e..f2ad61f 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -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(, , , 'i') command! -buffer -nargs=1 VimwikiChangeSymbolInListTo call vimwiki#lst#change_marker_in_list() command! -buffer -range VimwikiToggleListItem call vimwiki#lst#toggle_cb(, ) +command! -buffer -range VimwikiToggleListItemRejected call vimwiki#lst#toggle_rejected_cb(, ) command! -buffer -range VimwikiIncrementListItem call vimwiki#lst#increment_cb(, ) command! -buffer -range VimwikiDecrementListItem call vimwiki#lst#decrement_cb(, ) command! -buffer -range -nargs=+ VimwikiListChangeLvl call vimwiki#lst#change_level(, , ) diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim index e31c734..c7c90a4 100644 --- a/plugin/vimwiki.vim +++ b/plugin/vimwiki.vim @@ -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) diff --git a/syntax/vimwiki_default.vim b/syntax/vimwiki_default.vim index a90ea20..173c54a 100644 --- a/syntax/vimwiki_default.vim +++ b/syntax/vimwiki_default.vim @@ -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 diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim index 3ae9da0..647cad9 100644 --- a/syntax/vimwiki_markdown.vim +++ b/syntax/vimwiki_markdown.vim @@ -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 diff --git a/syntax/vimwiki_media.vim b/syntax/vimwiki_media.vim index a6f8e4a..814d934 100644 --- a/syntax/vimwiki_media.vim +++ b/syntax/vimwiki_media.vim @@ -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