local function H()vim.o.exrc=false vim.g.mapleader=" "vim.g.maplocalleader=" "vim.g.lsp_configs={};(require("\095\046\117\116\105\108\115")).set_indent(4)end local function A()local H=vim.fs.root(vim.env.PWD,{"\046\103\105\116";"\046\101\100\105\116\111\114\099\111\110\102\105\103","\077\097\107\101\102\105\108\101";"\112\097\099\107\097\103\101\046\106\115\111\110","\112\121\112\114\111\106\101\099\116\046\116\111\109\108";"\103\111\046\109\111\100"})if H and H~=vim.uv.cwd()then vim.fn.chdir(H)end end local function K(H)local A=vim.fs.dirname(H)if A~=H then K(A)end local e=vim.fs.joinpath(H,"\046\110\118\105\109\046\108\117\097")if not vim.uv.fs_stat(e)then return end if not vim.secure.read(e)then return end if not xpcall(vim.cmd.source,debug.traceback,e)then vim.api.nvim_notify(string.format("\067\097\110\110\111\116 \108\111\097\100 \037\115 \101\120\114\099",e),vim.log.levels.WARN,{})end end local function e()H()A()K(vim.uv.cwd())end e()
-- custom pipeline tha sources .nvim.lua files starting from the root
-- a better exrc because allows to open project file in a random directory

local function setup_settings()
  vim.o.exrc = false
  -- lazy.nvim required mapleader to be present before its execution
  vim.g.mapleader = " "
  vim.g.maplocalleader = " "

  vim.g.lsp_configs = {}

  require("_.utils").set_indent(4)
end

local function setup_project_root()
  local root = vim.fs.root(vim.env.PWD, {
    ".git",
    ".editorconfig",
    "Makefile",
    "package.json",
    "pyproject.toml",
    "go.mod",
  })

  if root and root ~= vim.uv.cwd() then
    vim.fn.chdir(root)
  end
end

local function setup_project_settings(root)
  local dirname = vim.fs.dirname(root)
  if dirname ~= root then
    setup_project_settings(dirname)
  end

  local exrc_path = vim.fs.joinpath(root, ".nvim.lua")
  if not vim.uv.fs_stat(exrc_path) then
    return
  end

  if not vim.secure.read(exrc_path) then
    return
  end

  if not xpcall(vim.cmd.source, debug.traceback, exrc_path) then
    vim.api.nvim_notify(
      string.format("Cannot load %s exrc", exrc_path),
      vim.log.levels.WARN,
      {}
    )
  end
end

local function setup()
  setup_settings()
  setup_project_root()
  setup_project_settings(vim.uv.cwd())
end

setup()
