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
|
local F = vim.fn
local G = vim.g
local O = vim.o
local uniquify = require('uniquify')
local vimrc = require('vimrc')
-- Color scheme {{{1
-- if not pcall(function() vim.cmd('colorscheme ocean') end) then
-- -- Load "desert", one of the built-in colorschemes, instead of mine
-- -- when nvim failed to load it.
-- vim.cmd('colorscheme desert')
-- end
-- Statusline {{{1
O.statusline = '%!v:lua.vimrc.statusline.build()'
vimrc.statusline = {}
function vimrc.statusline.build()
local winid = G.statusline_winid
local bufnr = F.winbufnr(winid)
local is_active = winid == F.win_getid()
local left
if is_active then
local mode, mode_hl = vimrc.statusline.mode()
left = string.format('%%#statusLineMode%s# %s %%#statusLine#', mode_hl, mode)
else
left = ''
end
local ro = vimrc.statusline.readonly(bufnr)
local fname = vimrc.statusline.filename(bufnr)
local mod = vimrc.statusline.modified(bufnr)
local extra_info = vimrc.statusline.extra_info(bufnr, winid)
local linenum = vimrc.statusline.linenum(winid)
local fenc = vimrc.statusline.fenc(bufnr)
local eol = vimrc.statusline.eol(bufnr)
local ff = vimrc.statusline.ff(bufnr)
local ft = vimrc.statusline.filetype(bufnr)
return string.format(
'%s %s%s%s %%= %s%s %s%s%s %s ',
left,
ro and ro .. ' ' or '',
fname,
mod and ' ' .. mod or '',
extra_info == '' and '' or extra_info .. ' ',
linenum,
fenc,
eol,
ff,
ft)
end
function vimrc.statusline.mode()
local mode_map = {
n = { 'N', 'Normal' },
no = { 'O', 'Operator' },
nov = { 'Oc', 'Operator' },
noV = { 'Ol', 'Operator' },
[vimrc.term('no<C-v>')] = { 'Ob', 'Operator' },
niI = { 'In', 'Insert' },
niR = { 'Rn', 'Replace' },
niV = { 'Rn', 'Replace' },
v = { 'V', 'Visual' },
V = { 'Vl', 'Visual' },
[vimrc.term('<C-v>')] = { 'Vb', 'Visual' },
s = { 'S', 'Visual' },
S = { 'Sl', 'Visual' },
[vimrc.term('<C-s>')] = { 'Sb', 'Visual' },
i = { 'I', 'Insert' },
ic = { 'I?', 'Insert' },
ix = { 'I?', 'Insert' },
R = { 'R', 'Replace' },
Rc = { 'R?', 'Replace' },
Rv = { 'R', 'Replace' },
Rx = { 'R?', 'Replace' },
c = { 'C', 'Command' },
cv = { 'C', 'Command' },
ce = { 'C', 'Command' },
r = { '-', 'Other' },
rm = { '-', 'Other' },
['r?'] = { '-', 'Other' },
['!'] = { '-', 'Other' },
t = { 'T', 'Terminal' },
}
local vim_mode_and_hl = mode_map[F.mode(true)] or { '-', 'Other' }
local vim_mode = vim_mode_and_hl[1]
local hl = vim_mode_and_hl[2]
local skk_mode
if F.exists('*skkeleton#mode') == 1 then
skk_mode = ({
['hira'] = ' (あ)',
['kata'] = ' (ア)',
['hankata'] = ' (半ア)',
['zenkaku'] = ' (全角英数)',
['abbrev'] = ' (abbrev)',
})[F['skkeleton#mode']()] or ''
else
skk_mode = ''
end
return vim_mode .. skk_mode, hl
end
function vimrc.statusline.readonly(bufnr)
local ro = F.getbufvar(bufnr, '&readonly')
if ro == 1 then
return '[RO]'
else
return nil
end
end
function vimrc.statusline.filename(bufnr)
if F.bufname(bufnr) == '' then
return '[No Name]'
end
if vim.b[bufnr]._scratch_ then
return '*scratch*'
end
local this_path = F.expand(('#%s:p'):format(bufnr))
local other_paths = {}
for b = 1, F.bufnr('$') do
if F.bufexists(b) and b ~= bufnr then
other_paths[#other_paths+1] = F.bufname(b)
end
end
local result = uniquify.uniquify(this_path, other_paths)
if vim.bo[bufnr].filetype == 'dirvish' then
return '[dir] ' .. result .. '/'
else
return result
end
end
function vimrc.statusline.modified(bufnr)
local mod = F.getbufvar(bufnr, '&modified')
local ma = F.getbufvar(bufnr, '&modifiable')
if mod == 1 then
return '[+]'
elseif ma == 0 then
return '[-]'
else
return nil
end
end
function vimrc.statusline.extra_info(bufnr, winid)
local autosave = F.getbufvar(bufnr, 'autosave_timer_id', -1) ~= -1
local spell = F.getwinvar(winid, '&spell') == 1
return (autosave and '(A)' or '') .. (spell and '(S)' or '')
end
function vimrc.statusline.linenum(winid)
return F.line('.', winid) .. '/' .. F.line('$', winid)
end
function vimrc.statusline.fenc(bufnr)
local fenc = F.getbufvar(bufnr, '&fileencoding')
local bom = F.getbufvar(bufnr, '&bomb') -- BOMB!!
if fenc == '' then
local fencs = F.split(O.fileencodings, ',')
fenc = fencs[1] or O.encoding
end
if fenc == 'utf-8' then
return bom == 1 and 'U8[BOM]' or 'U8'
elseif fenc == 'utf-16' then
return 'U16[BE]'
elseif fenc == 'utf-16le' then
return 'U16[LE]'
elseif fenc == 'ucs-4' then
return 'U32[BE]'
elseif fenc == 'ucs-4le' then
return 'U32[LE]'
else
return fenc:upper()
end
end
function vimrc.statusline.eol(bufnr)
local eol = F.getbufvar(bufnr, '&endofline')
return eol == 0 and '[noeol]' or ''
end
function vimrc.statusline.ff(bufnr)
local ff = F.getbufvar(bufnr, '&fileformat')
if ff == 'unix' then
return ''
elseif ff == 'dos' then
return ' (CRLF)'
elseif ff == 'mac' then
return ' (CR)'
else
return ' (Unknown)'
end
end
function vimrc.statusline.filetype(bufnr)
local ft = F.getbufvar(bufnr, '&filetype')
if ft == '' then
return '[None]'
else
return ft
end
end
-- Tabline {{{1
O.tabline = '%!v:lua.vimrc.tabline.build()'
vimrc.tabline = {}
function vimrc.tabline.build()
local tal = ''
for tabnr = 1, F.tabpagenr('$') do
local is_active = tabnr == F.tabpagenr()
local buflist = F.tabpagebuflist(tabnr)
local bufnr = buflist[F.tabpagewinnr(tabnr)]
tal = tal .. string.format(
'%%#%s# %s ',
is_active and 'TabLineSel' or 'TabLine',
vimrc.statusline.filename(bufnr))
end
return tal .. '%#TabLineFill#'
end
|