Skip to content

Commit b9c98ff

Browse files
committedFeb 1, 2025
fix: schedule initial buffer attach to handle lazy loading edge cases
## Details Issue: #315 Previously we added a step to attach to the current buffer to handle `vim-plug` based lazy loading not running for the initial file. This causes a problem with `lazy.nvim` since the attach function will run before picking up user configuration values, which will cause the first buffer to be out of sync from the user configuration. As a sort of hacky but good enough solution run the lazy load handling attach calls behind a vim.schedule. This should result in the event based ones running first and avoid this problem.
1 parent 1ba6fb7 commit b9c98ff

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed
 

Diff for: ‎doc/render-markdown.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2025 January 28
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 January 31
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

Diff for: ‎lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '7.8.12'
8+
M.version = '7.8.13'
99

1010
function M.check()
1111
M.start('version')

Diff for: ‎lua/render-markdown/manager.lua

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ M.group = vim.api.nvim_create_augroup('RenderMarkdown', { clear = true })
1515
---Should only be called from plugin directory
1616
function M.setup()
1717
-- Lazy Loading: ignores current buffer as FileType event already executed
18-
M.attach(util.current('buf'))
18+
M.schedule_attach()
1919
-- Attempt to attach to all buffers, cannot use pattern to support plugin directory
2020
vim.api.nvim_create_autocmd('FileType', {
2121
group = M.group,
@@ -43,7 +43,7 @@ end
4343
---@param enabled boolean
4444
function M.set_all(enabled)
4545
-- Lazy Loading: all previously opened buffers have been ignored
46-
M.attach(util.current('buf'))
46+
M.schedule_attach()
4747
state.enabled = enabled
4848
for _, buf in ipairs(buffers) do
4949
ui.update(buf, vim.fn.bufwinid(buf), 'UserCommand', true)
@@ -56,6 +56,14 @@ function M.is_attached(buf)
5656
return vim.tbl_contains(buffers, buf)
5757
end
5858

59+
---@private
60+
function M.schedule_attach()
61+
local buf = util.current('buf')
62+
vim.schedule(function()
63+
M.attach(buf)
64+
end)
65+
end
66+
5967
---@private
6068
---@param buf integer
6169
function M.attach(buf)

0 commit comments

Comments
 (0)
Please sign in to comment.