diff --git a/autoload/latex.vim b/autoload/latex.vim index b0c5e3b..e2ee480 100644 --- a/autoload/latex.vim +++ b/autoload/latex.vim @@ -48,7 +48,7 @@ endfunction " {{{1 latex#help function! latex#help() - if g:latex_default_mappings + if g:latex_mappings_enabled echo "Latex mappings" nmap vmap @@ -72,10 +72,12 @@ function! latex#reinit() " " Reset and reinitialize buffers " + let n = bufnr('%') bufdo if getbufvar('%', '&filetype') == 'tex' | - \ unlet b:notbslash b:notcomment b:latex | - \ call latex#init() | + \ unlet b:latex | + \ call latex#init() | \ endif + silent execute 'buffer ' . n endfunction " {{{1 latex#view @@ -101,13 +103,6 @@ function! s:init_environment() call latex#util#set_default('g:latex#data', []) call latex#util#set_default('b:latex', {}) - " - " Initialize some common patterns - " - call latex#util#set_default('b:notbslash', '\%(\\\@ li :call latex#info() nnoremap lh :call latex#help() nnoremap lv :call latex#view() nnoremap lR :call latex#reinit() - inoremap \item + inoremap \item endif endfunction diff --git a/autoload/latex/change.vim b/autoload/latex/change.vim index 2ea7caf..56f44eb 100644 --- a/autoload/latex/change.vim +++ b/autoload/latex/change.vim @@ -1,6 +1,6 @@ " {{{1 latex#change#init function! latex#change#init(initialized) - if g:latex_default_mappings + if g:latex_mappings_enabled nnoremap dse :call latex#change#env('') nnoremap cse :call latex#change#env_prompt() diff --git a/autoload/latex/fold.vim b/autoload/latex/fold.vim index fa0e084..e3f9323 100644 --- a/autoload/latex/fold.vim +++ b/autoload/latex/fold.vim @@ -6,7 +6,7 @@ function! latex#fold#init(initialized) setl foldtext=latex#fold#text() call latex#fold#refresh() - if g:latex_default_mappings + if g:latex_mappings_enabled nnoremap zx :call latex#fold#refresh()zx endif @@ -69,9 +69,9 @@ function! latex#fold#level(lnum) " Fold environments if g:latex_fold_envs - if line =~# b:notcomment . b:notbslash . '\\begin\s*{.\{-}}' + if line =~# s:notcomment . s:notbslash . '\\begin\s*{.\{-}}' return "a1" - elseif line =~# b:notcomment . b:notbslash . '\\end\s*{.\{-}}' + elseif line =~# s:notcomment . s:notbslash . '\\end\s*{.\{-}}' return "s1" endif endif @@ -163,6 +163,10 @@ function! latex#fold#text() endfunction " }}}1 +" {{{1 s:notbslash and s:notcomment +let s:notbslash = '\%(\\\@ ll :call latex#latexmk#compile() nnoremap lc :call latex#latexmk#clean() nnoremap lC :call latex#latexmk#clean(1) diff --git a/autoload/latex/motion.vim b/autoload/latex/motion.vim index c3ef26e..711c04f 100644 --- a/autoload/latex/motion.vim +++ b/autoload/latex/motion.vim @@ -2,7 +2,7 @@ function! latex#motion#init(initialized) if !g:latex_motion_enabled | return | endif - if g:latex_default_mappings + if g:latex_mappings_enabled nnoremap % :call latex#motion#find_matching_pair() vnoremap % \ :call latex#motion#find_matching_pair(1) @@ -88,7 +88,7 @@ function! latex#motion#find_matching_pair(...) " Finally, find the matching delimiter if delim =~ '^\$' - let inline = b:notcomment . b:notbslash . '\$' + let inline = s:notcomment . s:notbslash . '\$' let [lnum0, cnum0] = searchpos('.', 'nW') if lnum0 && latex#util#has_syntax('texMathZoneX', lnum0, cnum0) let [lnum2, cnum2] = searchpos(inline, 'nW', 0, 200) @@ -99,8 +99,8 @@ function! latex#motion#find_matching_pair(...) call cursor(lnum2,cnum2) else for i in range(len(s:delimiters)) - let open_pat = '\C' . b:notbslash . s:delimiters_open[i] - let close_pat = '\C' . b:notbslash . s:delimiters_close[i] + let open_pat = '\C' . s:notbslash . s:delimiters_open[i] + let close_pat = '\C' . s:notbslash . s:delimiters_close[i] if delim =~# '^' . open_pat call searchpairpos(open_pat, '', close_pat, @@ -250,6 +250,9 @@ endfunction " {{{1 Common patterns +let s:notbslash = '\%(\\\@' @@ -310,11 +313,11 @@ function! s:highlight_matching_pair(...) " let [lnum0, cnum0] = searchpos('.', 'nW') 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) else let [lnum2, cnum2] = searchpos('\%(\%'. nl . 'l\%' - \ . cnum . 'c\)\@!'. b:notcomment . b:notbslash . '\$', + \ . cnum . 'c\)\@!'. s:notcomment . s:notbslash . '\$', \ 'bnW', line('w0'), 200) endif @@ -325,8 +328,8 @@ function! s:highlight_matching_pair(...) " Match other delimitors " for i in range(len(s:delimiters_open)) - let open_pat = '\C' . b:notbslash . s:delimiters_open[i] - let close_pat = '\C' . b:notbslash . s:delimiters_close[i] + let open_pat = '\C' . s:notbslash . s:delimiters_open[i] + let close_pat = '\C' . s:notbslash . s:delimiters_close[i] if delim =~# '^' . open_pat let [lnum2, cnum2] = searchpairpos(open_pat, '', close_pat, diff --git a/autoload/latex/toc.vim b/autoload/latex/toc.vim index 98bef68..49bffd0 100644 --- a/autoload/latex/toc.vim +++ b/autoload/latex/toc.vim @@ -1,6 +1,6 @@ " {{{1 latex#toc#init function! latex#toc#init(initialized) - if g:latex_default_mappings && g:latex_toc_enabled + if g:latex_mappings_enabled && g:latex_toc_enabled nnoremap lt :call latex#toc#open() nnoremap lT :call latex#toc#toggle() endif diff --git a/ftplugin/tex.vim b/ftplugin/tex.vim index 782a1e5..ffb69cc 100644 --- a/ftplugin/tex.vim +++ b/ftplugin/tex.vim @@ -7,72 +7,62 @@ if exists('g:latex_enabled') && !g:latex_enabled finish endif - if exists('b:did_ftplugin') finish endif let b:did_ftplugin = 1 -" Set default options -" {{{1 Completion +" {{{1 Options + +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_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*{[^{}]*', \ 'bib' : '\C\\\a*cite\a*\*\?\(\[[^\]]*\]\)*\_\s*{[^{}]*', \ }) - -" {{{1 Folding +call latex#util#set_default('g:latex_errorformat_show_warnings', 1) +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_preamble', 1) call latex#util#set_default('g:latex_fold_envs', 1) call latex#util#set_default('g:latex_fold_parts', \ [ - \ "appendix", - \ "frontmatter", - \ "mainmatter", - \ "backmatter", + \ "appendix", + \ "frontmatter", + \ "mainmatter", + \ "backmatter", \ ]) call latex#util#set_default('g:latex_fold_sections', \ [ - \ "part", - \ "chapter", - \ "section", - \ "subsection", - \ "subsubsection", + \ "part", + \ "chapter", + \ "section", + \ "subsection", + \ "subsubsection", \ ]) - -" {{{1 Latexmk +call latex#util#set_default('g:latex_indent_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_output', 'pdf') 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', \ [ - \ 'main', - \ 'memo', - \ 'note', - \ 'report', - \ 'thesis', + \ 'main', + \ 'memo', + \ 'note', + \ 'report', + \ 'thesis', \]) -call latex#util#set_default('g:latex_errorformat_show_warnings', 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_mappings_enabled', 1) call latex#util#set_default('g:latex_motion_enabled', 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_width', 30) 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_fold', 0) call latex#util#set_default('g:latex_toc_fold_levels', 0) +call latex#util#set_default('g:latex_viewer', 'xdg-open') + " }}}1 call latex#init() diff --git a/indent/tex.vim b/indent/tex.vim index e72c028..dff2fc6 100644 --- a/indent/tex.vim +++ b/indent/tex.vim @@ -7,7 +7,7 @@ set cpo&vim " {{{1 Options and common patterns setlocal autoindent -setlocal indentexpr=s:indent() +setlocal indentexpr=LatexIndent() setlocal indentkeys& setlocal indentkeys+=[,(,{,),},],\&,0=item @@ -38,8 +38,8 @@ let s:delimiters_close = '\(' . join([ \ ], '\|') . '\)' " }}}1 -" {{{1 s:indent -function! s:indent() +" {{{1 LatexIndent +function! LatexIndent() " Find a non-blank non-comment line above the current line let lnum = prevnonblank(v:lnum - 1) 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_close) - echom max([0, sum1]) + min([0, sum2]) return max([0, sum1]) + min([0, sum2]) endfunction