dotfiles/nvim/lua/teaching.lua

55 lines
1.3 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",
[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("trouble").open()
2024-01-20 00:03:32 +01:00
require("nvim-tree").open()
2023-08-28 16:27:03 +02:00
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