vimwiki

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

commit f60993249a06e01710992934492d4dfea52d6851
parent 3756c6258baf4b089df870ae2c7112915bb09df5
Author: EinfachToll <istjanichtzufassen@googlemail.com>
Date:   Sat, 17 Feb 2018 21:05:06 +0100

Cherry-pick the changes from dev -- part5

Diffstat:
Mautoload/vimwiki/lst.vim | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Mdoc/vimwiki.txt | 15++++++++++++++-
Mftplugin/vimwiki.vim | 19+++++++++++++++++++
3 files changed, 99 insertions(+), 17 deletions(-)

diff --git a/autoload/vimwiki/lst.vim b/autoload/vimwiki/lst.vim @@ -813,9 +813,9 @@ function! s:remove_cb(item) "{{{ return item endfunction "}}} -"Toggles checkbox between [ ] and [X] or creates one +"Change state of checkbox "in the lines of the given range -function! vimwiki#lst#toggle_cb(from_line, to_line) "{{{ +function! s:change_cb(from_line, to_line, new_rate) "{{{ let from_item = s:get_corresponding_item(a:from_line) if from_item.type == 0 return @@ -823,6 +823,65 @@ function! vimwiki#lst#toggle_cb(from_line, to_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) + if cur_item.type != 0 && cur_item.cb != '' + call s:set_state_plus_children(cur_item, a:new_rate) + 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 + +endfunction "}}} + +"Decrement checkbox between [ ] and [X] +"in the lines of the given range +function! vimwiki#lst#decrement_cb(from_line, to_line) "{{{ + let from_item = s:get_corresponding_item(a:from_line) + if from_item.type == 0 + return + endif + + "if from_line has CB, decrement it and set all siblings to the same new state + let rate_first_line = s:get_rate(from_item) + let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list')) + 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) "{{{ + let from_item = s:get_corresponding_item(a:from_line) + if from_item.type == 0 + return + endif + + "if from_line has CB, increment it and set all siblings to the same new state + let rate_first_line = s:get_rate(from_item) + let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list')) + 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) "{{{ + 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 @@ -839,29 +898,20 @@ function! vimwiki#lst#toggle_cb(from_line, to_line) "{{{ 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 - for cur_ln in range(from_item.lnum, a:to_line) - let cur_item = s:get_item(cur_ln) - if cur_item.type != 0 && cur_item.cb != '' - call s:set_state_plus_children(cur_item, new_rate) - 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 + call s:change_cb(a:from_line, a:to_line, new_rate) endif - for parent_item in parent_items_of_lines - call s:update_state(parent_item) - endfor - endfunction "}}} function! vimwiki#lst#remove_cb(first_line, last_line) "{{{ diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt @@ -351,6 +351,16 @@ gL<Space> Remove checkboxes from all sibling list items. :map <Leader><Space> <Plug>VimwikiRemoveSingleCB :map <Leader><Space> <Plug>VimwikiRemoveCBInList < + *vimwiki_gln* *vimwiki_glp* +gln Increase the "done" status of a list checkbox, i.e. + from [ ] to [.] to [o] etc. See |vimwiki-todo-lists|. +glp Decrease the "done" status. + To remap: > + :nmap <M-+> <Plug>VimwikiIncrementListItem + :vmap <M-+> <Plug>VimwikiIncrementListItem + :nmap <M--> <Plug>VimwikiDecrementListItem + :vmap <M--> <Plug>VimwikiDecrementListItem + *vimwiki_gll* *vimwiki_gLl* gll Increase the level of a list item. gLl Increase the level of a list item and all child items. @@ -1542,7 +1552,7 @@ See |vimwiki_glstar|, |vimwiki_gl#| |vimwiki_gl-|, |vimwiki_gl-|, |vimwiki_gl1|, |vimwiki_gla|, |vimwiki_glA|, |vimwiki_gli|, |vimwiki_glI| -Use glr and gLr, if the numbers of a numbered list are mixed up. See +Use glr and gLr if the numbers of a numbered list are mixed up. See |vimwiki_glr| and |vimwiki_gLr|. @@ -1595,6 +1605,9 @@ child items (see also |g:vimwiki_listsyms|): > [O] -- 67-99% [X] -- 100% +You can use |vimwiki_gln| and |vimwiki_glp| to change the "done" status of a +checkbox without a childitem. + It is possible to toggle several list items using visual mode. But note that instead of toggling every item individually, all items get checked if the first item is unchecked and all items get unchecked if the first item is diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim @@ -289,6 +289,8 @@ command! -buffer -range -nargs=1 VimwikiListChangeSymbolI 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 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>) command! -buffer -range VimwikiRemoveSingleCB call vimwiki#lst#remove_cb(<line1>, <line2>) @@ -440,6 +442,23 @@ nnoremap <silent><script><buffer> vnoremap <silent><script><buffer> \ <Plug>VimwikiToggleListItem :VimwikiToggleListItem<CR> +if !hasmapto('<Plug>VimwikiIncrementListItem') + nmap <silent><buffer> gln <Plug>VimwikiIncrementListItem + vmap <silent><buffer> gln <Plug>VimwikiIncrementListItem +endif +if !hasmapto('<Plug>VimwikiDecrementListItem') + nmap <silent><buffer> glp <Plug>VimwikiDecrementListItem + vmap <silent><buffer> glp <Plug>VimwikiDecrementListItem +endif +nnoremap <silent><script><buffer> + \ <Plug>VimwikiIncrementListItem :VimwikiIncrementListItem<CR> +vnoremap <silent><script><buffer> + \ <Plug>VimwikiIncrementListItem :VimwikiIncrementListItem<CR> +nnoremap <silent><script><buffer> + \ <Plug>VimwikiDecrementListItem :VimwikiDecrementListItem<CR> +vnoremap <silent><script><buffer> + \ <Plug>VimwikiDecrementListItem :VimwikiDecrementListItem<CR> + if !hasmapto('<Plug>VimwikiDecreaseLvlSingleItem', 'i') imap <silent><buffer> <C-D> \ <Plug>VimwikiDecreaseLvlSingleItem