From 4e9385844ff211f963eeba216c2fe04ef03e59b0 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 25 Jan 2023 19:56:57 -0800 Subject: [PATCH] Remove globals --- lua/revolver.lua | 26 +++++++++++--------------- plugin/revolver.lua | 4 ++-- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lua/revolver.lua b/lua/revolver.lua index b73e0d9..65a28ee 100644 --- a/lua/revolver.lua +++ b/lua/revolver.lua @@ -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 diff --git a/plugin/revolver.lua b/plugin/revolver.lua index 19cf7f7..c606f2e 100644 --- a/plugin/revolver.lua +++ b/plugin/revolver.lua @@ -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, {})