diff --git a/mzte-nv/conf/lua/maps.fnl b/mzte-nv/conf/lua/maps.fnl index 5a2b80c..38e4328 100644 --- a/mzte-nv/conf/lua/maps.fnl +++ b/mzte-nv/conf/lua/maps.fnl @@ -1,4 +1,4 @@ -(local opts {:noremap true :silent true}) +(local opts (. (require :mzte_nv) :utils :map_opt)) (macro nmap [map action] `(vim.keymap.set :n ,map ,action opts)) @@ -23,12 +23,12 @@ (nmap : (cmd :cprevious)) ;; LSP -(nmap :-a #(vim.lsp.buf.code_action)) -(nmap :-d #(vim.diagnostic.goto_next)) -(nmap :-n #(vim.lsp.buf.rename)) +(nmap :-a vim.lsp.buf.code_action) +(nmap :-d vim.diagnostic.goto_next) +(nmap :-n vim.lsp.buf.rename) (nmap :-r #(vim.lsp.buf.format {:async true})) -(nmap : #(vim.lsp.buf.signature_help)) -(nmap :e #(vim.diagnostic.open_float)) +(nmap : vim.lsp.buf.signature_help) +(nmap :e vim.diagnostic.open_float) (nmap :K (fn [] (if ((. (require :conjure.client) :get)) diff --git a/mzte-nv/conf/lua/pluginconf/p-aerial.fnl b/mzte-nv/conf/lua/pluginconf/p-aerial.fnl index 347869e..ca77609 100644 --- a/mzte-nv/conf/lua/pluginconf/p-aerial.fnl +++ b/mzte-nv/conf/lua/pluginconf/p-aerial.fnl @@ -2,4 +2,4 @@ (aerial.setup {:backends [:lsp :treesitter :markdown :man]}) -(vim.keymap.set :n :-o #(aerial.toggle) {:noremap true :silent true}) +(vim.keymap.set :n :-o #(aerial.toggle) (. (require :mzte_nv) :utils :map_opt)) diff --git a/mzte-nv/conf/lua/pluginconf/p-dap.fnl b/mzte-nv/conf/lua/pluginconf/p-dap.fnl new file mode 100644 index 0000000..8215a25 --- /dev/null +++ b/mzte-nv/conf/lua/pluginconf/p-dap.fnl @@ -0,0 +1,39 @@ +(local (mztenv dap dapui) (values (require :mzte_nv) (require :dap) + (require :dapui))) + +(dapui.setup {}) + +(tset dap :adapters :lldb {:type :executable + ;; included in lldb package + :command (mztenv.utils.findInPath :lldb-vscode) + :name :lldb}) + +(local configs (. dap :configurations)) + +;; TODO: this UI sucks +(tset configs :c [{:name :Launch + :type :lldb + :request :launch + :program #(vim.fn.input "Binary: ") + :cwd "${workspaceFolder}" + :stopOnEntry false + :args #(vim.split (vim.fn.input "Args: ") " ") + :runInTerminal true}]) + +(tset configs :cpp (. configs :c)) +(tset configs :rust (. configs :c)) +(tset configs :zig (. configs :c)) + +(tset configs :java [{:type :java + :request :attach + :name "Java attach" + :hostName :127.0.0.1 + :port 5005}]) + +(let [mopt (. (require :mzte_nv) :utils :map_opt)] + (vim.keymap.set :n :fu dapui.toggle mopt) + (vim.keymap.set :n :fb dap.toggle_breakpoint mopt) + (vim.keymap.set :n :fc dap.continue mopt) + (vim.keymap.set :n :fn dap.step_over mopt) + (vim.keymap.set :n :fi dap.step_into mopt) + (vim.keymap.set :n :fo dap.step_out mopt)) diff --git a/mzte-nv/conf/lua/pluginconf/p-dap.lua b/mzte-nv/conf/lua/pluginconf/p-dap.lua deleted file mode 100644 index 2364103..0000000 --- a/mzte-nv/conf/lua/pluginconf/p-dap.lua +++ /dev/null @@ -1,54 +0,0 @@ -local map = vim.api.nvim_set_keymap -local mztenv = require "mzte_nv" - -local dap = require "dap" -local dapui = require "dapui" - -dapui.setup {} - -dap.adapters.lldb = { - type = "executable", - command = mztenv.utils.findInPath "lldb-vscode", -- included in lldb package - name = "lldb", -} - -dap.configurations.c = { - { - name = "Launch", - type = "lldb", - request = "launch", - program = function() - return vim.fn.input "Binary: " - end, - cwd = "${workspaceFolder}", - stopOnEntry = false, - args = function() - return vim.split(vim.fn.input "Args: ", " ") - end, - runInTerminal = true, - }, -} - -dap.configurations.cpp = dap.configurations.c - --- TODO: maybe some way to discover the executable here with cargo n stuff? -dap.configurations.rust = dap.configurations.c -dap.configurations.zig = dap.configurations.c - -dap.configurations.java = { - { - type = "java", - request = "attach", - name = "Java attach", - hostName = "127.0.0.1", - port = 5005, - }, -} - -local opts = { noremap = true, silent = true } -map("n", "fu", [[lua require("dapui").toggle()]], opts) -map("n", "fb", [[lua require("dap").toggle_breakpoint()]], opts) -map("n", "fc", [[lua require("dap").continue()]], opts) -map("n", "fn", [[lua require("dap").step_over()]], opts) -map("n", "fi", [[lua require("dap").step_into()]], opts) -map("n", "fo", [[lua require("dap").step_out()]], opts) diff --git a/mzte-nv/conf/lua/pluginconf/p-harpoon.fnl b/mzte-nv/conf/lua/pluginconf/p-harpoon.fnl new file mode 100644 index 0000000..be30799 --- /dev/null +++ b/mzte-nv/conf/lua/pluginconf/p-harpoon.fnl @@ -0,0 +1,9 @@ +(local (harpoon mark ui) + (values (require :harpoon) (require :harpoon.mark) (require :harpoon.ui))) + +(harpoon.setup {}) + +(local mopt (. (require :mzte_nv) :utils :map_opt)) +(vim.keymap.set :n :ma mark.toggle_file mopt) +(vim.keymap.set :n :mn ui.nav_next mopt) +(vim.keymap.set :n :mp ui.nav_prev mopt) diff --git a/mzte-nv/conf/lua/pluginconf/p-harpoon.lua b/mzte-nv/conf/lua/pluginconf/p-harpoon.lua deleted file mode 100644 index 814939b..0000000 --- a/mzte-nv/conf/lua/pluginconf/p-harpoon.lua +++ /dev/null @@ -1,7 +0,0 @@ -local map = vim.api.nvim_set_keymap - -require("harpoon").setup {} - -map("n", "ma", [[lua require("harpoon.mark").toggle_file()]], { silent = true }) -map("n", "mn", [[lua require("harpoon.ui").nav_next()]], { silent = true }) -map("n", "mp", [[lua require("harpoon.ui").nav_prev()]], { silent = true }) diff --git a/mzte-nv/conf/lua/pluginconf/p-nvimtree.fnl b/mzte-nv/conf/lua/pluginconf/p-nvimtree.fnl index 3c75f4f..316887f 100644 --- a/mzte-nv/conf/lua/pluginconf/p-nvimtree.fnl +++ b/mzte-nv/conf/lua/pluginconf/p-nvimtree.fnl @@ -19,4 +19,4 @@ (vim.api.nvim_create_autocmd [:VimEnter] {:callback on-enter}) (vim.keymap.set :n :TT #((. (require :nvim-tree.api) :tree :toggle)) - {:noremap true :silent true}) + (. (require :mzte_nv) :utils :map_opt)) diff --git a/mzte-nv/conf/lua/pluginconf/p-telescope.fnl b/mzte-nv/conf/lua/pluginconf/p-telescope.fnl index a14bf6a..2410b4a 100644 --- a/mzte-nv/conf/lua/pluginconf/p-telescope.fnl +++ b/mzte-nv/conf/lua/pluginconf/p-telescope.fnl @@ -18,23 +18,18 @@ (telescope.load_extension :harpoon) -(local mopt {:noremap true :silent true}) - -(macro nmap [map action] - `(vim.keymap.set :n ,map ,action mopt)) - -;; file finding mappings -(nmap :ff builtin.find_files) -(nmap :fg builtin.live_grep) - -;; LSP mappings -(nmap :gd builtin.lsp_definitions) -(nmap :gi builtin.lsp_implementations) -(nmap :gr builtin.lsp_references) -(nmap :gs builtin.lsp_dynamic_workspace_symbols) - -(nmap :gp #(builtin.diagnostics {:bufnr 0})) -(nmap :gP builtin.diagnostics) - -;; harpoon -(nmap :gm ext.harpoon.marks) +(let [mopt (. (require :mzte_nv) :utils :map_opt)] + (macro nmap [map action] + `(vim.keymap.set :n ,map ,action mopt)) + ;; file finding mappings + (nmap :ff builtin.find_files) + (nmap :fg builtin.live_grep) + ;; LSP mappings + (nmap :gd builtin.lsp_definitions) + (nmap :gi builtin.lsp_implementations) + (nmap :gr builtin.lsp_references) + (nmap :gs builtin.lsp_dynamic_workspace_symbols) + (nmap :gp #(builtin.diagnostics {:bufnr 0})) + (nmap :gP builtin.diagnostics) + ;; harpoon + (nmap :gm ext.harpoon.marks)) diff --git a/mzte-nv/conf/lua/pluginconf/p-treesitter.fnl b/mzte-nv/conf/lua/pluginconf/p-treesitter.fnl index ea03535..457f921 100644 --- a/mzte-nv/conf/lua/pluginconf/p-treesitter.fnl +++ b/mzte-nv/conf/lua/pluginconf/p-treesitter.fnl @@ -27,8 +27,9 @@ (vim.treesitter.get_node_range (ts-utils.get_node_at_cursor))) (vim.api.nvim_buf_set_text 0 r1 c1 r2 c2 [])) -;; Shorthand for deleting the TS node under the cursor -(vim.keymap.set :n :D delete-node-under-cursor {:noremap true :silent true}) - -;; Shorthand for deleting the TS node under the cursor and switching to insert mode -(vim.keymap.set :n :C (fn [] (delete-node-under-cursor) (vim.cmd.startinsert))) +(let [mopt (. (require :mzte_nv) :utils :map_opt)] + ;; Shorthand for deleting the TS node under the cursor + (vim.keymap.set :n :D delete-node-under-cursor mopt) + ;; Shorthand for deleting the TS node under the cursor and switching to insert mode + (vim.keymap.set :n :C + (fn [] (delete-node-under-cursor) (vim.cmd.startinsert)) mopt)) diff --git a/mzte-nv/conf/lua/pluginconf/p-tsn-actions.fnl b/mzte-nv/conf/lua/pluginconf/p-tsn-actions.fnl index 12b59c0..302fdae 100644 --- a/mzte-nv/conf/lua/pluginconf/p-tsn-actions.fnl +++ b/mzte-nv/conf/lua/pluginconf/p-tsn-actions.fnl @@ -35,4 +35,5 @@ :filetypes [:_all] :generator {:fn (. tsna :available_actions)}}) -(vim.keymap.set :n :U (. tsna :node_action) {:noremap true :silent true}) +(vim.keymap.set :n :U (. tsna :node_action) + (. (require :mzte_nv) :utils :map_opt)) diff --git a/mzte-nv/conf/lua/pluginconf/p-ufo.fnl b/mzte-nv/conf/lua/pluginconf/p-ufo.fnl new file mode 100644 index 0000000..3fa4133 --- /dev/null +++ b/mzte-nv/conf/lua/pluginconf/p-ufo.fnl @@ -0,0 +1,25 @@ +(local (ufo ts-parsers) + (values (require :ufo) (require :nvim-treesitter.parsers))) + +(fn lsp-folds? [bufnr] + (accumulate [has false _ client (ipairs (vim.lsp.get_active_clients {: bufnr})) + &until has] + (not= client.server_capabilities.foldingRangeProvider nil))) + +(ufo.setup {:open_fold_hl_timeout 0 + :provider_selector (fn [bufnr ft _] + (if (lsp-folds? bufnr) [:lsp :indent] + (ts-parsers.has_parser ft) [:treesitter + :indent] + [:indent]))}) + +(tset vim :o :foldcolumn :0) +(tset vim :o :foldlevel 256) +(tset vim :o :foldlevelstart 256) +(tset vim :o :foldenable true) + +(let [mopt (. (require :mzte_nv) :utils :map_opt)] + ;; toggle fold + (vim.keymap.set :n :t :za mopt) + (vim.keymap.set :n :zO ufo.openAllFolds mopt) + (vim.keymap.set :n :zC ufo.closeAllFolds mopt)) diff --git a/mzte-nv/conf/lua/pluginconf/p-ufo.lua b/mzte-nv/conf/lua/pluginconf/p-ufo.lua deleted file mode 100644 index 984b1df..0000000 --- a/mzte-nv/conf/lua/pluginconf/p-ufo.lua +++ /dev/null @@ -1,43 +0,0 @@ -local ufo = require "ufo" -local ts_parsers = require "nvim-treesitter.parsers" -local map = vim.api.nvim_set_keymap - -local function has_lsp_folds(bufnr) - local clients = vim.lsp.get_active_clients { bufnr = bufnr } - for _, client in ipairs(clients) do - if client.server_capabilities.foldingRangeProvider then - return true - end - end - return false -end - -ufo.setup { - open_fold_hl_timeout = 0, -- disable blinky thingy when opening fold - provider_selector = function(bufnr, ft, _) - if has_lsp_folds(bufnr) then - return { "lsp", "indent" } - elseif ts_parsers.has_parser(ft) then - return { "treesitter", "indent" } - else - return { "indent" } - end - end, -} - --- https://github.com/neovim/neovim/pull/17446 ---vim.o.foldcolumn = "1" ---vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]] -vim.o.foldcolumn = "0" -vim.o.foldlevel = 256 -vim.o.foldlevelstart = 256 -vim.o.foldenable = true - -local map_opts = { - noremap = true, - silent = true, -} - -map("n", "t", "za", map_opts) -- toggle fold -map("n", "zO", [[lua require("ufo").openAllFolds()]], map_opts) -map("n", "zC", [[lua require("ufo").closeAllFolds()]], map_opts) diff --git a/mzte-nv/src/modules/utils.zig b/mzte-nv/src/modules/utils.zig index e1441b4..aaa4c8c 100644 --- a/mzte-nv/src/modules/utils.zig +++ b/mzte-nv/src/modules/utils.zig @@ -6,6 +6,8 @@ const c = ffi.c; pub fn luaPush(l: *c.lua_State) void { ser.luaPushAny(l, .{ .findInPath = ffi.luaFunc(lFindInPath), + + .map_opt = .{ .noremap = true, .silent = true }, }); }