Skip to content

Commit

Permalink
fix: #196 #178 use api nvim_set_hl, add autocmd.
Browse files Browse the repository at this point in the history
  • Loading branch information
zztrieuzz committed Dec 20, 2023
1 parent a18a580 commit 0f2ae87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
32 changes: 12 additions & 20 deletions lua/spectre/highlight.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
local M = {}
local create_highlight_group = function (name, link)
local ok, hl = pcall(vim.api.nvim_get_hl_by_name, link, true)
if not ok then
return
end
if hl.foreground ~= nil then
-- vim.cmd.highlight({name, 'guifg='.. string.format("#%06x", hl.foreground)})
vim.cmd("highlight " .. name .. " guifg=" .. string.format("#%06x", hl.foreground) )
end

if hl.background ~= nil then
-- vim.cmd.highlight({name, 'guibg='.. string.format("#%06x", hl.background)})
vim.cmd("highlight " .. name .. " guibg=" .. string.format("#%06x", hl.background) )
end
M.set_hl = function()
vim.api.nvim_set_hl(0, 'SpectreHeader', { link = "Comment" })
vim.api.nvim_set_hl(0, 'SpectreBody', { link = "String" })
vim.api.nvim_set_hl(0, 'SpectreFile', { link = "Keyword" })
vim.api.nvim_set_hl(0, 'SpectreDir', { link = "Comment" })
vim.api.nvim_set_hl(0, 'SpectreSearch', { link = "DiffChange" })
vim.api.nvim_set_hl(0, 'SpectreBorder', { link = "Comment" })
vim.api.nvim_set_hl(0, 'SpectreReplace', { link = "DiffDelete" })
end

create_highlight_group('SpectreHeader', "Comment")
create_highlight_group('SpectreBody', "String")
create_highlight_group('SpectreFile', "Keyword")
create_highlight_group('SpectreDir', "Comment")
create_highlight_group('SpectreSearch', "DiffChange")
create_highlight_group('SpectreBorder', "Comment")
create_highlight_group('SpectreReplace', "DiffDelete")
vim.api.nvim_create_autocmd('ColorScheme', {
pattern = '*',
callback = M.set_hl
})

return M;
2 changes: 1 addition & 1 deletion lua/spectre/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ local state_utils = require('spectre.state_utils')
local utils = require('spectre.utils')
local ui = require('spectre.ui')
local log = require('spectre._log')
require('spectre.highlight')
local async = require('plenary.async')

local scheduler = async.util.scheduler
Expand All @@ -38,6 +37,7 @@ M.setup = function(cfg)
for _, opt in pairs(state.user_config.default.find.options) do
state.options[opt] = true
end
require('spectre.highlight').set_hl()
end

M.open_visual = function(opts)
Expand Down

0 comments on commit 0f2ae87

Please sign in to comment.