From 2b2f7f954a8ca24acde44e4e4497b27775ed83b9 Mon Sep 17 00:00:00 2001 From: HumanEntity Date: Sun, 24 Dec 2023 23:07:17 +0100 Subject: Added some docs --- lua/denote/config.lua | 30 ++++++++++++++++++++++-------- lua/denote/init.lua | 17 +++++++++-------- lua/denote/util.lua | 23 +++++++++++++++++++---- 3 files changed, 50 insertions(+), 20 deletions(-) (limited to 'lua/denote') diff --git a/lua/denote/config.lua b/lua/denote/config.lua index f6ec007..fce9a50 100644 --- a/lua/denote/config.lua +++ b/lua/denote/config.lua @@ -1,12 +1,26 @@ +---@class DenoteConfigFilename +---@field ext string defaults to "norg" +---@field date_sep string defaults to "_" +---@field name_sep string defaults to "-" +---@field tag_sep string defaults to "=" + +---@class DenoteConfigVault +---@field dir string defaults to "~/.denote/" + +---@class DenoteConfig +---@field filename DenoteConfigFilename +---@field vault DenoteConfigVault + +---@type DenoteConfig local M = { - config = { - filename = { - ext = "norg", - date_sep = "_", - name_sep = "-", - tag_sep = "=", - }, - vault_dir = "~/.denote/", + filename = { + ext = "norg", + date_sep = "_", + name_sep = "-", + tag_sep = "=", + }, + vault = { + dir = "~/.denote/", }, } diff --git a/lua/denote/init.lua b/lua/denote/init.lua index 18f57c1..814653f 100644 --- a/lua/denote/init.lua +++ b/lua/denote/init.lua @@ -1,13 +1,13 @@ local M = {} local U = require("denote.util") -local function splitlines(str) - local result = {} - for line in string.gmatch(str .. "\n", "(.-)\n") do - table.insert(result, line) - end - return result -end +-- local function splitlines(str) +-- local result = {} +-- for line in string.gmatch(str .. "\n", "(.-)\n") do +-- table.insert(result, line) +-- end +-- return result +-- end local function splitspace(str) local chunks = {} @@ -57,7 +57,7 @@ function M.search() local status = U.search(date, name, function(input) if input then - vim.cmd("e " .. U.config.vault_dir .. "/" .. input) + vim.cmd("e " .. U.config.vault.dir .. "/" .. input) end if date then print(date.year, " ", date.month, " ", date.day) @@ -75,6 +75,7 @@ function M.search() end end +---@param config DenoteConfig function M.setup(config) if config then U.config = config diff --git a/lua/denote/util.lua b/lua/denote/util.lua index 3bd7cec..657da9d 100644 --- a/lua/denote/util.lua +++ b/lua/denote/util.lua @@ -1,5 +1,14 @@ -local M = require("denote.config") +local M = {} +M.config = require("denote.config") +---@class DenoteDate +---@field year string +---@field month string +---@field day string + +---@param name string +---@param tags table|nil +---@return string filename format of files in denote.nvim function M.file(name, tags) local file = "" @@ -24,15 +33,21 @@ function M.file(name, tags) return file .. "." .. M.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 = M.config.vault.dir .. M.file(name, tags) -- Echo template - vim.cmd("!mkdir -p " .. M.config.vault_dir) + vim.cmd("!mkdir -p " .. M.config.vault.dir) vim.cmd("e " .. filename) end +---@param date DenoteDate|nil +---@param name string|nil +---@param func function function M.search(date, name, func) local items = {} local matcher = "" @@ -67,7 +82,7 @@ function M.search(date, name, func) -- matcher = matcher .. M.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 " .. M.config.vault.dir):lines() do local matched = file:match(matcher) if matched then -- cgit v1.2.3