mr.vimを好きなFuzzy Finderから使う (telescope)
code:lua
-- utils.lua
local M = {}
function M.join_table(...)
local result = {}
for _, table in ipairs({ ... }) do
for key, value in ipairs(table) do
if type(key) == "string" then
elseif type(key) == "number" then
else
error()
end
end
end
return result
end
return M
-- telescope.lua
local join_table = require("utils.join_table")
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local make_entry = require("telescope.make_entry")
local conf = require("telescope.config").values
local M = {}
M.recent_written_files = function(opts)
local safe_opts = opts or {}
pickers.new(safe_opts, {
prompt_title = "Recent written files",
finder = finders.new_table({
results = list,
entry_maker = make_entry.gen_from_file(safe_opts),
}),
previewer = conf.file_previewer(safe_opts),
sorter = conf.file_sorter(safe_opts),
}):find()
end
M.recent_used_files = function(opts)
local safe_opts = opts or {}
pickers.new(safe_opts, {
prompt_title = "Recent used files",
finder = finders.new_table({
results = list,
entry_maker = make_entry.gen_from_file(safe_opts),
}),
previewer = conf.file_previewer(safe_opts),
sorter = conf.file_sorter(safe_opts),
}):find()
end
return M
実際に使うときは
M.recent_written_files()
M.recent_used_files()
のように呼び出す。
また、検索ワードを入力した際に、Fuzzy Matchのマッチ度ではなく履歴順にならべたままにしたい場合は、
sorterを次のものに差し換える(sorter = recent_file_sorter(safe_opts, list))。
code:lua
local function recent_file_sorter(opts, list)
local indices = {}
for i, line in ipairs(list) do
end
local file_sorter = conf.file_sorter(opts)
local base_scorer = file_sorter.scoring_function
file_sorter.scoring_function = function(self, prompt, line)
local score = base_scorer(self, prompt, line)
if score <= 0 then
return -1
else
end
end
return file_sorter
end