Add @tag support (#247)

Co-authored-by: T. H. Wright <thwright@redemption.studio>
This commit is contained in:
T. H. Wright
2023-05-19 15:04:30 -04:00
committed by GitHub
parent 617469cd06
commit 8a8daa0ea1
4 changed files with 39 additions and 18 deletions

View File

@@ -52,6 +52,9 @@ M.is_tag_or_link_at = function(line, col, opts)
if char == "#" then
seen_hashtag = true
end
if char == "@" then
seen_hashtag = true
end
-- Tags should have a space before #, if not we are likely in a link
if char == " " and seen_hashtag and opts.tag_notation == "#tag" then
if not cannot_be_tag then

View File

@@ -5,6 +5,9 @@ local hashtag_re = "(^|\\s|'|\")#[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*"
-- PCRE hashtag allows to remove the hex color codes from hastags
local hashtag_re_pcre =
"(^|\\s|'|\")((?!(#[a-fA-F0-9]{3})(\\W|$)|(#[a-fA-F0-9]{6})(\\W|$))#[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*)"
local atsign_re = "(^|\\s|'|\")@[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*"
local atsign_re_pcre =
"(^|\\s|'|\")((?!(@[a-fA-F0-9]{3})(\\W|$)|(@[a-fA-F0-9]{6})(\\W|$))@[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*)"
local colon_re = "(^|\\s):[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*:"
local yaml_re =
"(^|\\s)tags:\\s*\\[\\s*([a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*(,\\s*)*)*\\s*]"
@@ -23,11 +26,11 @@ local function command_find_all_tags(opts)
local re = hashtag_re
if opts.tag_notation == ":tag:" then
if opts.tag_notation == "@tag" then
re = atsign_re
elseif opts.tag_notation == ":tag:" then
re = colon_re
end
if opts.tag_notation == "yaml-bare" then
elseif opts.tag_notation == "yaml-bare" then
re = yaml_re
end
@@ -41,18 +44,32 @@ local function command_find_all_tags(opts)
}
-- PCRE engine allows to remove hex color codes from #hastags
if opts.rg_pcre and (re == hashtag_re) then
re = hashtag_re_pcre
if opts.rg_pcre then
if re == hashtag_re then
re = hashtag_re_pcre
rg_args = {
"--vimgrep",
"--pcre2",
globArg,
"-o",
re,
"--",
opts.cwd,
}
rg_args = {
"--vimgrep",
"--pcre2",
globArg,
"-o",
re,
"--",
opts.cwd,
}
elseif re == atsign_re then
re = atsign_re_pcre
rg_args = {
"--vimgrep",
"--pcre2",
globArg,
"-o",
re,
"--",
opts.cwd,
}
end
end
return "rg", rg_args