actually fixed reloading

This commit is contained in:
iris committed 2022-08-03 14:53:35 -04:00
1 parent ea0cdc2c9e
commit b2b8e5f539
7 files changed
+56 -32

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
local config = function() local config = function()
local u = require 'config.utils' local u = require 'config.utils'.mapping
u.nmap('E', vim.diagnostic.open_float) u.nmap('E', vim.diagnostic.open_float)
u.nmap('[d', vim.diagnostic.goto_prev) u.nmap('[d', vim.diagnostic.goto_prev)
+1 -1
View File
@@ -6,7 +6,7 @@ return function(use)
config = function() config = function()
require 'telescope'.setup {} require 'telescope'.setup {}
local u = require 'config.utils' local u = require 'config.utils'.mapping
u.nmap('<space>ff', u.cmd('Telescope find_files')) u.nmap('<space>ff', u.cmd('Telescope find_files'))
u.nmap('<space>fg', u.cmd('Telescope live_grep')) u.nmap('<space>fg', u.cmd('Telescope live_grep'))
+1 -1
View File
@@ -20,7 +20,7 @@ return function(use)
}, },
} }
local u = require 'config.utils' local u = require 'config.utils'.mapping
u.nmap('<space>e', u.cmd('Neotree toggle')) u.nmap('<space>e', u.cmd('Neotree toggle'))
end end
} }
+16 -17
View File
@@ -1,11 +1,13 @@
local group = vim.api.nvim_create_augroup('reload', {}) local u = require 'config.utils'.load
local post_write = function(path, fn) local g
vim.api.nvim_create_autocmd('BufWritePost', { vim.api.nvim_create_augroup('reload', {})
group = group,
pattern = '**/lua/config/' .. path, -- reload these files when written to
callback = fn,
}) --- @param arg {file: string}
local reload_file = function(arg)
u.reload(u.path_for(arg.file))
end end
for _, path in ipairs({ for _, path in ipairs({
@@ -14,7 +16,7 @@ for _, path in ipairs({
'utils.lua', 'utils.lua',
'neovide.lua', 'neovide.lua',
'theme.lua', 'theme.lua',
}) do post_write(path, function(arg) dofile(arg.file) end) end }) do u.post_write(g, path, reload_file) end
-- allows you to install / clean / update plugins -- allows you to install / clean / update plugins
-- after writing to the file -- after writing to the file
@@ -23,17 +25,14 @@ for _, path in ipairs({
--- @param arg {file: string} --- @param arg {file: string}
local update_plugins = function(arg) local update_plugins = function(arg)
-- unload the file if it's not plugins.lua -- unload the file if it's not plugins.lua
local i = arg.file:find("config/plugins/") local mod = u.path_for(arg.file)
if i ~= nil then if mod ~= 'config.plugins' then
local mod = arg.file:sub(i):gsub("/", "."):sub(0, -5) u.unload(mod)
package.loaded[mod] = nil
end end
-- reload plugins.lua and compile -- reload plugins.lua and compile
package.loaded['config.plugins'] = nil u.reload('config.plugins')
require 'config.plugins'
require 'packer'.compile() require 'packer'.compile()
end end
post_write('plugins.lua', update_plugins) u.post_write(g, 'plugins.lua', update_plugins)
post_write('plugins/*', update_plugins) u.post_write(g, 'plugins/*', update_plugins)
+4 -3
View File
@@ -40,11 +40,12 @@ vim.diagnostic.config({
}) })
-- terminal -- terminal
u.map('t', '<esc>', '<C-\\><C-n>') local m = u.mapping
u.nmap('<space>tm', '<cmd>belowright 7sp<cr><cmd>term<cr><cmd>set nonu<cr>A') m.map('t', '<esc>', '<C-\\><C-n>')
m.nmap('<space>tm', '<cmd>belowright 7sp<cr><cmd>term<cr><cmd>set nonu<cr>A')
-- off search highlight when escape is pressed -- off search highlight when escape is pressed
u.nmap('<esc>', '<cmd>noh<cr><esc>') m.nmap('<esc>', '<cmd>noh<cr><esc>')
-- colemak -- colemak
local l = u.layout local l = u.layout
-1
View File
@@ -1,5 +1,4 @@
-- highlight extra white space with red -- highlight extra white space with red
vim.api.nvim_set_hl(0, 'ExtraWhitespace', { ctermbg = 'red', bg = '#ff8888' }) vim.api.nvim_set_hl(0, 'ExtraWhitespace', { ctermbg = 'red', bg = '#ff8888' })
vim.cmd [[match ExtraWhitespace /\s\+$/]] vim.cmd [[match ExtraWhitespace /\s\+$/]]
print("hello???")
+33 -8
View File
@@ -1,20 +1,45 @@
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
local utils = {} -- mapping
utils.map = function(mode, from, to) vim.keymap.set(mode, from, to, opts) end local mapping = {}
utils.nmap = function(from, to) vim.keymap.set('n', from, to, opts) end mapping.map = function(mode, from, to) vim.keymap.set(mode, from, to, opts) end
utils.cmd = function(content) return '<cmd>' .. content .. '<cr>' end mapping.nmap = function(from, to) vim.keymap.set('n', from, to, opts) end
mapping.cmd = function(content) return '<cmd>' .. content .. '<cr>' end
-- layout (mapping)
local layout = {} local layout = {}
layout.map = function(from, to) layout.map = function(from, to)
vim.keymap.set('n', from, to, opts) vim.keymap.set('n', from, to, opts)
vim.keymap.set('x', from, to, opts) vim.keymap.set('x', from, to, opts)
end end
layout.swap = function(a, b) layout.swap = function(a, b)
utils.layout.map(a, b) layout.map(a, b)
utils.layout.map(b, a) layout.map(b, a)
end end
utils.layout = layout mapping.layout = layout
return utils -- loading stuff
local load = {}
load.post_write = function(group, path, fn)
vim.api.nvim_create_autocmd('BufWritePost', {
group = group,
pattern = '**/lua/config/' .. path,
callback = fn,
})
end
load.unload = function(mod) package.loaded[mod] = nil end
load.reload = function(mod) load.unload(mod) require(mod) end
--- @param path string
load.path_for = function(path)
local i = path:find("lua/config/")
if i == nil then return nil end
local mod = path:sub(i + 4):gsub("/", "."):sub(0, -5)
return mod
end
return {
mapping = mapping,
layout = layout,
load = load,
}