Skip to content

Commit

Permalink
cleanup: remove unnecessary option restore_win_options
Browse files Browse the repository at this point in the history
This was only necessary to begin with because I was using `vim.wo` to
set window options. I mistakenly thought that would set the option as
window-local, but it did not. This was fixed in
6f8bf06. Now all the window options
should function as expected without the extra logic.
  • Loading branch information
stevearc committed Sep 12, 2023
1 parent 308fe70 commit 9e036c6
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 35 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,10 @@ require("oil").setup({
conceallevel = 3,
concealcursor = "nvic",
},
-- Restore window options to previous values when leaving an oil buffer
restore_win_options = true,
-- Send deleted files to the trash instead of permanently deleting them (:help oil-trash)
delete_to_trash = false,
-- Skip the confirmation popup for simple operations
skip_confirm_for_simple_edits = false,
-- Deleted files will be removed with the trash_command (below).
delete_to_trash = false,
-- Change this to customize the command used when deleting to trash
trash_command = "trash-put",
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
Expand Down
6 changes: 2 additions & 4 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ OPTIONS *oil-option
conceallevel = 3,
concealcursor = "nvic",
},
-- Restore window options to previous values when leaving an oil buffer
restore_win_options = true,
-- Send deleted files to the trash instead of permanently deleting them (:help oil-trash)
delete_to_trash = false,
-- Skip the confirmation popup for simple operations
skip_confirm_for_simple_edits = false,
-- Deleted files will be removed with the trash_command (below).
delete_to_trash = false,
-- Change this to customize the command used when deleting to trash
trash_command = "trash-put",
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
Expand Down
6 changes: 2 additions & 4 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ local default_config = {
conceallevel = 3,
concealcursor = "nvic",
},
-- Restore window options to previous values when leaving an oil buffer
restore_win_options = true,
-- Send deleted files to the trash instead of permanently deleting them (:help oil-trash)
delete_to_trash = false,
-- Skip the confirmation popup for simple operations
skip_confirm_for_simple_edits = false,
-- Deleted files will be removed with the trash_command (below).
delete_to_trash = false,
-- Change this to customize the command used when deleting to trash
trash_command = "trash-put",
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
Expand Down
5 changes: 0 additions & 5 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,6 @@ M.save = function(opts)
end

local function restore_alt_buf()
local config = require("oil.config")
if vim.bo.filetype == "oil" then
require("oil.view").set_win_options()
vim.api.nvim_win_set_var(0, "oil_did_enter", true)
Expand All @@ -742,10 +741,6 @@ local function restore_alt_buf()
end
end
end

if config.restore_win_options then
require("oil.view").restore_win_options()
end
end
end

Expand Down
18 changes: 0 additions & 18 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,10 @@ end
M.set_win_options = function()
local winid = vim.api.nvim_get_current_win()
for k, v in pairs(config.win_options) do
if config.restore_win_options then
local varname = "_oil_" .. k
if not pcall(vim.api.nvim_win_get_var, winid, varname) then
local prev_value = vim.wo[k]
vim.api.nvim_win_set_var(winid, varname, prev_value)
end
end
vim.api.nvim_set_option_value(k, v, { scope = "local", win = winid })
end
end

M.restore_win_options = function()
local winid = vim.api.nvim_get_current_win()
for k in pairs(config.win_options) do
local varname = "_oil_" .. k
local has_opt, opt = pcall(vim.api.nvim_win_get_var, winid, varname)
if has_opt then
vim.api.nvim_set_option_value(k, opt, { scope = "local", win = winid })
end
end
end

---Get a list of visible oil buffers and a list of hidden oil buffers
---@note
--- If any buffers are modified, return values are nil
Expand Down

0 comments on commit 9e036c6

Please sign in to comment.