Closed salkin-mada closed 3 years ago
This is because Lua's multi-line strings retain the leading spaces, to do what you want you have to do:
local U = require'snippets.utils'
require'snippets'.snippets = {
lua = {
["for"] = U.match_indentation [[
for ${1:i}, ${2:v} in ipairs(${3:t}) do
$0
end]];
};
}
to ensure there are no spaces before the snippet's text.
I personally don't like this way of writing multiline snippets, it would be nice to have a wrapper that removes the leading spaces, so your initial code would work (with that wrapper)
thanks @bew . I see. I thought match_indentation
did two things.
indeed a leading space removal wrapper would be nice to have.
I also write my multiline snippets like this for = "for ${1:i}, ${2:v} in ipairs(${3:t}) do\n\t$0\nend";
at the moment due to the leading space lua multi-line string "issue". And using \t
and \n
feels very much like home. Spend many hours with strings and println
/ postln
in different langs . But for multi-line snippets i would actually really love to be able to write them like so:
lua = {
["for"] = U.match_indentation [[
for ${1:i}, ${2:v} in ipairs(${3:t}) do
$0
end]];
};
keeping the indentation of the snippet def file makes it more readable. Especially when there is alot of automatic generated snippets from class trees.
Thanks for a nice snippet plugin! I use it every day in
lua
and especially on dynamic languages likesupercollider
. Its really fantastic for wrapping registers in other code etc.but. I cant get
match_indentation
to work with the following type of snippet.this always results in a lua for loop placed with the same amount of tabs/spaces that was present in the snippet file where it was defined. hope this makes sense :)
Am I doing something wrong or misunderstanding the use of
require'snippets.utils'.match_indentation
or is it broken?