Added indentation file for bibliographies
This commit is contained in:
parent
c3efc48ae0
commit
b4fc6c53b1
@ -398,6 +398,10 @@ List of section constructs that should be folded. >
|
|||||||
Use |vimtex| indentation function. Not as customizable as the official
|
Use |vimtex| indentation function. Not as customizable as the official
|
||||||
indentation function, but imho it is better. >
|
indentation function, but imho it is better. >
|
||||||
let g:vimtex_indent_enabled = 1
|
let g:vimtex_indent_enabled = 1
|
||||||
|
<
|
||||||
|
*g:vimtex_indent_bib_enabled*
|
||||||
|
Use |vimtex| indentation function for bibliography files. >
|
||||||
|
let g:vimtex_indent_bib_enabled = 1
|
||||||
<
|
<
|
||||||
*g:vimtex_latexmk_build_dir*
|
*g:vimtex_latexmk_build_dir*
|
||||||
Set this variable in case a dedicated build dir is used with `latexmk`/`latex`
|
Set this variable in case a dedicated build dir is used with `latexmk`/`latex`
|
||||||
@ -688,12 +692,15 @@ INDENTATION *vimtex-indent*
|
|||||||
|
|
||||||
The official indentation function is pretty good and allows for some
|
The official indentation function is pretty good and allows for some
|
||||||
customization. However, I am not quite satisfied, so I wrote my own
|
customization. However, I am not quite satisfied, so I wrote my own
|
||||||
indentation function that is not customizable at all (at least for now), but
|
indentation function that is not customizable, but that I think is better. It
|
||||||
that I think is better. It is enabled by default, but may be disabled if
|
is enabled by default, but may be disabled if desired.
|
||||||
desired |g:vimtex_indent_enabled|.
|
|
||||||
|
*vimtex-bib-indent*
|
||||||
|
I've also written an indentation file for bibliography files (`.bib` files).
|
||||||
|
|
||||||
Associated settings:
|
Associated settings:
|
||||||
|g:vimtex_indent_enabled|
|
|g:vimtex_indent_enabled|
|
||||||
|
|g:vimtex_indent_bib_enabled|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
LATEXMK *vimtex-latexmk*
|
LATEXMK *vimtex-latexmk*
|
||||||
|
83
indent/bib.vim
Normal file
83
indent/bib.vim
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
" vimtex - LaTeX plugin for Vim
|
||||||
|
"
|
||||||
|
" Maintainer: Karl Yngve Lervåg
|
||||||
|
" Email: karl.yngve@gmail.com
|
||||||
|
"
|
||||||
|
|
||||||
|
if exists('b:did_indent')
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
call vimtex#util#set_default('g:vimtex_indent_bib_enabled', 1)
|
||||||
|
if !g:vimtex_indent_bib_enabled | finish | endif
|
||||||
|
|
||||||
|
let s:cpo_save = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal indentexpr=VimtexIndentBib()
|
||||||
|
|
||||||
|
function! VimtexIndentBib() " {{{1
|
||||||
|
" Find first non-blank line above the current line
|
||||||
|
let lnum = prevnonblank(v:lnum - 1)
|
||||||
|
if lnum == 0
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Get some initial conditions
|
||||||
|
let ind = indent(lnum)
|
||||||
|
let line = getline(lnum)
|
||||||
|
let cline = getline(v:lnum)
|
||||||
|
let g:test = 1
|
||||||
|
|
||||||
|
" Zero indent for first line of each entry
|
||||||
|
if cline =~# '^\s*@'
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Title line of entry
|
||||||
|
if line =~# '^@'
|
||||||
|
if cline =~# '^\s*}'
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return &sw
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if line =~# '='
|
||||||
|
" Indent continued bib info entries
|
||||||
|
if s:count('{', line) - s:count('}', line) > 0
|
||||||
|
let match = searchpos('.*=\s*{','bcne')
|
||||||
|
return match[1]
|
||||||
|
elseif cline =~# '^\s*}'
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
elseif s:count('{', line) - s:count('}', line) < 0
|
||||||
|
if s:count('{', cline) - s:count('}', cline) < 0
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return &sw
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ind
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:count(pattern, line) " {{{1
|
||||||
|
let sum = 0
|
||||||
|
let indx = match(a:line, a:pattern)
|
||||||
|
while indx >= 0
|
||||||
|
let sum += 1
|
||||||
|
let indx += 1
|
||||||
|
let indx = match(a:line, a:pattern, indx)
|
||||||
|
endwhile
|
||||||
|
return sum
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" }}}1
|
||||||
|
|
||||||
|
let &cpo = s:cpo_save
|
||||||
|
unlet s:cpo_save
|
||||||
|
|
||||||
|
" vim: fdm=marker sw=2
|
Loading…
Reference in New Issue
Block a user