From 647e568d3b24936fae20af245b283755a712d62a Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 16 Aug 2022 19:14:05 +0200 Subject: [PATCH] rc kakrc: add kak=kakrc highlighter alias for markdown/restructuredtext Filetypes markdown and restructuredtext reuse highlighters from other filetypes to highlight code blocks. For example, to highlight a code block of language foo they essentially do require-module foo add-highlighter [...] ref foo This works great if the module name matches the shared highlighter. This is the case almost all scripts in rc/filetype*. The only exception is kakrc.kak: the highlighter is named "kakrc" (just like the filetype) but the module is named "kak". This requires weird hacks in markdown/restructuredtext. Ideally we could remove this inconsistency by renaming both the filetype and the highlighter to "kak" but that's a breaking change. Until we do that, let's add an alias so we can treat filetypes uniformly. This helps the following commits, which otherwise would need to add ugly extra code for kakrc highlighters. The following commit will generalize this approach, allowing users to add arbitrary aliases. --- rc/filetype/kakrc.kak | 2 ++ rc/filetype/markdown.kak | 5 ++--- rc/filetype/restructuredtext.kak | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rc/filetype/kakrc.kak b/rc/filetype/kakrc.kak index 65ef2bdc..32080b6e 100644 --- a/rc/filetype/kakrc.kak +++ b/rc/filetype/kakrc.kak @@ -90,6 +90,8 @@ add-highlighter shared/kakrc/double_string/escape regex '""' 0:default+b add-highlighter shared/kakrc/single_string/fill fill string add-highlighter shared/kakrc/single_string/escape regex "''" 0:default+b +add-highlighter shared/kak ref kakrc + # Commands # ‾‾‾‾‾‾‾‾ diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak index 599dfd5d..abd73481 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -54,13 +54,12 @@ 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}" - printf 'add-highlighter shared/markdown/%s/inner region \A\h*```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${ref}" + printf 'add-highlighter shared/markdown/%s/inner region \A\h*```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${lang}" 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}" + printf 'add-highlighter shared/markdown/listblock/%s/inner region \A\h*```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${lang}" done } diff --git a/rc/filetype/restructuredtext.kak b/rc/filetype/restructuredtext.kak index b1a69806..90c61f40 100644 --- a/rc/filetype/restructuredtext.kak +++ b/rc/filetype/restructuredtext.kak @@ -32,8 +32,7 @@ evaluate-commands %sh{ julia kak kickstart latex lisp lua makefile moon objc \ 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*code-block::\h*$ft\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)' "$ft" done }