From 1757b0b11f6544e478a7b82de278248da70950ee Mon Sep 17 00:00:00 2001 From: punkfairie Date: Sun, 1 Dec 2024 11:05:36 -0800 Subject: [PATCH] feat: Prepare to switch away from LazyVim lib --- nvim/init.lua | 2 ++ nvim/lua/lib/init.lua | 22 ++++++++++++++++++++++ nvim/lua/options.lua | 7 ++----- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 nvim/lua/lib/init.lua diff --git a/nvim/init.lua b/nvim/init.lua index 7da2aeb..af49fcd 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -5,6 +5,8 @@ vim.cmd.filetype('plugin', 'indent', 'on') ---@diagnostic disable-next-line:missing-parameter vim.g.sqlite_clib_path = require('luv').os_getenv('LIBSQLITE') +_G.MarleyVim = require('lib') + require('options') require('keymaps') require('autocmds') diff --git a/nvim/lua/lib/init.lua b/nvim/lua/lib/init.lua new file mode 100644 index 0000000..ca743bd --- /dev/null +++ b/nvim/lua/lib/init.lua @@ -0,0 +1,22 @@ +---@class lib +local M = {} + +---Find the root of a project based on `vim.g.root_spec`. Defaults to +---`{ '.git' }` if unset. +---@return string? +function M.root() + local root_spec = vim.g.root_spec or { '.git' } + + return vim.fs.root(0, root_spec) +end + +---Require a file relative to the given prefix, to avoid repetition. +---@param prefix string The string to prefix to all req calls. +function M.local_require(prefix) + ---@param mod string The module to require. + return function(mod) + return require(prefix .. '.' .. mod) + end +end + +return M diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua index 56775a4..434b5d9 100644 --- a/nvim/lua/options.lua +++ b/nvim/lua/options.lua @@ -2,11 +2,8 @@ local g = vim.g local opt = vim.opt -- Root dir detection options. --- Each entry can be: --- * the name of a detector function like `lsp` or `cwd` --- * a pattern or array of patterns like `.git` or `lua` --- * a function with signature `function(buf) -> string|string[]` -g.root_spec = { 'lsp', { '.git', 'lua' }, 'cwd' } +-- Each entry can be a pattern `.git` or `package.json` +g.root_spec = { '.git', 'package.json' } -- Only set clipboard if not in SSH, to make sure the OSC 52 integration works -- automatically. Requires Neovim >= 0.10.0.