diff --git a/README.md b/README.md index 323d6e9..779e87c 100644 --- a/README.md +++ b/README.md @@ -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**: diff --git a/doc/telekasten.txt b/doc/telekasten.txt index 06b24d5..13ad254 100644 --- a/doc/telekasten.txt +++ b/doc/telekasten.txt @@ -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()* diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 5dc1341..7750574 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -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", "", picker_actions.yank_link(opts)) - map("i", "", picker_actions.paste_link(opts)) - map("n", "", picker_actions.yank_link(opts)) - map("n", "", picker_actions.paste_link(opts)) - map("i", "", picker_actions.paste_link(opts)) - map("n", "", 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", "", picker_actions.yank_link(opts)) + map("i", "", picker_actions.paste_link(opts)) + map("n", "", picker_actions.yank_link(opts)) + map("n", "", picker_actions.paste_link(opts)) + map("i", "", picker_actions.paste_link(opts)) + map("n", "", 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", "", picker_actions.yank_link(opts)) - map("i", "", picker_actions.paste_link(opts)) - map("n", "", picker_actions.yank_link(opts)) - map("n", "", picker_actions.paste_link(opts)) - map("i", "", picker_actions.paste_link(opts)) - map("n", "", 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", "", picker_actions.yank_link(opts)) + map("i", "", picker_actions.paste_link(opts)) + map("n", "", picker_actions.yank_link(opts)) + map("n", "", picker_actions.paste_link(opts)) + map("i", "", picker_actions.paste_link(opts)) + map("n", "", 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 --