diff --git a/README.md b/README.md index b972a78..906b919 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ return { -- PrevParagraph = { text = "{", prio = 8 }, -- NextParagraph = { text = "}", prio = 8 }, -- }, + -- disabled_fts = { + -- "startify", + -- }, }, } ``` @@ -58,6 +61,8 @@ return { 1. As a table containing a link property pointing to an existing highlight group (see `:highlight` for valid options). 2. As a table specifying custom highlight values, such as foreground and background colors. ([more info]()) +- `disabled_fts` can be used to disable `precognition` on specific filetypes. + ### Hint priorities Any hints that could appear in the same place as others should have unique priorities to avoid conflicts. diff --git a/lua/precognition/init.lua b/lua/precognition/init.lua index 1d00e27..ff9c5c9 100644 --- a/lua/precognition/init.lua +++ b/lua/precognition/init.lua @@ -27,6 +27,7 @@ local M = {} ---@field highlightColor vim.api.keyset.highlight ---@field hints Precognition.HintConfig ---@field gutterHints Precognition.GutterHintConfig +---@field disabled_fts string[] ---@class Precognition.PartialConfig ---@field startVisible? boolean @@ -80,6 +81,9 @@ local default = { PrevParagraph = { text = "{", prio = 8 }, NextParagraph = { text = "}", prio = 8 }, }, + disabled_fts = { + "startify", + }, } ---@type Precognition.Config diff --git a/lua/precognition/utils.lua b/lua/precognition/utils.lua index 256ee9a..509198a 100644 --- a/lua/precognition/utils.lua +++ b/lua/precognition/utils.lua @@ -35,12 +35,23 @@ function M.char_class(char, big_word) end ---@param bufnr? integer +---@param disabled_fts? string[] ---@return boolean -function M.is_blacklisted_buffer(bufnr) +function M.is_blacklisted_buffer(bufnr, disabled_fts) bufnr = bufnr or vim.api.nvim_get_current_buf() if vim.api.nvim_get_option_value("buftype", { buf = bufnr }) ~= "" then return true end + + if disabled_fts == nil then + return false + end + + for _, ft in ipairs(disabled_fts) do + if vim.api.nvim_get_option_value("filetype", { buf = bufnr }) == ft then + return true + end + end return false end diff --git a/tests/precognition/blacklist_spec.lua b/tests/precognition/blacklist_spec.lua index 94d4810..7853bf0 100644 --- a/tests/precognition/blacklist_spec.lua +++ b/tests/precognition/blacklist_spec.lua @@ -48,4 +48,11 @@ describe("blacklist buffers", function() vim.api.nvim_open_term(test_buffer, {}) eq(utils.is_blacklisted_buffer(test_buffer), true) end) + + it("blacklisted buffer by filetype", function() + local test_buffer = vim.api.nvim_create_buf(true, false) + local test_fts = { "startify" } + vim.api.nvim_set_option_value("filetype", "startify", { buf = test_buffer }) + eq(utils.is_blacklisted_buffer(test_buffer, test_fts), true) + end) end)