vimwiki

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

commit 1e858b50cbeaf04c1292a68169ab440c7feafac5
parent 4c940cd5bb4551a49757ebf5750380ebd5b0dddc
Author: EinfachToll <istjanichtzufassen@googlemail.com>
Date:   Mon, 19 Feb 2018 07:07:22 +0100

Cherry-pick the changes from dev -- part7

Diffstat:
Mautoload/vimwiki/html.vim | 2++
Mautoload/vimwiki/lst.vim | 92++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Mautoload/vimwiki/style.css | 7+++++++
Mautoload/vimwiki/vars.vim | 10+++++++++-
Mdoc/vimwiki.txt | 27+++++++++++++++++++++++++++
Mftplugin/vimwiki.vim | 9+++++++++
6 files changed, 110 insertions(+), 37 deletions(-)

diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim @@ -876,6 +876,8 @@ function! s:process_tag_list(line, lists) "{{{ let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list')) if completion == 0 let st_tag = '<li class="done0">' + elseif completion == -1 && chk[1] == vimwiki#vars#get_global('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.'">' diff --git a/autoload/vimwiki/lst.vim b/autoload/vimwiki/lst.vim @@ -697,6 +697,9 @@ function! s:get_rate(item) "{{{ return -1 endif let state = a:item.cb + if state == vimwiki#vars#get_global('listsym_rejected') + return -1 + endif let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list')) return index(vimwiki#vars#get_syntaxlocal('listsyms_list'), state) * 100/(n-1) endfunction "}}} @@ -740,6 +743,8 @@ function! s:rate_to_state(rate) "{{{ let state = listsyms_list[n-1] elseif a:rate == 0 let state = listsyms_list[0] + elseif a:rate == -1 + let state = vimwiki#vars#get_global('listsym_rejected') else let index = float2nr(ceil(a:rate/100.0*(n-2))) let state = listsyms_list[index] @@ -764,8 +769,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 @@ -840,6 +848,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) "{{{ @@ -877,41 +925,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) "{{{ diff --git a/autoload/vimwiki/style.css b/autoload/vimwiki/style.css @@ -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==); diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim @@ -49,6 +49,7 @@ function! s:populate_global_variables() \ 'list_ignore_newline': 1, \ 'text_ignore_newline': 1, \ 'listsyms': ' .oOX', + \ 'listsym_rejected': '-', \ 'map_prefix': '<Leader>w', \ 'menu': 'Vimwiki', \ 'table_auto_fmt': 1, @@ -376,12 +377,19 @@ function! vimwiki#vars#populate_syntax_vars(syntax) "the user can set the listsyms as string, but vimwiki needs a list let g:vimwiki_syntax_variables[a:syntax].listsyms_list = \ split(vimwiki#vars#get_global('listsyms'), '\zs') + if match(vimwiki#vars#get_global('listsyms'), vimwiki#vars#get_global('listsym_rejected')) != -1 + echomsg 'Vimwiki Warning: the value of g:vimwiki_listsym_rejected (''' + \ . vimwiki#vars#get_global('listsym_rejected') + \ . ''') must not be a part of g:vimwiki_listsyms (''' . + \ . vimwiki#vars#get_global('listsyms') . ''')' + endif let g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB = \ '^\s*\%(\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\|\(' \ .g:vimwiki_syntax_variables[a:syntax].rxListNumber.'\)\)\s' let g:vimwiki_syntax_variables[a:syntax].rxListItem = \ g:vimwiki_syntax_variables[a:syntax].rxListItemWithoutCB - \ . '\+\%(\[\(['.vimwiki#vars#get_global('listsyms').']\)\]\s\)\?' + \ . '\+\%(\[\(['.vimwiki#vars#get_global('listsyms') + \ . vimwiki#vars#get_global('listsym_rejected').']\)\]\s\)\?' if g:vimwiki_syntax_variables[a:syntax].recurring_bullets let g:vimwiki_syntax_variables[a:syntax].rxListItemAndChildren = \ '^\('.g:vimwiki_syntax_variables[a:syntax].rxListBullet.'\)\s\+\[' diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt @@ -456,6 +456,13 @@ gLI Change the symbol of the current list to noremap glo :VimwikiChangeSymbolTo I)<CR> noremap glO :VimwikiChangeSymbolInListTo I)<CR> < + *vimwiki_glx* +glx Toggle checkbox of a list item disabled/off. + Maps to |:VimwikiToggleRejectedListItem|. + See |vimwiki-todo-lists|. + To remap: > + :map <Leader>tx <Plug>VimwikiToggleRejectedListItem +< *vimwiki_gqq* *vimwiki_gww* gqq Format table. If you made some changes to a table or without swapping insert/normal modes this command @@ -656,6 +663,10 @@ Vimwiki file. Toggle checkbox of a list item on/off. See |vimwiki-todo-lists|. +*:VimwikiToggleRejectedListItem* + Toggle checkbox of a list item disabled/off. + See |vimwiki-todo-lists|. + *:VimwikiListChangeLevel* CMD Change the nesting level, or symbol, for a single-line list item. CMD may be ">>" or "<<" to change the indentation of the item, or @@ -1617,6 +1628,9 @@ Use gl<Space> (see |vimwiki_gl<Space>|) to remove a single checkbox and gL<Space> (see |vimwiki_gL<Space>|) to remove all checkboxes of the list the cursor is in. +You can mark an item as rejected ("won't do") with +|vimwiki_glx|. A rejected item will not influence the status of its parents. + ============================================================================== 9. Tables *vimwiki-tables* @@ -2342,6 +2356,19 @@ You can set it to some more fancy symbols like this: ------------------------------------------------------------------------------ +*g:vimwiki_listsym_rejected* + +Character that is used to show that an item of a todo list will not be done. +Default value is '-'. + +The character used here must not be part of |g:vimwiki_listsyms|. + +You can set it to a more fancy symbol like this: +> + let g:vimwiki_listsym_rejected = '✗' + + +------------------------------------------------------------------------------ *g:vimwiki_use_mouse* Use local mouse mappings from |vimwiki-local-mappings|. diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim @@ -289,6 +289,7 @@ 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 VimwikiToggleRejectedListItem 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 @@ -437,10 +438,18 @@ if !hasmapto('<Plug>VimwikiToggleListItem') vmap <silent><buffer> <C-@> <Plug>VimwikiToggleListItem endif endif +if !hasmapto('<Plug>VimwikiToggleRejectedListItem') + nmap <silent><buffer> glx <Plug>VimwikiToggleRejectedListItem + vmap <silent><buffer> glx <Plug>VimwikiToggleRejectedListItem +endif nnoremap <silent><script><buffer> \ <Plug>VimwikiToggleListItem :VimwikiToggleListItem<CR> vnoremap <silent><script><buffer> \ <Plug>VimwikiToggleListItem :VimwikiToggleListItem<CR> +nnoremap <silent><script><buffer> + \ <Plug>VimwikiToggleRejectedListItem :VimwikiToggleRejectedListItem<CR> +vnoremap <silent><script><buffer> + \ <Plug>VimwikiToggleRejectedListItem :VimwikiToggleRejectedListItem<CR> if !hasmapto('<Plug>VimwikiIncrementListItem') nmap <silent><buffer> gln <Plug>VimwikiIncrementListItem