actually fixed reloading
This commit is contained in:
1 parent
ea0cdc2c9e
commit
b2b8e5f539
7 files changed
+56
-32
No files matched your search
@@ -1,5 +1,5 @@
|
||||
local config = function()
|
||||
local u = require 'config.utils'
|
||||
local u = require 'config.utils'.mapping
|
||||
|
||||
u.nmap('E', vim.diagnostic.open_float)
|
||||
u.nmap('[d', vim.diagnostic.goto_prev)
|
||||
|
||||
@@ -6,7 +6,7 @@ return function(use)
|
||||
config = function()
|
||||
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>fg', u.cmd('Telescope live_grep'))
|
||||
|
||||
@@ -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'))
|
||||
end
|
||||
}
|
||||
|
||||
+16
-17
@@ -1,11 +1,13 @@
|
||||
local group = vim.api.nvim_create_augroup('reload', {})
|
||||
local u = require 'config.utils'.load
|
||||
|
||||
local post_write = function(path, fn)
|
||||
vim.api.nvim_create_autocmd('BufWritePost', {
|
||||
group = group,
|
||||
pattern = '**/lua/config/' .. path,
|
||||
callback = fn,
|
||||
})
|
||||
local g
|
||||
vim.api.nvim_create_augroup('reload', {})
|
||||
|
||||
-- reload these files when written to
|
||||
|
||||
--- @param arg {file: string}
|
||||
local reload_file = function(arg)
|
||||
u.reload(u.path_for(arg.file))
|
||||
end
|
||||
|
||||
for _, path in ipairs({
|
||||
@@ -14,7 +16,7 @@ for _, path in ipairs({
|
||||
'utils.lua',
|
||||
'neovide.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
|
||||
-- after writing to the file
|
||||
@@ -23,17 +25,14 @@ for _, path in ipairs({
|
||||
--- @param arg {file: string}
|
||||
local update_plugins = function(arg)
|
||||
-- unload the file if it's not plugins.lua
|
||||
local i = arg.file:find("config/plugins/")
|
||||
if i ~= nil then
|
||||
local mod = arg.file:sub(i):gsub("/", "."):sub(0, -5)
|
||||
package.loaded[mod] = nil
|
||||
local mod = u.path_for(arg.file)
|
||||
if mod ~= 'config.plugins' then
|
||||
u.unload(mod)
|
||||
end
|
||||
-- reload plugins.lua and compile
|
||||
package.loaded['config.plugins'] = nil
|
||||
require 'config.plugins'
|
||||
u.reload('config.plugins')
|
||||
require 'packer'.compile()
|
||||
end
|
||||
|
||||
post_write('plugins.lua', update_plugins)
|
||||
post_write('plugins/*', update_plugins)
|
||||
|
||||
u.post_write(g, 'plugins.lua', update_plugins)
|
||||
u.post_write(g, 'plugins/*', update_plugins)
|
||||
@@ -40,11 +40,12 @@ vim.diagnostic.config({
|
||||
})
|
||||
|
||||
-- terminal
|
||||
u.map('t', '<esc>', '<C-\\><C-n>')
|
||||
u.nmap('<space>tm', '<cmd>belowright 7sp<cr><cmd>term<cr><cmd>set nonu<cr>A')
|
||||
local m = u.mapping
|
||||
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
|
||||
u.nmap('<esc>', '<cmd>noh<cr><esc>')
|
||||
m.nmap('<esc>', '<cmd>noh<cr><esc>')
|
||||
|
||||
-- colemak
|
||||
local l = u.layout
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
-- highlight extra white space with red
|
||||
vim.api.nvim_set_hl(0, 'ExtraWhitespace', { ctermbg = 'red', bg = '#ff8888' })
|
||||
vim.cmd [[match ExtraWhitespace /\s\+$/]]
|
||||
print("hello???")
|
||||
|
||||
+33
-8
@@ -1,20 +1,45 @@
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
local utils = {}
|
||||
utils.map = function(mode, from, to) vim.keymap.set(mode, from, to, opts) end
|
||||
utils.nmap = function(from, to) vim.keymap.set('n', from, to, opts) end
|
||||
utils.cmd = function(content) return '<cmd>' .. content .. '<cr>' end
|
||||
-- mapping
|
||||
local mapping = {}
|
||||
mapping.map = function(mode, from, to) vim.keymap.set(mode, from, to, opts) 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 = {}
|
||||
layout.map = function(from, to)
|
||||
vim.keymap.set('n', from, to, opts)
|
||||
vim.keymap.set('x', from, to, opts)
|
||||
end
|
||||
layout.swap = function(a, b)
|
||||
utils.layout.map(a, b)
|
||||
utils.layout.map(b, a)
|
||||
layout.map(a, b)
|
||||
layout.map(b, a)
|
||||
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,
|
||||
}
|
||||
Reference in new issue
Block a user