about summary refs log tree commit diff stats
path: root/modules/by-name/nv/nvim/plgs/luasnip/snippets/tex/delimiter.lua
blob: bcd128f7e5d8a4b6a81b3764dcfe677cc99d0fbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- nixos-config - My current NixOS configuration
--
-- Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
-- SPDX-License-Identifier: GPL-3.0-or-later
--
-- This file is part of my nixos-config.
--
-- You should have received a copy of the License along with this program.
-- If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.

local ls = require("luasnip")
local fmt = require("luasnip.extras.fmt").fmt

local get_visual = function(_, parent)
  if #parent.snippet.env.SELECT_RAW > 0 then
    return ls.snippet_node(nil, ls.insert_node(1, parent.snippet.env.SELECT_RAW))
  else
    return ls.snippet_node(nil, ls.insert_node(1, ""))
  end
end

local translation_table = { ["("] = ")"; ["{"] = "}"; ["["] = "]"; }

-- Return snippet tables
return {
  -- LEFT/RIGHT ALL BRACES
  ls.snippet(
    {
      trig = "([^%a])l([%(%[%{])";
      regTrig = true;
      wordTrig = false;
      snippetType = "autosnippet";
    },
    fmt("{}\\left{}{}\\right{}", {
      ls.function_node(function(_, snip) return snip.captures[1] end);
      ls.function_node(function(_, snip) return snip.captures[2] end);
      ls.dynamic_node(1, get_visual);
      ls.function_node(function(_, snip) return translation_table[snip.captures[2]] end);
    })
  );
}