Skip to content

Commit 5fe8051

Browse files
committed
Attach to any buffer that we enter.
1 parent 5fdf7e1 commit 5fe8051

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lua/luasnip-latex-snippets/util/ts_utils.lua

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ function M.in_text(check_parent)
4949
return true
5050
end
5151

52-
local in_mathzone = false
53-
5452
local function check_in_mathzone()
5553
local node = get_node_at_cursor()
5654
while node do
@@ -64,14 +62,21 @@ local function check_in_mathzone()
6462
return false
6563
end
6664

67-
vim.api.nvim_buf_attach(0, false, {
68-
on_lines = function(...)
69-
in_mathzone = check_in_mathzone()
70-
end,
71-
})
65+
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"},
66+
{pattern = {"*.md"},
67+
callback = function()
68+
if not vim.b.tracking_math then
69+
vim.api.nvim_buf_attach(0, false, {on_lines = function(...)
70+
vim.b.in_mathzone = check_in_mathzone()
71+
end})
72+
vim.b.in_mathzone = false
73+
vim.b.tracking_math = true
74+
end
75+
end
76+
})
7277

7378
function M.in_mathzone()
74-
return in_mathzone
79+
return vim.b.in_mathzone
7580
end
7681

7782
return M

0 commit comments

Comments
 (0)