diff options
| author | DefaultGen <gravel.justness270@slmail.me> | 2024-06-01 22:35:39 -0400 |
|---|---|---|
| committer | DefaultGen <gravel.justness270@slmail.me> | 2024-06-01 22:35:39 -0400 |
| commit | bde89bcfe9ceb6d312a02d3361fb817c304544f6 (patch) | |
| tree | 104d9e2b83130001e373206ba9378bf07a0c0b13 /lua/denote/api.lua | |
| parent | 22818fd95f438f83d32f6e1d482c6c2ef58772a0 (diff) | |
| download | simple-denote.nvim-bde89bcfe9ceb6d312a02d3361fb817c304544f6.tar.gz | |
Initial commit
Diffstat (limited to 'lua/denote/api.lua')
| -rw-r--r-- | lua/denote/api.lua | 109 |
1 files changed, 45 insertions, 64 deletions
diff --git a/lua/denote/api.lua b/lua/denote/api.lua index 277827f..e88a333 100644 --- a/lua/denote/api.lua +++ b/lua/denote/api.lua @@ -1,76 +1,57 @@ local M = {} + local internal = require("denote.internal") local util = require("denote.util") -local config = require("denote.config") +---@param options table ---@param name string|nil ---@param tags table|nil -function M.note(name, tags) - if not name then - vim.ui.input({ prompt = "Note name: " }, function(input) - name = input - end) - end - - if not tags then - vim.ui.input({ prompt = "Enter tags: " }, function(input) - if input ~= "" and input then - tags = util.splitspace(input) - end - end) - end - - if name == "" then - error("Didn't specify name") - end - - internal.note(name, tags) +function M.note(options, name, tags) + if not name then + vim.ui.input({ prompt = "Note title: " }, function(input) + name = input + end) + end + if not tags then + vim.ui.input({ prompt = "Tags: " }, function(input) + if input ~= "" and input then + tags = util.splitspace(input) + end + end) + end + internal.note(options, name, tags) end ----@param date DenoteDate|nil ----@param name string|nil ----@param tags table|nil -function M.search(date, name, tags) - if not date then - vim.ui.input({ prompt = "Date: " }, function(input) - local split = util.splitspace(input) - if split[0] then - date = {} - date.year = split[0] - if split[1] then - date.month = split[1] - if split[2] then - date.day = split[2] - end - end - end - end) - end - - if not name then - vim.ui.input({ prompt = "Name: " }, function(input) - name = input - end) - end - - if not tags then - vim.ui.input({ prompt = "Tags: " }, function(input) - if input == "" then - return - end - 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 - end) +---@param options table +---@param filename string|nil +---@param new_title string|nil +function M.retitle(options, filename, new_title) + if not filename then + filename = vim.fn.expand("%") + end + if not new_title then + vim.ui.input({ prompt = "New title: " }, function(input) + new_title = input + end) + end + internal.retitle(options, filename, new_title) +end - if not status then - print("Error opening file") - end +---@param options table +---@param filename string|nil +---@param new_tags table|nil +function M.retag(options, filename, new_tags) + if not filename then + filename = vim.fn.expand("%") + end + if not new_tags then + vim.ui.input({ prompt = "New tags: " }, function(input) + if input ~= "" and input then + new_tags = util.splitspace(input) + end + end) + end + internal.retag(options, filename, new_tags) end return M |
