From cad236f9bbe46fbb53127014731d8507a3bc80af Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 7 Nov 2024 00:17:38 +0100 Subject: [PATCH] feat(win): allow setting `ft` just for highlighting without actually changing the `filetype` --- lua/snacks/git.lua | 2 +- lua/snacks/notifier.lua | 5 +++-- lua/snacks/win.lua | 6 ++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lua/snacks/git.lua b/lua/snacks/git.lua index efba6ead..1acfa2e0 100644 --- a/lua/snacks/git.lua +++ b/lua/snacks/git.lua @@ -8,7 +8,7 @@ Snacks.config.style("blame_line", { border = "rounded", title = " Git Blame ", title_pos = "center", - bo = { filetype = "git" }, + ft = "git", }) --- Gets the git root for a buffer or path. diff --git a/lua/snacks/notifier.lua b/lua/snacks/notifier.lua index 23cbab56..751e0ae9 100644 --- a/lua/snacks/notifier.lua +++ b/lua/snacks/notifier.lua @@ -60,11 +60,12 @@ local M = setmetatable({}, { Snacks.config.style("notification", { border = "rounded", zindex = 100, + ft = "markdown", wo = { winblend = 5, wrap = false, }, - bo = { filetype = "markdown" }, + bo = { filetype = "snacks_notif" }, }) ---@class snacks.notifier.Config @@ -309,7 +310,7 @@ function N:render(notif) style = "notification", enter = false, backdrop = false, - bo = { filetype = notif.ft }, + ft = notif.ft, noautocmd = true, wo = { winhighlight = table.concat({ diff --git a/lua/snacks/win.lua b/lua/snacks/win.lua index f1de842b..0e2a3e7a 100644 --- a/lua/snacks/win.lua +++ b/lua/snacks/win.lua @@ -28,6 +28,7 @@ local M = setmetatable({}, { ---@field backdrop? number|false Opacity of the backdrop (default: 60) ---@field wo? vim.wo window options ---@field bo? vim.bo buffer options +---@field ft? string filetype to use for treesitter/syntax highlighting. Won't override existing filetype ---@field keys? table Key mappings ---@field on_buf? fun(self: snacks.win) Callback after opening the buffer ---@field on_win? fun(self: snacks.win) Callback after opening the window @@ -338,7 +339,7 @@ function M:show() self.opts.on_win(self) end - local ft = vim.bo[self.buf].filetype + local ft = self.opts.ft or vim.bo[self.buf].filetype if ft then local lang = ft and vim.treesitter.language.get_lang(ft) if lang and not vim.b[self.buf].ts_highlight and not pcall(vim.treesitter.start, self.buf, lang) then @@ -492,8 +493,6 @@ end ---@private ---@param type "win" | "buf" function M:set_options(type) - local ei = vim.o.eventignore - vim.o.eventignore = "all" local opts = type == "win" and self.opts.wo or self.opts.bo ---@diagnostic disable-next-line: no-unknown for k, v in pairs(opts or {}) do @@ -509,7 +508,6 @@ function M:set_options(type) ) end end - vim.o.eventignore = ei end function M:buf_valid()