From f7c3faa2e1dd4bc55a07c8d9d8232f3e85d2559b Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 15 Aug 2022 22:22:23 +0200 Subject: [PATCH] rc markdown taskpaper: require bare URL to start at word boundary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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' --- rc/filetype/markdown.kak | 4 ++-- rc/filetype/taskpaper.kak | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak index f201770a..2a5755b9 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -64,8 +64,8 @@ add-highlighter shared/markdown/codeline region "^( {4}|\t)" "$" fill meta # https://spec.commonmark.org/0.29/#link-destination add-highlighter shared/markdown/angle_bracket_url region (?<=<)([a-z]+://|(mailto|magnet|xmpp):) (?!\\).(?=>)|\n fill link -add-highlighter shared/markdown/inline/url region -recurse \( ([a-z]+://|(mailto|magnet|xmpp):) (?!\\).(?=\))|\s fill link -add-highlighter shared/markdown/listblock/angle_bracket_url region (?<=<)([a-z]+://|(mailto|magnet|xmpp):) (?!\\).(?=>)|\n fill link +add-highlighter shared/markdown/inline/url region -recurse \( (\b[a-z]+://|(mailto|magnet|xmpp):) (?!\\).(?=\))|\s fill link +add-highlighter shared/markdown/listblock/angle_bracket_url region (?<=<)(\b[a-z]+://|(mailto|magnet|xmpp):) (?!\\).(?=>)|\n fill link try %{ require-module html diff --git a/rc/filetype/taskpaper.kak b/rc/filetype/taskpaper.kak index ece6664e..187aa09c 100644 --- a/rc/filetype/taskpaper.kak +++ b/rc/filetype/taskpaper.kak @@ -36,7 +36,7 @@ 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 (([a-z]+://\S+)|((mailto:)[\w+-]+@\S+)) 0:link +add-highlighter shared/taskpaper/ regex \b(([a-z]+://\S+)|((mailto:)[\w+-]+@\S+)) 0:link # Commands # ‾‾‾‾‾‾‾‾