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

Handle nested optional placeholders #282

Open
rosshadden opened this issue Aug 10, 2015 · 4 comments
Open

Handle nested optional placeholders #282

rosshadden opened this issue Aug 10, 2015 · 4 comments

Comments

@rosshadden
Copy link

I have a proposal for supporting placeholders nested inside optional placeholders. This may be hard to explain so please bear with me.

Consider the following example snippet (I have a minimal example later on, but this one is practical):

snippet forEach
alias each
regexp '\.'
options word
    forEach((${1:value}${2:#:, ${3:key\}}) => {
        ${4}
    });${0}

The goal of this is that the text , key is optional, but the complication is that the important part of , key is the inner placeholder, key, which should be able to be changed or referenced. Another way of explaining this is that placeholder 3 is optional, but placeholder 2 should be removed if 3 is unchanged.

I think the best way to support this would be to modify what happens on expansion/jump of an optional placeholder. If nothing was changed on expansion, instead of removing the placeholder look to see if there is another placeholder inside it. If you jump away from the inner placeholder without changing, the outer one would be removed. If you change an inner placeholder, both would be kept. If this were the case, my above example would remove the key default text inside 3, as it would no longer make sense (or it could be left for visual reference, but would be removed if unchanged).

The following is a minimal example that my proposal would handle. Hello! would be printed if you jump over 1 and 2, and Hello, world! would be printed if you jump to 1 and 2 to type world.

snippet nest
    Hello${1:#:, ${2\}}!

I realize this sounds complicated, and maybe too complicated to add. I would encourage you to ask me for clarification if my proposal does not make sense. I would also like to mention that this is actually supported with Sublime Text (and therefore TextMate) snippets, in that you could just hit <backspace> on a snippet to delete it and continue to the following placeholders. In neosnippet.vim, however, manually deleting a placeholder screws up the jumping order. Maybe that should be called out as a separate issue.

@Shougo
Copy link
Owner

Shougo commented Aug 12, 2015

Please describe the different from current behaviour.

@rosshadden
Copy link
Author

Right now, jumping over an optional placeholder removes it, no matter what is inside. Thus nested placeholders only do something when the outer placeholder is not optional.

I am proposing that if there is a placeholder within an optional placeholder, the optional one is only removed if the inner placeholders are jumped over as well.

@Shougo
Copy link
Owner

Shougo commented Aug 13, 2015

I don't want to change the behavior.
Because, current implementation is too complex.

@Shougo
Copy link
Owner

Shougo commented Aug 19, 2020

It should be supported in deoppet.nvim.

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

No branches or pull requests

2 participants