More updates to new TOC system
This commit is contained in:
parent
da6926fb12
commit
c743e43dca
@ -99,9 +99,9 @@ function! s:parse_file(file, ...)
|
|||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Set limits for TOC numbering (only for the first call)
|
" Reset TOC numbering
|
||||||
if a:0 > 0
|
if a:0 > 0
|
||||||
let s:number = {}
|
call s:reset_number()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let toc = []
|
let toc = []
|
||||||
@ -121,6 +121,13 @@ function! s:parse_file(file, ...)
|
|||||||
call add(toc, s:parse_line_sec(a:file, lnum, line))
|
call add(toc, s:parse_line_sec(a:file, lnum, line))
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" 3. Change numbering for appendix
|
||||||
|
if line =~# '\v^\s*\\appendix'
|
||||||
|
call s:reset_number()
|
||||||
|
let s:number.appendix = 1
|
||||||
|
continue
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return toc
|
return toc
|
||||||
@ -147,28 +154,71 @@ let s:re_sec_title = s:re_sec . '\zs.{-}\ze\}?$'
|
|||||||
|
|
||||||
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 level = matchstr(a:line, s:re_sec_level)
|
let number = s:increment_number(matchstr(a:line, s:re_sec_level))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'title' : title,
|
\ 'title' : title,
|
||||||
\ 'number' : s:get_number(level),
|
\ 'number' : number,
|
||||||
\ 'file' : a:file,
|
\ 'file' : a:file,
|
||||||
\ 'line' : a:lnum,
|
\ 'line' : a:lnum,
|
||||||
\ }
|
\ }
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:get_number(level)
|
" }}}1
|
||||||
if a:level =~# '\v%(part|chapter|(sub)*section)$'
|
|
||||||
if has_key(s:number, a:level)
|
" {{{1 TOC numbering
|
||||||
let s:number.a:level += 1
|
let s:number = {}
|
||||||
else
|
function! s:reset_number()
|
||||||
let s:number.a:level = 1
|
let s:number.part = 0
|
||||||
endif
|
let s:number.chapter = 0
|
||||||
else
|
let s:number.section = 0
|
||||||
|
let s:number.subsection = 0
|
||||||
|
let s:number.subsubsection = 0
|
||||||
|
let s:number.appendix = 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:increment_number(level)
|
||||||
|
" Check if level should be incremented
|
||||||
|
if a:level !~# '\v%(part|chapter|(sub)*section)$'
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return PP(s:number)
|
" Increment numbers
|
||||||
|
if a:level == 'part'
|
||||||
|
let s:number.part += 1
|
||||||
|
let s:number.chapter = 0
|
||||||
|
let s:number.section = 0
|
||||||
|
let s:number.subsection = 0
|
||||||
|
let s:number.subsubsection = 0
|
||||||
|
elseif a:level == 'chapter'
|
||||||
|
let s:number.chapter += 1
|
||||||
|
let s:number.section = 0
|
||||||
|
let s:number.subsection = 0
|
||||||
|
let s:number.subsubsection = 0
|
||||||
|
elseif a:level == 'section'
|
||||||
|
let s:number.section += 1
|
||||||
|
let s:number.subsection = 0
|
||||||
|
let s:number.subsubsection = 0
|
||||||
|
elseif a:level == 'subsection'
|
||||||
|
let s:number.subsection += 1
|
||||||
|
let s:number.subsubsection = 0
|
||||||
|
elseif a:level == 'subsubsection'
|
||||||
|
let s:number.subsubsection += 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:print_number()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:print_number()
|
||||||
|
let number = [
|
||||||
|
\ s:number.part
|
||||||
|
\ s:number.chapter
|
||||||
|
\ s:number.section
|
||||||
|
\ s:number.subsection
|
||||||
|
\ s:number.subsubsection
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
return string
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user