Skip to content

Commit

Permalink
BREAKING CHANGE: Default wordTrig to true, not false.
Browse files Browse the repository at this point in the history
Makes sense as setting wordTrig to true is way more common than
setting it to false.
  • Loading branch information
L3MON4D3 committed Jul 23, 2021
1 parent d4ddebd commit 09716b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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, {})
)
Expand Down
10 changes: 5 additions & 5 deletions Examples/snippets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})
Expand Down
5 changes: 4 additions & 1 deletion lua/luasnip/nodes/snippet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 09716b1

Please sign in to comment.