(tangent warning) I have yet to – in any editor – really used snippets because there is always some ergonomic snafu that stops me. Sometimes I wonder if post-fix style snippets would work best…
x > 15
console.log("It sure is greater than 15"); exit
console.log("what a tiny less than 15 number"); continue
highlight 3 lines and do your “if” wrapper.
if (x > 15) {
console.log("It sure is greater than 15")
exit
} else {
console.log("what a tiny less than 15 number")
continue
}
There’s something like this in UltiSnips, called visual placeholder. What it esentially does, is, this:
if ($1) {
${VISUAL}
}
You select text you want to go into VISUAL, and press tab. Text disappears, and when you expand a snippet that has a visual placeholder, this text will be used. This doesn’t work more than one time in a row. And because we have R supporting this seems unreasonable.
But I really like your idea of line-based wrapping into snippet. Reminds me of theorem style programming, where you simply specify stuff on lines.
Yeah, I actually think I am going to make this, because it is something I want a lot, and all I need to do is find sane intra-line delimiter, semi-colon probably isn’t it as that will conflict with lots of languages.
I am trying to decide if this is a in conflict with the idea of objects / verb. The core of that thing is content, the action is wrapping it in some syntax?
Interesting idea, but since the number of statements per line is variable, selections would always be annoying… I think something like using Go and building a context object out of input and using the Go builtin template system would make this both easy and practical.
Postfix completion on the dot . operator then keyword is working well for me as it keeps a continuous workflow / momentum. The pictures below tell the story for your JavaScript. Perhaps a mix with Andrey’s suggestion would get it working snippet<–register<–postfix.
Mate, I had no idea. Thank you for the info.
So here is where I’m at and currently stuck. As my kakoune register skills need improvement.
The sequence of events are:
activate snippet trigger on .keyword
escape to normal mode
extend to previous . inclusive
delete
select to previous word start
save to register
delete selected text
do snippet
paste saved register into first tabstop position
if next tabstop then advance
else advance to end of line
enter insert mode
end sequence
Main.class<esc><a-f>.db"0y
do snippet
<c-r>0 paste saved register into first slot
<tab> advance onto next tab position
where *.class snippets is:
class ${1:Name} {
${0:// body}
}
If I can get one going then I’m off and running to postfix glory . Grateful for any help guys. Bye
I’m thinking that wrapping the snippets function will allow a way to define a subset of snippets as a trigger and or alternate sequence of execute-keys on a subset of those snippets.
this could work, but kakoune-snippets already feature automatic expansion of trigger in insert mode without needing to press anything. Maybe I misunderstood your proposal though.