Update
This commit is contained in:
@@ -6,10 +6,9 @@ local MATH_NODES = {
|
||||
math_environment = true,
|
||||
}
|
||||
|
||||
local ts_utils = require("nvim-treesitter.ts_utils")
|
||||
|
||||
M.in_env_md = function(env)
|
||||
local node = ts_utils.get_node_at_cursor()
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
local node = vim.treesitter.get_node({ bufnr = 0, pos = { row - 1, col } })
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
while node do
|
||||
if node:type() == "generic_environment" then
|
||||
@@ -29,12 +28,56 @@ M.in_env = function(env)
|
||||
return pos[1] ~= 0 or pos[2] ~= 0
|
||||
end
|
||||
|
||||
-- For markdown
|
||||
M.in_mathzone_md = function()
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
local node = vim.treesitter.get_node({ bufnr = 0, pos = { row - 1, col } })
|
||||
while node do
|
||||
if MATH_NODES[node:type()] then
|
||||
return true
|
||||
end
|
||||
node = node:parent()
|
||||
end
|
||||
return false
|
||||
end
|
||||
M.in_text_md = function()
|
||||
return not M.in_mathzone_md()
|
||||
end
|
||||
|
||||
-- For typst
|
||||
M.in_mathzone_typ = function()
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
local node = vim.treesitter.get_node({ bufnr = 0, pos = { row - 1, col } })
|
||||
while node do
|
||||
if node:type() == "math" then
|
||||
return true
|
||||
end
|
||||
node = node:parent()
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
M.in_mathzone_tex = function()
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
local node = vim.treesitter.get_node({ bufnr = 0, pos = { row - 1, col } })
|
||||
while node do
|
||||
if MATH_NODES[node:type()] then
|
||||
return true
|
||||
end
|
||||
node = node:parent()
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
M.in_mathzone = function()
|
||||
local ft = vim.bo.filetype
|
||||
if ft == "tex" then
|
||||
return vim.api.nvim_eval("vimtex#syntax#in_mathzone()") == 1
|
||||
return M.in_mathzone_tex()
|
||||
elseif ft == "markdown" then
|
||||
return M.in_mathzone_md()
|
||||
elseif ft == "typst" then
|
||||
return M.in_mathzone_typ()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,21 +101,6 @@ M.in_algo = function()
|
||||
return M.in_env("algorithmic")
|
||||
end
|
||||
|
||||
-- For markdown
|
||||
M.in_mathzone_md = function()
|
||||
local node = ts_utils.get_node_at_cursor()
|
||||
while node do
|
||||
if MATH_NODES[node:type()] then
|
||||
return true
|
||||
end
|
||||
node = node:parent()
|
||||
end
|
||||
return false
|
||||
end
|
||||
M.in_text_md = function()
|
||||
return not M.in_mathzone_md()
|
||||
end
|
||||
|
||||
-- M.clean = function()
|
||||
-- local current_dir = vim.fn.expand("%:p:h")
|
||||
-- local file_types = { "aux", "log", "out", "fls", "fdb_latexmk", "bcf", "run.xml", "toc", "DS_Store", "bak*", "dvi" }
|
||||
|
||||
Reference in New Issue
Block a user