rc modeline: Error out on unsupported formats

This commit makes `:modeline-parse` grab all lines that look like
modelines, and lets the parser deal with invalid formats.

This allows actually printing an error on unsupported modelines
formats, instead of ignoring them upfront.
This commit is contained in:
Frank LENORMAND 2020-09-16 12:10:05 +03:00
parent 30ee97386d
commit 2d78b0760d

View File

@ -65,7 +65,7 @@ define-command -hidden modeline-parse-impl %{
case "${kak_selection}" in
*vi:*|*vim:*) type_selection="vim";;
*kak:*|*kakoune:*) type_selection="kakoune";;
*) printf 'echo -debug Unsupported modeline format' \
*) printf 'echo -debug %s' "$(kakquote "Unsupported modeline format: ${kak_selection}")" \
| kak -p "${kak_session}"; exit 1 ;;
esac
@ -109,7 +109,7 @@ define-command -hidden modeline-parse-impl %{
define-command modeline-parse -docstring "Read and interpret vi-format modelines at the beginning/end of the buffer" %{
try %{ evaluate-commands -draft %{
execute-keys <percent> "s(?S)\A(.+\n){,%opt{modelines}}|(.+\n){,%opt{modelines}}\z<ret>" \
s^\S*?\s+?(vim?|kak(oune)?):\s?[^\n]+<ret> <a-x>
s^\S*?\s+?\w+:\s?[^\n]+<ret> <a-x>
evaluate-commands -draft -itersel modeline-parse-impl
} }
}