commit 072ba175f73a2a8b7c9cd850c830e12ee0a6342e
parent 19e4cf90ef86d1b150da9565360220a9cd6e8143
Author: EinfachToll <istjanichtzufassen@googlemail.de>
Date: Mon, 6 Jan 2014 13:30:33 +0100
More functions moved around
Diffstat:
1 file changed, 427 insertions(+), 408 deletions(-)
diff --git a/autoload/vimwiki/lst.vim b/autoload/vimwiki/lst.vim
@@ -9,7 +9,7 @@ if exists("g:loaded_vimwiki_list_auto") || &cp
endif
let g:loaded_vimwiki_list_auto = 1
-" incrementation functions for the various kinds of numbers {{{
+"incrementation functions for the various kinds of numbers {{{
function! s:increment_1(value) "{{{
return eval(a:value) + 1
@@ -81,9 +81,9 @@ function! s:increment_i(value) "{{{
return ''
endfunction "}}}
-" incrementation functions for the various kinds of numbers }}}
+"incrementation functions for the various kinds of numbers }}}
-" utility function {{{
+"utility functions {{{
function! s:substitute_rx_in_line(lnum, pattern, new_string) "{{{
call setline(a:lnum, substitute(getline(a:lnum), a:pattern, a:new_string,
@@ -109,8 +109,41 @@ else
endfunction
endif "}}}
+function! vimwiki#lst#default_symbol() "{{{
+ return g:vimwiki_list_markers[0]
+endfunction "}}}
+
+function! vimwiki#lst#get_list_margin() "{{{
+ if VimwikiGet('list_margin') < 0
+ return &sw
+ else
+ return VimwikiGet('list_margin')
+ endif
+endfunction "}}}
+
+"Returns: the column where the text of a line starts (possible list item
+"markers and checkboxes are skipped)
+function! s:text_begin(lnum) "{{{
+ return s:string_length(matchstr(getline(a:lnum), g:vimwiki_rxListItem))
+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) "{{{
+ if getline(a:lnum) =~# g:vimwiki_rxListItem.'\s*$'
+ return 1
+ elseif getline(a:lnum) =~# g:vimwiki_rxListItem.'\s*\S'
+ return 2
+ else
+ return 0
+ endif
+endfunction "}}}
+
"utility functions }}}
+"get properties of an item {{{
+
"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
@@ -166,6 +199,67 @@ function! s:get_level(lnum) "{{{
return level
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) "{{{
+ if a:item.type != 2 | return '' | endif
+ let number_chars = a:item.mrkr[:-2]
+ let divisor = a:item.mrkr[-1:]
+
+ if number_chars =~ '\d\+'
+ return '1'
+ endif
+ if number_chars =~# '\l\+'
+ if number_chars !~# '^[ivxlcdm]\+' || index(s:number_kinds, 'i') == -1
+ return 'a'
+ else
+
+ let item_above = s:get_prev_list_item(a:item, 0)
+ if item_above.type != 0
+ if index(s:number_kinds, 'a') == -1 ||
+ \ (item_above.mrkr[-1:] !=# divisor && number_chars =~# 'i\+') ||
+ \ s:increment_i(item_above.mrkr[:-2]) ==# number_chars
+ return 'i'
+ else
+ return 'a'
+ endif
+ else
+ if number_chars =~# 'i\+' || index(s:number_kinds, 'a') == -1
+ return 'i'
+ else
+ return 'a'
+ endif
+ endif
+
+ endif
+ endif
+ if number_chars =~# '\u\+'
+ if number_chars !~# '^[IVXLCDM]\+' || index(s:number_kinds, 'I') == -1
+ return 'A'
+ else
+
+ let item_above = s:get_prev_list_item(a:item, 0)
+ if item_above.type != 0
+ if index(s:number_kinds, 'A') == -1 ||
+ \ (item_above.mrkr[-1:] !=# divisor && number_chars =~# 'I\+') ||
+ \ s:increment_I(item_above.mrkr[:-2]) ==# number_chars
+ return 'I'
+ else
+ return 'A'
+ endif
+ else
+ if number_chars =~# 'I\+' || index(s:number_kinds, 'A') == -1
+ return 'I'
+ else
+ return 'A'
+ endif
+ endif
+
+ endif
+ endif
+endfunction "}}}
+
function! s:regexp_of_marker(item) "{{{
if a:item.type == 1
return vimwiki#u#escape(a:item.mrkr)
@@ -181,6 +275,10 @@ function! s:regexp_of_marker(item) "{{{
endif
endfunction "}}}
+"get properties of an item }}}
+
+"functions for navigating between items {{{
+
"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) "{{{
@@ -248,67 +346,6 @@ function! s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl) "{{{
endif
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) "{{{
- if a:item.type != 2 | return '' | endif
- let number_chars = a:item.mrkr[:-2]
- let divisor = a:item.mrkr[-1:]
-
- if number_chars =~ '\d\+'
- return '1'
- endif
- if number_chars =~# '\l\+'
- if number_chars !~# '^[ivxlcdm]\+' || index(s:number_kinds, 'i') == -1
- return 'a'
- else
-
- let item_above = s:get_prev_list_item(a:item, 0)
- if item_above.type != 0
- if index(s:number_kinds, 'a') == -1 ||
- \ (item_above.mrkr[-1:] !=# divisor && number_chars =~# 'i\+') ||
- \ s:increment_i(item_above.mrkr[:-2]) ==# number_chars
- return 'i'
- else
- return 'a'
- endif
- else
- if number_chars =~# 'i\+' || index(s:number_kinds, 'a') == -1
- return 'i'
- else
- return 'a'
- endif
- endif
-
- endif
- endif
- if number_chars =~# '\u\+'
- if number_chars !~# '^[IVXLCDM]\+' || index(s:number_kinds, 'I') == -1
- return 'A'
- else
-
- let item_above = s:get_prev_list_item(a:item, 0)
- if item_above.type != 0
- if index(s:number_kinds, 'A') == -1 ||
- \ (item_above.mrkr[-1:] !=# divisor && number_chars =~# 'I\+') ||
- \ s:increment_I(item_above.mrkr[:-2]) ==# number_chars
- return 'I'
- else
- return 'A'
- endif
- else
- if number_chars =~# 'I\+' || index(s:number_kinds, 'A') == -1
- return 'I'
- else
- return 'A'
- endif
- endif
-
- endif
- endif
-endfunction "}}}
-
function! s:get_first_item_in_list(item, ignore_kind) "{{{
let cur_item = a:item
while 1
@@ -453,6 +490,95 @@ function! s:get_parent(item) "{{{
return s:get_item(parent_line)
endfunction "}}}
+"Returns: the item above or the item below or an empty item
+function! s:get_a_neighbor_item(item) "{{{
+ let prev_item = s:get_prev_list_item(a:item, 1)
+ if prev_item.type != 0
+ return prev_item
+ else
+ let next_item = s:get_next_list_item(a:item, 1)
+ if next_item.type != 0
+ return next_item
+ endif
+ endif
+ return s:empty_item()
+endfunction "}}}
+
+function! s:get_a_neighbor_item_in_column(lnum, column) "{{{
+ let cur_ln = s:get_prev_line(a:lnum)
+ while cur_ln >= 1
+ if s:get_level(cur_ln) <= a:column
+ return s:get_corresponding_item(cur_ln)
+ endif
+ let cur_ln = s:get_prev_line(cur_ln)
+ endwhile
+ return s:empty_item()
+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) "{{{
+ let item = s:get_item(a:lnum)
+ if item.type != 0
+ return item
+ endif
+ let org_lvl = s:get_level(a:lnum)
+ let cur_ln = a:lnum
+ while cur_ln > 0
+ let cur_lvl = s:get_level(cur_ln)
+ let cur_item = s:get_item(cur_ln)
+ if cur_lvl < org_lvl && cur_item.type != 0
+ return cur_item
+ endif
+ if cur_lvl < org_lvl
+ let org_lvl = cur_lvl
+ endif
+ let cur_ln = s:get_prev_line(cur_ln)
+ endwhile
+ return s:empty_item()
+endfunction "}}}
+
+"Returns: the last line of a (possibly multiline) item, including all children
+function! s:get_last_line_of_item_incl_children(item) "{{{
+ let cur_ln = a:item.lnum
+ let org_lvl = s:get_level(a:item.lnum)
+ while 1
+ let next_line = s:get_next_line(cur_ln)
+ if next_line == 0 || s:get_level(next_line) <= org_lvl
+ return cur_ln
+ endif
+ let cur_ln = next_line
+ endwhile
+endfunction "}}}
+
+"Returns: the last line of a (possibly multiline) item
+"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)
+ let last_corresponding_line = a:item.lnum
+
+ let cur_ln = s:get_next_line(a:item.lnum)
+ while 1
+ if cur_ln == 0 || s:get_level(cur_ln) <= org_lvl
+ break
+ endif
+ let cur_item = s:get_item(cur_ln)
+ if cur_item.type == 0
+ 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))
+ endif
+ endwhile
+
+ return last_corresponding_line
+endfunction "}}}
+
+"functions for navigating between items }}}
+
+"renumber list items {{{
"Renumbers the current list from a:item on downwards
"Returns: the last item that was adjusted
function! s:adjust_numbered_list_below(item, recursive) "{{{
@@ -533,12 +659,39 @@ function! s:adjust_numbered_list(item, ignore_kind, recursive) "{{{
endwhile
endfunction "}}}
-"checkbox stuff {{{
+"Renumbers the list the cursor is in
+"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
+ call s:adjust_numbered_list(cur_item, 1, 0)
+ call s:update_state(s:get_parent(cur_item))
+endfunction "}}}
-"Returns: the rate of checkboxed list item in percent
-function! s:get_rate(item) "{{{
- if a:item.type == 0 || a:item.cb == ''
- return -1
+"Renumbers all lists of the buffer
+"of course, this might take some seconds
+function! vimwiki#lst#adjust_whole_buffer() "{{{
+ let cur_ln = 1
+ while 1
+ let cur_item = s:get_item(cur_ln)
+ if cur_item.type != 0
+ let cur_item = s:adjust_numbered_list(cur_item, 0, 1)
+ endif
+ let cur_ln = s:get_next_line(cur_item.lnum, 1)
+ if cur_ln <= 0 || cur_ln > line('$')
+ return
+ endif
+ endwhile
+endfunction "}}}
+
+"renumber list items }}}
+
+"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
endif
let state = a:item.cb
return index(g:vimwiki_listsyms, state) * 25
@@ -657,113 +810,6 @@ function! s:remove_cb(item) "{{{
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) "{{{
- let item = s:get_item(a:lnum)
- if item.type != 0
- return item
- endif
- let org_lvl = s:get_level(a:lnum)
- let cur_ln = a:lnum
- while cur_ln > 0
- let cur_lvl = s:get_level(cur_ln)
- let cur_item = s:get_item(cur_ln)
- if cur_lvl < org_lvl && cur_item.type != 0
- return cur_item
- endif
- if cur_lvl < org_lvl
- let org_lvl = cur_lvl
- endif
- let cur_ln = s:get_prev_line(cur_ln)
- endwhile
- return s:empty_item()
-endfunction "}}}
-
-"Returns: the last line of a (possibly multiline) item, including all children
-function! s:get_last_line_of_item_incl_children(item) "{{{
- let cur_ln = a:item.lnum
- let org_lvl = s:get_level(a:item.lnum)
- while 1
- let next_line = s:get_next_line(cur_ln)
- if next_line == 0 || s:get_level(next_line) <= org_lvl
- return cur_ln
- endif
- let cur_ln = next_line
- endwhile
-endfunction "}}}
-
-"Returns: the last line of a (possibly multiline) item
-"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)
- let last_corresponding_line = a:item.lnum
-
- let cur_ln = s:get_next_line(a:item.lnum)
- while 1
- if cur_ln == 0 || s:get_level(cur_ln) <= org_lvl
- break
- endif
- let cur_item = s:get_item(cur_ln)
- if cur_item.type == 0
- 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))
- endif
- endwhile
-
- return last_corresponding_line
-endfunction "}}}
-
-"Returns: the column where the text of a line starts (possible list item
-"markers and checkboxes are skipped)
-function! s:text_begin(lnum) "{{{
- return s:string_length(matchstr(getline(a:lnum), g:vimwiki_rxListItem))
-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) "{{{
- if getline(a:lnum) =~# g:vimwiki_rxListItem.'\s*$'
- return 1
- elseif getline(a:lnum) =~# g:vimwiki_rxListItem.'\s*\S'
- return 2
- else
- return 0
- endif
-endfunction "}}}
-
-"Renumbers the list the cursor is in
-"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
- call s:adjust_numbered_list(cur_item, 1, 0)
- call s:update_state(s:get_parent(cur_item))
-endfunction "}}}
-
-"Renumbers all lists of the buffer
-"of course, this might take some seconds
-function! vimwiki#lst#adjust_whole_buffer() "{{{
- let cur_ln = 1
- while 1
- let cur_item = s:get_item(cur_ln)
- if cur_item.type != 0
- let cur_item = s:adjust_numbered_list(cur_item, 0, 1)
- endif
- let cur_ln = s:get_next_line(cur_item.lnum, 1)
- if cur_ln <= 0 || cur_ln > line('$')
- return
- endif
- endwhile
-endfunction "}}}
-
"Toggles checkbox between [ ] and [X] or creates one
"in the lines of the given range
function! vimwiki#lst#toggle_cb(line1, line2) "{{{
@@ -816,107 +862,6 @@ 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)
- else
- let m = s:guess_kind_of_numbered_item(a:item) . a:item.mrkr[-1:]
- endif
- 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)]
- 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]
- endif
- let idx = s:get_idx_list_markers(a: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)]
- endif
-endfunction "}}}
-
-function! s:set_new_mrkr(item, new_mrkr) "{{{
- 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 && VimwikiGet('syntax') != 'media'
- call s:set_indent(a:item.lnum, vimwiki#lst#get_list_margin())
- endif
- else
- call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, a:new_mrkr)
- endif
-endfunction "}}}
-
-function! vimwiki#lst#change_marker(line1, line2, new_mrkr, mode) "{{{
- let cur_col_from_eol = col("$") - (a:mode == "i" ? col("'^") : col('.'))
- let new_mrkr = a:new_mrkr
- let cur_ln = a:line1
- while 1
- let cur_item = s:get_item(cur_ln)
-
- if new_mrkr ==# "next"
- let new_mrkr = s:get_next_mrkr(cur_item)
- elseif new_mrkr ==# "prev"
- let new_mrkr = s:get_prev_mrkr(cur_item)
- endif
-
- "handle markers like ***
- 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)
- 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)
- 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
- 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)
- endif
- endif
- endif
- endif
-
- endif
-
- call s:set_new_mrkr(cur_item, new_mrkr)
- call s:adjust_numbered_list(s:get_item(cur_ln), 1, 0)
-
- if cur_ln >= a:line2 | break | endif
- let cur_ln = s:get_next_line(cur_ln, 1)
- endwhile
-
- call cursor('.', col('$') - cur_col_from_eol)
-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)
@@ -962,21 +907,9 @@ function! vimwiki#lst#remove_cb_in_list() "{{{
call s:update_state(s:get_parent(first_item))
endfunction "}}}
-function! vimwiki#lst#change_marker_in_list(new_mrkr) "{{{
- 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)
- if first_item.type == 0 || last_item.type == 0 | return | endif
- let first_item_line = first_item.lnum
-
- let cur_item = first_item
- while cur_item.type != 0 && cur_item.lnum <= last_item.lnum
- call s:set_new_mrkr(cur_item, a:new_mrkr)
- let cur_item = s:get_next_list_item(cur_item, 1)
- endwhile
+"checkbox stuff }}}
- call s:adjust_numbered_list(s:get_item(first_item_line), 0, 0)
-endfunction "}}}
+"change the level of list items {{{
function! s:set_indent(lnum, new_indent) "{{{
if &expandtab
@@ -1027,65 +960,24 @@ function! s:increase_level(item) "{{{
call s:set_indent(a:item.lnum, new_indent)
let additional_indent = new_indent - old_indent
endif
- return additional_indent
-endfunction "}}}
-
-"adds a:indent_by to the current indent
-"a:indent_by can be negative
-function! s:indent_line_by(lnum, indent_by) "{{{
- let item = s:get_item(a:lnum)
- 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))
- elseif a:indent_by < 0
- call s:substitute_string_in_line(a:lnum, s:first_char(item.mrkr), '')
- endif
- else
- call s:set_indent(a:lnum, indent(a:lnum) + a:indent_by)
- endif
-endfunction "}}}
-
-"Returns: the item above or the item below or an empty item
-function! s:get_a_neighbor_item(item) "{{{
- let prev_item = s:get_prev_list_item(a:item, 1)
- if prev_item.type != 0
- return prev_item
- else
- let next_item = s:get_next_list_item(a:item, 1)
- if next_item.type != 0
- return next_item
- endif
- endif
- return s:empty_item()
-endfunction "}}}
-
-"sets kind of the item depending on neighbor items and the parent item
-function! s:adjust_mrkr(item) "{{{
- if a:item.type == 0 || VimwikiGet('syntax') == 'media'
- return
- endif
-
- let new_mrkr = a:item.mrkr
- let neighbor_item = s:get_a_neighbor_item(a:item)
- if neighbor_item.type != 0
- let new_mrkr = neighbor_item.mrkr
- endif
-
- "if possible, set e.g. *** if parent has ** as marker
- 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)
- endif
- endif
+ return additional_indent
+endfunction "}}}
- call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, new_mrkr)
- call s:adjust_numbered_list(a:item, 0, 1)
+"adds a:indent_by to the current indent
+"a:indent_by can be negative
+function! s:indent_line_by(lnum, indent_by) "{{{
+ let item = s:get_item(a:lnum)
+ 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))
+ elseif a:indent_by < 0
+ call s:substitute_string_in_line(a:lnum, s:first_char(item.mrkr), '')
+ endif
+ else
+ call s:set_indent(a:lnum, indent(a:lnum) + a:indent_by)
+ endif
endfunction "}}}
"changes lvl of lines in selection
@@ -1159,6 +1051,159 @@ function! vimwiki#lst#change_level(from_line, to_line, direction, plus_children)
call cursor('.', col('$') - cur_col)
endfunction "}}}
+"indent line a:lnum to be the continuation of a:prev_item
+function! s:indent_multiline(prev_item, lnum) "{{{
+ if a:prev_item.type != 0
+ call s:set_indent(a:lnum, s:text_begin(a:prev_item.lnum))
+ endif
+endfunction "}}}
+
+"change the level of list items }}}
+
+"change markers of list items {{{
+"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)
+ else
+ let m = s:guess_kind_of_numbered_item(a:item) . a:item.mrkr[-1:]
+ endif
+ 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)]
+ 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]
+ endif
+ let idx = s:get_idx_list_markers(a: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)]
+ endif
+endfunction "}}}
+
+function! s:set_new_mrkr(item, new_mrkr) "{{{
+ 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 && VimwikiGet('syntax') != 'media'
+ call s:set_indent(a:item.lnum, vimwiki#lst#get_list_margin())
+ endif
+ else
+ call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, a:new_mrkr)
+ endif
+endfunction "}}}
+
+function! vimwiki#lst#change_marker(line1, line2, new_mrkr, mode) "{{{
+ let cur_col_from_eol = col("$") - (a:mode == "i" ? col("'^") : col('.'))
+ let new_mrkr = a:new_mrkr
+ let cur_ln = a:line1
+ while 1
+ let cur_item = s:get_item(cur_ln)
+
+ if new_mrkr ==# "next"
+ let new_mrkr = s:get_next_mrkr(cur_item)
+ elseif new_mrkr ==# "prev"
+ let new_mrkr = s:get_prev_mrkr(cur_item)
+ endif
+
+ "handle markers like ***
+ 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)
+ 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)
+ 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
+ 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)
+ endif
+ endif
+ endif
+ endif
+
+ endif
+
+ call s:set_new_mrkr(cur_item, new_mrkr)
+ call s:adjust_numbered_list(s:get_item(cur_ln), 1, 0)
+
+ if cur_ln >= a:line2 | break | endif
+ let cur_ln = s:get_next_line(cur_ln, 1)
+ endwhile
+
+ call cursor('.', col('$') - cur_col_from_eol)
+endfunction "}}}
+
+function! vimwiki#lst#change_marker_in_list(new_mrkr) "{{{
+ 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)
+ if first_item.type == 0 || last_item.type == 0 | return | endif
+ let first_item_line = first_item.lnum
+
+ let cur_item = first_item
+ while cur_item.type != 0 && cur_item.lnum <= last_item.lnum
+ call s:set_new_mrkr(cur_item, a:new_mrkr)
+ let cur_item = s:get_next_list_item(cur_item, 1)
+ endwhile
+
+ call s:adjust_numbered_list(s:get_item(first_item_line), 0, 0)
+endfunction "}}}
+"sets kind of the item depending on neighbor items and the parent item
+function! s:adjust_mrkr(item) "{{{
+ if a:item.type == 0 || VimwikiGet('syntax') == 'media'
+ return
+ endif
+
+ let new_mrkr = a:item.mrkr
+ let neighbor_item = s:get_a_neighbor_item(a:item)
+ if neighbor_item.type != 0
+ let new_mrkr = neighbor_item.mrkr
+ endif
+
+ "if possible, set e.g. *** if parent has ** as marker
+ 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)
+ endif
+ endif
+
+ call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, new_mrkr)
+ call s:adjust_numbered_list(a:item, 0, 1)
+endfunction "}}}
+
function! s:clone_marker_from_to(from, to) "{{{
let item_from = s:get_item(a:from)
if item_from.type == 0 | return | endif
@@ -1176,39 +1221,6 @@ function! s:clone_marker_from_to(from, to) "{{{
endif
endfunction "}}}
-"indent line a:lnum to be the continuation of a:prev_item
-function! s:indent_multiline(prev_item, lnum) "{{{
- if a:prev_item.type != 0
- call s:set_indent(a:lnum, s:text_begin(a:prev_item.lnum))
- endif
-endfunction "}}}
-
-function! vimwiki#lst#kbd_o() "{{{
- let fold_end = foldclosedend('.')
- let lnum = (fold_end == -1) ? line('.') : fold_end
- let cur_item = s:get_item(lnum)
- "inserting and deleting the x is necessary
- "because otherwise the indent is lost
- normal! ox
- if cur_item.lnum < s:get_last_line_of_item(cur_item)
- call s:indent_multiline(cur_item, cur_item.lnum+1)
- else
- call s:clone_marker_from_to(cur_item.lnum, cur_item.lnum+1)
- endif
- startinsert!
-endfunction "}}}
-
-function! vimwiki#lst#kbd_O() "{{{
- normal! Ox
- let cur_ln = line('.')
- if getline(cur_ln+1) !~ '^\s*$'
- call s:clone_marker_from_to(cur_ln+1, cur_ln)
- else
- call s:clone_marker_from_to(cur_ln-1, cur_ln)
- endif
- startinsert!
-endfunction "}}}
-
function! s:remove_mrkr(item) "{{{
let item = a:item
if item.cb != ''
@@ -1225,17 +1237,6 @@ function! s:remove_mrkr(item) "{{{
return item
endfunction "}}}
-function! s:get_a_neighbor_item_in_column(lnum, column) "{{{
- let cur_ln = s:get_prev_line(a:lnum)
- while cur_ln >= 1
- if s:get_level(cur_ln) <= a:column
- return s:get_corresponding_item(cur_ln)
- endif
- let cur_ln = s:get_prev_line(cur_ln)
- endwhile
- return s:empty_item()
-endfunction "}}}
-
function! s:create_marker(lnum) "{{{
let new_sibling = s:get_corresponding_item(a:lnum)
if new_sibling.type == 0
@@ -1250,6 +1251,35 @@ function! s:create_marker(lnum) "{{{
endif
endfunction "}}}
+"change markers of list items }}}
+
+"handle keys {{{
+function! vimwiki#lst#kbd_o() "{{{
+ let fold_end = foldclosedend('.')
+ let lnum = (fold_end == -1) ? line('.') : fold_end
+ let cur_item = s:get_item(lnum)
+ "inserting and deleting the x is necessary
+ "because otherwise the indent is lost
+ normal! ox
+ if cur_item.lnum < s:get_last_line_of_item(cur_item)
+ call s:indent_multiline(cur_item, cur_item.lnum+1)
+ else
+ call s:clone_marker_from_to(cur_item.lnum, cur_item.lnum+1)
+ endif
+ startinsert!
+endfunction "}}}
+
+function! vimwiki#lst#kbd_O() "{{{
+ normal! Ox
+ let cur_ln = line('.')
+ if getline(cur_ln+1) !~ '^\s*$'
+ call s:clone_marker_from_to(cur_ln+1, cur_ln)
+ else
+ call s:clone_marker_from_to(cur_ln-1, cur_ln)
+ endif
+ startinsert!
+endfunction "}}}
+
function! s:cr_on_empty_list_item(lnum, behavior) "{{{
if a:behavior == 1
"just make a new list item
@@ -1411,18 +1441,9 @@ function! vimwiki#lst#toggle_list_item() "{{{
endif
endfunction "}}}
-function! vimwiki#lst#default_symbol() "{{{
- return g:vimwiki_list_markers[0]
-endfunction "}}}
-
-function! vimwiki#lst#get_list_margin() "{{{
- if VimwikiGet('list_margin') < 0
- return &sw
- else
- return VimwikiGet('list_margin')
- endif
-endfunction "}}}
+"handle keys }}}
+"misc stuff {{{
function! vimwiki#lst#setup_marker_infos() "{{{
let s:rx_bullet_chars = '['.join(keys(g:vimwiki_bullet_types), '').']\+'
@@ -1495,8 +1516,6 @@ fun! vimwiki#lst#fold_level(lnum) "{{{
endif
endif
return '='
-endfu
-
-
- return '='
endf "}}}
+
+"misc stuff }}}