Skip to content

Cache "is_math" state #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lua/luasnip-latex-snippets/util/ts_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function M.in_text(check_parent)
return true
end

function M.in_mathzone()
local function check_in_mathzone()
local node = get_node_at_cursor()
while node do
if node:type() == "text_mode" then
Expand All @@ -62,4 +62,21 @@ function M.in_mathzone()
return false
end

vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"},
{pattern = {"*.md"},
callback = function()
if not vim.b.tracking_math then
vim.api.nvim_buf_attach(0, false, {on_lines = function(...)
vim.b.in_mathzone = check_in_mathzone()
end})
vim.b.in_mathzone = false
vim.b.tracking_math = true
end
end
})

function M.in_mathzone()
return vim.b.in_mathzone
end

return M