diff --git a/doc/preview_options.txt b/doc/preview_options.txt index bccbfda..f5934ca 100644 --- a/doc/preview_options.txt +++ b/doc/preview_options.txt @@ -35,6 +35,8 @@ ---@field filetypes? string[] --- Buftypes that should be ignored(e.g. nofile). ---@field ignore_buftypes? string[] + --- Condition to check if a buffer should be attached or not. + ---@field condition? fun(buffer: integer): boolean --- Maximum number of lines a buffer can have before switching to partial rendering. ---@field max_buf_lines? integer --- @@ -749,6 +751,15 @@ ignore_buftypes ~ List of buffer types to ignore when attaching to new buffers. Checked after the filetype. + *markview.nvim-preview.condition* +condition ~ + + - Type: `nil | fun(buffer: integer): boolean` + - Dynamic: false + - Default: nil + +Condition used to check if a buffer should be attached to or not. + *markview.nvim-preview.max_buf_lines* max_buf_lines ~ diff --git a/lua/definitions/preview.lua b/lua/definitions/preview.lua index c78142a..78023c8 100644 --- a/lua/definitions/preview.lua +++ b/lua/definitions/preview.lua @@ -35,6 +35,8 @@ local M = {}; ---@field filetypes? string[] --- Buftypes that should be ignored(e.g. nofile). ---@field ignore_buftypes? string[] +--- Condition to check if a buffer should be attached or not. +---@field condition? fun(buffer: integer): boolean --- Maximum number of lines a buffer can have before switching to partial rendering. ---@field max_buf_lines? integer --- diff --git a/markview.nvim.wiki b/markview.nvim.wiki index 326e232..b80de73 160000 --- a/markview.nvim.wiki +++ b/markview.nvim.wiki @@ -1 +1 @@ -Subproject commit 326e23245a02d3aa1691e5a65a964b5c1c9acfaa +Subproject commit b80de73284932a9db9ac93f198460fde037bd5c9 diff --git a/plugin/markview.lua b/plugin/markview.lua index c04d6b9..be1e24d 100644 --- a/plugin/markview.lua +++ b/plugin/markview.lua @@ -131,12 +131,16 @@ vim.api.nvim_create_autocmd({ "BufAdd", "BufEnter" }, { local attach_ft = spec.get({ "preview", "filetypes" }, { fallback = {}, ignore_enable = true }); local ignore_bt = spec.get({ "preview", "ignore_buftypes" }, { fallback = {}, ignore_enable = true }); + local condition = spec.get({ "preview", "condition" }, { eval_args = { buffer } }); + if vim.list_contains(ignore_bt, bt) == true then --- Ignored buffer type. return; elseif vim.list_contains(attach_ft, ft) == false then --- Ignored file type. return; + elseif condition == false then + return; end markview.actions.attach(buffer);