Some updates and improvements
This commit is contained in:
parent
d427907af2
commit
00b4e1fe3d
@ -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 <buffer>
|
||||
vmap <buffer>
|
||||
@ -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 |
|
||||
\ 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', '\%(\\\@<!\%(\\\\\)*\)\@<=')
|
||||
call latex#util#set_default('b:notcomment',
|
||||
\ '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!')
|
||||
|
||||
"
|
||||
" Create new or link to old blob
|
||||
"
|
||||
@ -135,13 +130,13 @@ function! s:init_environment()
|
||||
let b:latex.id = len(g:latex#data) - 1
|
||||
endif
|
||||
|
||||
if g:latex_default_mappings
|
||||
if g:latex_mappings_enabled
|
||||
nnoremap <silent><buffer> <localleader>li :call latex#info()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lh :call latex#help()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lv :call latex#view()<cr>
|
||||
nnoremap <silent><buffer> <LocalLeader>lR :call latex#reinit()<cr>
|
||||
|
||||
inoremap <silent><buffer> <m-i> \item
|
||||
inoremap <silent><buffer> <m-i> \item<space>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
" {{{1 latex#change#init
|
||||
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> cse :call latex#change#env_prompt()<cr>
|
||||
|
@ -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 <silent><buffer> zx :call latex#fold#refresh()<cr>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 = '\%(\\\@<!\%(\\\\\)*\)\@<='
|
||||
let s:notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
|
||||
|
||||
" {{{1 s:fdm_restore
|
||||
function! s:fdm_restore()
|
||||
silent execute 'setlocal foldmethod=' . s:fdm
|
||||
|
@ -12,7 +12,7 @@ function! latex#latexmk#init(initialized)
|
||||
"
|
||||
" 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>lc :call latex#latexmk#clean()<cr>
|
||||
nnoremap <silent><buffer> <localleader>lC :call latex#latexmk#clean(1)<cr>
|
||||
|
@ -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 <silent><buffer> % :call latex#motion#find_matching_pair()<cr>
|
||||
vnoremap <silent><buffer> %
|
||||
\ :<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
|
||||
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 = '\%(\\\@<!\%(\\\\\)*\)\@<='
|
||||
let s:notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
|
||||
|
||||
" Patterns to match opening and closing delimiters/environments
|
||||
let s:delimiters_open = [
|
||||
\ '{',
|
||||
@ -277,7 +280,7 @@ let s:delimiters = join(s:delimiters_open + s:delimiters_close, '\|')
|
||||
let s:delimiters = '\(' . s:delimiters . '\|\$\)'
|
||||
|
||||
" 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.= '>'
|
||||
|
||||
@ -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,
|
||||
|
@ -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 <silent><buffer> <LocalLeader>lt :call latex#toc#open()<cr>
|
||||
nnoremap <silent><buffer> <LocalLeader>lT :call latex#toc#toggle()<cr>
|
||||
endif
|
||||
|
@ -7,22 +7,28 @@
|
||||
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)
|
||||
@ -41,17 +47,11 @@ call latex#util#set_default('g:latex_fold_sections',
|
||||
\ "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',
|
||||
@ -60,19 +60,9 @@ call latex#util#set_default('g:latex_main_tex_candidates',
|
||||
\ '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()
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user