diff options
| author | historia <gravel.justness270@slmail.me> | 2024-08-14 15:52:14 -0400 |
|---|---|---|
| committer | historia <gravel.justness270@slmail.me> | 2024-08-14 15:52:14 -0400 |
| commit | 64b58e667d0d255439b055227f1f11012fcc9006 (patch) | |
| tree | 9ce5c173ff05af0e647a4a00b04c59e54c701fa3 /lua/simple-denote | |
| parent | 8da26902f526a54c8873d16d1b7b6e7820fb293b (diff) | |
| download | simple-denote.nvim-64b58e667d0d255439b055227f1f11012fcc9006.tar.gz | |
Feature: Command to change file extension
Diffstat (limited to 'lua/simple-denote')
| -rw-r--r-- | lua/simple-denote/api.lua | 25 | ||||
| -rw-r--r-- | lua/simple-denote/internal.lua | 18 |
2 files changed, 33 insertions, 10 deletions
diff --git a/lua/simple-denote/api.lua b/lua/simple-denote/api.lua index c26bafd..a03c9f2 100644 --- a/lua/simple-denote/api.lua +++ b/lua/simple-denote/api.lua @@ -4,7 +4,7 @@ local internal = require("simple-denote.internal") ---@param options table ---@param title string|nil ----@param keywords table|nil +---@param keywords string|nil function M.note(options, title, keywords) if not title then vim.ui.input({ prompt = "Note title: " }, function(input) @@ -38,7 +38,7 @@ end ---@param options table ---@param filename string|nil ----@param keywords table|nil +---@param keywords string|nil function M.keywords(options, filename, keywords) if not filename then filename = vim.fn.expand("%") @@ -52,10 +52,9 @@ function M.keywords(options, filename, keywords) internal.keyword(options, filename, keywords) end ----@param options table ---@param filename string|nil ----@param sig string -function M.signature(options, filename, sig) +---@param sig string|nil +function M.signature(filename, sig) filename = filename or vim.fn.expand("%") if not sig then vim.ui.input({ prompt = "Signature: " }, function(input) @@ -63,7 +62,21 @@ function M.signature(options, filename, sig) end) end if not sig then return end - internal.signature(options, filename, sig) + internal.signature(filename, sig) +end + +---@param filename string|nil +---@param ext string|nil +function M.extension(filename, ext) + filename = filename or vim.fn.expand("%") + if not ext then + vim.ui.input({ prompt = "Extension: " }, function(input) + ext = input + end) + end + if not ext then return end + internal.extension(filename, ext) end + return M diff --git a/lua/simple-denote/internal.lua b/lua/simple-denote/internal.lua index 73ba71f..8821689 100644 --- a/lua/simple-denote/internal.lua +++ b/lua/simple-denote/internal.lua @@ -18,7 +18,7 @@ function M.plain_format(str) end ---@param str string ----@param char delimiter that replaces spaces (- for titles, _ for keywords, = for sigs) +---@param char string delimiter that replaces spaces (- for titles, _ for keywords, = for sigs) ---Format the title/keywords/sig string of a Denote filename function M.format_denote_string(str, char) str = M.plain_format(str) @@ -28,7 +28,6 @@ function M.format_denote_string(str, char) end ---@param title string heading text ----@param ext string file extension ---Set the first line to title if it's an empty buffer or the first line is a heading function M.set_heading(options, title) if title == "" then return end @@ -108,11 +107,10 @@ function M.keyword(options, filename, keywords) M.replace_file(filename, new_filename) end ----@param options table ---@param filename string ---@param sig string ---Add/change the ==signature in the filename -function M.signature(options, filename, sig) +function M.signature(filename, sig) local prefix, suffix = filename:match("^(.-%d%d%d%d%d%d%d%dT%d%d%d%d%d%d)(.*)") if not prefix then error("This doesn't look like a Denote filename") @@ -123,4 +121,16 @@ function M.signature(options, filename, sig) M.replace_file(filename, new_filename) end +---@param filename string +---@param ext string +---Replace the extension in the file with ext +function M.extension(filename, ext) + local prefix, _ = filename:match("^(.-%d%d%d%d%d%d%d%dT%d%d%d%d%d%d.*%.)(.+)$") + if not prefix then + error("This doesn't look like a Denote file") + end + local new_filename = prefix .. ext + M.replace_file(filename, new_filename) +end + return M |
