Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable by filetype #78

Merged
merged 6 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,36 @@ return {
-- PrevParagraph = { text = "{", prio = 8 },
-- NextParagraph = { text = "}", prio = 8 },
-- },
-- disabled_fts = {
-- "NvimTree",
-- "TelescopePrompt",
-- "aerial",
-- "alpha",
-- "checkhealth",
-- "dapui*",
-- "Diffview*",
-- "Dressing*",
-- "help",
-- "httpResult",
-- "lazy",
-- "lspinfo",
-- "Neogit*",
-- "mason",
-- "neotest%-summary",
-- "minifiles",
-- "neo%-tree*",
-- "netrw",
-- "noice",
-- "notify",
-- "prompt",
-- "qf",
-- "query",
-- "oil",
-- "undotree",
-- "trouble",
-- "Trouble",
-- "fugitive",
-- },
},
}
```
Expand All @@ -58,6 +88,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
31 changes: 31 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 table
tris203 marked this conversation as resolved.
Show resolved Hide resolved

---@class Precognition.PartialConfig
---@field startVisible? boolean
Expand Down Expand Up @@ -80,6 +81,36 @@ local default = {
PrevParagraph = { text = "{", prio = 8 },
NextParagraph = { text = "}", prio = 8 },
},
disabled_fts = {
"NvimTree",
"TelescopePrompt",
"aerial",
"alpha",
"checkhealth",
"dapui*",
"Diffview*",
"Dressing*",
"help",
"httpResult",
"lazy",
"lspinfo",
"Neogit*",
"mason",
"neotest%-summary",
"minifiles",
"neo%-tree*",
"netrw",
"noice",
"notify",
"prompt",
"qf",
"query",
"oil",
"undotree",
"trouble",
"Trouble",
"fugitive",
tris203 marked this conversation as resolved.
Show resolved Hide resolved
},
}

---@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? table
tris203 marked this conversation as resolved.
Show resolved Hide resolved
---@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)