From 2d78b0760d2d755321dbc3321cb2e47d5d08c90f Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 16 Sep 2020 12:10:05 +0300 Subject: [PATCH] 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. --- rc/detection/modeline.kak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rc/detection/modeline.kak b/rc/detection/modeline.kak index 516080db..dc092a1c 100644 --- a/rc/detection/modeline.kak +++ b/rc/detection/modeline.kak @@ -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 "s(?S)\A(.+\n){,%opt{modelines}}|(.+\n){,%opt{modelines}}\z" \ - s^\S*?\s+?(vim?|kak(oune)?):\s?[^\n]+ + s^\S*?\s+?\w+:\s?[^\n]+ evaluate-commands -draft -itersel modeline-parse-impl } } }