mirror of
https://github.com/HiPhish/rainbow-delimiters.nvim.git
synced 2024-09-16 14:24:05 +02:00
a74553b331
Based on a GitHub discussion[1], this option lets users specify a predicate to dynamically enable or disable rainbow delimiters for a buffer. [1] https://github.com/HiPhish/rainbow-delimiters.nvim/discussions/130
77 lines
2.7 KiB
Lua
77 lines
2.7 KiB
Lua
-- Copyright 2023 Alejandro "HiPhish" Sanchez
|
|
-- Copyright 2020-2022 Chinmay Dalal
|
|
--
|
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
|
-- you may not use this file except in compliance with the License.
|
|
-- You may obtain a copy of the License at
|
|
--
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
--
|
|
-- Unless required by applicable law or agreed to in writing, software
|
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
-- See the License for the specific language governing permissions and
|
|
-- limitations under the License.
|
|
|
|
if vim.g.loaded_rainbow then
|
|
return
|
|
end
|
|
|
|
local api = vim.api
|
|
local set_hl = api.nvim_set_hl
|
|
local create_augroup = api.nvim_create_augroup
|
|
local create_autocmd = api.nvim_create_autocmd
|
|
local get_lang = vim.treesitter.language.get_lang
|
|
local config = require 'rainbow-delimiters.config'
|
|
local log = require 'rainbow-delimiters.log'
|
|
local lib = require 'rainbow-delimiters.lib'
|
|
|
|
|
|
--- [ DEFINE HIGHLIGHT GROUPS ]------------------------------------------------
|
|
local function define_hlgroups()
|
|
log.trace 'Define highlight groups'
|
|
|
|
set_hl(0, 'RainbowDelimiterRed' , {default = true, fg = '#cc241d', ctermfg= 'Red' })
|
|
set_hl(0, 'RainbowDelimiterOrange', {default = true, fg = '#d65d0e', ctermfg= 'White' })
|
|
set_hl(0, 'RainbowDelimiterYellow', {default = true, fg = '#d79921', ctermfg= 'Yellow' })
|
|
set_hl(0, 'RainbowDelimiterGreen' , {default = true, fg = '#689d6a', ctermfg= 'Green' })
|
|
set_hl(0, 'RainbowDelimiterCyan' , {default = true, fg = '#a89984', ctermfg= 'Cyan' })
|
|
set_hl(0, 'RainbowDelimiterBlue' , {default = true, fg = '#458588', ctermfg= 'Blue' })
|
|
set_hl(0, 'RainbowDelimiterViolet', {default = true, fg = '#b16286', ctermfg= 'Magenta'})
|
|
end
|
|
|
|
define_hlgroups()
|
|
|
|
|
|
--- [ SET UP AUTOCOMMANDS ]----------------------------------------------------
|
|
local hl_augroup = create_augroup('TSRainbowHighlight', {})
|
|
local rb_augroup = create_augroup('TSRainbowDelimits', {})
|
|
|
|
create_autocmd('ColorScheme', {
|
|
desc = 'Re-apply highlight group definitions when the colour scheme changes',
|
|
group = hl_augroup,
|
|
callback = define_hlgroups
|
|
})
|
|
|
|
create_autocmd('FileType', {
|
|
desc = 'Attach to a new buffer',
|
|
group = rb_augroup,
|
|
callback = function(args)
|
|
local lang = get_lang(args.match)
|
|
local bufnr = args.buf
|
|
if not config.enabled_for(lang) then return end
|
|
if not config.enabled_when(bufnr) then return end
|
|
|
|
lib.attach(bufnr)
|
|
end,
|
|
})
|
|
|
|
create_autocmd('BufUnload', {
|
|
desc = 'Detach from the current buffer',
|
|
group = rb_augroup,
|
|
callback = function(args) lib.detach(args.buf) end
|
|
})
|
|
|
|
vim.g.loaded_rainbow = true
|
|
|
|
-- vim:tw=79:ts=4:sw=4:noet:
|