mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
implement #3: show backlinks
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
- [ ] yt video
|
||||
|
||||
## 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
|
||||
- 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
|
||||
|
||||
16
README.md
16
README.md
@@ -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).
|
||||
|
||||
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.
|
||||
|
||||
@@ -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
|
||||
- `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.
|
||||
- `setup(opts)`: used for configuring paths, file extension, etc.
|
||||
|
||||
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>zi :lua require('telekasten').paste_img_and_link()<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
|
||||
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>
|
||||
|
||||
@@ -409,6 +409,10 @@ telekasten.toggle_todo()~
|
||||
Turns a line into a `- [ ] ` todo line, or toggle between `- [ ]`, `- [x]`,
|
||||
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*
|
||||
|
||||
@@ -536,6 +540,7 @@ However, here are some suggestions:
|
||||
nnoremap <leader>zC :CalendarT<CR>
|
||||
nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<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
|
||||
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>
|
||||
|
||||
@@ -58,7 +58,6 @@ M.Cfg = {
|
||||
|
||||
local function file_exists(fname)
|
||||
local f = io.open(fname, "r")
|
||||
-- print("checking for " .. fname)
|
||||
if f ~= nil then
|
||||
io.close(f)
|
||||
return true
|
||||
@@ -67,6 +66,7 @@ local function file_exists(fname)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- image stuff
|
||||
local imgFromClipboard = function()
|
||||
@@ -255,7 +255,6 @@ local FindDailyNotes = function(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local today = os.date("%Y-%m-%d")
|
||||
print("dailies: ", M.Cfg.dailies)
|
||||
local fname = M.Cfg.dailies .. "/" .. today .. M.Cfg.extension
|
||||
local fexists = file_exists(fname)
|
||||
if
|
||||
@@ -434,6 +433,25 @@ local SearchNotes = function(_)
|
||||
})
|
||||
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:
|
||||
-- ------------
|
||||
@@ -630,8 +648,6 @@ local ToggleTodo = function()
|
||||
-- - [x] by -
|
||||
local linenr = vim.api.nvim_win_get_cursor(0)[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 repline
|
||||
if vim.startswith(stripped, "- ") and not vim.startswith(stripped, "- [") then
|
||||
@@ -648,7 +664,6 @@ local ToggleTodo = function()
|
||||
end
|
||||
end
|
||||
vim.api.nvim_buf_set_lines(0, linenr - 1, linenr, false, { repline })
|
||||
-- print('rep: ' .. repl)
|
||||
end
|
||||
|
||||
-- Setup(cfg)
|
||||
@@ -721,5 +736,6 @@ M.CalendarSignDay = CalendarSignDay
|
||||
M.CalendarAction = CalendarAction
|
||||
M.paste_img_and_link = imgFromClipboard
|
||||
M.toggle_todo = ToggleTodo
|
||||
M.show_backlinks = ShowBacklinks
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user