mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
add: basic note renaming
This commit is contained in:
@@ -304,6 +304,8 @@ require('telekasten').setup({
|
|||||||
-- except for notes/with/subdirs/in/title.
|
-- except for notes/with/subdirs/in/title.
|
||||||
new_note_location = "smart",
|
new_note_location = "smart",
|
||||||
|
|
||||||
|
-- should all links be updated when a file is renamed
|
||||||
|
rename_update_links = true,
|
||||||
})
|
})
|
||||||
END
|
END
|
||||||
```
|
```
|
||||||
@@ -338,6 +340,7 @@ END
|
|||||||
| | - `#tag` (default) | |
|
| | - `#tag` (default) | |
|
||||||
| | - `:tag:` | |
|
| | - `:tag:` | |
|
||||||
| | - `yaml-bare` | |
|
| | - `yaml-bare` | |
|
||||||
|
| `rename_update_links` | update links when a file is renamed | true |
|
||||||
| | see [2.1 Tag notation](#24-tag-notation)| |
|
| | see [2.1 Tag notation](#24-tag-notation)| |
|
||||||
| `command_palette_theme` | theme (layout) of the command palette| ivy |
|
| `command_palette_theme` | theme (layout) of the command palette| ivy |
|
||||||
| | - `ivy` (default): bottom panel overlay | |
|
| | - `ivy` (default): bottom panel overlay | |
|
||||||
@@ -463,6 +466,7 @@ the list for a more detailed description:
|
|||||||
- `insert_img_link` : Browse images / media files and insert a link to the selected one
|
- `insert_img_link` : Browse images / media files and insert a link to the selected one
|
||||||
- `preview_img` : preview image under the cursor
|
- `preview_img` : preview image under the cursor
|
||||||
- `browse_media` : Browse images / media files
|
- `browse_media` : Browse images / media files
|
||||||
|
- `rename_note` : Rename current note and possibly update the links pointing to it
|
||||||
|
|
||||||
The Telekasten command supports sub-command completion, in my case by pressing <kbd>TAB</kbd>.
|
The Telekasten command supports sub-command completion, in my case by pressing <kbd>TAB</kbd>.
|
||||||
|
|
||||||
@@ -558,6 +562,7 @@ The plugin defines the following functions:
|
|||||||
- `setup(opts)`: used for configuring paths, file extension, etc.
|
- `setup(opts)`: used for configuring paths, file extension, etc.
|
||||||
- `panel()` : brings up the command palette
|
- `panel()` : brings up the command palette
|
||||||
- `show_tags()` : brings up the tag list. From there you can select a tag to search for tagged notes - or yank or insert the tag
|
- `show_tags()` : brings up the tag list. From there you can select a tag to search for tagged notes - or yank or insert the tag
|
||||||
|
- `rename_note()` : rename the current note and update the links pointing to it
|
||||||
|
|
||||||
To use one of the functions above, just run them with the `:lua ...` command.
|
To use one of the functions above, just run them with the `:lua ...` command.
|
||||||
|
|
||||||
@@ -809,6 +814,7 @@ nnoremap <leader>zp :lua require('telekasten').preview_img()<CR>
|
|||||||
nnoremap <leader>zm :lua require('telekasten').browse_media()<CR>
|
nnoremap <leader>zm :lua require('telekasten').browse_media()<CR>
|
||||||
nnoremap <leader>za :lua require('telekasten').show_tags()<CR>
|
nnoremap <leader>za :lua require('telekasten').show_tags()<CR>
|
||||||
nnoremap <leader># :lua require('telekasten').show_tags()<CR>
|
nnoremap <leader># :lua require('telekasten').show_tags()<CR>
|
||||||
|
nnoremap <leader>zr :lua require('telekasten').rename_note()<CR>
|
||||||
|
|
||||||
" on hesitation, bring up the panel
|
" on hesitation, bring up the panel
|
||||||
nnoremap <leader>z :lua require('telekasten').panel()<CR>
|
nnoremap <leader>z :lua require('telekasten').panel()<CR>
|
||||||
|
|||||||
@@ -312,6 +312,12 @@ telekasten.setup({opts})
|
|||||||
|
|
||||||
Default: `smart`
|
Default: `smart`
|
||||||
|
|
||||||
|
*telekasten.settings.rename_update_links*
|
||||||
|
rename_update_links:~
|
||||||
|
If `true`, telekasten will automatically update the links after a file
|
||||||
|
has been renamed.
|
||||||
|
|
||||||
|
Default: `true`
|
||||||
*telekasten.calendar_opts*
|
*telekasten.calendar_opts*
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
Valid keys for {opts.calendar_opts}
|
Valid keys for {opts.calendar_opts}
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ M.Cfg = {
|
|||||||
-- present or else in home
|
-- present or else in home
|
||||||
-- except for notes/with/subdirs/in/title.
|
-- except for notes/with/subdirs/in/title.
|
||||||
new_note_location = "smart",
|
new_note_location = "smart",
|
||||||
|
|
||||||
|
-- should all links be updated when a file is renamed
|
||||||
|
rename_update_links = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function file_exists(fname)
|
local function file_exists(fname)
|
||||||
@@ -198,6 +201,20 @@ local function escape(s)
|
|||||||
return string.gsub(s, "[%%%]%^%-$().[*+?]", "%%%1")
|
return string.gsub(s, "[%%%]%^%-$().[*+?]", "%%%1")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function recursive_substitution(dir, old, new)
|
||||||
|
os.execute(
|
||||||
|
"find "
|
||||||
|
.. dir
|
||||||
|
.. " -type f -name '*"
|
||||||
|
.. M.Cfg.extension
|
||||||
|
.. "' -exec sed -i 's|"
|
||||||
|
.. old
|
||||||
|
.. "|"
|
||||||
|
.. new
|
||||||
|
.. "|g' {} +"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
-- ----------------------------------------------------------------------------
|
-- ----------------------------------------------------------------------------
|
||||||
-- image stuff
|
-- image stuff
|
||||||
local function imgFromClipboard()
|
local function imgFromClipboard()
|
||||||
@@ -1396,6 +1413,32 @@ local function YankLink()
|
|||||||
print("yanked " .. title)
|
print("yanked " .. title)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- RenameNote:
|
||||||
|
-- -----------
|
||||||
|
--
|
||||||
|
-- Prompt for new note title, rename the note and update all links.
|
||||||
|
--
|
||||||
|
local function RenameNote()
|
||||||
|
local oldname = Pinfo:new({ filepath = vim.fn.expand("%:p"), M.Cfg }).title
|
||||||
|
local newname = vim.fn.input("New name: ")
|
||||||
|
newname = newname:gsub("[" .. M.Cfg.extension .. "]+$", "")
|
||||||
|
|
||||||
|
if newname ~= "" and newname ~= oldname then
|
||||||
|
vim.cmd("saveas " .. newname .. M.Cfg.extension)
|
||||||
|
vim.cmd("bdelete " .. oldname .. M.Cfg.extension)
|
||||||
|
vim.cmd("!rm " .. oldname .. M.Cfg.extension)
|
||||||
|
vim.cmd("redraw!")
|
||||||
|
end
|
||||||
|
|
||||||
|
if M.Cfg.rename_update_links == true then
|
||||||
|
-- Sed magic to rename all links (in a separate function)
|
||||||
|
local oldlink = "\\[\\[" .. oldname .. "\\]\\]"
|
||||||
|
local newlink = "\\[\\[" .. newname .. "\\]\\]"
|
||||||
|
recursive_substitution(M.Cfg.home, oldlink, newlink)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- GotoDate:
|
-- GotoDate:
|
||||||
-- ----------
|
-- ----------
|
||||||
@@ -2564,6 +2607,7 @@ M.new_note = CreateNote
|
|||||||
M.goto_thisweek = GotoThisWeek
|
M.goto_thisweek = GotoThisWeek
|
||||||
M.find_weekly_notes = FindWeeklyNotes
|
M.find_weekly_notes = FindWeeklyNotes
|
||||||
M.yank_notelink = YankLink
|
M.yank_notelink = YankLink
|
||||||
|
M.rename_note = RenameNote
|
||||||
M.new_templated_note = CreateNoteSelectTemplate
|
M.new_templated_note = CreateNoteSelectTemplate
|
||||||
M.show_calendar = ShowCalendar
|
M.show_calendar = ShowCalendar
|
||||||
M.CalendarSignDay = CalendarSignDay
|
M.CalendarSignDay = CalendarSignDay
|
||||||
@@ -2592,6 +2636,7 @@ local TelekastenCmd = {
|
|||||||
{ "goto thisweek", "goto_thisweek", M.goto_thisweek },
|
{ "goto thisweek", "goto_thisweek", M.goto_thisweek },
|
||||||
{ "find weekly notes", "find_weekly_notes", M.find_weekly_notes },
|
{ "find weekly notes", "find_weekly_notes", M.find_weekly_notes },
|
||||||
{ "yank link to note", "yank_notelink", M.yank_notelink },
|
{ "yank link to note", "yank_notelink", M.yank_notelink },
|
||||||
|
{ "rename note", "rename_note", M.rename_note },
|
||||||
{
|
{
|
||||||
"new templated note",
|
"new templated note",
|
||||||
"new_templated_note",
|
"new_templated_note",
|
||||||
|
|||||||
Reference in New Issue
Block a user