From 68da8f5a24813e28c91109bf32b7859fe16c41d2 Mon Sep 17 00:00:00 2001 From: Zelong Kuang Date: Tue, 14 Oct 2025 20:51:06 +1100 Subject: [PATCH] Update --- lazy-lock.json | 2 +- lazyvim.json | 3 +- lua/config/lazy.lua | 1 + lua/plugins/default/luasnip.lua | 76 ++++----------- lua/plugins/{editing => }/tabout.lua | 1 + lua/util/latex.lua | 138 +++++++++++---------------- 6 files changed, 78 insertions(+), 143 deletions(-) rename lua/plugins/{editing => }/tabout.lua (86%) diff --git a/lazy-lock.json b/lazy-lock.json index dcdd798..384bd18 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -39,6 +39,7 @@ "mini.pairs": { "branch": "main", "commit": "b9aada8c0e59f2b938e98fbf4eae0799eba96ad9" }, "mini.surround": { "branch": "main", "commit": "444e155147e2b5159dd28a65f9736254c16cb817" }, "neo-tree.nvim": { "branch": "main", "commit": "c4c168e459395275c552179a1baf9c3d885d6a74" }, + "neotab.nvim": { "branch": "master", "commit": "e99d3e28c5a2066d2d368dfe4ef3827c8d75d337" }, "neotest": { "branch": "master", "commit": "7166dc36af2760a76479e021e0521e23f62165f1" }, "neotest-haskell": { "branch": "master", "commit": "5266c115617186f17708344451f46ec88f3d1f6b" }, "neotest-python": { "branch": "master", "commit": "b0d3a861bd85689d8ed73f0590c47963a7eb1bf9" }, @@ -73,7 +74,6 @@ "vim-dadbod": { "branch": "master", "commit": "e95afed23712f969f83b4857a24cf9d59114c2e6" }, "vim-dadbod-completion": { "branch": "master", "commit": "a8dac0b3cf6132c80dc9b18bef36d4cf7a9e1fe6" }, "vim-dadbod-ui": { "branch": "master", "commit": "e8b53c0f3aa6e6127ac2a2d2071d9aade6c6e373" }, - "vim-startuptime": { "branch": "master", "commit": "b6f0d93f6b8cf6eee0b4c94450198ba2d6a05ff6" }, "vimtex": { "branch": "master", "commit": "be9deac3a23eeb145ccf11dd09080795838496ce" }, "which-key.nvim": { "branch": "main", "commit": "b4177e3eaf15fe5eb8357ebac2286d488be1ed00" }, "yanky.nvim": { "branch": "main", "commit": "04775cc6e10ef038c397c407bc17f00a2f52b378" }, diff --git a/lazyvim.json b/lazyvim.json index c73a4f2..8ac54a7 100644 --- a/lazyvim.json +++ b/lazyvim.json @@ -29,8 +29,7 @@ "lazyvim.plugins.extras.ui.treesitter-context", "lazyvim.plugins.extras.util.chezmoi", "lazyvim.plugins.extras.util.dot", - "lazyvim.plugins.extras.util.mini-hipatterns", - "lazyvim.plugins.extras.util.startuptime" + "lazyvim.plugins.extras.util.mini-hipatterns" ], "install_version": 8, "news": { diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua index d169d34..a2f7448 100644 --- a/lua/config/lazy.lua +++ b/lua/config/lazy.lua @@ -19,6 +19,7 @@ require("lazy").setup({ { import = "plugins" }, { import = "plugins.ui" }, { import = "plugins.lang" }, + { import = "plugins.coding" }, { import = "plugins.default" }, }, diff --git a/lua/plugins/default/luasnip.lua b/lua/plugins/default/luasnip.lua index f36981c..844de65 100644 --- a/lua/plugins/default/luasnip.lua +++ b/lua/plugins/default/luasnip.lua @@ -7,64 +7,24 @@ return { store_selection_keys = "`", }) require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/LuaSnip" }) - local auto_expand = require("luasnip").expand_auto - require("luasnip").expand_auto = function(...) - vim.o.undolevels = vim.o.undolevels - auto_expand(...) - end - -- local types = require("luasnip.util.types") - -- require("luasnip").config.setup({ - -- ext_opts = { - -- [types.choiceNode] = { - -- active = { - -- virt_text = { { "●", "GruvboxOrange" } }, - -- }, - -- }, - -- [types.insertNode] = { - -- active = { - -- virt_text = { { "●", "GruvboxBlue" } }, - -- }, - -- }, - -- }, - -- }) - end, - keys = function() - return { - { - "fj", - function() - return require("luasnip").expand_or_locally_jumpable() and "luasnip-jump-next" - -- or ":call searchpair('[([{<|]', '', '[)\\]}>|]', 'W')a" - end, - expr = true, - silent = true, - mode = "i", - }, - { - "fj", - function() - return require("luasnip").jump(1) - end, - mode = "s", - }, - { - "fk", - function() - require("luasnip").jump(-1) - end, - mode = { "i", "s" }, - }, - { - "", - "luasnip-next-choice", - mode = { "i", "s" }, - }, - { - "", - "luasnip-prev-choice", - mode = { "i", "s" }, - }, - } + -- local auto_expand = require("luasnip").expand_auto + -- require("luasnip").expand_auto = function(...) + -- vim.o.undolevels = vim.o.undolevels + -- auto_expand(...) + -- end end, + keys = { + { + "", + function() + return require("luasnip").jumpable(1) -- + and "luasnip-jump-next" + or "(neotab-out)" + end, + expr = true, + silent = true, + mode = "i", + }, + }, }, } diff --git a/lua/plugins/editing/tabout.lua b/lua/plugins/tabout.lua similarity index 86% rename from lua/plugins/editing/tabout.lua rename to lua/plugins/tabout.lua index 91ca0c6..22cc804 100644 --- a/lua/plugins/editing/tabout.lua +++ b/lua/plugins/tabout.lua @@ -4,6 +4,7 @@ return { event = "InsertEnter", opts = { -- configuration goes here + tabkey = "", }, }, } diff --git a/lua/util/latex.lua b/lua/util/latex.lua index 553dbfb..3d50bbb 100644 --- a/lua/util/latex.lua +++ b/lua/util/latex.lua @@ -1,5 +1,42 @@ local M = {} +local has_treesitter, ts = pcall(require, "vim.treesitter") +local _, query = pcall(require, "vim.treesitter.query") + +local M = {} + +local function get_node_at_cursor() + local cursor = vim.api.nvim_win_get_cursor(0) + local cursor_range = { cursor[1] - 1, cursor[2] } + local buf = vim.api.nvim_get_current_buf() + local ok, parser = pcall(ts.get_parser, buf, "latex") + if not ok or not parser then + return + end + local root_tree = parser:parse()[1] + local root = root_tree and root_tree:root() + + if not root then + return + end + + return root:named_descendant_for_range( + cursor_range[1], + cursor_range[2], + cursor_range[1], + cursor_range[2] + ) +end + +local MATH_ENVIRONMENTS = { + displaymath = true, + equation = true, + eqnarray = true, + align = true, + math = true, + array = true, +} + local MATH_NODES = { displayed_equation = true, inline_formula = true, @@ -28,62 +65,33 @@ 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 - 1} }) - while node do - if node:type() == "math" then - return true +M.in_mathzone= function() + if has_treesitter then + local buf = vim.api.nvim_get_current_buf() + local node = get_node_at_cursor() + while node do + if MATH_NODES[node:type()] then + return true + elseif node:type() == "math_environment" or node:type() == "generic_environment" then + local begin = node:child(0) + local names = begin and begin:field("name") + if names and names[1] and MATH_ENVIRONMENTS[query.get_node_text(names[1], buf):match("[A-Za-z]+")] then + return true + end + end + node = node:parent() 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 - 1} }) - 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 M.in_mathzone_tex() - elseif ft == "markdown" then - return M.in_mathzone_md() - elseif ft == "typst" then - return M.in_mathzone_typ() + return false end end M.in_text = function() return not M.in_mathzone() end +M.in_text_md = function() + return not M.in_mathzone() +end M.in_item = function() return M.in_env("itemize") or M.in_env("enumerate") @@ -97,39 +105,5 @@ end M.in_tikz = function() return M.in_env("tikzpicture") end -M.in_quantikz = function() - return M.in_env("quantikz") -end -M.in_algo = function() - return M.in_env("algorithmic") -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" } --- for _, file_type in ipairs(file_types) do --- local command = "rm " .. current_dir .. "/*." .. file_type --- vim.api.nvim_call_function("system", { command }) --- end --- end --- --- M.format = function() --- local current_file = vim.fn.expand("%:p") --- local latexindent = "latexindent -g /dev/null " .. current_file .. " -wd -l ~/Documents/Latex/latexindent.yaml" --- local build = "pdflatex " .. current_file --- vim.api.nvim_call_function("system", { build }) --- vim.cmd("w") --- M.clean() --- vim.api.nvim_call_function("system", { latexindent }) --- vim.cmd("e") --- vim.cmd("normal! zz") --- -- vim.cmd("TexlabForward") --- end --- --- M.sympy_calc = function() --- local selected_text = vim.fn.getreg("v") --- print(selected_text) --- vim.api.nvim_out_write(selected_text) --- end return M