From 40e0a096e83e6e2f6107df982dadf889fdd16c10 Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Sat, 16 Dec 2023 19:40:08 +0100 Subject: [PATCH] Migrate more neovim plugins from lua to nix --- home/features/neovim/config/lazy-lock.json | 16 +- .../neovim/config/lua/my/plugins/clue.lua | 99 ++++++ .../neovim/config/lua/my/plugins/gitsigns.lua | 7 +- .../neovim/config/lua/my/plugins/idris.lua | 44 --- .../neovim/config/lua/my/plugins/iron.lua | 63 ---- .../neovim/config/lua/my/plugins/lean.lua | 26 -- .../config/lua/my/plugins/lspconfig.lua | 4 +- .../neovim/config/lua/my/plugins/magma.lua | 61 ---- .../config/lua/my/plugins/mini-files.lua | 30 -- .../config/lua/my/plugins/mini-operators.lua | 7 - .../config/lua/my/plugins/mini-surround.lua | 42 --- .../neovim/config/lua/my/plugins/neogit.lua | 26 -- .../config/lua/my/plugins/telescope.lua | 76 ----- .../neovim/config/lua/my/plugins/venn.lua | 71 ++-- .../neovim/config/lua/my/plugins/vimux.lua | 40 --- .../neovim/config/lua/my/plugins/whichkey.lua | 2 +- .../features/neovim/config/lua/my/runtime.lua | 10 +- home/features/neovim/default.nix | 316 +++++++++++++++--- modules/common/lua-encoders.nix | 16 +- modules/common/neovim.nix | 63 +++- 20 files changed, 481 insertions(+), 538 deletions(-) create mode 100644 home/features/neovim/config/lua/my/plugins/clue.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/idris.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/iron.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/lean.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/magma.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/mini-files.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/mini-operators.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/mini-surround.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/neogit.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/telescope.lua delete mode 100644 home/features/neovim/config/lua/my/plugins/vimux.lua diff --git a/home/features/neovim/config/lazy-lock.json b/home/features/neovim/config/lazy-lock.json index b10a92b..48e1bb1 100644 --- a/home/features/neovim/config/lazy-lock.json +++ b/home/features/neovim/config/lazy-lock.json @@ -1,7 +1,7 @@ { "LuaSnip": { "branch": "master", "commit": "118263867197a111717b5f13d954cd1ab8124387" }, "alpha-nvim": { "branch": "main", "commit": "29074eeb869a6cbac9ce1fbbd04f5f5940311b32" }, - "catppuccin": { "branch": "main", "commit": "64dc309bc157779691be38bbfc5123584e0a4a85" }, + "catppuccin": { "branch": "main", "commit": "079500a625f3ae5aa6efb758f1a17fe4c7a57e52" }, "clipboard-image": { "branch": "main", "commit": "485de5493d196154db30f85665f8ac480ce116a2" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" }, @@ -24,17 +24,15 @@ "haskell-tools": { "branch": "master", "commit": "92e097c6832405fb64e4c44a7ce8bebe7836cae6" }, "hydra.nvim": { "branch": "master", "commit": "3ced42c0b6a6c85583ff0f221635a7f4c1ab0dd0" }, "hyprland-vim-syntax": { "branch": "main", "commit": "8488a24b50882da969979103b4d668c70e7995b9" }, - "idris2-nvim": { "branch": "main", "commit": "8bff02984a33264437e70fd9fff4359679d910da" }, + "idris": { "branch": "main", "commit": "8bff02984a33264437e70fd9fff4359679d910da" }, "inc-rename.nvim": { "branch": "main", "commit": "a48c7cec5c4f00d7438dce5fadb55f4d715ef9f2" }, "indent-blankline": { "branch": "master", "commit": "7206c77cb931f79885fc47f88ae18f99148392eb" }, - "iron.nvim": { "branch": "master", "commit": "7f876ee3e1f4ea1e5284b1b697cdad5b256e8046" }, "kmonad-vim": { "branch": "master", "commit": "37978445197ab00edeb5b731e9ca90c2b141723f" }, "kotlin-vim": { "branch": "master", "commit": "53fe045906df8eeb07cb77b078fc93acda6c90b8" }, "lastplace": { "branch": "main", "commit": "0bb6103c506315044872e0f84b1f736c4172bb20" }, "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, - "lean.nvim": { "branch": "main", "commit": "360908674890f3bd92eb41c5b362510dca8fc4cb" }, + "lean": { "branch": "main", "commit": "a5daac8ebccb93af25ace2a2041b503f18ff3dcb" }, "lspkind.nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" }, - "magma-nvim": { "branch": "main", "commit": "ff3deba8a879806a51c005e50782130246143d06" }, "mini.comment": { "branch": "main", "commit": "3d9c8009615857e982f09bc5357fc95f2a2175f3" }, "mini.files": { "branch": "main", "commit": "173d73f5d0b2a9abbb2d6533a3770fdbbd0c4dcc" }, "mini.operators": { "branch": "main", "commit": "7a97e2528a4c274e9da8953d3ba22f493c360a9f" }, @@ -45,6 +43,7 @@ "neodev.nvim": { "branch": "main", "commit": "c4ce017bd4bacf60bf59330cec9e93c5d5e104a6" }, "neogit": { "branch": "master", "commit": "761e9be2aa7cc4c8ca87f10c8c37108a687b928e" }, "nui": { "branch": "main", "commit": "c9b4de623d19a85b353ff70d2ae9c77143abe69c" }, + "nui.nvim": { "branch": "main", "commit": "c9b4de623d19a85b353ff70d2ae9c77143abe69c" }, "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, "nvim-autopairs": { "branch": "master", "commit": "0f04d78619cce9a5af4f355968040f7d675854a1" }, "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, @@ -65,17 +64,12 @@ "scrap.nvim": { "branch": "main", "commit": "0f833d8dccaabe49c1ed7a2b24cfd887d9d5003f" }, "smart-splits.nvim": { "branch": "master", "commit": "c970c7a3cc7ba635fd73d43c81b40f04c00f5058" }, "ssr": { "branch": "main", "commit": "bb323ba621ac647b4ac5638b47666e3ef3c279e1" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, - "telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, + "telescope": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, "typst.vim": { "branch": "main", "commit": "5b11b42de1703838ca1bb31dc66e73c002698e49" }, "undotree": { "branch": "master", "commit": "36ff7abb6b60980338344982ad4cdf03f7961ecd" }, - "venn.nvim": { "branch": "main", "commit": "e4d68341a73dd56c64955058821a58295fb337b1" }, "vim-teal": { "branch": "master", "commit": "d2aa107b257879e774680792a2aebaf9cd5742e0" }, - "vim-tmux-navigator": { "branch": "master", "commit": "7db70e08ea03b3e4d91f63713d76134512e28d7e" }, - "vimux": { "branch": "master", "commit": "616fcb4799674a7a809b14ca2dc155bb6ba25788" }, "wakatime": { "branch": "master", "commit": "8c8856327815a077cbebeba8c7456312a3d2c39c" }, "web-devicons": { "branch": "master", "commit": "5efb8bd06841f91f97c90e16de85e96d57e9c862" }, - "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }, "winbar": { "branch": "main", "commit": "13739fdb31be51a1000486189662596f07a59a31" }, "yuck.vim": { "branch": "master", "commit": "9b5e0370f70cc30383e1dabd6c215475915fe5c3" } } \ No newline at end of file diff --git a/home/features/neovim/config/lua/my/plugins/clue.lua b/home/features/neovim/config/lua/my/plugins/clue.lua new file mode 100644 index 0000000..da40204 --- /dev/null +++ b/home/features/neovim/config/lua/my/plugins/clue.lua @@ -0,0 +1,99 @@ +local M = { + "echasnovski/mini.clue", + lazy = false, +} + +function M.config() + local miniclue = require("mini.clue") + miniclue.setup({ + triggers = { + -- Leader triggers + { mode = "n", keys = "" }, + { mode = "x", keys = "" }, + { mode = "v", keys = "" }, + }, + clues = { + -- Enhance this by adding descriptions for mapping groups + miniclue.gen_clues.builtin_completion(), + miniclue.gen_clues.g(), + miniclue.gen_clues.marks(), + miniclue.gen_clues.registers(), + miniclue.gen_clues.windows(), + miniclue.gen_clues.z(), + { + mode = "n", + keys = "f", + desc = "[F]iles", + }, + { + mode = "n", + keys = "g", + desc = "[G]o to", + }, + { + mode = "n", + keys = "r", + desc = "[R]ename / [R]eplace / [R]eload", + }, + { + mode = "n", + keys = "l", + desc = "[L]ocal", + }, + { + mode = "n", + keys = "w", + desc = "[W]orkspace", + }, + { + mode = "n", + keys = "y", + desc = "[Y]ank", + }, + { + mode = "n", + keys = "s", + desc = "[S]ettings", + }, + { + mode = "n", + keys = "v", + desc = "[V]imux", + }, + { + mode = "n", + keys = "h", + desc = "git [h]hunks", + }, + { + mode = "n", + keys = "VH", + postkeys = "V", + }, + { + mode = "n", + keys = "VJ", + postkeys = "V", + }, + { + mode = "n", + keys = "VK", + postkeys = "V", + }, + { + mode = "n", + keys = "VL", + postkeys = "V", + }, + { + mode = "n", + keys = "Vf", + postkeys = "V", + }, + }, + }) + + require("my.keymaps").nmap("Q", ":wqa", "Save all files and [q]uit") +end + +return {} diff --git a/home/features/neovim/config/lua/my/plugins/gitsigns.lua b/home/features/neovim/config/lua/my/plugins/gitsigns.lua index 9e393e8..76a7a8b 100644 --- a/home/features/neovim/config/lua/my/plugins/gitsigns.lua +++ b/home/features/neovim/config/lua/my/plugins/gitsigns.lua @@ -6,7 +6,6 @@ local M = { cond = env.firenvim.not_active() and env.vscode.not_active(), opts = { on_attach = function(bufnr) - local wk = require("which-key") local gs = package.loaded.gitsigns -- {{{ Helpers @@ -51,9 +50,9 @@ local M = { -- {{{ Actions local prefix = "h" - wk.register({ - [""] = { h = { name = "gitsigns" } }, - }) + -- require("which-key").register({ + -- [""] = { h = { name = "gitsigns" } }, + -- }) -- {{{ Normal mode map("n", prefix .. "s", gs.stage_hunk, "[s]tage hunk") diff --git a/home/features/neovim/config/lua/my/plugins/idris.lua b/home/features/neovim/config/lua/my/plugins/idris.lua deleted file mode 100644 index ba490dc..0000000 --- a/home/features/neovim/config/lua/my/plugins/idris.lua +++ /dev/null @@ -1,44 +0,0 @@ -local env = require("my.helpers.env") -local lspconfig = require("my.plugins.lspconfig") - -local M = { - "ShinKage/idris2-nvim", - dependencies = {"nui.nvim", "nvim-lspconfig"}, - ft = { "idris2", "lidris2", "ipkg" }, - cond = env.vscode.not_active(), -} - -function M.config() - local idris2 = require("idris2") - - idris2.setup({ - server = { - on_attach = function(client, bufnr) - lspconfig.on_attach(client, bufnr) - - local function nmap(from, to, desc) - vim.keymap.set("n", "I" .. from, function() - require("idris2.code_action")[to]() - end, { desc = desc, bufnr = true }) - end - - nmap("C", "make_case", "Make [c]ase") - nmap("L", "make_lemma", "Make [l]emma") - nmap("c", "add_clause", "Add [c]lause") - nmap("e", "expr_search", "[E]xpression search") - nmap("d", "generate_def", "Generate [d]efinition") - nmap("s", "case_split", "Case [s]plit") - nmap("h", "refine_hole", "Refine [h]ole") - - local status, wk = pcall(require, "which-key") - - if status then - wk.register({ ["I"] = { name = "[I]dris", buffer = bufnr } }) - end - end, - }, - client = { hover = { use_split = true } }, - }) -end - -return M diff --git a/home/features/neovim/config/lua/my/plugins/iron.lua b/home/features/neovim/config/lua/my/plugins/iron.lua deleted file mode 100644 index 6629de0..0000000 --- a/home/features/neovim/config/lua/my/plugins/iron.lua +++ /dev/null @@ -1,63 +0,0 @@ -local env = require("my.helpers.env") - -local M = { - "hkupty/iron.nvim", -- repl support - cond = env.vscode.not_active(), - cmd = "IronRepl", -} - -function M.init() - -- iron also has a list of commands, see :h iron-commands for all available commands - vim.keymap.set("n", "iss", "IronRepl") - vim.keymap.set("n", "ir", "IronRestart") - vim.keymap.set("n", "if", "IronFocus") - vim.keymap.set("n", "ih", "IronHide") - - local status, wk = pcall(require, "which-key") - - if status then - wk.register({ - ["i"] = { - name = "[I]ron repl", - s = { name = "[s]end" }, - m = { name = "[m]ark" }, - }, - }) - end -end - -function M.config() - local iron = require("iron.core") - - iron.setup({ - config = { - -- Your repl definitions come here - repl_definition = {}, - -- How the repl window will be displayed - -- See below for more information - repl_open_cmd = require("iron.view").right(40), - }, - -- Iron doesn't set keymaps by default anymore. - -- You can set them here or manually add keymaps to the functions in iron.core - keymaps = { - send_motion = "isc", - visual_send = "is", - send_file = "isf", - send_line = "isl", - send_mark = "ism", - mark_motion = "imc", - mark_visual = "imc", - remove_mark = "imd", - cr = "is", - interrupt = "is", - exit = "isq", - clear = "isr", - }, - -- If the highlight is on, you can change how it looks - -- For the available options, check nvim_set_hl - highlight = { italic = true }, - ignore_blank_lines = true, -- ignore blank lines when sending visual select lines - }) -end - -return M diff --git a/home/features/neovim/config/lua/my/plugins/lean.lua b/home/features/neovim/config/lua/my/plugins/lean.lua deleted file mode 100644 index 291d05c..0000000 --- a/home/features/neovim/config/lua/my/plugins/lean.lua +++ /dev/null @@ -1,26 +0,0 @@ -local env = require("my.helpers.env") -local lspconfig = require("my.plugins.lspconfig") - -local M = { - "Julian/lean.nvim", -- lean support - dependencies = { - "neovim/nvim-lspconfig", - "nvim-lua/plenary.nvim", - "hrsh7th/nvim-cmp", - }, - ft = "lean", - config = function() - require("lean").setup({ - abbreviations = { builtin = true, cmp = true }, - lsp = { - on_attach = lspconfig.on_attach, - capabilities = lspconfig.capabilities(), - }, - lsp3 = false, - mappings = true, - }) - end, - cond = env.vscode.not_active(), -} - -return M diff --git a/home/features/neovim/config/lua/my/plugins/lspconfig.lua b/home/features/neovim/config/lua/my/plugins/lspconfig.lua index c207256..475dd7f 100644 --- a/home/features/neovim/config/lua/my/plugins/lspconfig.lua +++ b/home/features/neovim/config/lua/my/plugins/lspconfig.lua @@ -39,8 +39,8 @@ function M.on_attach(client, bufnr) -- }}} -- {{{ Go to declaration / references / implementation nmap("gd", vim.lsp.buf.definition, "[G]o to [d]efinition") - nmap("gi", vim.lsp.buf.implementation, "[G]o to [i]mplementation") - nmap("gr", vim.lsp.buf.references, "[G]o to [r]eferences") + nmap("gi", vim.lsp.buf.implementation, "[G]o to [i]mplementation") + nmap("gr", vim.lsp.buf.references, "[G]o to [r]eferences") -- }}} -- {{{ Hover -- Note: diagnostics are already covered in keymaps.lua diff --git a/home/features/neovim/config/lua/my/plugins/magma.lua b/home/features/neovim/config/lua/my/plugins/magma.lua deleted file mode 100644 index b947147..0000000 --- a/home/features/neovim/config/lua/my/plugins/magma.lua +++ /dev/null @@ -1,61 +0,0 @@ -local M = { - "dccsillag/magma-nvim", - cmd = "MagmaInit", - config = function() - local prefix = "M" - - local status, wk = pcall(require, "which-key") - - if status then - wk.register({ - [prefix] = { - desc = "[M]agma", - }, - }) - end - - vim.keymap.set( - "n", - prefix .. "e", - "MagmaEvaluateOperator", - { expr = true, silent = true, desc = "[E]valuate motion" } - ) - - vim.keymap.set( - "n", - prefix .. "ee", - "MagmaEvaluateLine", - { silent = true, desc = "[E]valuate line" } - ) - - vim.keymap.set( - "n", - prefix .. "r", - "MagmaReevaluateCell", - { silent = true, desc = "[R]e-evaluate cell" } - ) - - vim.keymap.set( - "n", - prefix .. "d", - "MagmaDelete", - { silent = true, desc = "[D]elete cell" } - ) - - vim.keymap.set( - "n", - prefix .. "o", - "MagmaShowOutput", - { silent = true, desc = "Show [o]utput" } - ) - - vim.keymap.set( - "v", - prefix .. "e", - "MagmaEvaluateVisual", - { silent = true, desc = "[E]vluate visual selection" } - ) - end, -} - -return M diff --git a/home/features/neovim/config/lua/my/plugins/mini-files.lua b/home/features/neovim/config/lua/my/plugins/mini-files.lua deleted file mode 100644 index aba31d8..0000000 --- a/home/features/neovim/config/lua/my/plugins/mini-files.lua +++ /dev/null @@ -1,30 +0,0 @@ -local K = require("my.keymaps") -local env = require("my.helpers.env") - -local M = { - "echasnovski/mini.files", - keys = { "" }, - cond = env.vscode.not_active() and env.firenvim.not_active(), -} - -function M.config() - local files = require("mini.files") - - files.setup({ - windows = { - preview = false, - }, - mappings = { - go_in_plus = "l", - }, - }) - - K.nmap("", function() - if not files.close() then - files.open(vim.api.nvim_buf_get_name(0)) - files.reveal_cwd() - end - end, "[S]earch [F]iles") -end - -return M diff --git a/home/features/neovim/config/lua/my/plugins/mini-operators.lua b/home/features/neovim/config/lua/my/plugins/mini-operators.lua deleted file mode 100644 index d9fa955..0000000 --- a/home/features/neovim/config/lua/my/plugins/mini-operators.lua +++ /dev/null @@ -1,7 +0,0 @@ -local M = { - "echasnovski/mini.operators", - event = "BufReadPost", - config = true, -} - -return M diff --git a/home/features/neovim/config/lua/my/plugins/mini-surround.lua b/home/features/neovim/config/lua/my/plugins/mini-surround.lua deleted file mode 100644 index b89be37..0000000 --- a/home/features/neovim/config/lua/my/plugins/mini-surround.lua +++ /dev/null @@ -1,42 +0,0 @@ -local M = { - "echasnovski/mini.surround", - event = "BufReadPost", -} - -function M.config() - require("mini.surround").setup({ - mappings = { - add = "s", -- Add surrounding in Normal and Visul modes - delete = "d", -- Delete surrounding - find = "f", -- Find surrounding (to the right) - find_left = "F", -- Find surrounding (to the left) - highlight = "h", -- Highlight surrounding - replace = "r", -- Replace surrounding - update_n_lines = "", -- Update `n_lines` - }, - custom_surroundings = { - ["b"] = { - input = { "%b()", "^.%s*().-()%s*.$" }, - output = { left = "(", right = ")" }, - }, - ["B"] = { - input = { "%b{}", "^.%s*().-()%s*.$" }, - output = { left = "{", right = "}" }, - }, - ["r"] = { - input = { "%b[]", "^.%s*().-()%s*.$" }, - output = { left = "[", right = "]" }, - }, - ["q"] = { - input = { '".-"', "^.().*().$" }, - output = { left = '"', right = '"' }, - }, - ["a"] = { - input = { "'.-'", "^.().*().$" }, - output = { left = "'", right = "'" }, - }, - }, - }) -end - -return M diff --git a/home/features/neovim/config/lua/my/plugins/neogit.lua b/home/features/neovim/config/lua/my/plugins/neogit.lua deleted file mode 100644 index 2b5abe7..0000000 --- a/home/features/neovim/config/lua/my/plugins/neogit.lua +++ /dev/null @@ -1,26 +0,0 @@ -local env = require("my.helpers.env") - -local M = { - "TimUntersberger/neogit", - dependencies = { "nvim-lua/plenary.nvim" }, - cmd = "Neogit", - cond = env.firenvim.not_active() and env.vscode.not_active(), - init = function() - vim.keymap.set("n", "", "Neogit", { desc = "Open neo[g]it" }) - end, - config = function() - require("neogit").setup({}) - - -- {{{ Disable folds inside neogit - vim.api.nvim_create_autocmd("FileType", { - pattern = { "NeogitStatus" }, - group = vim.api.nvim_create_augroup("NeogitStatusOptions", {}), - callback = function() - vim.opt.foldenable = false - end, - }) - -- }}} - end, -} - -return M diff --git a/home/features/neovim/config/lua/my/plugins/telescope.lua b/home/features/neovim/config/lua/my/plugins/telescope.lua deleted file mode 100644 index 8defe70..0000000 --- a/home/features/neovim/config/lua/my/plugins/telescope.lua +++ /dev/null @@ -1,76 +0,0 @@ -local env = require("my.helpers.env") - -local telescope = { - "nvim-telescope/telescope.nvim", - cmd = "Telescope", - dependencies = { - { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, - "nvim-lua/plenary.nvim", - }, - version = "0.1.x", - cond = env.vscode.not_active(), -} - -local M = telescope - -local function find_files_by_extension(extension) - return "find_files find_command=rg,--files,--glob=**/*." .. extension -end - -local function with_theme(base, theme) - return base .. " theme=" .. theme -end - -local defaultTheme = "ivy" - -local keybinds = { - { "", "find_files", "Find files" }, - { "ft", find_files_by_extension("tex"), "[F]ind [t]ex files" }, - { "fl", find_files_by_extension("lua"), "[F]ind [l]ua files" }, - { "fn", find_files_by_extension("nix"), "[F]ind [n]ix files" }, - { - "fp", - find_files_by_extension("purs"), - "[F]ind [p]urescript files", - }, - { "d", "diagnostics", "[D]iagnostics" }, - { "", "live_grep", "[F]ind in project" }, - { "t", "builtin", "[T]elescope pickers" }, -} - -local function mkAction(action) - if not string.find(action, "theme=") then - action = with_theme(action, defaultTheme) - end - - if not string.find(action, "winblend=") and env.neovide.active() then - action = action .. " winblend=45" - end - - return "Telescope " .. action .. "" -end - -function telescope.init() - for _, mapping in pairs(keybinds) do - vim.keymap.set("n", mapping[1], mkAction(mapping[2]), { desc = mapping[3] }) - end -end - -function telescope.config() - local settings = { - defaults = { mappings = { i = { [""] = "which_key" } } }, - pickers = { find_files = { hidden = true } }, - extensions = { - fzf = { - fuzzy = true, - override_generic_sorter = true, - override_file_sorter = true, - }, - }, - } - - require("telescope").setup(settings) - require("telescope").load_extension("fzf") -end - -return M diff --git a/home/features/neovim/config/lua/my/plugins/venn.lua b/home/features/neovim/config/lua/my/plugins/venn.lua index bccc771..0bc37ad 100644 --- a/home/features/neovim/config/lua/my/plugins/venn.lua +++ b/home/features/neovim/config/lua/my/plugins/venn.lua @@ -28,39 +28,46 @@ local venn_hint = H.concat_many_h({ }, 3).value function M.config() - local Hydra = require("hydra") + local r = "V" + vim.keymap.set("n", r .. "H", "h:VBox", { desc = "left" }) + vim.keymap.set("n", r .. "J", "j:VBox", { desc = "down" }) + vim.keymap.set("n", r .. "K", "k:VBox", { desc = "up" }) + vim.keymap.set("n", r .. "L", "l:VBox", { desc = "right" }) + vim.keymap.set("v", r .. "f", ":VBox", { desc = "box" }) - Hydra({ - name = "Draw Diagram", - hint = venn_hint, - config = { - color = "pink", - invoke_on_body = true, - hint = { - border = "single", - }, - on_enter = function() - vim.o.virtualedit = "all" - end, - }, - mode = "n", - desc = "[V]enn mode", - body = "V", - heads = { - { "H", "h:VBox" }, - { "J", "j:VBox" }, - { "K", "k:VBox" }, - { "L", "l:VBox" }, - { "f", ":VBox", { mode = "v" } }, - { "", nil, { exit = true } }, - }, - }) + -- local Hydra = require("hydra") + -- + -- Hydra({ + -- name = "Draw Diagram", + -- hint = venn_hint, + -- config = { + -- color = "pink", + -- invoke_on_body = true, + -- hint = { + -- border = "single", + -- }, + -- on_enter = function() + -- vim.o.virtualedit = "all" + -- end, + -- }, + -- mode = "n", + -- desc = "[V]enn mode", + -- body = "V", + -- heads = { + -- { "H", "h:VBox" }, + -- { "J", "j:VBox" }, + -- { "K", "k:VBox" }, + -- { "L", "l:VBox" }, + -- { "f", ":VBox", { mode = "v" } }, + -- { "", nil, { exit = true } }, + -- }, + -- }) end -function M.init() - require("which-key").register({ - ["V"] = { name = "[V]enn mode" }, - }) -end +-- function M.init() +-- require("which-key").register({ +-- ["V"] = { name = "[V]enn mode" }, +-- }) +-- end -return M +return {} diff --git a/home/features/neovim/config/lua/my/plugins/vimux.lua b/home/features/neovim/config/lua/my/plugins/vimux.lua deleted file mode 100644 index c83c6d7..0000000 --- a/home/features/neovim/config/lua/my/plugins/vimux.lua +++ /dev/null @@ -1,40 +0,0 @@ -local K = require("my.keymaps") -local env = require("my.helpers.env") - -local M = { - "preservim/vimux", -- interact with tmux from within vim - cmd = { "VimuxPromptCommand", "VimuxRunCommand", "VimuxRunLastCommand" }, - -- TODO: only enable when actually inside tmux - cond = env.vscode.not_active() - -- and env.neovide.not_active() - and env.firenvim.not_active(), -} - -function M.init() - --{{{ Register keybinds - K.nmap( - "vp", - ":VimuxPromptCommand", - "[V]imux: [p]rompt for command" - ) - K.nmap("vc", ':VimuxRunCommand "clear"', "[V]imux: [c]lear pane") - K.nmap( - "vl", - ":VimuxRunLastCommand", - "[V]imux: rerun [l]ast command" - ) - --}}} - --{{{ Register which-key docs - local status, wk = pcall(require, "which-key") - - if status then - wk.register({ - ["v"] = { - name = "[V]imux", - }, - }) - end - --}}} -end - -return M diff --git a/home/features/neovim/config/lua/my/plugins/whichkey.lua b/home/features/neovim/config/lua/my/plugins/whichkey.lua index 34e5366..a7dea3c 100644 --- a/home/features/neovim/config/lua/my/plugins/whichkey.lua +++ b/home/features/neovim/config/lua/my/plugins/whichkey.lua @@ -28,4 +28,4 @@ function M.config() }) end -return M +return {} diff --git a/home/features/neovim/config/lua/my/runtime.lua b/home/features/neovim/config/lua/my/runtime.lua index 3edec99..2761083 100644 --- a/home/features/neovim/config/lua/my/runtime.lua +++ b/home/features/neovim/config/lua/my/runtime.lua @@ -47,13 +47,13 @@ end function M.create_autocmd(opts) local callback - if type(opts.callback) == "function" then - callback = opts.callback + if type(opts.action) == "function" then + callback = opts.action end - if type(opts.callback) == "table" then + if type(opts.action) == "table" then callback = function(event) - M.configure(opts.callback, event) + M.configure(opts.action, event) end end @@ -115,9 +115,9 @@ function M.configure(opts, context) if type(context) == "table" + and context.lazy ~= nil and context.opts ~= nil and vim.inspect(context.opts) ~= "{}" - and context.lazy ~= nil then -- This is a terrible way to do it :/ local status, module = pcall(require, context.lazy.name) diff --git a/home/features/neovim/default.nix b/home/features/neovim/default.nix index 36eed1b..1885882 100644 --- a/home/features/neovim/default.nix +++ b/home/features/neovim/default.nix @@ -9,23 +9,13 @@ let rnix-lsp # nix nil # nix inputs.nixd.packages.${system}.nixd # nix - # haskell-language-server # haskell - # REASON: marked as broken - # dhall-lsp-server # dhall - # tectonic # something related to latex (?) texlab # latex nodePackages_latest.vscode-langservers-extracted # web stuff - # python310Packages.python-lsp-server # python - # pyright # python - rust-analyzer # rust typst-lsp # typst + # haskell-language-server # haskell # Formatters - # luaformatter # Lua stylua # Lua - # black # Python - # yapf # Python - # isort # Reorder python imports nodePackages_latest.purs-tidy # Purescript nodePackages_latest.prettier # Js & friends nodePackages_latest.prettier_d_slim # Js & friends @@ -33,45 +23,20 @@ let # Linters ruff # Python linter - # mypy # Python typechecking # Languages nodePackages.typescript # typescript lua # For repls and whatnot - wakatime # time tracking - rustfmt # Others fd # file finder - ripgrep # Grep rewrite update-nix-fetchgit # Useful for nix stuff tree-sitter # Syntax highlighting libstdcxx5 # Required by treesitter aparently - # python310Packages.jupytext # Convert between jupyter notebooks and python files - # graphviz # For rust crate graph - # haskellPackages.hoogle # For haskell search - - # Preview - # zathura # Pdf reader - # xdotool # For zathura reverse search or whatever it's called - # glow # Md preview in terminal - # pandoc # Md processing - # libsForQt5.falkon # Needed for one of the md preview plugins I tried # Latex setup # texlive.combined.scheme-full # Latex stuff # python38Packages.pygments # required for latex syntax highlighting - # sage - # sagetex # sage in latex - - # required for the telescope fzf extension - gnumake - cmake - gcc - - # Required by magma-nvim: - # python310Packages.pynvim - # python310Packages.jupyter ] ++ config.satellite.neovim.generated.dependencies; # }}} # {{{ extraRuntime @@ -83,7 +48,7 @@ let ) # Experimental nix module generation - config.satellite.neovim.generated.all + config.satellite.neovim.generated.lazySingleFile ]; extraRuntimeJoinedPaths = pkgs.symlinkJoin { @@ -282,6 +247,29 @@ in ''; }; # }}} + # {{{ mini.files + satellite.neovim.lazy.mini-files = { + package = "echasnovski/mini.files"; + name = "mini.files"; + dependencies.lua = [ lazy.web-devicons.package ]; + + env.blacklist = [ "vscode" "firenvim" ]; + keys = { + mapping = ""; + desc = "[S]earch [F]iles"; + action = nlib.thunk /* lua */ '' + local files = require("mini.files") + if not files.close() then + files.open(vim.api.nvim_buf_get_name(0)) + files.reveal_cwd() + end + ''; + }; + + opts.windows.preview = false; + opts.mappings.go_in_plus = "l"; + }; + # }}} # {{{ winbar satellite.neovim.lazy.winbar = { package = "fgheng/winbar.nvim"; @@ -329,6 +317,102 @@ in ]; }; # }}} + # {{{ neogit + satellite.neovim.lazy.neogit = { + package = "TimUntersberger/neogit"; + dependencies.lua = [ lazy.plenary.package ]; + + env.blacklist = [ "vscode" "firenvim" ]; + keys = { + mapping = ""; + action = "Neogit"; + desc = "Open neo[g]it"; + }; + + opts = true; # Here so the tempest runtime will call .setup + setup.autocmds = { + event = "FileType"; + pattern = "NeogitStatus"; + group = "NeogitStatusDisableFolds"; + action.vim.opt.foldenable = false; + }; + }; + # }}} + # {{{ telescope + satellite.neovim.lazy.telescope = { + package = "nvim-telescope/telescope.nvim"; + version = "0.1.x"; + env.blacklist = [ "vscode" ]; + + # {{{ Dependencies + dependencies = { + nix = [ pkgs.ripgrep ]; + lua = [ + lazy.plenary.package + { + # We want a prebuilt version of this plugin + dir = pkgs.vimPlugins.telescope-fzf-native-nvim; + name = "telescope-fzf-native"; + } + ]; + }; + # }}} + # {{{ Keymaps + keys = + let + keymap = mapping: action: desc: { + inherit mapping desc; + action = "Telescope ${action} theme=ivy"; + }; + + findFilesByExtension = mapping: extension: tag: + keymap + "f${mapping}" + "find_files find_command=rg,--files,--glob=**/*.${extension}" + "Find ${tag} files"; + in + [ + (keymap "" "find_files" "Find files") + (keymap "d" "diagnostics" "Diagnostics") + (keymap "" "live_grep" "[F]ind in project") + (keymap "t" "builtin" "[T]elescope pickers") + # {{{ Files by extension + (findFilesByExtension "tx" "tex" "[t]ex") + (findFilesByExtension "ts" "ts" "[t]ypescript") + (findFilesByExtension "ty" "typst" "[t]ypst") + (findFilesByExtension "l" "lua" "[l]ua") + (findFilesByExtension "n" "nix" "[n]ua") + (findFilesByExtension "p" "purs" "[p]urescript") + (findFilesByExtension "h" "hs" "[h]askell") + (findFilesByExtension "e" "elm" "[e]lm") + (findFilesByExtension "r" "rs" "[r]ust") + # }}} + ]; + # }}} + # {{{ Disable folds in telescope windows + setup.autocmds = { + event = "FileType"; + pattern = "TelescopeResults"; + group = "TelescopeResultsDisableFolds"; + action.vim.opt.foldenable = false; + }; + # }}} + # {{{ Load fzf extension + setup.callback = nlib.thunkString /* lua */ '' + require("telescope").load_extension("fzf") + ''; + # }}} + # {{{ Options + opts.defaults.mappings.i."" = "which_key"; + opts.pickers.find_files.hidden = true; + opts.extensions.fzf = { + fuzzy = true; + override_generic_sorter = true; + override_file_sorter = true; + }; + # }}} + }; + # }}} # }}} # {{{ visual # The line between `ui` and `visual` is a bit rought. I currenlty mostly judge @@ -464,10 +548,74 @@ in setup = true; keys = [ { mapping = "gc"; mode = "nxv"; } - { mapping = "gcc"; } + "gcc" ]; }; # }}} + # {{{ mini.surround + satellite.neovim.lazy.mini-surround = { + package = "echasnovski/mini.surround"; + name = "mini.surround"; + + keys = lib.flatten [ + # ^ doing the whole `flatten` thing to lie to my formatter + { mapping = "s"; mode = "nv"; } + [ "d" "f" "F" "h" "r" ] + ]; + + # {{{ Keymaps + opts.mappings = { + add = "s"; # Add surrounding in Normal and Visul modes + delete = "d"; # Delete surrounding + find = "f"; # Find surrounding (to the right) + find_left = "F"; # Find surrounding (to the left) + highlight = "h"; # Highlight surrounding + replace = "r"; # Replace surrounding + update_n_lines = ""; # Update `n_lines` + }; + # }}} + # {{{ Custom surroundings + opts.custom_surroundings = + let mk = balanced: input: left: right: { + input = [ + input + (if balanced + then "^.%s*().-()%s*.$" + else "^.().*().$") + ]; + output = { inherit left right; }; + }; + in + { + b = mk true "%b()" "(" ")"; + B = mk true "%b{}" "{" "}"; + r = mk true "%b[]" "[" "]"; + q = mk false "\".-\"" "\"" "\""; + a = mk false "'.-'" "'" "'"; + }; + # }}} + }; + # }}} + # {{{ mini.operators + satellite.neovim.lazy.mini-operators = { + package = "echasnovski/mini.operators"; + name = "mini.operators"; + + setup = true; + keys = + let operator = key: [ + { mapping = "g${key}"; mode = "nv"; } + "g${key}${key}" + ]; + in + lib.flatten [ + (operator "=") + (operator "x") + (operator "r") + (operator "s") + ]; + }; + # }}} # }}} # {{{ ide # {{{ conform @@ -538,6 +686,7 @@ in # {{{ rust-tools satellite.neovim.lazy.rust-tools = { package = "simrat39/rust-tools.nvim"; + dependencies.nix = [ pkgs.rust-analyzer pkgs.rustfmt ]; env.blacklist = [ "vscode" ]; ft = "rust"; @@ -572,7 +721,7 @@ in event = "InsertEnter"; group = "CargoCmpSource"; pattern = "Cargo.toml"; - callback = nlib.thunkString /* lua */ '' + action = nlib.thunkString /* lua */ '' require("cmp").setup.buffer({ sources = { { name = "crates" } } }) ''; } @@ -582,18 +731,18 @@ in event = "BufReadPost"; group = "CargoKeybinds"; pattern = "Cargo.toml"; - # {{{ Register which-key info - callback.callback = nlib.contextThunk /* lua */ '' - require("which-key").register({ - ["lc"] = { - name = "[l]ocal [c]rates", - bufnr = context.bufnr - }, - }) - ''; + # # {{{ Register which-key info + # callback.callback = nlib.contextThunk /* lua */ '' + # require("which-key").register({ + # ["lc"] = { + # name = "[l]ocal [c]rates", + # bufnr = context.bufnr + # }, + # }) + # ''; # }}} - callback.keys = + action.keys = let # {{{ Keymap helpers keymap = mapping: action: desc: { @@ -626,16 +775,83 @@ in }; # }}} # }}} + # {{{ lean + satellite.neovim.lazy.lean = { + package = "Julian/lean.nvim"; + name = "lean"; + dependencies.lua = [ + lazy.plenary.package + "neovim/nvim-lspconfig" + "hrsh7th/nvim-cmp" + ]; + + env.blacklist = [ "vscode" ]; + ft = "lean"; + + opts = { + abbreviations = { + builtin = true; + cmp = true; + }; + + lsp = { + on_attach = nlib.lua /* lua */ ''require("my.plugins.lspconfig").on_attach''; + capabilites = nlib.lua /* lua */ ''require("my.plugins.lspconfig").capabilities''; + }; + + lsp3 = false; # We don't want the lean 3 language server! + mappings = true; + }; + }; + # }}} + # {{{ idris + satellite.neovim.lazy.idris = { + package = "ShinKage/idris2-nvim"; + name = "idris"; + dependencies.lua = [ + lazy.nui.package + "neovim/nvim-lspconfig" + ]; + + env.blacklist = [ "vscode" ]; + ft = [ "idris2" "lidris2" "ipkg" ]; + + opts = { + client.hover.use_split = true; + serve.on_attach = nlib.languageServerOnAttach { + # {{{ Keymaps + keys = + let keymap = mapping: action: desc: { + inherit desc; + mapping = "i${mapping}"; + action = nlib.lua /* lua */ ''require("idris2.code_action").${action}''; + }; + in + [ + (keymap "C" "make_case" "Make [c]ase") + (keymap "L" "make_lemma" "Make [l]emma") + (keymap "c" "add_clause" "Add [c]lause") + (keymap "e" "expr_search" "[E]xpression search") + (keymap "d" "generate_def" "Generate [d]efinition") + (keymap "s" "case_split" "Case [s]plit") + (keymap "h" "refine_hole" "Refine [h]ole") + ]; + # }}} + }; + }; + }; + # }}} # }}} # {{{ external # These plugins integrate neovim with external services # {{{ wakatime satellite.neovim.lazy.wakatime = { package = "wakatime/vim-wakatime"; + dependencies.nix = [ pkgs.wakatime ]; + env.blacklist = [ "vscode" "firenvim" ]; event = "BufReadPost"; }; - # }}} # {{{ discord rich presence satellite.neovim.lazy.discord-rich-presence = { diff --git a/modules/common/lua-encoders.nix b/modules/common/lua-encoders.nix index 68e8fa1..818fdb4 100644 --- a/modules/common/lua-encoders.nix +++ b/modules/common/lua-encoders.nix @@ -112,13 +112,20 @@ let (luaEncoders.oneOrMany encoder); # }}} # {{{ Attrsets + attrName = s: + let forbiddenChars = lib.stringToCharacters "<>'\".,;"; # This list *is* incomplete + in + if lib.any (c: lib.hasInfix c s) forbiddenChars then + "[${luaEncoders.string s}]" + else s; + attrsetOf = encoder: object: luaEncoders.mkRawLuaObject (lib.mapAttrsToList (name: value: let result = encoder value; in lib.optionalString (result != "nil") - "${name} = ${result}" + "${luaEncoders.attrName name} = ${result}" ) object ); @@ -150,7 +157,7 @@ let let result = encoder (attrset.${attr} or null); in lib.optionalString (!(lib.elem attr listOrder) && shouldKeep result) - "${attr} = ${result}" + "${luaEncoders.attrName attr} = ${result}" ) spec; in @@ -184,7 +191,10 @@ in writeFile = path: name: text: let destination = "${path}/${name}.lua"; - unformatted = pkgs.writeText "raw-lua-${name}" text; + unformatted = pkgs.writeText "raw-lua-${name}" '' + -- ❄️ This file was generated using nix ^~^ + ${text} + ''; in pkgs.runCommand "formatted-lua-${name}" { } '' mkdir -p $out/${path} diff --git a/modules/common/neovim.nix b/modules/common/neovim.nix index 23744a2..e7a862a 100644 --- a/modules/common/neovim.nix +++ b/modules/common/neovim.nix @@ -155,7 +155,7 @@ let description = "Name of the group to create and assign autocmd to"; }; - callback = lib.mkOption { + action = lib.mkOption { example.vim.opt.cmdheight = 1; type = types.oneOf [ myTypes.tempestConfiguration @@ -219,14 +219,18 @@ let lazyModule = lib.fix (lazyModule: types.submodule ({ name ? null, ... }: { options = { package = lib.mkOption { - type = types.oneOf [ - types.package - types.str - ]; + default = null; + type = types.nullOr types.str; description = "Package to configure the module around"; example = "nvim-telescope/telescope.nvim"; }; + dir = lib.mkOption { + default = null; + type = types.nullOr types.path; + description = "Path to install pacakge from"; + }; + name = lib.mkOption { default = name; type = types.nullOr types.str; @@ -377,6 +381,11 @@ in description = "Derivation building all the given nix modules"; }; + lazySingleFile = lib.mkOption { + type = types.package; + description = "Derivation building all the given nix modules in a single file"; + }; + dependencies = lib.mkOption { default = [ ]; type = types.listOf types.package; @@ -426,7 +435,7 @@ in event = e.oneOrMany e.string; pattern = e.oneOrMany e.string; group = e.string; - callback = e.conditional lib.isAttrs + action = e.conditional lib.isAttrs cfg.lib.encodeTempestConfiguration e.luaString; }); @@ -520,14 +529,21 @@ in }); # }}} # {{{ Lazy spec encoder + xor = a: b: (a || b) && (!a || !b); + implies = a: b: !a || b; + hasProp = obj: p: (obj.${p} or null) != null; + propXor = a: b: obj: xor (hasProp obj a) (hasProp obj b); + propImplies = a: b: obj: implies (hasProp obj a) (hasProp obj b); + lazyObjectEncoder = e.bind (opts: e.attrset true [ "package" ] { - package = e.string; + package = e.nullOr e.string; + dir = assert propXor "package" "dir" opts; e.nullOr e.string; + tag = assert propImplies "tag" "package" opts; e.nullOr e.string; + version = assert propImplies "tag" "package" opts; e.nullOr e.string; name = e.nullOr e.string; main = e.nullOr e.string; - tag = e.nullOr e.string; - version = e.nullOr e.string; dependencies = e.map (d: d.lua) (e.tryNonemptyList (e.stringOr lazyObjectEncoder)); lazy = e.nullOr e.bool; cond = e.conjunction @@ -559,19 +575,36 @@ in opts = e.anything; }); # }}} - - makeLazyScript = opts: '' - -- ❄️ This file was generated using nix ^~^ - return ${lazyObjectEncoder opts} - ''; in lib.attrsets.mapAttrs (name: opts: rec { - raw = makeLazyScript opts; + raw = lazyObjectEncoder opts; module = config.satellite.lib.lua.writeFile "lua/nix/plugins" name raw; }) cfg.lazy; + config.satellite.neovim.generated.lazySingleFile = + let + makeFold = name: m: '' + -- {{{ ${name} + ${m.raw}, + -- }}}''; + + mkReturnList = objects: '' + return { + ${objects} + }''; + + script = lib.pipe cfg.generated.lazy [ + (lib.attrsets.mapAttrsToList makeFold) + (lib.concatStringsSep "\n") + mkReturnList + ]; + in + config.satellite.lib.lua.writeFile + "lua/nix/plugins" "init" + script; + config.satellite.neovim.generated.all = pkgs.symlinkJoin { name = "lazy-nvim-modules";