occivink / kakoune-snippets

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

Whitespace at beginning of line #13

Closed JJK96 closed 5 years ago

JJK96 commented 5 years ago

I have the following snippets

    set -add buffer snippets \
    "comment" "/*" %{snippets-insert %{/*
 * $1
 */}}

I would like to have the whilespace before the * characters to persist into the snippets, currently it seems to be removed

occivink commented 5 years ago

It's this line that is responsible for the alignment: https://github.com/occivink/kakoune-snippets/blob/master/snippets.kak#L154 You can change it to exec -itersel -draft '<a-s><a-;>1&' and it will work for this case, but it might have undesirable consequences on other multi-line snippets, I need to think about it

andreyorst commented 5 years ago

Maybe introduce ${space} placeholder, that will be much like ${indent}? Though if #6 will be implemented, I believe that ${indent} will not be needed anymore, and so will ${space}

occivink commented 5 years ago

I don't think snippet files will solve the indentation problem, we inherently need something dynamic so that you don't have to match your snippet definition with your preferred indentwidth. One thing that we could say is that instead of using ${indent}, leading tabs are automatically converted to match indentwidth. Thoughts on this?

Btw the undesirable consequence I was mentioning is for example your ability to do

set -add snippets 'For-loop' 'for' %{for (int $1 = 0; $1 < $2; ++$1) {
                                     ${indent}$3
                                     }}

as that will be interested like that in the buffer:

for (int $1 = 0; $1 < $2; ++$1) {
                                     ${indent}$3
                                     }

However, that particular problem should be solved by snippet files so I'm inclined to go with the change I mentioned earlier.

JJK96 commented 5 years ago

leading tabs are automatically converted to match indentwidth. Thoughts on this?

I think this is a nice solution, then the snippet more closely corresponds to the result upon expanding. One problem for me would be that I would need to insert a literal tab, currently my tabs are automatically converted to spaces. This wouldn't be a big problem however.

andreyorst commented 5 years ago

What if language determines that it should be indented with spaces? Should snippet definition contain tabs or spaces?

andreyorst commented 5 years ago

One problem for me would be that I would need to insert a literal tab

At the beginning of the line? I think that this is really rare case for snippets.

JJK96 commented 5 years ago

I don't think it is, If you have a snippet that inserts a block, then you usually want indentation. If we do this implementation:

leading tabs are automatically converted to match indentwidth

Then you would need a tab character at the beginning of the line.