aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorHumanEntity <human_entity@icloud.com>2023-12-25 12:54:37 +0100
committerHumanEntity <human_entity@icloud.com>2023-12-25 12:54:37 +0100
commit4997cc9704883b7833372386b71ddc8bbb177a56 (patch)
treed746e294b74a0a2dbd8a4cfec6e66369b0c6810f /lua
parent9fb27f9c4f8258662b5642d0768c60f4b870bca2 (diff)
downloadsimple-denote.nvim-4997cc9704883b7833372386b71ddc8bbb177a56.tar.gz
Little restructurization and cmd update
Diffstat (limited to 'lua')
-rw-r--r--lua/denote/api.lua3
-rw-r--r--lua/denote/cmd.lua22
-rw-r--r--lua/denote/init.lua11
-rw-r--r--lua/denote/internal.lua22
4 files changed, 34 insertions, 24 deletions
diff --git a/lua/denote/api.lua b/lua/denote/api.lua
index b01cdfa..fd83f5b 100644
--- a/lua/denote/api.lua
+++ b/lua/denote/api.lua
@@ -1,6 +1,7 @@
local M = {}
local internal = require("denote.internal")
local util = require("denote.util")
+local config = require("denote.config")
function M.note()
local name = ""
@@ -46,7 +47,7 @@ function M.search()
local status = internal.search(date, name, function(input)
if input then
- vim.cmd("e " .. internal.config.vault.dir .. "/" .. input)
+ vim.cmd("e " .. config.vault.dir .. "/" .. input)
end
if date then
print(date.year, " ", date.month, " ", date.day)
diff --git a/lua/denote/cmd.lua b/lua/denote/cmd.lua
index aa93637..9b8d9e6 100644
--- a/lua/denote/cmd.lua
+++ b/lua/denote/cmd.lua
@@ -1,17 +1,25 @@
-local M = {}
+local M = {
+ commands = { "note", "search" },
+}
local api = require("denote.api")
function M.load_cmd()
vim.api.nvim_create_user_command("Denote", function(opts)
- if opts.fargs[1] == "note" then
- api.note()
- elseif opts.fargs[1] == "search" then
- api.search()
+ if opts.fargs[1] then
+ if opts.fargs[1] == "note" then
+ api.note()
+ elseif opts.fargs[1] == "search" then
+ api.search()
+ else
+ error("Unsupported operation " .. opts.fargs[1])
+ end
else
- error("Unsupported operation " .. opts.fargs[1])
+ vim.ui.select(M.commands, { prompt = "Command: " }, function(choice)
+ api[choice]()
+ end)
end
end, {
- nargs = 1,
+ -- nargs = 1,
complete = function()
return { "note", "search" }
end,
diff --git a/lua/denote/init.lua b/lua/denote/init.lua
index c18300d..396486f 100644
--- a/lua/denote/init.lua
+++ b/lua/denote/init.lua
@@ -1,12 +1,13 @@
-local M = {}
-local api = require("denote.api")
-local cmd = require("denote.cmd")
+local M = {
+ api = require("denote.api"),
+ cmd = require("denote.cmd"),
+}
---@param config DenoteConfig
function M.setup(config)
- cmd.load_cmd()
+ M.cmd.load_cmd()
if config then
- internal.config = config
+ M.config = config
end
end
diff --git a/lua/denote/internal.lua b/lua/denote/internal.lua
index 95ee7dc..d2c6ebe 100644
--- a/lua/denote/internal.lua
+++ b/lua/denote/internal.lua
@@ -1,5 +1,5 @@
local M = {}
-M.config = require("denote.config")
+local config = require("denote.config")
---@class DenoteDate
---@field year string
@@ -20,28 +20,28 @@ function M.file(name, tags)
for i, tag in pairs(tags) do
tags_str = tags_str .. tag
if i < #tags then
- tags_str = tags_str .. M.config.filename.tag_sep
+ tags_str = tags_str .. config.filename.tag_sep
end
end
end
- file = date .. M.config.filename.date_sep .. M.config.filename.date_sep .. name
+ file = date .. config.filename.date_sep .. M.config.filename.date_sep .. name
if tags then
- file = file .. M.config.filename.name_sep .. M.config.filename.name_sep .. tags_str
+ file = file .. config.filename.name_sep .. M.config.filename.name_sep .. tags_str
end
- return file .. "." .. M.config.filename.ext
+ return file .. "." .. config.filename.ext
end
---@param name string
---@param tags table|nil
--- Opens your note
function M.note(name, tags)
- local filename = M.config.vault.dir .. M.file(name, tags)
+ local filename = config.vault.dir .. M.file(name, tags)
-- Echo template
- vim.cmd("!mkdir -p " .. M.config.vault.dir)
+ vim.cmd("!mkdir -p " .. config.vault.dir)
vim.cmd("e " .. filename)
end
@@ -69,9 +69,9 @@ function M.search(date, name, func)
matcher = "%d%d"
end
- matcher = matcher .. M.config.filename.date_sep .. M.config.filename.date_sep
+ matcher = matcher .. config.filename.date_sep .. M.config.filename.date_sep
else
- matcher = "%d+" .. M.config.filename.date_sep .. M.config.filename.date_sep
+ matcher = "%d+" .. config.filename.date_sep .. M.config.filename.date_sep
end
if name then
@@ -80,9 +80,9 @@ function M.search(date, name, func)
matcher = matcher .. ".+"
end
- -- matcher = matcher .. M.config.filename.name_sep .. "?" .. M.config.filename.name_sep .. "?" .. ".-"
+ -- matcher = matcher .. config.filename.name_sep .. "?" .. M.config.filename.name_sep .. "?" .. ".-"
- for file in io.popen("ls " .. M.config.vault.dir):lines() do
+ for file in io.popen("ls " .. config.vault.dir):lines() do
local matched = file:match(matcher)
if matched then