Some updates and improvements

This commit is contained in:
Karl Yngve Lervåg 2013-10-10 21:48:52 +02:00
parent d427907af2
commit 00b4e1fe3d
8 changed files with 62 additions and 69 deletions

View File

@ -48,7 +48,7 @@ endfunction
" {{{1 latex#help " {{{1 latex#help
function! latex#help() function! latex#help()
if g:latex_default_mappings if g:latex_mappings_enabled
echo "Latex mappings" echo "Latex mappings"
nmap <buffer> nmap <buffer>
vmap <buffer> vmap <buffer>
@ -72,10 +72,12 @@ function! latex#reinit()
" "
" Reset and reinitialize buffers " Reset and reinitialize buffers
" "
let n = bufnr('%')
bufdo if getbufvar('%', '&filetype') == 'tex' | bufdo if getbufvar('%', '&filetype') == 'tex' |
\ unlet b:notbslash b:notcomment b:latex | \ unlet b:latex |
\ call latex#init() | \ call latex#init() |
\ endif \ endif
silent execute 'buffer ' . n
endfunction endfunction
" {{{1 latex#view " {{{1 latex#view
@ -101,13 +103,6 @@ function! s:init_environment()
call latex#util#set_default('g:latex#data', []) call latex#util#set_default('g:latex#data', [])
call latex#util#set_default('b:latex', {}) call latex#util#set_default('b:latex', {})
"
" Initialize some common patterns
"
call latex#util#set_default('b:notbslash', '\%(\\\@<!\%(\\\\\)*\)\@<=')
call latex#util#set_default('b:notcomment',
\ '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!')
" "
" Create new or link to old blob " Create new or link to old blob
" "
@ -135,13 +130,13 @@ function! s:init_environment()
let b:latex.id = len(g:latex#data) - 1 let b:latex.id = len(g:latex#data) - 1
endif endif
if g:latex_default_mappings if g:latex_mappings_enabled
nnoremap <silent><buffer> <localleader>li :call latex#info()<cr> nnoremap <silent><buffer> <localleader>li :call latex#info()<cr>
nnoremap <silent><buffer> <localleader>lh :call latex#help()<cr> nnoremap <silent><buffer> <localleader>lh :call latex#help()<cr>
nnoremap <silent><buffer> <localleader>lv :call latex#view()<cr> nnoremap <silent><buffer> <localleader>lv :call latex#view()<cr>
nnoremap <silent><buffer> <LocalLeader>lR :call latex#reinit()<cr> nnoremap <silent><buffer> <LocalLeader>lR :call latex#reinit()<cr>
inoremap <silent><buffer> <m-i> \item inoremap <silent><buffer> <m-i> \item<space>
endif endif
endfunction endfunction

View File

@ -1,6 +1,6 @@
" {{{1 latex#change#init " {{{1 latex#change#init
function! latex#change#init(initialized) function! latex#change#init(initialized)
if g:latex_default_mappings if g:latex_mappings_enabled
nnoremap <silent><buffer> dse :call latex#change#env('')<cr> nnoremap <silent><buffer> dse :call latex#change#env('')<cr>
nnoremap <silent><buffer> cse :call latex#change#env_prompt()<cr> nnoremap <silent><buffer> cse :call latex#change#env_prompt()<cr>

View File

@ -6,7 +6,7 @@ function! latex#fold#init(initialized)
setl foldtext=latex#fold#text() setl foldtext=latex#fold#text()
call latex#fold#refresh() call latex#fold#refresh()
if g:latex_default_mappings if g:latex_mappings_enabled
nnoremap <silent><buffer> zx :call latex#fold#refresh()<cr>zx nnoremap <silent><buffer> zx :call latex#fold#refresh()<cr>zx
endif endif
@ -69,9 +69,9 @@ function! latex#fold#level(lnum)
" Fold environments " Fold environments
if g:latex_fold_envs if g:latex_fold_envs
if line =~# b:notcomment . b:notbslash . '\\begin\s*{.\{-}}' if line =~# s:notcomment . s:notbslash . '\\begin\s*{.\{-}}'
return "a1" return "a1"
elseif line =~# b:notcomment . b:notbslash . '\\end\s*{.\{-}}' elseif line =~# s:notcomment . s:notbslash . '\\end\s*{.\{-}}'
return "s1" return "s1"
endif endif
endif endif
@ -163,6 +163,10 @@ function! latex#fold#text()
endfunction endfunction
" }}}1 " }}}1
" {{{1 s:notbslash and s:notcomment
let s:notbslash = '\%(\\\@<!\%(\\\\\)*\)\@<='
let s:notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
" {{{1 s:fdm_restore " {{{1 s:fdm_restore
function! s:fdm_restore() function! s:fdm_restore()
silent execute 'setlocal foldmethod=' . s:fdm silent execute 'setlocal foldmethod=' . s:fdm

View File

@ -12,7 +12,7 @@ function! latex#latexmk#init(initialized)
" "
" Set default mappings " Set default mappings
" "
if g:latex_default_mappings if g:latex_mappings_enabled
nnoremap <silent><buffer> <localleader>ll :call latex#latexmk#compile()<cr> nnoremap <silent><buffer> <localleader>ll :call latex#latexmk#compile()<cr>
nnoremap <silent><buffer> <localleader>lc :call latex#latexmk#clean()<cr> nnoremap <silent><buffer> <localleader>lc :call latex#latexmk#clean()<cr>
nnoremap <silent><buffer> <localleader>lC :call latex#latexmk#clean(1)<cr> nnoremap <silent><buffer> <localleader>lC :call latex#latexmk#clean(1)<cr>

View File

@ -2,7 +2,7 @@
function! latex#motion#init(initialized) function! latex#motion#init(initialized)
if !g:latex_motion_enabled | return | endif if !g:latex_motion_enabled | return | endif
if g:latex_default_mappings if g:latex_mappings_enabled
nnoremap <silent><buffer> % :call latex#motion#find_matching_pair()<cr> nnoremap <silent><buffer> % :call latex#motion#find_matching_pair()<cr>
vnoremap <silent><buffer> % vnoremap <silent><buffer> %
\ :<c-u>call latex#motion#find_matching_pair(1)<cr> \ :<c-u>call latex#motion#find_matching_pair(1)<cr>
@ -88,7 +88,7 @@ function! latex#motion#find_matching_pair(...)
" Finally, find the matching delimiter " Finally, find the matching delimiter
if delim =~ '^\$' if delim =~ '^\$'
let inline = b:notcomment . b:notbslash . '\$' let inline = s:notcomment . s:notbslash . '\$'
let [lnum0, cnum0] = searchpos('.', 'nW') let [lnum0, cnum0] = searchpos('.', 'nW')
if lnum0 && latex#util#has_syntax('texMathZoneX', lnum0, cnum0) if lnum0 && latex#util#has_syntax('texMathZoneX', lnum0, cnum0)
let [lnum2, cnum2] = searchpos(inline, 'nW', 0, 200) let [lnum2, cnum2] = searchpos(inline, 'nW', 0, 200)
@ -99,8 +99,8 @@ function! latex#motion#find_matching_pair(...)
call cursor(lnum2,cnum2) call cursor(lnum2,cnum2)
else else
for i in range(len(s:delimiters)) for i in range(len(s:delimiters))
let open_pat = '\C' . b:notbslash . s:delimiters_open[i] let open_pat = '\C' . s:notbslash . s:delimiters_open[i]
let close_pat = '\C' . b:notbslash . s:delimiters_close[i] let close_pat = '\C' . s:notbslash . s:delimiters_close[i]
if delim =~# '^' . open_pat if delim =~# '^' . open_pat
call searchpairpos(open_pat, '', close_pat, call searchpairpos(open_pat, '', close_pat,
@ -250,6 +250,9 @@ endfunction
" {{{1 Common patterns " {{{1 Common patterns
let s:notbslash = '\%(\\\@<!\%(\\\\\)*\)\@<='
let s:notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
" Patterns to match opening and closing delimiters/environments " Patterns to match opening and closing delimiters/environments
let s:delimiters_open = [ let s:delimiters_open = [
\ '{', \ '{',
@ -277,7 +280,7 @@ let s:delimiters = join(s:delimiters_open + s:delimiters_close, '\|')
let s:delimiters = '\(' . s:delimiters . '\|\$\)' let s:delimiters = '\(' . s:delimiters . '\|\$\)'
" Pattern to match section/chapter/... " Pattern to match section/chapter/...
let s:section = b:notcomment . '\v\s*\\' let s:section = s:notcomment . '\v\s*\\'
let s:section.= '((sub)*section|chapter|part|appendix|(front|back|main)matter)' let s:section.= '((sub)*section|chapter|part|appendix|(front|back|main)matter)'
let s:section.= '>' let s:section.= '>'
@ -310,11 +313,11 @@ function! s:highlight_matching_pair(...)
" "
let [lnum0, cnum0] = searchpos('.', 'nW') let [lnum0, cnum0] = searchpos('.', 'nW')
if lnum0 && latex#util#has_syntax('texMathZoneX', lnum0, cnum0) if lnum0 && latex#util#has_syntax('texMathZoneX', lnum0, cnum0)
let [lnum2, cnum2] = searchpos(b:notcomment . b:notbslash . '\$', let [lnum2, cnum2] = searchpos(s:notcomment . s:notbslash . '\$',
\ 'nW', line('w$'), 200) \ 'nW', line('w$'), 200)
else else
let [lnum2, cnum2] = searchpos('\%(\%'. nl . 'l\%' let [lnum2, cnum2] = searchpos('\%(\%'. nl . 'l\%'
\ . cnum . 'c\)\@!'. b:notcomment . b:notbslash . '\$', \ . cnum . 'c\)\@!'. s:notcomment . s:notbslash . '\$',
\ 'bnW', line('w0'), 200) \ 'bnW', line('w0'), 200)
endif endif
@ -325,8 +328,8 @@ function! s:highlight_matching_pair(...)
" Match other delimitors " Match other delimitors
" "
for i in range(len(s:delimiters_open)) for i in range(len(s:delimiters_open))
let open_pat = '\C' . b:notbslash . s:delimiters_open[i] let open_pat = '\C' . s:notbslash . s:delimiters_open[i]
let close_pat = '\C' . b:notbslash . s:delimiters_close[i] let close_pat = '\C' . s:notbslash . s:delimiters_close[i]
if delim =~# '^' . open_pat if delim =~# '^' . open_pat
let [lnum2, cnum2] = searchpairpos(open_pat, '', close_pat, let [lnum2, cnum2] = searchpairpos(open_pat, '', close_pat,

View File

@ -1,6 +1,6 @@
" {{{1 latex#toc#init " {{{1 latex#toc#init
function! latex#toc#init(initialized) function! latex#toc#init(initialized)
if g:latex_default_mappings && g:latex_toc_enabled if g:latex_mappings_enabled && g:latex_toc_enabled
nnoremap <silent><buffer> <LocalLeader>lt :call latex#toc#open()<cr> nnoremap <silent><buffer> <LocalLeader>lt :call latex#toc#open()<cr>
nnoremap <silent><buffer> <LocalLeader>lT :call latex#toc#toggle()<cr> nnoremap <silent><buffer> <LocalLeader>lT :call latex#toc#toggle()<cr>
endif endif

View File

@ -7,22 +7,28 @@
if exists('g:latex_enabled') && !g:latex_enabled if exists('g:latex_enabled') && !g:latex_enabled
finish finish
endif endif
if exists('b:did_ftplugin') if exists('b:did_ftplugin')
finish finish
endif endif
let b:did_ftplugin = 1 let b:did_ftplugin = 1
" Set default options " {{{1 Options
" {{{1 Completion
call latex#util#set_default('g:latex_build_dir', '.')
call latex#util#set_default('g:latex_complete_enabled', 1) call latex#util#set_default('g:latex_complete_enabled', 1)
call latex#util#set_default('g:latex_complete_close_braces', 0) call latex#util#set_default('g:latex_complete_close_braces', 0)
call latex#util#set_default('g:latex_complete_patterns', { call latex#util#set_default('g:latex_complete_patterns',
\ {
\ 'ref' : '\C\\v\?\(eq\|page\|[cC]\)\?ref\*\?\_\s*{[^{}]*', \ 'ref' : '\C\\v\?\(eq\|page\|[cC]\)\?ref\*\?\_\s*{[^{}]*',
\ 'bib' : '\C\\\a*cite\a*\*\?\(\[[^\]]*\]\)*\_\s*{[^{}]*', \ 'bib' : '\C\\\a*cite\a*\*\?\(\[[^\]]*\]\)*\_\s*{[^{}]*',
\ }) \ })
call latex#util#set_default('g:latex_errorformat_show_warnings', 1)
" {{{1 Folding call latex#util#set_default('g:latex_errorformat_ignore_warnings',
\ [
\ 'Underfull',
\ 'Overfull',
\ 'specifier changed to',
\ ])
call latex#util#set_default('g:latex_fold_enabled', 1) call latex#util#set_default('g:latex_fold_enabled', 1)
call latex#util#set_default('g:latex_fold_preamble', 1) call latex#util#set_default('g:latex_fold_preamble', 1)
call latex#util#set_default('g:latex_fold_envs', 1) call latex#util#set_default('g:latex_fold_envs', 1)
@ -41,17 +47,11 @@ call latex#util#set_default('g:latex_fold_sections',
\ "subsection", \ "subsection",
\ "subsubsection", \ "subsubsection",
\ ]) \ ])
call latex#util#set_default('g:latex_indent_enabled', 1)
" {{{1 Latexmk
call latex#util#set_default('g:latex_latexmk_enabled', 1) call latex#util#set_default('g:latex_latexmk_enabled', 1)
call latex#util#set_default('g:latex_latexmk_options', '') call latex#util#set_default('g:latex_latexmk_options', '')
call latex#util#set_default('g:latex_latexmk_output', 'pdf') call latex#util#set_default('g:latex_latexmk_output', 'pdf')
call latex#util#set_default('g:latex_latexmk_autojump', '0') call latex#util#set_default('g:latex_latexmk_autojump', '0')
" {{{1 Miscelleneous
call latex#util#set_default('g:latex_default_mappings', 1)
call latex#util#set_default('g:latex_viewer', 'xdg-open')
call latex#util#set_default('g:latex_build_dir', '.')
call latex#util#set_default('g:latex_main_tex_candidates', call latex#util#set_default('g:latex_main_tex_candidates',
\ [ \ [
\ 'main', \ 'main',
@ -60,19 +60,9 @@ call latex#util#set_default('g:latex_main_tex_candidates',
\ 'report', \ 'report',
\ 'thesis', \ 'thesis',
\]) \])
call latex#util#set_default('g:latex_errorformat_show_warnings', 1) call latex#util#set_default('g:latex_mappings_enabled', 1)
call latex#util#set_default('g:latex_errorformat_ignore_warnings',
\ [
\ 'Underfull',
\ 'Overfull',
\ 'specifier changed to',
\ ])
" {{{1 Motion
call latex#util#set_default('g:latex_motion_enabled', 1) call latex#util#set_default('g:latex_motion_enabled', 1)
call latex#util#set_default('g:latex_motion_matchparen', 1) call latex#util#set_default('g:latex_motion_matchparen', 1)
" {{{1 Toc
call latex#util#set_default('g:latex_toc_enabled', 1) call latex#util#set_default('g:latex_toc_enabled', 1)
call latex#util#set_default('g:latex_toc_width', 30) call latex#util#set_default('g:latex_toc_width', 30)
call latex#util#set_default('g:latex_toc_split_side', 'leftabove') call latex#util#set_default('g:latex_toc_split_side', 'leftabove')
@ -80,6 +70,8 @@ call latex#util#set_default('g:latex_toc_resize', 1)
call latex#util#set_default('g:latex_toc_hide_help', 0) call latex#util#set_default('g:latex_toc_hide_help', 0)
call latex#util#set_default('g:latex_toc_fold', 0) call latex#util#set_default('g:latex_toc_fold', 0)
call latex#util#set_default('g:latex_toc_fold_levels', 0) call latex#util#set_default('g:latex_toc_fold_levels', 0)
call latex#util#set_default('g:latex_viewer', 'xdg-open')
" }}}1 " }}}1
call latex#init() call latex#init()

View File

@ -7,7 +7,7 @@ set cpo&vim
" {{{1 Options and common patterns " {{{1 Options and common patterns
setlocal autoindent setlocal autoindent
setlocal indentexpr=s:indent() setlocal indentexpr=LatexIndent()
setlocal indentkeys& setlocal indentkeys&
setlocal indentkeys+=[,(,{,),},],\&,0=item setlocal indentkeys+=[,(,{,),},],\&,0=item
@ -38,8 +38,8 @@ let s:delimiters_close = '\(' . join([
\ ], '\|') . '\)' \ ], '\|') . '\)'
" }}}1 " }}}1
" {{{1 s:indent " {{{1 LatexIndent
function! s:indent() function! LatexIndent()
" Find a non-blank non-comment line above the current line " Find a non-blank non-comment line above the current line
let lnum = prevnonblank(v:lnum - 1) let lnum = prevnonblank(v:lnum - 1)
while lnum != 0 && getline(lnum) =~ '^\s*%' while lnum != 0 && getline(lnum) =~ '^\s*%'
@ -130,7 +130,6 @@ function! s:indent_braces(cline, pline)
let sum2 = s:match_brace(a:cline, s:delimiters_open) let sum2 = s:match_brace(a:cline, s:delimiters_open)
let sum2 -= s:match_brace(a:cline, s:delimiters_close) let sum2 -= s:match_brace(a:cline, s:delimiters_close)
echom max([0, sum1]) + min([0, sum2])
return max([0, sum1]) + min([0, sum2]) return max([0, sum1]) + min([0, sum2])
endfunction endfunction