diff --git a/DOC.md b/DOC.md index a9e3f3e0f..13485c8ea 100644 --- a/DOC.md +++ b/DOC.md @@ -46,7 +46,7 @@ entries: for multiple lines. - `wordTrig`: boolean, if true, the snippet is only expanded if the word (`[%w_]+`) before the cursor matches the trigger entirely. - False by default. + True by default. - `regTrig`: boolean, whether the trigger should be interpreted as a lua pattern. False by default. @@ -150,7 +150,7 @@ Examples: Use captures from the regex-trigger using a functionNode: ```lua - s({trig = "b(%d)", regTrig = true, wordTrig = true}, + s({trig = "b(%d)", regTrig = true}, f(function(args) return "Captured Text: " .. args[1].captures[1] .. "." end, {}) ) diff --git a/Examples/snippets.lua b/Examples/snippets.lua index dce2ddcc9..e3571c5da 100644 --- a/Examples/snippets.lua +++ b/Examples/snippets.lua @@ -187,28 +187,28 @@ ls.snippets = { "Wow! This ${1:Stuff} really ${2:works. ${3:Well, a bit.}}" ), - -- When wordTrig is set, snippets only expand as full words (lte won't expand, te will). + -- When wordTrig is set to false, snippets may also expand inside other words. ls.parser.parse_snippet( - { trig = "te", wordTrig = true }, + { trig = "te", wordTrig = false }, "${1:cond} ? ${2:true} : ${3:false}" ), -- When regTrig is set, trig is treated like a pattern, this snippet will expand after any number. ls.parser.parse_snippet( - { trig = "%d", regTrig = true, wordTrig = true }, + { trig = "%d", regTrig = true }, "A Number!!" ), -- The last entry of args passed to the user-function is the surrounding snippet. s( - { trig = "a%d", regTrig = true, wordTrig = true }, + { trig = "a%d", regTrig = true }, f(function(args) return "Triggered with " .. args[1].trigger .. "." end, {}) ), -- It's possible to use capture-groups inside regex-triggers. s( - { trig = "b(%d)", regTrig = true, wordTrig = true }, + { trig = "b(%d)", regTrig = true }, f(function(args) return "Captured Text: " .. args[1].captures[1] .. "." end, {}) diff --git a/lua/luasnip/nodes/snippet.lua b/lua/luasnip/nodes/snippet.lua index 8e1f370b8..83217e328 100644 --- a/lua/luasnip/nodes/snippet.lua +++ b/lua/luasnip/nodes/snippet.lua @@ -67,6 +67,9 @@ local function S(context, nodes, condition, ...) end end + -- default: true. + if context.wordTrig == nil then context.wordTrig = true end + local snip = Snippet:new({ trigger = context.trig, dscr = dscr, @@ -280,7 +283,7 @@ function Snippet:matches(line) return nil end - -- if wordTrig is set, the char before the trigger has to be \w or the + -- if wordTrig is set, the char before the trigger can't be \w or the -- word has to start at the beginning of the line. if self.wordTrig