diff options
| author | ottjk <joshott16@gmail.com> | 2023-12-30 19:23:04 -0500 |
|---|---|---|
| committer | ottjk <joshott16@gmail.com> | 2023-12-30 19:23:04 -0500 |
| commit | ed46f1c5e82709417085b1a3b7708b209c5f4bfe (patch) | |
| tree | d7eb3f2b4b00e75e5f10199e1cbff959c355b312 /nvim/lua/luasnip-helpers.lua | |
| download | dotfiles-ed46f1c5e82709417085b1a3b7708b209c5f4bfe.tar.gz dotfiles-ed46f1c5e82709417085b1a3b7708b209c5f4bfe.zip | |
initial commit
Diffstat (limited to 'nvim/lua/luasnip-helpers.lua')
| -rw-r--r-- | nvim/lua/luasnip-helpers.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/nvim/lua/luasnip-helpers.lua b/nvim/lua/luasnip-helpers.lua new file mode 100644 index 0000000..e912046 --- /dev/null +++ b/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 |