aboutsummaryrefslogtreecommitdiff
path: root/lua/denote
diff options
context:
space:
mode:
Diffstat (limited to 'lua/denote')
-rw-r--r--lua/denote/api.lua10
-rw-r--r--lua/denote/internal.lua39
-rw-r--r--lua/denote/util.lua16
3 files changed, 59 insertions, 6 deletions
diff --git a/lua/denote/api.lua b/lua/denote/api.lua
index feecefe..7213f8c 100644
--- a/lua/denote/api.lua
+++ b/lua/denote/api.lua
@@ -29,7 +29,7 @@ end
---@param date DenoteDate|nil
---@param name string|nil
-function M.search(date, name)
+function M.search(date, name, tags)
if not date then
vim.ui.input({ prompt = "Date: " }, function(input)
local split = util.splitspace(input)
@@ -52,7 +52,13 @@ function M.search(date, name)
end)
end
- local status = internal.search(date, name, function(input)
+ if not tags then
+ vim.ui.input({ prompt = "Tags: " }, function(input)
+ tags = util.splitstring(input, " ")
+ end)
+ end
+
+ local status = internal.search(date, name, tags, function(input)
if input then
vim.cmd("e " .. config.vault.dir .. "/" .. input)
end
diff --git a/lua/denote/internal.lua b/lua/denote/internal.lua
index a559cd1..fd1249b 100644
--- a/lua/denote/internal.lua
+++ b/lua/denote/internal.lua
@@ -1,5 +1,6 @@
local M = {}
local config = require("denote.config")
+local util = require("denote.util")
---@class DenoteDate
---@field year string
@@ -47,8 +48,9 @@ end
---@param date DenoteDate|nil
---@param name string|nil
+---@param tags table|nil
---@param func function
-function M.search(date, name, func)
+function M.search(date, name, tags, func)
local items = {}
local matcher = ""
@@ -95,14 +97,43 @@ function M.search(date, name, func)
return nil
end
+ if tags then
+ local items_copy = items
+ items = {}
+ for _, item in pairs(items_copy) do
+ local item_tags_pre = M.get_tags(item)
+ local item_tags = {}
+ for _, i in item_tags_pre do
+ item_tags[i] = 0
+ end
+ local good = true
+ for _, tag in pairs(tags) do
+ if item_tags[tag] == nil then
+ good = false
+ end
+ end
+ if good then
+ items[#items + 1] = item
+ end
+ end
+ end
+
vim.ui.select(items, {
prompt = "Select note",
- -- format_item = function(item)
- -- return "" .. item
- -- end,
}, func)
return true
end
+---@param filename string
+---@return table
+function M.get_tags(filename)
+ local tags = {}
+ local name = util.splitstring(filename, ".")[1]
+ for _, s in pairs(util.splitstring(util.splitstring(name, config.filename.name_sep)[3], config.filename.tag_sep)) do
+ tags[#tags + 1] = s
+ end
+ return tags
+end
+
return M
diff --git a/lua/denote/util.lua b/lua/denote/util.lua
index ce998f0..bd237eb 100644
--- a/lua/denote/util.lua
+++ b/lua/denote/util.lua
@@ -8,4 +8,20 @@ function M.splitspace(str)
return chunks
end
+function M.splitstring(str, delim)
+ local items = {}
+ local fulldelim = nil
+ if delim == "." or delim == "-" then
+ fulldelim = "%" .. delim
+ else
+ fulldelim = delim
+ end
+ print("fulldelim: ", fulldelim)
+ str = str .. delim
+ for w in str:gmatch("(.-)" .. fulldelim) do
+ items[#items + 1] = w
+ end
+ return items
+end
+
return M