mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
improve checks, save all buffers
This commit is contained in:
@@ -466,7 +466,7 @@ the list for a more detailed description:
|
||||
- `insert_img_link` : Browse images / media files and insert a link to the selected one
|
||||
- `preview_img` : preview image under the cursor
|
||||
- `browse_media` : Browse images / media files
|
||||
- `rename_note` : Rename current note and possibly update the links pointing to it
|
||||
- `rename_note` : Rename current note and update the links pointing to it
|
||||
|
||||
The Telekasten command supports sub-command completion, in my case by pressing <kbd>TAB</kbd>.
|
||||
|
||||
|
||||
@@ -202,21 +202,30 @@ local function escape(s)
|
||||
end
|
||||
|
||||
local function recursive_substitution(dir, old, new)
|
||||
if vim.fn.has("mac") == 1 or vim.fn.has("unix") == 1 then
|
||||
os.execute(
|
||||
"find "
|
||||
.. dir
|
||||
.. " -type f -name '*"
|
||||
.. M.Cfg.extension
|
||||
.. "' -exec sed -i 's|"
|
||||
.. old
|
||||
.. "|"
|
||||
.. new
|
||||
.. "|g' {} +"
|
||||
)
|
||||
else
|
||||
print("Cannot open update links on your operating system")
|
||||
if not global_dir_check() then
|
||||
return
|
||||
end
|
||||
|
||||
if vim.fn.executable("find") == 0 then
|
||||
vim.api.nvim_err_write("Find not installed!\n")
|
||||
return
|
||||
end
|
||||
if vim.fn.executable("sed") == 0 then
|
||||
vim.api.nvim_err_write("Sed not installed!\n")
|
||||
return
|
||||
end
|
||||
|
||||
os.execute(
|
||||
"find "
|
||||
.. dir
|
||||
.. " -type f -name '*"
|
||||
.. M.Cfg.extension
|
||||
.. "' -exec sed -i 's|"
|
||||
.. old
|
||||
.. "|"
|
||||
.. new
|
||||
.. "|g' {} +"
|
||||
)
|
||||
end
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
@@ -1431,11 +1440,12 @@ local function RenameNote()
|
||||
newname = newname:gsub("[" .. M.Cfg.extension .. "]+$", "")
|
||||
local newpath = newname:match("(.*/)")
|
||||
|
||||
-- If no subdir specified, place the new note in the same place as old note
|
||||
if M.Cfg.subdirs_in_links == true and newpath == nil and subdir ~= "" then
|
||||
newname = subdir .. "/" .. newname
|
||||
end
|
||||
|
||||
-- could probably be improved substantially
|
||||
-- Savas newfile, delete buffer of old one and remove old file
|
||||
if newname ~= "" and newname ~= oldname then
|
||||
vim.cmd("saveas " .. newname .. M.Cfg.extension)
|
||||
vim.cmd("bdelete " .. oldname .. M.Cfg.extension)
|
||||
@@ -1446,10 +1456,12 @@ local function RenameNote()
|
||||
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
|
||||
-- Should also account for other types of links (?)
|
||||
local oldlink = "\\[\\[" .. oldname
|
||||
local newlink = "\\[\\[" .. newname
|
||||
|
||||
-- Save all open buffers before looking for links to replace
|
||||
vim.cmd("wa")
|
||||
|
||||
recursive_substitution(M.Cfg.home, oldlink, newlink)
|
||||
recursive_substitution(M.Cfg.dailies, oldlink, newlink)
|
||||
recursive_substitution(M.Cfg.weeklies, oldlink, newlink)
|
||||
|
||||
Reference in New Issue
Block a user