Added commands
Also made minor syntactical changes to source code folding
This commit is contained in:
parent
2de33a68d5
commit
cae066f778
@ -1,6 +1,7 @@
|
||||
" {{{1 latex#init
|
||||
" vim-latex is not initialized until latex#init() has been run once
|
||||
let s:initialized = 0
|
||||
function! latex#init()
|
||||
|
||||
function! latex#init() " {{{1
|
||||
call s:init_environment()
|
||||
call s:init_errorformat()
|
||||
|
||||
@ -18,8 +19,7 @@ function! latex#init()
|
||||
let s:initialized = 1
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#info
|
||||
function! latex#info()
|
||||
function! latex#info() " {{{1
|
||||
echo "b:latex"
|
||||
echo ' id: ' . b:latex.id
|
||||
if has_key(b:latex, 'fold_parts') && !empty(b:latex.fold_parts)
|
||||
@ -51,8 +51,7 @@ function! latex#info()
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#help
|
||||
function! latex#help()
|
||||
function! latex#help() " {{{1
|
||||
if g:latex_mappings_enabled
|
||||
nmap <buffer>
|
||||
vmap <buffer>
|
||||
@ -62,8 +61,7 @@ function! latex#help()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#reinit
|
||||
function! latex#reinit()
|
||||
function! latex#reinit() " {{{1
|
||||
"
|
||||
" Stop latexmk processes (if running)
|
||||
"
|
||||
@ -86,8 +84,7 @@ function! latex#reinit()
|
||||
silent execute 'buffer ' . n
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#view
|
||||
function! latex#view(...)
|
||||
function! latex#view(...) " {{{1
|
||||
let outfile = g:latex#data[b:latex.id].out()
|
||||
if !filereadable(outfile)
|
||||
echomsg "Can't view: Output file is not readable!"
|
||||
@ -104,8 +101,7 @@ function! latex#view(...)
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:init_environment
|
||||
function! s:init_environment()
|
||||
function! s:init_environment() " {{{1
|
||||
"
|
||||
" Initialize global and local data blobs
|
||||
"
|
||||
@ -139,6 +135,11 @@ function! s:init_environment()
|
||||
let b:latex.id = len(g:latex#data) - 1
|
||||
endif
|
||||
|
||||
command! -buffer VimLatexInfo call latex#info()
|
||||
command! -buffer VimLatexHelp call latex#help()
|
||||
command! -buffer VimLatexView call latex#view()
|
||||
command! -buffer VimLatexReinitialize call latex#reinit()
|
||||
|
||||
if g:latex_mappings_enabled
|
||||
nnoremap <silent><buffer> <localleader>li :call latex#info()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lh :call latex#help()<cr>
|
||||
@ -149,8 +150,7 @@ function! s:init_environment()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 s:init_errorformat
|
||||
function! s:init_errorformat()
|
||||
function! s:init_errorformat() " {{{1
|
||||
"
|
||||
" Note: The error formats assume we're using the -file-line-error with
|
||||
" [pdf]latex. For more info, see |errorformat-LaTeX|.
|
||||
@ -198,8 +198,7 @@ function! s:init_errorformat()
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:get_id
|
||||
function! s:get_id(main)
|
||||
function! s:get_id(main) " {{{1
|
||||
if exists('g:latex#data') && !empty(g:latex#data)
|
||||
let id = 0
|
||||
while id < len(g:latex#data)
|
||||
@ -213,8 +212,7 @@ function! s:get_id(main)
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
" {{{1 s:get_main
|
||||
function! s:get_main()
|
||||
function! s:get_main() " {{{1
|
||||
"
|
||||
" Search for main file specifier at the beginning of file. This is similar
|
||||
" to the method used by several other plugins and editors, such as vim with
|
||||
@ -245,8 +243,7 @@ function! s:get_main()
|
||||
return expand('%:p')
|
||||
endfunction
|
||||
|
||||
" {{{1 s:get_main_recurse
|
||||
function! s:get_main_recurse(file)
|
||||
function! s:get_main_recurse(file) " {{{1
|
||||
"
|
||||
" Check if file is readable
|
||||
"
|
||||
@ -281,8 +278,7 @@ function! s:get_main_recurse(file)
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" {{{1 s:get_main_ext
|
||||
function! s:get_main_ext(texdata, ext)
|
||||
function! s:get_main_ext(texdata, ext) " {{{1
|
||||
" Create set of candidates
|
||||
let candidates = [
|
||||
\ a:texdata.name,
|
||||
@ -301,8 +297,7 @@ function! s:get_main_ext(texdata, ext)
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
" {{{1 s:info_sort_func
|
||||
function! s:info_sort_func(a, b)
|
||||
function! s:info_sort_func(a, b) " {{{1
|
||||
if a:a[1][0] == "!"
|
||||
" Put cmd's way behind
|
||||
return 1
|
||||
@ -323,8 +318,7 @@ function! s:info_sort_func(a, b)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 s:truncate
|
||||
function! s:truncate(string)
|
||||
function! s:truncate(string) " {{{1
|
||||
if len(a:string) >= winwidth('.') - 9
|
||||
return a:string[0:10] . "..." . a:string[-winwidth('.')+23:]
|
||||
else
|
||||
|
@ -1,5 +1,4 @@
|
||||
" {{{1 latex#change#init
|
||||
function! latex#change#init(initialized)
|
||||
function! latex#change#init(initialized) " {{{1
|
||||
if g:latex_mappings_enabled
|
||||
nnoremap <silent><buffer> dse :call latex#change#env('')<cr>
|
||||
|
||||
@ -15,8 +14,7 @@ function! latex#change#init(initialized)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#change#close_environment
|
||||
function! latex#change#close_environment()
|
||||
function! latex#change#close_environment() " {{{1
|
||||
" Close delimiters
|
||||
let [lnum, cnum] = searchpairpos('\C\\left\>', '', '\C\\right\>', 'bnW',
|
||||
\ 'latex#util#in_comment()')
|
||||
@ -46,8 +44,7 @@ function! latex#change#close_environment()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#change#delim
|
||||
function! latex#change#delim(open, close)
|
||||
function! latex#change#delim(open, close) " {{{1
|
||||
let [d1, l1, c1, d2, l2, c2] = latex#util#get_delim()
|
||||
|
||||
let line = getline(l1)
|
||||
@ -67,8 +64,7 @@ function! latex#change#delim(open, close)
|
||||
call setline(l2, line)
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#change#env
|
||||
function! latex#change#env(new_env)
|
||||
function! latex#change#env(new_env) " {{{1
|
||||
let [env, l1, c1, l2, c2] = latex#util#get_env(1)
|
||||
|
||||
if a:new_env == ''
|
||||
@ -100,8 +96,7 @@ function! latex#change#env(new_env)
|
||||
call setline(l2, line)
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#change#env_prompt
|
||||
function! latex#change#env_prompt()
|
||||
function! latex#change#env_prompt() " {{{1
|
||||
let new_env = input('Change ' . latex#util#get_env() . ' for: ', '',
|
||||
\ 'customlist,' . s:sidwrap('input_complete'))
|
||||
if empty(new_env)
|
||||
@ -111,8 +106,7 @@ function! latex#change#env_prompt()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#change#to_command
|
||||
function! latex#change#to_command()
|
||||
function! latex#change#to_command() " {{{1
|
||||
" Get current line
|
||||
let line = getline('.')
|
||||
|
||||
@ -152,8 +146,7 @@ function! latex#change#to_command()
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#change#toggle_delim
|
||||
function! latex#change#toggle_delim()
|
||||
function! latex#change#toggle_delim() " {{{1
|
||||
"
|
||||
" Toggle \left and \right variants of delimiters
|
||||
"
|
||||
@ -188,8 +181,7 @@ function! latex#change#toggle_delim()
|
||||
call setline(l2, line)
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#change#toggle_env_star
|
||||
function! latex#change#toggle_env_star()
|
||||
function! latex#change#toggle_env_star() " {{{1
|
||||
let env = latex#util#get_env()
|
||||
|
||||
if env == '\('
|
||||
@ -206,14 +198,12 @@ function! latex#change#toggle_env_star()
|
||||
endfunction
|
||||
|
||||
|
||||
" {{{1 latex#change#wrap_selection
|
||||
function! latex#change#wrap_selection(wrapper)
|
||||
function! latex#change#wrap_selection(wrapper) " {{{1
|
||||
keepjumps normal! `>a}
|
||||
execute 'keepjumps normal! `<i\' . a:wrapper . '{'
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#change#wrap_selection_prompt
|
||||
function! latex#change#wrap_selection_prompt(...)
|
||||
function! latex#change#wrap_selection_prompt(...) " {{{1
|
||||
let env = input('Environment: ', '',
|
||||
\ 'customlist,' . s:sidwrap('input_complete'))
|
||||
if empty(env)
|
||||
@ -241,14 +231,13 @@ function! latex#change#wrap_selection_prompt(...)
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:sidwrap
|
||||
let s:SID = matchstr(expand('<sfile>'), '\zs<SNR>\d\+_\ze.*$')
|
||||
function! s:sidwrap(func)
|
||||
function! s:sidwrap(func) " {{{1
|
||||
return s:SID . a:func
|
||||
endfunction
|
||||
|
||||
" {{{1 s:input_complete
|
||||
function! s:input_complete(lead, cmdline, pos)
|
||||
let s:SID = matchstr(expand('<sfile>'), '\zs<SNR>\d\+_\ze.*$')
|
||||
|
||||
function! s:input_complete(lead, cmdline, pos) " {{{1
|
||||
let suggestions = []
|
||||
for entry in g:latex_complete_environments
|
||||
let env = entry.word
|
||||
@ -259,8 +248,7 @@ function! s:input_complete(lead, cmdline, pos)
|
||||
return suggestions
|
||||
endfunction
|
||||
|
||||
" {{{1 s:search_and_skip_comments
|
||||
function! s:search_and_skip_comments(pat, ...)
|
||||
function! s:search_and_skip_comments(pat, ...) " {{{1
|
||||
" Usage: s:search_and_skip_comments(pat, [flags, stopline])
|
||||
let flags = a:0 >= 1 ? a:1 : ''
|
||||
let stopline = a:0 >= 2 ? a:2 : 0
|
||||
|
@ -1,5 +1,6 @@
|
||||
" {{{1 latex#complete#init
|
||||
function! latex#complete#init(initialized)
|
||||
function! latex#complete#init(initialized) " {{{1
|
||||
if !g:latex_complete_enabled | return | endif
|
||||
|
||||
"
|
||||
" Check if bibtex is available
|
||||
"
|
||||
@ -19,15 +20,10 @@ function! latex#complete#init(initialized)
|
||||
let s:bibtex = 0
|
||||
endif
|
||||
|
||||
if g:latex_complete_enabled
|
||||
setlocal omnifunc=latex#complete#omnifunc
|
||||
endif
|
||||
setlocal omnifunc=latex#complete#omnifunc
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#complete#omnifunc
|
||||
let s:bibtex = 1
|
||||
let s:completion_type = ''
|
||||
function! latex#complete#omnifunc(findstart, base)
|
||||
function! latex#complete#omnifunc(findstart, base) " {{{1
|
||||
if a:findstart
|
||||
"
|
||||
" First call: Find start of text to be completed
|
||||
@ -64,8 +60,11 @@ function! latex#complete#omnifunc(findstart, base)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#complete#labels
|
||||
function! latex#complete#labels(regex)
|
||||
" Define auxiliary variables for completion
|
||||
let s:bibtex = 1
|
||||
let s:completion_type = ''
|
||||
|
||||
function! latex#complete#labels(regex) " {{{1
|
||||
let labels = s:labels_get(g:latex#data[b:latex.id].aux())
|
||||
let matches = filter(copy(labels), 'v:val[0] =~ ''' . a:regex . '''')
|
||||
|
||||
@ -103,8 +102,7 @@ function! latex#complete#labels(regex)
|
||||
return suggestions
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#complete#bibtex
|
||||
function! latex#complete#bibtex(regexp)
|
||||
function! latex#complete#bibtex(regexp) " {{{1
|
||||
let res = []
|
||||
|
||||
let s:type_length = 4
|
||||
@ -136,10 +134,7 @@ function! latex#complete#bibtex(regexp)
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:bibtex_search
|
||||
let s:bstfile = expand('<sfile>:p:h') . '/vimcomplete'
|
||||
let s:type_length = 0
|
||||
function! s:bibtex_search(regexp)
|
||||
function! s:bibtex_search(regexp) " {{{1
|
||||
let res = []
|
||||
|
||||
" Find data from external bib files
|
||||
@ -214,8 +209,11 @@ function! s:bibtex_search(regexp)
|
||||
return res
|
||||
endfunction
|
||||
|
||||
" {{{1 s:bibtex_find_bibs
|
||||
function! s:bibtex_find_bibs(...)
|
||||
" Define some auxiliary variables
|
||||
let s:bstfile = expand('<sfile>:p:h') . '/vimcomplete'
|
||||
let s:type_length = 0
|
||||
|
||||
function! s:bibtex_find_bibs(...) " {{{1
|
||||
if a:0
|
||||
let file = a:1
|
||||
else
|
||||
@ -259,7 +257,8 @@ function! s:bibtex_find_bibs(...)
|
||||
return bibdata_list
|
||||
endfunction
|
||||
|
||||
" {{{1 s:labels_cache
|
||||
" }}}1
|
||||
|
||||
"
|
||||
" s:label_cache is a dictionary that maps filenames to tuples of the form
|
||||
"
|
||||
@ -269,11 +268,9 @@ endfunction
|
||||
" returned by extract_labels, and inputs is a list like returned by
|
||||
" s:extract_inputs.
|
||||
"
|
||||
|
||||
let s:label_cache = {}
|
||||
|
||||
" {{{1 s:labels_get
|
||||
function! s:labels_get(file)
|
||||
function! s:labels_get(file) " {{{1
|
||||
"
|
||||
" s:labels_get compares modification time of each entry in the label cache
|
||||
" and updates it if necessary. During traversal of the label cache, all
|
||||
@ -307,8 +304,7 @@ function! s:labels_get(file)
|
||||
return labels
|
||||
endfunction
|
||||
|
||||
" {{{1 s:labels_extract
|
||||
function! s:labels_extract(file)
|
||||
function! s:labels_extract(file) " {{{1
|
||||
"
|
||||
" Searches file for commands of the form
|
||||
"
|
||||
@ -334,8 +330,7 @@ function! s:labels_extract(file)
|
||||
return matches
|
||||
endfunction
|
||||
|
||||
" {{{1 s:labels_extract_inputs
|
||||
function! s:labels_extract_inputs(file)
|
||||
function! s:labels_extract_inputs(file) " {{{1
|
||||
"
|
||||
" Searches file for \@input{file} entries and returns list of all files.
|
||||
"
|
||||
@ -348,8 +343,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:next_chars_match
|
||||
function! s:next_chars_match(regex)
|
||||
function! s:next_chars_match(regex) " {{{1
|
||||
return strpart(getline('.'), col('.') - 1) =~ a:regex
|
||||
endfunction
|
||||
" }}}1
|
||||
|
@ -1,44 +1,46 @@
|
||||
" {{{1 latex#fold#init
|
||||
function! latex#fold#init(initialized)
|
||||
if g:latex_fold_enabled
|
||||
setl foldmethod=expr
|
||||
setl foldexpr=latex#fold#level(v:lnum)
|
||||
setl foldtext=latex#fold#text()
|
||||
call latex#fold#refresh()
|
||||
function! latex#fold#init(initialized) " {{{1
|
||||
if !g:latex_fold_enabled | return | endif
|
||||
|
||||
if g:latex_mappings_enabled
|
||||
nnoremap <silent><buffer> zx :call latex#fold#refresh()<cr>zx
|
||||
endif
|
||||
" Set fold options
|
||||
setl foldmethod=expr
|
||||
setl foldexpr=latex#fold#level(v:lnum)
|
||||
setl foldtext=latex#fold#text()
|
||||
|
||||
"
|
||||
" For some reason, foldmethod=expr makes undo slow (at least in some cases)
|
||||
"
|
||||
nnoremap <silent><buffer> u :call FdmSave()<cr>u:call FdmRestore()<cr>
|
||||
" Refresh fold levels
|
||||
call latex#fold#refresh()
|
||||
|
||||
"
|
||||
" The foldexpr function returns "=" for most lines, which means it can
|
||||
" become slow for large files. The following is a hack that is based on
|
||||
" this reply to a discussion on the Vim Developer list:
|
||||
" http://permalink.gmane.org/gmane.editors.vim.devel/14100
|
||||
"
|
||||
if !a:initialized
|
||||
augroup latex_fold
|
||||
autocmd!
|
||||
autocmd InsertEnter *.tex call FdmSave()
|
||||
autocmd InsertLeave *.tex call FdmRestore()
|
||||
augroup END
|
||||
endif
|
||||
" Define commands and maps
|
||||
command! -buffer VimLatexRefreshFoldLevels call latex#fold#refresh()
|
||||
if g:latex_mappings_enabled
|
||||
nnoremap <silent><buffer> zx :call latex#fold#refresh()<cr>zx
|
||||
endif
|
||||
|
||||
"
|
||||
" For some reason, foldmethod=expr makes undo slow (at least in some cases)
|
||||
"
|
||||
nnoremap <silent><buffer> u :call FdmSave()<cr>u:call FdmRestore()<cr>
|
||||
|
||||
"
|
||||
" The foldexpr function returns "=" for most lines, which means it can
|
||||
" become slow for large files. The following is a hack that is based on
|
||||
" this reply to a discussion on the Vim Developer list:
|
||||
" http://permalink.gmane.org/gmane.editors.vim.devel/14100
|
||||
"
|
||||
if !a:initialized
|
||||
augroup latex_fold
|
||||
autocmd!
|
||||
autocmd InsertEnter *.tex call FdmSave()
|
||||
autocmd InsertLeave *.tex call FdmRestore()
|
||||
augroup END
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#fold#refresh
|
||||
function! latex#fold#refresh()
|
||||
function! latex#fold#refresh() " {{{1
|
||||
" Parse tex file to dynamically set the sectioning fold levels
|
||||
let b:latex.fold_parts = s:find_fold_parts()
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#fold#level
|
||||
function! latex#fold#level(lnum)
|
||||
function! latex#fold#level(lnum) " {{{1
|
||||
" Check for normal lines first (optimization)
|
||||
let line = getline(a:lnum)
|
||||
if line !~ '\(% Fake\|\\\(document\|begin\|end\|'
|
||||
@ -84,8 +86,7 @@ function! latex#fold#level(lnum)
|
||||
return "="
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#fold#text
|
||||
function! latex#fold#text()
|
||||
function! latex#fold#text() " {{{1
|
||||
" Initialize
|
||||
let line = getline(v:foldstart)
|
||||
let level = v:foldlevel > 1 ? repeat('-', v:foldlevel-2) . '*' : ''
|
||||
@ -158,25 +159,23 @@ function! latex#fold#text()
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
" {{{1 FdmRestore
|
||||
function! FdmRestore()
|
||||
function! FdmRestore() " {{{1
|
||||
let &l:foldmethod = s:fdm
|
||||
endfunction
|
||||
|
||||
" {{{1 FdmSave
|
||||
let s:fdm=''
|
||||
function! FdmSave()
|
||||
function! FdmSave() " {{{1
|
||||
let s:fdm = &l:foldmethod
|
||||
setlocal foldmethod=manual
|
||||
endfunction
|
||||
|
||||
let s:fdm=''
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:notbslash and s:notcomment
|
||||
" Define common regexps
|
||||
let s:notbslash = '\%(\\\@<!\%(\\\\\)*\)\@<='
|
||||
let s:notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
|
||||
|
||||
" {{{1 s:find_fold_parts
|
||||
function! s:find_fold_parts()
|
||||
function! s:find_fold_parts() " {{{1
|
||||
"
|
||||
" This function parses the tex file to find the sections that are to be
|
||||
" folded and their levels, and then predefines the patterns for optimized
|
||||
@ -224,8 +223,7 @@ function! s:find_fold_parts()
|
||||
return foldsections
|
||||
endfunction
|
||||
|
||||
" {{{1 s:parse_label
|
||||
function! s:parse_label()
|
||||
function! s:parse_label() " {{{1
|
||||
let i = v:foldend
|
||||
while i >= v:foldstart
|
||||
if getline(i) =~ '^\s*\\label'
|
||||
@ -236,8 +234,7 @@ function! s:parse_label()
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
" {{{1 s:parse_caption
|
||||
function! s:parse_caption(line)
|
||||
function! s:parse_caption(line) " {{{1
|
||||
let i = v:foldend
|
||||
while i >= v:foldstart
|
||||
if getline(i) =~ '^\s*\\caption'
|
||||
@ -251,8 +248,7 @@ function! s:parse_caption(line)
|
||||
return matchstr(a:line,'\\begin\*\?{.*}\s*%\s*\zs.*')
|
||||
endfunction
|
||||
|
||||
" {{{1 s:parse_caption_table
|
||||
function! s:parse_caption_table(line)
|
||||
function! s:parse_caption_table(line) " {{{1
|
||||
let i = v:foldstart
|
||||
while i <= v:foldend
|
||||
if getline(i) =~ '^\s*\\caption'
|
||||
@ -266,8 +262,7 @@ function! s:parse_caption_table(line)
|
||||
return matchstr(a:line,'\\begin\*\?{.*}\s*%\s*\zs.*')
|
||||
endfunction
|
||||
|
||||
" {{{1 s:parse_caption_frame
|
||||
function! s:parse_caption_frame(line)
|
||||
function! s:parse_caption_frame(line) " {{{1
|
||||
" Test simple variants first
|
||||
let caption1 = matchstr(a:line,'\\begin\*\?{.*}{\zs.\+\ze}')
|
||||
let caption2 = matchstr(a:line,'\\begin\*\?{.*}{\zs.\+')
|
||||
|
@ -1,9 +1,8 @@
|
||||
" {{{1 latex#latexmk#init
|
||||
function! latex#latexmk#init(initialized)
|
||||
function! latex#latexmk#init(initialized) " {{{1
|
||||
if !g:latex_latexmk_enabled | return | endif
|
||||
|
||||
"
|
||||
" Check if system is incompatible with latexmk
|
||||
" Check system compatibility
|
||||
"
|
||||
if s:system_incompatible() | return | endif
|
||||
|
||||
@ -14,16 +13,26 @@ function! latex#latexmk#init(initialized)
|
||||
let g:latex#data[b:latex.id].pid = 0
|
||||
endif
|
||||
|
||||
"
|
||||
" Define commands
|
||||
"
|
||||
com! -buffer VimLatexCompile call latex#latexmk#compile()
|
||||
com! -buffer VimLatexStop call latex#latexmk#stop()
|
||||
com! -buffer VimLatexStopAll call latex#latexmk#stop_all()
|
||||
com! -buffer VimLatexErrors call latex#latexmk#errors(1)
|
||||
com! -buffer -bang VimLatexClean call latex#latexmk#clean(<q-bang> == "!")
|
||||
com! -buffer -bang VimLatexStatus call latex#latexmk#status(<q-bang> == "!")
|
||||
|
||||
"
|
||||
" Set default mappings
|
||||
"
|
||||
if g:latex_mappings_enabled
|
||||
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(0)<cr>
|
||||
nnoremap <silent><buffer> <localleader>lC :call latex#latexmk#clean(1)<cr>
|
||||
nnoremap <silent><buffer> <localleader>lg :call latex#latexmk#status()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lg :call latex#latexmk#status(0)<cr>
|
||||
nnoremap <silent><buffer> <localleader>lG :call latex#latexmk#status(1)<cr>
|
||||
nnoremap <silent><buffer> <localleader>lk :call latex#latexmk#stop(1)<cr>
|
||||
nnoremap <silent><buffer> <localleader>lk :call latex#latexmk#stop()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lK :call latex#latexmk#stop_all()<cr>
|
||||
nnoremap <silent><buffer> <localleader>le :call latex#latexmk#errors(1)<cr>
|
||||
endif
|
||||
@ -49,10 +58,8 @@ function! latex#latexmk#init(initialized)
|
||||
augroup END
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#latexmk#clean
|
||||
function! latex#latexmk#clean(...)
|
||||
let full = a:0 > 0
|
||||
|
||||
" }}}1
|
||||
function! latex#latexmk#clean(full) " {{{1
|
||||
let data = g:latex#data[b:latex.id]
|
||||
if data.pid
|
||||
echomsg "latexmk is already running"
|
||||
@ -67,7 +74,7 @@ function! latex#latexmk#clean(...)
|
||||
else
|
||||
let cmd = 'cd ' . shellescape(data.root) . ';'
|
||||
endif
|
||||
if full
|
||||
if a:full
|
||||
let cmd .= 'latexmk -C '
|
||||
else
|
||||
let cmd .= 'latexmk -c '
|
||||
@ -80,15 +87,15 @@ function! latex#latexmk#clean(...)
|
||||
\ }
|
||||
call latex#util#execute(exe)
|
||||
|
||||
if full
|
||||
if a:full
|
||||
echomsg "latexmk full clean finished"
|
||||
else
|
||||
echomsg "latexmk clean finished"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#latexmk#compile
|
||||
function! latex#latexmk#compile()
|
||||
" }}}1
|
||||
function! latex#latexmk#compile() " {{{1
|
||||
let data = g:latex#data[b:latex.id]
|
||||
if data.pid
|
||||
echomsg "latexmk is already running for `" . data.base . "'"
|
||||
@ -112,8 +119,7 @@ function! latex#latexmk#compile()
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
" {{{1 latex#latexmk#errors
|
||||
function! latex#latexmk#errors(force)
|
||||
function! latex#latexmk#errors(force) " {{{1
|
||||
cclose
|
||||
|
||||
let log = g:latex#data[b:latex.id].log()
|
||||
@ -150,11 +156,9 @@ function! latex#latexmk#errors(force)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#latexmk#status
|
||||
function! latex#latexmk#status(...)
|
||||
let detailed = a:0 > 0
|
||||
|
||||
if detailed
|
||||
" }}}1
|
||||
function! latex#latexmk#status(detailed) " {{{1
|
||||
if a:detailed
|
||||
let running = 0
|
||||
for data in g:latex#data
|
||||
if data.pid
|
||||
@ -184,26 +188,21 @@ function! latex#latexmk#status(...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#latexmk#stop
|
||||
function! latex#latexmk#stop(...)
|
||||
let l:verbose = a:0 > 0
|
||||
|
||||
" }}}1
|
||||
function! latex#latexmk#stop() " {{{1
|
||||
let pid = g:latex#data[b:latex.id].pid
|
||||
let base = g:latex#data[b:latex.id].base
|
||||
if pid
|
||||
call s:latexmk_kill_pid(pid)
|
||||
let g:latex#data[b:latex.id].pid = 0
|
||||
if l:verbose
|
||||
echo "latexmk stopped for `" . base . "'"
|
||||
endif
|
||||
elseif l:verbose
|
||||
echo "latexmk stopped for `" . base . "'"
|
||||
else
|
||||
echo "latexmk is not running for `" . base . "'"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
" {{{1 latex#latexmk#stop_all
|
||||
function! latex#latexmk#stop_all()
|
||||
function! latex#latexmk#stop_all() " {{{1
|
||||
for data in g:latex#data
|
||||
if data.pid
|
||||
call s:latexmk_kill_pid(data.pid)
|
||||
@ -215,8 +214,7 @@ endfunction
|
||||
" }}}1
|
||||
|
||||
" Helper functions for latexmk command
|
||||
" {{{1 s:latexmk_set_cmd
|
||||
function! s:latexmk_set_cmd(data)
|
||||
function! s:latexmk_set_cmd(data) " {{{1
|
||||
" Note: We don't send output to /dev/null, but rather to a temporary file,
|
||||
" which allows inspection of latexmk output
|
||||
let tmp = tempname()
|
||||
@ -257,8 +255,7 @@ function! s:latexmk_set_cmd(data)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
" {{{1 s:latexmk_set_pid
|
||||
function! s:latexmk_set_pid(data)
|
||||
function! s:latexmk_set_pid(data) " {{{1
|
||||
if has('win32')
|
||||
let tmpfile = tempname()
|
||||
silent execute '!cmd /c "wmic process where '
|
||||
@ -273,8 +270,7 @@ function! s:latexmk_set_pid(data)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
" {{{1 s:latexmk_kill_pid
|
||||
function! s:latexmk_kill_pid(pid)
|
||||
function! s:latexmk_kill_pid(pid) " {{{1
|
||||
let exe = {}
|
||||
let exe.bg = 0
|
||||
let exe.null = 0
|
||||
@ -290,8 +286,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:log_contains_error
|
||||
function! s:log_contains_error(logfile)
|
||||
function! s:log_contains_error(logfile) " {{{1
|
||||
let lines = readfile(a:logfile)
|
||||
let lines = filter(lines, 'v:val =~ ''^.*:\d\+: ''')
|
||||
let lines = uniq(map(lines, 'matchstr(v:val, ''^.*\ze:\d\+:'')'))
|
||||
@ -300,8 +295,7 @@ function! s:log_contains_error(logfile)
|
||||
return len(lines) > 0
|
||||
endfunction
|
||||
|
||||
" {{{1 s:stop_buffer
|
||||
function! s:stop_buffer()
|
||||
function! s:stop_buffer() " {{{1
|
||||
"
|
||||
" Only run if latex variables are set
|
||||
"
|
||||
@ -327,13 +321,12 @@ function! s:stop_buffer()
|
||||
" Only stop if current buffer is the last for current latex blob
|
||||
"
|
||||
if n == 1
|
||||
call latex#latexmk#stop(0)
|
||||
silent call latex#latexmk#stop()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 s:system_incompatible()
|
||||
function! s:system_incompatible()
|
||||
function! s:system_incompatible() " {{{1
|
||||
if has('win32')
|
||||
let required = ['latexmk']
|
||||
else
|
||||
|
@ -1,5 +1,4 @@
|
||||
" {{{1 latex#motion#init
|
||||
function! latex#motion#init(initialized)
|
||||
function! latex#motion#init(initialized) " {{{1
|
||||
if !g:latex_motion_enabled | return | endif
|
||||
|
||||
if g:latex_mappings_enabled
|
||||
@ -58,8 +57,7 @@ function! latex#motion#init(initialized)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#motion#find_matching_pair
|
||||
function! latex#motion#find_matching_pair(...)
|
||||
function! latex#motion#find_matching_pair(...) " {{{1
|
||||
if a:0 > 0
|
||||
normal! gv
|
||||
endif
|
||||
@ -116,8 +114,7 @@ function! latex#motion#find_matching_pair(...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#motion#next_section
|
||||
function! latex#motion#next_section(type, backwards, visual)
|
||||
function! latex#motion#next_section(type, backwards, visual) " {{{1
|
||||
" Restore visual mode if desired
|
||||
if a:visual
|
||||
normal! gv
|
||||
@ -151,8 +148,7 @@ function! latex#motion#next_section(type, backwards, visual)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#motion#sel_delimiter
|
||||
function! latex#motion#sel_delimiter(...)
|
||||
function! latex#motion#sel_delimiter(...) " {{{1
|
||||
let inner = a:0 > 0
|
||||
|
||||
let [d1, l1, c1, d2, l2, c2] = latex#util#get_delim()
|
||||
@ -186,8 +182,7 @@ function! latex#motion#sel_delimiter(...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#motion#sel_environment
|
||||
function! latex#motion#sel_environment(...)
|
||||
function! latex#motion#sel_environment(...) " {{{1
|
||||
let inner = a:0 > 0
|
||||
|
||||
let [env, lnum, cnum, lnum2, cnum2] = latex#util#get_env(1)
|
||||
@ -216,8 +211,7 @@ function! latex#motion#sel_environment(...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#motion#sel_inline_math
|
||||
function! latex#motion#sel_inline_math(...)
|
||||
function! latex#motion#sel_inline_math(...) " {{{1
|
||||
let inner = a:0 > 0
|
||||
|
||||
let dollar_pat = '\\\@<!\$'
|
||||
@ -286,8 +280,7 @@ let s:section.= '>'
|
||||
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:highlight_matching_pair
|
||||
function! s:highlight_matching_pair(...)
|
||||
function! s:highlight_matching_pair(...) " {{{1
|
||||
if latex#util#in_comment() | return | endif
|
||||
let hmode = a:0 > 0 ? 1 : 0
|
||||
|
||||
@ -353,8 +346,7 @@ function! s:highlight_matching_pair(...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 s:search_and_skip_comments
|
||||
function! s:search_and_skip_comments(pat, ...)
|
||||
function! s:search_and_skip_comments(pat, ...) " {{{1
|
||||
" Usage: s:search_and_skip_comments(pat, [flags, stopline])
|
||||
let flags = a:0 >= 1 ? a:1 : ''
|
||||
let stopline = a:0 >= 2 ? a:2 : 0
|
||||
|
@ -1,13 +1,18 @@
|
||||
" {{{1 latex#toc#init
|
||||
function! latex#toc#init(initialized)
|
||||
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#toggle()<cr>
|
||||
function! latex#toc#init(initialized) " {{{1
|
||||
if !g:latex_toc_enabled | return | endif
|
||||
|
||||
" Define commands
|
||||
command! -buffer VimLatexTocOpen call latex#toc#open()
|
||||
command! -buffer VimLatexTocToggle call latex#toc#toggle()
|
||||
|
||||
" Define mappings
|
||||
if g:latex_mappings_enabled
|
||||
nnoremap <buffer> <LocalLeader>lt :call latex#toc#open()<cr>
|
||||
nnoremap <buffer> <LocalLeader>lT :call latex#toc#toggle()<cr>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#toc#open
|
||||
function! latex#toc#open()
|
||||
function! latex#toc#open() " {{{1
|
||||
" Go to TOC if it already exists
|
||||
let winnr = bufwinnr(bufnr('LaTeX TOC'))
|
||||
if winnr >= 0
|
||||
@ -64,8 +69,7 @@ function! latex#toc#open()
|
||||
setlocal nomodifiable
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#toc#toggle
|
||||
function! latex#toc#toggle()
|
||||
function! latex#toc#toggle() " {{{1
|
||||
if bufwinnr(bufnr('LaTeX TOC')) >= 0
|
||||
if g:latex_toc_resize
|
||||
silent exe "set columns-=" . g:latex_toc_width
|
||||
@ -78,8 +82,19 @@ function! latex#toc#toggle()
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
" {{{1 s:parse_file
|
||||
function! s:parse_file(file, ...)
|
||||
" Define dictionary to keep track of TOC numbers
|
||||
let s:number = {}
|
||||
|
||||
" Define regular expressions to match input and include lines
|
||||
let s:re_input = '\v^\s*\\%(input|include)\s*\{'
|
||||
let s:re_input_file = s:re_input . '\zs[^\}]+\ze}'
|
||||
|
||||
" Define regular expressions to match various sectioning commands
|
||||
let s:re_sec = '\v^\s*\\%(part|chapter|%(sub)*section)\*?\s*\{'
|
||||
let s:re_sec_level = '\v^\s*\\\zs%(part|chapter|%(sub)*section)\*?'
|
||||
let s:re_sec_title = s:re_sec . '\zs.{-}\ze\}?$'
|
||||
|
||||
function! s:parse_file(file, ...) " {{{1
|
||||
" Parses tex file for TOC entries
|
||||
"
|
||||
" The function returns a list of entries. Each entry is a dictionary:
|
||||
@ -149,14 +164,7 @@ function! s:parse_file(file, ...)
|
||||
return toc
|
||||
endfunction
|
||||
|
||||
"}}}1
|
||||
" {{{1 s:parse_line
|
||||
" Define regular expressions to match input and include lines
|
||||
let s:re_input = '\v^\s*\\%(input|include)\s*\{'
|
||||
let s:re_input_file = s:re_input . '\zs[^\}]+\ze}'
|
||||
|
||||
" Parse input/include lines
|
||||
function! s:parse_line_input(line)
|
||||
function! s:parse_line_input(line) " {{{1
|
||||
let l:file = matchstr(a:line, s:re_input_file)
|
||||
if l:file !~# '.tex$'
|
||||
let l:file .= '.tex'
|
||||
@ -164,13 +172,7 @@ function! s:parse_line_input(line)
|
||||
return fnamemodify(l:file, ':p')
|
||||
endfunction
|
||||
|
||||
" Define regular expressions to match various sectioning commands
|
||||
let s:re_sec = '\v^\s*\\%(part|chapter|%(sub)*section)\*?\s*\{'
|
||||
let s:re_sec_level = '\v^\s*\\\zs%(part|chapter|%(sub)*section)\*?'
|
||||
let s:re_sec_title = s:re_sec . '\zs.{-}\ze\}?$'
|
||||
|
||||
" Parse sectioning lines
|
||||
function! s:parse_line_sec(file, lnum, line)
|
||||
function! s:parse_line_sec(file, lnum, line) " {{{1
|
||||
let title = matchstr(a:line, s:re_sec_title)
|
||||
let number = s:number_increment(matchstr(a:line, s:re_sec_level))
|
||||
|
||||
@ -182,10 +184,7 @@ function! s:parse_line_sec(file, lnum, line)
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
" {{{1 s:number_*
|
||||
let s:number = {}
|
||||
function! s:number_reset()
|
||||
function! s:number_reset() " {{{1
|
||||
let s:number.part = 0
|
||||
let s:number.chapter = 0
|
||||
let s:number.section = 0
|
||||
@ -195,7 +194,7 @@ function! s:number_reset()
|
||||
let s:number.preamble = 1
|
||||
endfunction
|
||||
|
||||
function! s:number_start_appendix()
|
||||
function! s:number_start_appendix() " {{{1
|
||||
let s:number.part = 0
|
||||
let s:number.chapter = 0
|
||||
let s:number.section = 0
|
||||
@ -204,7 +203,7 @@ function! s:number_start_appendix()
|
||||
let s:number.appendix = 1
|
||||
endfunction
|
||||
|
||||
function! s:number_increment(level)
|
||||
function! s:number_increment(level) " {{{1
|
||||
" Check if level should be incremented
|
||||
if a:level !~# '\v%(part|chapter|(sub)*section)$'
|
||||
return ''
|
||||
@ -236,7 +235,7 @@ function! s:number_increment(level)
|
||||
return s:number_print()
|
||||
endfunction
|
||||
|
||||
function! s:number_print()
|
||||
function! s:number_print() " {{{1
|
||||
let number = [
|
||||
\ s:number.part,
|
||||
\ s:number.chapter,
|
||||
|
@ -1,8 +1,7 @@
|
||||
"
|
||||
" Utility functions sorted by name
|
||||
"
|
||||
" {{{1 latex#util#convert_back
|
||||
function! latex#util#convert_back(line)
|
||||
function! latex#util#convert_back(line) " {{{1
|
||||
"
|
||||
" Substitute stuff like '\IeC{\"u}' to corresponding unicode symbols
|
||||
"
|
||||
@ -78,8 +77,7 @@ let s:convert_back_list = map([
|
||||
\ ['\\\~n}' , 'ñ'],
|
||||
\], '[''\C\(\\IeC\s*{\)\?'' . v:val[0], v:val[1]]')
|
||||
|
||||
" {{{1 latex#util#error_deprecated
|
||||
function! latex#util#error_deprecated(variable)
|
||||
function! latex#util#error_deprecated(variable) " {{{1
|
||||
if exists(a:variable)
|
||||
echoerr "Deprecation error: " . a:variable
|
||||
echoerr "Please red docs for more info!"
|
||||
@ -87,8 +85,7 @@ function! latex#util#error_deprecated(variable)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#util#execute
|
||||
function! latex#util#execute(exe)
|
||||
function! latex#util#execute(exe) " {{{1
|
||||
" Execute the given command on the current system. Wrapper function to make
|
||||
" it easier to run on both windows and unix.
|
||||
"
|
||||
@ -138,8 +135,7 @@ function! latex#util#execute(exe)
|
||||
endif
|
||||
endfunction
|
||||
" }}}1
|
||||
" {{{1 latex#util#get_env
|
||||
function! latex#util#get_env(...)
|
||||
function! latex#util#get_env(...) " {{{1
|
||||
" latex#util#get_env([with_pos])
|
||||
" Returns:
|
||||
" - environment
|
||||
@ -201,8 +197,7 @@ function! latex#util#get_env(...)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#util#get_delim
|
||||
function! latex#util#get_delim()
|
||||
function! latex#util#get_delim() " {{{1
|
||||
" Save position in order to restore before finishing
|
||||
let pos_original = getpos('.')
|
||||
|
||||
@ -276,8 +271,7 @@ let s:delimiters_close = [
|
||||
\ '\\\cbigg\?\()\|\]\|\\}\)',
|
||||
\ ]
|
||||
|
||||
" {{{1 latex#util#has_syntax
|
||||
function! latex#util#has_syntax(name, ...)
|
||||
function! latex#util#has_syntax(name, ...) " {{{1
|
||||
" Usage: latex#util#has_syntax(name, [line], [col])
|
||||
let line = a:0 >= 1 ? a:1 : line('.')
|
||||
let col = a:0 >= 2 ? a:2 : col('.')
|
||||
@ -285,13 +279,11 @@ function! latex#util#has_syntax(name, ...)
|
||||
\ 'synIDattr(v:val, "name") == "' . a:name . '"'), 1)
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#util#in_comment
|
||||
function! latex#util#in_comment(...)
|
||||
function! latex#util#in_comment(...) " {{{1
|
||||
return synIDattr(synID(line('.'), col('.'), 0), "name") =~# '^texComment'
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#util#kpsewhich
|
||||
function! latex#util#kpsewhich(file, ...)
|
||||
function! latex#util#kpsewhich(file, ...) " {{{1
|
||||
let cmd = 'kpsewhich '
|
||||
let cmd .= a:0 > 0 ? a:1 : ''
|
||||
let cmd .= ' "' . a:file . '"'
|
||||
@ -307,15 +299,13 @@ function! latex#util#kpsewhich(file, ...)
|
||||
return out
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#util#set_default
|
||||
function! latex#util#set_default(variable, default)
|
||||
function! latex#util#set_default(variable, default) " {{{1
|
||||
if !exists(a:variable)
|
||||
let {a:variable} = a:default
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#util#tex2tree
|
||||
function! latex#util#tex2tree(str)
|
||||
function! latex#util#tex2tree(str) " {{{1
|
||||
let tree = []
|
||||
let i1 = 0
|
||||
let i2 = -1
|
||||
@ -346,8 +336,7 @@ function! latex#util#tex2tree(str)
|
||||
return tree
|
||||
endfunction
|
||||
|
||||
" {{{1 latex#util#tree2tex
|
||||
function! latex#util#tree2tex(tree)
|
||||
function! latex#util#tree2tex(tree) " {{{1
|
||||
if type(a:tree) == type('')
|
||||
return a:tree
|
||||
else
|
||||
|
@ -1,5 +1,4 @@
|
||||
" {{{1 toc#fold_level
|
||||
function! toc#fold_level(lnum)
|
||||
function! toc#fold_level(lnum) " {{{1
|
||||
let line = getline(a:lnum)
|
||||
let match_s1 = line =~# '^\w\+\s'
|
||||
let match_s2 = line =~# '^\w\+\.\w\+\s'
|
||||
@ -30,8 +29,7 @@ function! toc#fold_level(lnum)
|
||||
return "="
|
||||
endfunction
|
||||
|
||||
" {{{1 toc#fold_text
|
||||
function! toc#fold_text()
|
||||
function! toc#fold_text() " {{{1
|
||||
let parts = matchlist(getline(v:foldstart), '^\(.*\)\t\(.*\)$')
|
||||
return printf('%-8s%-72s', parts[1], parts[2])
|
||||
endfunction
|
||||
|
Loading…
x
Reference in New Issue
Block a user