Skip to content

Commit

Permalink
feat: allow specific window to be provided to delete_url_match and …
Browse files Browse the repository at this point in the history
…`set_url_match`
  • Loading branch information
mehalter committed Apr 17, 2024
1 parent 269c5a2 commit 2a77fdc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lua/astrocore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,20 @@ M.url_matcher =
"\\v\\c%(%(h?ttps?|ftp|file|ssh|git)://|[a-z]+[@][a-z]+[.][a-z]+:)%([&:#*@~%_\\-=?!+;/0-9a-z]+%(%([.;/?]|[.][.]+)[&:#*@~%_\\-=?!+/0-9a-z]+|:\\d+|,%(%(%(h?ttps?|ftp|file|ssh|git)://|[a-z]+[@][a-z]+[.][a-z]+:)@![0-9a-z]+))*|\\([&:#*@~%_\\-=?!+;/.0-9a-z]*\\)|\\[[&:#*@~%_\\-=?!+;/.0-9a-z]*\\]|\\{%([&:#*@~%_\\-=?!+;/.0-9a-z]*|\\{[&:#*@~%_\\-=?!+;/.0-9a-z]*})\\})+"

--- Delete the syntax matching rules for URLs/URIs if set
function M.delete_url_match()
for _, match in ipairs(vim.fn.getmatches()) do
if match.group == "HighlightURL" then vim.fn.matchdelete(match.id) end
---@param win integer? the window id to remove url highlighting in (default: current window)
function M.delete_url_match(win)
if not win then win = vim.api.nvim_get_current_win() end
for _, match in ipairs(vim.fn.getmatches(win)) do
if match.group == "HighlightURL" then vim.fn.matchdelete(match.id, win) end
end
end

--- Add syntax matching rules for highlighting URLs/URIs
function M.set_url_match()
M.delete_url_match()
if M.config.features.highlighturl then vim.fn.matchadd("HighlightURL", M.url_matcher, 15) end
---@param win integer? the window id to remove url highlighting in (default: current window)
function M.set_url_match(win)
if not win then win = vim.api.nvim_get_current_win() end
M.delete_url_match(win)
if M.config.features.highlighturl then vim.fn.matchadd("HighlightURL", M.url_matcher, 15, -1, { window = win }) end
end

--- Run a shell command and capture the output and if the command succeeded or failed
Expand Down

0 comments on commit 2a77fdc

Please sign in to comment.