From 8efea0316370616bd7a429d340453ae77dd2b12a Mon Sep 17 00:00:00 2001 From: punkfairie Date: Tue, 26 Nov 2024 20:50:32 -0800 Subject: [PATCH] fix: Proper injection queries --- modules/nixvim/autocommands/default.nix | 154 ++++++++---------- modules/nixvim/keymaps/default.nix | 18 +- .../nixvim/plugins/util/snacks/default.nix | 56 +++---- 3 files changed, 104 insertions(+), 124 deletions(-) diff --git a/modules/nixvim/autocommands/default.nix b/modules/nixvim/autocommands/default.nix index bbb2f48..8bc6ed6 100644 --- a/modules/nixvim/autocommands/default.nix +++ b/modules/nixvim/autocommands/default.nix @@ -23,51 +23,43 @@ in { ]; autoCmd = [ - (autocmds.mk' ["FocusGained" "TermClose" "TermLeave"] "checktime" (mkRaw - # lua - '' - function() - if vim.o.buftype ~= "nofile" then - vim.cmd("checktime") - end + (autocmds.mk' ["FocusGained" "TermClose" "TermLeave"] "checktime" (mkRaw '' + function() + if vim.o.buftype ~= "nofile" then + vim.cmd("checktime") end - '') "Check if file needs to be reloaded when changed") + end + '') "Check if file needs to be reloaded when changed") - (autocmds.mk' ["TextYankPost"] "highlight_yank" (mkRaw - # lua - '' - function() - (vim.hl or vim.highlight).on_yank() - end - '') "Highlight on yank") + (autocmds.mk' ["TextYankPost"] "highlight_yank" (mkRaw '' + function() + (vim.hl or vim.highlight).on_yank() + end + '') "Highlight on yank") - (autocmds.mk' ["VimResized"] "resize_splits" (mkRaw - # lua - '' - function() - local current_tab = vim.fn.tabpagenr() - vim.cmd("tabdo wincmd =") - vim.cmd("tabnext " .. current_tab) - end - '') "Resize splits on window resize") + (autocmds.mk' ["VimResized"] "resize_splits" (mkRaw '' + function() + local current_tab = vim.fn.tabpagenr() + vim.cmd("tabdo wincmd =") + vim.cmd("tabnext " .. current_tab) + end + '') "Resize splits on window resize") - (autocmds.mk' ["BufReadPost"] "last_loc" (mkRaw - # lua - '' - function(event) - local exclude = { "gitcommit" } - local buf = event.buf - if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].marleyvim_last_loc then - return - end - vim.b[buf].marleyvim_last_loc = true - local mark = vim.api.nvim_buf_get_mark(buf, '"') - local lcount = vim.api.nvim_buf_line_count(buf) - if mark[1] > 0 and mark[1] <= lcount then - pcall(vim.api.nvim_win_set_cursor, 0, mark) - end + (autocmds.mk' ["BufReadPost"] "last_loc" (mkRaw '' + function(event) + local exclude = { "gitcommit" } + local buf = event.buf + if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].marleyvim_last_loc then + return end - '') "Go to last location when opening a buffer") + vim.b[buf].marleyvim_last_loc = true + local mark = vim.api.nvim_buf_get_mark(buf, '"') + local lcount = vim.api.nvim_buf_line_count(buf) + if mark[1] > 0 and mark[1] <= lcount then + pcall(vim.api.nvim_win_set_cursor, 0, mark) + end + end + '') "Go to last location when opening a buffer") (autocmds.mk ["FileType"] "close_with_q" [ "PlenaryTestPopup" @@ -86,31 +78,27 @@ in { "spectre_panel" "startuptime" "tsplayground" - ] (mkRaw - # lua - '' - function(event) - vim.bo[event.buf].buflisted = false - vim.schedule(function() - vim.keymap.set("n", "q", function() - vim.cmd("close") - pcall(vim.api.nvim_buf_delete, event.buf, { force = true }) - end, { - buffer = event.buf, - silent = true, - desc = "Quit buffer", - }) - end) - end - '') "Close some filetypes with ") - - (autocmds.mk ["FileType"] "man_unlisted" ["man"] (mkRaw - # lua - '' + ] (mkRaw '' function(event) vim.bo[event.buf].buflisted = false + vim.schedule(function() + vim.keymap.set("n", "q", function() + vim.cmd("close") + pcall(vim.api.nvim_buf_delete, event.buf, { force = true }) + end, { + buffer = event.buf, + silent = true, + desc = "Quit buffer", + }) + end) end - '') "Easy-close man files") + '') "Close some filetypes with ") + + (autocmds.mk ["FileType"] "man_unlisted" ["man"] (mkRaw '' + function(event) + vim.bo[event.buf].buflisted = false + end + '') "Easy-close man files") (autocmds.mk ["FileType"] "wrap_spell" [ "text" @@ -118,33 +106,27 @@ in { "typst" "gitcommit" "markdown" - ] (mkRaw - # lua - '' - function() - vim.opt_local.wrap = true - vim.opt_local.spell = true - end - '') "Wrap & check spelling in text files") - - (autocmds.mk ["FileType"] "json_conceal" ["json" "jsonc" "json5"] (mkRaw - # lua - '' + ] (mkRaw '' function() - vim.opt_local.conceallevel = 0 + vim.opt_local.wrap = true + vim.opt_local.spell = true end - '') "Fix conceallevel for json files") + '') "Wrap & check spelling in text files") - (autocmds.mk' ["BufWritePre"] "auto_create_dir" (mkRaw - # lua - '' - function(event) - if event.match:match("^%w%w+:[\\/][\\/]") then - return - end - local file = vim.uv.fs_realpath(event.match) or event.match - vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") + (autocmds.mk ["FileType"] "json_conceal" ["json" "jsonc" "json5"] (mkRaw '' + function() + vim.opt_local.conceallevel = 0 + end + '') "Fix conceallevel for json files") + + (autocmds.mk' ["BufWritePre"] "auto_create_dir" (mkRaw '' + function(event) + if event.match:match("^%w%w+:[\\/][\\/]") then + return end - '') "Auto create missing parent dirs when saving") + local file = vim.uv.fs_realpath(event.match) or event.match + vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") + end + '') "Auto create missing parent dirs when saving") ]; } diff --git a/modules/nixvim/keymaps/default.nix b/modules/nixvim/keymaps/default.nix index 5237bc1..d01d9ec 100644 --- a/modules/nixvim/keymaps/default.nix +++ b/modules/nixvim/keymaps/default.nix @@ -165,9 +165,9 @@ in { # Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ [ (keys.mk ["n"] "cd" ( - mkRaw - # lua - "function() vim.diagnostic.open_float() end" + mkRaw '' + function() vim.diagnostic.open_float() end + '' ) "Line Diagnostics") ] ++ ( @@ -200,13 +200,11 @@ in { cmd = toLower dir; sev = sevs."${key}".key; in - keys.mk ["n"] kmap - ( - mkRaw - # lua - "function() vim.diagnostic.goto_${cmd}({ severity = ${sev} }) end" - ) - "${dir} ${sevs."${key}".desc}" + keys.mk ["n"] kmap ( + mkRaw '' + function() vim.diagnostic.goto_${cmd}({ severity = ${sev} }) end + '' + ) "${dir} ${sevs."${key}".desc}" ) { dir = ["Next" "Prev"]; diff --git a/modules/nixvim/plugins/util/snacks/default.nix b/modules/nixvim/plugins/util/snacks/default.nix index 41bc962..7c3c06b 100644 --- a/modules/nixvim/plugins/util/snacks/default.nix +++ b/modules/nixvim/plugins/util/snacks/default.nix @@ -23,62 +23,62 @@ in { keymaps = [ (keys.mk ["n"] "un" ( - mkRaw - # lua - "function() Snacks.notifier.hide() end" + mkRaw '' + function() Snacks.notifier.hide() end + '' ) "Dismiss All Notifications") (keys.mk ["n"] "bd" ( - mkRaw - # lua - "function() Snacks.bufdelete() end" + mkRaw '' + function() Snacks.bufdelete() end + '' ) "Delete Buffer") (keys.mk ["n"] "bo" ( - mkRaw - # lua - "function() Snacks.bufdelete.other() end" + mkRaw '' + function() Snacks.bufdelete.other() end + '' ) "Delete Other Buffers") # LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (keys.mk ["n"] "gg" ( - mkRaw - # lua - "function() Snacks.lazygit() end" + mkRaw '' + function() Snacks.lazygit() end + '' ) "Lazygit") (keys.mk ["n"] "gf" ( - mkRaw - # lua - "function() Snacks.lazygit.log_file() end" + mkRaw '' + function() Snacks.lazygit.log_file() end + '' ) "Lazygit Current File History") (keys.mk ["n"] "gl" ( - mkRaw - # lua - "function() Snacks.lazygit.log() end" + mkRaw '' + function() Snacks.lazygit.log() end + '' ) "Lazygit Log") # Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (keys.mk ["n"] "gb" ( - mkRaw - # lua - "function() Snacks.git.blame_line() end" + mkRaw '' + function() Snacks.git.blame_line() end + '' ) "Git Blame Line") (keys.mk ["n" "x"] "gB" ( - mkRaw - # lua - "function() Snacks.gitbrowse() end" + mkRaw '' + function() Snacks.gitbrowse() end + '' ) "Git Browse (open)") - (keys.mk ["n" "x"] "gY" (mkRaw - # lua - '' + (keys.mk ["n" "x"] "gY" ( + mkRaw '' function() Snacks.gitbrowse({ open = function(url) vim.fn.setreg("+", url) end }) end - '') "Git Browse (copy)") + '' + ) "Git Browse (copy)") ]; # Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -