mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
Add with live grep option to insert link function and find notes function (closes #188)
* add with_live_grep option to InsertLink function * add with_live_grep option to FindNotes function * update documents
This commit is contained in:
committed by
GitHub
parent
04deff8579
commit
9de25d1657
@@ -652,7 +652,8 @@ The plugin defines the following functions:
|
||||
- **note**:
|
||||
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is
|
||||
useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#3-bind-it).
|
||||
- example: `insert_link({ i=true })`
|
||||
- example: `insert_link({ i=true })`
|
||||
- this function accepts a parameter `{with_live_grep}`. If `true`, it will use live_grep picker and you can search file by file contents.
|
||||
- `follow_link()`: take text between brackets (linked note) or of a tag and open a Telescope file finder with it: selects note to
|
||||
open (incl. preview) - with optional note creation for non-existing notes, honoring the configured template
|
||||
- **note**:
|
||||
|
||||
@@ -537,9 +537,16 @@ telekasten.new_templated_note()~
|
||||
See also:~
|
||||
- |telekasten.template_files|
|
||||
*telekasten.find_notes()*
|
||||
telekasten.find_notes()~
|
||||
telekasten.find_notes({opts})~
|
||||
Opens a Telescope file finder and lets you pick a note by title (file name).
|
||||
|
||||
Valid keys for {opts}
|
||||
|
||||
with_live_grep:~
|
||||
If `true`, it will use live_grep picker and you can search file by file contents.
|
||||
|
||||
Default: `nil`
|
||||
|
||||
*telekasten.find_daily_notes()*
|
||||
telekasten.find_daily_notes()~
|
||||
Find daily notes by date, via Telescope. File names are sorted by file name,
|
||||
@@ -631,6 +638,11 @@ telekasten.insert_link({opts})~
|
||||
when being used in a simple `inoremap` key mapping like shown in
|
||||
|telekasten.mappings|.
|
||||
|
||||
Default: `nil`
|
||||
|
||||
with_live_grep:~
|
||||
If `true`, it will use live_grep picker and you can search file by file contents.
|
||||
|
||||
Default: `nil`
|
||||
|
||||
*telekasten.follow_link()*
|
||||
|
||||
@@ -1442,38 +1442,48 @@ local function InsertLink(opts)
|
||||
return
|
||||
end
|
||||
|
||||
find_files_sorted({
|
||||
prompt_title = "Insert link to note",
|
||||
cwd = M.Cfg.home,
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
local pinfo = Pinfo:new({
|
||||
filepath = selection.value,
|
||||
opts,
|
||||
})
|
||||
vim.api.nvim_put(
|
||||
{ "[[" .. pinfo.title .. "]]" },
|
||||
"",
|
||||
true,
|
||||
true
|
||||
)
|
||||
if opts.i then
|
||||
vim.api.nvim_feedkeys("A", "m", false)
|
||||
end
|
||||
end)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("i", "<c-cr>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
||||
return true
|
||||
end,
|
||||
find_command = M.Cfg.find_command,
|
||||
sort = M.Cfg.sort,
|
||||
})
|
||||
local cwd = M.Cfg.home
|
||||
local find_command = M.Cfg.find_command
|
||||
local sort = M.Cfg.sort
|
||||
local attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
local pinfo = Pinfo:new({
|
||||
filepath = selection.filename,
|
||||
opts,
|
||||
})
|
||||
vim.api.nvim_put({ "[[" .. pinfo.title .. "]]" }, "", true, true)
|
||||
if opts.i then
|
||||
vim.api.nvim_feedkeys("A", "m", false)
|
||||
end
|
||||
end)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("i", "<c-cr>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
||||
return true
|
||||
end
|
||||
|
||||
if opts.with_live_grep then
|
||||
builtin.live_grep({
|
||||
prompt_title = "Insert link to note with live grep",
|
||||
cwd = cwd,
|
||||
attach_mappings = attach_mappings,
|
||||
find_command = find_command,
|
||||
sort = sort,
|
||||
})
|
||||
else
|
||||
find_files_sorted({
|
||||
prompt_title = "Insert link to note",
|
||||
cwd = cwd,
|
||||
attach_mappings = attach_mappings,
|
||||
find_command = find_command,
|
||||
sort = sort,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- local function check_for_link_or_tag()
|
||||
@@ -1845,22 +1855,37 @@ local function FindNotes(opts)
|
||||
return
|
||||
end
|
||||
|
||||
find_files_sorted({
|
||||
prompt_title = "Find notes by name",
|
||||
cwd = M.Cfg.home,
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("i", "<c-cr>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
||||
return true
|
||||
end,
|
||||
sort = M.Cfg.sort,
|
||||
})
|
||||
local cwd = M.Cfg.home
|
||||
local find_command = M.Cfg.find_command
|
||||
local sort = M.Cfg.sort
|
||||
local attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("i", "<c-cr>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
||||
return true
|
||||
end
|
||||
|
||||
if opts.with_live_grep then
|
||||
builtin.live_grep({
|
||||
prompt_title = "Find notes by live grep",
|
||||
cwd = cwd,
|
||||
find_command = find_command,
|
||||
attach_mappings = attach_mappings,
|
||||
sort = sort,
|
||||
})
|
||||
else
|
||||
find_files_sorted({
|
||||
prompt_title = "Find notes by name",
|
||||
cwd = cwd,
|
||||
find_command = find_command,
|
||||
attach_mappings = attach_mappings,
|
||||
sort = sort,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user