Refresh generated neovim config
This commit is contained in:
@ -119,7 +119,8 @@ available and fall back to a plain diff with treesitter highlights.
|
||||
* `side_by_side`, which tells `delta` to render diffs side-by-side. Thus, requires `delta` to be
|
||||
used. Be aware that `delta` always uses its own configuration, so it might be that you're getting
|
||||
the side-by-side view even if this is set to false.
|
||||
* `diff_context_lines`, defaults to your scrolloff value.
|
||||
* `vim_diff_opts`, defaults to all of `:help vim.diff` default options, but sets `ctxlen` to your
|
||||
scrolloff value.
|
||||
* `entry_format`, defaults to `"state #$ID, $STAT, $TIME""`, which contains the three supported
|
||||
variables.
|
||||
* `time_format`, defaults to "" for a timeago-style representation. Can be set to a [Lua date format
|
||||
@ -140,7 +141,9 @@ opts = {
|
||||
use_delta = true,
|
||||
use_custom_command = nil, -- setting this implies `use_delta = false`. Accepted format is: { "bash", "-c", "echo '$DIFF' | delta" }
|
||||
side_by_side = false,
|
||||
diff_context_lines = vim.o.scrolloff,
|
||||
vim_diff_opts = {
|
||||
ctxlen = vim.o.scrolloff,
|
||||
},
|
||||
entry_format = "state #$ID, $STAT, $TIME",
|
||||
time_format = "",
|
||||
saved_only = false,
|
||||
@ -197,7 +200,7 @@ require("telescope").setup({
|
||||
})
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> [!IMPORTANT]
|
||||
> Note how above example uses the call to telescope's `setup()`. This is due to the fact that
|
||||
> directly requiring these actions needs `telescope-undo` to be available already, which it is not
|
||||
> inside lazy's `opts` key when using above "standalone" spec. See the next example for how to do it
|
||||
|
||||
@ -2,7 +2,7 @@ local actions = require("telescope.actions")
|
||||
local actions_state = require("telescope.actions.state")
|
||||
|
||||
local function _get_default_register()
|
||||
local clipboardFlags = vim.split(vim.api.nvim_get_option("clipboard"), ",")
|
||||
local clipboardFlags = vim.split(vim.api.nvim_get_option_value("clipboard", {}), ",")
|
||||
if vim.tbl_contains(clipboardFlags, "unnamedplus") then
|
||||
return "+"
|
||||
end
|
||||
|
||||
@ -2,9 +2,9 @@ local finders = require("telescope.finders")
|
||||
local pickers = require("telescope.pickers")
|
||||
local conf = require("telescope.config").values
|
||||
|
||||
require("telescope-undo.previewer")
|
||||
require("telescope-undo.actions")
|
||||
require("telescope-undo.lua-timeago")
|
||||
local get_previewer = require("telescope-undo.previewer").get_previewer
|
||||
local timeago = require("telescope-undo.lua-timeago").timeago
|
||||
|
||||
local function _traverse_undotree(opts, entries, level)
|
||||
local undolist = {}
|
||||
@ -28,10 +28,7 @@ local function _traverse_undotree(opts, entries, level)
|
||||
local header = filename .. "\n--- " .. filename .. "\n+++ " .. filename .. "\n"
|
||||
|
||||
-- do the diff using our internal diff function
|
||||
local diff = vim.diff(buffer_before, buffer_after, {
|
||||
algorithm = "patience",
|
||||
ctxlen = opts.diff_context_lines or 0,
|
||||
})
|
||||
local diff = vim.diff(buffer_before, buffer_after, opts.vim_diff_opts)
|
||||
|
||||
-- extract data for yanking and searching
|
||||
local ordinal = ""
|
||||
@ -96,7 +93,7 @@ end
|
||||
local M = {}
|
||||
|
||||
M.undo = function(opts)
|
||||
if not vim.api.nvim_buf_get_option(0, "modifiable") then
|
||||
if not vim.api.nvim_get_option_value("modifiable", { buf = 0 }) then
|
||||
print("telescope-undo.nvim: Current buffer is not modifiable.")
|
||||
return
|
||||
end
|
||||
|
||||
@ -17,7 +17,7 @@ local function round(num)
|
||||
return math.floor(num + 0.5)
|
||||
end
|
||||
|
||||
function timeago(time)
|
||||
local function timeago(time)
|
||||
local now = os.time()
|
||||
local diff_seconds = os.difftime(now, time)
|
||||
if diff_seconds < 45 then
|
||||
@ -70,3 +70,5 @@ function timeago(time)
|
||||
end
|
||||
return round(diff_years) .. " " .. language.year.plural
|
||||
end
|
||||
|
||||
return { timeago = timeago }
|
||||
|
||||
@ -3,10 +3,10 @@ local is_wsl = (function()
|
||||
local output = vim.fn.systemlist("uname -r")
|
||||
return not not string.find(output[1] or "", "WSL")
|
||||
end)()
|
||||
function get_previewer(opts)
|
||||
local function get_previewer(opts)
|
||||
if opts.use_custom_command ~= nil then
|
||||
return previewers.new_termopen_previewer({
|
||||
get_command = function(entry, status)
|
||||
get_command = function(entry, _)
|
||||
local difftext = entry.value.diff:gsub("'", [['"'"']])
|
||||
local shlexed = {}
|
||||
for i, part in ipairs(opts.use_custom_command) do
|
||||
@ -20,7 +20,7 @@ function get_previewer(opts)
|
||||
local has_bash = vim.fn.executable("bash") == 1
|
||||
if opts.use_delta and not is_wsl and (has_powershell or has_bash) and vim.fn.executable("delta") == 1 then
|
||||
return previewers.new_termopen_previewer({
|
||||
get_command = function(entry, status)
|
||||
get_command = function(entry, _)
|
||||
local append = ""
|
||||
if opts.side_by_side == true then
|
||||
append = append .. " -s"
|
||||
@ -44,7 +44,7 @@ function get_previewer(opts)
|
||||
else
|
||||
return previewers.new_buffer_previewer({
|
||||
-- this is not the prettiest preview...
|
||||
define_preview = function(self, entry, status)
|
||||
define_preview = function(self, entry, _)
|
||||
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, vim.split(entry.value.diff, "\n"))
|
||||
require("telescope.previewers.utils").highlighter(
|
||||
self.state.bufnr,
|
||||
@ -55,3 +55,4 @@ function get_previewer(opts)
|
||||
})
|
||||
end
|
||||
end
|
||||
return { get_previewer = get_previewer }
|
||||
|
||||
@ -8,10 +8,12 @@ local defaults = {
|
||||
use_delta = true,
|
||||
use_custom_command = nil, -- should be in this format: { "bash", "-c", "echo '$DIFF' | delta" }
|
||||
side_by_side = false,
|
||||
diff_context_lines = vim.o.scrolloff,
|
||||
entry_format = "state #$ID, $STAT, $TIME",
|
||||
time_format = "",
|
||||
saved_only = false,
|
||||
vim_diff_opts = {
|
||||
ctxlen = vim.o.scrolloff,
|
||||
},
|
||||
mappings = {
|
||||
i = {
|
||||
["<cr>"] = require("telescope-undo.actions").yank_additions,
|
||||
@ -33,25 +35,53 @@ local M = {
|
||||
exports = {},
|
||||
}
|
||||
|
||||
M.exports.undo = function(config)
|
||||
config = vim.tbl_deep_extend("force", M.config, config or {})
|
||||
local function extend_config(base, extend)
|
||||
local config = vim.tbl_deep_extend("force", base, extend)
|
||||
-- deprecation notices
|
||||
if config.diff_context_lines ~= nil then
|
||||
vim.deprecate(
|
||||
"diff_context_lines",
|
||||
"vim_diff_opts = { ctxlen = " .. config.diff_context_lines .. " }",
|
||||
"1.0",
|
||||
"telescope-undo.nvim",
|
||||
false
|
||||
)
|
||||
config.vim_diff_opts.ctxlen = config.diff_context_lines
|
||||
config.diff_context_lines = nil
|
||||
end
|
||||
|
||||
-- warn about impossible configurations
|
||||
if config["side_by_side"] and not config["use_delta"] then
|
||||
error("telescope_undo.nvim: setting side_by_side but not use_delta will have no effect")
|
||||
end
|
||||
|
||||
-- remove default keymaps that have been disabled by the user
|
||||
for _, mode in ipairs({ "i", "n" }) do
|
||||
config.mappings[mode] = vim.tbl_map(function(val)
|
||||
return val ~= false and val or nil
|
||||
end, config.mappings[mode])
|
||||
end
|
||||
|
||||
-- expand theme configs
|
||||
if config.theme then
|
||||
config = require("telescope.themes")["get_" .. config.theme](config)
|
||||
end
|
||||
require("telescope-undo").undo(config)
|
||||
return config
|
||||
end
|
||||
|
||||
M.setup = function(extension_config, telescope_config)
|
||||
M.config = vim.tbl_deep_extend("force", defaults, extension_config)
|
||||
-- Remove default keymaps that have been disabled by the user.
|
||||
for _, mode in ipairs({ "i", "n" }) do
|
||||
M.config.mappings[mode] = vim.tbl_map(function(val)
|
||||
return val ~= false and val or nil
|
||||
end, M.config.mappings[mode])
|
||||
end
|
||||
if M.config["side_by_side"] and not M.config["use_delta"] then
|
||||
error("telescope_undo.nvim: setting side_by_side but not use_delta will have no effect")
|
||||
M.exports.undo = function(config)
|
||||
local final_config
|
||||
-- skip reevaluation of extend_config if we're updating with an empty table
|
||||
if config == nil or next(config) == nil then
|
||||
final_config = M.config
|
||||
else
|
||||
final_config = extend_config(M.config, config)
|
||||
end
|
||||
require("telescope-undo").undo(final_config)
|
||||
end
|
||||
|
||||
M.setup = function(extension_config, _)
|
||||
M.config = extend_config(defaults, extension_config)
|
||||
end
|
||||
|
||||
return telescope.register_extension(M)
|
||||
|
||||
Reference in New Issue
Block a user