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

Expand a snippet inside another #63

Open
tiagoprn opened this issue May 25, 2022 · 4 comments
Open

Expand a snippet inside another #63

tiagoprn opened this issue May 25, 2022 · 4 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@tiagoprn
Copy link

Is it possible to expand a snippet inside another? E.g.:

snippet qtimestamp
	`strftime("%Y-%m-%dT%H:%M:%S")`-03:00

snippet qheader
	---
	created: qtimestamp
	modified: qtimestamp
	type: Journal
	---

On the example above, on the snippet "qheader", I would like to automatically expand the qtimestamp snippet on the "created" and "modified" fields.

@dcampos
Copy link
Owner

dcampos commented May 26, 2022

Hi. That kind of reference to another snippet from a snippet's body isn't possible, though I agree it would be handy sometimes. I'm not aware of any snippet engine that supports it.

@dcampos dcampos added enhancement New feature or request question Further information is requested labels May 26, 2022
@tiagoprn
Copy link
Author

The snippets engine I used before, vim-vsnip, supports that: https://github.com/hrsh7th/vim-vsnip#features - it calls that feature "nested snippet expansion".

As a user I think that feature is awesome, but as a developer I have a feeling this may be not trivial to implement. 😅

Nice to see you tagged this as an enhancement, I would be happy to test it if you decide to work on that, just mention me on this issue.

BTW, congrats for your work here! 🚀 I prefer your plugin because your snippets are much, much more cleaner than VSCode's style ones with all that JSON. 😎

@dcampos
Copy link
Owner

dcampos commented May 27, 2022

The snippets engine I used before, vim-vsnip, supports that: https://github.com/hrsh7th/vim-vsnip#features - it calls that feature "nested snippet expansion".

Interesting. I thought the "nested snippet expansion" referred to expanding a snippet from inside an already expanded snippet, which is also possible with Snippy—that is, you expand a snippet, type the trigger for another snippet, and expand it.

Does it mean Vsnip allows to automatically expand a snippet? Can you give an example?

@tiagoprn
Copy link
Author

I guess at least for VS-Code style snippets, it does.

I had mine on that format before. Using the same example as the one I opened this issue with, when I triggered the qheader snippet, it already expanded the qtimestamp one. That got me impressed, and I started relying on that funcionality (maybe too much? 🤣)

But I did not try it at the time with the snippets on the same format as snippy and vsnip support. So maybe that is particular to VSCode's JSON format? (which I do not intend to use due to parsing the JSON being much more prone to errors).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants