summaryrefslogtreecommitdiffstats
path: root/indent/bib.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2020-04-25 21:30:46 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2020-04-25 21:30:46 +0200
commitd757bfd643cc73c2d495355c153ed0257f5d5b47 (patch)
treeff210950456938a779d98f6a2ba7321aca512897 /indent/bib.vim
parent8ec73a3a8974a62a613680a6b6222a77a7b99546 (diff)
downloadvim-polyglot-d757bfd643cc73c2d495355c153ed0257f5d5b47.tar.gz
vim-polyglot-d757bfd643cc73c2d495355c153ed0257f5d5b47.zip
Change latex provider to luatex, closes #476
Diffstat (limited to 'indent/bib.vim')
-rw-r--r--indent/bib.vim85
1 files changed, 85 insertions, 0 deletions
diff --git a/indent/bib.vim b/indent/bib.vim
new file mode 100644
index 00000000..fa326f3a
--- /dev/null
+++ b/indent/bib.vim
@@ -0,0 +1,85 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
+
+" vimtex - LaTeX plugin for Vim
+"
+" Maintainer: Karl Yngve LervÄg
+" Email: karl.yngve@gmail.com
+"
+
+if exists('b:did_indent')
+ finish
+endif
+
+if !get(g:, 'vimtex_indent_bib_enabled', 1) | finish | endif
+
+let b:did_indent = 1
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+setlocal autoindent
+setlocal indentexpr=VimtexIndentBib()
+
+function! VimtexIndentBib() abort " {{{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) abort " {{{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
+
+endif