occivink / kakoune-snippets

Snippet support for kakoune
The Unlicense
46 stars 6 forks source link

Doc is not clear on how to define snippets other than in snippets-add-snippet #40

Closed augustebaum closed 4 years ago

augustebaum commented 4 years ago

Hi, I'm new to snippets (and to Kakoune) and loving it. Until now I've been using the snippets-directory extension, but I'd rather just have all my snippets for a given language written in one file (whose name could be interpreted as a regex like when using snippets-directory).

The thing is I simply can't figure out how to add a new snippet other than using the add-snippets command (which creates a file) or manually adding a file myself. Based on syntax that I saw written in other issues, I added this to my kakrc: hook global WinSetOption filetype=latex %{ set -add buffer snippets "hello" "\h" %{snippets-insert %{\hello{$1} $0}} }

But this only expands when I write "\h " and when it does it doesn't remove the "\h", the result is "\h\hello{}". Yet most (not all) of the snippets I added as a file using a directory work as expected (it's really nice!).

Is there something I'm not getting here? Sorry if this is a stupid question. Ideally I'd rather have all my snippets in one place. Thanks in advance.

occivink commented 4 years ago

The commands you're running look about right, and they seem to work on my end. However, be careful that the trigger (\h here) is a regex, and \h happen to be the regex escape for any horizontal whitespace. You might want to use \\h instead. To debug any difference between manually setting the option and using snippets-directory.kak I recommend simply running echo -debug %opt{snippets} and looking for any difference in the value, since this is all that snippets-directory does.

augustebaum commented 4 years ago

Ooh I was unaware of that regex escape! Thanks very much, I'll try all that. I guess this is no longer an issue.