mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-20 18:45:08 +02:00
bring back behavior we used to get from astronauta
This commit is contained in:
parent
9a68500333
commit
a6a10e3fdb
2 changed files with 50 additions and 0 deletions
|
@ -2,6 +2,11 @@ local autocommands = {}
|
|||
|
||||
lvim.autocommands = {
|
||||
_general_settings = {
|
||||
{
|
||||
"Filetype",
|
||||
"*",
|
||||
"lua require('utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))",
|
||||
},
|
||||
{
|
||||
"TextYankPost",
|
||||
"*",
|
||||
|
|
45
lua/utils/ft.lua
Normal file
45
lua/utils/ft.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
local ft = {}
|
||||
|
||||
ft.find_lua_ftplugins = function(filetype)
|
||||
local patterns = {
|
||||
string.format("ftplugin/%s.lua", filetype),
|
||||
|
||||
-- Looks like we don't need this, because the first one works
|
||||
-- string.format("after/ftplugin/%s.lua", filetype),
|
||||
}
|
||||
|
||||
local result = {}
|
||||
for _, pat in ipairs(patterns) do
|
||||
vim.list_extend(result, vim.api.nvim_get_runtime_file(pat, true))
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
ft.do_filetype = function(filetype)
|
||||
local ftplugins = ft.find_lua_ftplugins(filetype)
|
||||
|
||||
local f_env = setmetatable({
|
||||
-- Override print, so the prints still go through, otherwise it's confusing for people
|
||||
print = vim.schedule_wrap(print),
|
||||
}, {
|
||||
-- Buf default back read/write to whatever is going on in the global landscape
|
||||
__index = _G,
|
||||
__newindex = _G,
|
||||
})
|
||||
|
||||
for _, file in ipairs(ftplugins) do
|
||||
local f = loadfile(file)
|
||||
if not f then
|
||||
vim.api.nvim_err_writeln("Unable to load file: " .. file)
|
||||
else
|
||||
local ok, msg = pcall(setfenv(f, f_env))
|
||||
|
||||
if not ok then
|
||||
vim.api.nvim_err_writeln("Error while processing file: " .. file .. "\n" .. msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return ft
|
Loading…
Reference in a new issue