Merge remote-tracking branch 'krobelus/generic-language-highlighting'

This commit is contained in:
Maxime Coste 2022-09-15 13:21:25 +02:00
commit 8f7b1df9ab
3 changed files with 48 additions and 40 deletions

View File

@ -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/fill fill string
add-highlighter shared/kakrc/single_string/escape regex "''" 0:default+b add-highlighter shared/kakrc/single_string/escape regex "''" 0:default+b
add-highlighter shared/kak ref kakrc
# Commands # Commands
# ‾‾‾‾‾‾‾‾ # ‾‾‾‾‾‾‾‾

View File

@ -21,8 +21,12 @@ hook global WinSetOption filetype=markdown %{
} }
hook -group markdown-load-languages global WinSetOption filetype=markdown %{ hook -group markdown-load-languages global WinSetOption filetype=markdown %{
hook -group markdown-load-languages window NormalIdle .* markdown-load-languages markdown-load-languages '%'
hook -group markdown-load-languages window InsertIdle .* markdown-load-languages }
hook -group markdown-load-languages global WinSetOption filetype=markdown %{
hook -group markdown-load-languages window NormalIdle .* %{markdown-load-languages gtGbGl}
hook -group markdown-load-languages window InsertIdle .* %{markdown-load-languages gtGbGl}
} }
@ -46,32 +50,16 @@ add-highlighter shared/markdown/listblock/g default-region group
add-highlighter shared/markdown/listblock/g/ ref markdown/inline 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/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
gas go haml haskell html ini java javascript json julia kak kickstart
latex lisp lua makefile markdown moon objc ocaml perl pug python ragel
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/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/codeblock region -match-capture \ add-highlighter shared/markdown/codeblock region -match-capture \
^(\h*)```\h* \ ^(\h*)```\h* \
^(\h*)```\h*$ \ ^(\h*)```\h*$ \
fill meta regions
add-highlighter shared/markdown/codeblock/ default-region fill meta
add-highlighter shared/markdown/listblock/codeblock region -match-capture \ add-highlighter shared/markdown/listblock/codeblock region -match-capture \
^(\h*)```\h* \ ^(\h*)```\h* \
^(\h*)```\h*$ \ ^(\h*)```\h*$ \
fill meta regions
add-highlighter shared/markdown/listblock/codeblock/ default-region fill meta
add-highlighter shared/markdown/codeline region "^( {4}|\t)" "$" fill meta add-highlighter shared/markdown/codeline region "^( {4}|\t)" "$" fill meta
# https://spec.commonmark.org/0.29/#link-destination # https://spec.commonmark.org/0.29/#link-destination
@ -103,6 +91,21 @@ add-highlighter shared/markdown/inline/text/ regex "\H( {2,})$" 1:+r@meta
# Commands # Commands
# ‾‾‾‾‾‾‾‾ # ‾‾‾‾‾‾‾‾
define-command markdown-load-languages -params 1 %{
evaluate-commands -draft %{ try %{
execute-keys "%arg{1}s```\h*\{?[.=]?\K\w+<ret>" # }
evaluate-commands -itersel %{ try %{
require-module %val{selection}
add-highlighter "shared/markdown/codeblock/%val{selection}" region -match-capture "^(\h*)```\h*(%val{selection}\b|\{[.=]?%val{selection}\})" ^(\h*)``` regions
add-highlighter "shared/markdown/codeblock/%val{selection}/" default-region fill meta
add-highlighter "shared/markdown/codeblock/%val{selection}/inner" region \A\h*```[^\n]*\K (?=```) ref %val{selection}
add-highlighter "shared/markdown/listblock/codeblock/%val{selection}" region -match-capture "^(\h*)```\h*(%val{selection}\b|\{[.=]?%val{selection}\})" ^(\h*)``` regions
add-highlighter "shared/markdown/listblock/codeblock/%val{selection}/" default-region fill meta
add-highlighter "shared/markdown/listblock/codeblock/%val{selection}/inner" region \A\h*```[^\n]*\K (?=```) ref %val{selection}
}}
}}
}
define-command -hidden markdown-trim-indent %{ define-command -hidden markdown-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{ evaluate-commands -no-hooks -draft -itersel %{
execute-keys x execute-keys x
@ -124,11 +127,4 @@ define-command -hidden markdown-indent-on-new-line %{
} }
} }
define-command -hidden markdown-load-languages %{
evaluate-commands -draft %{ try %{
execute-keys 'gtGbGls```\h*\{?[.=]?\K[^}\s]+<ret>'
evaluate-commands -itersel %{ try %{ require-module %val{selection} } }
}}
}
} }

View File

@ -12,6 +12,15 @@ hook global WinSetOption filetype=restructuredtext %{
require-module restructuredtext require-module restructuredtext
} }
hook -group restructuredtext-load-languages global WinSetOption filetype=restructuredtext %{
restructuredtext-load-languages '%'
}
hook -group restructuredtext-load-languages global WinSetOption filetype=restructuredtext %{
hook -group restructuredtext-load-languages window NormalIdle .* %{restructuredtext-load-languages gtGbGl}
hook -group restructuredtext-load-languages window InsertIdle .* %{restructuredtext-load-languages gtGbGl}
}
hook -group restructuredtext-highlight global WinSetOption filetype=restructuredtext %{ hook -group restructuredtext-highlight global WinSetOption filetype=restructuredtext %{
add-highlighter window/restructuredtext ref restructuredtext add-highlighter window/restructuredtext ref restructuredtext
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/restructuredtext } hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/restructuredtext }
@ -26,17 +35,6 @@ add-highlighter shared/restructuredtext regions
add-highlighter shared/restructuredtext/content default-region group add-highlighter shared/restructuredtext/content default-region group
add-highlighter shared/restructuredtext/code region ::\h*\n ^(?=\S) fill meta add-highlighter shared/restructuredtext/code region ::\h*\n ^(?=\S) fill meta
evaluate-commands %sh{
for ft in c cabal clojure coffee cpp css cucumber ddiff dockerfile \
fish gas go haml haskell html ini java javascript json \
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"
done
}
# Setext-style header # Setext-style header
# Valid header characters: # Valid header characters:
# # ! " $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ # # ! " $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
@ -79,4 +77,16 @@ add-highlighter shared/restructuredtext/content/ regex [^*](\*\*([^\s*]|([^\s*][
add-highlighter shared/restructuredtext/content/ regex [^*](\*([^\s*]|([^\s*][^*]*[^\s*]))\*)[^*] 1:+i add-highlighter shared/restructuredtext/content/ regex [^*](\*([^\s*]|([^\s*][^*]*[^\s*]))\*)[^*] 1:+i
add-highlighter shared/restructuredtext/content/ regex [^`](``([^\s`]|([^\s`][^`]*[^\s`]))``)[^`] 1:mono add-highlighter shared/restructuredtext/content/ regex [^`](``([^\s`]|([^\s`][^`]*[^\s`]))``)[^`] 1:mono
define-command restructuredtext-load-languages -params 1 %{
evaluate-commands -draft %{ try %{
execute-keys "%arg{1}s^\.\.\h*code-block::\h*\K\w+<ret>"
evaluate-commands -itersel %{ try %{
require-module %val{selection}
add-highlighter "shared/restructuredtext/%val{selection}" region "\.\.\h*code-block::\h*%val{selection}\h*\n" '^(?=\S)' regions
add-highlighter "shared/restructuredtext/%val{selection}/" default-region fill meta
add-highlighter "shared/restructuredtext/%val{selection}/inner" region \A\.\.\h*code-block::[^\n]*\K '^(?=\S)' ref %val{selection}
}}
}}
}
} }