Skip to content

Commit

Permalink
Use FileType event instead of Syntax, call nvim_win_is_valid instead …
Browse files Browse the repository at this point in the history
…of win > 0
  • Loading branch information
MeanderingProgrammer committed May 21, 2024
1 parent 966472e commit 655da2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 3 additions & 6 deletions lua/render-markdown/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function M.setup(opts)
end
end,
})
vim.api.nvim_create_autocmd({ 'FileChangedShellPost', 'Syntax', 'TextChanged' }, {
vim.api.nvim_create_autocmd({ 'FileChangedShellPost', 'FileType', 'TextChanged' }, {
group = group,
callback = function(event)
vim.schedule(function()
Expand All @@ -179,11 +179,8 @@ function M.setup(opts)
end,
})

vim.api.nvim_create_user_command(
'RenderMarkdownToggle',
M.toggle,
{ desc = 'Switch between enabling & disabling render markdown plugin' }
)
local description = 'Switch between enabling & disabling render markdown plugin'
vim.api.nvim_create_user_command('RenderMarkdownToggle', M.toggle, { desc = description })
end

M.toggle = function()
Expand Down
8 changes: 4 additions & 4 deletions lua/render-markdown/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ M.refresh = function(buf)
util.set_conceal(buf, state.config.conceal.rendered)

-- Make sure injections are processed
vim.treesitter.get_parser(buf):parse(true)

vim.treesitter.get_parser(buf):for_each_tree(function(tree, language_tree)
local parser = vim.treesitter.get_parser(buf)
parser:parse(true)
parser:for_each_tree(function(tree, language_tree)
local language = language_tree:lang()
logger.debug({ language = language })
if language == 'markdown' then
Expand Down Expand Up @@ -58,7 +58,7 @@ M.clear_valid = function(buf)
end
vim.api.nvim_buf_clear_namespace(buf, M.namespace, 0, -1)
local win = util.buf_to_win(buf)
if win < 0 then
if not vim.api.nvim_win_is_valid(win) then
return false
end
util.set_conceal(buf, state.config.conceal.default)
Expand Down

0 comments on commit 655da2c

Please sign in to comment.