Closed andreyorst closed 5 years ago
I merged the two options as I was hinting at, it now follows this pattern:
snippet-name
snippet-trigger
snippet-command
...
I've only been testing the happy path where the option is well-formed so there are probably some bugs if it's not, but I cannot reproduce this one.
Is the option already set to something when you do this?
Note that I also pushed a fix for another issue, but it doesn't look like the same.
Is the option already set to something when you do this?
No, it is empty. Maybe it is somehow related to Perl? My Perl is v5.28.1.
I merged the two options as I was hinting at, it now follows this pattern:
snippet-name
snippet-trigger
snippet-command
...
It would be great if somewhere in the repo were an up to date example of proper snippet definition.
I've updated my snippet definitions to what you've described:
hook global WinSetOption filetype=(c|cpp) %{
unset-option window snippets
set-option -add window snippets 'For loop' 'for' %{
snippets-insert 'for (int ${1:i}; $1 < $2; $1++) {
${indent}$0
}'
}
set-option -add window snippets 'Main function' 'main' %{
snippets-insert %{int main() {
${indent}$0
}}
}
}
hook global WinSetOption filetype=(rust) %{
unset-option window snippets
set-option -add window snippets 'Main function' 'main' %{
snippets-insert 'fn main() {
${indent}$0
}'
}
}
And now it works. However the issue still persists.
This particular setup seems to work on my side, is this with 35b3371ce8b5937ce1ebb616cd03b08c826c287d? I've also got the same perl version.
It would be great if somewhere in the repo were an up to date example of proper snippet definition.
Yeah that's a good idea
I've updated Kakoune, and your plugin, and executing :set-option -add window snippets 'trigger' 'snippet'
still hangs my editor. I understand that there must be 3 parameters, but error handling should deal with it.
The problem is here: https://github.com/occivink/kakoune-snippets/blob/3edfca8fa44c22d52f37f6e14a66b67203f83c1a/snippets.kak#L14 but I don't see the proper way to ensure that user provided all three args. Maybe use a function that will require three parameters to add snippet? It could replace snippet insert too.
Something like:
snippets-add 'hint' 'trigger' snippet'
This also could be used by other plugins to dynamically add snippets.
Oh I can reproduce it now, it only occurs with bash
as the shell, somehow not with dash
Note that I heavily recommend using dash with kakoune (consider using KAKOUNE_POSIX_SHELL
if you don't want to modify /bin/sh
) especially if you're on linux, the performance gains are substantial (and essentially free).
I'm using dash on part of my devices, but I also use bash because I want to ensure that my plug.kak and fzf.kak work fine on both shells.
One thing that surprises me is that this
snippets-insert 'if ($1) {
${indent}$2
} else {
${indent}$0
}'
works nicely regarding indentation. With how I implemented it, I would expect this:
if ($1) {
${indent}$2
} else {
${indent}$0
}
to be inserted.
edit: nevermind, I implemented that it copies the indentation from the first lines to the others so it's actually working as intended.
It seems that I can't find any info about KAKOUNE_POSIX_SHELL
Is it a shell variable that I can set in my shellrc?
It's an environment variable that was added somewhat recently (see the closing commit), it's not really advertised since it can break things if you don't use a posix shell.
simply executing of
:set-option -add window snippets 'trigger' 'snippet'
results in endless waiting for shell to finish.*debug*
buffer shows insanely huge log: