diff options
| author | Robert Günzler <r@gnzler.io> | 2022-10-14 20:57:03 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2022-10-14 21:01:15 +0200 |
| commit | 2d2009413f8be624a7cca95cf702e32d9315cbef (patch) | |
| tree | f024c1b5b27b886530e86221593e3cfdc3672d7e /.vim/lua/exrc.lua | |
| parent | 6d7e524d3d7a71da2cea61b335a59e9544e2a6f7 (diff) | |
vim: move custom modules under internal/
Diffstat (limited to '.vim/lua/exrc.lua')
| -rw-r--r-- | .vim/lua/exrc.lua | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/.vim/lua/exrc.lua b/.vim/lua/exrc.lua deleted file mode 100644 index 6b7742b..0000000 --- a/.vim/lua/exrc.lua +++ /dev/null @@ -1,49 +0,0 @@ -local root_pattern = require('lspconfig.util').root_pattern - -local M = { - config = { - filenames = {'.nvimrc'} - } -} - -M.setup = function (opt) - vim.validate { - filenames = { opt.filenames, 'table', true }, - } - - M.config = vim.tbl_extend('force', M.config, opt) - - local group = vim.api.nvim_create_augroup('ExrcLoad', { clear = true }) - vim.api.nvim_create_autocmd('VimEnter', { - callback = M.load, - group = group, - }) -end - -local load = function (root, filename) - local fpath = root .. '/' .. filename - if root and vim.loop.fs_stat(fpath) then - vim.cmd('luafile ' .. fpath) - vim.notify('[exrc] loaded') - else - error(string.format('[exrc] %s not found', fpath)) - end -end - -M.load = function () - local root = vim.fn.getcwd() - for _, fname in ipairs(M.config.filenames) do - local ok = false - ok, _ = pcall(load, root, fname) - if ok then return true end - - -- try harder by searching up the dir tree - root = root_pattern(fname)(root) - ok, _ = pcall(load, root, fname) - if ok then return true end - end - - return false -end - -return M |