Move around and simplify the code for initialization
This commit is contained in:
parent
6805438779
commit
79b78dc9ee
@ -54,21 +54,31 @@ function! s:increment_a(value) "{{{
|
|||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:increment_I(value) "{{{
|
function! s:increment_I(value) "{{{
|
||||||
let subst_list = [ ['XLVIII$', 'IL'], ['VIII$', 'IX'], ['III$', 'IV'], ['DCCCXCIX$', 'CM'], ['CCCXCIX$', 'CD'], ['LXXXIX$', 'XC'], ['XXXIX$', 'XL'], ['\(I\{1,2\}\)$', '\1I'], ['CDXCIX$', 'D'], ['CMXCIX$', 'M'], ['XCIX$', 'C'], ['I\([VXLCDM]\)$', '\1'], ['\([VXLCDM]\)$', '\1I'] ]
|
let subst_list = [ ['XLVIII$', 'IL'], ['VIII$', 'IX'], ['III$', 'IV'],
|
||||||
|
\ ['DCCCXCIX$', 'CM'], ['CCCXCIX$', 'CD'], ['LXXXIX$', 'XC'],
|
||||||
|
\ ['XXXIX$', 'XL'], ['\(I\{1,2\}\)$', '\1I'], ['CDXCIX$', 'D'],
|
||||||
|
\ ['CMXCIX$', 'M'], ['XCIX$', 'C'], ['I\([VXLCDM]\)$', '\1'],
|
||||||
|
\ ['\([VXLCDM]\)$', '\1I'] ]
|
||||||
for [regex, subst] in subst_list
|
for [regex, subst] in subst_list
|
||||||
if a:value =~# regex
|
if a:value =~# regex
|
||||||
return substitute(a:value, regex, subst, '')
|
return substitute(a:value, regex, subst, '')
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
return ''
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:increment_i(value) "{{{
|
function! s:increment_i(value) "{{{
|
||||||
let subst_list = [ ['xlviii$', 'il'], ['viii$', 'ix'], ['iii$', 'iv'], ['dcccxcix$', 'cm'], ['cccxcix$', 'cd'], ['lxxxix$', 'xc'], ['xxxix$', 'xl'], ['\(i\{1,2\}\)$', '\1i'], ['cdxcix$', 'd'], ['cmxcix$', 'm'], ['xcix$', 'c'], ['i\([vxlcdm]\)$', '\1'], ['\([vxlcdm]\)$', '\1i'] ]
|
let subst_list = [ ['xlviii$', 'il'], ['viii$', 'ix'], ['iii$', 'iv'],
|
||||||
|
\ ['dcccxcix$', 'cm'], ['cccxcix$', 'cd'], ['lxxxix$', 'xc'],
|
||||||
|
\ ['xxxix$', 'xl'], ['\(i\{1,2\}\)$', '\1i'], ['cdxcix$', 'd'],
|
||||||
|
\ ['cmxcix$', 'm'], ['xcix$', 'c'], ['i\([vxlcdm]\)$', '\1'],
|
||||||
|
\ ['\([vxlcdm]\)$', '\1i'] ]
|
||||||
for [regex, subst] in subst_list
|
for [regex, subst] in subst_list
|
||||||
if a:value =~# regex
|
if a:value =~# regex
|
||||||
return substitute(a:value, regex, subst, '')
|
return substitute(a:value, regex, subst, '')
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
return ''
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
" incrementation functions for the various kinds of numbers }}}
|
" incrementation functions for the various kinds of numbers }}}
|
||||||
@ -93,7 +103,7 @@ function! s:get_item(lnum) "{{{
|
|||||||
let item.type = 0
|
let item.type = 0
|
||||||
return item
|
return item
|
||||||
endif
|
endif
|
||||||
let matches = matchlist(getline(a:lnum), vimwiki#lst#get_list_item_rx(1))
|
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
|
let item.type = 0
|
||||||
return item
|
return item
|
||||||
@ -112,15 +122,13 @@ function! s:get_item(lnum) "{{{
|
|||||||
return item
|
return item
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
|
|
||||||
"Returns: level of the line
|
"Returns: level of the line
|
||||||
"0 is the 'highest' level
|
"0 is the 'highest' level
|
||||||
function! s:get_level(lnum) "{{{
|
function! s:get_level(lnum) "{{{
|
||||||
if VimwikiGet('syntax') != 'media'
|
if VimwikiGet('syntax') != 'media'
|
||||||
let level = getline(a:lnum) !~ '^\s*$' ? indent(a:lnum) : 0
|
let level = getline(a:lnum) !~ '^\s*$' ? indent(a:lnum) : 0
|
||||||
else
|
else
|
||||||
let rx_markers = '^[' . vimwiki#u#escape(join(keys(g:vimwiki_bullet_points), "")) . ']\+'
|
let level = vimwiki#u#count_first_sym(a:lnum) - 1
|
||||||
let level = s:string_length(matchstr(getline(a:lnum), rx_markers)) - 1
|
|
||||||
if level < 0
|
if level < 0
|
||||||
let level = (indent(a:lnum) == 0) ? 0 : 9999
|
let level = (indent(a:lnum) == 0) ? 0 : 9999
|
||||||
endif
|
endif
|
||||||
@ -128,19 +136,12 @@ function! s:get_level(lnum) "{{{
|
|||||||
return level
|
return level
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
"XXX does not distinguish between letters and romanian numerals
|
|
||||||
"Should be no problem as long as the user doesn't mix them
|
|
||||||
function! s:regexp_of_marker(item) "{{{
|
function! s:regexp_of_marker(item) "{{{
|
||||||
if a:item.type == 1
|
if a:item.type == 1
|
||||||
return vimwiki#u#escape(a:item.mrkr)
|
return vimwiki#u#escape(a:item.mrkr)
|
||||||
elseif a:item.type == 2
|
elseif a:item.type == 2
|
||||||
for ki in ['d', 'u', 'l']
|
let kind = s:guess_kind_of_numbered_item(a:item)
|
||||||
let mats = matchstr(a:item.mrkr, '\'.ki.'\+['.vimwiki#u#escape(g:vimwiki_bullet_numbers[1]).']')
|
return s:char_to_rx[kind] . vimwiki#u#escape(a:item.mrkr[-1:])
|
||||||
if mats != ''
|
|
||||||
let [_, divisor] = s:get_chars_and_divisor(mats)
|
|
||||||
return '\'.ki.'\+'.vimwiki#u#escape(divisor)
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
else
|
else
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
@ -164,14 +165,16 @@ endfunction "}}}
|
|||||||
|
|
||||||
function! s:get_next_or_prev_list_item(item, direction, until, all) "{{{
|
function! s:get_next_or_prev_list_item(item, direction, until, all) "{{{
|
||||||
let org_lvl = s:get_level(a:item.lnum)
|
let org_lvl = s:get_level(a:item.lnum)
|
||||||
let org_regex = s:regexp_of_marker(a:item)
|
if !a:all
|
||||||
|
let org_regex = s:regexp_of_marker(a:item)
|
||||||
|
endif
|
||||||
let cur_ln = s:get_next_prev_line(a:item.lnum, a:direction)
|
let cur_ln = s:get_next_prev_line(a:item.lnum, a:direction)
|
||||||
while cur_ln != a:until
|
while cur_ln != a:until
|
||||||
let cur_lvl = s:get_level(cur_ln)
|
let cur_lvl = s:get_level(cur_ln)
|
||||||
let cur_linecontent = getline(cur_ln)
|
let cur_linecontent = getline(cur_ln)
|
||||||
|
|
||||||
if cur_lvl == org_lvl
|
if cur_lvl == org_lvl
|
||||||
if a:all == 1 || cur_linecontent =~# '^\s*'.org_regex.'\s'
|
if a:all || cur_linecontent =~# '^\s*'.org_regex.'\s'
|
||||||
return s:get_item(cur_ln)
|
return s:get_item(cur_ln)
|
||||||
else
|
else
|
||||||
return s:empty_item()
|
return s:empty_item()
|
||||||
@ -189,39 +192,33 @@ function! s:first_char(string) "{{{
|
|||||||
return matchstr(a:string, '^.')
|
return matchstr(a:string, '^.')
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
"Returns: 'bla)' -> ['bla', ')']
|
|
||||||
" must be that complicated, because
|
|
||||||
" 'bla)'[:-2] wouldn't work for multibyte chars
|
|
||||||
function! s:get_chars_and_divisor(string) "{{{
|
|
||||||
return matchlist(a:string, '^\(.\+\)\(.\)$')[1:2]
|
|
||||||
endfunction "}}}
|
|
||||||
|
|
||||||
"Returns: 1, a, i, A, I or ''
|
"Returns: 1, a, i, A, I or ''
|
||||||
"If in doubt if alphanumeric character or romanian
|
"If in doubt if alphanumeric character or romanian
|
||||||
"numeral, peek in the previous line
|
"numeral, peek in the previous line
|
||||||
function! s:guess_kind_of_numbered_item(item) "{{{
|
function! s:guess_kind_of_numbered_item(item) "{{{
|
||||||
if a:item.type != 2 | return '' | endif
|
if a:item.type != 2 | return '' | endif
|
||||||
let kinds = split(g:vimwiki_bullet_numbers[0], '.\zs')
|
let number_chars = a:item.mrkr[:-2]
|
||||||
let [chars, divisor] = s:get_chars_and_divisor(a:item.mrkr)
|
let divisor = a:item.mrkr[-1:]
|
||||||
|
|
||||||
if chars =~ '\d\+'
|
if number_chars =~ '\d\+'
|
||||||
return '1'
|
return '1'
|
||||||
endif
|
endif
|
||||||
if chars =~# '\l\+'
|
if number_chars =~# '\l\+'
|
||||||
if chars !~# '^[ivxlcdm]\+' || index(kinds, 'i') == -1
|
if number_chars !~# '^[ivxlcdm]\+' || index(s:number_kinds, 'i') == -1
|
||||||
return 'a'
|
return 'a'
|
||||||
else
|
else
|
||||||
|
|
||||||
let item_above = s:get_prev_list_item(a:item, 0)
|
let item_above = s:get_prev_list_item(a:item, 1)
|
||||||
if item_above.type != 0
|
if item_above.type != 0
|
||||||
let [chars_above, div_above] = s:get_chars_and_divisor(item_above.mrkr)
|
if index(s:number_kinds, 'a') == -1 ||
|
||||||
if index(kinds, 'a') == -1 || (div_above !=# divisor && chars =~# 'i\+') || s:increment_i(chars_above) ==# chars
|
\ (item_above.mrkr[-1:] !=# divisor && number_chars =~# 'i\+') ||
|
||||||
|
\ s:increment_i(item_above.mrkr[:-2]) ==# number_chars
|
||||||
return 'i'
|
return 'i'
|
||||||
else
|
else
|
||||||
return 'a'
|
return 'a'
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if chars =~# 'i\+' || index(kinds, 'a') == -1
|
if number_chars =~# 'i\+' || index(s:number_kinds, 'a') == -1
|
||||||
return 'i'
|
return 'i'
|
||||||
else
|
else
|
||||||
return 'a'
|
return 'a'
|
||||||
@ -230,21 +227,22 @@ function! s:guess_kind_of_numbered_item(item) "{{{
|
|||||||
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if chars =~# '\u\+'
|
if number_chars =~# '\u\+'
|
||||||
if chars !~# '^[IVXLCDM]\+' || index(kinds, 'I') == -1
|
if number_chars !~# '^[IVXLCDM]\+' || index(s:number_kinds, 'I') == -1
|
||||||
return 'A'
|
return 'A'
|
||||||
else
|
else
|
||||||
|
|
||||||
let item_above = s:get_prev_list_item(a:item, 0)
|
let item_above = s:get_prev_list_item(a:item, 1)
|
||||||
if item_above.type != 0
|
if item_above.type != 0
|
||||||
let [chars_above, div_above] = s:get_chars_and_divisor(item_above.mrkr)
|
if index(s:number_kinds, 'A') == -1 ||
|
||||||
if index(kinds, 'A') == -1 || (div_above !=# divisor && chars =~# 'I\+') || s:increment_i(chars_above) ==# chars
|
\ (item_above.mrkr[-1:] !=# divisor && number_chars =~# 'I\+') ||
|
||||||
|
\ s:increment_i(item_above.mrkr[:-2]) ==# number_chars
|
||||||
return 'I'
|
return 'I'
|
||||||
else
|
else
|
||||||
return 'A'
|
return 'A'
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if chars =~# 'I\+' || index(kinds, 'A') == -1
|
if number_chars =~# 'I\+' || index(s:number_kinds, 'A') == -1
|
||||||
return 'I'
|
return 'I'
|
||||||
else
|
else
|
||||||
return 'A'
|
return 'A'
|
||||||
@ -386,8 +384,7 @@ function! s:adjust_numbered_list_below(item, recursive) "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if cur_item.type == 2
|
if cur_item.type == 2
|
||||||
let [chars, divisor] = s:get_chars_and_divisor(cur_item.mrkr)
|
let new_val = s:increment_{kind}(cur_item.mrkr[:-2]) . cur_item.mrkr[-1:]
|
||||||
let new_val = s:increment_{kind}(chars) . divisor
|
|
||||||
call s:substitute_string_in_line(next_item.lnum, next_item.mrkr, new_val)
|
call s:substitute_string_in_line(next_item.lnum, next_item.mrkr, new_val)
|
||||||
let next_item.mrkr = new_val
|
let next_item.mrkr = new_val
|
||||||
endif
|
endif
|
||||||
@ -429,8 +426,7 @@ function! s:adjust_numbered_list(item, all, recursive) "{{{
|
|||||||
|
|
||||||
while 1
|
while 1
|
||||||
if first_item.type == 2
|
if first_item.type == 2
|
||||||
let [_, divisor] = s:get_chars_and_divisor(first_item.mrkr)
|
let new_mrkr = s:guess_kind_of_numbered_item(first_item) . first_item.mrkr[-1:]
|
||||||
let new_mrkr = s:guess_kind_of_numbered_item(first_item) . divisor
|
|
||||||
call s:substitute_string_in_line(first_item.lnum, first_item.mrkr, new_mrkr)
|
call s:substitute_string_in_line(first_item.lnum, first_item.mrkr, new_mrkr)
|
||||||
let first_item.mrkr = new_mrkr
|
let first_item.mrkr = new_mrkr
|
||||||
endif
|
endif
|
||||||
@ -636,26 +632,26 @@ endfunction "}}}
|
|||||||
"Returns: the column where the text of a line starts (possible list item
|
"Returns: the column where the text of a line starts (possible list item
|
||||||
"markers and checkboxes are skipped)
|
"markers and checkboxes are skipped)
|
||||||
function! s:text_begin(lnum) "{{{
|
function! s:text_begin(lnum) "{{{
|
||||||
return s:string_length(matchstr(getline(a:lnum), vimwiki#lst#get_list_item_rx(1)))
|
return s:string_length(matchstr(getline(a:lnum), g:vimwiki_rxListItem))
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
if exists("*strdisplaywidth")
|
if exists("*strdisplaywidth") "{{{
|
||||||
fu! s:string_length(str)
|
function! s:string_length(str)
|
||||||
return strdisplaywidth(a:str)
|
return strdisplaywidth(a:str)
|
||||||
endfu
|
endfunction
|
||||||
else
|
else
|
||||||
fu! s:string_length(str)
|
function! s:string_length(str)
|
||||||
return strlen(substitute(a:str, '.', 'x', 'g'))
|
return strlen(substitute(a:str, '.', 'x', 'g'))
|
||||||
endfu
|
endfunction
|
||||||
endif
|
endif "}}}
|
||||||
|
|
||||||
"Returns: 2 if there is a marker and text
|
"Returns: 2 if there is a marker and text
|
||||||
" 1 for a marker and no text
|
" 1 for a marker and no text
|
||||||
" 0 for no marker at all (empty line or only text)
|
" 0 for no marker at all (empty line or only text)
|
||||||
function! s:line_has_marker(lnum) "{{{
|
function! s:line_has_marker(lnum) "{{{
|
||||||
if getline(a:lnum) =~# vimwiki#lst#get_list_item_rx(1).'\s*$'
|
if getline(a:lnum) =~# g:vimwiki_rxListItem.'\s*$'
|
||||||
return 1
|
return 1
|
||||||
elseif getline(a:lnum) =~# vimwiki#lst#get_list_item_rx(1).'\s*\S'
|
elseif getline(a:lnum) =~# g:vimwiki_rxListItem.'\s*\S'
|
||||||
return 2
|
return 2
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
@ -742,8 +738,7 @@ function! s:get_idx_list_markers(item) "{{{
|
|||||||
if a:item.type == 1
|
if a:item.type == 1
|
||||||
let m = s:first_char(a:item.mrkr)
|
let m = s:first_char(a:item.mrkr)
|
||||||
else
|
else
|
||||||
let [_, divisor] = s:get_chars_and_divisor(a:item.mrkr)
|
let m = s:guess_kind_of_numbered_item(a:item) . a:item.mrkr[-1:]
|
||||||
let m = s:guess_kind_of_numbered_item(a:item) . divisor
|
|
||||||
endif
|
endif
|
||||||
return index(g:vimwiki_list_markers, m)
|
return index(g:vimwiki_list_markers, m)
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
@ -795,7 +790,7 @@ function! vimwiki#lst#change_marker(line1, line2, new_mrkr) "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
"handle markers like ***
|
"handle markers like ***
|
||||||
if has_key(g:vimwiki_bullet_points, s:first_char(new_mrkr)) && g:vimwiki_bullet_points[s:first_char(new_mrkr)] == 1
|
if index(s:multiple_bullet_chars, s:first_char(new_mrkr)) > -1
|
||||||
"use *** if the item above has *** too
|
"use *** if the item above has *** too
|
||||||
let item_above = s:get_prev_list_item(cur_item, 1)
|
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)
|
||||||
@ -807,7 +802,7 @@ function! vimwiki#lst#change_marker(line1, line2, new_mrkr) "{{{
|
|||||||
let new_mrkr = item_below.mrkr
|
let new_mrkr = item_below.mrkr
|
||||||
else
|
else
|
||||||
"if the old is ### and the new is * use ***
|
"if the old is ### and the new is * use ***
|
||||||
if cur_item.type == 1 && has_key(g:vimwiki_bullet_points, s:first_char(cur_item.mrkr)) && g:vimwiki_bullet_points[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))
|
let new_mrkr = repeat(new_mrkr, s:string_length(cur_item.mrkr))
|
||||||
else
|
else
|
||||||
"use *** if the parent item has **
|
"use *** if the parent item has **
|
||||||
@ -915,7 +910,8 @@ endfunction "}}}
|
|||||||
|
|
||||||
function! s:decrease_level(item) "{{{
|
function! s:decrease_level(item) "{{{
|
||||||
let removed_indent = 0
|
let removed_indent = 0
|
||||||
if VimwikiGet('syntax') == 'media' && a:item.type == 1 && g:vimwiki_bullet_points[s:first_char(a:item.mrkr)]
|
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
|
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
|
let removed_indent = -1
|
||||||
@ -935,7 +931,8 @@ endfunction "}}}
|
|||||||
|
|
||||||
function! s:increase_level(item) "{{{
|
function! s:increase_level(item) "{{{
|
||||||
let additional_space = 0
|
let additional_space = 0
|
||||||
if VimwikiGet('syntax') == 'media' && a:item.type == 1 && g:vimwiki_bullet_points[s:first_char(a:item.mrkr)]
|
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
|
let additional_indent = 1
|
||||||
else
|
else
|
||||||
@ -955,7 +952,8 @@ endfunction "}}}
|
|||||||
"a:indent_by can be negative
|
"a:indent_by can be negative
|
||||||
function! s:indent_line_by(lnum, indent_by) "{{{
|
function! s:indent_line_by(lnum, indent_by) "{{{
|
||||||
let item = s:get_item(a:lnum)
|
let item = s:get_item(a:lnum)
|
||||||
if VimwikiGet('syntax') == 'media' && item.type == 1 && g:vimwiki_bullet_points[s:first_char(item.mrkr)]
|
if VimwikiGet('syntax') == 'media' && item.type == 1 &&
|
||||||
|
\ index(s:multiple_bullet_chars, s:first_char(item.mrkr)) > -1
|
||||||
if a:indent_by > 0
|
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
|
elseif a:indent_by < 0
|
||||||
@ -993,12 +991,13 @@ function! s:adjust_mrkr(item) "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
"if possible, set e.g. *** if parent has ** as marker
|
"if possible, set e.g. *** if parent has ** as marker
|
||||||
if neighbor_item.type == 0 && a:item.type == 1 && has_key(g:vimwiki_bullet_points, s:first_char(a:item.mrkr)) && g:vimwiki_bullet_points[s:first_char(a:item.mrkr)] == 1
|
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)
|
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)
|
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)
|
let new_mrkr = repeat(s:first_char(parent_item.mrkr), s:string_length(parent_item.mrkr)+1)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, new_mrkr)
|
call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, new_mrkr)
|
||||||
call s:adjust_numbered_list(a:item, 0, 1)
|
call s:adjust_numbered_list(a:item, 0, 1)
|
||||||
@ -1280,12 +1279,36 @@ function! vimwiki#lst#get_list_margin() "{{{
|
|||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! vimwiki#lst#get_list_item_rx(with_cb) "{{{
|
function! vimwiki#lst#setup_marker_infos()
|
||||||
let rx_without_cb = '^\s*\%(\('.g:vimwiki_rxListBullet.'\)\|\('.g:vimwiki_rxListNumber.'\)\)'
|
let s:multiple_bullet_chars = []
|
||||||
if a:with_cb
|
for i in keys(g:vimwiki_bullet_types)
|
||||||
return rx_without_cb . '\s\+\%(\[\(['.join(g:vimwiki_listsyms, '').']\)\]\s\)\?'
|
if g:vimwiki_bullet_types[i] == 1
|
||||||
else
|
call add(s:multiple_bullet_chars, i)
|
||||||
return rx_without_cb . '\s'
|
endif
|
||||||
endif
|
endfor
|
||||||
endfunction "}}}
|
|
||||||
|
|
||||||
|
let s:number_kinds = []
|
||||||
|
for i in g:vimwiki_number_types
|
||||||
|
call add(s:number_kinds, i[0])
|
||||||
|
endfor
|
||||||
|
|
||||||
|
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])') , '\|')
|
||||||
|
|
||||||
|
"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]) . '\|'
|
||||||
|
endfor
|
||||||
|
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
|
||||||
|
let g:vimwiki_rxListNumber = '$^'
|
||||||
|
endif
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
@ -327,24 +327,54 @@ glr Renumber list items for the current list.
|
|||||||
gLr Renumber list items for the whole buffer.
|
gLr Renumber list items for the whole buffer.
|
||||||
|
|
||||||
*vimwiki_glstar* *vimwiki_glstar*
|
*vimwiki_glstar* *vimwiki_glstar*
|
||||||
gl* Make a list item out of normal line or change ther marker
|
gl* Make a list item out of normal line or change the marker
|
||||||
for the current item.
|
of the current item to *.
|
||||||
gL* Change the marker of the current list to *.
|
gL* Change the marker of the current list to *.
|
||||||
|
|
||||||
*vimwiki_gl#* *vimwiki_gL#*
|
*vimwiki_gl#* *vimwiki_gL#*
|
||||||
gl# Make a list item out of normal line or change ther marker
|
gl# Make a list item out of normal line or change the marker
|
||||||
for the current item.
|
of the current item to #.
|
||||||
gL# Change the marker of the current list to #.
|
gL# Change the marker of the current list to #.
|
||||||
|
|
||||||
*vimwiki_gl-* *vimwiki_gL-*
|
*vimwiki_gl-* *vimwiki_gL-*
|
||||||
gl- Make a list item out of normal line or change ther marker
|
gl- Make a list item out of normal line or change the marker
|
||||||
for the current item.
|
of the current item to -.
|
||||||
gL- Change the marker of the current list to -.
|
gL- Change the marker of the current list to -.
|
||||||
|
|
||||||
|
*vimwiki_gl.* *vimwiki_gL.*
|
||||||
|
gl. Make a list item out of normal line or change the marker
|
||||||
|
of the current item to •.
|
||||||
|
gL. Change the marker of the current list to •.
|
||||||
|
|
||||||
*vimwiki_gl1* *vimwiki_gL1*
|
*vimwiki_gl1* *vimwiki_gL1*
|
||||||
gl1. Make a list item out of normal line or change ther marker
|
gl1 Make a list item out of normal line or change the marker
|
||||||
for the current item.
|
of the current item to 1., the numbering is adjusted
|
||||||
gL1. Change the marker of the current list to 1..
|
according to the surrounding list items.
|
||||||
|
gL1 Change the marker of the current list to 1. 2. 3. ...
|
||||||
|
|
||||||
|
*vimwiki_gla* *vimwiki_gLa*
|
||||||
|
gla Make a list item out of normal line or change the marker
|
||||||
|
of the current item to a), the numbering is adjusted
|
||||||
|
according to the surrounding list items.
|
||||||
|
gLa Change the marker of the current list to a) b) c) ...
|
||||||
|
|
||||||
|
*vimwiki_glA* *vimwiki_gLA*
|
||||||
|
glA Make a list item out of normal line or change the marker
|
||||||
|
of the current item to A), the numbering is adjusted
|
||||||
|
according to the surrounding list items.
|
||||||
|
gLA Change the marker of the current list to A) B) C) ...
|
||||||
|
|
||||||
|
*vimwiki_gli* *vimwiki_gLi*
|
||||||
|
gli Make a list item out of normal line or change the marker
|
||||||
|
of the current item to i), the numbering is adjusted
|
||||||
|
according to the surrounding list items.
|
||||||
|
gLi Change the marker of the current list to i) ii) iii) ...
|
||||||
|
|
||||||
|
*vimwiki_glI* *vimwiki_gLI*
|
||||||
|
glI Make a list item out of normal line or change the marker
|
||||||
|
of the current item to I), the numbering is adjusted
|
||||||
|
according to the surrounding list items.
|
||||||
|
gLI Change the marker of the current list to I) II) III) ...
|
||||||
|
|
||||||
*vimwiki_gqq* *vimwiki_gww*
|
*vimwiki_gqq* *vimwiki_gww*
|
||||||
gqq Format table. If you made some changes to a table
|
gqq Format table. If you made some changes to a table
|
||||||
|
@ -7,6 +7,7 @@ if exists("b:did_ftplugin")
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let b:did_ftplugin = 1 " Don't load another plugin for this buffer
|
let b:did_ftplugin = 1 " Don't load another plugin for this buffer
|
||||||
|
execute 'runtime! syntax/vimwiki.vim'
|
||||||
|
|
||||||
" UNDO list {{{
|
" UNDO list {{{
|
||||||
" Reset the following options to undo this plugin.
|
" Reset the following options to undo this plugin.
|
||||||
@ -44,9 +45,8 @@ setlocal formatoptions-=2
|
|||||||
setlocal formatoptions+=n
|
setlocal formatoptions+=n
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"Create 'formatlistpat'
|
"Create 'formatlistpat'
|
||||||
let &formatlistpat = vimwiki#lst#get_list_item_rx(1)
|
let &formatlistpat = g:vimwiki_rxListItem
|
||||||
|
|
||||||
|
|
||||||
if !empty(&langmap)
|
if !empty(&langmap)
|
||||||
@ -472,24 +472,14 @@ noremap <silent> <buffer> gl<Space> :VimwikiListRemoveCB<CR>
|
|||||||
map <silent> <buffer> gL<Space> :call vimwiki#lst#remove_cb_in_list()<CR>
|
map <silent> <buffer> gL<Space> :call vimwiki#lst#remove_cb_in_list()<CR>
|
||||||
inoremap <silent> <buffer> <C-L><C-M> <Esc>:call vimwiki#lst#toggle_list_item()<CR>
|
inoremap <silent> <buffer> <C-L><C-M> <Esc>:call vimwiki#lst#toggle_list_item()<CR>
|
||||||
|
|
||||||
for s:k in keys(g:vimwiki_bullet_points)
|
for s:k in keys(g:vimwiki_bullet_types)
|
||||||
exe 'noremap <silent> <buffer> gl'.s:k.' :VimwikiListChangeMarker '.s:k.'<CR>'
|
let s:char = (s:k == '•' ? '.' : s:k)
|
||||||
exe 'noremap <silent> <buffer> gL'.s:k.' :VimwikiListChangeMarkerInList '.s:k.'<CR>'
|
exe 'noremap <silent> <buffer> gl'.s:char.' :VimwikiListChangeMarker '.s:k.'<CR>'
|
||||||
|
exe 'noremap <silent> <buffer> gL'.s:char.' :VimwikiListChangeMarkerInList '.s:k.'<CR>'
|
||||||
endfor
|
endfor
|
||||||
for s:a in split(g:vimwiki_bullet_numbers[0], '.\zs')
|
for s:k in g:vimwiki_number_types
|
||||||
let chars = split(g:vimwiki_bullet_numbers[1], '.\zs')
|
exe 'noremap <silent> <buffer> gl'.s:k[0].' :VimwikiListChangeMarker '.s:k.'<CR>'
|
||||||
if len(chars) == 0
|
exe 'noremap <silent> <buffer> gL'.s:k[0].' :VimwikiListChangeMarkerInList '.s:k.'<CR>'
|
||||||
exe 'noremap <silent> <buffer> gl'.s:a.' :VimwikiListChangeMarker '.s:a.'<CR>'
|
|
||||||
exe 'noremap <silent> <buffer> gL'.s:a.' :VimwikiListChangeMarkerInList '.s:a.'<CR>'
|
|
||||||
elseif len(chars) == 1
|
|
||||||
exe 'noremap <silent> <buffer> gl'.s:a.' :VimwikiListChangeMarker '.s:a.chars[0].'<CR>'
|
|
||||||
exe 'noremap <silent> <buffer> gL'.s:a.' :VimwikiListChangeMarkerInList '.s:a.chars[0].'<CR>'
|
|
||||||
else
|
|
||||||
for s:b in chars
|
|
||||||
exe 'noremap <silent> <buffer> gl'.s:a.s:b.' :VimwikiListChangeMarker '.s:a.s:b.'<CR>'
|
|
||||||
exe 'noremap <silent> <buffer> gL'.s:a.s:b.' :VimwikiListChangeMarkerInList '.s:a.s:b.'<CR>'
|
|
||||||
endfor
|
|
||||||
endif
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
|
||||||
|
@ -377,28 +377,6 @@ let g:vimwiki_rxTodo = '\C\%(TODO:\|DONE:\|STARTED:\|FIXME:\|FIXED:\|XXX:\)'
|
|||||||
execute 'syntax match VimwikiTodo /'. g:vimwiki_rxTodo .'/'
|
execute 'syntax match VimwikiTodo /'. g:vimwiki_rxTodo .'/'
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Lists "{{{
|
|
||||||
let g:vimwiki_rxListBullet = join( map(keys(g:vimwiki_bullet_points), 'vimwiki#u#escape(v:val) . repeat("\\+", g:vimwiki_bullet_points[v:val])') , '\|')
|
|
||||||
|
|
||||||
"create regex for numbered list
|
|
||||||
if g:vimwiki_bullet_numbers[0] == ''
|
|
||||||
"regex that matches nothing
|
|
||||||
let g:vimwiki_rxListNumber = '$^'
|
|
||||||
else
|
|
||||||
let s:char_to_rx = {'1': '\d\+', 'i': '[ivxlcdm]\+', 'I': '[IVXLCDM]\+', 'a': '\l\{1,3}', 'A': '\u\{1,3}'}
|
|
||||||
let g:vimwiki_rxListNumber = '\C\%(' . join( map(split(g:vimwiki_bullet_numbers[0], '.\zs'), "s:char_to_rx[v:val]"), '\|').'\)'
|
|
||||||
let g:vimwiki_rxListNumber .= '['.vimwiki#u#escape(g:vimwiki_bullet_numbers[1]).']'
|
|
||||||
endif
|
|
||||||
|
|
||||||
" XXX: Should this be in corresponding syntax file?
|
|
||||||
if VimwikiGet('syntax') == 'default' || VimwikiGet('syntax') == 'markdown'
|
|
||||||
let g:vimwiki_rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)\s\+\['.g:vimwiki_listsyms[4].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
|
|
||||||
else
|
|
||||||
let g:vimwiki_rxListItemAndChildren = '^\('.g:vimwiki_rxListBullet.'\)\s\+\['.g:vimwiki_listsyms[4].'\]\s.*\%(\n\%(\1\%('.g:vimwiki_rxListBullet.'\).*\|^$\|^\s.*\)\)*'
|
|
||||||
endif
|
|
||||||
|
|
||||||
"}}}
|
|
||||||
|
|
||||||
" main syntax groups {{{
|
" main syntax groups {{{
|
||||||
|
|
||||||
" Tables
|
" Tables
|
||||||
@ -422,14 +400,16 @@ syntax match VimwikiCellSeparator
|
|||||||
\ /\%(|\)\|\%(-\@<=+\-\@=\)\|\%([|+]\@<=-\+\)/ contained
|
\ /\%(|\)\|\%(-\@<=+\-\@=\)\|\%([|+]\@<=-\+\)/ contained
|
||||||
|
|
||||||
" List items
|
" List items
|
||||||
execute 'syntax match VimwikiList /'.vimwiki#lst#get_list_item_rx(0).'/'
|
let g:vimwiki_rxListItemWithoutCB = '^\s*\%(\('.g:vimwiki_rxListBullet.'\)\|\('.g:vimwiki_rxListNumber.'\)\)\s'
|
||||||
|
let g:vimwiki_rxListItem = g:vimwiki_rxListItemWithoutCB . '\+\%(\[\(['.join(g:vimwiki_listsyms, '').']\)\]\s\)\?'
|
||||||
|
|
||||||
|
execute 'syntax match VimwikiList /'.g:vimwiki_rxListItemWithoutCB.'/'
|
||||||
execute 'syntax match VimwikiList /'.g:vimwiki_rxListDefine.'/'
|
execute 'syntax match VimwikiList /'.g:vimwiki_rxListDefine.'/'
|
||||||
execute 'syntax match VimwikiListTodo /'.vimwiki#lst#get_list_item_rx(1).'/'
|
execute 'syntax match VimwikiListTodo /'.g:vimwiki_rxListItem.'/'
|
||||||
|
|
||||||
if g:vimwiki_hl_cb_checked == 1
|
if g:vimwiki_hl_cb_checked == 1
|
||||||
execute 'syntax match VimwikiCheckBoxDone /'.vimwiki#lst#get_list_item_rx(0).'\s*\['.g:vimwiki_listsyms[4].'\]\s.*$/ '.
|
execute 'syntax match VimwikiCheckBoxDone /'.g:vimwiki_rxListItemWithoutCB.'\s*\['.g:vimwiki_listsyms[4].'\]\s.*$/ '.
|
||||||
\ 'contains=VimwikiNoExistsLink,VimwikiLink,@Spell'
|
\ 'contains=VimwikiNoExistsLink,VimwikiLink,@Spell'
|
||||||
|
|
||||||
elseif g:vimwiki_hl_cb_checked == 2
|
elseif g:vimwiki_hl_cb_checked == 2
|
||||||
execute 'syntax match VimwikiCheckBoxDone /'.g:vimwiki_rxListItemAndChildren.'/ contains=VimwikiNoExistsLink,VimwikiLink,@Spell'
|
execute 'syntax match VimwikiCheckBoxDone /'.g:vimwiki_rxListItemAndChildren.'/ contains=VimwikiNoExistsLink,VimwikiLink,@Spell'
|
||||||
endif
|
endif
|
||||||
@ -551,7 +531,6 @@ hi def link VimwikiLinkT VimwikiLink
|
|||||||
|
|
||||||
hi def link VimwikiList Identifier
|
hi def link VimwikiList Identifier
|
||||||
hi def link VimwikiListTodo VimwikiList
|
hi def link VimwikiListTodo VimwikiList
|
||||||
"hi def link VimwikiCheckBox VimwikiList
|
|
||||||
hi def link VimwikiCheckBoxDone Comment
|
hi def link VimwikiCheckBoxDone Comment
|
||||||
hi def link VimwikiEmoticons Character
|
hi def link VimwikiEmoticons Character
|
||||||
hi def link VimwikiHR Identifier
|
hi def link VimwikiHR Identifier
|
||||||
|
@ -74,13 +74,16 @@ let g:vimwiki_rxTableSep = '|'
|
|||||||
|
|
||||||
" Lists
|
" Lists
|
||||||
"1 means multiple bullets, like * ** ***
|
"1 means multiple bullets, like * ** ***
|
||||||
let g:vimwiki_bullet_points = { '-':0, '*':0, '#':0 , '◆':0}
|
let g:vimwiki_bullet_types = { '-':0, '*':0, '#':0 , '•':0 }
|
||||||
let g:vimwiki_bullet_numbers = ['1iIaA', '.)]']
|
let g:vimwiki_number_types = ['1)', '1.', 'i)', 'I)', 'a)', 'A)']
|
||||||
"this should contain at least one element
|
"this should contain at least one element
|
||||||
"it is used for i_<C-A> among other things
|
"it is used for i_<C-L><C-J> among other things
|
||||||
let g:vimwiki_list_markers = ['-', '#', '◆', '1.', 'i)', 'a)']
|
let g:vimwiki_list_markers = ['-', '•', '1.', '*', 'I)', 'a)']
|
||||||
let g:vimwiki_rxListDefine = '::\(\s\|$\)'
|
let g:vimwiki_rxListDefine = '::\(\s\|$\)'
|
||||||
|
|
||||||
|
call vimwiki#lst#setup_marker_infos()
|
||||||
|
let g:vimwiki_rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)\s\+\['.g:vimwiki_listsyms[4].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
|
||||||
|
|
||||||
" Preformatted text
|
" Preformatted text
|
||||||
let g:vimwiki_rxPreStart = '{{{'
|
let g:vimwiki_rxPreStart = '{{{'
|
||||||
let g:vimwiki_rxPreEnd = '}}}'
|
let g:vimwiki_rxPreEnd = '}}}'
|
||||||
|
@ -73,10 +73,12 @@ let g:vimwiki_rxHR = '^-----*$'
|
|||||||
let g:vimwiki_rxTableSep = '|'
|
let g:vimwiki_rxTableSep = '|'
|
||||||
|
|
||||||
" Lists
|
" Lists
|
||||||
let g:vimwiki_bullet_points = { '-':0, '*':0, '+':0 }
|
let g:vimwiki_bullet_types = { '-':0, '*':0, '+':0 }
|
||||||
let g:vimwiki_bullet_numbers = ['1', '.']
|
let g:vimwiki_number_types = ['1.']
|
||||||
let g:vimwiki_list_markers = ['-', '*', '+', '1.']
|
let g:vimwiki_list_markers = ['-', '*', '+', '1.']
|
||||||
let g:vimwiki_rxListDefine = '::\%(\s\|$\)'
|
let g:vimwiki_rxListDefine = '::\%(\s\|$\)'
|
||||||
|
call vimwiki#lst#setup_marker_infos()
|
||||||
|
let g:vimwiki_rxListItemAndChildren = '^\(\s*\)\%('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)\s\+\['.g:vimwiki_listsyms[4].'\]\s.*\%(\n\%(\1\s.*\|^$\)\)*'
|
||||||
|
|
||||||
" Preformatted text
|
" Preformatted text
|
||||||
let g:vimwiki_rxPreStart = '```'
|
let g:vimwiki_rxPreStart = '```'
|
||||||
|
@ -54,10 +54,12 @@ let g:vimwiki_rxHR = '^-----*$'
|
|||||||
let g:vimwiki_rxTableSep = '|'
|
let g:vimwiki_rxTableSep = '|'
|
||||||
|
|
||||||
" Lists
|
" Lists
|
||||||
let g:vimwiki_bullet_points = { '*':1, '#':1 }
|
let g:vimwiki_bullet_types = { '*':1, '#':1 }
|
||||||
let g:vimwiki_bullet_numbers = ['', '']
|
let g:vimwiki_number_types = []
|
||||||
let g:vimwiki_list_markers = ['*', '#']
|
let g:vimwiki_list_markers = ['*', '#']
|
||||||
let g:vimwiki_rxListDefine = '^\%(;\|:\)\s'
|
let g:vimwiki_rxListDefine = '^\%(;\|:\)\s'
|
||||||
|
call vimwiki#lst#setup_marker_infos()
|
||||||
|
let g:vimwiki_rxListItemAndChildren = '^\('.g:vimwiki_rxListBullet.'\)\s\+\['.g:vimwiki_listsyms[4].'\]\s.*\%(\n\%(\1\%('.g:vimwiki_rxListBullet.'\).*\|^$\|^\s.*\)\)*'
|
||||||
|
|
||||||
" Preformatted text
|
" Preformatted text
|
||||||
let g:vimwiki_rxPreStart = '<pre>'
|
let g:vimwiki_rxPreStart = '<pre>'
|
||||||
|
Loading…
Reference in New Issue
Block a user