aboutsummaryrefslogtreecommitdiff
path: root/lua/simple-denote/api.lua
blob: f835b7b67352db2ad14286d4f48ded5ac1c29199 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
local M = {}

local internal = require("simple-denote.internal")
local util = require("simple-denote.util")

---@param options table
---@param name string|nil
---@param tags table|nil
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 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

---@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