aboutsummaryrefslogtreecommitdiff
path: root/lua/simple-denote/internal.lua
diff options
context:
space:
mode:
authorhistoria <gravel.justness270@slmail.me>2024-08-14 15:52:14 -0400
committerhistoria <gravel.justness270@slmail.me>2024-08-14 15:52:14 -0400
commit64b58e667d0d255439b055227f1f11012fcc9006 (patch)
tree9ce5c173ff05af0e647a4a00b04c59e54c701fa3 /lua/simple-denote/internal.lua
parent8da26902f526a54c8873d16d1b7b6e7820fb293b (diff)
downloadsimple-denote.nvim-64b58e667d0d255439b055227f1f11012fcc9006.tar.gz
Feature: Command to change file extension
Diffstat (limited to 'lua/simple-denote/internal.lua')
-rw-r--r--lua/simple-denote/internal.lua18
1 files changed, 14 insertions, 4 deletions
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