summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.config/nvim/init.lua23
1 files changed, 18 insertions, 5 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua
index 3b81fa3..efc6e23 100644
--- a/.config/nvim/init.lua
+++ b/.config/nvim/init.lua
@@ -15,13 +15,26 @@ vim.g.dotfiles = {
-- Show the diff between the current buffer and the file it was loaded from
local function show_buf_diff_orig()
- vim.cmd.new({ mods = { vertical = true } })
- vim.b.buftype = "nofile"
- vim.cmd.read("++edit #")
- vim.api.nvim_buf_set_lines(0, 0, 2, true, {})
+ local bname = vim.api.nvim_buf_get_name(0)
+ if not vim.uv.fs_stat(bname) then
+ vim.notify("Cannot diff with original because " .. bname .. " doesn't exist", vim.log.levels.WARN)
+ return
+ end
+ local cwin = vim.api.nvim_get_current_win()
vim.cmd.diffthis()
- vim.cmd.wincmd("p")
+ local temp = vim.fn.tempname()
+ local ok, err = vim.uv.fs_copyfile(bname, temp)
+ if not ok then
+ vim.notify("Could not copy file: " .. err, vim.log.levels.ERROR)
+ return
+ end
+ vim.cmd.split({ temp, mods = { vertical = vim.api.nvim_win_get_width(0) >= vim.o.textwidth * 2, keepalt = true } })
vim.cmd.diffthis()
+ vim.opt_local.bufhidden = "wipe"
+ vim.opt_local.buftype = "nofile"
+ vim.opt_local.swapfile = false
+ vim.opt_local.readonly = true
+ vim.api.nvim_set_current_win(cwin)
end
local function reload_buffer()