mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 14:14:24 -05:00
fix: old file deletion and link update
- Old file properly deleted after renaming no matter where we are in the zettelkasten tree. - Workaround links with `#heading` and `#^paragraph` by only looking for the first elements of the link. Ideally it should be a proper regex
This commit is contained in:
@@ -1424,18 +1424,27 @@ local function RenameNote()
|
|||||||
local newname = vim.fn.input("New name: ")
|
local newname = vim.fn.input("New name: ")
|
||||||
newname = newname:gsub("[" .. M.Cfg.extension .. "]+$", "")
|
newname = newname:gsub("[" .. M.Cfg.extension .. "]+$", "")
|
||||||
|
|
||||||
|
-- oldname should include subdir if subdirs_in_links = true
|
||||||
|
-- newname should automatically add subdir if subdirs_in_links = true and user did not add it themselves
|
||||||
|
|
||||||
|
-- could probably be improved substantially
|
||||||
if newname ~= "" and newname ~= oldname then
|
if newname ~= "" and newname ~= oldname then
|
||||||
vim.cmd("saveas " .. newname .. M.Cfg.extension)
|
vim.cmd("saveas " .. newname .. M.Cfg.extension)
|
||||||
vim.cmd("bdelete " .. oldname .. M.Cfg.extension)
|
vim.cmd("bdelete " .. oldname .. M.Cfg.extension)
|
||||||
vim.cmd("!rm " .. oldname .. M.Cfg.extension)
|
os.execute("rm " .. M.Cfg.home .. "/" .. oldname .. M.Cfg.extension)
|
||||||
vim.cmd("redraw!")
|
vim.cmd("redraw!")
|
||||||
end
|
end
|
||||||
|
|
||||||
if M.Cfg.rename_update_links == true then
|
if M.Cfg.rename_update_links == true then
|
||||||
-- Sed magic to rename all links (in a separate function)
|
-- Only look for the first part of the link, so we do not touch to #heading or #^paragraph
|
||||||
local oldlink = "\\[\\[" .. oldname .. "\\]\\]"
|
-- Should use regex instead to ensure it is a proper link
|
||||||
local newlink = "\\[\\[" .. newname .. "\\]\\]"
|
-- Should also account for other types of links (?)
|
||||||
|
local oldlink = "\\[\\[" .. oldname
|
||||||
|
local newlink = "\\[\\[" .. newname
|
||||||
|
|
||||||
recursive_substitution(M.Cfg.home, oldlink, newlink)
|
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user