From a290afdd82a4136e6ab918efaf7141f3f9ef8bf4 Mon Sep 17 00:00:00 2001 From: Thore Strassburg Date: Wed, 14 Sep 2022 08:35:40 +0200 Subject: [PATCH 1/2] feat: add new built-in condition for line ending --- Examples/snippets.lua | 5 +++++ lua/luasnip/extras/expand_conditions.lua | 5 +++++ 2 files changed, 10 insertions(+) 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/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 From 7117f5ee7406f279a143c9258dd0173757ba5a5b Mon Sep 17 00:00:00 2001 From: weilbith Date: Wed, 14 Sep 2022 06:59:06 +0000 Subject: [PATCH 2/2] Auto generate docs --- doc/luasnip.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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*