Stylistic changes to pass vint tests.
Two non-stylistic errors were also fixed: 1. Removed duplicate function with invalid argument usage 2. Added missing quotes to a function call argument
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
" Home: https://github.com/vimwiki/vimwiki/
|
||||
|
||||
|
||||
if exists("g:loaded_vimwiki_list_auto") || &cp
|
||||
if exists('g:loaded_vimwiki_list_auto') || &compatible
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_list_auto = 1
|
||||
@ -14,12 +14,12 @@ let g:loaded_vimwiki_list_auto = 1
|
||||
" incrementation functions for the various kinds of numbers
|
||||
" ---------------------------------------------------------
|
||||
|
||||
function! s:increment_1(value)
|
||||
function! s:increment_1(value) abort
|
||||
return eval(a:value) + 1
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:increment_A(value)
|
||||
function! s:increment_A(value) abort
|
||||
let list_of_chars = split(a:value, '.\zs')
|
||||
let done = 0
|
||||
for idx in reverse(range(len(list_of_chars)))
|
||||
@ -39,7 +39,7 @@ function! s:increment_A(value)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:increment_a(value)
|
||||
function! s:increment_a(value) abort
|
||||
let list_of_chars = split(a:value, '.\zs')
|
||||
let done = 0
|
||||
for idx in reverse(range(len(list_of_chars)))
|
||||
@ -59,7 +59,7 @@ function! s:increment_a(value)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:increment_I(value)
|
||||
function! s:increment_I(value) abort
|
||||
let subst_list = [ ['XLVIII$', 'IL'], ['VIII$', 'IX'], ['III$', 'IV'],
|
||||
\ ['DCCCXCIX$', 'CM'], ['CCCXCIX$', 'CD'], ['LXXXIX$', 'XC'],
|
||||
\ ['XXXIX$', 'XL'], ['\(I\{1,2\}\)$', '\1I'], ['CDXCIX$', 'D'],
|
||||
@ -74,7 +74,7 @@ function! s:increment_I(value)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:increment_i(value)
|
||||
function! s:increment_i(value) abort
|
||||
let subst_list = [ ['xlviii$', 'il'], ['viii$', 'ix'], ['iii$', 'iv'],
|
||||
\ ['dcccxcix$', 'cm'], ['cccxcix$', 'cd'], ['lxxxix$', 'xc'],
|
||||
\ ['xxxix$', 'xl'], ['\(i\{1,2\}\)$', '\1i'], ['cdxcix$', 'd'],
|
||||
@ -93,41 +93,41 @@ endfunction
|
||||
" utility functions
|
||||
" ---------------------------------------------------------
|
||||
|
||||
function! s:substitute_rx_in_line(lnum, pattern, new_string)
|
||||
function! s:substitute_rx_in_line(lnum, pattern, new_string) abort
|
||||
call setline(a:lnum, substitute(getline(a:lnum), a:pattern, a:new_string, ''))
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:substitute_string_in_line(lnum, old_string, new_string)
|
||||
function! s:substitute_string_in_line(lnum, old_string, new_string) abort
|
||||
call s:substitute_rx_in_line(a:lnum, vimwiki#u#escape(a:old_string), a:new_string)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:first_char(string)
|
||||
function! s:first_char(string) abort
|
||||
return matchstr(a:string, '^.')
|
||||
endfunction
|
||||
|
||||
|
||||
if exists("*strdisplaywidth")
|
||||
function! s:string_length(str)
|
||||
if exists('*strdisplaywidth')
|
||||
function! s:string_length(str) abort
|
||||
return strdisplaywidth(a:str)
|
||||
endfunction
|
||||
else
|
||||
function! s:string_length(str)
|
||||
function! s:string_length(str) abort
|
||||
return strlen(substitute(a:str, '.', 'x', 'g'))
|
||||
endfunction
|
||||
endif
|
||||
|
||||
|
||||
function! vimwiki#lst#default_symbol()
|
||||
function! vimwiki#lst#default_symbol() abort
|
||||
return vimwiki#vars#get_syntaxlocal('list_markers')[0]
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#get_list_margin()
|
||||
function! vimwiki#lst#get_list_margin() abort
|
||||
let list_margin = vimwiki#vars#get_wikilocal('list_margin')
|
||||
if list_margin < 0
|
||||
return &sw
|
||||
return &shiftwidth
|
||||
else
|
||||
return list_margin
|
||||
endif
|
||||
@ -136,7 +136,7 @@ endfunction
|
||||
|
||||
"Returns: the column where the text of a line starts (possible list item
|
||||
"markers and checkboxes are skipped)
|
||||
function! s:text_begin(lnum)
|
||||
function! s:text_begin(lnum) abort
|
||||
return s:string_length(matchstr(getline(a:lnum), vimwiki#vars#get_syntaxlocal('rxListItem')))
|
||||
endfunction
|
||||
|
||||
@ -144,7 +144,7 @@ endfunction
|
||||
"Returns: 2 if there is a marker and text
|
||||
" 1 for a marker and no text
|
||||
" 0 for no marker at all (empty line or only text)
|
||||
function! s:line_has_marker(lnum)
|
||||
function! s:line_has_marker(lnum) abort
|
||||
if getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxListItem').'\s*$'
|
||||
return 1
|
||||
elseif getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxListItem').'\s*\S'
|
||||
@ -165,7 +165,7 @@ endfunction
|
||||
"type - 1 for bulleted item, 2 for numbered item, 0 for a regular line
|
||||
"mrkr - the concrete marker, e.g. '**' or 'b)'
|
||||
"cb - the char in the checkbox or '' if there is no checkbox
|
||||
function! s:get_item(lnum)
|
||||
function! s:get_item(lnum) abort
|
||||
let item = {'lnum': a:lnum}
|
||||
if a:lnum == 0 || a:lnum > line('$')
|
||||
let item.type = 0
|
||||
@ -174,15 +174,15 @@ function! s:get_item(lnum)
|
||||
|
||||
let matches = matchlist(getline(a:lnum), vimwiki#vars#get_syntaxlocal('rxListItem'))
|
||||
if matches == [] ||
|
||||
\ (matches[1] == '' && matches[2] == '') ||
|
||||
\ (matches[1] != '' && matches[2] != '')
|
||||
\ (matches[1] ==? '' && matches[2] ==? '') ||
|
||||
\ (matches[1] !=? '' && matches[2] !=? '')
|
||||
let item.type = 0
|
||||
return item
|
||||
endif
|
||||
|
||||
let item.cb = matches[3]
|
||||
|
||||
if matches[1] != ''
|
||||
if matches[1] !=? ''
|
||||
let item.type = 1
|
||||
let item.mrkr = matches[1]
|
||||
else
|
||||
@ -194,14 +194,14 @@ function! s:get_item(lnum)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:empty_item()
|
||||
function! s:empty_item() abort
|
||||
return {'type': 0}
|
||||
endfunction
|
||||
|
||||
|
||||
"Returns: level of the line
|
||||
"0 is the 'highest' level
|
||||
function! s:get_level(lnum)
|
||||
function! s:get_level(lnum) abort
|
||||
if getline(a:lnum) =~# '^\s*$'
|
||||
return 0
|
||||
endif
|
||||
@ -209,7 +209,7 @@ function! s:get_level(lnum)
|
||||
let level = indent(a:lnum)
|
||||
else
|
||||
let level = s:string_length(matchstr(getline(a:lnum),
|
||||
\ vimwiki#vars#get_syntaxlocal(rx_bullet_chars)))-1
|
||||
\ vimwiki#vars#get_syntaxlocal('rx_bullet_chars')))-1
|
||||
if level < 0
|
||||
let level = (indent(a:lnum) == 0) ? 0 : 9999
|
||||
endif
|
||||
@ -221,7 +221,7 @@ endfunction
|
||||
"Returns: 1, a, i, A, I or ''
|
||||
"If in doubt if alphanumeric character or romanian
|
||||
"numeral, peek in the previous line
|
||||
function! s:guess_kind_of_numbered_item(item)
|
||||
function! s:guess_kind_of_numbered_item(item) abort
|
||||
if a:item.type != 2 | return '' | endif
|
||||
let number_chars = a:item.mrkr[:-2]
|
||||
let divisor = a:item.mrkr[-1:]
|
||||
@ -282,14 +282,14 @@ function! s:guess_kind_of_numbered_item(item)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:regexp_of_marker(item)
|
||||
function! s:regexp_of_marker(item) abort
|
||||
if a:item.type == 1
|
||||
return vimwiki#u#escape(a:item.mrkr)
|
||||
elseif a:item.type == 2
|
||||
let number_divisors = vimwiki#vars#get_syntaxlocal('number_divisors')
|
||||
for ki in ['d', 'u', 'l']
|
||||
let match = matchstr(a:item.mrkr, '\'.ki.'\+['.number_divisors.']')
|
||||
if match != ''
|
||||
if match !=? ''
|
||||
return '\'.ki.'\+'.vimwiki#u#escape(match[-1:])
|
||||
endif
|
||||
endfor
|
||||
@ -300,7 +300,7 @@ endfunction
|
||||
|
||||
|
||||
" Returns: Whether or not the checkbox of a list item is [X] or [-]
|
||||
function! s:is_closed(item)
|
||||
function! s:is_closed(item) abort
|
||||
let state = a:item.cb
|
||||
return state ==# vimwiki#vars#get_syntaxlocal('listsyms_list')[-1]
|
||||
\ || state ==# vimwiki#vars#get_global('listsym_rejected')
|
||||
@ -312,7 +312,7 @@ endfunction
|
||||
|
||||
"Returns: the list item after a:item or an empty item
|
||||
"If a:ignore_kind is 1, the markers can differ
|
||||
function! s:get_next_list_item(item, ignore_kind)
|
||||
function! s:get_next_list_item(item, ignore_kind) abort
|
||||
let org_lvl = s:get_level(a:item.lnum)
|
||||
if !a:ignore_kind
|
||||
let org_regex = s:regexp_of_marker(a:item)
|
||||
@ -336,7 +336,7 @@ endfunction
|
||||
|
||||
"Returns: the list item before a:item or an empty item
|
||||
"If a:ignore_kind is 1, the markers can differ
|
||||
function! s:get_prev_list_item(item, ignore_kind)
|
||||
function! s:get_prev_list_item(item, ignore_kind) abort
|
||||
let org_lvl = s:get_level(a:item.lnum)
|
||||
if !a:ignore_kind
|
||||
let org_regex = s:regexp_of_marker(a:item)
|
||||
@ -358,7 +358,7 @@ function! s:get_prev_list_item(item, ignore_kind)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex)
|
||||
function! s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex) abort
|
||||
let cur_linecontent = getline(a:cur_ln)
|
||||
if a:cur_lvl == a:org_lvl
|
||||
if cur_linecontent =~# '^\s*'.a:org_regex.'\s'
|
||||
@ -372,7 +372,7 @@ function! s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl)
|
||||
function! s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl) abort
|
||||
if a:cur_lvl == a:org_lvl
|
||||
return s:get_item(a:cur_ln)
|
||||
elseif a:cur_lvl < a:org_lvl
|
||||
@ -381,7 +381,7 @@ function! s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_first_item_in_list(item, ignore_kind)
|
||||
function! s:get_first_item_in_list(item, ignore_kind) abort
|
||||
let cur_item = a:item
|
||||
while 1
|
||||
let prev_item = s:get_prev_list_item(cur_item, a:ignore_kind)
|
||||
@ -395,7 +395,7 @@ function! s:get_first_item_in_list(item, ignore_kind)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_last_item_in_list(item, ignore_kind)
|
||||
function! s:get_last_item_in_list(item, ignore_kind) abort
|
||||
let cur_item = a:item
|
||||
while 1
|
||||
let next_item = s:get_next_list_item(cur_item, a:ignore_kind)
|
||||
@ -413,7 +413,7 @@ endfunction
|
||||
"0 in case of nonvalid line.
|
||||
"If there is no second argument, 0 is returned at a header, otherwise the
|
||||
"header is skipped
|
||||
function! s:get_next_line(lnum, ...)
|
||||
function! s:get_next_line(lnum, ...) abort
|
||||
if getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
|
||||
let cur_ln = a:lnum + 1
|
||||
while cur_ln <= line('$') && getline(cur_ln) !~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
|
||||
@ -441,7 +441,7 @@ endfunction
|
||||
|
||||
"Returns: lnum-1 in most cases, but skips blank lines and preformatted text
|
||||
"0 in case of nonvalid line and a header, because a header ends every list
|
||||
function! s:get_prev_line(lnum)
|
||||
function! s:get_prev_line(lnum) abort
|
||||
let cur_ln = a:lnum - 1
|
||||
|
||||
if getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
|
||||
@ -464,7 +464,7 @@ function! s:get_prev_line(lnum)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_first_child(item)
|
||||
function! s:get_first_child(item) abort
|
||||
if a:item.lnum >= line('$')
|
||||
return s:empty_item()
|
||||
endif
|
||||
@ -485,7 +485,7 @@ endfunction
|
||||
"Returns: the next sibling of a:child, given the parent item
|
||||
"Used for iterating over children
|
||||
"Note: child items do not necessarily have the same indent, i.e. level
|
||||
function! s:get_next_child_item(parent, child)
|
||||
function! s:get_next_child_item(parent, child) abort
|
||||
if a:parent.type == 0 | return s:empty_item() | endif
|
||||
let parent_lvl = s:get_level(a:parent.lnum)
|
||||
let cur_ln = s:get_last_line_of_item_incl_children(a:child)
|
||||
@ -504,7 +504,7 @@ function! s:get_next_child_item(parent, child)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_parent(item)
|
||||
function! s:get_parent(item) abort
|
||||
let parent_line = 0
|
||||
|
||||
let cur_ln = prevnonblank(a:item.lnum)
|
||||
@ -532,7 +532,7 @@ endfunction
|
||||
|
||||
|
||||
"Returns: the item above or the item below or an empty item
|
||||
function! s:get_a_neighbor_item(item)
|
||||
function! s:get_a_neighbor_item(item) abort
|
||||
let prev_item = s:get_prev_list_item(a:item, 1)
|
||||
if prev_item.type != 0
|
||||
return prev_item
|
||||
@ -546,7 +546,7 @@ function! s:get_a_neighbor_item(item)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_a_neighbor_item_in_column(lnum, column)
|
||||
function! s:get_a_neighbor_item_in_column(lnum, column) abort
|
||||
let cur_ln = s:get_prev_line(a:lnum)
|
||||
while cur_ln >= 1
|
||||
if s:get_level(cur_ln) <= a:column
|
||||
@ -560,7 +560,7 @@ endfunction
|
||||
|
||||
"Returns: the item if there is one in a:lnum
|
||||
"else the multiline item a:lnum belongs to
|
||||
function! s:get_corresponding_item(lnum)
|
||||
function! s:get_corresponding_item(lnum) abort
|
||||
let item = s:get_item(a:lnum)
|
||||
if item.type != 0
|
||||
return item
|
||||
@ -583,7 +583,7 @@ endfunction
|
||||
|
||||
|
||||
"Returns: the last line of a (possibly multiline) item, including all children
|
||||
function! s:get_last_line_of_item_incl_children(item)
|
||||
function! s:get_last_line_of_item_incl_children(item) abort
|
||||
let cur_ln = a:item.lnum
|
||||
let org_lvl = s:get_level(a:item.lnum)
|
||||
while 1
|
||||
@ -598,7 +598,7 @@ endfunction
|
||||
|
||||
"Returns: the last line of a (possibly multiline) item
|
||||
"Note: there can be other list items between the first and last line
|
||||
function! s:get_last_line_of_item(item)
|
||||
function! s:get_last_line_of_item(item) abort
|
||||
if a:item.type == 0 | return 0 | endif
|
||||
let org_lvl = s:get_level(a:item.lnum)
|
||||
let last_corresponding_line = a:item.lnum
|
||||
@ -627,7 +627,7 @@ endfunction
|
||||
|
||||
"Renumbers the current list from a:item on downwards
|
||||
"Returns: the last item that was adjusted
|
||||
function! s:adjust_numbered_list_below(item, recursive)
|
||||
function! s:adjust_numbered_list_below(item, recursive) abort
|
||||
if !(a:item.type == 2 || (a:item.type == 1 && a:recursive))
|
||||
return a:item
|
||||
endif
|
||||
@ -657,7 +657,7 @@ function! s:adjust_numbered_list_below(item, recursive)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:adjust_items_recursively(parent)
|
||||
function! s:adjust_items_recursively(parent) abort
|
||||
if a:parent.type == 0
|
||||
return s:empty_item()
|
||||
end
|
||||
@ -681,7 +681,7 @@ endfunction
|
||||
"If a:ignore_kind == 0, only the items which have the same kind of marker as
|
||||
"a:item are considered, otherwise all items.
|
||||
"Returns: the last item that was adjusted
|
||||
function! s:adjust_numbered_list(item, ignore_kind, recursive)
|
||||
function! s:adjust_numbered_list(item, ignore_kind, recursive) abort
|
||||
if !(a:item.type == 2 || (a:item.type == 1 && (a:ignore_kind || a:recursive)))
|
||||
return s:empty_item()
|
||||
end
|
||||
@ -708,7 +708,7 @@ endfunction
|
||||
|
||||
"Renumbers the list the cursor is in
|
||||
"also update its parents checkbox state
|
||||
function! vimwiki#lst#adjust_numbered_list()
|
||||
function! vimwiki#lst#adjust_numbered_list() abort
|
||||
let cur_item = s:get_corresponding_item(line('.'))
|
||||
if cur_item.type == 0 | return | endif
|
||||
call s:adjust_numbered_list(cur_item, 1, 0)
|
||||
@ -718,7 +718,7 @@ endfunction
|
||||
|
||||
"Renumbers all lists of the buffer
|
||||
"of course, this might take some seconds
|
||||
function! vimwiki#lst#adjust_whole_buffer()
|
||||
function! vimwiki#lst#adjust_whole_buffer() abort
|
||||
let cur_ln = 1
|
||||
while 1
|
||||
let cur_item = s:get_item(cur_ln)
|
||||
@ -738,8 +738,8 @@ endfunction
|
||||
" ---------------------------------------------------------
|
||||
|
||||
"Returns: the rate of checkboxed list item in percent
|
||||
function! s:get_rate(item)
|
||||
if a:item.type == 0 || a:item.cb == ''
|
||||
function! s:get_rate(item) abort
|
||||
if a:item.type == 0 || a:item.cb ==? ''
|
||||
return -1
|
||||
endif
|
||||
let state = a:item.cb
|
||||
@ -753,7 +753,7 @@ endfunction
|
||||
|
||||
"Set state of the list item to [ ] or [o] or whatever
|
||||
"Returns: 1 if the state changed, 0 otherwise
|
||||
function! s:set_state(item, new_rate)
|
||||
function! s:set_state(item, new_rate) abort
|
||||
let new_state = s:rate_to_state(a:new_rate)
|
||||
let old_state = s:rate_to_state(s:get_rate(a:item))
|
||||
if new_state !=# old_state
|
||||
@ -768,7 +768,7 @@ endfunction
|
||||
" Sets the state of the list item to [ ] or [o] or whatever. Updates the states of its child items.
|
||||
" If the new state should be [X] or [-], the state of the current list item is changed to this
|
||||
" state, but if a child item already has [X] or [-] it is left alone.
|
||||
function! s:set_state_plus_children(item, new_rate, ...)
|
||||
function! s:set_state_plus_children(item, new_rate, ...) abort
|
||||
let retain_state_if_closed = a:0 > 0 && a:1 > 0
|
||||
|
||||
if !(retain_state_if_closed && (a:new_rate == 100 || a:new_rate == -1) && s:is_closed(a:item))
|
||||
@ -812,7 +812,7 @@ function! s:set_state_plus_children(item, new_rate, ...)
|
||||
if child_item.type == 0
|
||||
break
|
||||
endif
|
||||
if child_item.cb != ''
|
||||
if child_item.cb !=? ''
|
||||
call s:set_state_plus_children(child_item, a:new_rate, retain_closed_children)
|
||||
endif
|
||||
let child_item = s:get_next_child_item(a:item, child_item)
|
||||
@ -821,7 +821,7 @@ endfunction
|
||||
|
||||
|
||||
"Returns: the appropriate symbol for a given percent rate
|
||||
function! s:rate_to_state(rate)
|
||||
function! s:rate_to_state(rate) abort
|
||||
let listsyms_list = vimwiki#vars#get_syntaxlocal('listsyms_list')
|
||||
let state = ''
|
||||
let n = len(listsyms_list)
|
||||
@ -841,8 +841,8 @@ endfunction
|
||||
|
||||
"updates the symbol of a checkboxed item according to the symbols of its
|
||||
"children
|
||||
function! s:update_state(item)
|
||||
if a:item.type == 0 || a:item.cb == ''
|
||||
function! s:update_state(item) abort
|
||||
if a:item.type == 0 || a:item.cb ==? ''
|
||||
return
|
||||
endif
|
||||
|
||||
@ -856,7 +856,7 @@ function! s:update_state(item)
|
||||
if child_item.type == 0
|
||||
break
|
||||
endif
|
||||
if child_item.cb != ''
|
||||
if child_item.cb !=? ''
|
||||
let rate = s:get_rate(child_item)
|
||||
if rate == -1
|
||||
" for calculating the parent rate, a [-] item counts as much as a [X] item ...
|
||||
@ -886,7 +886,7 @@ function! s:update_state(item)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:set_state_recursively(item, new_rate)
|
||||
function! s:set_state_recursively(item, new_rate) abort
|
||||
let state_changed = s:set_state(a:item, a:new_rate)
|
||||
if state_changed
|
||||
call s:update_state(s:get_parent(a:item))
|
||||
@ -896,8 +896,8 @@ endfunction
|
||||
|
||||
"Creates checkbox in a list item.
|
||||
"Returns: 1 if successful
|
||||
function! s:create_cb(item, start_rate)
|
||||
if a:item.type == 0 || a:item.cb != ''
|
||||
function! s:create_cb(item, start_rate) abort
|
||||
if a:item.type == 0 || a:item.cb !=? ''
|
||||
return 0
|
||||
endif
|
||||
|
||||
@ -911,9 +911,9 @@ function! s:create_cb(item, start_rate)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:remove_cb(item)
|
||||
function! s:remove_cb(item) abort
|
||||
let item = a:item
|
||||
if item.type != 0 && item.cb != ''
|
||||
if item.type != 0 && item.cb !=? ''
|
||||
let item.cb = ''
|
||||
call s:substitute_rx_in_line(item.lnum, '\s\+\[.\]', '')
|
||||
endif
|
||||
@ -922,7 +922,7 @@ endfunction
|
||||
|
||||
|
||||
" Change state of the checkboxes in the lines of the given range
|
||||
function! s:change_cb(from_line, to_line, new_rate)
|
||||
function! s:change_cb(from_line, to_line, new_rate) abort
|
||||
let from_item = s:get_corresponding_item(a:from_line)
|
||||
if from_item.type == 0
|
||||
return
|
||||
@ -932,7 +932,7 @@ function! s:change_cb(from_line, to_line, new_rate)
|
||||
|
||||
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 != ''
|
||||
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
|
||||
@ -950,13 +950,13 @@ endfunction
|
||||
|
||||
" Toggles checkbox between two states in the lines of the given range, creates checkboxes (with
|
||||
" a:start_rate as state) if there aren't any.
|
||||
function! s:toggle_create_cb(from_line, to_line, state1, state2, start_rate)
|
||||
function! s:toggle_create_cb(from_line, to_line, state1, state2, start_rate) abort
|
||||
let from_item = s:get_corresponding_item(a:from_line)
|
||||
if from_item.type == 0
|
||||
return
|
||||
endif
|
||||
|
||||
if from_item.cb == ''
|
||||
if from_item.cb ==? ''
|
||||
|
||||
"if from_line has no CB, make a CB in every selected line
|
||||
let parent_items_of_lines = []
|
||||
@ -991,7 +991,7 @@ endfunction
|
||||
|
||||
"Decrement checkbox between [ ] and [X]
|
||||
"in the lines of the given range
|
||||
function! vimwiki#lst#decrement_cb(from_line, to_line)
|
||||
function! vimwiki#lst#decrement_cb(from_line, to_line) abort
|
||||
let from_item = s:get_corresponding_item(a:from_line)
|
||||
if from_item.type == 0
|
||||
return
|
||||
@ -1009,7 +1009,7 @@ endfunction
|
||||
|
||||
"Increment checkbox between [ ] and [X]
|
||||
"in the lines of the given range
|
||||
function! vimwiki#lst#increment_cb(from_line, to_line)
|
||||
function! vimwiki#lst#increment_cb(from_line, to_line) abort
|
||||
let from_item = s:get_corresponding_item(a:from_line)
|
||||
if from_item.type == 0
|
||||
return
|
||||
@ -1027,19 +1027,19 @@ 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)
|
||||
function! vimwiki#lst#toggle_cb(from_line, to_line) abort
|
||||
return s:toggle_create_cb(a:from_line, a:to_line, 100, 0, 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)
|
||||
function! vimwiki#lst#toggle_rejected_cb(from_line, to_line) abort
|
||||
return s:toggle_create_cb(a:from_line, a:to_line, -1, 0, -1)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#remove_cb(first_line, last_line)
|
||||
function! vimwiki#lst#remove_cb(first_line, last_line) abort
|
||||
let first_item = s:get_corresponding_item(a:first_line)
|
||||
let last_item = s:get_corresponding_item(a:last_line)
|
||||
|
||||
@ -1067,7 +1067,7 @@ function! vimwiki#lst#remove_cb(first_line, last_line)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#remove_cb_in_list()
|
||||
function! vimwiki#lst#remove_cb_in_list() abort
|
||||
let first_item = s:get_first_item_in_list(s:get_corresponding_item(line('.')), 0)
|
||||
|
||||
let cur_item = first_item
|
||||
@ -1090,7 +1090,7 @@ endfunction
|
||||
" change the level of list items
|
||||
" ---------------------------------------------------------
|
||||
|
||||
function! s:set_indent(lnum, new_indent)
|
||||
function! s:set_indent(lnum, new_indent) abort
|
||||
if &expandtab
|
||||
let indentstring = repeat(' ', a:new_indent)
|
||||
else
|
||||
@ -1100,7 +1100,7 @@ function! s:set_indent(lnum, new_indent)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:decrease_level(item)
|
||||
function! s:decrease_level(item) abort
|
||||
let removed_indent = 0
|
||||
if vimwiki#vars#get_syntaxlocal('recurring_bullets') && a:item.type == 1 &&
|
||||
\ index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'),
|
||||
@ -1123,7 +1123,7 @@ function! s:decrease_level(item)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:increase_level(item)
|
||||
function! s:increase_level(item) abort
|
||||
let additional_indent = 0
|
||||
if vimwiki#vars#get_syntaxlocal('recurring_bullets') && a:item.type == 1 &&
|
||||
\ index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'),
|
||||
@ -1147,7 +1147,7 @@ endfunction
|
||||
|
||||
"adds a:indent_by to the current indent
|
||||
"a:indent_by can be negative
|
||||
function! s:indent_line_by(lnum, indent_by)
|
||||
function! s:indent_line_by(lnum, indent_by) abort
|
||||
let item = s:get_item(a:lnum)
|
||||
if vimwiki#vars#get_syntaxlocal('recurring_bullets') && item.type == 1 &&
|
||||
\ index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'),
|
||||
@ -1164,7 +1164,7 @@ endfunction
|
||||
|
||||
|
||||
"changes lvl of lines in selection
|
||||
function! s:change_level(from_line, to_line, direction, plus_children)
|
||||
function! s:change_level(from_line, to_line, direction, plus_children) abort
|
||||
let from_item = s:get_corresponding_item(a:from_line)
|
||||
if from_item.type == 0
|
||||
if a:direction ==# 'increase' && a:from_line == a:to_line && empty(getline(a:from_line))
|
||||
@ -1227,7 +1227,7 @@ function! s:change_level(from_line, to_line, direction, plus_children)
|
||||
endif
|
||||
call s:update_state(old_parent)
|
||||
let from_item = s:get_item(from_item.lnum)
|
||||
if from_item.cb != ''
|
||||
if from_item.cb !=? ''
|
||||
call s:update_state(from_item)
|
||||
call s:update_state(s:get_parent(from_item))
|
||||
endif
|
||||
@ -1241,7 +1241,7 @@ function! s:change_level(from_line, to_line, direction, plus_children)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#change_level(from_line, to_line, direction, plus_children)
|
||||
function! vimwiki#lst#change_level(from_line, to_line, direction, plus_children) abort
|
||||
let cur_col = col('$') - col('.')
|
||||
call s:change_level(a:from_line, a:to_line, a:direction, a:plus_children)
|
||||
call cursor('.', col('$') - cur_col)
|
||||
@ -1249,7 +1249,7 @@ endfunction
|
||||
|
||||
|
||||
"indent line a:lnum to be the continuation of a:prev_item
|
||||
function! s:indent_multiline(prev_item, lnum)
|
||||
function! s:indent_multiline(prev_item, lnum) abort
|
||||
if a:prev_item.type != 0
|
||||
call s:set_indent(a:lnum, s:text_begin(a:prev_item.lnum))
|
||||
endif
|
||||
@ -1261,7 +1261,7 @@ endfunction
|
||||
" ---------------------------------------------------------
|
||||
|
||||
"Returns: the position of a marker in g:vimwiki_list_markers
|
||||
function! s:get_idx_list_markers(item)
|
||||
function! s:get_idx_list_markers(item) abort
|
||||
if a:item.type == 1
|
||||
let m = s:first_char(a:item.mrkr)
|
||||
else
|
||||
@ -1272,7 +1272,7 @@ endfunction
|
||||
|
||||
|
||||
"changes the marker of the given item to the next in g:vimwiki_list_markers
|
||||
function! s:get_next_mrkr(item)
|
||||
function! s:get_next_mrkr(item) abort
|
||||
let markers = vimwiki#vars#get_syntaxlocal('list_markers')
|
||||
if a:item.type == 0
|
||||
let new_mrkr = markers[0]
|
||||
@ -1285,7 +1285,7 @@ endfunction
|
||||
|
||||
|
||||
"changes the marker of the given item to the previous in g:vimwiki_list_markers
|
||||
function! s:get_prev_mrkr(item)
|
||||
function! s:get_prev_mrkr(item) abort
|
||||
let markers = vimwiki#vars#get_syntaxlocal('list_markers')
|
||||
if a:item.type == 0
|
||||
return markers[-1]
|
||||
@ -1299,7 +1299,7 @@ function! s:get_prev_mrkr(item)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:set_new_mrkr(item, new_mrkr)
|
||||
function! s:set_new_mrkr(item, new_mrkr) abort
|
||||
if a:item.type == 0
|
||||
call s:substitute_rx_in_line(a:item.lnum, '^\s*\zs\ze', a:new_mrkr.' ')
|
||||
if indent(a:item.lnum) == 0 && !vimwiki#vars#get_syntaxlocal('recurring_bullets')
|
||||
@ -1311,16 +1311,16 @@ function! s:set_new_mrkr(item, new_mrkr)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#change_marker(from_line, to_line, new_mrkr, mode)
|
||||
let cur_col_from_eol = col("$") - (a:mode ==# "i" ? col("'^") : col('.'))
|
||||
function! vimwiki#lst#change_marker(from_line, to_line, new_mrkr, mode) abort
|
||||
let cur_col_from_eol = col('$') - (a:mode ==# 'i' ? col("'^") : col('.'))
|
||||
let new_mrkr = a:new_mrkr
|
||||
let cur_ln = a:from_line
|
||||
while 1
|
||||
let cur_item = s:get_item(cur_ln)
|
||||
|
||||
if new_mrkr ==# "next"
|
||||
if new_mrkr ==# 'next'
|
||||
let new_mrkr = s:get_next_mrkr(cur_item)
|
||||
elseif new_mrkr ==# "prev"
|
||||
elseif new_mrkr ==# 'prev'
|
||||
let new_mrkr = s:get_prev_mrkr(cur_item)
|
||||
endif
|
||||
|
||||
@ -1365,7 +1365,7 @@ function! vimwiki#lst#change_marker(from_line, to_line, new_mrkr, mode)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#change_marker_in_list(new_mrkr)
|
||||
function! vimwiki#lst#change_marker_in_list(new_mrkr) abort
|
||||
let cur_item = s:get_corresponding_item(line('.'))
|
||||
let first_item = s:get_first_item_in_list(cur_item, 0)
|
||||
let last_item = s:get_last_item_in_list(cur_item, 0)
|
||||
@ -1383,7 +1383,7 @@ endfunction
|
||||
|
||||
|
||||
"sets kind of the item depending on neighbor items and the parent item
|
||||
function! s:adjust_mrkr(item)
|
||||
function! s:adjust_mrkr(item) abort
|
||||
if a:item.type == 0 || vimwiki#vars#get_syntaxlocal('recurring_bullets')
|
||||
return
|
||||
endif
|
||||
@ -1409,14 +1409,14 @@ function! s:adjust_mrkr(item)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:clone_marker_from_to(from, to)
|
||||
function! s:clone_marker_from_to(from, to) abort
|
||||
let item_from = s:get_item(a:from)
|
||||
if item_from.type == 0 | return | endif
|
||||
let new_mrkr = item_from.mrkr . ' '
|
||||
call s:substitute_rx_in_line(a:to, '^\s*', new_mrkr)
|
||||
let new_indent = ( vimwiki#vars#get_syntaxlocal('recurring_bullets') ? 0 : indent(a:from) )
|
||||
call s:set_indent(a:to, new_indent)
|
||||
if item_from.cb != ''
|
||||
if item_from.cb !=? ''
|
||||
call s:create_cb(s:get_item(a:to), 0)
|
||||
call s:update_state(s:get_parent(s:get_item(a:to)))
|
||||
endif
|
||||
@ -1427,9 +1427,9 @@ function! s:clone_marker_from_to(from, to)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:remove_mrkr(item)
|
||||
function! s:remove_mrkr(item) abort
|
||||
let item = a:item
|
||||
if item.cb != ''
|
||||
if item.cb !=? ''
|
||||
let item = s:remove_cb(item)
|
||||
let parent_item = s:get_parent(item)
|
||||
else
|
||||
@ -1444,7 +1444,7 @@ function! s:remove_mrkr(item)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:create_marker(lnum)
|
||||
function! s:create_marker(lnum) abort
|
||||
let new_sibling = s:get_corresponding_item(a:lnum)
|
||||
if new_sibling.type == 0
|
||||
let new_sibling = s:get_a_neighbor_item_in_column(a:lnum, virtcol('.'))
|
||||
@ -1463,7 +1463,7 @@ endfunction
|
||||
" handle keys
|
||||
" ---------------------------------------------------------
|
||||
|
||||
function! vimwiki#lst#kbd_o()
|
||||
function! vimwiki#lst#kbd_o() abort
|
||||
let fold_end = foldclosedend('.')
|
||||
let lnum = (fold_end == -1) ? line('.') : fold_end
|
||||
let cur_item = s:get_item(lnum)
|
||||
@ -1482,7 +1482,7 @@ function! vimwiki#lst#kbd_o()
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#kbd_O()
|
||||
function! vimwiki#lst#kbd_O() abort
|
||||
exe 'normal!' "Ox\<C-H>"
|
||||
let cur_ln = line('.')
|
||||
if !vimwiki#u#is_codeblock(cur_ln)
|
||||
@ -1496,7 +1496,7 @@ function! vimwiki#lst#kbd_O()
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:cr_on_empty_list_item(lnum, behavior)
|
||||
function! s:cr_on_empty_list_item(lnum, behavior) abort
|
||||
if a:behavior == 1
|
||||
"just make a new list item
|
||||
exe 'normal!' "gi\<CR>\<ESC>"
|
||||
@ -1513,7 +1513,7 @@ function! s:cr_on_empty_list_item(lnum, behavior)
|
||||
let item = s:get_item(a:lnum)
|
||||
let neighbor_item = s:get_a_neighbor_item(item)
|
||||
let child_item = s:get_first_child(item)
|
||||
let parent_item = (item.cb != '') ? s:get_parent(item) : s:empty_item()
|
||||
let parent_item = (item.cb !=? '') ? s:get_parent(item) : s:empty_item()
|
||||
normal! "_cc
|
||||
call s:adjust_numbered_list(neighbor_item, 0, 0)
|
||||
call s:adjust_numbered_list(child_item, 0, 0)
|
||||
@ -1525,7 +1525,7 @@ function! s:cr_on_empty_list_item(lnum, behavior)
|
||||
let item = s:get_item(a:lnum)
|
||||
let neighbor_item = s:get_a_neighbor_item(item)
|
||||
let child_item = s:get_first_child(item)
|
||||
let parent_item = (item.cb != '') ? s:get_parent(item) : s:empty_item()
|
||||
let parent_item = (item.cb !=? '') ? s:get_parent(item) : s:empty_item()
|
||||
exe 'normal!' "_cc\<CR>"
|
||||
call s:adjust_numbered_list(neighbor_item, 0, 0)
|
||||
call s:adjust_numbered_list(child_item, 0, 0)
|
||||
@ -1541,7 +1541,7 @@ function! s:cr_on_empty_list_item(lnum, behavior)
|
||||
let item = s:get_item(a:lnum)
|
||||
let neighbor_item = s:get_a_neighbor_item(item)
|
||||
let child_item = s:get_first_child(item)
|
||||
let parent_item = (item.cb != '') ? s:get_parent(item) : s:empty_item()
|
||||
let parent_item = (item.cb !=? '') ? s:get_parent(item) : s:empty_item()
|
||||
normal! "_cc
|
||||
call s:adjust_numbered_list(neighbor_item, 0, 0)
|
||||
call s:adjust_numbered_list(child_item, 0, 0)
|
||||
@ -1552,7 +1552,7 @@ function! s:cr_on_empty_list_item(lnum, behavior)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:cr_on_empty_line(lnum, behavior)
|
||||
function! s:cr_on_empty_line(lnum, behavior) abort
|
||||
let lst = s:get_corresponding_item(a:lnum)
|
||||
|
||||
"inserting and deleting the x is necessary
|
||||
@ -1570,7 +1570,7 @@ function! s:cr_on_empty_line(lnum, behavior)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:cr_on_list_item(lnum, insert_new_marker, not_at_eol)
|
||||
function! s:cr_on_list_item(lnum, insert_new_marker, not_at_eol) abort
|
||||
if a:insert_new_marker
|
||||
"the ultimate feature of this script: make new marker on <CR>
|
||||
exe 'normal!' "gi\<CR>\<ESC>"
|
||||
@ -1589,7 +1589,7 @@ function! s:cr_on_list_item(lnum, insert_new_marker, not_at_eol)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#kbd_cr(normal, just_mrkr)
|
||||
function! vimwiki#lst#kbd_cr(normal, just_mrkr) abort
|
||||
let lnum = line('.')
|
||||
let has_bp = s:line_has_marker(lnum)
|
||||
|
||||
@ -1608,8 +1608,8 @@ function! vimwiki#lst#kbd_cr(normal, just_mrkr)
|
||||
if getline('.')[col("'^")-1:] =~# '^\s\+$'
|
||||
let cur_col = 0
|
||||
else
|
||||
let cur_col = col("$") - col("'^")
|
||||
if getline('.')[col("'^")-1] =~# '\s' && exists("*strdisplaywidth")
|
||||
let cur_col = col('$') - col("'^")
|
||||
if getline('.')[col("'^")-1] =~# '\s' && exists('*strdisplaywidth')
|
||||
let ws_behind_cursor =
|
||||
\ strdisplaywidth(matchstr(getline('.')[col("'^")-1:], '\s\+'),
|
||||
\ virtcol("'^")-1)
|
||||
@ -1628,7 +1628,7 @@ function! vimwiki#lst#kbd_cr(normal, just_mrkr)
|
||||
call s:cr_on_list_item(lnum, insert_new_marker, cur_col)
|
||||
endif
|
||||
|
||||
call cursor(lnum+1, col("$") - cur_col)
|
||||
call cursor(lnum+1, col('$') - cur_col)
|
||||
if cur_col == 0
|
||||
startinsert!
|
||||
else
|
||||
@ -1639,8 +1639,8 @@ endfunction
|
||||
|
||||
|
||||
"creates a list item in the current line or removes it
|
||||
function! vimwiki#lst#toggle_list_item()
|
||||
let cur_col_from_eol = col("$") - col("'^")
|
||||
function! vimwiki#lst#toggle_list_item() abort
|
||||
let cur_col_from_eol = col('$') - col("'^")
|
||||
let cur_item = s:get_item(line('.'))
|
||||
|
||||
if cur_item.type == 0
|
||||
@ -1660,7 +1660,7 @@ function! vimwiki#lst#toggle_list_item()
|
||||
endif
|
||||
|
||||
"set cursor position s.t. it's on the same char as before
|
||||
let new_cur_col = col("$") - cur_col_from_eol
|
||||
let new_cur_col = col('$') - cur_col_from_eol
|
||||
call cursor(cur_item.lnum, new_cur_col >= 1 ? new_cur_col : 1)
|
||||
|
||||
if cur_col_from_eol == 0 || getline(cur_item.lnum) =~# '^\s*$'
|
||||
@ -1675,7 +1675,7 @@ endfunction
|
||||
" misc stuff
|
||||
" ---------------------------------------------------------
|
||||
|
||||
function! vimwiki#lst#TO_list_item(inner, visual)
|
||||
function! vimwiki#lst#TO_list_item(inner, visual) abort
|
||||
let lnum = prevnonblank('.')
|
||||
let item = s:get_corresponding_item(lnum)
|
||||
if item.type == 0
|
||||
@ -1694,7 +1694,7 @@ function! vimwiki#lst#TO_list_item(inner, visual)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#lst#fold_level(lnum)
|
||||
function! vimwiki#lst#fold_level(lnum) abort
|
||||
let cur_item = s:get_item(a:lnum)
|
||||
if cur_item.type != 0
|
||||
let parent_item = s:get_parent(cur_item)
|
||||
|
Reference in New Issue
Block a user