add telescope functions for notes
This commit is contained in:
parent
fe8acec2f1
commit
651e05c30a
4 changed files with 73 additions and 18 deletions
|
@ -10,3 +10,4 @@ require('autocompletion')
|
||||||
require('treesitterconfig')
|
require('treesitterconfig')
|
||||||
require('filemanager')
|
require('filemanager')
|
||||||
require('statusline')
|
require('statusline')
|
||||||
|
require('notes')
|
||||||
|
|
|
@ -1,21 +1,4 @@
|
||||||
local map = function(key)
|
local map = require("utils").map
|
||||||
-- get the extra options
|
|
||||||
local opts = {noremap = true}
|
|
||||||
for i, v in pairs(key) do
|
|
||||||
if type(i) == 'string' then opts[i] = v end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- basic support for buffer-scoped keybindings
|
|
||||||
local buffer = opts.buffer
|
|
||||||
opts.buffer = nil
|
|
||||||
|
|
||||||
if buffer then
|
|
||||||
vim.api.nvim_buf_set_keymap(0, key[1], key[2], key[3], opts)
|
|
||||||
else
|
|
||||||
vim.api.nvim_set_keymap(key[1], key[2], key[3], opts)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- search for visual selection
|
-- search for visual selection
|
||||||
map {'v', '//', 'y/<C-R>"<CR>'}
|
map {'v', '//', 'y/<C-R>"<CR>'}
|
||||||
map {'n', 'H', '^'}
|
map {'n', 'H', '^'}
|
||||||
|
@ -44,6 +27,9 @@ map {'n', '<leader>f', '<cmd>Telescope find_files<CR>'}
|
||||||
map {'n', '<leader>l', '<cmd>Telescope live_grep<CR>'}
|
map {'n', '<leader>l', '<cmd>Telescope live_grep<CR>'}
|
||||||
map {'n', '<silent> gy', '<cmd>Telescope treesitter<CR>'}
|
map {'n', '<silent> gy', '<cmd>Telescope treesitter<CR>'}
|
||||||
|
|
||||||
|
map {'n', '<leader>wm', '<cmd>lua require("notes").list()<CR>'}
|
||||||
|
map {'n', '<leader>wt', '<cmd>lua require("notes").tags()<CR>'}
|
||||||
|
|
||||||
-- neo formatter
|
-- neo formatter
|
||||||
map {'n', '<leader>p', ':Neoformat<CR>'}
|
map {'n', '<leader>p', ':Neoformat<CR>'}
|
||||||
|
|
||||||
|
|
47
nvim/lua/notes.lua
Normal file
47
nvim/lua/notes.lua
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
local finders = require "telescope.finders"
|
||||||
|
local make_entry = require "telescope.make_entry"
|
||||||
|
local pickers = require "telescope.pickers"
|
||||||
|
local sorters = require "telescope.sorters"
|
||||||
|
local conf = require("telescope.config").values
|
||||||
|
local flatten = vim.tbl_flatten
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.list()
|
||||||
|
require("telescope.builtin").find_files {
|
||||||
|
prompt_title = "Notes",
|
||||||
|
cwd = "~/.notes"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.tags()
|
||||||
|
local opts = {}
|
||||||
|
|
||||||
|
local vimgrep_arguments = conf.vimgrep_arguments
|
||||||
|
opts.cwd = vim.fn.expand("~/.notes")
|
||||||
|
|
||||||
|
local additional_args = {}
|
||||||
|
if opts.additional_args ~= nil and type(opts.additional_args) == "function" then
|
||||||
|
additional_args = opts.additional_args(opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
local live_grepper = finders.new_job(function(prompt)
|
||||||
|
if not prompt or prompt == "" then
|
||||||
|
prompt = "#[A-z]+"
|
||||||
|
else
|
||||||
|
prompt = "#" .. prompt
|
||||||
|
end
|
||||||
|
|
||||||
|
local command = flatten { vimgrep_arguments, additional_args, "--", prompt }
|
||||||
|
return command
|
||||||
|
end, make_entry.gen_from_vimgrep(opts), opts.max_results, opts.cwd)
|
||||||
|
|
||||||
|
pickers.new(opts, {
|
||||||
|
prompt_title = "Note Tags",
|
||||||
|
finder = live_grepper,
|
||||||
|
previewer = conf.grep_previewer(opts),
|
||||||
|
sorter = sorters.highlighter_only(opts),
|
||||||
|
}):find()
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
21
nvim/lua/utils.lua
Normal file
21
nvim/lua/utils.lua
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
function M.map(key)
|
||||||
|
-- get the extra options
|
||||||
|
local opts = {noremap = true}
|
||||||
|
for i, v in pairs(key) do
|
||||||
|
if type(i) == 'string' then opts[i] = v end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- basic support for buffer-scoped keybindings
|
||||||
|
local buffer = opts.buffer
|
||||||
|
opts.buffer = nil
|
||||||
|
|
||||||
|
if buffer then
|
||||||
|
vim.api.nvim_buf_set_keymap(0, key[1], key[2], key[3], opts)
|
||||||
|
else
|
||||||
|
vim.api.nvim_set_keymap(key[1], key[2], key[3], opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
Loading…
Add table
Reference in a new issue