Skip to content

Commit

Permalink
feat: disable by filetype (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
marovira authored Jun 25, 2024
1 parent 02dcc8f commit 2a566f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ return {
-- PrevParagraph = { text = "{", prio = 8 },
-- NextParagraph = { text = "}", prio = 8 },
-- },
-- disabled_fts = {
-- "startify",
-- },
},
}
```
Expand All @@ -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](<https://neovim.io/doc/user/api.html#nvim_set_hl()>))

- `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.
Expand Down
4 changes: 4 additions & 0 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,6 +81,9 @@ local default = {
PrevParagraph = { text = "{", prio = 8 },
NextParagraph = { text = "}", prio = 8 },
},
disabled_fts = {
"startify",
},
}

---@type Precognition.Config
Expand Down
13 changes: 12 additions & 1 deletion lua/precognition/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions tests/precognition/blacklist_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2a566f0

Please sign in to comment.