Update latex ftplugin

This commit is contained in:
Adam Stankiewicz 2013-09-26 12:40:21 +02:00
parent c069f0661a
commit 0db9bdbfd6

View File

@ -75,7 +75,9 @@ function! s:FindMatchingPair(mode)
let lnum = line('.')
let cnum = searchpos('\A', 'cbnW', lnum)[1]
" if the previous char is a backslash
if strpart(getline(lnum), 0, cnum-1) !~ notbslash . '$' | let cnum = cnum-1 | endif
if strpart(getline(lnum), cnum-2, 1) == '\'
let cnum = cnum-1
endif
let delim = matchstr(getline(lnum), '\C^'. anymatch , cnum - 1)
if empty(delim) || strlen(delim)+cnum-1< col('.')
@ -89,7 +91,9 @@ function! s:FindMatchingPair(mode)
" if not found, move one char bacward and search
let cnum = searchpos('\A', 'bnW', lnum)[1]
" if the previous char is a backslash
if strpart(getline(lnum), 0, cnum-1) !~ notbslash . '$' | let cnum = cnum-1 | endif
if strpart(getline(lnum), cnum-2, 1) == '\'
let cnum = cnum-1
endif
let delim = matchstr(getline(lnum), '\C^'. anymatch , cnum - 1)
if empty(delim) || strlen(delim)+cnum< col('.') | return | endif
elseif a:mode =~ 'h'
@ -274,70 +278,18 @@ endfunction
" Special UTF-8 conversion
function! s:ConvertBack(line)
let line = a:line
if !exists('g:LatexBox_plaintext_toc')
let line = substitute(line, "\\\\IeC\s*{\\\\'a}", 'á', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`a}", 'à', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^a}", 'à', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨a}", 'ä', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"a}", 'ä', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'e}", 'é', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`e}", 'è', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^e}", 'ê', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨e}", 'ë', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"e}", 'ë', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'i}", 'í', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`i}", 'î', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^i}", 'ì', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨i}", 'ï', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"i}", 'ï', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'o}", 'ó', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`o}", 'ò', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^o}", 'ô', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨o}", 'ö', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"o}", 'ö', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'u}", 'ú', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`u}", 'ù', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^u}", 'û', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨u}", 'ü', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"u}", 'ü', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'A}", 'Á', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`A}", 'À', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^A}", 'À', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨A}", 'Ä', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"A}", 'Ä', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'E}", 'É', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`E}", 'È', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^E}", 'Ê', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨E}", 'Ë', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"E}", 'Ë', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'I}", 'Í', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`I}", 'Î', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^I}", 'Ì', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨I}", 'Ï', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"I}", 'Ï', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'O}", 'Ó', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`O}", 'Ò', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^O}", 'Ô', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨O}", 'Ö', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"O}", 'Ö', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\'U}", 'Ú', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\`U}", 'Ù', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\^U}", 'Û', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\¨U}", 'Ü', 'g')
let line = substitute(line, "\\\\IeC\s*{\\\\\"U}", 'Ü', 'g')
if exists('g:LatexBox_plaintext_toc')
"
" Substitute stuff like '\IeC{\"u}' to plain 'u'
"
let line = substitute(line, '\\IeC\s*{\\.\(.\)}', '\1', 'g')
else
" substitute stuff like '\IeC{\"u}' (utf-8 umlauts in section heading)
" to plain 'u'
let line = substitute(line, "\\\\IeC\s*{\\\\.\\(.\\)}", '\1', 'g')
"
" Substitute stuff like '\IeC{\"u}' to corresponding unicode symbols
"
for [pat, symbol] in s:ConvBackPats
let line = substitute(line, pat, symbol, 'g')
endfor
endif
return line
endfunction
@ -376,7 +328,7 @@ function! s:ReadTOC(auxfile, texfile, ...)
continue
endif
let tree = LatexBox_TexToTree(line)
let tree = LatexBox_TexToTree(s:ConvertBack(line))
if len(tree) < 3
" unknown entry type: just skip it
@ -398,7 +350,6 @@ function! s:ReadTOC(auxfile, texfile, ...)
if len(tree[1]) > 1
if !empty(tree[1][1])
let secnum = LatexBox_TreeToTex(tree[1][1])
let secnum = s:ConvertBack(secnum)
let secnum = substitute(secnum, '\\\S\+\s', '', 'g')
let secnum = substitute(secnum, '\\\S\+{\(.\{-}\)}', '\1', 'g')
let secnum = substitute(secnum, '^{\+\|}\+$', '', 'g')
@ -410,7 +361,6 @@ function! s:ReadTOC(auxfile, texfile, ...)
endif
" parse section title
let text = LatexBox_TreeToTex(tree)
let text = s:ConvertBack(text)
let text = substitute(text, '^{\+\|}\+$', '', 'g')
" add TOC entry
@ -508,6 +458,65 @@ function! s:FindClosestSection(toc, fileindices)
return a:fileindices[file][imin]
endfunction
let s:ConvBackPats = map([
\ ['\\''A}' , 'Á'],
\ ['\\`A}' , 'À'],
\ ['\\^A}' , 'À'],
\ ['\\¨A}' , 'Ä'],
\ ['\\"A}' , 'Ä'],
\ ['\\''a}' , 'á'],
\ ['\\`a}' , 'à'],
\ ['\\^a}' , 'à'],
\ ['\\¨a}' , 'ä'],
\ ['\\"a}' , 'ä'],
\ ['\\''E}' , 'É'],
\ ['\\`E}' , 'È'],
\ ['\\^E}' , 'Ê'],
\ ['\\¨E}' , 'Ë'],
\ ['\\"E}' , 'Ë'],
\ ['\\''e}' , 'é'],
\ ['\\`e}' , 'è'],
\ ['\\^e}' , 'ê'],
\ ['\\¨e}' , 'ë'],
\ ['\\"e}' , 'ë'],
\ ['\\''I}' , 'Í'],
\ ['\\`I}' , 'Î'],
\ ['\\^I}' , 'Ì'],
\ ['\\¨I}' , 'Ï'],
\ ['\\"I}' , 'Ï'],
\ ['\\''i}' , 'í'],
\ ['\\`i}' , 'î'],
\ ['\\^i}' , 'ì'],
\ ['\\¨i}' , 'ï'],
\ ['\\"i}' , 'ï'],
\ ['\\''{\?\\i }' , 'í'],
\ ['\\''O}' , 'Ó'],
\ ['\\`O}' , 'Ò'],
\ ['\\^O}' , 'Ô'],
\ ['\\¨O}' , 'Ö'],
\ ['\\"O}' , 'Ö'],
\ ['\\''o}' , 'ó'],
\ ['\\`o}' , 'ò'],
\ ['\\^o}' , 'ô'],
\ ['\\¨o}' , 'ö'],
\ ['\\"o}' , 'ö'],
\ ['\\''U}' , 'Ú'],
\ ['\\`U}' , 'Ù'],
\ ['\\^U}' , 'Û'],
\ ['\\¨U}' , 'Ü'],
\ ['\\"U}' , 'Ü'],
\ ['\\''u}' , 'ú'],
\ ['\\`u}' , 'ù'],
\ ['\\^u}' , 'û'],
\ ['\\¨u}' , 'ü'],
\ ['\\"u}' , 'ü'],
\ ['\\`N}' , 'Ǹ'],
\ ['\\\~N}' , 'Ñ'],
\ ['\\''n}' , 'ń'],
\ ['\\`n}' , 'ǹ'],
\ ['\\\~n}' , 'ñ'],
\], '[''\C\(\\IeC\s*{\)\?'' . v:val[0], v:val[1]]')
" }}}
" TOC Command {{{