Skip to content

Commit

Permalink
Version 0.9.5
Browse files Browse the repository at this point in the history
bug fixes
some support for tcsh
patch to wrap in environment by W. E. Skeith
  • Loading branch information
mungerd authored and vim-scripts committed Oct 18, 2011
1 parent 2e27392 commit 297acb9
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 37 deletions.
25 changes: 15 additions & 10 deletions ftplugin/latex-box/common.vim
Expand Up @@ -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)
Expand Down Expand Up @@ -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*{'
Expand Down Expand Up @@ -124,15 +130,15 @@ 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')
if l:file !~ '\.tex$'
let l:file .= '.tex'
endif
endwhile
execute 'cd ' . saved_dir
execute 'cd ' . fnameescape(saved_dir)
return l:file
endfunction

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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*{[^}]*}\|\\\@<!\\\[\|\\\@<!\\('
let end_pat = '\C\\end\_\s*{[^}]*}\|\\\@<!\\\]\|\\\@<!\\)'
let saved_pos = getpos('.')

" move to the left until on a backslash
Expand Down
22 changes: 17 additions & 5 deletions ftplugin/latex-box/complete.vim
Expand Up @@ -104,7 +104,7 @@ endfunction
" the optional argument is the file name to be searched
function! LatexBox_kpsewhich(file)
let old_dir = getcwd()
execute 'lcd ' . LatexBox_GetTexRoot()
execute 'lcd ' . fnameescape(LatexBox_GetTexRoot())
redir => out
silent execute '!kpsewhich ' . a:file
redir END
Expand All @@ -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
Expand Down Expand Up @@ -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! `<O\begin{' . env . '}'
" indent and format, if requested.
if a:0 && a:1
normal! gv>
normal! gvgq
endif
else
execute 'keepjumps normal! `>a\end{' . env . '}'
execute 'keepjumps normal! `<i\begin{' . env . '}'
end
endif
exe "setlocal indentexpr=" . ieOld
endfunction
" }}}

Expand Down Expand Up @@ -403,6 +414,7 @@ endfunction
imap <silent> <Plug>LatexCloseCurEnv <C-R>=<SID>CloseCurEnv()<CR>
vmap <silent> <Plug>LatexWrapSelection :<c-u>call <SID>WrapSelection('')<CR>i
vmap <silent> <Plug>LatexEnvWrapSelection :<c-u>call <SID>PromptEnvWrapSelection()<CR>
vmap <silent> <Plug>LatexEnvWrapFmtSelection :<c-u>call <SID>PromptEnvWrapSelection(1)<CR>
nmap <silent> <Plug>LatexChangeEnv :call <SID>ChangeEnvPrompt()<CR>
" }}}

Expand Down
41 changes: 26 additions & 15 deletions ftplugin/latex-box/latexmk.vim
Expand Up @@ -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
" }}}
Expand Down Expand Up @@ -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
" }}}

Expand Down Expand Up @@ -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
" }}}

Expand Down Expand Up @@ -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(<q-bang> == "!")
command! -buffer -bang LatexmkClean call LatexBox_LatexmkClean(<q-bang> == "!")
command! -buffer -bang LatexmkStatus call LatexBox_LatexmkStatus(<q-bang> == "!")
command! -buffer LatexmkStop call LatexBox_LatexmkStop()
command! -buffer LatexErrors call LatexBox_LatexErrors(1)
" }}}

autocmd VimLeavePre * call <SID>kill_all_latexmk()
Expand Down
6 changes: 3 additions & 3 deletions ftplugin/latex-box/mappings.vim
Expand Up @@ -6,11 +6,11 @@ endif

" latexmk {{{
map <buffer> <LocalLeader>ll :Latexmk<CR>
map <buffer> <LocalLeader>lL :LatexmkForce<CR>
map <buffer> <LocalLeader>lL :Latexmk!<CR>
map <buffer> <LocalLeader>lc :LatexmkClean<CR>
map <buffer> <LocalLeader>lC :LatexmkCleanAll<CR>
map <buffer> <LocalLeader>lC :LatexmkClean!<CR>
map <buffer> <LocalLeader>lg :LatexmkStatus<CR>
map <buffer> <LocalLeader>lG :LatexmkStatusDetailed<CR>
map <buffer> <LocalLeader>lG :LatexmkStatus!<CR>
map <buffer> <LocalLeader>lk :LatexmkStop<CR>
map <buffer> <LocalLeader>le :LatexErrors<CR>
" }}}
Expand Down
6 changes: 3 additions & 3 deletions ftplugin/latex-box/motion.vim
Expand Up @@ -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 = '\\\@<!\$'

let saved_pos = getpos('.')
Expand Down Expand Up @@ -272,7 +272,7 @@ function! s:ReadTOC(auxfile)
let text = substitute(text, '^{\+\|}\+$', '', 'g')

" add TOC entry
call add(toc, {'file': fnamemodify(a:auxfile, ':r') . '.tex',
call add(toc, {'file': bufname('%'),
\ 'level': level, 'number': secnum, 'text': text, 'page': page})
endfor

Expand Down
2 changes: 1 addition & 1 deletion ftplugin/tex_LatexBox.vim
@@ -1,7 +1,7 @@
" LaTeX Box plugin for Vim
" Maintainer: David Munger
" Email: mungerd@gmail.com
" Version: 0.9.4
" Version: 0.9.5

if has('*fnameescape')
function! s:FNameEscape(s)
Expand Down

0 comments on commit 297acb9

Please sign in to comment.