diff --git a/Examples/snippets.lua b/Examples/snippets.lua index 02eceea0e..f9077b922 100644 --- a/Examples/snippets.lua +++ b/Examples/snippets.lua @@ -326,6 +326,11 @@ ls.add_snippets("all", { }, { condition = conds.line_begin, }), + s("cond3", { + t("will only expand at the end of the line"), + }, { + condition = conds.line_end, + }), -- The last entry of args passed to the user-function is the surrounding snippet. s( { trig = "a%d", regTrig = true }, diff --git a/doc/luasnip.txt b/doc/luasnip.txt index 62eac0047..6e3f7f8ff 100644 --- a/doc/luasnip.txt +++ b/doc/luasnip.txt @@ -1,4 +1,4 @@ -*luasnip.txt* For NVIM v0.5.0 Last change: 2022 September 08 +*luasnip.txt* For NVIM v0.5.0 Last change: 2022 September 14 ============================================================================== Table of Contents *luasnip-table-of-contents* diff --git a/lua/luasnip/extras/expand_conditions.lua b/lua/luasnip/extras/expand_conditions.lua index a1c012098..52a6101dc 100644 --- a/lua/luasnip/extras/expand_conditions.lua +++ b/lua/luasnip/extras/expand_conditions.lua @@ -5,4 +5,9 @@ function M.line_begin(line_to_cursor, matched_trigger) return line_to_cursor:sub(1, -(#matched_trigger + 1)):match("^%s*$") end +function M.line_end(line_to_cursor) + local line = vim.api.nvim_get_current_line() + return #line_to_cursor == #line +end + return M