mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-07 18:34:50 +02:00
refactor: use modern option setter/getter methods
This commit is contained in:
parent
3a17406d9d
commit
189bf4cce7
8 changed files with 29 additions and 32 deletions
|
@ -410,7 +410,7 @@ local nerd_icons = {
|
|||
local M = {}
|
||||
|
||||
M.get_filetypes = function(bufnr)
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr or 0, "filetype")
|
||||
local ft = vim.bo[bufnr or 0].filetype
|
||||
return vim.split(ft, "%.")
|
||||
end
|
||||
|
||||
|
|
|
@ -164,21 +164,21 @@ M.maybe_set_foldmethod = function(bufnr)
|
|||
winids = { vim.api.nvim_get_current_win() }
|
||||
end
|
||||
for _, winid in ipairs(winids) do
|
||||
local fdm = vim.api.nvim_win_get_option(winid, "foldmethod")
|
||||
local fde = vim.api.nvim_win_get_option(winid, "foldexpr")
|
||||
local fdm = vim.wo[winid].foldmethod
|
||||
local fde = vim.wo[winid].foldexpr
|
||||
if
|
||||
not util.is_managing_folds(winid)
|
||||
and (manage_folds == true or (manage_folds == "auto" and fdm == "manual"))
|
||||
then
|
||||
vim.api.nvim_win_set_var(winid, prev_fdm, fdm)
|
||||
vim.api.nvim_win_set_var(winid, prev_fde, fde)
|
||||
vim.api.nvim_win_set_option(winid, "foldmethod", "expr")
|
||||
vim.api.nvim_win_set_option(winid, "foldexpr", "v:lua.aerial_foldexpr()")
|
||||
vim.wo[winid].foldmethod = "expr"
|
||||
vim.wo[winid].foldexpr = "v:lua.aerial_foldexpr()"
|
||||
if config.link_folds_to_tree then
|
||||
local fdl = vim.api.nvim_win_get_option(winid, "foldlevel")
|
||||
local fdl = vim.wo[winid].foldlevel
|
||||
require("aerial").tree_set_collapse_level(bufnr, fdl)
|
||||
elseif config.link_tree_to_folds then
|
||||
vim.api.nvim_win_set_option(winid, "foldlevel", 99)
|
||||
vim.wo[winid].foldlevel = 99
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -435,7 +435,7 @@ M.info = function()
|
|||
do_setup()
|
||||
local util = require("aerial.util")
|
||||
local bufnr = util.get_buffers(0)
|
||||
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
|
||||
local filetype = vim.bo[bufnr].filetype
|
||||
local ignored, message = util.is_ignored_win()
|
||||
return {
|
||||
ignore = {
|
||||
|
|
|
@ -158,7 +158,7 @@ M.set_collapse_level = function(bufnr, level)
|
|||
end
|
||||
|
||||
for _, winid in ipairs(wins) do
|
||||
vim.api.nvim_win_set_option(winid, "foldlevel", level)
|
||||
vim.wo[winid].foldlevel = level
|
||||
end
|
||||
end
|
||||
_post_tree_mutate(bufnr)
|
||||
|
|
|
@ -50,11 +50,8 @@ end
|
|||
---@return integer
|
||||
M.win_get_gutter_width = function(winid)
|
||||
winid = winid or 0
|
||||
if
|
||||
vim.api.nvim_win_get_option(winid, "number")
|
||||
or vim.api.nvim_win_get_option(winid, "relativenumber")
|
||||
then
|
||||
return vim.api.nvim_win_get_option(winid, "numberwidth")
|
||||
if vim.wo[winid].number or vim.wo[winid].relativenumber then
|
||||
return vim.wo[winid].numberwidth
|
||||
else
|
||||
return 0
|
||||
end
|
||||
|
@ -66,7 +63,7 @@ M.is_aerial_buffer = function(bufnr)
|
|||
if not vim.api.nvim_buf_is_valid(bufnr or 0) then
|
||||
return false
|
||||
end
|
||||
local ft = vim.api.nvim_buf_get_option(bufnr or 0, "filetype")
|
||||
local ft = vim.bo[bufnr or 0].filetype
|
||||
return ft == "aerial"
|
||||
end
|
||||
|
||||
|
@ -245,12 +242,12 @@ M.is_ignored_buf = function(bufnr)
|
|||
return false
|
||||
end
|
||||
local ignore = config.ignore
|
||||
if ignore.unlisted_buffers and not vim.api.nvim_buf_get_option(bufnr, "buflisted") then
|
||||
if ignore.unlisted_buffers and not vim.bo[bufnr].buflisted then
|
||||
return true, "Buffer is not listed"
|
||||
end
|
||||
if ignore.buftypes then
|
||||
local buftype = vim.api.nvim_buf_get_option(bufnr, "buftype")
|
||||
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
|
||||
local buftype = vim.bo[bufnr].buftype
|
||||
local filetype = vim.bo[bufnr].filetype
|
||||
if ignore.buftypes == "special" then
|
||||
if buftype ~= "" and buftype ~= "help" and filetype ~= "man" then
|
||||
return true, string.format("Buftype '%s' is \"special\"", buftype)
|
||||
|
@ -302,7 +299,7 @@ end
|
|||
---@param winid nil|integer
|
||||
---@return boolean
|
||||
M.is_managing_folds = function(winid)
|
||||
return vim.api.nvim_win_get_option(winid or 0, "foldexpr") == "v:lua.aerial_foldexpr()"
|
||||
return vim.wo[winid or 0].foldexpr == "v:lua.aerial_foldexpr()"
|
||||
end
|
||||
|
||||
---@return "left"|"right"|"float"
|
||||
|
|
|
@ -84,16 +84,16 @@ end
|
|||
---@param aer_winid integer
|
||||
local function setup_aerial_win(src_winid, aer_winid, aer_bufnr)
|
||||
vim.api.nvim_win_set_buf(aer_winid, aer_bufnr)
|
||||
vim.api.nvim_win_set_option(aer_winid, "list", false)
|
||||
vim.api.nvim_win_set_option(aer_winid, "winfixwidth", true)
|
||||
vim.api.nvim_win_set_option(aer_winid, "number", false)
|
||||
vim.api.nvim_win_set_option(aer_winid, "signcolumn", "no")
|
||||
vim.api.nvim_win_set_option(aer_winid, "foldcolumn", "0")
|
||||
vim.api.nvim_win_set_option(aer_winid, "relativenumber", false)
|
||||
vim.api.nvim_win_set_option(aer_winid, "wrap", false)
|
||||
vim.api.nvim_win_set_option(aer_winid, "spell", false)
|
||||
vim.wo[aer_winid].list = false
|
||||
vim.wo[aer_winid].winfixwidth = true
|
||||
vim.wo[aer_winid].number = false
|
||||
vim.wo[aer_winid].signcolumn = "no"
|
||||
vim.wo[aer_winid].foldcolumn = "0"
|
||||
vim.wo[aer_winid].relativenumber = false
|
||||
vim.wo[aer_winid].wrap = false
|
||||
vim.wo[aer_winid].spell = false
|
||||
for k, v in pairs(config.layout.win_opts) do
|
||||
vim.api.nvim_win_set_option(aer_winid, k, v)
|
||||
vim.wo[aer_winid][k] = v
|
||||
end
|
||||
vim.api.nvim_win_set_var(aer_winid, "is_aerial_win", true)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ local function aerial_picker(opts)
|
|||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local filename = vim.api.nvim_buf_get_name(0)
|
||||
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
|
||||
local filetype = vim.bo[bufnr].filetype
|
||||
local show_nesting = ext_config.show_nesting[filetype]
|
||||
if show_nesting == nil then
|
||||
show_nesting = ext_config.show_nesting["_"]
|
||||
|
|
|
@ -18,7 +18,7 @@ a.describe("layout", function()
|
|||
aerial.toggle()
|
||||
local winid = vim.api.nvim_tabpage_list_wins(0)[1]
|
||||
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
||||
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
||||
assert.equals("aerial", vim.bo[aer_bufnr].filetype)
|
||||
end)
|
||||
|
||||
a.it("can open relative to the window, to the right", function()
|
||||
|
@ -32,7 +32,7 @@ a.describe("layout", function()
|
|||
aerial.toggle()
|
||||
local winid = vim.api.nvim_tabpage_list_wins(0)[2]
|
||||
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
||||
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
||||
assert.equals("aerial", vim.bo[aer_bufnr].filetype)
|
||||
end)
|
||||
|
||||
a.it("can open aerial in float", function()
|
||||
|
@ -40,7 +40,7 @@ a.describe("layout", function()
|
|||
aerial.toggle({ direction = "float" })
|
||||
local winid = vim.api.nvim_tabpage_list_wins(0)[2]
|
||||
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
||||
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
||||
assert.equals("aerial", vim.bo[aer_bufnr].filetype)
|
||||
assert(require("aerial.util").is_floating_win(winid))
|
||||
end)
|
||||
|
||||
|
|
Loading…
Reference in a new issue