Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: transparentbg plugin and whichkey[leader + n] added #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added lua/.DS_Store
Binary file not shown.
Binary file added lua/user/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions lua/user/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ return packer.startup(function(use)
use "goolord/alpha-nvim"
use "antoinemadec/FixCursorHold.nvim" -- This is needed to fix lsp doc highlight
use "folke/which-key.nvim"
use "xiyaowong/nvim-transparent"

-- Colorschemes
-- use "lunarvim/colorschemes" -- A bunch of colorschemes you can try out
Expand Down
125 changes: 125 additions & 0 deletions lua/user/transparent.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
local M = {}

local config = {
enable = false,
groups = {
"Normal",
"Comment",
"Constant",
"Special",
"Identifier",
"Statement",
"PreProc",
"Type",
"Underlined",
"Todo",
"String",
"Function",
"Conditional",
"Repeat",
"Operator",
"Structure",
"LineNr",
"NonText",
"SignColumn",
"CursorLineNr",
"EndOfBuffer",
},
extra_groups = {},
exclude = {},
}

local clear_group_bg = function(group, highlights)
if group then
if vim.tbl_contains(config.exclude, group) or vim.fn.highlight_exists(group) == 0 then
return
end
if not highlights then
highlights = vim.api.nvim_exec("highlight " .. group, true)
end
else
if highlights then
grou = vim.split(highlights, " ")[1]
else
return
end
end

if vim.tbl_contains(config.exclude, group) then
return
end

if highlights:match("links to") then
return
end

local term = highlights:match([[term=([%w#]+)]]) or "NONE"
local ctermfg = highlights:match([[ctermfg=([%w#]+)]]) or "NONE"
local gui = highlights:match([[gui=([%w#]+)]]) or "NONE"
local guifg = highlights:match([[guifg=([%w#]+)]]) or "NONE"
vim.cmd(
string.format(
"hi %s term=%s ctermfg=%s ctermbg=NONE gui=%s guifg=%s guibg=NONE",
group,
term,
ctermfg,
gui,
guifg
)
)
end

local function _clear_bg()
for _, group in ipairs(config.groups) do
clear_group_bg(group)
end

if type(config.extra_groups) == "string" then
if config.extra_groups == "all" then
local hls = vim.split(vim.api.nvim_exec("highlight", true), "\n")
for _, hl in ipairs(hls) do
clear_group_bg(nil, hl)
end
else
clear_group_bg(config.extra_groups)
end
else
for _, group in ipairs(config.extra_groups) do
clear_group_bg(group)
end
end
end

function M.clear_bg()
if vim.g.transparent_enabled ~= true then
return
end
-- ? some plugins calculate colors from basic highlights
-- : clear immediately
_clear_bg()
-- ? some plugins use autocommands to redefine highlights
-- : clear again after a while
vim.defer_fn(_clear_bg, 500)
end

function M.toggle_transparent(option)
if option == nil then
vim.g.transparent_enabled = not vim.g.transparent_enabled
else
vim.g.transparent_enabled = option
end
if vim.g.colors_name then
vim.cmd("colorscheme " .. vim.g.colors_name)
else
vim.cmd("doautocmd ColorScheme")
end
end

function M.setup(user_config)
config = vim.tbl_extend("force", config, user_config)
if vim.g.transparent_enabled == nil then
vim.g.transparent_enabled = config.enable
end
end

return Mp
1 change: 1 addition & 0 deletions lua/user/whichkey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ local mappings = {
"<cmd>lua require('telescope.builtin').find_files(require('telescope.themes').get_dropdown{previewer = false})<cr>",
"Find files",
},
["n"] = { "<cmd>TransparentEnable<cr>", "Transparent" },
["F"] = { "<cmd>Telescope live_grep theme=ivy<cr>", "Find Text" },
["P"] = { "<cmd>lua require('telescope').extensions.projects.projects()<cr>", "Projects" },

Expand Down