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",
|
2023-09-03 14:12:00 +02:00
|
|
|
[6] = "TinyXML"
|
2023-08-28 19:14:35 +02:00
|
|
|
}
|
2023-08-28 19:16:52 +02:00
|
|
|
local match = {
|
|
|
|
[1] = ".hpp",
|
|
|
|
[2] = ".h",
|
|
|
|
[3] = ".cpp",
|
|
|
|
[4] = ".c",
|
|
|
|
}
|
2023-08-28 19:14:35 +02:00
|
|
|
for _, pattern in ipairs(ignore) do
|
|
|
|
if string.find(path, pattern, 0, true) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2023-08-28 19:16:52 +02:00
|
|
|
for _, pattern in ipairs(match) do
|
|
|
|
if ends_with(path, pattern) then
|
|
|
|
return true
|
|
|
|
end
|
2023-08-28 16:27:03 +02:00
|
|
|
end
|
2023-08-28 19:16:52 +02:00
|
|
|
return false
|
2023-08-28 16:27:03 +02:00
|
|
|
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
|