aboutsummaryrefslogtreecommitdiff
path: root/lua/simple-denote
diff options
context:
space:
mode:
Diffstat (limited to 'lua/simple-denote')
-rw-r--r--lua/simple-denote/api.lua25
-rw-r--r--lua/simple-denote/internal.lua18
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