Closed sucrecacao closed 2 years ago
This is the expected behaviour, see :doc command-parsing balanced-strings
@mawww
Sorry for the previous verbose example, but to be sure do you mean that:
define-command test %{
# {
echo foo
}
raising an exception ( and not to being able to run :test<ret>
) is normal behavior?
This is expected yes. Balanced strings count occurrences of the delimiters, and the string ends on the first closing delimiter that does not have a matching opening.
If a balanced string must contain unbalanced occurrences of the delimiters, you have two options:
evaluate-commands %< echo { >
evaluate-command %{
echo {
# comment containing }
}
The advantage of doing this is that it is easy to nest such strings without resorting to multi-level escaping (sometimes known as backslash hell). Such nesting is very common when writing kakoune scripts, for example see here. Multiple %{..}
strings are nested, and it just works thanks to the counting of braces. If '..'
strings were used instead, the inner set-register
call would have to use 4 consecutive '
.
Balanced strings are not suited when their content is arbitrary input, normal '..'
strings should be used in that case (and their content escaped if it may contain '
).
To add up to @occivink’s explanation, Kakoune block strings should not be confused with blocks in programming languages: they are simply strings banged together, until they are being evaluated.
So for example, when you execute:
evaluate-commands %(echo %(foo))
the string passed to evaluate-commands
is literally:
echo %(foo)
until the command evaluates it.
Version of Kakoune
Kakoune v2020.09.01-806-ga70dbda5
Reproducer
In you autoload folder, paste the following code in a file called
remember_filetype.kak
( it's a macro to easily create filetype hook )
Save the file and open a new kak instance
Outcome
get the following error in my debug buffer:
Expectations
kakoune loads
remember_filetype.kak
normallyAdditional information
If I remove the comment on line 8 I don't get the error, so I guess the error comes from the extra
{
in line 8