home/rc/filetype
Johannes Altmanninger 907ad84f46 rc markdown: only add language highlighters for actual code blocks in buffer
There have been proposals to add more language aliases to markdown.kak
(#4592) and allow users to add their own aliases (#4489).

To recap: various markdown implementations allow specifying aliases
for languages. For example, here is a code block that should be
highlighted as filetype "haskell" but isn't:

	```hs
	-- highlight as haskell
	```

There are lots of aliases out in the wild - "pygmentize -L" lists
some but I don't think there is a canonical list.

Today we have a hardcoded list of supported filetypes. This is hard
to mainta, extend, and it can impact performance.
This patch simply attempts to load the module "hs" and the shared
highlighter "hs". This means that users can use this (obvious?) snippet
to add their own aliases:

	provide-module hs %{
		require-module haskell
		add-highlighter shared/hs ref haskell
	}

Untrusted Markdown files can load arbitrary modules, but that was
already true before, and modules are assumed to be trusted anyway.

Since language highlighters are now loaded *after* the generic
code-block highlighter, we need to make sure the language highlighters
take precedence. Do this by making them sub-regions of the generic one.

Closes #4489

This improves performance on the [5MB Markdown
file](https://github.com/mawww/kakoune/issues/4685#issuecomment-1208129806).

	$ HOME=$PWD hyperfine -w 1 'git checkout HEAD'{~,}' -- :/rc/filetype/markdown.kak && ./kak.opt big_markdown.md -e "hook global NormalIdle .* quit" -ui dummy'
	Benchmark 1: git checkout HEAD~ -- :/rc/filetype/markdown.kak && ./kak.opt big_markdown.md -e "hook global NormalIdle .* quit" -ui dummy
	  Time (mean ± σ):      3.225 s ±  0.074 s    [User: 3.199 s, System: 0.027 s]
	  Range (min … max):    3.099 s …  3.362 s    10 runs
	 
	Benchmark 2: git checkout HEAD -- :/rc/filetype/markdown.kak && ./kak.opt big_markdown.md -e "hook global NormalIdle .* quit" -ui dummy
	  Time (mean ± σ):      1.181 s ±  0.030 s    [User: 1.162 s, System: 0.021 s]
	  Range (min … max):    1.149 s …  1.234 s    10 runs
	 
	Summary
	  'git checkout HEAD -- :/rc/filetype/markdown.kak && ./kak.opt big_markdown.md -e "hook global NormalIdle .* quit" -ui dummy' ran
	    2.73 ± 0.09 times faster than 'git checkout HEAD~ -- :/rc/filetype/markdown.kak && ./kak.opt big_markdown.md -e "hook global NormalIdle .* quit" -ui dummy'

(These numbers depend on another optimization.)
2022-09-10 07:35:29 +02:00
..
arch-linux.kak
asciidoc.kak Fix AsciiDoc blocks 2021-10-17 00:19:53 +02:00
awk.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
c-family.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
cabal.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
clojure.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
cmake.kak CMake: fix comment highlight 2022-03-18 09:01:02 +01:00
coffee.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
conf.kak rc conf: treat ini files as conf if they contain a #-comment 2022-02-19 17:31:55 +01:00
coq.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
crystal.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
css.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
cucumber.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
cue.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
d.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
dart.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
dhall.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
diff.kak Remove unnecessary leading space in prompt from mappings 2022-08-01 07:37:02 +02:00
dockerfile.kak rc/filetype/dockerfile: detect filenames that contain special characters 2022-08-16 11:50:30 -04:00
elixir.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
elm.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
elvish.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
erlang.kak Erlang syntax highlighting: Improved support for numeric literals, refs, ports and pids 2021-10-28 12:43:00 +05:30
eruby.kak Add missing eRuby indent group 2021-06-15 14:30:35 +02:00
etc.kak Fixed several more support files. 2019-04-10 16:48:46 -07:00
exherbo.kak Update remaining files to new provide/require format 2019-04-11 15:54:58 -07:00
fennel.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
fidl.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
fish.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
fsharp.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
gas.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
gdscript.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
gentoo-linux.kak Add gentoo linux ebuild filetype detection. 2021-08-06 11:30:06 -07:00
git.kak Merge remote-tracking branch 'adamchristiansen/gitignore-highlighting' 2022-05-10 22:36:44 +10:00
gluon.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
go.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
graphql.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
haml.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
hare.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
haskell.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
hbs.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
html.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
i3.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
ini.kak Add conf filetype, for generic Unix configuration files 2022-02-19 17:31:16 +01:00
janet.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
java.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
javascript.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
jinja.kak rc jinja: Highlight Jinja statements/expressions 2020-01-08 12:22:34 +01:00
json.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
julia.kak rc julia: add multiline comments 2021-02-21 19:20:03 +01:00
just.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
kakrc.kak rc kakrc: add kak=kakrc highlighter alias for markdown/restructuredtext 2022-09-10 07:35:29 +02:00
kickstart.kak Update remaining files to new provide/require format 2019-04-11 15:54:58 -07:00
kotlin.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
latex.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
ledger.kak rc ledger: don't use region highlighter for simple keywords 2022-08-28 08:21:57 +02:00
lisp.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
lua.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
mail.kak Remove unnecessary leading space in prompt from mappings 2022-08-01 07:37:02 +02:00
makefile.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
markdown.kak rc markdown: only add language highlighters for actual code blocks in buffer 2022-09-10 07:35:29 +02:00
mercurial.kak Update remaining files to new provide/require format 2019-04-11 15:54:58 -07:00
mercury.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
meson.kak meson: improve highlighting, add static words 2021-01-13 15:44:38 +01:00
mlb.kak Add highlighters for Standard ML 2020-06-23 19:22:35 +01:00
moon.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
nim.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
ninja.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
nix.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
ocaml.kak OCaml: Recognize '\"' as a char literal and not the start of a string literal 2022-05-15 11:23:06 +05:30
pascal.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
perl.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
php.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
pony.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
protobuf.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
pug.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
purescript.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
python.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
r.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
ragel.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
restructuredtext.kak rc kakrc: add kak=kakrc highlighter alias for markdown/restructuredtext 2022-09-10 07:35:29 +02:00
ruby.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
rust.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
sass.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
scala.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
scheme.kak rc filetype: fix double space in trim-indent hooks 2022-05-26 17:08:15 +02:00
scss.kak rc filetype: fix double space in trim-indent hooks 2022-05-26 17:08:15 +02:00
sh.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
sml.kak Add highlighters for Standard ML 2020-06-23 19:22:35 +01:00
sql.kak Fix function highlighting by adding lazy instead of greedy regexp quantifier 2020-10-14 14:54:43 -06:00
svelte.kak Improve svelte highlighter 2020-11-13 00:21:05 +01:00
swift.kak rc swift: Add open and internal keywords 2021-06-24 14:29:10 +03:00
systemd.kak
taskpaper.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
terraform.kak Add filetype for terraform files with syntax hl 2019-11-18 20:41:42 +00:00
toml.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
troff.kak Add comment highlighter for troff files. 2021-02-25 20:18:10 +01:00
tupfile.kak Fixed many of the filetype support modules to not use BufSetOption to load 2019-04-09 20:54:19 -07:00
twig.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00
vhdl.kak Merge remote-tracking branch 'm-kru/vhdl_time_vector' 2022-09-09 15:42:37 +02:00
void-linux.kak
yaml.kak Move user mappings to <space> and keep/remove selection to , 2022-07-05 08:43:40 +10:00
zig.kak Make x just select the full lines 2022-07-05 08:43:40 +10:00