mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
Add @tag support (#247)
Co-authored-by: T. H. Wright <thwright@redemption.studio>
This commit is contained in:
@@ -362,8 +362,9 @@ See the documentation for more details regarding the different types of links
|
|||||||
Telekasten supports the following tag notations:
|
Telekasten supports the following tag notations:
|
||||||
|
|
||||||
1. `#tag`
|
1. `#tag`
|
||||||
2. `:tag:`
|
2. `@tag`
|
||||||
3. `yaml-bare`: bare tags in a tag collection in the yaml metadata:
|
3. `:tag:`
|
||||||
|
4. `yaml-bare`: bare tags in a tag collection in the yaml metadata:
|
||||||
|
|
||||||
|
|
||||||
See the documentation for more details regarding the tag syntax (`:h
|
See the documentation for more details regarding the tag syntax (`:h
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ telekasten.setup({opts})
|
|||||||
-- Make syntax available to markdown buffers and telescope previewers
|
-- Make syntax available to markdown buffers and telescope previewers
|
||||||
install_syntax = true,
|
install_syntax = true,
|
||||||
|
|
||||||
-- Tag notation: '#tag', ':tag:', 'yaml-bare'
|
-- Tag notation: '#tag', '@tag', ':tag:', 'yaml-bare'
|
||||||
tag_notation = "#tag",
|
tag_notation = "#tag",
|
||||||
|
|
||||||
-- When linking to a note in subdir/, create a [[subdir/title]] link
|
-- When linking to a note in subdir/, create a [[subdir/title]] link
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ M.is_tag_or_link_at = function(line, col, opts)
|
|||||||
if char == "#" then
|
if char == "#" then
|
||||||
seen_hashtag = true
|
seen_hashtag = true
|
||||||
end
|
end
|
||||||
|
if char == "@" then
|
||||||
|
seen_hashtag = true
|
||||||
|
end
|
||||||
-- Tags should have a space before #, if not we are likely in a link
|
-- 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 char == " " and seen_hashtag and opts.tag_notation == "#tag" then
|
||||||
if not cannot_be_tag then
|
if not cannot_be_tag then
|
||||||
|
|||||||
@@ -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
|
-- PCRE hashtag allows to remove the hex color codes from hastags
|
||||||
local hashtag_re_pcre =
|
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/\\-_]*)"
|
"(^|\\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 colon_re = "(^|\\s):[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*:"
|
||||||
local yaml_re =
|
local yaml_re =
|
||||||
"(^|\\s)tags:\\s*\\[\\s*([a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*(,\\s*)*)*\\s*]"
|
"(^|\\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
|
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
|
re = colon_re
|
||||||
end
|
elseif opts.tag_notation == "yaml-bare" then
|
||||||
|
|
||||||
if opts.tag_notation == "yaml-bare" then
|
|
||||||
re = yaml_re
|
re = yaml_re
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -41,18 +44,32 @@ local function command_find_all_tags(opts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
-- PCRE engine allows to remove hex color codes from #hastags
|
-- PCRE engine allows to remove hex color codes from #hastags
|
||||||
if opts.rg_pcre and (re == hashtag_re) then
|
if opts.rg_pcre then
|
||||||
re = hashtag_re_pcre
|
if re == hashtag_re then
|
||||||
|
re = hashtag_re_pcre
|
||||||
|
|
||||||
rg_args = {
|
rg_args = {
|
||||||
"--vimgrep",
|
"--vimgrep",
|
||||||
"--pcre2",
|
"--pcre2",
|
||||||
globArg,
|
globArg,
|
||||||
"-o",
|
"-o",
|
||||||
re,
|
re,
|
||||||
"--",
|
"--",
|
||||||
opts.cwd,
|
opts.cwd,
|
||||||
}
|
}
|
||||||
|
elseif re == atsign_re then
|
||||||
|
re = atsign_re_pcre
|
||||||
|
|
||||||
|
rg_args = {
|
||||||
|
"--vimgrep",
|
||||||
|
"--pcre2",
|
||||||
|
globArg,
|
||||||
|
"-o",
|
||||||
|
re,
|
||||||
|
"--",
|
||||||
|
opts.cwd,
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return "rg", rg_args
|
return "rg", rg_args
|
||||||
|
|||||||
Reference in New Issue
Block a user