aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.local/share/nvim/site/autoload/airline/extensions/vimtex.vim
blob: 9eda8d55137af091e6e0531d54bcdee1902c4e87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
" MIT License. Copyright (c) 2013-2018 Bailey Ling et al.
" vim: et ts=2 sts=2 sw=2

" This plugin replace the whole section_a when in vimagit buffer
scriptencoding utf-8

let s:spc = g:airline_symbols.space

function! s:SetDefault(var, val)
  if !exists(a:var)
    execute 'let ' . a:var . '=' . string(a:val)
  endif
endfunction

" Left and right delimiters (added only when status string is not empty)
call s:SetDefault( 'g:airline#extensions#vimtex#left',       "{")
call s:SetDefault( 'g:airline#extensions#vimtex#right',      "}")

" The current tex file is the main project file
call s:SetDefault( 'g:airline#extensions#vimtex#main',       "" )
"
" The current tex file is a subfile of the project
" and the compilation is set for the main file
call s:SetDefault( 'g:airline#extensions#vimtex#sub_main',   "m")
"
" The current tex file is a subfile of the project
" and the compilation is set for this subfile
call s:SetDefault( 'g:airline#extensions#vimtex#sub_local',  "l")
"
" Compilation is running and continuous compilation is off
call s:SetDefault( 'g:airline#extensions#vimtex#compiled',   "c₁")

" Compilation is running and continuous compilation is on
call s:SetDefault( 'g:airline#extensions#vimtex#continuous', "c")

" Viewer is opened
call s:SetDefault( 'g:airline#extensions#vimtex#viewer',     "v")

function! airline#extensions#vimtex#init(ext)
  call airline#parts#define_raw('vimtex', '%{airline#extensions#vimtex#get_scope()}')
  call a:ext.add_statusline_func('airline#extensions#vimtex#apply')
endfunction

function! airline#extensions#vimtex#apply(...)
  if exists("b:vimtex")
    let w:airline_section_x = get(w:, 'airline_section_x', g:airline_section_x)
    let w:airline_section_x.=s:spc.g:airline_left_alt_sep.s:spc.'%{airline#extensions#vimtex#get_scope()}'
  endif
endfunction

function! airline#extensions#vimtex#get_scope()
  let l:status = ''

  let vt_local = get(b:, 'vimtex_local', {})
  if empty(vt_local)
    let l:status .= g:airline#extensions#vimtex#main
  else
    if get(vt_local, 'active')
      let l:status .= g:airline#extensions#vimtex#sub_local
    else
      let l:status .= g:airline#extensions#vimtex#sub_main
    endif
  endif

  if get(get(get(b:, 'vimtex', {}), 'viewer', {}), 'xwin_id')
    let l:status .= g:airline#extensions#vimtex#viewer
  endif

  let l:compiler = get(get(b:, 'vimtex', {}), 'compiler', {})
  if !empty(l:compiler)
    if has_key(l:compiler, 'is_running') && b:vimtex.compiler.is_running()
      if get(l:compiler, 'continuous')
        let l:status .= g:airline#extensions#vimtex#continuous
      else
        let l:status .= g:airline#extensions#vimtex#compiled
      endif
    endif
  endif

  if !empty(l:status)
    let l:status = g:airline#extensions#vimtex#left . l:status . g:airline#extensions#vimtex#right
  endif
  return l:status
endfunction