Release candidate ready

This commit is contained in:
Karl Yngve Lervåg 2014-07-09 12:43:10 +02:00
parent c743e43dca
commit 01e2592696

View File

@ -101,7 +101,7 @@ function! s:parse_file(file, ...)
" Reset TOC numbering " Reset TOC numbering
if a:0 > 0 if a:0 > 0
call s:reset_number() call s:number_reset(0)
endif endif
let toc = [] let toc = []
@ -122,10 +122,9 @@ function! s:parse_file(file, ...)
continue continue
endif endif
" 3. Change numbering for appendix " 3. Reset and change numbering for appendix
if line =~# '\v^\s*\\appendix' if line =~# '\v^\s*\\appendix'
call s:reset_number() call s:number_reset(1)
let s:number.appendix = 1
continue continue
endif endif
endfor endfor
@ -134,10 +133,12 @@ function! s:parse_file(file, ...)
endfunction endfunction
"}}}1 "}}}1
" {{{1 s:parse_line_input " {{{1 s:parse_line
" Define regular expressions to match input and include lines
let s:re_input = '\v^\s*\\%(input|include)\s*\{' let s:re_input = '\v^\s*\\%(input|include)\s*\{'
let s:re_input_file = s:re_input . '\zs[^\}]+\ze}' let s:re_input_file = s:re_input . '\zs[^\}]+\ze}'
" Parse input/include lines
function! s:parse_line_input(line) function! s:parse_line_input(line)
let l:file = matchstr(a:line, s:re_input_file) let l:file = matchstr(a:line, s:re_input_file)
if l:file !~# '.tex$' if l:file !~# '.tex$'
@ -146,15 +147,15 @@ function! s:parse_line_input(line)
return fnamemodify(l:file, ':p') return fnamemodify(l:file, ':p')
endfunction endfunction
" }}}1 " Define regular expressions to match various sectioning commands
" {{{1 s:parse_line_sec let s:re_sec = '\v^\s*\\%(part|chapter|%(sub)*section)\*?\s*\{'
let s:re_sec = '\v^\s*\\%(chapter|%(sub)*section)\*?\s*\{' let s:re_sec_level = '\v^\s*\\\zs%(part|chapter|%(sub)*section)\*?'
let s:re_sec_level = '\v^\s*\\\zs%(chapter|%(sub)*section)\*?'
let s:re_sec_title = s:re_sec . '\zs.{-}\ze\}?$' let s:re_sec_title = s:re_sec . '\zs.{-}\ze\}?$'
" Parse sectioning lines
function! s:parse_line_sec(file, lnum, line) function! s:parse_line_sec(file, lnum, line)
let title = matchstr(a:line, s:re_sec_title) let title = matchstr(a:line, s:re_sec_title)
let number = s:increment_number(matchstr(a:line, s:re_sec_level)) let number = s:number_increment(matchstr(a:line, s:re_sec_level))
return { return {
\ 'title' : title, \ 'title' : title,
@ -165,19 +166,18 @@ function! s:parse_line_sec(file, lnum, line)
endfunction endfunction
" }}}1 " }}}1
" {{{1 s:number_*
" {{{1 TOC numbering
let s:number = {} let s:number = {}
function! s:reset_number() function! s:number_reset(appendix)
let s:number.part = 0 let s:number.part = 0
let s:number.chapter = 0 let s:number.chapter = 0
let s:number.section = 0 let s:number.section = 0
let s:number.subsection = 0 let s:number.subsection = 0
let s:number.subsubsection = 0 let s:number.subsubsection = 0
let s:number.appendix = 0 let s:number.appendix = a:appendix ? 1 : 0
endfunction endfunction
function! s:increment_number(level) function! s:number_increment(level)
" Check if level should be incremented " Check if level should be incremented
if a:level !~# '\v%(part|chapter|(sub)*section)$' if a:level !~# '\v%(part|chapter|(sub)*section)$'
return '' return ''
@ -206,19 +206,31 @@ function! s:increment_number(level)
let s:number.subsubsection += 1 let s:number.subsubsection += 1
endif endif
return s:print_number() return s:number_print()
endfunction endfunction
function! s:print_number() function! s:number_print()
let number = [ let number = [
\ s:number.part \ s:number.part,
\ s:number.chapter \ s:number.chapter,
\ s:number.section \ s:number.section,
\ s:number.subsection \ s:number.subsection,
\ s:number.subsubsection \ s:number.subsubsection,
\ ] \ ]
return string while number[0] == 0
call remove(number, 0)
endwhile
while number[-1] == 0
call remove(number, -1)
endwhile
if s:number.appendix
let number[0] = nr2char(number[0] + 64)
endif
return join(number, '.')
endfunction endfunction
" }}}1 " }}}1