Skip to content

Commit

Permalink
feat; Added condition for more fine grained control over special bu…
Browse files Browse the repository at this point in the history
…ffers

Closes #272
  • Loading branch information
OXY2DEV committed Jan 30, 2025
1 parent 5b7b6e4 commit f933b45
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions doc/preview_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down Expand Up @@ -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 ~

Expand Down
2 changes: 2 additions & 0 deletions lua/definitions/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
Expand Down
2 changes: 1 addition & 1 deletion markview.nvim.wiki
4 changes: 4 additions & 0 deletions plugin/markview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f933b45

Please sign in to comment.