From e0c77d272a8444bb4cc265536870aa7a29036349 Mon Sep 17 00:00:00 2001 From: Anthony Cicchetti Date: Sat, 19 Nov 2022 15:17:50 -0500 Subject: [PATCH] fennel-ify neovim --- nvim/fnl/config/core.fnl | 11 +++ nvim/fnl/config/init.fnl | 4 + nvim/fnl/config/mapping.fnl | 27 +++++++ nvim/fnl/config/module/core.fnl | 12 +++ nvim/fnl/config/module/plugin.fnl | 79 ++++++++++++++++++++ nvim/fnl/config/module/plugin/base16-vim.fnl | 4 + nvim/fnl/config/module/plugin/bubbly.fnl | 3 + nvim/fnl/config/module/plugin/mason.fnl | 4 + nvim/fnl/config/plugin.fnl | 64 ++++++++++++++++ nvim/fnl/config/plugin/bubbly.fnl | 18 +++++ nvim/fnl/config/plugin/colorscheme.fnl | 4 + nvim/fnl/config/plugin/ctrlp.fnl | 6 ++ nvim/fnl/config/plugin/fugitive.fnl | 2 + nvim/fnl/config/plugin/lspconfig.fnl | 13 ++++ nvim/fnl/config/plugin/treesitter.fnl | 37 +++++++++ nvim/fnl/config/plugin/which-key.fnl | 5 ++ nvim/fnl/config/util.fnl | 26 +++++++ nvim/init.lua | 26 +++++++ 18 files changed, 345 insertions(+) create mode 100644 nvim/fnl/config/core.fnl create mode 100644 nvim/fnl/config/init.fnl create mode 100644 nvim/fnl/config/mapping.fnl create mode 100644 nvim/fnl/config/module/core.fnl create mode 100644 nvim/fnl/config/module/plugin.fnl create mode 100644 nvim/fnl/config/module/plugin/base16-vim.fnl create mode 100644 nvim/fnl/config/module/plugin/bubbly.fnl create mode 100644 nvim/fnl/config/module/plugin/mason.fnl create mode 100644 nvim/fnl/config/plugin.fnl create mode 100644 nvim/fnl/config/plugin/bubbly.fnl create mode 100644 nvim/fnl/config/plugin/colorscheme.fnl create mode 100644 nvim/fnl/config/plugin/ctrlp.fnl create mode 100644 nvim/fnl/config/plugin/fugitive.fnl create mode 100644 nvim/fnl/config/plugin/lspconfig.fnl create mode 100644 nvim/fnl/config/plugin/treesitter.fnl create mode 100644 nvim/fnl/config/plugin/which-key.fnl create mode 100644 nvim/fnl/config/util.fnl create mode 100644 nvim/init.lua diff --git a/nvim/fnl/config/core.fnl b/nvim/fnl/config/core.fnl new file mode 100644 index 0000000..07b08ac --- /dev/null +++ b/nvim/fnl/config/core.fnl @@ -0,0 +1,11 @@ +(module config.core + {autoload {nvim aniseed.nvim}}) + +(set nvim.o.termguicolors true) +(set nvim.o.list true) +(set nvim.o.spell true) +(set nvim.o.wildmenu true) +(set nvim.o.wildmode "list:longest,full") +(set nvim.o.mouse "a") +(set nvim.o.updatetime 500) +(set nvim.o.sessionoptions "blank,curdir,folds,help,tabpages,winsize") diff --git a/nvim/fnl/config/init.fnl b/nvim/fnl/config/init.fnl new file mode 100644 index 0000000..9b68e2d --- /dev/null +++ b/nvim/fnl/config/init.fnl @@ -0,0 +1,4 @@ +(module config.init + {require [config.core + config.mapping + config.plugin]}) diff --git a/nvim/fnl/config/mapping.fnl b/nvim/fnl/config/mapping.fnl new file mode 100644 index 0000000..9289652 --- /dev/null +++ b/nvim/fnl/config/mapping.fnl @@ -0,0 +1,27 @@ +(module config.mapping + {autoload {nvim aniseed.nvim + nu aniseed.nvim.util + core aniseed.core}}) + +(defn- noremap [mode from to] + "Sets a mapping with {:noremap true}" + (nvim.set_keymap mode from to {:noremap true})) + +(set nvim.g.mapleader " ") +(set nvim.g.maplocalleader ",") + +(set nvim.o.signcolumn "yes") + +(noremap :n :u ":UndotreeToggle") + +(noremap :n :h :) +(noremap :n :j :) +(noremap :n :k :) +(noremap :n :l :) +(noremap :n : :) +(noremap :n : :) +(noremap :v : :) +(noremap :v : :) + +(nvim.set_keymap :v :v ":call expand_region#next('v', '+')" {}) +(nvim.set_keymap :v : ":call expand_region#next('v', '-')" {}) diff --git a/nvim/fnl/config/module/core.fnl b/nvim/fnl/config/module/core.fnl new file mode 100644 index 0000000..352d616 --- /dev/null +++ b/nvim/fnl/config/module/core.fnl @@ -0,0 +1,12 @@ +(local nvim (require :aniseed.nvim)) + +;; Generic Neovim configuration. +(set nvim.o.termguicolors true) +(set nvim.o.list true) +(set nvim.o.spell true) +(set nvim.o.wildmenu true) +(set nvim.o.wildmode "list:longest,full") +(set nvim.o.mouse "a") +(set nvim.o.updatetime 500) +(set nvim.o.sessionoptions "blank,curdir,folds,help,tabpages,winsize") +;; (nvim.colorscheme "base16-oceanicnext") diff --git a/nvim/fnl/config/module/plugin.fnl b/nvim/fnl/config/module/plugin.fnl new file mode 100644 index 0000000..6eca029 --- /dev/null +++ b/nvim/fnl/config/module/plugin.fnl @@ -0,0 +1,79 @@ +(local nvim (require :aniseed.nvim)) +(local core (require :aniseed.core)) +(local util (require :config.util)) + +(lambda plug [coord ?opts] + "Defines a plugin through vim-plug." + (if (= opts nil) + (nvim.fn.plug# coord) + (nvim.fn.plug# coord opts))) + +(fn known-plugin? [candidate] + "Returns true if the given name can be found within any of the required + plugin names. So `deoplete` would match `deoplete.nvim`." + (or (. nvim.g.plugs candidate) + (->> (core.keys nvim.g.plugs) + (core.some + (fn [plug-name] + (plug-name:find candidate 1 true)))))) + +;; Set up vim-plug, like in init.vim earlier. +(nvim.fn.plug#begin (.. (nvim.fn.stdpath "data") "/plugged")) + +;; This is in init.vim but if it's not here too sync.sh will delete it. +; (plug "Olical/aniseed") +(plug "Olical/aniseed" {:branch :develop}) + +(plug "inkarkat/vim-ReplaceWithRegister") +(plug "chriskempson/base16-vim") + +;; LSP Stuff +(plug "williamboman/mason.nvim") +(plug "williamboman/mason-lspconfig.nvim") +(plug "neovim/nvim-lspconfig") + +;; Lisp-in-lua +(plug "Olical/conjure") +(plug "bakpakin/fennel.vim") + +(plug "ctrlpvim/ctrlp.vim") + +;; Usable dispatch +(plug "tpope/vim-dispatch") +(plug "radenling/vim-dispatch-neovim") + +;; Follow symlinks +(plug "moll/vim-bbye") +(plug "aymericbeaumet/vim-symlink") + +;; Respect editorconfig +(plug "gpanders/editorconfig.nvim") + +(plug "terryma/vim-expand-region") + + +;; TODO CONFIGURE +(plug "nvim-treesitter/nvim-treesitter" {:do ":TSUpdate"}) +(plug "https://git.sr.ht/~p00f/nvim-ts-rainbow") + +;; TODO CONFIGURE +(plug "datwaft/bubbly.nvim") + +(plug "tpope/vim-fugitive") +(plug "mhinz/vim-signify") +(plug "tpope/vim-commentary") +(plug "mbbill/undotree") +(plug "folke/which-key.nvim") +(plug "airblade/vim-rooter") + +;; Define all required plugins. +(nvim.fn.plug#end) + +;; Load plugin configuration modules. +(core.run! + (fn [path] + (let [name (nvim.fn.fnamemodify path ":t:r")] + (if (known-plugin? name) + (require (.. "config.module.plugin." name)) + (print (.. "Orphan plugin configuration: " name))))) + (util.glob (.. (nvim.fn.stdpath "config") "/lua/config/module/plugin/*.lua"))) diff --git a/nvim/fnl/config/module/plugin/base16-vim.fnl b/nvim/fnl/config/module/plugin/base16-vim.fnl new file mode 100644 index 0000000..5c5c805 --- /dev/null +++ b/nvim/fnl/config/module/plugin/base16-vim.fnl @@ -0,0 +1,4 @@ +(local nvim (require :aniseed.nvim)) + +(nvim.ex.colorscheme "base16-oceanicnext") + diff --git a/nvim/fnl/config/module/plugin/bubbly.fnl b/nvim/fnl/config/module/plugin/bubbly.fnl new file mode 100644 index 0000000..4e4cfee --- /dev/null +++ b/nvim/fnl/config/module/plugin/bubbly.fnl @@ -0,0 +1,3 @@ +(local nvim (require :aniseed.nvim)) + +(set nvim.g.bubbly_tabline 1) diff --git a/nvim/fnl/config/module/plugin/mason.fnl b/nvim/fnl/config/module/plugin/mason.fnl new file mode 100644 index 0000000..2773a69 --- /dev/null +++ b/nvim/fnl/config/module/plugin/mason.fnl @@ -0,0 +1,4 @@ +(local nvim (require :aniseed.nvim)) + +(nvim.ex.lua "require('mason').setup()") +(nvim.ex.lua "require('mason-lspconfig').setup()") diff --git a/nvim/fnl/config/plugin.fnl b/nvim/fnl/config/plugin.fnl new file mode 100644 index 0000000..cd6dd93 --- /dev/null +++ b/nvim/fnl/config/plugin.fnl @@ -0,0 +1,64 @@ +(module config.plugin + {autoload {nvim aniseed.nvim + a aniseed.core + util config.util + : packer}}) + + +(defn safe-require-plugin-config [name] + (let [(ok? val-or-err) (pcall require (.. :config.plugin. name))] + (when (not ok?) + (print (.. "config error: " val-or-err))))) + +(defn- use [...] + "Iterates through the arguments as pairs and calls packer's use function for + each of them. Works around Fennel not liking mixed associative and sequential + tables as well." + (let [pkgs [...]] + (packer.startup + (fn [use] + (for [i 1 (a.count pkgs) 2] + (let [name (. pkgs i) + opts (. pkgs (+ i 1))] + (-?> (. opts :mod) (safe-require-plugin-config)) + (use (a.assoc opts 1 name))))))) + nil) + +(use + ;; Defined further up + :wbthomason/packer.nvim {} + :Olical/aniseed {} + :lewis6991/impatient.nvim {} + + + :inkarkat/vim-ReplaceWithRegister {} + :chriskempson/base16-vim {:mod :colorscheme} + + :williamboman/mason.nvim {} + :williamboman/mason-lspconfig.nvim {} + :neovim/nvim-lspconfig {:mod :lspconfig :requires [[:williamboman/mason.nvim] [:williamboman/mason-lspconfig.nvim]]} + + :ctrlpvim/ctrlp.vim {:mod :ctrlp} + + :radenling/vim-dispatch-neovim {:requires [[:tpope/vim-dispatch]]} + + :moll/vim-bbye {} + :aymericbeaumet/vim-symlink {} + :gpanders/editorconfig.nvim {} + + :terryma/vim-expand-region {} + + ;; TODO CONFIGURE + :nvim-treesitter/nvim-treesitter {:mod :treesitter :event ["BufEnter"] :run ":TSUpdate"} + + "https://git.sr.ht/~p00f/nvim-ts-rainbow" {:requires [[:nvim-treesitter/nvim-treesitter]]} + + ;; TODO CONFIGURE + :datwaft/bubbly.nvim {:mod :bubbly} + + :tpope/vim-fugitive {:mod :fugitive} + :mhinz/vim-signify {} + :tpope/vim-commentary {} + :mbbill/undotree {} + :folke/which-key.nvim {:mod :which-key} + :airblade/vim-rooter {}) diff --git a/nvim/fnl/config/plugin/bubbly.fnl b/nvim/fnl/config/plugin/bubbly.fnl new file mode 100644 index 0000000..0c77c28 --- /dev/null +++ b/nvim/fnl/config/plugin/bubbly.fnl @@ -0,0 +1,18 @@ +(module config.plugin.bubbly + {autoload {nvim aniseed.nvim}}) + +(set nvim.g.bubbly_palette { + :background "#34343c" + :foreground "#c5cdd9" + :black "3e4249" + :red "#ec5f67" + :green "#99c794" + :yellow "#fac863" + :blue "#6699cc" + :purple "#c594c5" + :cyan "#62b3b2" + :white "#ffffff" + :lightgrey "#a7adba" + :darkgrey "#65737e" + }) + diff --git a/nvim/fnl/config/plugin/colorscheme.fnl b/nvim/fnl/config/plugin/colorscheme.fnl new file mode 100644 index 0000000..be94cc1 --- /dev/null +++ b/nvim/fnl/config/plugin/colorscheme.fnl @@ -0,0 +1,4 @@ +(module config.plugin.colorscheme + {autoload {nvim aniseed.nvim}}) + +(nvim.ex.colorscheme "base16-oceanicnext") diff --git a/nvim/fnl/config/plugin/ctrlp.fnl b/nvim/fnl/config/plugin/ctrlp.fnl new file mode 100644 index 0000000..2316c67 --- /dev/null +++ b/nvim/fnl/config/plugin/ctrlp.fnl @@ -0,0 +1,6 @@ +(module config.plugin.ctrlp + {autoload {nvim aniseed.nvim}}) + +(set nvim.g.ctrlp_map "p") +(set nvim.g.ctrlp_cmd "CtrlPMixed") +(set nvim.g.ctrlp_user_command "rg --files %s") diff --git a/nvim/fnl/config/plugin/fugitive.fnl b/nvim/fnl/config/plugin/fugitive.fnl new file mode 100644 index 0000000..2fb871c --- /dev/null +++ b/nvim/fnl/config/plugin/fugitive.fnl @@ -0,0 +1,2 @@ +(module config.plugin.fugitive + {autoload {nvim aniseed.nvim}}) diff --git a/nvim/fnl/config/plugin/lspconfig.fnl b/nvim/fnl/config/plugin/lspconfig.fnl new file mode 100644 index 0000000..082bca1 --- /dev/null +++ b/nvim/fnl/config/plugin/lspconfig.fnl @@ -0,0 +1,13 @@ +(module config.plugin.lspconfig + {autoload {nvim aniseed.nvim + util config.util}}) + + +(let [(lspconfig? lspconfig) (pcall require :lspconfig) + (mason? mason) (pcall require :mason) + (mason-lsp? mason-lsp) (pcall require :mason-lspconfig)] + (when ok? + (mason.setup) + (mason-lsp.setup) + (lspconfig.rust_analyzer.setup {}) + (lspconfig.yamlls.setup {}))) diff --git a/nvim/fnl/config/plugin/treesitter.fnl b/nvim/fnl/config/plugin/treesitter.fnl new file mode 100644 index 0000000..d4830f9 --- /dev/null +++ b/nvim/fnl/config/plugin/treesitter.fnl @@ -0,0 +1,37 @@ +(module config.plugin.treesitter + {autoload {nvim aniseed.nvim}}) + +(let [(ok? ts) (pcall require :nvim-treesitter.configs)] + (when ok? + (ts.setup + {:highlight {:enable true :additional_vim_regex_highlighting false} + :rainbow {:enable true + :extended_mode true + :max_files_lines nil} + :incremental_selection { + :enable true + :keymaps { + :init_selection "s" + :node_incremental "u" + :scope_incremental "s" + :node_decremental "d" + } + } + :refactor { + :highlight_definitions {:enable true} + :smart_rename { + :enable true + :keymaps { + :smart_rename "r" + } + } + } + :navigation { + :enable true + :keymaps {:goto_definition "tg" + :list_definition "ta"} + } + :ensure_installed [:python :yaml :rust :fennel :lua]}) + (set nvim.o.foldmethod "expr") + (set nvim.o.foldexpr "nvim_treesitter#foldexpr()") + )) diff --git a/nvim/fnl/config/plugin/which-key.fnl b/nvim/fnl/config/plugin/which-key.fnl new file mode 100644 index 0000000..61042c1 --- /dev/null +++ b/nvim/fnl/config/plugin/which-key.fnl @@ -0,0 +1,5 @@ +(module config.plugin.which-key) + +(let [(ok? which-key) (pcall #(require :which-key))] + (when ok? + (which-key.setup {}))) diff --git a/nvim/fnl/config/util.fnl b/nvim/fnl/config/util.fnl new file mode 100644 index 0000000..910ff88 --- /dev/null +++ b/nvim/fnl/config/util.fnl @@ -0,0 +1,26 @@ +(module config.util + {autoload {nvim aniseed.nvim + a aniseed.core}}) + +(fn expand [path] + (nvim.fn.expand path)) + +(fn glob [path] + (nvim.fn.glob path true true true)) + +(fn exists? [path] + (= (nvim.fn.filereadable path) 1)) + +(fn lua-file [path] + (nvim.ex.luafile path)) + +(defn nnoremap [from to opts] + (let [map-opts {:noremap true} + to (.. ":" to "")] + (if (a.get opts :local?) + (nvim.buf_set_keymap 0 :n from to map-opts) + (nvim.set_keymap :n from to map-opts)))) + +(defn lnnoremap [from to] + (nnoremap (.. "" from) to)) + diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..b52f014 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,26 @@ +local execute = vim.api.nvim_command +local fn = vim.fn + +local pack_path = fn.stdpath("data") .. "/site/pack" +local fmt = string.format + +function ensure (user, repo) + -- Ensures a given github.com/USER/REPO is cloned in the pack/packer/start directory. + local install_path = fmt("%s/packer/start/%s", pack_path, repo) + if fn.empty(fn.glob(install_path)) > 0 then + execute(fmt("!git clone https://github.com/%s/%s %s", user, repo, install_path)) + execute(fmt("packadd %s", repo)) + end +end + +ensure("wbthomason", "packer.nvim") +ensure("Olical", "aniseed") +ensure("lewis6991", "impatient.nvim") + +require("impatient") + +vim.g["aniseed#env"] = { + module = "config.init", + compile = true +} +