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

View File

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