From 9dcaa0255a2c6876ae5d430af195036a8a8b259b Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Wed, 20 Apr 2022 16:27:26 +0200 Subject: [PATCH] nvim: REPL support --- config/nvim/nifoc/keymap.fnl | 17 +++++++++++++++-- config/nvim/nifoc/repl.fnl | 25 +++++++++++++++++++++++++ config/nvim/plugins/toggleterm.fnl | 14 ++++++++++---- flake.lock | 30 +++++++++++++++--------------- overlay-patches.nix | 8 +++++++- programs/nvim/default.nix | 6 ++++-- programs/nvim/plugins.nix | 12 ++++++------ 7 files changed, 82 insertions(+), 30 deletions(-) create mode 100644 config/nvim/nifoc/repl.fnl diff --git a/config/nvim/nifoc/keymap.fnl b/config/nvim/nifoc/keymap.fnl index 575815a..a0b45e0 100644 --- a/config/nvim/nifoc/keymap.fnl +++ b/config/nvim/nifoc/keymap.fnl @@ -9,7 +9,8 @@ telescope-ivy (telescope-themes.get_ivy) telescope-dropdown (telescope-themes.get_dropdown) npairs (require :nvim-autopairs) - gitsigns (require :gitsigns)] + gitsigns (require :gitsigns) + repl (require :nifoc.repl)] (fn map-entry [key cmd opts] (vim.tbl_extend :keep {1 key 2 cmd} opts)) @@ -27,6 +28,10 @@ {:description "New File"}) (map-entry :ut :UndotreeToggle {:description "Toggle Undotree"}) + (map-entry :c repl.toggle-shell + {:description "Toggle Shell"}) + (map-entry :r repl.toggle-repl + {:description "Toggle REPL"}) ;; Buffer (map-entry :bl #(telescope-builtin.buffers telescope-dropdown) @@ -112,7 +117,7 @@ (map-entry :ld #(telescope-builtin.diagnostics (vim.tbl_extend :keep telescope-ivy - {:bufnr 0})) + {: bufnr})) {:description "LSP Document Diagnostics" :opts {:buffer bufnr}}) (map-entry :lca @@ -138,5 +143,13 @@ {:description "Format Buffer" :opts {:buffer bufnr}})])) + (fn mod.terminal-open [bufnr] + (let [map-opts {:noremap true :buffer bufnr}] + (keymap.set :t : "" map-opts) + (keymap.set :t : "h" map-opts) + (keymap.set :t : "j" map-opts) + (keymap.set :t : "k" map-opts) + (keymap.set :t : "l" map-opts))) + mod) diff --git a/config/nvim/nifoc/repl.fnl b/config/nvim/nifoc/repl.fnl new file mode 100644 index 0000000..a71c9bc --- /dev/null +++ b/config/nvim/nifoc/repl.fnl @@ -0,0 +1,25 @@ +(let [mod {} + terminal-class (require :toggleterm.terminal) + terminal terminal-class.Terminal] + (local elixir (terminal:new {:cmd :iex :close_on_exit true})) + (local erlang (terminal:new {:cmd :erl :close_on_exit true})) + (local fennel (terminal:new {:cmd "fennel --repl" :close_on_exit true})) + (local fish (terminal:new {:cmd :fish :close_on_exit true})) + (local javascript (terminal:new {:cmd :node :close_on_exit true})) + (local nix (terminal:new {:cmd "nix repl" :close_on_exit true})) + (local ruby (terminal:new {:cmd :irb :close_on_exit true})) + ;; Map filetype to REPL + (local repl-map {: elixir : erlang : fennel : fish : javascript : nix : ruby}) + + (fn mod.toggle-shell [] + (let [shell (. repl-map :fish)] + (shell:toggle))) + + (fn mod.toggle-repl [] + (let [ft vim.bo.filetype + repl (. repl-map ft)] + (when (not= repl nil) + (repl:toggle)))) + + mod) + diff --git a/config/nvim/plugins/toggleterm.fnl b/config/nvim/plugins/toggleterm.fnl index e02ff50..56f81bc 100644 --- a/config/nvim/plugins/toggleterm.fnl +++ b/config/nvim/plugins/toggleterm.fnl @@ -1,9 +1,15 @@ (let [toggleterm (require :toggleterm)] - (toggleterm.setup {:shell :fish :open_mapping :}) + (toggleterm.setup {:shell vim.o.shell + :open_mapping : + :close_on_exit true}) (let [augroup (vim.api.nvim_create_augroup :NifocTerm {:clear true}) - aucmd vim.api.nvim_create_autocmd] - (aucmd :TermOpen {:callback (fn [] + aucmd vim.api.nvim_create_autocmd + keymap (require :nifoc.keymap)] + (aucmd :TermOpen {:pattern "term://*toggleterm#*" + :callback (fn [opts] (set vim.opt_local.number false) (set vim.opt_local.relativenumber false) - (set vim.opt_local.cursorline false)) + (set vim.opt_local.cursorline false) + (keymap.terminal-open opts.buf)) :group augroup}))) + diff --git a/flake.lock b/flake.lock index 7ec7c7e..ab1def7 100644 --- a/flake.lock +++ b/flake.lock @@ -23,11 +23,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1648199409, - "narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=", + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", "owner": "edolstra", "repo": "flake-compat", - "rev": "64a525ee38886ab9028e6f61790de0832aa3ef03", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", "type": "github" }, "original": { @@ -73,11 +73,11 @@ ] }, "locked": { - "lastModified": 1650301786, - "narHash": "sha256-9rz9NqL+mC+BIggn2emuzZ+3MYogxVBTdsFK7E3Vv1k=", + "lastModified": 1650413050, + "narHash": "sha256-e4Ajk6n+xQnF4CmqZf42OaLxsqm4LpJHkofRh5wwad0=", "owner": "nix-community", "repo": "home-manager", - "rev": "8d38ca886880265d523a66fe3da4d42e92ab0748", + "rev": "8ec13d33b17f246e03ddfea100b7c3a143255bea", "type": "github" }, "original": { @@ -96,11 +96,11 @@ }, "locked": { "dir": "contrib", - "lastModified": 1650333806, - "narHash": "sha256-ZrnN9ssclGTChvomcqL4Uact8L9+yToywNwrjyUULgI=", + "lastModified": 1650436522, + "narHash": "sha256-/Z1I2F6J8j/1Wis1fsKViZWqkCmmA+gEsyITT0cXTgM=", "owner": "neovim", "repo": "neovim", - "rev": "147cc60d24f093b5154824889f2151489774ef33", + "rev": "a391cd517bb4f0d638da3f0aaaf57f98e153447e", "type": "github" }, "original": { @@ -119,11 +119,11 @@ ] }, "locked": { - "lastModified": 1650356316, - "narHash": "sha256-RojfPzSC+veD2SCugaMNJ9c+TzD9hPIToWkC2venhrU=", + "lastModified": 1650443062, + "narHash": "sha256-K0PAS1YfaEcUD5XACEifwKTnsyE6DyuPkoKiHPto+4U=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "1c8ffbfa48d212eb806e3ea3eeae4c6c444130d5", + "rev": "c744e2783e846836c2c05f9dbdcc464ad980f488", "type": "github" }, "original": { @@ -186,11 +186,11 @@ ] }, "locked": { - "lastModified": 1650328756, - "narHash": "sha256-rA/Pdrl/vBpl/URdkF03bb7N8fp111OIP7+Aqb+YOKE=", + "lastModified": 1650415318, + "narHash": "sha256-HZDhiEELVjhZf9pR0Y3cYVFI7SZVCiSc1g3yqvMYdFk=", "owner": "arqv", "repo": "zig-overlay", - "rev": "77597e467567b462efce312d1c99b5a6dc24ea92", + "rev": "da3b287c1d29761e576ad81ac94aed260744d20d", "type": "github" }, "original": { diff --git a/overlay-patches.nix b/overlay-patches.nix index ddb4f23..e73d058 100644 --- a/overlay-patches.nix +++ b/overlay-patches.nix @@ -1 +1,7 @@ -self: super: { } +self: super: { + fennel-luajit = super.fennel.overrideAttrs ( + o: rec { + buildInputs = [ super.luajit ]; + } + ); +} diff --git a/programs/nvim/default.nix b/programs/nvim/default.nix index 4d854a1..6cb94a9 100644 --- a/programs/nvim/default.nix +++ b/programs/nvim/default.nix @@ -49,13 +49,15 @@ in # LSP Tools deadnix hadolint - fennel + fennel-luajit fnlfmt shellcheck shfmt statix ]; + extraLuaPackages = with pkgs.luajitPackages; [ readline ]; + plugins = (with customPlugins; [ # Fixes impatient-nvim @@ -310,7 +312,7 @@ in xdg.configFile."nvim" = { source = pkgs.runCommand "nvim-fennel-files" { - nativeBuildInputs = [ pkgs.fennel pkgs.stylua ]; + nativeBuildInputs = with pkgs; [ fennel-luajit stylua ]; } '' mkdir -p $out/lua/configuration mkdir -p $out/lua/nifoc/utils diff --git a/programs/nvim/plugins.nix b/programs/nvim/plugins.nix index 67e13fb..0e71e26 100644 --- a/programs/nvim/plugins.nix +++ b/programs/nvim/plugins.nix @@ -87,12 +87,12 @@ }; leap-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix { pname = "leap.nvim"; - version = "1650369149"; + version = "1650440510"; src = pkgs.fetchFromGitHub { owner = "ggandor"; repo = "leap.nvim"; - rev = "4e4ce2bba4fa6c30fc9e8999e71dcc67386732b0"; - sha256 = "TG5tAzr+erpTHiaL/VaJC4rMOcqY7abzhpN5lNsFnCs="; + rev = "2a7965c6ec3f5de9efde92dcec0c53f12c84732a"; + sha256 = "VBhzMxYkUQfFFVgUM+ZDtgGoEFQRvcdWX8oH7h54+E8="; fetchSubmodules = true; }; meta.homepage = "https://github.com/ggandor/leap.nvim"; @@ -238,12 +238,12 @@ }; nvim-cmp = pkgs.vimUtils.buildVimPluginFrom2Nix { pname = "nvim-cmp"; - version = "1650365016"; + version = "1650428497"; src = pkgs.fetchFromGitHub { owner = "hrsh7th"; repo = "nvim-cmp"; - rev = "07132dc597e94a8b6df75efce9784a581f55742c"; - sha256 = "9wPv8mXax2fr1L6TeiFOSK7ZdXNg1v/1eRj00OFDw1Y="; + rev = "f51dc68e1bb170fc49c2d7e13eb45e5ec83f5ee9"; + sha256 = "U5lDWtslhZuDZBgzSijFmOlNShP+geVJw3FIxKIfxYU="; fetchSubmodules = true; }; meta.homepage = "https://github.com/hrsh7th/nvim-cmp";