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**:
|
- **note**:
|
||||||
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is
|
- 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).
|
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
|
- `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
|
open (incl. preview) - with optional note creation for non-existing notes, honoring the configured template
|
||||||
- **note**:
|
- **note**:
|
||||||
|
|||||||
@@ -537,9 +537,16 @@ telekasten.new_templated_note()~
|
|||||||
See also:~
|
See also:~
|
||||||
- |telekasten.template_files|
|
- |telekasten.template_files|
|
||||||
*telekasten.find_notes()*
|
*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).
|
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()*
|
||||||
telekasten.find_daily_notes()~
|
telekasten.find_daily_notes()~
|
||||||
Find daily notes by date, via Telescope. File names are sorted by file name,
|
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
|
when being used in a simple `inoremap` key mapping like shown in
|
||||||
|telekasten.mappings|.
|
|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`
|
Default: `nil`
|
||||||
|
|
||||||
*telekasten.follow_link()*
|
*telekasten.follow_link()*
|
||||||
|
|||||||
@@ -1442,38 +1442,48 @@ local function InsertLink(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
find_files_sorted({
|
local cwd = M.Cfg.home
|
||||||
prompt_title = "Insert link to note",
|
local find_command = M.Cfg.find_command
|
||||||
cwd = M.Cfg.home,
|
local sort = M.Cfg.sort
|
||||||
attach_mappings = function(prompt_bufnr, map)
|
local attach_mappings = function(prompt_bufnr, map)
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
local pinfo = Pinfo:new({
|
local pinfo = Pinfo:new({
|
||||||
filepath = selection.value,
|
filepath = selection.filename,
|
||||||
opts,
|
opts,
|
||||||
})
|
})
|
||||||
vim.api.nvim_put(
|
vim.api.nvim_put({ "[[" .. pinfo.title .. "]]" }, "", true, true)
|
||||||
{ "[[" .. pinfo.title .. "]]" },
|
if opts.i then
|
||||||
"",
|
vim.api.nvim_feedkeys("A", "m", false)
|
||||||
true,
|
end
|
||||||
true
|
end)
|
||||||
)
|
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||||
if opts.i then
|
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||||
vim.api.nvim_feedkeys("A", "m", false)
|
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||||
end
|
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||||
end)
|
map("i", "<c-cr>", picker_actions.paste_link(opts))
|
||||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
||||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
return true
|
||||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
end
|
||||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
|
||||||
map("i", "<c-cr>", picker_actions.paste_link(opts))
|
if opts.with_live_grep then
|
||||||
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
builtin.live_grep({
|
||||||
return true
|
prompt_title = "Insert link to note with live grep",
|
||||||
end,
|
cwd = cwd,
|
||||||
find_command = M.Cfg.find_command,
|
attach_mappings = attach_mappings,
|
||||||
sort = M.Cfg.sort,
|
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
|
end
|
||||||
|
|
||||||
-- local function check_for_link_or_tag()
|
-- local function check_for_link_or_tag()
|
||||||
@@ -1845,22 +1855,37 @@ local function FindNotes(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
find_files_sorted({
|
local cwd = M.Cfg.home
|
||||||
prompt_title = "Find notes by name",
|
local find_command = M.Cfg.find_command
|
||||||
cwd = M.Cfg.home,
|
local sort = M.Cfg.sort
|
||||||
find_command = M.Cfg.find_command,
|
local attach_mappings = function(_, map)
|
||||||
attach_mappings = function(_, map)
|
actions.select_default:replace(picker_actions.select_default)
|
||||||
actions.select_default:replace(picker_actions.select_default)
|
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
map("n", "<c-i>", picker_actions.paste_link(opts))
|
||||||
map("n", "<c-i>", picker_actions.paste_link(opts))
|
map("i", "<c-cr>", picker_actions.paste_link(opts))
|
||||||
map("i", "<c-cr>", picker_actions.paste_link(opts))
|
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
||||||
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
return true
|
||||||
return true
|
end
|
||||||
end,
|
|
||||||
sort = M.Cfg.sort,
|
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
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user