clean up lst.vim, move functions around
no actual change in behavior or so
This commit is contained in:
parent
9821aaf528
commit
373ad1cee5
@ -83,14 +83,34 @@ endfunction "}}}
|
||||
|
||||
" incrementation functions for the various kinds of numbers }}}
|
||||
|
||||
" utility function {{{
|
||||
|
||||
function! s:substitute_rx_in_line(lnum, pattern, new_string) "{{{
|
||||
call setline(a:lnum, substitute(getline(a:lnum), a:pattern, a:new_string, ''))
|
||||
call setline(a:lnum, substitute(getline(a:lnum), a:pattern, a:new_string,
|
||||
\ ''))
|
||||
endfunction "}}}
|
||||
|
||||
function! s:substitute_string_in_line(lnum, pattern, new_string) "{{{
|
||||
call s:substitute_rx_in_line(a:lnum, vimwiki#u#escape(a:pattern), a:new_string)
|
||||
function! s:substitute_string_in_line(lnum, old_string, new_string) "{{{
|
||||
call s:substitute_rx_in_line(a:lnum, vimwiki#u#escape(a:old_string),
|
||||
\ a:new_string)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:first_char(string) "{{{
|
||||
return matchstr(a:string, '^.')
|
||||
endfunction "}}}
|
||||
|
||||
if exists("*strdisplaywidth") "{{{
|
||||
function! s:string_length(str)
|
||||
return strdisplaywidth(a:str)
|
||||
endfunction
|
||||
else
|
||||
function! s:string_length(str)
|
||||
return strlen(substitute(a:str, '.', 'x', 'g'))
|
||||
endfunction
|
||||
endif "}}}
|
||||
|
||||
"utility functions }}}
|
||||
|
||||
"Returns: the mainly used data structure in this file
|
||||
"An item represents a single list item and is a dictionary with the keys
|
||||
"lnum - the line number of the list item
|
||||
@ -103,13 +123,15 @@ function! s:get_item(lnum) "{{{
|
||||
let item.type = 0
|
||||
return item
|
||||
endif
|
||||
|
||||
let matches = matchlist(getline(a:lnum), g:vimwiki_rxListItem)
|
||||
if matches == [] || (matches[1] == '' && matches[2] == '') || (matches[1] != '' && matches[2] != '')
|
||||
if matches == [] ||
|
||||
\ (matches[1] == '' && matches[2] == '') ||
|
||||
\ (matches[1] != '' && matches[2] != '')
|
||||
let item.type = 0
|
||||
return item
|
||||
endif
|
||||
|
||||
|
||||
let item.cb = matches[3]
|
||||
|
||||
if matches[1] != ''
|
||||
@ -123,6 +145,10 @@ function! s:get_item(lnum) "{{{
|
||||
return item
|
||||
endfunction "}}}
|
||||
|
||||
function! s:empty_item() "{{{
|
||||
return {'type': 0}
|
||||
endfunction "}}}
|
||||
|
||||
"Returns: level of the line
|
||||
"0 is the 'highest' level
|
||||
function! s:get_level(lnum) "{{{
|
||||
@ -132,7 +158,7 @@ function! s:get_level(lnum) "{{{
|
||||
if VimwikiGet('syntax') != 'media'
|
||||
let level = indent(a:lnum)
|
||||
else
|
||||
let level = s:string_length(matchstr(getline(a:lnum), s:rx_bullet_chars)) - 1
|
||||
let level = s:string_length(matchstr(getline(a:lnum), s:rx_bullet_chars))-1
|
||||
if level < 0
|
||||
let level = (indent(a:lnum) == 0) ? 0 : 9999
|
||||
endif
|
||||
@ -155,15 +181,11 @@ function! s:regexp_of_marker(item) "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:empty_item() "{{{
|
||||
return {'type': 0}
|
||||
endfunction "}}}
|
||||
|
||||
"Returns: the list item after a:item in its list or empty item
|
||||
"If a:all is 1, the markers can differ
|
||||
function! s:get_next_list_item(item, all) "{{{
|
||||
"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) "{{{
|
||||
let org_lvl = s:get_level(a:item.lnum)
|
||||
if !a:all
|
||||
if !a:ignore_kind
|
||||
let org_regex = s:regexp_of_marker(a:item)
|
||||
endif
|
||||
|
||||
@ -171,7 +193,7 @@ function! s:get_next_list_item(item, all) "{{{
|
||||
while cur_ln <= line('$')
|
||||
let cur_lvl = s:get_level(cur_ln)
|
||||
if cur_lvl <= org_lvl
|
||||
if a:all
|
||||
if a:ignore_kind
|
||||
return s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl)
|
||||
else
|
||||
return s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex)
|
||||
@ -182,11 +204,11 @@ function! s:get_next_list_item(item, all) "{{{
|
||||
return s:empty_item()
|
||||
endfunction "}}}
|
||||
|
||||
"Returns: the list item before a:item in its list or empty item
|
||||
"If a:all is 1, the markers can differ
|
||||
function! s:get_prev_list_item(item, all) "{{{
|
||||
"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) "{{{
|
||||
let org_lvl = s:get_level(a:item.lnum)
|
||||
if !a:all
|
||||
if !a:ignore_kind
|
||||
let org_regex = s:regexp_of_marker(a:item)
|
||||
endif
|
||||
|
||||
@ -194,7 +216,7 @@ function! s:get_prev_list_item(item, all) "{{{
|
||||
while cur_ln >= 1
|
||||
let cur_lvl = s:get_level(cur_ln)
|
||||
if cur_lvl <= org_lvl
|
||||
if a:all
|
||||
if a:ignore_kind
|
||||
return s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl)
|
||||
else
|
||||
return s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex)
|
||||
@ -226,10 +248,6 @@ function! s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl) "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:first_char(string) "{{{
|
||||
return matchstr(a:string, '^.')
|
||||
endfunction "}}}
|
||||
|
||||
"Returns: 1, a, i, A, I or ''
|
||||
"If in doubt if alphanumeric character or romanian
|
||||
"numeral, peek in the previous line
|
||||
@ -291,11 +309,10 @@ function! s:guess_kind_of_numbered_item(item) "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
|
||||
function! s:get_first_item_in_list(item, all) "{{{
|
||||
function! s:get_first_item_in_list(item, ignore_kind) "{{{
|
||||
let cur_item = a:item
|
||||
while 1
|
||||
let prev_item = s:get_prev_list_item(cur_item, a:all)
|
||||
let prev_item = s:get_prev_list_item(cur_item, a:ignore_kind)
|
||||
if prev_item.type == 0
|
||||
break
|
||||
else
|
||||
@ -305,10 +322,10 @@ function! s:get_first_item_in_list(item, all) "{{{
|
||||
return cur_item
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_last_item_in_list(item, all) "{{{
|
||||
function! s:get_last_item_in_list(item, ignore_kind) "{{{
|
||||
let cur_item = a:item
|
||||
while 1
|
||||
let next_item = s:get_next_list_item(cur_item, a:all)
|
||||
let next_item = s:get_next_list_item(cur_item, a:ignore_kind)
|
||||
if next_item.type == 0
|
||||
break
|
||||
else
|
||||
@ -325,7 +342,8 @@ endfunction "}}}
|
||||
function! s:get_next_line(lnum, ...) "{{{
|
||||
if getline(a:lnum) =~# '^\s*'.g:vimwiki_rxPreStart
|
||||
let cur_ln = a:lnum + 1
|
||||
while cur_ln <= line('$') && getline(cur_ln) !~# '^\s*'.g:vimwiki_rxPreEnd.'\s*$'
|
||||
while cur_ln <= line('$') &&
|
||||
\ getline(cur_ln) !~# '^\s*'.g:vimwiki_rxPreEnd.'\s*$'
|
||||
let cur_ln += 1
|
||||
endwhile
|
||||
let next_line = nextnonblank(cur_ln+1)
|
||||
@ -337,7 +355,8 @@ function! s:get_next_line(lnum, ...) "{{{
|
||||
let next_line = s:get_next_line(next_line, 1)
|
||||
endif
|
||||
|
||||
if next_line < 0 || next_line > line('$') || (getline(next_line) =~# g:vimwiki_rxHeader && a:0 == 0)
|
||||
if next_line < 0 || next_line > line('$') ||
|
||||
\ (getline(next_line) =~# g:vimwiki_rxHeader && a:0 == 0)
|
||||
return 0
|
||||
endif
|
||||
|
||||
@ -360,7 +379,8 @@ function! s:get_prev_line(lnum) "{{{
|
||||
let prev_line = cur_ln
|
||||
endif
|
||||
|
||||
if prev_line < 0 || prev_line > line('$') || getline(prev_line) =~# g:vimwiki_rxHeader
|
||||
if prev_line < 0 || prev_line > line('$') ||
|
||||
\ getline(prev_line) =~# g:vimwiki_rxHeader
|
||||
return 0
|
||||
endif
|
||||
|
||||
@ -377,7 +397,8 @@ function! s:get_first_child(item) "{{{
|
||||
if cur_item.type != 0 && s:get_level(cur_item.lnum) > org_lvl
|
||||
return cur_item
|
||||
endif
|
||||
if cur_item.lnum > line('$') || cur_item.lnum <= 0 || s:get_level(cur_item.lnum) <= org_lvl
|
||||
if cur_item.lnum > line('$') || cur_item.lnum <= 0 ||
|
||||
\ s:get_level(cur_item.lnum) <= org_lvl
|
||||
return s:empty_item()
|
||||
endif
|
||||
let cur_item = s:get_item(s:get_next_line(cur_item.lnum))
|
||||
@ -406,6 +427,32 @@ function! s:get_next_child_item(parent, child) "{{{
|
||||
return s:empty_item()
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_parent(item) "{{{
|
||||
let parent_line = 0
|
||||
|
||||
let cur_ln = prevnonblank(a:item.lnum)
|
||||
let child_lvl = s:get_level(cur_ln)
|
||||
if child_lvl == 0
|
||||
return s:empty_item()
|
||||
endif
|
||||
|
||||
while 1
|
||||
let cur_ln = s:get_prev_line(cur_ln)
|
||||
if cur_ln == 0 | break | endif
|
||||
let cur_lvl = s:get_level(cur_ln)
|
||||
if cur_lvl < child_lvl
|
||||
let cur_item = s:get_item(cur_ln)
|
||||
if cur_item.type == 0
|
||||
let child_lvl = cur_lvl
|
||||
continue
|
||||
endif
|
||||
let parent_line = cur_ln
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
return s:get_item(parent_line)
|
||||
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) "{{{
|
||||
@ -457,34 +504,38 @@ function! s:adjust_items_recursively(parent) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
"Renumbers the list a:item is in.
|
||||
"If a:all == 0, only the items which have the same kind of marker as a:item are
|
||||
"considered, otherwise all items.
|
||||
"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, all, recursive) "{{{
|
||||
if !(a:item.type == 2 || (a:item.type == 1 && (a:all || a:recursive)))
|
||||
function! s:adjust_numbered_list(item, ignore_kind, recursive) "{{{
|
||||
if !(a:item.type == 2 || (a:item.type == 1 && (a:ignore_kind || a:recursive)))
|
||||
return s:empty_item()
|
||||
end
|
||||
|
||||
let first_item = s:get_first_item_in_list(a:item, a:all)
|
||||
let first_item = s:get_first_item_in_list(a:item, a:ignore_kind)
|
||||
|
||||
while 1
|
||||
if first_item.type == 2
|
||||
let new_mrkr = s:guess_kind_of_numbered_item(first_item) . first_item.mrkr[-1:]
|
||||
call s:substitute_string_in_line(first_item.lnum, first_item.mrkr, new_mrkr)
|
||||
let new_mrkr = s:guess_kind_of_numbered_item(first_item) .
|
||||
\ first_item.mrkr[-1:]
|
||||
call s:substitute_string_in_line(first_item.lnum, first_item.mrkr,
|
||||
\ new_mrkr)
|
||||
let first_item.mrkr = new_mrkr
|
||||
endif
|
||||
|
||||
let last_item = s:adjust_numbered_list_below(first_item, a:recursive)
|
||||
|
||||
let next_first_item = s:get_next_list_item(last_item, 1)
|
||||
if a:all == 0 || next_first_item.type == 0
|
||||
if a:ignore_kind == 0 || next_first_item.type == 0
|
||||
return last_item
|
||||
endif
|
||||
let first_item = next_first_item
|
||||
endwhile
|
||||
endfunction "}}}
|
||||
|
||||
"Returns: the (rounded) rate of checkboxed list item in percent
|
||||
"checkbox stuff {{{
|
||||
|
||||
"Returns: the rate of checkboxed list item in percent
|
||||
function! s:get_rate(item) "{{{
|
||||
if a:item.type == 0 || a:item.cb == ''
|
||||
return -1
|
||||
@ -523,6 +574,7 @@ function! s:set_state_plus_children(item, new_rate) "{{{
|
||||
endwhile
|
||||
endfunction "}}}
|
||||
|
||||
"Returns: the appropriate symbol for a given percent rate
|
||||
function! s:rate_to_state(rate) "{{{
|
||||
let state = ''
|
||||
if a:rate == 100
|
||||
@ -539,32 +591,8 @@ function! s:rate_to_state(rate) "{{{
|
||||
return state
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_parent(item) "{{{
|
||||
let parent_line = 0
|
||||
|
||||
let cur_ln = prevnonblank(a:item.lnum)
|
||||
let child_lvl = s:get_level(cur_ln)
|
||||
if child_lvl == 0
|
||||
return s:empty_item()
|
||||
endif
|
||||
|
||||
while 1
|
||||
let cur_ln = s:get_prev_line(cur_ln)
|
||||
if cur_ln == 0 | break | endif
|
||||
let cur_lvl = s:get_level(cur_ln)
|
||||
if cur_lvl < child_lvl
|
||||
let cur_item = s:get_item(cur_ln)
|
||||
if cur_item.type == 0
|
||||
let child_lvl = cur_lvl
|
||||
continue
|
||||
endif
|
||||
let parent_line = cur_ln
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
return s:get_item(parent_line)
|
||||
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 == ''
|
||||
return
|
||||
@ -613,12 +641,24 @@ function! s:create_cb(item) "{{{
|
||||
|
||||
let new_item = a:item
|
||||
let new_item.cb = g:vimwiki_listsyms[0]
|
||||
call s:substitute_rx_in_line(new_item.lnum, vimwiki#u#escape(new_item.mrkr) . '\zs\ze', ' [' . new_item.cb . ']')
|
||||
call s:substitute_rx_in_line(new_item.lnum,
|
||||
\ vimwiki#u#escape(new_item.mrkr) . '\zs\ze', ' [' . new_item.cb . ']')
|
||||
|
||||
call s:update_state(new_item)
|
||||
return 1
|
||||
endfunction "}}}
|
||||
|
||||
function! s:remove_cb(item) "{{{
|
||||
let item = a:item
|
||||
if item.type != 0 && item.cb != ''
|
||||
let item.cb = ''
|
||||
call s:substitute_rx_in_line(item.lnum, '\s\+\[.\]', '')
|
||||
endif
|
||||
return item
|
||||
endfunction "}}}
|
||||
|
||||
"checkbox stuff }}}
|
||||
|
||||
"Returns: the item if there is one in a:lnum
|
||||
"else the multiline item a:lnum belongs to
|
||||
function! s:get_corresponding_item(lnum) "{{{
|
||||
@ -656,7 +696,7 @@ function! s:get_last_line_of_item_incl_children(item) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
"Returns: the last line of a (possibly multiline) item
|
||||
"Note: there can be other list items inbetween these lines
|
||||
"Note: there can be other list items inbetween the first and last lines
|
||||
function! s:get_last_line_of_item(item) "{{{
|
||||
if a:item.type == 0 | return 0 | endif
|
||||
let org_lvl = s:get_level(a:item.lnum)
|
||||
@ -672,7 +712,8 @@ function! s:get_last_line_of_item(item) "{{{
|
||||
let last_corresponding_line = cur_ln
|
||||
let cur_ln = s:get_next_line(cur_ln)
|
||||
else
|
||||
let cur_ln = s:get_next_line(s:get_last_line_of_item_incl_children(cur_item))
|
||||
let cur_ln = s:get_next_line(
|
||||
\ s:get_last_line_of_item_incl_children(cur_item))
|
||||
endif
|
||||
endwhile
|
||||
|
||||
@ -685,16 +726,6 @@ function! s:text_begin(lnum) "{{{
|
||||
return s:string_length(matchstr(getline(a:lnum), g:vimwiki_rxListItem))
|
||||
endfunction "}}}
|
||||
|
||||
if exists("*strdisplaywidth") "{{{
|
||||
function! s:string_length(str)
|
||||
return strdisplaywidth(a:str)
|
||||
endfunction
|
||||
else
|
||||
function! s:string_length(str)
|
||||
return strlen(substitute(a:str, '.', 'x', 'g'))
|
||||
endfunction
|
||||
endif "}}}
|
||||
|
||||
"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)
|
||||
@ -709,7 +740,7 @@ function! s:line_has_marker(lnum) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
"Renumbers the list the cursor is in
|
||||
"also update its parents state
|
||||
"also update its parents checkbox state
|
||||
function! vimwiki#lst#adjust_numbered_list() "{{{
|
||||
let cur_item = s:get_corresponding_item(line('.'))
|
||||
if cur_item.type == 0 | return | endif
|
||||
@ -733,7 +764,8 @@ function! vimwiki#lst#adjust_whole_buffer() "{{{
|
||||
endwhile
|
||||
endfunction "}}}
|
||||
|
||||
"Toggle checkbox between [ ] and [X] or creates one
|
||||
"Toggles checkbox between [ ] and [X] or creates one
|
||||
"in the lines of the given range
|
||||
function! vimwiki#lst#toggle_cb(line1, line2) "{{{
|
||||
let from_item = s:get_corresponding_item(a:line1)
|
||||
let to_item = s:get_corresponding_item(a:line2)
|
||||
@ -784,6 +816,7 @@ function! vimwiki#lst#toggle_cb(line1, line2) "{{{
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
"Returns: the position of a marker in g:vimwiki_list_markers
|
||||
function! s:get_idx_list_markers(item) "{{{
|
||||
if a:item.type == 1
|
||||
let m = s:first_char(a:item.mrkr)
|
||||
@ -793,16 +826,18 @@ function! s:get_idx_list_markers(item) "{{{
|
||||
return index(g:vimwiki_list_markers, m)
|
||||
endfunction "}}}
|
||||
|
||||
"changes the marker of the given item to the next in g:vimwiki_list_markers
|
||||
function! s:get_next_mrkr(item) "{{{
|
||||
if a:item.type == 0
|
||||
let new_mrkr = g:vimwiki_list_markers[0]
|
||||
else
|
||||
let idx = s:get_idx_list_markers(a:item)
|
||||
let new_mrkr = g:vimwiki_list_markers[(idx + 1) % len(g:vimwiki_list_markers)]
|
||||
let new_mrkr = g:vimwiki_list_markers[(idx+1) % len(g:vimwiki_list_markers)]
|
||||
endif
|
||||
return new_mrkr
|
||||
endfunction "}}}
|
||||
|
||||
"changes the marker of the given item to the previous in g:vimwiki_list_markers
|
||||
function! s:get_prev_mrkr(item) "{{{
|
||||
if a:item.type == 0
|
||||
return g:vimwiki_list_markers[-1]
|
||||
@ -811,7 +846,8 @@ function! s:get_prev_mrkr(item) "{{{
|
||||
if idx == -1
|
||||
return g:vimwiki_list_markers[-1]
|
||||
else
|
||||
return g:vimwiki_list_markers[(idx - 1 + len(g:vimwiki_list_markers)) % len(g:vimwiki_list_markers)]
|
||||
return g:vimwiki_list_markers[(idx - 1 + len(g:vimwiki_list_markers)) %
|
||||
\ len(g:vimwiki_list_markers)]
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
@ -843,22 +879,27 @@ function! vimwiki#lst#change_marker(line1, line2, new_mrkr, mode) "{{{
|
||||
if index(s:multiple_bullet_chars, s:first_char(new_mrkr)) > -1
|
||||
"use *** if the item above has *** too
|
||||
let item_above = s:get_prev_list_item(cur_item, 1)
|
||||
if item_above.type == 1 && s:first_char(item_above.mrkr) == s:first_char(new_mrkr)
|
||||
if item_above.type == 1 &&
|
||||
\ s:first_char(item_above.mrkr) ==s:first_char(new_mrkr)
|
||||
let new_mrkr = item_above.mrkr
|
||||
else
|
||||
"use *** if the item below has *** too
|
||||
let item_below = s:get_next_list_item(cur_item, 1)
|
||||
if item_below.type == 1 && s:first_char(item_below.mrkr) == s:first_char(new_mrkr)
|
||||
if item_below.type == 1 &&
|
||||
\ s:first_char(item_below.mrkr) == s:first_char(new_mrkr)
|
||||
let new_mrkr = item_below.mrkr
|
||||
else
|
||||
"if the old is ### and the new is * use ***
|
||||
if cur_item.type == 1 && index(s:multiple_bullet_chars, s:first_char(cur_item.mrkr)) > -1
|
||||
if cur_item.type == 1 &&
|
||||
\ index(s:multiple_bullet_chars,s:first_char(cur_item.mrkr))>-1
|
||||
let new_mrkr = repeat(new_mrkr, s:string_length(cur_item.mrkr))
|
||||
else
|
||||
"use *** if the parent item has **
|
||||
let parent_item = s:get_parent(cur_item)
|
||||
if parent_item.type == 1 && s:first_char(parent_item.mrkr) == s:first_char(new_mrkr)
|
||||
let new_mrkr = repeat(s:first_char(parent_item.mrkr), s:string_length(parent_item.mrkr)+1)
|
||||
if parent_item.type == 1 &&
|
||||
\ s:first_char(parent_item.mrkr) == s:first_char(new_mrkr)
|
||||
let new_mrkr = repeat(s:first_char(parent_item.mrkr),
|
||||
\ s:string_length(parent_item.mrkr)+1)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@ -876,15 +917,6 @@ function! vimwiki#lst#change_marker(line1, line2, new_mrkr, mode) "{{{
|
||||
call cursor('.', col('$') - cur_col_from_eol)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:remove_cb(item) "{{{
|
||||
let item = a:item
|
||||
if item.type != 0 && item.cb != ''
|
||||
let item.cb = ''
|
||||
call s:substitute_rx_in_line(item.lnum, '\s\+\[.\]', '')
|
||||
endif
|
||||
return item
|
||||
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)
|
||||
@ -913,7 +945,8 @@ function! vimwiki#lst#remove_cb(first_line, last_line) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#lst#remove_cb_in_list() "{{{
|
||||
let first_item = s:get_first_item_in_list(s:get_corresponding_item(line('.')), 0)
|
||||
let first_item = s:get_first_item_in_list(
|
||||
\ s:get_corresponding_item(line('.')), 0)
|
||||
|
||||
let cur_item = first_item
|
||||
while 1
|
||||
@ -949,7 +982,8 @@ function! s:set_indent(lnum, new_indent) "{{{
|
||||
if &expandtab
|
||||
let indentstring = repeat(' ', a:new_indent)
|
||||
else
|
||||
let indentstring = repeat('\t', a:new_indent / &tabstop) . repeat(' ', a:new_indent % &tabstop)
|
||||
let indentstring = repeat('\t', a:new_indent / &tabstop) .
|
||||
\ repeat(' ', a:new_indent % &tabstop)
|
||||
endif
|
||||
call s:substitute_rx_in_line(a:lnum, '^\s*', indentstring)
|
||||
endfunction "}}}
|
||||
@ -959,7 +993,8 @@ function! s:decrease_level(item) "{{{
|
||||
if VimwikiGet('syntax') == 'media' && a:item.type == 1 &&
|
||||
\ index(s:multiple_bullet_chars, s:first_char(a:item.mrkr)) > -1
|
||||
if s:string_length(a:item.mrkr) >= 2
|
||||
call s:substitute_string_in_line(a:item.lnum, s:first_char(a:item.mrkr), '')
|
||||
call s:substitute_string_in_line(a:item.lnum,
|
||||
\ s:first_char(a:item.mrkr), '')
|
||||
let removed_indent = -1
|
||||
endif
|
||||
else
|
||||
@ -979,7 +1014,8 @@ function! s:increase_level(item) "{{{
|
||||
let additional_space = 0
|
||||
if VimwikiGet('syntax') == 'media' && a:item.type == 1 &&
|
||||
\ index(s:multiple_bullet_chars, s:first_char(a:item.mrkr)) > -1
|
||||
call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, a:item.mrkr . s:first_char(a:item.mrkr))
|
||||
call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, a:item.mrkr .
|
||||
\ s:first_char(a:item.mrkr))
|
||||
let additional_indent = 1
|
||||
else
|
||||
let old_indent = indent(a:item.lnum)
|
||||
@ -1001,7 +1037,8 @@ function! s:indent_line_by(lnum, indent_by) "{{{
|
||||
if VimwikiGet('syntax') == 'media' && item.type == 1 &&
|
||||
\ index(s:multiple_bullet_chars, s:first_char(item.mrkr)) > -1
|
||||
if a:indent_by > 0
|
||||
call s:substitute_string_in_line(a:lnum, item.mrkr, item.mrkr . s:first_char(item.mrkr))
|
||||
call s:substitute_string_in_line(a:lnum, item.mrkr,
|
||||
\ item.mrkr . s:first_char(item.mrkr))
|
||||
elseif a:indent_by < 0
|
||||
call s:substitute_string_in_line(a:lnum, s:first_char(item.mrkr), '')
|
||||
endif
|
||||
@ -1040,8 +1077,10 @@ function! s:adjust_mrkr(item) "{{{
|
||||
if neighbor_item.type == 0 && a:item.type == 1 &&
|
||||
\ index(s:multiple_bullet_chars, s:first_char(a:item.mrkr)) > -1
|
||||
let parent_item = s:get_parent(a:item)
|
||||
if parent_item.type == 1 && s:first_char(parent_item.mrkr) == s:first_char(a:item.mrkr)
|
||||
let new_mrkr = repeat(s:first_char(parent_item.mrkr), s:string_length(parent_item.mrkr)+1)
|
||||
if parent_item.type == 1 &&
|
||||
\ s:first_char(parent_item.mrkr) == s:first_char(a:item.mrkr)
|
||||
let new_mrkr = repeat(s:first_char(parent_item.mrkr),
|
||||
\ s:string_length(parent_item.mrkr)+1)
|
||||
endif
|
||||
endif
|
||||
|
||||
@ -1053,11 +1092,12 @@ endfunction "}}}
|
||||
function! s:change_level(from_line, to_line, direction, plus_children) "{{{
|
||||
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))
|
||||
if a:direction == 'increase' && a:from_line == a:to_line &&
|
||||
\ empty(getline(a:from_line))
|
||||
"that's because :> doesn't work on an empty line
|
||||
normal! gi
|
||||
else
|
||||
execute a:from_line.','.a:to_line. (a:direction == 'increase' ? '>' : '<')
|
||||
execute a:from_line.','.a:to_line.(a:direction == 'increase' ? '>' : '<')
|
||||
endif
|
||||
return
|
||||
endif
|
||||
@ -1080,11 +1120,15 @@ function! s:change_level(from_line, to_line, direction, plus_children) "{{{
|
||||
let first_line_level = s:get_level(from_item.lnum)
|
||||
let more_than_one_level_concerned = 0
|
||||
|
||||
let first_line_indented_by = (a:direction == 'increase') ? s:increase_level(from_item) : s:decrease_level(from_item)
|
||||
let first_line_indented_by =
|
||||
\ (a:direction == 'increase') ?
|
||||
\ s:increase_level(from_item) : s:decrease_level(from_item)
|
||||
|
||||
let cur_ln = s:get_next_line(from_item.lnum)
|
||||
while cur_ln > 0 && cur_ln <= to_line
|
||||
if !more_than_one_level_concerned && s:get_level(cur_ln) != first_line_level && s:get_item(cur_ln).type != 0
|
||||
if !more_than_one_level_concerned &&
|
||||
\ s:get_level(cur_ln) != first_line_level &&
|
||||
\ s:get_item(cur_ln).type != 0
|
||||
let more_than_one_level_concerned = 1
|
||||
endif
|
||||
call s:indent_line_by(cur_ln, first_line_indented_by)
|
||||
@ -1342,7 +1386,8 @@ function! vimwiki#lst#toggle_list_item() "{{{
|
||||
let prev_item = s:get_corresponding_item(s:get_prev_line(cur_item.lnum))
|
||||
endif
|
||||
let cur_item = s:remove_mrkr(cur_item)
|
||||
let adjust_prev_item = (prev_item.type == 2 && s:get_level(cur_item.lnum) <= s:get_level(prev_item.lnum)) ? 1 : 0
|
||||
let adjust_prev_item = (prev_item.type == 2 &&
|
||||
\ s:get_level(cur_item.lnum) <= s:get_level(prev_item.lnum)) ? 1 : 0
|
||||
call s:indent_multiline(prev_item, cur_item.lnum)
|
||||
if adjust_prev_item
|
||||
call s:adjust_numbered_list_below(prev_item, 0)
|
||||
@ -1389,19 +1434,22 @@ function! vimwiki#lst#setup_marker_infos() "{{{
|
||||
let s:number_divisors .= vimwiki#u#escape(i[1])
|
||||
endfor
|
||||
|
||||
let s:char_to_rx = {'1': '\d\+', 'i': '[ivxlcdm]\+', 'I': '[IVXLCDM]\+', 'a': '\l\{1,2}', 'A': '\u\{1,2}'}
|
||||
let s:char_to_rx = {'1': '\d\+', 'i': '[ivxlcdm]\+', 'I': '[IVXLCDM]\+',
|
||||
\ 'a': '\l\{1,2}', 'A': '\u\{1,2}'}
|
||||
|
||||
"create regexp for bulleted list items
|
||||
let g:vimwiki_rxListBullet = join( map(keys(g:vimwiki_bullet_types),
|
||||
\ 'vimwiki#u#escape(v:val) . repeat("\\+", g:vimwiki_bullet_types[v:val])') , '\|')
|
||||
\'vimwiki#u#escape(v:val).repeat("\\+", g:vimwiki_bullet_types[v:val])'
|
||||
\ ) , '\|')
|
||||
|
||||
"create regex for numbered list items
|
||||
if !empty(g:vimwiki_number_types)
|
||||
let g:vimwiki_rxListNumber = '\C\%('
|
||||
for type in g:vimwiki_number_types[:-2]
|
||||
let g:vimwiki_rxListNumber .= s:char_to_rx[type[0]] . vimwiki#u#escape(type[1]) . '\|'
|
||||
let g:vimwiki_rxListNumber .= s:char_to_rx[type[0]] .
|
||||
\ vimwiki#u#escape(type[1]) . '\|'
|
||||
endfor
|
||||
let g:vimwiki_rxListNumber .= s:char_to_rx[g:vimwiki_number_types[-1][0]] .
|
||||
let g:vimwiki_rxListNumber .= s:char_to_rx[g:vimwiki_number_types[-1][0]].
|
||||
\ vimwiki#u#escape(g:vimwiki_number_types[-1][1]) . '\)'
|
||||
else
|
||||
"regex that matches nothing
|
||||
@ -1440,6 +1488,9 @@ fun! vimwiki#lst#fold_level(lnum) "{{{
|
||||
return 's1'
|
||||
endif
|
||||
endif
|
||||
return '='
|
||||
endfu
|
||||
|
||||
|
||||
return '='
|
||||
endf "}}}
|
||||
|
Loading…
Reference in New Issue
Block a user