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

Support placeholder expansion inside of eval #145

Open
thalesmello opened this issue Dec 27, 2024 · 1 comment
Open

Support placeholder expansion inside of eval #145

thalesmello opened this issue Dec 27, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@thalesmello
Copy link

Problem Statement

Some configs snippet expansions I want to do would require expanding the placeholder inside of the eval expression. Would be possible to support that as a feature?

An example of what I'm trying to accomplish, basically to break the line automatically if I hit enter in the $2 placeholder.

snippet f "Anonymous function" i
    function (${1})${2: }$3 `!lua "$2" == "\n" and "\n" or ""`end${0}

Ideas or possible solutions

I think it could maybe be solved by expanding $2 inside the string of the enclosed eval expression, but that would require re-evaluating the eval expression each time the placeholders are updated.

Alternatives you have considered

Alternatively, this could be exposed as a function call:

snippet f "Anonymous function" i
    function (${1})${2: }$3 `!lua require("snippy").expand("$2") == "\n" and "\n" or ""`end${0}
@thalesmello thalesmello added the enhancement New feature or request label Dec 27, 2024
@dcampos
Copy link
Owner

dcampos commented Jan 6, 2025

Looks like an interesting feature to add. Because Snippy uses luaeval() to handle Lua code, we could rely on the "magic" bult-in global _A, that works like this:

luaeval('_A[1] + _A[2]', [40, 2])

So we could have:

snippet f "Anonymous function" i
    function (${1})${2: }$3 `!lua _A[2] == "\n" and "\n" or ""`end${0}

Or something like that.

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

No branches or pull requests

2 participants