dotfiles/nvim/lua/teaching.lua

45 lines
1.2 KiB
Lua
Raw Normal View History

2023-08-28 16:27:03 +02:00
local teaching = {}
local function ends_with(path, extension)
return string.sub(path, -#extension) == extension
end
local function should_load(path)
2023-08-28 19:14:35 +02:00
local ignore = {
[1] = "rapidjson",
[2] = "json.hpp",
[3] = "build",
[4] = "third-party",
[5] = "sfml",
}
for _, pattern in ipairs(ignore) do
if string.find(path, pattern, 0, true) then
return false
end
end
if ends_with(path, ".h") or ends_with(path, ".cpp") or ends_with(path, ".cpp") or ends_with(path, ".cpp") then
2023-08-28 16:27:03 +02:00
return true
end
end
function teaching.load()
require("nvim-tree").open()
require("trouble").open()
local scan = require("plenary.scandir").scan_dir('.')
local cwd = vim.fn.getcwd()
for _, v in ipairs(scan) do
local filename = vim.fs.normalize(v)
if should_load(v) then
vim.api.nvim_set_current_dir(cwd)
local buf_id = vim.fn.bufadd(filename)
vim.api.nvim_set_current_buf(buf_id)
vim.api.nvim_buf_set_option(buf_id, "buflisted", true)
end
end
vim.api.nvim_set_current_dir(cwd)
end
2023-08-28 19:14:35 +02:00
vim.api.nvim_create_user_command("AP", teaching.load, {})
2023-08-28 16:27:03 +02:00
return teaching