From 297acb984ced74aaffd26f55f8ee4448b5d55020 Mon Sep 17 00:00:00 2001 From: David Munger Date: Sat, 15 Oct 2011 00:00:00 +0000 Subject: [PATCH] Version 0.9.5 bug fixes some support for tcsh patch to wrap in environment by W. E. Skeith --- ftplugin/latex-box/common.vim | 25 ++++++++++++-------- ftplugin/latex-box/complete.vim | 22 ++++++++++++++---- ftplugin/latex-box/latexmk.vim | 41 +++++++++++++++++++++------------ ftplugin/latex-box/mappings.vim | 6 ++--- ftplugin/latex-box/motion.vim | 6 ++--- ftplugin/tex_LatexBox.vim | 2 +- 6 files changed, 65 insertions(+), 37 deletions(-) diff --git a/ftplugin/latex-box/common.vim b/ftplugin/latex-box/common.vim index 2117896..1cf18fb 100644 --- a/ftplugin/latex-box/common.vim +++ b/ftplugin/latex-box/common.vim @@ -7,10 +7,16 @@ " g:vim_program {{{ if !exists('g:vim_program') + if match(&shell, '/bash$') >= 0 + let ppid = '$PPID' + else + let ppid = '$$' + endif + " attempt autodetection of vim executable let g:vim_program = '' let tmpfile = tempname() - silent execute '!ps -o command= -p $PPID > ' . tmpfile + silent execute '!ps -o command= -p ' . ppid . ' > ' . tmpfile for line in readfile(tmpfile) let line = matchstr(line, '^\S\+\>') if !empty(line) && executable(line) @@ -53,7 +59,7 @@ if !exists('g:LatexBox_bibtex_wild_spaces') endif if !exists('g:LatexBox_cite_pattern') - let g:LatexBox_cite_pattern = '\C\\cite\(p\|t\)\?\*\?\_\s*{' + let g:LatexBox_cite_pattern = '\C\\cite\(p\|t\)\=\*\=\(\[[^\]]*\]\)*\_\s*{' endif if !exists('g:LatexBox_ref_pattern') let g:LatexBox_ref_pattern = '\C\\v\?\(eq\|page\)\?ref\*\?\_\s*{' @@ -124,7 +130,7 @@ endfunction function! s:PromptForMainFile() let saved_dir = getcwd() - execute 'cd ' . expand('%:p:h') + execute 'cd ' . fnameescape(expand('%:p:h')) let l:file = '' while glob(l:file, 1) == '' let l:file = input('main LaTeX file: ', '', 'file') @@ -132,7 +138,7 @@ function! s:PromptForMainFile() let l:file .= '.tex' endif endwhile - execute 'cd ' . saved_dir + execute 'cd ' . fnameescape(saved_dir) return l:file endfunction @@ -170,10 +176,9 @@ function! LatexBox_View() return endif let cmd = '!' . g:LatexBox_viewer . ' ' . shellescape(outfile) . ' &>/dev/null &' - if has("gui_running") - silent execute cmd - else - execute cmd + silent execute cmd + if !has("gui_running") + redraw! endif endfunction @@ -203,8 +208,8 @@ function! LatexBox_GetCurrentEnvironment(...) let with_pos = 0 endif - let begin_pat = '\C\\begin\_\s*{[^}]*}\|\\\[\|\\(' - let end_pat = '\C\\end\_\s*{[^}]*}\|\\\]\|\\)' + let begin_pat = '\C\\begin\_\s*{[^}]*}\|\\\@ out silent execute '!kpsewhich ' . a:file redir END @@ -113,7 +113,7 @@ function! LatexBox_kpsewhich(file) let out = substitute(out, '\r', '', 'g') let out = glob(fnamemodify(out, ':p'), 1) - execute 'lcd ' . old_dir + execute 'lcd ' . fnameescape(old_dir) return out endfunction @@ -324,18 +324,29 @@ endfunction " }}} " Wrap Selection in Environment with Prompt {{{ -function! s:PromptEnvWrapSelection() +function! s:PromptEnvWrapSelection(...) let env = input('environment: ', '', 'customlist,' . s:SIDWrap('GetEnvironmentList')) if empty(env) return endif - if visualmode() == 'V' + " LaTeXBox's custom indentation can interfere with environment + " insertion when environments are indented (common for nested + " environments). Temporarily disable it for this operation: + let ieOld = &indentexpr + setlocal indentexpr="" + if visualmode() ==# 'V' execute 'keepjumps normal! `>o\end{' . env . '}' execute 'keepjumps normal! ` + normal! gvgq + endif else execute 'keepjumps normal! `>a\end{' . env . '}' execute 'keepjumps normal! ` LatexCloseCurEnv =CloseCurEnv() vmap LatexWrapSelection :call WrapSelection('')i vmap LatexEnvWrapSelection :call PromptEnvWrapSelection() +vmap LatexEnvWrapFmtSelection :call PromptEnvWrapSelection(1) nmap LatexChangeEnv :call ChangeEnvPrompt() " }}} diff --git a/ftplugin/latex-box/latexmk.vim b/ftplugin/latex-box/latexmk.vim index 33228ad..3b50f7f 100644 --- a/ftplugin/latex-box/latexmk.vim +++ b/ftplugin/latex-box/latexmk.vim @@ -30,7 +30,7 @@ function! s:LatexmkCallback(basename, status) echomsg "latexmk finished" endif call remove(s:latexmk_running_pids, a:basename) - call LatexBox_LatexErrors(g:LatexBox_autojump, a:basename) + call LatexBox_LatexErrors(g:LatexBox_autojump && a:status, a:basename) "call setpos('.', pos) endfunction " }}} @@ -64,17 +64,28 @@ function! LatexBox_Latexmk(force) let vimsetpid = g:vim_program . ' --servername ' . v:servername . ' --remote-expr ' . \ shellescape(callsetpid) . '\(\"' . fnameescape(basename) . '\",$$\)' - " latexmk command " wrap width in log file let max_print_line = 2000 - let cmd = 'cd ' . shellescape(LatexBox_GetTexRoot()) . ' ; max_print_line=' . max_print_line . + + " set environment + if match(&shell, '/tcsh$') >= 0 + let l:env = 'setenv max_print_line ' . max_print_line . '; ' + else + let l:env = 'max_print_line=' . max_print_line + endif + + " latexmk command + let cmd = 'cd ' . shellescape(LatexBox_GetTexRoot()) . ' ; ' . l:env . \ ' latexmk ' . l:options . ' ' . shellescape(LatexBox_GetMainTexFile()) " callback after latexmk is finished let vimcmd = g:vim_program . ' --servername ' . v:servername . ' --remote-expr ' . \ shellescape(callback) . '\(\"' . fnameescape(basename) . '\",$?\)' - silent execute '! ( ' . vimsetpid . ' ; ( ' . cmd . ' ) ; ' . vimcmd . ' ) &' + silent execute '! ( ' . vimsetpid . ' ; ( ' . cmd . ' ) ; ' . vimcmd . ' ) >&/dev/null &' + if !has("gui_running") + redraw! + endif endfunction " }}} @@ -142,11 +153,14 @@ function! LatexBox_LatexmkClean(cleanall) let l:options = '-c' endif - let l:cmd = 'cd ' . shellescape(LatexBox_GetTexRoot()) . ' ; latexmk ' . l:options - \ . ' ' . shellescape(LatexBox_GetMainTexFile()) + silent execute '! cd ' . shellescape(LatexBox_GetTexRoot()) . ' ; latexmk ' . l:options + \ . ' ' . shellescape(LatexBox_GetMainTexFile()) . ' >&/dev/null' + if !has("gui_running") + redraw! + endif - silent execute '! ' . l:cmd echomsg "latexmk clean finished" + endfunction " }}} @@ -196,14 +210,11 @@ endfunction " }}} " Commands {{{ -command! Latexmk call LatexBox_Latexmk(0) -command! LatexmkForce call LatexBox_Latexmk(1) -command! LatexmkClean call LatexBox_LatexmkClean(0) -command! LatexmkCleanAll call LatexBox_LatexmkClean(1) -command! LatexmkStatus call LatexBox_LatexmkStatus(0) -command! LatexmkStatusDetailed call LatexBox_LatexmkStatus(1) -command! LatexmkStop call LatexBox_LatexmkStop() -command! LatexErrors call LatexBox_LatexErrors(1) +command! -buffer -bang Latexmk call LatexBox_Latexmk( == "!") +command! -buffer -bang LatexmkClean call LatexBox_LatexmkClean( == "!") +command! -buffer -bang LatexmkStatus call LatexBox_LatexmkStatus( == "!") +command! -buffer LatexmkStop call LatexBox_LatexmkStop() +command! -buffer LatexErrors call LatexBox_LatexErrors(1) " }}} autocmd VimLeavePre * call kill_all_latexmk() diff --git a/ftplugin/latex-box/mappings.vim b/ftplugin/latex-box/mappings.vim index 3937d10..5a016f5 100644 --- a/ftplugin/latex-box/mappings.vim +++ b/ftplugin/latex-box/mappings.vim @@ -6,11 +6,11 @@ endif " latexmk {{{ map ll :Latexmk -map lL :LatexmkForce +map lL :Latexmk! map lc :LatexmkClean -map lC :LatexmkCleanAll +map lC :LatexmkClean! map lg :LatexmkStatus -map lG :LatexmkStatusDetailed +map lG :LatexmkStatus! map lk :LatexmkStop map le :LatexErrors " }}} diff --git a/ftplugin/latex-box/motion.vim b/ftplugin/latex-box/motion.vim index 3272eaf..5218a0b 100644 --- a/ftplugin/latex-box/motion.vim +++ b/ftplugin/latex-box/motion.vim @@ -63,8 +63,8 @@ function! s:JumpToMatch(mode, ...) endif " open/close pairs (dollars signs are treated apart) - let open_pats = ['{', '\[', '(', '\\begin\>', '\\left\>'] - let close_pats = ['}', '\]', ')', '\\end\>', '\\right\>'] + let open_pats = ['{', '\[', '(', '\\begin\>', '\\left\>', '\\lceil\>', '\\lgroup\>', '\\lfloor', '\\langle'] + let close_pats = ['}', '\]', ')', '\\end\>', '\\right\>', '\\rceil', '\\rgroup\>', '\\rfloor', '\\rangle'] let dollar_pat = '\\\@