mirror of
https://github.com/zoriya/telescope.nvim.git
synced 2025-12-05 22:36:13 +00:00
chore: cleanup vim options (#1946)
This commit is contained in:
committed by
Simon Hauser
parent
440684edad
commit
4482c2b551
File diff suppressed because it is too large
Load Diff
@@ -569,17 +569,20 @@ internal.search_history = function(opts)
|
||||
end
|
||||
|
||||
internal.vim_options = function(opts)
|
||||
-- Load vim options.
|
||||
local vim_opts = loadfile(Path:new({ utils.data_directory(), "options", "options.lua" }):absolute())().options
|
||||
local res = {}
|
||||
for _, v in pairs(vim.api.nvim_get_all_options_info()) do
|
||||
table.insert(res, v)
|
||||
end
|
||||
table.sort(res, function(left, right)
|
||||
return left.name < right.name
|
||||
end)
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt_title = "options",
|
||||
finder = finders.new_table {
|
||||
results = vim_opts,
|
||||
results = res,
|
||||
entry_maker = opts.entry_maker or make_entry.gen_from_vimoptions(opts),
|
||||
},
|
||||
-- TODO: previewer for Vim options
|
||||
-- previewer = previewers.help.new(opts),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function()
|
||||
actions.select_default:replace(function()
|
||||
@@ -591,41 +594,14 @@ internal.vim_options = function(opts)
|
||||
|
||||
local esc = ""
|
||||
if vim.fn.mode() == "i" then
|
||||
-- TODO: don't make this local
|
||||
esc = vim.api.nvim_replace_termcodes("<esc>", true, false, true)
|
||||
end
|
||||
|
||||
-- TODO: Make this actually work.
|
||||
|
||||
-- actions.close(prompt_bufnr)
|
||||
-- vim.api.nvim_win_set_var(vim.api.nvim_get_current_win(), "telescope", 1)
|
||||
-- print(prompt_bufnr)
|
||||
-- print(vim.fn.bufnr())
|
||||
-- vim.cmd([[ autocmd BufEnter <buffer> ++nested ++once startinsert!]])
|
||||
-- print(vim.fn.winheight(0))
|
||||
|
||||
-- local prompt_winnr = vim.fn.getbufinfo(prompt_bufnr)[1].windows[1]
|
||||
-- print(prompt_winnr)
|
||||
|
||||
-- local float_opts = {}
|
||||
-- float_opts.relative = "editor"
|
||||
-- float_opts.anchor = "sw"
|
||||
-- float_opts.focusable = false
|
||||
-- float_opts.style = "minimal"
|
||||
-- float_opts.row = vim.api.nvim_get_option("lines") - 2 -- TODO: inc `cmdheight` and `laststatus` in this calc
|
||||
-- float_opts.col = 2
|
||||
-- float_opts.height = 10
|
||||
-- float_opts.width = string.len(selection.last_set_from)+15
|
||||
-- local buf = vim.api.nvim_create_buf(false, true)
|
||||
-- vim.api.nvim_buf_set_lines(buf, 0, 0, false,
|
||||
-- {"default value: abcdef", "last set from: " .. selection.last_set_from})
|
||||
-- local status_win = vim.api.nvim_open_win(buf, false, float_opts)
|
||||
-- -- vim.api.nvim_win_set_option(status_win, "winblend", 100)
|
||||
-- vim.api.nvim_win_set_option(status_win, "winhl", "Normal:PmenuSel")
|
||||
-- -- vim.api.nvim_set_current_win(status_win)
|
||||
-- vim.cmd[[redraw!]]
|
||||
-- vim.cmd("autocmd CmdLineLeave : ++once echom 'beep'")
|
||||
vim.api.nvim_feedkeys(string.format("%s:set %s=%s", esc, selection.name, selection.current_value), "m", true)
|
||||
vim.api.nvim_feedkeys(
|
||||
string.format("%s:set %s=%s", esc, selection.value.name, selection.value.value),
|
||||
"m",
|
||||
true
|
||||
)
|
||||
end)
|
||||
|
||||
return true
|
||||
|
||||
@@ -811,67 +811,6 @@ function make_entry.gen_from_buffer_lines(opts)
|
||||
end
|
||||
|
||||
function make_entry.gen_from_vimoptions()
|
||||
local process_one_opt = function(o)
|
||||
local ok, value_origin
|
||||
|
||||
local option = {
|
||||
name = "",
|
||||
description = "",
|
||||
current_value = "",
|
||||
default_value = "",
|
||||
value_type = "",
|
||||
set_by_user = false,
|
||||
last_set_from = "",
|
||||
}
|
||||
|
||||
local is_global = false
|
||||
for _, v in ipairs(o.scope) do
|
||||
if v == "global" then
|
||||
is_global = true
|
||||
end
|
||||
end
|
||||
|
||||
if not is_global then
|
||||
return
|
||||
end
|
||||
|
||||
if is_global then
|
||||
option.name = o.full_name
|
||||
|
||||
ok, option.current_value = pcall(vim.api.nvim_get_option, o.full_name)
|
||||
if not ok then
|
||||
return
|
||||
end
|
||||
|
||||
local str_funcname = o.short_desc()
|
||||
option.description = assert(loadstring(str_funcname))()
|
||||
-- if #option.description > opts.desc_col_length then
|
||||
-- opts.desc_col_length = #option.description
|
||||
-- end
|
||||
|
||||
if o.defaults ~= nil then
|
||||
option.default_value = o.defaults.if_true.vim or o.defaults.if_true.vi
|
||||
end
|
||||
|
||||
if type(option.default_value) == "function" then
|
||||
option.default_value = "Macro: " .. option.default_value()
|
||||
end
|
||||
|
||||
option.value_type = (type(option.current_value) == "boolean" and "bool" or type(option.current_value))
|
||||
|
||||
if option.current_value ~= option.default_value then
|
||||
option.set_by_user = true
|
||||
value_origin = vim.fn.execute("verbose set " .. o.full_name .. "?")
|
||||
if string.match(value_origin, "Last set from") then
|
||||
-- TODO: parse file and line number as separate items
|
||||
option.last_set_from = value_origin:gsub("^.*Last set from ", "")
|
||||
end
|
||||
end
|
||||
|
||||
return option
|
||||
end
|
||||
end
|
||||
|
||||
local displayer = entry_display.create {
|
||||
separator = "",
|
||||
hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" },
|
||||
@@ -884,25 +823,27 @@ function make_entry.gen_from_vimoptions()
|
||||
|
||||
local make_display = function(entry)
|
||||
return displayer {
|
||||
{ entry.name, "Keyword" },
|
||||
{ "[" .. entry.value_type .. "]", "Type" },
|
||||
utils.display_termcodes(tostring(entry.current_value)),
|
||||
entry.description,
|
||||
{ entry.value.name, "Keyword" },
|
||||
{ "[" .. entry.value.type .. "]", "Type" },
|
||||
utils.display_termcodes(tostring(entry.value.value)),
|
||||
}
|
||||
end
|
||||
|
||||
return function(line)
|
||||
local entry = process_one_opt(line)
|
||||
if not entry then
|
||||
return
|
||||
end
|
||||
return function(o)
|
||||
local entry = {
|
||||
display = make_display,
|
||||
value = {
|
||||
name = o.name,
|
||||
value = o.default,
|
||||
type = o.type,
|
||||
},
|
||||
ordinal = o.name,
|
||||
}
|
||||
|
||||
entry.valid = true
|
||||
entry.display = make_display
|
||||
entry.value = line
|
||||
entry.ordinal = line.full_name
|
||||
-- entry.raw_value = d.raw_value
|
||||
-- entry.last_set_from = d.last_set_from
|
||||
local ok, value = pcall(vim.api.nvim_get_option, o.name)
|
||||
if ok then
|
||||
entry.value.value = value
|
||||
end
|
||||
|
||||
return entry
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user