Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guidance to set triggers #4

Closed
carlitux opened this issue Apr 3, 2021 · 4 comments
Closed

Guidance to set triggers #4

carlitux opened this issue Apr 3, 2021 · 4 comments

Comments

@carlitux
Copy link
Contributor

carlitux commented Apr 3, 2021

If I have this

  ls.parser.parse_snippet(
    {
      trig = "te",
      name = "ternary",
      dscr = ""
    },
    "${1:cond} ? ${2:true} : ${3:false}"
  ),

  ls.parser.parse_snippet(
    {
      trig = "e",
      name = "module export",
      dscr = ""
    },
    "export ${1:member}"
  ),

and I have editing

te|

must expand to |cond ? true : false but was expanded as texport |member

where | is the cursor

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Apr 3, 2021

By default Luasnip just matches all snippet-triggers to the cursor position and expands whichever snippet matches first, disregarding word boundaries.
It's possible to only have snippets expand when they match the entire word before the cursor (conditional expansion, take a look at this snippet, you'd of course have to write a different function that checks if the word before the cursor matches the trigger), but not yet when parsing snippets.
As this is pretty common, I think I'll add some way to have parsed snippets behave that way aswell

@carlitux
Copy link
Contributor Author

carlitux commented Apr 3, 2021

Maybe add a key at the first argument that accepts out-the-box functions or a custom one? into the parser function

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Apr 3, 2021

Yeah, that's the most comfortable way I think.

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Apr 3, 2021

Alright, you can now set 'wordTrig' to only have snippets expand if the entire word matches, example here.

@L3MON4D3 L3MON4D3 closed this as completed Apr 7, 2021
danilshvalov added a commit to danilshvalov/LuaSnip that referenced this issue Sep 20, 2022
# This is the 1st commit message:

fix(snipmate): correctly escape backtick

# This is the commit message L3MON4D3#2:

test(parser): add backtick escape tests

# This is the commit message L3MON4D3#3:

fix(snipmate): replace escaped backtick in body

# This is the commit message L3MON4D3#4:

Auto generate docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants