mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2025-12-31 22:04:24 -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:
|
||||
|
||||
1. `#tag`
|
||||
2. `:tag:`
|
||||
3. `yaml-bare`: bare tags in a tag collection in the yaml metadata:
|
||||
2. `@tag`
|
||||
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
|
||||
|
||||
@@ -114,7 +114,7 @@ telekasten.setup({opts})
|
||||
-- Make syntax available to markdown buffers and telescope previewers
|
||||
install_syntax = true,
|
||||
|
||||
-- Tag notation: '#tag', ':tag:', 'yaml-bare'
|
||||
-- Tag notation: '#tag', '@tag', ':tag:', 'yaml-bare'
|
||||
tag_notation = "#tag",
|
||||
|
||||
-- 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
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user