From 95c095f3fb52a539b0f516a05fb4267f317e0690 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 16 Sep 2020 10:55:36 +0300 Subject: [PATCH 1/2] rc modeline: Don't select more lines than configured This commit addresses an off-by-one error that selected `modelines`+1 lines when looking for modelines in a buffer. Note that setting `modelines` to 0 will still select one line. Fixes #3733. --- rc/detection/modeline.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/detection/modeline.kak b/rc/detection/modeline.kak index 1a343448..00d2fcdc 100644 --- a/rc/detection/modeline.kak +++ b/rc/detection/modeline.kak @@ -96,7 +96,7 @@ define-command -hidden modeline-parse-impl %{ # [text]{white}{vi:|vim:|Vim:|ex:}[white]se[t] {options}:[text] 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\A|.\z %opt{modelines}k %opt{modelines}X \ + execute-keys "s(?S)\A(.+\n){,%opt{modelines}}|(.+\n){,%opt{modelines}}\z" \ s^\S*?\s+?(vim?|kak(oune)?):\s?[^\n]+ evaluate-commands -draft -itersel modeline-parse-impl } } From 643bf2bb59779d0fb54ff40e6c02f5509ee07932 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 16 Sep 2020 10:59:12 +0300 Subject: [PATCH 2/2] test: Implement a regression test for #3733 --- test/regression/3733-modeline-parsing-off-by-one-line/cmd | 3 +++ test/regression/3733-modeline-parsing-off-by-one-line/in | 7 +++++++ test/regression/3733-modeline-parsing-off-by-one-line/out | 1 + test/regression/3733-modeline-parsing-off-by-one-line/rc | 2 ++ 4 files changed, 13 insertions(+) create mode 100644 test/regression/3733-modeline-parsing-off-by-one-line/cmd create mode 100644 test/regression/3733-modeline-parsing-off-by-one-line/in create mode 100644 test/regression/3733-modeline-parsing-off-by-one-line/out create mode 100644 test/regression/3733-modeline-parsing-off-by-one-line/rc diff --git a/test/regression/3733-modeline-parsing-off-by-one-line/cmd b/test/regression/3733-modeline-parsing-off-by-one-line/cmd new file mode 100644 index 00000000..344c7543 --- /dev/null +++ b/test/regression/3733-modeline-parsing-off-by-one-line/cmd @@ -0,0 +1,3 @@ +:modeline-parse +% +:exec c %opt{tabstop} diff --git a/test/regression/3733-modeline-parsing-off-by-one-line/in b/test/regression/3733-modeline-parsing-off-by-one-line/in new file mode 100644 index 00000000..58f3ec24 --- /dev/null +++ b/test/regression/3733-modeline-parsing-off-by-one-line/in @@ -0,0 +1,7 @@ +# kak:tabstop=1: +# kak:tabstop=2: +# kak:tabstop=3: +foo +foo +foo +foo diff --git a/test/regression/3733-modeline-parsing-off-by-one-line/out b/test/regression/3733-modeline-parsing-off-by-one-line/out new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/test/regression/3733-modeline-parsing-off-by-one-line/out @@ -0,0 +1 @@ +1 diff --git a/test/regression/3733-modeline-parsing-off-by-one-line/rc b/test/regression/3733-modeline-parsing-off-by-one-line/rc new file mode 100644 index 00000000..98e55e02 --- /dev/null +++ b/test/regression/3733-modeline-parsing-off-by-one-line/rc @@ -0,0 +1,2 @@ +source "%val{runtime}/rc/detection/modeline.kak" +set-option global modelines 1