diff --git a/README.md b/README.md index a8330db..ef310b8 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ A Neovim (lua) plugin for working with a text-based, markdown [zettelkasten](htt - calendar support - paste images from clipboard - toggle [ ] todo status of line +- show back-links and notes also referencing links --- @@ -225,6 +226,7 @@ The plugin defines the following functions. - `paste_img_and_link()` : pastes an image from the clipboard into a file under `image_subdir` and inserts a link to it at the current cursor position - `toggle_todo()` : turn a line into a `- [ ] ` line, or toggle between `- [ ]`, `- [x]`, and `- `. - `show_backlinks()` : opens a telescope search for notes that `[[link]]` back to the current note. +- `find_friends()` : opens a telescope search for notes that also `[[link]]` to the link under the cursor. - `setup(opts)`: used for configuring paths, file extension, etc. To use one of the functions above, just run them with the `:lua ...` command. diff --git a/doc/telekasten.txt b/doc/telekasten.txt index e0d9abc..855c584 100644 --- a/doc/telekasten.txt +++ b/doc/telekasten.txt @@ -413,6 +413,11 @@ telekasten.toggle_todo()~ telekasten.show_backlinks()~ Opens a telescope search for notes that `[[link]]` back to the current note. + *telekasten.find_friends()* +telekasten.find_friends()~ + Opens a telescope search for notes that also `[[link]]` to the link under the + cursor. + -------------------------------------------------------------------------------- Section 3.1: Templates *telekasten.templates* diff --git a/lua/telekasten.lua b/lua/telekasten.lua index cce468e..fa92055 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -66,7 +66,6 @@ local function file_exists(fname) end end - -- ---------------------------------------------------------------------------- -- image stuff local imgFromClipboard = function() @@ -352,6 +351,24 @@ local FollowLink = function(opts) }) end +-- +-- FindFriends: +-- ----------- +-- +-- Find notes also linking to the link under cursor +-- +local FindFriends = function() + vim.cmd("normal yi]") + local title = vim.fn.getreg('"0') + + builtin.live_grep({ + prompt_title = "Notes referencing `" .. title .. "`", + cwd = M.Cfg.home, + default_text = "\\[\\[" .. title .. "\\]\\]", + find_command = M.Cfg.find_command, + }) +end + -- -- YankLink: -- ----------- @@ -440,14 +457,14 @@ end -- Find all notes linking to this one -- local ShowBacklinks = function(_) - local title = path_to_linkname(vim.fn.expand('%')) + local title = path_to_linkname(vim.fn.expand("%")) -- or vim.api.nvim_buf_get_name(0) builtin.live_grep({ results_title = "Backlinks to " .. title, - prompt_title = "Search", + prompt_title = "Search", cwd = M.Cfg.home, search_dirs = { M.Cfg.home }, - default_text = '\\[\\[' .. title .. '\\]\\]', + default_text = "\\[\\[" .. title .. "\\]\\]", find_command = M.Cfg.find_command, }) end @@ -737,5 +754,6 @@ M.CalendarAction = CalendarAction M.paste_img_and_link = imgFromClipboard M.toggle_todo = ToggleTodo M.show_backlinks = ShowBacklinks +M.find_friends = FindFriends return M