summaryrefslogtreecommitdiffstats
path: root/.config/nvim/plugin/50-highlight.lua
blob: 1daba82efa610ebc1d01d0f87169d7fc3f7cdca0 (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
--
-- 50-highlight.lua
--
-- * Creates a function to adjust highlight groups for the solarized colorscheme. It also sets popup
--   menu width and border style.
-- * Creates an autocommand to trigger this function when the background or color scheme changes.
-- * Sets the default colorscheme (solarized) and background (dark).
--
-- User commands:
--   `ColorsBgToggle`: toggle light/dark background
--

-- Adjust highlights (for the solarized theme) to fit my personal tastes.
local function adjust_solarized_highlights()
	local colors = { blue = "#268bd2", yellow = "#b58900" }
	-- Window bar style
	vim.api.nvim_set_hl(0, "WinBarCwd", { fg = colors.blue, italic = true })
	vim.api.nvim_set_hl(0, "WinBarFilePath", { italic = true })
	-- Matching delimiter
	vim.api.nvim_set_hl(0, "MatchParen", { link = "CurSearch" })
	-- Floating windows and popup menu windows follow the editor background, their borders too so
	-- that the popup menu border draws a clean separation.
	vim.opt.pumborder = "rounded"
	vim.opt.pumwidth = 25 -- Minimum popup menu width
	vim.api.nvim_set_hl(0, "NormalFloat", { link = "Normal" })
	local normal_bg = vim.api.nvim_get_hl(0, { name = "Normal", link = false }).bg
	vim.api.nvim_set_hl(0, "FloatBorder", { bg = normal_bg, update = true })
	vim.api.nvim_set_hl(0, "Pmenu", { bg = normal_bg, update = true })
	vim.api.nvim_set_hl(0, "PmenuSbar", { bg = normal_bg, update = true })
	-- Currently selected tabpage
	vim.api.nvim_set_hl(0, "TabLineSel", { fg = colors.yellow, bold = true, update = true })
	-- Todo hl group
	vim.api.nvim_set_hl(0, "Todo", { bg = "Yellow", fg = "Black", bold = true })
end

-- Adjust highlights to fit my personal tastes.
local function adjust_highlights()
	if vim.g.colors_name == "solarized" then
		adjust_solarized_highlights()
	end
end

local function toggle_theme()
	vim.opt.background = vim.o.background == "light" and "dark" or "light"
	vim.notify("Color theme set to " .. vim.o.background)
end

----------------------------------------------------------------------------------------------------

vim.api.nvim_create_autocmd("ColorScheme", {
	desc = "Adjust custom highlights",
	group = vim.g.dotfiles.augroup,
	callback = adjust_highlights,
})

vim.api.nvim_create_autocmd("OptionSet", {
	desc = "Adjust custom highlights on theme change",
	pattern = "background",
	group = vim.g.dotfiles.augroup,
	callback = adjust_highlights,
})

vim.api.nvim_create_user_command(
	"ColorsBgToggle",
	toggle_theme,
	{ desc = "Toggle light/dark theme" }
)

vim.cmd.colorscheme("solarized")
vim.opt.background = "dark"