summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-25 05:04:15 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-25 05:35:07 +0200
commitd8654076282df55d425b2e4fa0be9355bde6b928 (patch)
treeaa3d2ab58c816da7cdd29ef64faa75e70bca5f31 /plugin
parent49b46e1104c0df3f87c9746b4851fd09f6a2239c (diff)
downloadnvim-config-d8654076282df55d425b2e4fa0be9355bde6b928.tar.gz
nvim-config-d8654076282df55d425b2e4fa0be9355bde6b928.zip
feat(nvim): follow <scheme://…> autolinks with gf
Diffstat (limited to 'plugin')
-rw-r--r--plugin/50-follow.lua34
1 files changed, 33 insertions, 1 deletions
diff --git a/plugin/50-follow.lua b/plugin/50-follow.lua
index e8ed3a6..dd207ab 100644
--- a/plugin/50-follow.lua
+++ b/plugin/50-follow.lua
@@ -147,6 +147,31 @@ local function markdown_link_matches()
end
----------------------------------------------------------------------------------------------------
+-- Autolinks ---------------------------------------------------------------------------------------
+----------------------------------------------------------------------------------------------------
+
+--[[ All CommonMark autolinks `<scheme://…>` in the buffer, targeting the inner URL with the angle
+brackets stripped. Registered before the bare-URL entity so a bracketed link wins: the looser URL
+scan would otherwise swallow the closing `>` and trailing punctuation into the target. The match
+spans the brackets so the cursor follows from `<` through `>`. `open_target` percent-decodes the
+URI, so the inner text may be percent-encoded (e.g. `<nvim-help://%27statusline%27>`). ]]
+local function autolink_matches()
+ local out = {}
+ for i, line in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
+ local init = 1
+ while true do
+ local s, e, inner = line:find("<(%a[%w+.-]*://[^>%s]*)>", init)
+ if s == nil then
+ break
+ end
+ out[#out + 1] = { from = { i, s - 1 }, to = { i, e }, target = inner }
+ init = e + 1
+ end
+ end
+ return out
+end
+
+----------------------------------------------------------------------------------------------------
-- URLs --------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
@@ -160,7 +185,13 @@ local function url_matches()
if s == nil then
break
end
- out[#out + 1] = { from = { i, s - 1 }, to = { i, e }, target = line:sub(s, e) }
+ -- A `<scheme://…>` autolink is matched by the autolink entity; skip it here.
+ local is_autolink = s > 1
+ and line:sub(s - 1, s - 1) == "<"
+ and line:find("^[^>%s]*>", s) ~= nil
+ if not is_autolink then
+ out[#out + 1] = { from = { i, s - 1 }, to = { i, e }, target = line:sub(s, e) }
+ end
init = e + 1
end
end
@@ -241,6 +272,7 @@ else
)
end
df.register("markdown-link", markdown_link_matches, df.open)
+df.register("autolink", autolink_matches, df.open)
df.register("url", url_matches, df.open)
df.register("cfile", cfile_matches, open_cfile)
df.register_scheme("nvim-help", nvim_help_scheme)