Skip to content

Commit c16c0bc

Browse files
Added a callback that is called when the buffer is cleared. (#356)
1 parent 1ef7664 commit c16c0bc

File tree

7 files changed

+15
-2
lines changed

7 files changed

+15
-2
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ require('render-markdown').setup({
260260
attach = function() end,
261261
-- Called after plugin renders a buffer
262262
render = function() end,
263+
-- Called after plugin clears a buffer
264+
clear = function() end,
263265
},
264266
heading = {
265267
-- Turn on / off heading icon & background rendering

Diff for: doc/limitations.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ in this plugin. Different plugins will have different setups, below are some exa
3737
latex = { enabled = false },
3838
win_options = { conceallevel = { rendered = 2 } },
3939
on = {
40-
attach = function()
40+
render = function()
4141
require('nabla').enable_virt({ autogen = true })
4242
end,
43+
clear = function()
44+
require('nabla').disable_virt()
45+
end,
4346
},
4447
},
4548
},

Diff for: doc/render-markdown.txt

+3
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ Default Configuration ~
321321
attach = function() end,
322322
-- Called after plugin renders a buffer
323323
render = function() end,
324+
-- Called after plugin clears a buffer
325+
clear = function() end,
326+
324327
},
325328
heading = {
326329
-- Turn on / off heading icon & background rendering

Diff for: lua/render-markdown/core/ui.lua

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function M.run_update(buf, win, change)
150150
state.on.render({ buf = buf })
151151
else
152152
M.clear(buf, buffer_state)
153+
state.on.clear({ buf = buf })
153154
end
154155
end
155156

Diff for: lua/render-markdown/init.lua

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local M = {}
2121
---@class (exact) render.md.UserCallback
2222
---@field public attach? fun(ctx: render.md.CallbackContext)
2323
---@field public render? fun(ctx: render.md.CallbackContext)
24+
---@field public clear? fun(ctx: render.md.CallbackContext)
2425

2526
---@class (exact) render.md.UserInjection
2627
---@field public enabled? boolean
@@ -401,6 +402,8 @@ M.default_config = {
401402
attach = function() end,
402403
-- Called after plugin renders a buffer
403404
render = function() end,
405+
-- Called after plugin clears a buffer
406+
clear = function() end,
404407
},
405408
heading = {
406409
-- Turn on / off heading icon & background rendering

Diff for: lua/render-markdown/state.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ function M.validate()
335335
:check()
336336
end)
337337
:nested('on', function(on)
338-
on:type({ 'attach', 'render' }, 'function'):check()
338+
on:type({ 'attach', 'render' , 'clear'}, 'function'):check()
339339
end)
340340
:nested('overrides', function(overrides)
341341
overrides

Diff for: lua/render-markdown/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
---@class (exact) render.md.Callback
44
---@field public attach fun(ctx: render.md.CallbackContext)
55
---@field public render fun(ctx: render.md.CallbackContext)
6+
---@field public clear fun(ctx: render.md.CallbackContext)
67

78
---@class (exact) render.md.Injection
89
---@field public enabled boolean

0 commit comments

Comments
 (0)