aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDefaultGen <gravel.justness270@slmail.me>2024-06-06 04:55:50 -0400
committerDefaultGen <gravel.justness270@slmail.me>2024-06-06 04:55:50 -0400
commit15389262bfb4ba280fc1aa1b0dd688947aa00f80 (patch)
tree45700b04fa8bec3cb523b6d95056c1aee92ce14f
parentdd178bb90f501297c3b5e714f95d0f233a4303a4 (diff)
downloadsimple-denote.nvim-15389262bfb4ba280fc1aa1b0dd688947aa00f80.tar.gz
Change filenames
-rw-r--r--README.md2
-rw-r--r--lua/simple-denote.lua46
2 files changed, 47 insertions, 1 deletions
diff --git a/README.md b/README.md
index dae6c5c..0fc6e8d 100644
--- a/README.md
+++ b/README.md
@@ -62,7 +62,7 @@ require('simple-denote').setup({
dir = "~/notes",
add_heading = true,
retitle_heading = true,
-}
+})
```
### Manual upgrade
diff --git a/lua/simple-denote.lua b/lua/simple-denote.lua
new file mode 100644
index 0000000..3f199fe
--- /dev/null
+++ b/lua/simple-denote.lua
@@ -0,0 +1,46 @@
+local M = {}
+
+local api = require("simple-denote.api")
+local config = require("simple-denote.config")
+
+function M.load_cmd(options)
+ vim.api.nvim_create_user_command("Denote", function(opts)
+ if opts.fargs[1] == "note" then
+ api.note(options)
+ elseif opts.fargs[1] == "title" then
+ api.title(options)
+ elseif opts.fargs[1] == "tag" then
+ api.tag(options)
+ elseif opts.fargs[1] == "signature" then
+ api.signature(options)
+ else
+ error("Unsupported operation " .. opts.fargs[1])
+ end
+ end, {
+ nargs = 1,
+ complete = function()
+ return { "note", "title", "tag", "signature" }
+ end,
+ })
+end
+
+---Add / to directory if necessary and set the heading_char based on the ext
+function M.fix_options()
+ if config.options.dir:sub(-1) ~= "/" then
+ config.options.dir = config.options.dir .. "/"
+ end
+ if config.options.ext == "md" then
+ config.options.heading_char = "#"
+ elseif config.options.ext == "org" or config.options.ext == "norg" then
+ config.options.heading_char = "*"
+ end
+end
+
+---@param options? table user configuration
+function M.setup(options)
+ config.options = vim.tbl_deep_extend("force", config.defaults, options or {})
+ M.fix_options()
+ M.load_cmd(config.options)
+end
+
+return M