ccc.nvim icon indicating copy to clipboard operation
ccc.nvim copied to clipboard

Add `highlighter.exclude_buftypes`

Open 33KK opened this issue 1 year ago • 2 comments

Request for additional color space

No response

Request for other features

And I guess replace highlighter.excludes with highlighter.exclude_filetypes and add highlighter.buftypes for parity. The use case mostly is highlighter.exclude_buftypes = { "nofile" } with ccc.picker.trailing_whitespace, it's really hard to get all the filetypes that plugins use which shouldn't be highlighted, some don't even have any filetype.

Currently using a workaround:

vim.api.nvim_create_autocmd("BufEnter", {
	group = vim.api.nvim_create_augroup("ccc-highlighter-auto-enable", {}),
	callback = function(ev)
		if
			vim.tbl_contains(
				opts.highlighter.exclude_buftypes,
				vim.api.nvim_get_option_value("buftype", { buf = ev.buf })
			)
			or vim.tbl_contains(
				opts.highlighter.exclude_filetypes,
				vim.api.nvim_get_option_value("filetype", { buf = ev.buf })
			)
		then
			return
		end

		local ok, stat = pcall(vim.uv.fs_stat, ev.file)
		if ok and stat and stat.size > require("ccc.config").options.highlighter.max_byte then
			return
		end

		require("ccc.highlighter"):enable(ev.buf)
	end,
})

33KK avatar Jan 21 '25 19:01 33KK

Actually, this would be better, but it turns on the highlighting when switching to another buffer and it doesn't get disabled until you switch back and enter insert mode:

ccc.picker.trailing_whitespace({
	disable = function(buf)
		return vim.api.nvim_get_option_value("buftype", { buf = buf }) == "nofile"
	end
}),

33KK avatar Jan 21 '25 20:01 33KK

Thanks for the report. Let me treat this as a bug in the disable function. I will also consider allowing the highlighter to set the disable option, which is a function that returns a boolean.

uga-rosa avatar Feb 24 '25 11:02 uga-rosa