summaryrefslogtreecommitdiffstats
path: root/.config/nvim/plugin/50-statusline.lua
blob: eea1291ccd84c6ab8d25753717dc4b0975723fc7 (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
--
-- Status line configuration plugin
--
-- I use lualine, see https://github.com/nvim-lualine/lualine.nvim#configuring-lualine-in-initvim

local lualine = require("lualine")

local function spell_status()
	if vim.o.spelllang == "fr" then
		return "+S(fr)"
	elseif vim.o.spelllang == "en_us" then
		return "+S(en)"
	elseif vim.o.spelllang == "en_us,fr" then
		return "+S(en,fr)"
	end
end

local function statuses()
	return (vim.b.autoformat and "+F" or "") .. (vim.o.spell and spell_status() or "")
end

-- lualine builds its own section-b-backed highlights for the diff/diagnostics
-- components (lualine_b_diff_added_normal, lualine_b_diagnostics_error_normal,
-- ...). Stamp bold onto them with update=true so only the bold attribute
-- changes -- fg and section b's background are left untouched. Must run after
-- lualine (re)creates the groups: initial setup, theme switch, colorscheme.
local function bold_diff_diag()
	for name in pairs(vim.api.nvim_get_hl(0, {})) do
		if name:find("^lualine_b_diff") or name:find("^lualine_b_diagnostics") then
			vim.api.nvim_set_hl(0, name, { bold = true, update = true })
		end
	end
end

vim.api.nvim_create_autocmd("ColorScheme", {
	desc = "Re-bold lualine diff/diagnostics after colorscheme rebuild",
	group = vim.g.dotfiles.augroup,
	callback = function()
		vim.schedule(bold_diff_diag)
	end,
})

local lualine_sections = {
	lualine_c = { statuses, "filename" },
	lualine_x = { "encoding", "fileformat", "filetype", "lsp_status" },
}

-- Adjust colors when the theme (light/dark) changes
vim.api.nvim_create_autocmd("OptionSet", {
	desc = "Adjust color scheme",
	pattern = "background",
	group = vim.g.dotfiles.augroup,
	callback = function()
		lualine.setup({
			options = {
				theme = vim.o.background == "light" and "solarized_light" or "solarized_dark",
				disabled_filetypes = { "netrw", "qf" },
				component_separators = { left = "|", right = "|" },
				section_separators = { left = "", right = "" },
			},
		})
		vim.schedule(bold_diff_diag)
	end,
})

lualine.setup({
	options = { theme = vim.o.background == "light" and "solarized_light" or "solarized_dark" },
	sections = lualine_sections,
})
vim.schedule(bold_diff_diag)

vim.api.nvim_create_user_command("LualineConfig", function()
	vim.notify(vim.inspect(lualine.get_config()))
end, { desc = "Show lualine configuration" })