chore: cleanup vim options (#1946)

This commit is contained in:
Simon Hauser
2022-05-22 10:33:01 +02:00
committed by Simon Hauser
parent 440684edad
commit 4482c2b551
3 changed files with 30 additions and 3370 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -569,17 +569,20 @@ internal.search_history = function(opts)
end end
internal.vim_options = function(opts) internal.vim_options = function(opts)
-- Load vim options. local res = {}
local vim_opts = loadfile(Path:new({ utils.data_directory(), "options", "options.lua" }):absolute())().options 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, { pickers.new(opts, {
prompt_title = "options", prompt_title = "options",
finder = finders.new_table { finder = finders.new_table {
results = vim_opts, results = res,
entry_maker = opts.entry_maker or make_entry.gen_from_vimoptions(opts), 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), sorter = conf.generic_sorter(opts),
attach_mappings = function() attach_mappings = function()
actions.select_default:replace(function() actions.select_default:replace(function()
@@ -591,41 +594,14 @@ internal.vim_options = function(opts)
local esc = "" local esc = ""
if vim.fn.mode() == "i" then if vim.fn.mode() == "i" then
-- TODO: don't make this local
esc = vim.api.nvim_replace_termcodes("<esc>", true, false, true) esc = vim.api.nvim_replace_termcodes("<esc>", true, false, true)
end end
-- TODO: Make this actually work. vim.api.nvim_feedkeys(
string.format("%s:set %s=%s", esc, selection.value.name, selection.value.value),
-- actions.close(prompt_bufnr) "m",
-- vim.api.nvim_win_set_var(vim.api.nvim_get_current_win(), "telescope", 1) true
-- 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)
end) end)
return true return true

View File

@@ -811,67 +811,6 @@ function make_entry.gen_from_buffer_lines(opts)
end end
function make_entry.gen_from_vimoptions() 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 { local displayer = entry_display.create {
separator = "", separator = "",
hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" }, hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" },
@@ -884,25 +823,27 @@ function make_entry.gen_from_vimoptions()
local make_display = function(entry) local make_display = function(entry)
return displayer { return displayer {
{ entry.name, "Keyword" }, { entry.value.name, "Keyword" },
{ "[" .. entry.value_type .. "]", "Type" }, { "[" .. entry.value.type .. "]", "Type" },
utils.display_termcodes(tostring(entry.current_value)), utils.display_termcodes(tostring(entry.value.value)),
entry.description,
} }
end end
return function(line) return function(o)
local entry = process_one_opt(line) local entry = {
if not entry then display = make_display,
return value = {
end name = o.name,
value = o.default,
type = o.type,
},
ordinal = o.name,
}
entry.valid = true local ok, value = pcall(vim.api.nvim_get_option, o.name)
entry.display = make_display if ok then
entry.value = line entry.value.value = value
entry.ordinal = line.full_name end
-- entry.raw_value = d.raw_value
-- entry.last_set_from = d.last_set_from
return entry return entry
end end