implement #3: show backlinks

This commit is contained in:
Rene Schallner
2021-11-27 14:28:49 +01:00
parent faa11c125d
commit 9f286ae78e
4 changed files with 42 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
- [ ] yt video - [ ] yt video
## Dones ## Dones
- [x] show_backlinks() : issue #3
- [x] replaced `vim.ui.input` by `vim.fn.input`, as the former was causing problems on nvim 0.5.x - [x] replaced `vim.ui.input` by `vim.fn.input`, as the former was causing problems on nvim 0.5.x
- might not report on all closed issues here in the future as they are available in the issue tracker anyway - might not report on all closed issues here in the future as they are available in the issue tracker anyway
- [x] bugfixed and PRed calendar-vim: passing proper `week`(day) param from :CalendarT - [x] bugfixed and PRed calendar-vim: passing proper `week`(day) param from :CalendarT

View File

@@ -2,7 +2,19 @@
A Neovim (lua) plugin for working with a text-based, markdown [zettelkasten](https://takesmartnotes.com/) / Wiki and mixing it with a journal, based on [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim). A Neovim (lua) plugin for working with a text-based, markdown [zettelkasten](https://takesmartnotes.com/) / Wiki and mixing it with a journal, based on [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim).
Find notes by name, daily and weekly notes by date, search within all notes, place and follow links to your notes or create new ones, with templates. Current daily and weekly notes are (optionally) created if not present when searching for dailies or weeklies. Following a link to a non-existing note can also create the missing note (optional). #### Highlights:
- Find notes by name, daily and weekly notes by date
- search within all notes
- place and follow links to your notes or create new ones, with templates
- current daily and weekly notes are (optionally) created if not present when searching for dailies or weeklies
- following a link to a non-existing note can also create the missing note (optional)
- find notes **that link back to your notes**
- calendar support
- paste images from clipboard
- toggle [ ] todo status of line
---
Telekasten.nvim can optionally plug into [calendar-vim](https://github.com/renerocksai/calendar-vim): Selecting a day in the calendar will open up a telescope search with preview that lets you open the daily note (or cancel out and keep browsing your calendar). The daily note will be created if it doesn't exist. Days with daily notes get marked in the calendar. Telekasten.nvim can optionally plug into [calendar-vim](https://github.com/renerocksai/calendar-vim): Selecting a day in the calendar will open up a telescope search with preview that lets you open the daily note (or cancel out and keep browsing your calendar). The daily note will be created if it doesn't exist. Days with daily notes get marked in the calendar.
@@ -212,6 +224,7 @@ The plugin defines the following functions.
- `show_calendar()` : opens up the calendar in a properly-sized vertical split at the very right - `show_calendar()` : opens up the calendar in a properly-sized vertical split at the very right
- `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 - `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 `- `. - `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.
- `setup(opts)`: used for configuring paths, file extension, etc. - `setup(opts)`: used for configuring paths, file extension, etc.
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.
@@ -326,6 +339,7 @@ nnoremap <leader>zc :lua require('telekasten').show_calendar()<CR>
nnoremap <leader>zC :CalendarT<CR> nnoremap <leader>zC :CalendarT<CR>
nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR> nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR>
nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR> nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR>
" we could define [[ in **insert mode** to call insert link " we could define [[ in **insert mode** to call insert link
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR> " inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>

View File

@@ -409,6 +409,10 @@ telekasten.toggle_todo()~
Turns a line into a `- [ ] ` todo line, or toggle between `- [ ]`, `- [x]`, Turns a line into a `- [ ] ` todo line, or toggle between `- [ ]`, `- [x]`,
and `-` . and `-` .
*telekasten.show_backlinks()*
telekasten.show_backlinks()~
Opens a telescope search for notes that `[[link]]` back to the current note.
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Section 3.1: Templates *telekasten.templates* Section 3.1: Templates *telekasten.templates*
@@ -536,6 +540,7 @@ However, here are some suggestions:
nnoremap <leader>zC :CalendarT<CR> nnoremap <leader>zC :CalendarT<CR>
nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR> nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR>
nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR> nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR>
" we could define [[ in **insert mode** to call insert link " we could define [[ in **insert mode** to call insert link
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR> " inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>

View File

@@ -58,7 +58,6 @@ M.Cfg = {
local function file_exists(fname) local function file_exists(fname)
local f = io.open(fname, "r") local f = io.open(fname, "r")
-- print("checking for " .. fname)
if f ~= nil then if f ~= nil then
io.close(f) io.close(f)
return true return true
@@ -67,6 +66,7 @@ local function file_exists(fname)
end end
end end
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
-- image stuff -- image stuff
local imgFromClipboard = function() local imgFromClipboard = function()
@@ -255,7 +255,6 @@ local FindDailyNotes = function(opts)
opts = opts or {} opts = opts or {}
local today = os.date("%Y-%m-%d") local today = os.date("%Y-%m-%d")
print("dailies: ", M.Cfg.dailies)
local fname = M.Cfg.dailies .. "/" .. today .. M.Cfg.extension local fname = M.Cfg.dailies .. "/" .. today .. M.Cfg.extension
local fexists = file_exists(fname) local fexists = file_exists(fname)
if if
@@ -434,6 +433,25 @@ local SearchNotes = function(_)
}) })
end end
--
-- ShowBacklinks:
-- ------------
--
-- Find all notes linking to this one
--
local ShowBacklinks = function(_)
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",
cwd = M.Cfg.home,
search_dirs = { M.Cfg.home },
default_text = '\\[\\[' .. title .. '\\]\\]',
find_command = M.Cfg.find_command,
})
end
-- --
-- CreateNote: -- CreateNote:
-- ------------ -- ------------
@@ -630,8 +648,6 @@ local ToggleTodo = function()
-- - [x] by - -- - [x] by -
local linenr = vim.api.nvim_win_get_cursor(0)[1] local linenr = vim.api.nvim_win_get_cursor(0)[1]
local curline = vim.api.nvim_buf_get_lines(0, linenr - 1, linenr, false)[1] local curline = vim.api.nvim_buf_get_lines(0, linenr - 1, linenr, false)[1]
-- if curline.strip().startswith('- ') and not curline.strip.startswith('- [')...
-- print('cur: ' .. curline)
local stripped = vim.trim(curline) local stripped = vim.trim(curline)
local repline local repline
if vim.startswith(stripped, "- ") and not vim.startswith(stripped, "- [") then if vim.startswith(stripped, "- ") and not vim.startswith(stripped, "- [") then
@@ -648,7 +664,6 @@ local ToggleTodo = function()
end end
end end
vim.api.nvim_buf_set_lines(0, linenr - 1, linenr, false, { repline }) vim.api.nvim_buf_set_lines(0, linenr - 1, linenr, false, { repline })
-- print('rep: ' .. repl)
end end
-- Setup(cfg) -- Setup(cfg)
@@ -721,5 +736,6 @@ M.CalendarSignDay = CalendarSignDay
M.CalendarAction = CalendarAction M.CalendarAction = CalendarAction
M.paste_img_and_link = imgFromClipboard M.paste_img_and_link = imgFromClipboard
M.toggle_todo = ToggleTodo M.toggle_todo = ToggleTodo
M.show_backlinks = ShowBacklinks
return M return M