From b633b6f9c3f83a35a1ab595dfabaecb5847a7b56 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 13 Aug 2022 22:32:36 +0200 Subject: [PATCH 1/4] rc restructuredtext: fix code block regex Commit 9ea6b88c1 (Fix remaining kak scripts to use the new highlighter syntax, 2018-07-01) changed the regex that detects HTML code blocks from \.\.\h*code::\h*html\h*\n to \.\.\h*html::\h*c\h*\n the stray c looks wrong. According to https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#showing-code-examples a code block looks like .. code-block:: html Some HTML code. Correct the regex accordingly. The original version used "code" instead of "cod- block". That was incorrect because "code" requires a different syntax (no "..") and creates inline code blocks (for which we could add highlighting later), see https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-code --- rc/filetype/restructuredtext.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/restructuredtext.kak b/rc/filetype/restructuredtext.kak index 434525a5..b1a69806 100644 --- a/rc/filetype/restructuredtext.kak +++ b/rc/filetype/restructuredtext.kak @@ -33,7 +33,7 @@ evaluate-commands %sh{ perl pug python ragel ruby rust sass scala scss sh swift \ tupfile yaml; do if [ "$ft" = kak ]; then ref="kakrc"; else ref="$ft"; fi - printf 'add-highlighter shared/restructuredtext/%s region %s %s ref %s\n' "$ft" '\.\.\h*'$ft'::\h*c\h*\n' '^(?=\S)' "$ref" + printf 'add-highlighter shared/restructuredtext/%s region %s %s ref %s\n' "$ft" "\.\.\h*code-block::\h*$ft\h*\n" '^(?=\S)' "$ref" done } From 9d362b8b3e9be6c89ce880144167f8b2f9ab70c1 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 16 Aug 2022 19:06:13 +0200 Subject: [PATCH 2/4] rc markdown: fix loading language highlighter module given multiple code blocks After opening a markdown file ```b ``` ```c int main() {} ``` markdown-load-languages will run an "evaluate-commands -itersel". The first selection makes us run "require-module b", which fails because that module can't be found. Since -itersel only ignores the "no selection remaining" error we fail to run "require-module c". Fix this by ignoring errors. --- rc/filetype/markdown.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak index 3aaf1c45..d6d95b14 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -124,7 +124,7 @@ define-command -hidden markdown-indent-on-new-line %{ define-command -hidden markdown-load-languages %{ evaluate-commands -draft %{ try %{ execute-keys 'gtGbGls```\h*\{?[.=]?\K[^}\s]+' - evaluate-commands -itersel %{ require-module %val{selection} } + evaluate-commands -itersel %{ try %{ require-module %val{selection} } } }} } From 615ec3ef7e741d29aa8fe1b2c5a55181b44b4587 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 16 Aug 2022 19:12:06 +0200 Subject: [PATCH 3/4] rc markdown: use language highlighting also for indented code blocks --- rc/filetype/markdown.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak index d6d95b14..3db7ca1d 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -52,7 +52,7 @@ evaluate-commands %sh{ printf 'add-highlighter shared/markdown/%s region -match-capture ^(\h*)```\h*(%s\\b|\\{[.=]?%s\\}) ^(\h*)``` regions\n' "${lang}" "${lang}" "${lang}" printf 'add-highlighter shared/markdown/%s/ default-region fill meta\n' "${lang}" [ "${lang}" = kak ] && ref=kakrc || ref="${lang}" - printf 'add-highlighter shared/markdown/%s/inner region \A```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${ref}" + printf 'add-highlighter shared/markdown/%s/inner region \A\h*```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${ref}" done } From feb912fb9f2e706b88c8b93bc2d9229a768d249d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 16 Aug 2022 19:44:08 +0200 Subject: [PATCH 4/4] rc markdown: use language highlighting also for indented code blocks inside lists --- rc/filetype/markdown.kak | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak index 3db7ca1d..599dfd5d 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -41,6 +41,11 @@ add-highlighter shared/markdown regions add-highlighter shared/markdown/inline default-region regions add-highlighter shared/markdown/inline/text default-region group +add-highlighter shared/markdown/listblock region ^\h*[-*]\s ^(?=\S) regions +add-highlighter shared/markdown/listblock/g default-region group +add-highlighter shared/markdown/listblock/g/ ref markdown/inline +add-highlighter shared/markdown/listblock/g/marker regex ^\h*([-*])\s 1:bullet + evaluate-commands %sh{ languages=" awk c cabal clojure coffee cpp crystal css cucumber d diff dockerfile elixir erlang fish @@ -49,18 +54,16 @@ evaluate-commands %sh{ ruby rust sass scala scss sh swift toml tupfile typescript yaml sql " for lang in ${languages}; do + [ "${lang}" = kak ] && ref=kakrc || ref="${lang}" printf 'add-highlighter shared/markdown/%s region -match-capture ^(\h*)```\h*(%s\\b|\\{[.=]?%s\\}) ^(\h*)``` regions\n' "${lang}" "${lang}" "${lang}" printf 'add-highlighter shared/markdown/%s/ default-region fill meta\n' "${lang}" - [ "${lang}" = kak ] && ref=kakrc || ref="${lang}" printf 'add-highlighter shared/markdown/%s/inner region \A\h*```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${ref}" + printf 'add-highlighter shared/markdown/listblock/%s region -match-capture ^(\h*)```\h*(%s\\b|\\{[.=]?%s\\}) ^(\h*)``` regions\n' "${lang}" "${lang}" "${lang}" + printf 'add-highlighter shared/markdown/listblock/%s/ default-region fill meta\n' "${lang}" + printf 'add-highlighter shared/markdown/listblock/%s/inner region \A\h*```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${ref}" done } -add-highlighter shared/markdown/listblock region ^\h*[-*]\s ^(?=\S) regions -add-highlighter shared/markdown/listblock/g default-region group -add-highlighter shared/markdown/listblock/g/ ref markdown/inline -add-highlighter shared/markdown/listblock/g/marker regex ^\h*([-*])\s 1:bullet - add-highlighter shared/markdown/codeblock region -match-capture \ ^(\h*)```\h* \ ^(\h*)```\h*$ \