From 7a7221ff0d8e95bd4c7e9a5e0abc150d66e51d77 Mon Sep 17 00:00:00 2001 From: Cian Hughes Date: Tue, 14 Jul 2026 13:18:18 +0100 Subject: [PATCH] Further migration of expressive functionality to fennel --- fnl/config/autocmds.fnl | 29 +++++++++++++++++++++++++++++ init.lua | 27 ++++----------------------- lua/config/init.lua | 35 +---------------------------------- lua/config/utils.lua | 22 ++++++++++++++++++++++ 4 files changed, 56 insertions(+), 57 deletions(-) create mode 100644 fnl/config/autocmds.fnl create mode 100644 lua/config/utils.lua diff --git a/fnl/config/autocmds.fnl b/fnl/config/autocmds.fnl new file mode 100644 index 0000000..db637ad --- /dev/null +++ b/fnl/config/autocmds.fnl @@ -0,0 +1,29 @@ +;; Neovim autocommands and runtime logic in Fennel + +;; Highlight on yank +(vim.api.nvim_create_autocmd :TextYankPost + {:desc "Highlight when yanking (copying) text" + :group (vim.api.nvim_create_augroup :kickstart-highlight-yank {:clear true}) + :callback #(vim.highlight.on_yank)}) + +;; FileType custom commentstrings +(vim.api.nvim_create_autocmd :FileType + {:pattern ["nix" "flake"] + :callback #(set vim.bo.commentstring "# %s")}) + +(vim.api.nvim_create_autocmd :FileType + {:pattern ["scallop"] + :callback #(set vim.bo.commentstring "//%s")}) + +;; Root changer on VimEnter (Custom pipeline logic) +(vim.api.nvim_create_autocmd :VimEnter + {:desc "Change CWD to project root if inside git repo" + :callback (fn [] + (let [current-file (vim.fn.expand "%:p")] + (when (not= current-file "") + (let [find-results (vim.fs.find [".git"] {:upward true :path (vim.fs.dirname current-file)}) + git-dir (. find-results 1)] + (when git-dir + (let [root-dir (vim.fs.dirname git-dir)] + (vim.cmd.cd root-dir) + (print (.. "Root changed to: " root-dir))))))))}) diff --git a/init.lua b/init.lua index 68d7923..196f784 100644 --- a/init.lua +++ b/init.lua @@ -6,29 +6,9 @@ vim.g.maplocalleader = "\\\\" require("config") --- Then, i want to load lazy as my plugin manager and have it load my plugins -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) -end - -local hotpotpath = vim.fn.stdpath("data") .. "/lazy/hotpot.nvim" -if not vim.loop.fs_stat(hotpotpath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/rktjmp/hotpot.nvim.git", - hotpotpath, - }) -end +local utils = require("config.utils") +local lazypath = utils.ensure_plugin("lazy.nvim", "folke/lazy.nvim", "stable") +local hotpotpath = utils.ensure_plugin("hotpot.nvim", "rktjmp/hotpot.nvim") ---@diagnostic disable: undefined-field vim.opt.rtp:prepend(hotpotpath) @@ -37,6 +17,7 @@ vim.opt.rtp:prepend(lazypath) require("hotpot") require("keybindings") +require("config.autocmds") require("lazy").setup("plugins") require("nvim-web-devicons").refresh() -- This fixes screwiness with the devicon colors diff --git a/lua/config/init.lua b/lua/config/init.lua index bf8b31a..a5c3162 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -20,31 +20,7 @@ if (vim.fn.executable("nu") == 1) and shell_path:find("nu") then vim.opt.shellpipe = "| complete | update stderr { ansi strip } | tee { get stderr | save --force --raw %s } | into record" end --- Check if we're inside a git repo, and if we are make the project root the CWD -vim.api.nvim_create_autocmd("VimEnter", { - callback = function() - local current_file = vim.fn.expand("%:p") - if current_file == "" then - return - end - local root_dir = vim.fs.dirname( - vim.fs.find({ ".git" }, { upward = true, path = vim.fs.dirname(current_file) })[1] - ) - if root_dir then - vim.cmd.cd(root_dir) - print("Root changed to: " .. root_dir) - end - end, -}) --- Add custom commentstring definitions -vim.api.nvim_create_autocmd("FileType", { - pattern = "nix,flake", - command = "setlocal commentstring=#\\ %s", -}) -vim.api.nvim_create_autocmd("FileType", { - pattern = "scallop", - command = "setlocal commentstring=//%s", -}) + -- Add custom file types vim.filetype.add({ extension = { @@ -85,15 +61,6 @@ vim.opt.scrolloff = 4 -- Minimal number of screen lines to keep above and below -- Set highlight on search, but clear on pressing in normal mode vim.opt.hlsearch = true --- Highlight when yanking (copying) text -vim.api.nvim_create_autocmd("TextYankPost", { - desc = "Highlight when yanking (copying) text", - group = vim.api.nvim_create_augroup("kickstart-highlight-yank", { clear = true }), - callback = function() - vim.highlight.on_yank() - end, -}) - -- Diagnostics config vim.diagnostic.config({ float = { diff --git a/lua/config/utils.lua b/lua/config/utils.lua new file mode 100644 index 0000000..9f1415c --- /dev/null +++ b/lua/config/utils.lua @@ -0,0 +1,22 @@ +local M = {} + +-- Helper function to ensure core bootstrapping plugins are installed +function M.ensure_plugin(name, repo, branch) + local path = vim.fn.stdpath("data") .. "/lazy/" .. name + if not (vim.uv or vim.loop).fs_stat(path) then + local cmd = { + "git", + "clone", + "--filter=blob:none", + "https://github.com/" .. repo .. ".git", + } + if branch then + table.insert(cmd, "--branch=" .. branch) + end + table.insert(cmd, path) + vim.fn.system(cmd) + end + return path +end + +return M