Simplify some regexes

This commit is contained in:
EinfachToll 2016-03-18 15:16:59 +01:00
parent 128581babc
commit 4bd0690a52
3 changed files with 21 additions and 15 deletions

View File

@ -376,10 +376,10 @@ endfunction "}}}
"If there is no second argument, 0 is returned at a header, otherwise the
"header is skipped
function! s:get_next_line(lnum, ...) "{{{
if getline(a:lnum) =~# '^\s*'.g:vimwiki_rxPreStart
if getline(a:lnum) =~# g:vimwiki_rxPreStart
let cur_ln = a:lnum + 1
while cur_ln <= line('$') &&
\ getline(cur_ln) !~# '^\s*'.g:vimwiki_rxPreEnd.'\s*$'
\ getline(cur_ln) !~# g:vimwiki_rxPreEnd
let cur_ln += 1
endwhile
let next_line = cur_ln
@ -404,10 +404,10 @@ endfunction "}}}
function! s:get_prev_line(lnum) "{{{
let prev_line = prevnonblank(a:lnum-1)
if getline(prev_line) =~# '^\s*'.g:vimwiki_rxPreEnd.'\s*$'
if getline(prev_line) =~# g:vimwiki_rxPreEnd
let cur_ln = a:lnum - 1
while 1
if cur_ln == 0 || getline(cur_ln) =~# '^\s*'.g:vimwiki_rxPreStart
if cur_ln == 0 || getline(cur_ln) =~# g:vimwiki_rxPreStart
break
endif
let cur_ln -= 1

View File

@ -173,9 +173,9 @@ function! VimwikiFoldLevel(lnum) "{{{
if line =~# g:vimwiki_rxHeader
return '>'.vimwiki#u#count_first_sym(line)
" Code block folding...
elseif line =~# '^\s*'.g:vimwiki_rxPreStart
elseif line =~# g:vimwiki_rxPreStart
return 'a1'
elseif line =~# '^\s*'.g:vimwiki_rxPreEnd.'\s*$'
elseif line =~# g:vimwiki_rxPreEnd
return 's1'
else
return "="
@ -221,7 +221,7 @@ function! VimwikiFoldText() "{{{
let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '')
let fold_len = v:foldend - v:foldstart + 1
let len_text = ' ['.fold_len.'] '
if line !~# '^\s*'.g:vimwiki_rxPreStart
if line !~# g:vimwiki_rxPreStart
let [main_text, spare_len] = s:shorten_text(main_text, 50)
return main_text.len_text
else

View File

@ -315,6 +315,12 @@ endfor
" }}}
let g:vimwiki_rxPreStart = '^\s*'.g:vimwiki_rxPreStart
let g:vimwiki_rxPreEnd = '^\s*'.g:vimwiki_rxPreEnd.'\s*$'
let g:vimwiki_rxMathStart = '^\s*'.g:vimwiki_rxMathStart
let g:vimwiki_rxMathEnd = '^\s*'.g:vimwiki_rxMathEnd.'\s*$'
" possibly concealed chars " {{{
let s:conceal = exists("+conceallevel") ? ' conceal' : ''
@ -444,11 +450,11 @@ execute 'syntax match VimwikiCodeT /'.g:vimwiki_rxCode.'/ contained contains=Vim
" <hr> horizontal rule
execute 'syntax match VimwikiHR /'.g:vimwiki_rxHR.'/'
execute 'syntax region VimwikiPre start=/^\s*'.g:vimwiki_rxPreStart.
\ '/ end=/^\s*'.g:vimwiki_rxPreEnd.'\s*$/ contains=@Spell'
execute 'syntax region VimwikiPre start=/'.g:vimwiki_rxPreStart.
\ '/ end=/'.g:vimwiki_rxPreEnd.'/ contains=@Spell'
execute 'syntax region VimwikiMath start=/^\s*'.g:vimwiki_rxMathStart.
\ '/ end=/^\s*'.g:vimwiki_rxMathEnd.'\s*$/ contains=@Spell'
execute 'syntax region VimwikiMath start=/'.g:vimwiki_rxMathStart.
\ '/ end=/'.g:vimwiki_rxMathEnd.'/ contains=@Spell'
" placeholders
@ -594,16 +600,16 @@ endif
if !empty(s:nested)
for [s:hl_syntax, s:vim_syntax] in items(s:nested)
call vimwiki#base#nested_syntax(s:vim_syntax,
\ '^\s*'.g:vimwiki_rxPreStart.'\%(.*[[:blank:][:punct:]]\)\?'.
\ g:vimwiki_rxPreStart.'\%(.*[[:blank:][:punct:]]\)\?'.
\ s:hl_syntax.'\%([[:blank:][:punct:]].*\)\?',
\ '^\s*'.g:vimwiki_rxPreEnd, 'VimwikiPre')
\ g:vimwiki_rxPreEnd, 'VimwikiPre')
endfor
endif
" LaTeX
call vimwiki#base#nested_syntax('tex',
\ '^\s*'.g:vimwiki_rxMathStart.'\%(.*[[:blank:][:punct:]]\)\?'.
\ g:vimwiki_rxMathStart.'\%(.*[[:blank:][:punct:]]\)\?'.
\ '\%([[:blank:][:punct:]].*\)\?',
\ '^\s*'.g:vimwiki_rxMathEnd, 'VimwikiMath')
\ g:vimwiki_rxMathEnd, 'VimwikiMath')
"}}}