mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
Merge pull request #268 from Sleepful/main
Create subdirs when creating new note
This commit is contained in:
@@ -70,7 +70,7 @@ telekasten.setup({opts})
|
|||||||
-- Main paths
|
-- Main paths
|
||||||
home = '/path/to/directory', -- path to main notes folder
|
home = '/path/to/directory', -- path to main notes folder
|
||||||
daily = '/path/to/directory', -- path to daily notes
|
daily = '/path/to/directory', -- path to daily notes
|
||||||
weekly = '/path/to/directory', -- path to weekly notes
|
weeklies = '/path/to/directory', -- path to weekly notes
|
||||||
templates = '/path/to/directory', -- path to templates
|
templates = '/path/to/directory', -- path to templates
|
||||||
|
|
||||||
-- Specific note templates
|
-- Specific note templates
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ local function generate_note_filename(uuid, title)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function check_dir_and_ask(dir, purpose)
|
local function check_dir_and_ask(dir, purpose, callback)
|
||||||
local ret = false
|
local ret = false
|
||||||
if dir ~= nil and Path:new(dir):exists() == false then
|
if dir ~= nil and Path:new(dir):exists() == false then
|
||||||
vim.ui.select({ "No (default)", "Yes" }, {
|
vim.ui.select({ "No (default)", "Yes" }, {
|
||||||
@@ -201,34 +201,44 @@ local function check_dir_and_ask(dir, purpose)
|
|||||||
vim.cmd('echomsg " "')
|
vim.cmd('echomsg " "')
|
||||||
vim.cmd('echomsg "' .. dir .. ' created"')
|
vim.cmd('echomsg "' .. dir .. ' created"')
|
||||||
ret = true
|
ret = true
|
||||||
|
callback(ret)
|
||||||
else
|
else
|
||||||
-- unreachable: plenary.Path:mkdir() will error out
|
-- unreachable: plenary.Path:mkdir() will error out
|
||||||
tkutils.print_error("Could not create directory " .. dir)
|
tkutils.print_error("Could not create directory " .. dir)
|
||||||
ret = false
|
ret = false
|
||||||
|
callback(ret)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
ret = true
|
ret = true
|
||||||
|
if callback ~= nil then
|
||||||
|
callback(ret)
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function global_dir_check()
|
local function global_dir_check(callback)
|
||||||
local ret
|
local ret
|
||||||
if M.Cfg.home == nil then
|
if M.Cfg.home == nil then
|
||||||
tkutils.print_error("Telekasten.nvim: home is not configured!")
|
tkutils.print_error("Telekasten.nvim: home is not configured!")
|
||||||
ret = false
|
ret = false
|
||||||
else
|
callback(ret)
|
||||||
ret = check_dir_and_ask(M.Cfg.home, "home")
|
|
||||||
end
|
end
|
||||||
|
local check = check_dir_and_ask
|
||||||
ret = ret and check_dir_and_ask(M.Cfg.dailies, "dailies")
|
-- nested callbacks to handle asynchronous vim.ui.select
|
||||||
ret = ret and check_dir_and_ask(M.Cfg.weeklies, "weeklies")
|
-- looks a little confusing but execution is sequential from top to bottom
|
||||||
ret = ret and check_dir_and_ask(M.Cfg.templates, "templates")
|
check(M.Cfg.home, "home", function()
|
||||||
ret = ret and check_dir_and_ask(M.Cfg.image_subdir, "images")
|
check(M.Cfg.dailies, "dailies", function()
|
||||||
|
check(M.Cfg.weeklies, "weeklies", function()
|
||||||
return ret
|
check(M.Cfg.templates, "templates", function()
|
||||||
|
-- Note the `callback` in this last function call
|
||||||
|
check(M.Cfg.image_subdir, "images", callback)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make_config_path_absolute(path)
|
local function make_config_path_absolute(path)
|
||||||
@@ -245,7 +255,8 @@ local function make_config_path_absolute(path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function recursive_substitution(dir, old, new)
|
local function recursive_substitution(dir, old, new)
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -275,6 +286,7 @@ local function recursive_substitution(dir, old, new)
|
|||||||
.. new
|
.. new
|
||||||
.. "\\2|g' >/dev/null 2>&1"
|
.. "\\2|g' >/dev/null 2>&1"
|
||||||
os.execute(replace_cmd)
|
os.execute(replace_cmd)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function save_all_mod_buffers()
|
local function save_all_mod_buffers()
|
||||||
@@ -341,7 +353,8 @@ local function make_relative_path(bufferpath, imagepath, sep)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function imgFromClipboard()
|
local function imgFromClipboard()
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -428,6 +441,7 @@ local function imgFromClipboard()
|
|||||||
else
|
else
|
||||||
vim.api.nvim_err_writeln("Unable to write image " .. png)
|
vim.api.nvim_err_writeln("Unable to write image " .. png)
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- end of image stuff
|
-- end of image stuff
|
||||||
@@ -437,7 +451,8 @@ local function create_note_from_template(
|
|||||||
uuid,
|
uuid,
|
||||||
filepath,
|
filepath,
|
||||||
templatefn,
|
templatefn,
|
||||||
calendar_info
|
calendar_info,
|
||||||
|
callback
|
||||||
)
|
)
|
||||||
-- first, read the template file
|
-- first, read the template file
|
||||||
local lines = {}
|
local lines = {}
|
||||||
@@ -448,7 +463,14 @@ local function create_note_from_template(
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- now write the output file, substituting vars line by line
|
-- now write the output file, substituting vars line by line
|
||||||
|
local file_dir = filepath:match("(.*/)") or ""
|
||||||
|
check_dir_and_ask(file_dir, "Create weekly dir", function(dir_succeed)
|
||||||
|
if dir_succeed == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local ofile = io.open(filepath, "a")
|
local ofile = io.open(filepath, "a")
|
||||||
|
|
||||||
for _, line in pairs(lines) do
|
for _, line in pairs(lines) do
|
||||||
ofile:write(
|
ofile:write(
|
||||||
templates.subst_templated_values(
|
templates.subst_templated_values(
|
||||||
@@ -463,6 +485,8 @@ local function create_note_from_template(
|
|||||||
|
|
||||||
ofile:flush()
|
ofile:flush()
|
||||||
ofile:close()
|
ofile:close()
|
||||||
|
callback()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Pinfo
|
--- Pinfo
|
||||||
@@ -710,10 +734,6 @@ function Pinfo:resolve_link(title, opts)
|
|||||||
-- final round, there still can be a subdir mess-up
|
-- final round, there still can be a subdir mess-up
|
||||||
if not Path:new(self.filepath):parent():exists() then
|
if not Path:new(self.filepath):parent():exists() then
|
||||||
print("Path " .. self.filepath .. " is invalid!")
|
print("Path " .. self.filepath .. " is invalid!")
|
||||||
-- local fname_only = Path:new(self.filename):_split()
|
|
||||||
-- fname_only = fname_only[#fname_only]
|
|
||||||
-- self.filepath = opts.home .. "/" .. fname_only
|
|
||||||
self.filepath = ""
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1113,13 +1133,34 @@ local function FindDailyNotes(opts)
|
|||||||
opts.close_after_yanking = opts.close_after_yanking
|
opts.close_after_yanking = opts.close_after_yanking
|
||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local today = os.date(dateutils.dateformats.date)
|
local today = os.date(dateutils.dateformats.date)
|
||||||
local fname = M.Cfg.dailies .. "/" .. today .. M.Cfg.extension
|
local fname = M.Cfg.dailies .. "/" .. today .. M.Cfg.extension
|
||||||
local fexists = fileutils.file_exists(fname)
|
local fexists = fileutils.file_exists(fname)
|
||||||
|
local function picker()
|
||||||
|
find_files_sorted({
|
||||||
|
prompt_title = "Find daily note",
|
||||||
|
cwd = M.Cfg.dailies,
|
||||||
|
find_command = M.Cfg.find_command,
|
||||||
|
attach_mappings = function(_, map)
|
||||||
|
actions.select_default:replace(
|
||||||
|
picker_actions.select_default
|
||||||
|
)
|
||||||
|
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||||
|
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||||
|
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||||
|
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||||
|
map("n", "<c-c>", picker_actions.close(opts))
|
||||||
|
map("n", "<esc>", picker_actions.close(opts))
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
|
})
|
||||||
|
end
|
||||||
if
|
if
|
||||||
(fexists ~= true)
|
(fexists ~= true)
|
||||||
and (
|
and (
|
||||||
@@ -1131,28 +1172,18 @@ local function FindDailyNotes(opts)
|
|||||||
today,
|
today,
|
||||||
nil,
|
nil,
|
||||||
fname,
|
fname,
|
||||||
M.note_type_templates.daily
|
M.note_type_templates.daily,
|
||||||
)
|
nil,
|
||||||
|
function()
|
||||||
opts.erase = true
|
opts.erase = true
|
||||||
opts.erase_file = fname
|
opts.erase_file = fname
|
||||||
|
picker()
|
||||||
end
|
end
|
||||||
|
)
|
||||||
find_files_sorted({
|
return
|
||||||
prompt_title = "Find daily note",
|
end
|
||||||
cwd = M.Cfg.dailies,
|
picker()
|
||||||
find_command = M.Cfg.find_command,
|
end)
|
||||||
attach_mappings = function(_, map)
|
|
||||||
actions.select_default:replace(picker_actions.select_default)
|
|
||||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
|
||||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
|
||||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("n", "<c-c>", picker_actions.close(opts))
|
|
||||||
map("n", "<esc>", picker_actions.close(opts))
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
sort = M.Cfg.sort,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1168,13 +1199,36 @@ local function FindWeeklyNotes(opts)
|
|||||||
opts.close_after_yanking = opts.close_after_yanking
|
opts.close_after_yanking = opts.close_after_yanking
|
||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local title = os.date(dateutils.dateformats.isoweek)
|
local title = os.date(dateutils.dateformats.isoweek)
|
||||||
local fname = M.Cfg.weeklies .. "/" .. title .. M.Cfg.extension
|
local fname = M.Cfg.weeklies .. "/" .. title .. M.Cfg.extension
|
||||||
local fexists = fileutils.file_exists(fname)
|
local fexists = fileutils.file_exists(fname)
|
||||||
|
|
||||||
|
local function picker()
|
||||||
|
find_files_sorted({
|
||||||
|
prompt_title = "Find weekly note",
|
||||||
|
cwd = M.Cfg.weeklies,
|
||||||
|
find_command = M.Cfg.find_command,
|
||||||
|
attach_mappings = function(_, map)
|
||||||
|
actions.select_default:replace(
|
||||||
|
picker_actions.select_default
|
||||||
|
)
|
||||||
|
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||||
|
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||||
|
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||||
|
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||||
|
map("n", "<c-c>", picker_actions.close(opts))
|
||||||
|
map("n", "<esc>", picker_actions.close(opts))
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
if
|
if
|
||||||
(fexists ~= true)
|
(fexists ~= true)
|
||||||
and (
|
and (
|
||||||
@@ -1186,28 +1240,18 @@ local function FindWeeklyNotes(opts)
|
|||||||
title,
|
title,
|
||||||
nil,
|
nil,
|
||||||
fname,
|
fname,
|
||||||
M.note_type_templates.weekly
|
M.note_type_templates.weekly,
|
||||||
)
|
nil,
|
||||||
|
function()
|
||||||
opts.erase = true
|
opts.erase = true
|
||||||
opts.erase_file = fname
|
opts.erase_file = fname
|
||||||
|
picker()
|
||||||
end
|
end
|
||||||
|
)
|
||||||
find_files_sorted({
|
return
|
||||||
prompt_title = "Find weekly note",
|
end
|
||||||
cwd = M.Cfg.weeklies,
|
picker()
|
||||||
find_command = M.Cfg.find_command,
|
end)
|
||||||
attach_mappings = function(_, map)
|
|
||||||
actions.select_default:replace(picker_actions.select_default)
|
|
||||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
|
||||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
|
||||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("n", "<c-c>", picker_actions.close(opts))
|
|
||||||
map("n", "<esc>", picker_actions.close(opts))
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
sort = M.Cfg.sort,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1224,7 +1268,8 @@ local function InsertLink(opts)
|
|||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
opts.subdirs_in_links = opts.subdirs_in_links or M.Cfg.subdirs_in_links
|
opts.subdirs_in_links = opts.subdirs_in_links or M.Cfg.subdirs_in_links
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1239,7 +1284,12 @@ local function InsertLink(opts)
|
|||||||
filepath = selection.filename or selection.value,
|
filepath = selection.filename or selection.value,
|
||||||
opts,
|
opts,
|
||||||
})
|
})
|
||||||
vim.api.nvim_put({ "[[" .. pinfo.title .. "]]" }, "", false, true)
|
vim.api.nvim_put(
|
||||||
|
{ "[[" .. pinfo.title .. "]]" },
|
||||||
|
"",
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
)
|
||||||
if opts.i then
|
if opts.i then
|
||||||
vim.api.nvim_feedkeys("a", "m", false)
|
vim.api.nvim_feedkeys("a", "m", false)
|
||||||
end
|
end
|
||||||
@@ -1270,6 +1320,7 @@ local function InsertLink(opts)
|
|||||||
sort = sort,
|
sort = sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- local function check_for_link_or_tag()
|
-- local function check_for_link_or_tag()
|
||||||
@@ -1319,7 +1370,8 @@ local function PreviewImg(opts)
|
|||||||
opts.close_after_yanking = opts.close_after_yanking
|
opts.close_after_yanking = opts.close_after_yanking
|
||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1365,6 +1417,7 @@ local function PreviewImg(opts)
|
|||||||
else
|
else
|
||||||
print("File not found: " .. M.Cfg.home .. "/" .. fname)
|
print("File not found: " .. M.Cfg.home .. "/" .. fname)
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1380,7 +1433,8 @@ local function BrowseImg(opts)
|
|||||||
opts.close_after_yanking = opts.close_after_yanking
|
opts.close_after_yanking = opts.close_after_yanking
|
||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1412,6 +1466,7 @@ local function BrowseImg(opts)
|
|||||||
end,
|
end,
|
||||||
sort = M.Cfg.sort,
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1427,7 +1482,8 @@ local function FindFriends(opts)
|
|||||||
opts.close_after_yanking = opts.close_after_yanking
|
opts.close_after_yanking = opts.close_after_yanking
|
||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1455,6 +1511,7 @@ local function FindFriends(opts)
|
|||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1471,6 +1528,31 @@ local function YankLink()
|
|||||||
print("yanked " .. title)
|
print("yanked " .. title)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function rename_update_links(oldfile, newname)
|
||||||
|
if M.Cfg.rename_update_links == true then
|
||||||
|
-- Only look for the first part of the link, so we do not touch to #heading or #^paragraph
|
||||||
|
-- Should use regex instead to ensure it is a proper link
|
||||||
|
local oldlink = "[[" .. oldfile.title
|
||||||
|
local newlink = "[[" .. newname
|
||||||
|
|
||||||
|
-- Save open buffers before looking for links to replace
|
||||||
|
if #(vim.fn.getbufinfo({ bufmodified = 1 })) > 1 then
|
||||||
|
vim.ui.select({ "Yes (default)", "No" }, {
|
||||||
|
prompt = "Telekasten.nvim: "
|
||||||
|
.. "Save all modified buffers before updating links?",
|
||||||
|
}, function(answer)
|
||||||
|
if answer ~= "No" then
|
||||||
|
save_all_mod_buffers()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
recursive_substitution(M.Cfg.home, oldlink, newlink)
|
||||||
|
recursive_substitution(M.Cfg.dailies, oldlink, newlink)
|
||||||
|
recursive_substitution(M.Cfg.weeklies, oldlink, newlink)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- RenameNote:
|
-- RenameNote:
|
||||||
-- -----------
|
-- -----------
|
||||||
@@ -1502,7 +1584,8 @@ local function RenameNote()
|
|||||||
|
|
||||||
-- Savas newfile, delete buffer of old one and remove old file
|
-- Savas newfile, delete buffer of old one and remove old file
|
||||||
if newname ~= "" and newname ~= oldfile.title then
|
if newname ~= "" and newname ~= oldfile.title then
|
||||||
if not (check_dir_and_ask(newpath, "Renamed file")) then
|
check_dir_and_ask(newpath, "Renamed file", function(success)
|
||||||
|
if not success then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1514,29 +1597,10 @@ local function RenameNote()
|
|||||||
os.execute(
|
os.execute(
|
||||||
"rm " .. M.Cfg.home .. "/" .. oldTitle .. M.Cfg.extension
|
"rm " .. M.Cfg.home .. "/" .. oldTitle .. M.Cfg.extension
|
||||||
)
|
)
|
||||||
end
|
rename_update_links(oldfile, newname)
|
||||||
|
|
||||||
if M.Cfg.rename_update_links == true then
|
|
||||||
-- Only look for the first part of the link, so we do not touch to #heading or #^paragraph
|
|
||||||
-- Should use regex instead to ensure it is a proper link
|
|
||||||
local oldlink = "[[" .. oldfile.title
|
|
||||||
local newlink = "[[" .. newname
|
|
||||||
|
|
||||||
-- Save open buffers before looking for links to replace
|
|
||||||
if #(vim.fn.getbufinfo({ bufmodified = 1 })) > 1 then
|
|
||||||
vim.ui.select({ "Yes (default)", "No" }, {
|
|
||||||
prompt = "Telekasten.nvim: "
|
|
||||||
.. "Save all modified buffers before updating links?",
|
|
||||||
}, function(answer)
|
|
||||||
if answer ~= "No" then
|
|
||||||
save_all_mod_buffers()
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
end
|
else
|
||||||
|
rename_update_links(oldfile, newname)
|
||||||
recursive_substitution(M.Cfg.home, oldlink, newlink)
|
|
||||||
recursive_substitution(M.Cfg.dailies, oldlink, newlink)
|
|
||||||
recursive_substitution(M.Cfg.weeklies, oldlink, newlink)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -1562,24 +1626,7 @@ local function GotoDate(opts)
|
|||||||
|
|
||||||
local fname = M.Cfg.dailies .. "/" .. word .. M.Cfg.extension
|
local fname = M.Cfg.dailies .. "/" .. word .. M.Cfg.extension
|
||||||
local fexists = fileutils.file_exists(fname)
|
local fexists = fileutils.file_exists(fname)
|
||||||
if
|
local function picker()
|
||||||
(fexists ~= true)
|
|
||||||
and (
|
|
||||||
(opts.dailies_create_nonexisting == true)
|
|
||||||
or M.Cfg.dailies_create_nonexisting == true
|
|
||||||
)
|
|
||||||
then
|
|
||||||
create_note_from_template(
|
|
||||||
word,
|
|
||||||
nil,
|
|
||||||
fname,
|
|
||||||
M.note_type_templates.daily,
|
|
||||||
opts.dates
|
|
||||||
)
|
|
||||||
opts.erase = true
|
|
||||||
opts.erase_file = fname
|
|
||||||
end
|
|
||||||
|
|
||||||
if opts.journal_auto_open then
|
if opts.journal_auto_open then
|
||||||
vim.cmd("e " .. fname)
|
vim.cmd("e " .. fname)
|
||||||
else
|
else
|
||||||
@@ -1609,6 +1656,31 @@ local function GotoDate(opts)
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if
|
||||||
|
(fexists ~= true)
|
||||||
|
and (
|
||||||
|
(opts.dailies_create_nonexisting == true)
|
||||||
|
or M.Cfg.dailies_create_nonexisting == true
|
||||||
|
)
|
||||||
|
then
|
||||||
|
create_note_from_template(
|
||||||
|
word,
|
||||||
|
nil,
|
||||||
|
fname,
|
||||||
|
M.note_type_templates.daily,
|
||||||
|
opts.dates,
|
||||||
|
function()
|
||||||
|
opts.erase = true
|
||||||
|
opts.erase_file = fname
|
||||||
|
picker()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
picker()
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1620,7 +1692,8 @@ end
|
|||||||
local function GotoToday(opts)
|
local function GotoToday(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1629,6 +1702,7 @@ local function GotoToday(opts)
|
|||||||
opts.date = today
|
opts.date = today
|
||||||
opts.dailies_create_nonexisting = true -- Always use template for GotoToday
|
opts.dailies_create_nonexisting = true -- Always use template for GotoToday
|
||||||
GotoDate(opts)
|
GotoDate(opts)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1644,7 +1718,8 @@ local function FindNotes(opts)
|
|||||||
opts.close_after_yanking = opts.close_after_yanking
|
opts.close_after_yanking = opts.close_after_yanking
|
||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1681,6 +1756,7 @@ local function FindNotes(opts)
|
|||||||
sort = sort,
|
sort = sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1692,7 +1768,8 @@ end
|
|||||||
local function InsertImgLink(opts)
|
local function InsertImgLink(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1731,6 +1808,7 @@ local function InsertImgLink(opts)
|
|||||||
end,
|
end,
|
||||||
sort = M.Cfg.sort,
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1746,7 +1824,8 @@ local function SearchNotes(opts)
|
|||||||
opts.close_after_yanking = opts.close_after_yanking
|
opts.close_after_yanking = opts.close_after_yanking
|
||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1767,6 +1846,7 @@ local function SearchNotes(opts)
|
|||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1782,11 +1862,13 @@ local function ShowBacklinks(opts)
|
|||||||
opts.close_after_yanking = opts.close_after_yanking
|
opts.close_after_yanking = opts.close_after_yanking
|
||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local title = Pinfo:new({ filepath = vim.fn.expand("%:p"), M.Cfg }).title
|
local title =
|
||||||
|
Pinfo:new({ filepath = vim.fn.expand("%:p"), M.Cfg }).title
|
||||||
-- or vim.api.nvim_buf_get_name(0)
|
-- or vim.api.nvim_buf_get_name(0)
|
||||||
builtin.live_grep({
|
builtin.live_grep({
|
||||||
results_title = "Backlinks to " .. title,
|
results_title = "Backlinks to " .. title,
|
||||||
@@ -1806,6 +1888,7 @@ local function ShowBacklinks(opts)
|
|||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1857,11 +1940,13 @@ local function on_create_with_template(opts, title)
|
|||||||
uuid,
|
uuid,
|
||||||
fname,
|
fname,
|
||||||
template,
|
template,
|
||||||
pinfo.calendar_info
|
pinfo.calendar_info,
|
||||||
)
|
function()
|
||||||
-- open the new note
|
-- open the new note
|
||||||
vim.cmd("e " .. fname)
|
vim.cmd("e " .. fname)
|
||||||
picker_actions.post_open()
|
picker_actions.post_open()
|
||||||
|
end
|
||||||
|
)
|
||||||
end)
|
end)
|
||||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||||
@@ -1875,13 +1960,15 @@ end
|
|||||||
local function CreateNoteSelectTemplate(opts)
|
local function CreateNoteSelectTemplate(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
fileutils.prompt_title(M.Cfg.extension, nil, function(title)
|
fileutils.prompt_title(M.Cfg.extension, nil, function(title)
|
||||||
on_create_with_template(opts, title)
|
on_create_with_template(opts, title)
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1911,19 +1998,7 @@ local function on_create(opts, title)
|
|||||||
})
|
})
|
||||||
local fname = pinfo.filepath
|
local fname = pinfo.filepath
|
||||||
|
|
||||||
if pinfo.fexists ~= true then
|
local function picker()
|
||||||
-- TODO: pass in the calendar_info returned in pinfo
|
|
||||||
create_note_from_template(
|
|
||||||
title,
|
|
||||||
uuid,
|
|
||||||
fname,
|
|
||||||
pinfo.template,
|
|
||||||
pinfo.calendar_info
|
|
||||||
)
|
|
||||||
opts.erase = true
|
|
||||||
opts.erase_file = fname
|
|
||||||
end
|
|
||||||
|
|
||||||
find_files_sorted({
|
find_files_sorted({
|
||||||
prompt_title = "Created note...",
|
prompt_title = "Created note...",
|
||||||
cwd = pinfo.root_dir,
|
cwd = pinfo.root_dir,
|
||||||
@@ -1940,12 +2015,32 @@ local function on_create(opts, title)
|
|||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
end
|
||||||
|
if pinfo.fexists ~= true then
|
||||||
|
-- TODO: pass in the calendar_info returned in pinfo
|
||||||
|
create_note_from_template(
|
||||||
|
title,
|
||||||
|
uuid,
|
||||||
|
fname,
|
||||||
|
pinfo.template,
|
||||||
|
pinfo.calendar_info,
|
||||||
|
function()
|
||||||
|
opts.erase = true
|
||||||
|
opts.erase_file = fname
|
||||||
|
picker()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
picker()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function CreateNote(opts)
|
local function CreateNote(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1956,6 +2051,7 @@ local function CreateNote(opts)
|
|||||||
fileutils.prompt_title(M.Cfg.extension, nil, function(title)
|
fileutils.prompt_title(M.Cfg.extension, nil, function(title)
|
||||||
on_create(opts, title)
|
on_create(opts, title)
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -1975,7 +2071,8 @@ local function FollowLink(opts)
|
|||||||
opts.new_note_location = opts.new_note_location or M.Cfg.new_note_location
|
opts.new_note_location = opts.new_note_location or M.Cfg.new_note_location
|
||||||
local uuid_type = opts.uuid_type or M.Cfg.uuid_type
|
local uuid_type = opts.uuid_type or M.Cfg.uuid_type
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2054,10 +2151,31 @@ local function FollowLink(opts)
|
|||||||
-- check if subdir exists
|
-- check if subdir exists
|
||||||
local filepath = title:match("(.*/)") or ""
|
local filepath = title:match("(.*/)") or ""
|
||||||
filepath = M.Cfg.home .. "/" .. filepath
|
filepath = M.Cfg.home .. "/" .. filepath
|
||||||
check_dir_and_ask(filepath, "")
|
check_dir_and_ask(filepath, "", function()
|
||||||
|
|
||||||
-- check if fname exists anywhere
|
-- check if fname exists anywhere
|
||||||
local pinfo = Pinfo:new({ title = title })
|
local pinfo = Pinfo:new({ title = title })
|
||||||
|
local function picker()
|
||||||
|
find_files_sorted({
|
||||||
|
prompt_title = "Follow link to note...",
|
||||||
|
cwd = pinfo.root_dir,
|
||||||
|
default_text = title,
|
||||||
|
find_command = M.Cfg.find_command,
|
||||||
|
attach_mappings = function(_, map)
|
||||||
|
actions.select_default:replace(
|
||||||
|
picker_actions.select_default
|
||||||
|
)
|
||||||
|
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||||
|
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||||
|
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||||
|
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||||
|
map("n", "<c-c>", picker_actions.close(opts))
|
||||||
|
map("n", "<esc>", picker_actions.close(opts))
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
if
|
if
|
||||||
(pinfo.fexists ~= true)
|
(pinfo.fexists ~= true)
|
||||||
and (
|
and (
|
||||||
@@ -2076,30 +2194,19 @@ local function FollowLink(opts)
|
|||||||
uuid,
|
uuid,
|
||||||
pinfo.filepath,
|
pinfo.filepath,
|
||||||
pinfo.template,
|
pinfo.template,
|
||||||
pinfo.calendar_info
|
pinfo.calendar_info,
|
||||||
)
|
function()
|
||||||
opts.erase = true
|
opts.erase = true
|
||||||
opts.erase_file = pinfo.filepath
|
opts.erase_file = pinfo.filepath
|
||||||
|
picker()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
find_files_sorted({
|
picker()
|
||||||
prompt_title = "Follow link to note...",
|
end)
|
||||||
cwd = pinfo.root_dir,
|
|
||||||
default_text = title,
|
|
||||||
find_command = M.Cfg.find_command,
|
|
||||||
attach_mappings = function(_, map)
|
|
||||||
actions.select_default:replace(picker_actions.select_default)
|
|
||||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
|
||||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
|
||||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("n", "<c-c>", picker_actions.close(opts))
|
|
||||||
map("n", "<esc>", picker_actions.close(opts))
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
sort = M.Cfg.sort,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if search_mode ~= "files" then
|
if search_mode ~= "files" then
|
||||||
@@ -2124,7 +2231,8 @@ local function FollowLink(opts)
|
|||||||
local display =
|
local display =
|
||||||
utils.transform_path(display_opts, display_entry.value)
|
utils.transform_path(display_opts, display_entry.value)
|
||||||
|
|
||||||
display_entry.filn = display_entry.filn or display:gsub(":.*", "")
|
display_entry.filn = display_entry.filn
|
||||||
|
or display:gsub(":.*", "")
|
||||||
display, hl_group =
|
display, hl_group =
|
||||||
utils.transform_devicons(display_entry.filn, display, false)
|
utils.transform_devicons(display_entry.filn, display, false)
|
||||||
|
|
||||||
@@ -2263,7 +2371,8 @@ local function FollowLink(opts)
|
|||||||
if Path:new(t.filename):is_absolute() then
|
if Path:new(t.filename):is_absolute() then
|
||||||
return t.filename, false
|
return t.filename, false
|
||||||
else
|
else
|
||||||
return Path:new({ t.cwd, t.filename }):absolute(), false
|
return Path:new({ t.cwd, t.filename }):absolute(),
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
filename = function(t)
|
filename = function(t)
|
||||||
@@ -2385,7 +2494,9 @@ local function FollowLink(opts)
|
|||||||
previewer = conf.grep_previewer(opts),
|
previewer = conf.grep_previewer(opts),
|
||||||
sorter = sorters.highlighter_only(opts),
|
sorter = sorters.highlighter_only(opts),
|
||||||
attach_mappings = function(_, map)
|
attach_mappings = function(_, map)
|
||||||
actions.select_default:replace(picker_actions.select_default)
|
actions.select_default:replace(
|
||||||
|
picker_actions.select_default
|
||||||
|
)
|
||||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||||
@@ -2397,6 +2508,7 @@ local function FollowLink(opts)
|
|||||||
})
|
})
|
||||||
picker:find()
|
picker:find()
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -2413,7 +2525,8 @@ local function GotoThisWeek(opts)
|
|||||||
or M.Cfg.close_after_yanking
|
or M.Cfg.close_after_yanking
|
||||||
opts.journal_auto_open = opts.journal_auto_open or M.Cfg.journal_auto_open
|
opts.journal_auto_open = opts.journal_auto_open or M.Cfg.journal_auto_open
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2422,6 +2535,31 @@ local function GotoThisWeek(opts)
|
|||||||
local title = dinfo.isoweek
|
local title = dinfo.isoweek
|
||||||
local fname = M.Cfg.weeklies .. "/" .. title .. M.Cfg.extension
|
local fname = M.Cfg.weeklies .. "/" .. title .. M.Cfg.extension
|
||||||
local fexists = fileutils.file_exists(fname)
|
local fexists = fileutils.file_exists(fname)
|
||||||
|
local function picker()
|
||||||
|
if opts.journal_auto_open then
|
||||||
|
vim.cmd("e " .. fname)
|
||||||
|
else
|
||||||
|
find_files_sorted({
|
||||||
|
prompt_title = "Goto this week:",
|
||||||
|
cwd = M.Cfg.weeklies,
|
||||||
|
default_text = title,
|
||||||
|
find_command = M.Cfg.find_command,
|
||||||
|
attach_mappings = function(_, map)
|
||||||
|
actions.select_default:replace(
|
||||||
|
picker_actions.select_default
|
||||||
|
)
|
||||||
|
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||||
|
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||||
|
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||||
|
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||||
|
map("n", "<c-c>", picker_actions.close(opts))
|
||||||
|
map("n", "<esc>", picker_actions.close(opts))
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if
|
if
|
||||||
(fexists ~= true)
|
(fexists ~= true)
|
||||||
and (
|
and (
|
||||||
@@ -2433,32 +2571,19 @@ local function GotoThisWeek(opts)
|
|||||||
title,
|
title,
|
||||||
nil,
|
nil,
|
||||||
fname,
|
fname,
|
||||||
M.note_type_templates.weekly
|
M.note_type_templates.weekly,
|
||||||
)
|
nil,
|
||||||
|
function()
|
||||||
opts.erase = true
|
opts.erase = true
|
||||||
opts.erase_file = fname
|
opts.erase_file = fname
|
||||||
|
picker()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.journal_auto_open then
|
picker()
|
||||||
vim.cmd("e " .. fname)
|
end)
|
||||||
else
|
|
||||||
find_files_sorted({
|
|
||||||
prompt_title = "Goto this week:",
|
|
||||||
cwd = M.Cfg.weeklies,
|
|
||||||
default_text = title,
|
|
||||||
find_command = M.Cfg.find_command,
|
|
||||||
attach_mappings = function(_, map)
|
|
||||||
actions.select_default:replace(picker_actions.select_default)
|
|
||||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
|
||||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
|
||||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("n", "<c-c>", picker_actions.close(opts))
|
|
||||||
map("n", "<esc>", picker_actions.close(opts))
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -2613,7 +2738,8 @@ local function FindAllTags(opts)
|
|||||||
opts.templateDir = templateDir
|
opts.templateDir = templateDir
|
||||||
opts.rg_pcre = M.Cfg.rg_pcre
|
opts.rg_pcre = M.Cfg.rg_pcre
|
||||||
|
|
||||||
if not global_dir_check() then
|
global_dir_check(function(dir_check)
|
||||||
|
if not dir_check then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2697,6 +2823,7 @@ local function FindAllTags(opts)
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:find()
|
:find()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Setup(cfg)
|
-- Setup(cfg)
|
||||||
|
|||||||
Reference in New Issue
Block a user