Skip to content

Commit

Permalink
feat: support glob pattern for disabled_filetypes (#80)
Browse files Browse the repository at this point in the history
* feat: support glob pattern for disabled_filetypes

* refactor: update default disabled_filetypes

* refactor: refine glob matching function

---------

Co-authored-by: Max Shen <m4xshen@gmail.com>
  • Loading branch information
heywhy and m4xshen committed Apr 17, 2024
1 parent 83228b9 commit ef90503
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/hardtime.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Example:

>lua
-- Add "oil" to the disabled_filetypes
disabled_filetypes = { "qf", "netrw", "NvimTree", "lazy", "mason", "oil" },
disabled_filetypes = { "qf", "netrw", "NvimTree", "lazy", "mason", "oil", "Neogit*" },
<

If the option is a table with a `key = value` pair, your value will overwrite
Expand Down
16 changes: 4 additions & 12 deletions lua/hardtime/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,15 @@ M.config = {
"aerial",
"alpha",
"checkhealth",
"dapui-repl",
"dapui_breakpoints",
"dapui_console",
"dapui_scopes",
"dapui_stacks",
"dapui_watches",
"DressingInput",
"DressingSelect",
"dapui*",
"Dressing*",
"help",
"lazy",
"NeogitStatus",
"NeogitLogView",
"Neogit*",
"mason",
"neotest-summary",
"minifiles",
"neo-tree",
"neo-tree-popup",
"neo-tree*",
"netrw",
"noice",
"notify",
Expand Down
12 changes: 12 additions & 0 deletions lua/hardtime/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ local function get_return_key(key)
return key
end

local function match_filetype(ft)
for _, value in pairs(config.disabled_filetypes) do
local matcher = "^" .. value .. (value:sub(-1) == "*" and "" or "$")
if ft:match(matcher) then
return true
end
end

return false
end

local function should_disable()
return vim.tbl_contains(config.disabled_filetypes, vim.bo.ft)
or match_filetype(vim.bo.ft)
or vim.api.nvim_buf_get_option(0, "buftype") == "terminal"
or vim.fn.reg_executing() ~= ""
or vim.fn.reg_recording() ~= ""
Expand Down

0 comments on commit ef90503

Please sign in to comment.