nvim-config

Log | Files | Refs | Submodules | README

commit af8757bb448acd4929954ab34e3bad1d71780ca9
parent 7158252171f4e3e995956112ac6d093704ea0e6c
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date:   Sat, 13 May 2023 08:57:17 +0200

feat: update latex keys and tools

Diffstat:
Mafter/ftplugin/tex.lua | 16+++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/after/ftplugin/tex.lua b/after/ftplugin/tex.lua @@ -18,16 +18,20 @@ local ts_utils = require 'nvim-treesitter.ts_utils' local p = require 'nvim-treesitter.parsers' -- Replace the surrounding environment -local query = vim.treesitter.parse_query("latex", [[ +local query = vim.treesitter.query.parse("latex", [[ (generic_environment (begin (curly_group_text text: (_) @envbegin)) (end (curly_group_text text: (_) @envend))) + + (math_environment + (begin (curly_group_text text: (_) @envbegin)) + (end (curly_group_text text: (_) @envend))) ]]) vim.keymap.set('n', '<LocalLeader>re', function() local curbuf = vim.api.nvim_get_current_buf() local curnode = ts_utils.get_node_at_cursor() - while curnode and curnode:type() ~= "generic_environment" do + while curnode and curnode:type() ~= "generic_environment" and curnode:type() ~= "math_environment" do curnode = curnode:parent() end @@ -36,7 +40,7 @@ vim.keymap.set('n', '<LocalLeader>re', function() local start_row, _, end_row, _ = curnode:range() vim.ui.input({ prompt = "Replacement" }, function(replacement) if replacement then - edit.edit(curbuf, p.get_parser(curbuf), query, { replacement, replacement }, start_row, end_row) + edit.edit(curbuf, p.get_parser(curbuf), query, { envbegin = replacement, envend = replacement }, start_row, end_row) end end) end, { buffer = true }) @@ -79,7 +83,8 @@ local function correct_position_wrap(ty, spos, epos, func) func(ty, curbuf, start_line, start_col, end_line, end_col, text, vim.fn['repeat'](' ', indent)) end -TexDispatch = function() end +TexDispatch = function() +end local function vis_mapping(map, func) -- First handle the visual mapping @@ -100,7 +105,6 @@ local function vis_mapping(map, func) -- Then create the operator mapping vim.keymap.set('n', map, function() - -- Ensure that the operator func is this correct one local tmpopf = vim.o.operatorfunc vim.o.operatorfunc = 'v:lua.TexDispatch' @@ -133,7 +137,6 @@ end local function preffix_suffix_change(func) return function(type, text, input, indent) - local preffix, suffix = func(input) if type == 'char' then @@ -176,4 +179,3 @@ end)) vis_input_change('<LocalLeader>e', 'Environment name', preffix_suffix_change(function(input) return string.format('\\begin{%s}', input), string.format('\\end{%s}', input) end)) -