mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-01 16:32:54 +03:00
f7c3faa2e1
I can't think of a case where a URL would not start at a word boundary. Let's add that to the regex. In addition to correctness, this also slightly improves performance because matching can stop earlier. $ 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 ± σ): 1.123 s ± 0.022 s [User: 1.100 s, System: 0.027 s] Range (min … max): 1.093 s … 1.174 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.019 s ± 0.026 s [User: 1.001 s, System: 0.021 s] Range (min … max): 0.984 s … 1.051 s 10 runs Summary 'git checkout HEAD -- :/rc/filetype/markdown.kak && ./kak.opt big_markdown.md -e "hook global NormalIdle .* quit" -ui dummy' ran 1.10 ± 0.04 times faster than 'git checkout HEAD~ -- :/rc/filetype/markdown.kak && ./kak.opt big_markdown.md -e "hook global NormalIdle .* quit" -ui dummy'
64 lines
2.0 KiB
Plaintext
64 lines
2.0 KiB
Plaintext
# https://www.taskpaper.com
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
# Detection
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
hook global BufCreate .*\.taskpaper %{
|
|
set-option buffer filetype taskpaper
|
|
}
|
|
|
|
# Initialization
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
hook global WinSetOption filetype=taskpaper %{
|
|
require-module taskpaper
|
|
|
|
hook window ModeChange pop:insert:.* -group taskpaper-trim-indent taskpaper-trim-indent
|
|
hook window InsertChar \n -group taskpaper-indent taskpaper-indent-on-new-line
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window taskpaper-.+ }
|
|
}
|
|
|
|
hook -group taskpaper-highlight global WinSetOption filetype=taskpaper %{
|
|
add-highlighter window/taskpaper ref taskpaper
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/taskpaper }
|
|
}
|
|
|
|
|
|
provide-module taskpaper %{
|
|
|
|
# Highlighters
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
add-highlighter shared/taskpaper group
|
|
|
|
add-highlighter shared/taskpaper/ regex ^\h*([^:\n]+):\h*\n 1:header
|
|
add-highlighter shared/taskpaper/ regex \h@\w+(?:\(([^)]*)\))? 0:variable 1:value
|
|
add-highlighter shared/taskpaper/ regex ^\h*([^-:\n]+)\n 1:+i
|
|
add-highlighter shared/taskpaper/ regex ^\h*-\h+[^\n]*@done[^\n]* 0:+d
|
|
add-highlighter shared/taskpaper/ regex \b(([a-z]+://\S+)|((mailto:)[\w+-]+@\S+)) 0:link
|
|
|
|
# Commands
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
define-command -hidden taskpaper-trim-indent %{
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
|
execute-keys x
|
|
# remove trailing white spaces
|
|
try %{ execute-keys -draft s \h + $ <ret> d }
|
|
}
|
|
}
|
|
|
|
define-command -hidden taskpaper-indent-on-new-line %{
|
|
evaluate-commands -draft -itersel %{
|
|
# preserve previous line indent
|
|
try %{ execute-keys -draft <semicolon>K<a-&> }
|
|
## If the line above is a project indent with a tab
|
|
try %{ execute-keys -draft Z kx <a-k>^\h*([^:\n]+):<ret> z i<tab> }
|
|
# cleanup trailing white spaces on previous line
|
|
try %{ execute-keys -draft kx s \h+$ <ret>d }
|
|
}
|
|
}
|
|
|
|
}
|