1

Remove globals

This commit is contained in:
Alex Yatskov 2023-01-25 19:56:57 -08:00
parent 45618174b9
commit 4e9385844f
2 changed files with 13 additions and 17 deletions

View File

@ -1,18 +1,14 @@
Config = {
Suffixes = {
'.c',
'.cpp',
'.h',
'.hpp',
'.inl',
}
local RevolverSuffixes = {
'.c',
'.cpp',
'.h',
'.hpp',
'.inl',
}
local function setup(config)
if config then
for key, value in pairs(config) do
Config[key] = config[key] or value
end
RevolverSuffixes = config
end
end
@ -32,7 +28,7 @@ local function revolve(back)
local suffix_index = nil
local prefix = nil
for i, s in ipairs(Config.Suffixes) do
for i, s in ipairs(RevolverSuffixes) do
prefix = path_pivot(path, s)
if prefix then
suffix_index = i
@ -42,7 +38,7 @@ local function revolve(back)
if prefix then
local start = 1
local stop = #Config.Suffixes - 1
local stop = #RevolverSuffixes - 1
local step = 1
if back then
start, stop = stop, start
@ -50,8 +46,8 @@ local function revolve(back)
end
for i = start, stop, step do
local j = (i + suffix_index - 1) % #Config.Suffixes + 1
local next_path = prefix .. Config.Suffixes[j]
local j = (i + suffix_index - 1) % #RevolverSuffixes + 1
local next_path = prefix .. RevolverSuffixes[j]
if path ~= next_path and file_exists(next_path) then
vim.cmd(string.format('e %s', next_path))
break

View File

@ -1,4 +1,6 @@
if not vim.g.hflip then
local revolver = require('revolver')
local function reload()
package.loaded.revolver = nil
revolver = require('revolver')
@ -12,8 +14,6 @@ if not vim.g.hflip then
revolver.revolve(true)
end
reload()
vim.api.nvim_create_user_command('Revolver', revolve, {})
vim.api.nvim_create_user_command('RevolverBack', revolve_back, {})
vim.api.nvim_create_user_command('RevolverReload', reload, {})