diff options
| author | joott <josh@ottmail.me> | 2025-07-30 15:53:29 -0400 |
|---|---|---|
| committer | joott <josh@ottmail.me> | 2025-07-30 15:53:29 -0400 |
| commit | 26694e09e8f5bf2262737312e7ad217118db20de (patch) | |
| tree | ca55eee2f8c5106c61e747979780d6f393fd24c9 /.config/nvim/lua/luasnip-helpers.lua | |
| parent | 89a596a50ec61b8ebd6040b06a7cab994afd1b3a (diff) | |
| download | dotfiles-26694e09e8f5bf2262737312e7ad217118db20de.tar.gz dotfiles-26694e09e8f5bf2262737312e7ad217118db20de.zip | |
switching to yadm
Diffstat (limited to '.config/nvim/lua/luasnip-helpers.lua')
| -rw-r--r-- | .config/nvim/lua/luasnip-helpers.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/.config/nvim/lua/luasnip-helpers.lua b/.config/nvim/lua/luasnip-helpers.lua new file mode 100644 index 0000000..e912046 --- /dev/null +++ b/.config/nvim/lua/luasnip-helpers.lua @@ -0,0 +1,41 @@ +local n = require("luasnip-nodes") +local utils = {} + +utils.get_visual = function(args, parent) + if (#parent.snippet.env.LS_SELECT_RAW > 0) then + return n.sn(nil, n.i(1, parent.snippet.env.LS_SELECT_RAW)) + else -- If LS_SELECT_RAW is empty, return a blank insert node + return n.sn(nil, n.i(1)) + end +end + +utils.in_mathzone = function() -- math context detection + return vim.fn['vimtex#syntax#in_mathzone']() == 1 +end +utils.in_text = function() + return not utils.in_mathzone() +end +utils.in_comment = function() -- comment detection + return vim.fn['vimtex#syntax#in_comment']() == 1 +end +utils.in_env = function(name) -- generic environment detection + local is_inside = vim.fn['vimtex#env#is_inside'](name) + return (is_inside[1] > 0 and is_inside[2] > 0) +end +-- A few concrete environments---adapt as needed +utils.in_equation = function() -- equation environment detection + return utils.in_env('equation') +end +utils.in_itemize = function() -- itemize environment detection + return utils.in_env('itemize') +end +utils.in_enumerate = function() -- itemize environment detection + return utils.in_env('enumerate') +end +utils.in_tikz = function() -- TikZ picture environment detection + return utils.in_env('tikzpicture') +end + +utils.line_begin = require("luasnip.extras.expand_conditions").line_begin + +return utils |