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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
" Autoload funtions for custom statusbar.
" Last Changed: 2021-09-29
" Author: Federico Igne <>
" License: This file is placed in the public domain.
" Highlight statusbar if current buffer contains unsaved changes.
function! dyamon#statusline#setcolor() abort
if getbufvar(bufnr('%'), '&modified')
highlight User3 ctermbg=3 guibg=#d79921
else
highlight User3 ctermbg=248 guibg=#bdae93
endif
" Force statusline update
setlocal statusline=
" Overrides default return value (0) that would be displayed in the
" statusbar
return ''
endfunction
function! dyamon#statusline#modeflag() abort
" The preview window is an exception among exceptions
if &previewwindow && has_key(g:specialFlag, 'preview')
return g:specialFlag.preview
endif
" Compute the correct flag
let l:flag=get( g:nameFlag,
\ expand('%'),
\ get( g:filetypeFlag,
\ &filetype,
\ get(g:modeFlag, mode(), 'Err')
\ )
\ )
return l:flag
endfunction
function! dyamon#statusline#fileprefix() abort
let l:basename=expand('%:h')
if l:basename ==# '' || l:basename ==# '.'
return ''
elseif winwidth(0) > g:fullstatusline
return substitute(l:basename . '/', '\C^' . $HOME, '~', '')
else
return ''
endif
endfunction
" Return session flag, if an active (Ob)session is detected.
function! dyamon#statusline#session() abort
let l:session_flag = ['s', 'S']
let l:numeric = !empty(v:this_session) + exists('g:this_obsession')
if l:numeric
return ',' . l:session_flag[l:numeric-1]
else
return ''
endif
endfunction
" Return filetype (if any).
function! dyamon#statusline#filetype() abort
if strlen(&ft) && !has_key(g:filetypeFlag,&ft)
return ',' . &ft
else
return ''
endif
endfunction
" Return file encoding if different from default (utf8).
function! dyamon#statusline#fileenc() abort
if strlen(&fenc) && &fenc !=# 'utf-8' && winwidth(0) > g:fullstatusline
return ',' . &fenc
else
return ''
endif
endfunction
" Return git related info (if GitGutter is active provide additional info
" about changed hunks in the current buffer)
function! dyamon#statusline#gitinfo() abort
let l:git = ' '
let l:head = ''
if exists('*FugitiveHead') && len(FugitiveHead(8))
let l:head = FugitiveHead(8)
let l:git .= ' ' . l:head . ' '
endif
if len(l:head) &&
\ exists('g:gitgutter_enabled') && g:gitgutter_enabled &&
\ winwidth(0) ># g:fullstatusline
let l:s = GitGutterGetHunkSummary()
let l:git .= len(l:s) ? printf('(+%d ~%d -%d) ', l:s[0], l:s[1], l:s[2]) : ''
endif
return l:git
endfun
" If a language server is registered and enabled (via `vim-lsp` plugin)
" add a custom indicator.
function! dyamon#statusline#lsp() abort
" Manually detect the server name based on the filetype
let l:servers = {
\ 'scala' : 'metals',
\ 'sbt' : 'metals'
\}
" Indicators
let l:indicators = {
\ 'unknown server' : ' ',
\ 'exited' : ' ',
\ 'starting' : ' ',
\ 'failed' : ' ',
\ 'running' : ' ',
\ 'not running' : ' ',
\ 'hint' : ' ',
\ 'information' : ' ',
\ 'warning' : ' ',
\ 'error' : ' '
\}
let l:server = get(l:servers, &filetype, '')
if len(l:server)
let l:status = lsp#get_server_status(l:server)
let l:prefix = '▕ '
if l:status ==# 'running'
" Get language server counts
let l:counts = lsp#get_buffer_diagnostics_counts()
let l:hint = get(l:counts, 'hint', 0)
let l:info = get(l:counts, 'information', 0)
let l:warn = get(l:counts, 'warning', 0)
let l:erro = get(l:counts, 'error', 0)
" Build output
let l:output = ''
if l:hint > 0
let l:output .= get(l:indicators,'hint') . l:hint . ' '
endif
if l:info > 0
let l:output .= get(l:indicators,'information') . l:info . ' '
endif
if l:warn > 0
let l:output .= get(l:indicators,'warning') . l:warn . ' '
endif
if l:erro > 0
let l:output .= get(l:indicators,'error') . l:erro . ' '
endif
if len(l:output)
return l:prefix . l:output
else
return l:prefix . get(l:indicators, l:status) . ' '
endif
else
return l:prefix . get(l:indicators, l:status) . ' '
endif
else
return ''
endif
endfun
" Blur statusline
function! dyamon#statusline#blur() abort
if ! exists("b:disable_statusline")
let l:blurred='\ ' " space
let l:blurred.='%<' " truncation point
let l:blurred.='%f' " filename
let l:blurred.='%=' " split left/right halves (makes background cover whole)
execute 'setlocal statusline=' . l:blurred
endif
endfunction
" Focus statusline
function! dyamon#statusline#focus() abort
if ! exists("b:disable_statusline")
" Reset to global option
setlocal statusline=
endif
endfunction
" Custom function for the TagBar plugin
function! dyamon#statusline#tagbar(current, sort, fname, flags, ...) abort
" Initialise custom statusline
let l:statusline = ''
if a:current
" Tagbar label is always set to 'unmodified' color
highlight User3 cterm=bold ctermfg=18 ctermbg=20
" 'TagBar' label
let l:statusline .= '%3* TagBar '
" Filename
let l:statusline .= '%* '.a:fname.' '
" Left/right separator
let l:statusline .= '%='
" Flags (sort method included)
let l:statusline .= '[' . ((a:sort ==# 'Name') ? 'N' : 'O') . ',' . join(a:flags, ',') . '] '
else
" 'TagBar' label
let l:statusline .= ' TagBar > '
" Filename
let l:statusline .= a:fname
endif
return l:statusline
endfunction
function! dyamon#statusline#tabline() abort
let line = ''
for i in range(tabpagenr('$'))
" Select the relevant highlight group
if i + 1 == tabpagenr()
let line .= '%#TabLineSel#'
else
let line .= '%#TabLine#'
endif
" Start tabpage label (with number indicator)
let line .= '%' . (i + 1) . 'T ' . (i + 1)
" Modified buffer indicator
let l:modified = ''
let l:buflist = tabpagebuflist(i + 1)
for l:buf in l:buflist
if getbufvar(l:buf, '&modified')
let l:modified = '+'
endif
endfor
let line .= l:modified
" Get tabpage label
let line .= ' %{dyamon#statusline#tablabel(' . (i + 1) . ')} '
" Get number of windows
"let line .= '[%{tabpagewinnr(' . (i + 1) . ', "$")}]'
endfor
" Fill with TabLineFill and reset tabpage label
let line .= '%#TabLineFill#%T'
return line
endfunction
function! dyamon#statusline#tablabel(tab) abort
let buflist = tabpagebuflist(a:tab)
let winnr = tabpagewinnr(a:tab)
let cwd = getcwd(-1, a:tab)
if exists('*FugitiveGitDir') && len(FugitiveGitDir(buflist[winnr-1]))
let gitroot = fnamemodify(FugitiveGitDir(buflist[winnr-1]), ':h:h')
let cwd = substitute(cwd, gitroot . '/', '', '')
else
let cwd = fnamemodify(cwd, ':t')
endif
return cwd
endfunction
|