diff --git a/nvim/.config/nvim/after/ftplugin/markdown.lua b/nvim/.config/nvim/after/ftplugin/markdown.lua index d7f2888..50d5511 100644 --- a/nvim/.config/nvim/after/ftplugin/markdown.lua +++ b/nvim/.config/nvim/after/ftplugin/markdown.lua @@ -11,35 +11,37 @@ if require("core.util").is_available("zk") and require("zk.util").notebook_root( map("n", "", "lua vim.lsp.buf.definition()", { silent = true }) end --- edit code cells with full lsp access -map("n", "ce", "FeMaco", { silent = true, desc = "edit code block" }) -- execute code cells -map("n", "cc", "MdEval", { silent = true, desc = "evaluate code block" }) -map("n", "cx", "MdEvalClean", { silent = true, desc = "clear code results" }) +if vim.fn.mapcheck("cc") == "" then + map("n", "cc", require("mdeval").eval_code_block, { silent = true, desc = "evaluate code block" }) +end +if vim.fn.mapcheck("cx") == "" then + map("n", "cx", require("mdeval").eval_clean_results, { silent = true, desc = "clear code results" }) +end -- jump to beginning of previous/ next cell code map("n", "]c", "/^```}:nohl", { desc = "next code cell" }) map("n", "[c", "?^```n}:nohl", { desc = "previous code cell" }) -- insert cell header above/below -map("n", "co", "o```python```k", { desc = "Insert quarto cell below" }) -map("n", "cO", "O```python```k", { desc = "Insert quarto cell above" }) +map("n", "co", "o```python```k", { desc = "Insert code cell below" }) +map("n", "cO", "O```python```k", { desc = "Insert code cell above" }) if require("core.util").is_available("which-key") then require("which-key").add({ "p", group = "prose" }) end -- show nice md preview in browser (auto-syncs scrolling) +local peek_key = "po" if require("core.util").is_available("peek") then - local peek = require("peek") - local function togglePeek() + map("n", peek_key, function() + local peek = require("peek") if peek.is_open() then peek.close() else peek.open() end - end - map("n", "po", togglePeek, { desc = "show md preview" }) -else - map("n", "po", "MarkdownPreviewToggle", { desc = "show md preview" }) + end, { desc = "show md preview" }) +elseif vim.fn.exists(":MarkdownPreviewToggle") > 0 then + map("n", peek_key, "MarkdownPreviewToggle", { desc = "show md preview" }) end -- create mindmaps directly from markdown! requires external executable diff --git a/nvim/.config/nvim/after/ftplugin/quarto.lua b/nvim/.config/nvim/after/ftplugin/quarto.lua index 170805a..a38d353 100644 --- a/nvim/.config/nvim/after/ftplugin/quarto.lua +++ b/nvim/.config/nvim/after/ftplugin/quarto.lua @@ -1,17 +1,24 @@ -local default_buffer_session = function() - local buffer_path = vim.api.nvim_buf_get_name(0) or vim.fn.tempname() - local temp_path = vim.fn.stdpath("run") .. "/molten-sessions" .. buffer_path .. ".json" +if require("core.util").is_available("quarto") then + vim.keymap.set("n", "po", require("quarto").quartoPreview, { desc = "show quarto preview" }) +end - local dir = vim.fn.fnamemodify(temp_path, ":p:h") - if vim.fn.getftype(dir) ~= "dir" then - vim.fn.mkdir(dir, "p") +-- TODO: Puths kernel into local file dir currently, +-- could take an argument to put it into temporary dir instead. +local kernel_filename = function() + local buf = vim.api.nvim_buf_get_name(0) + if not buf or buf:match("^$") then + vim.fn.tempname() end - return temp_path + local path, name = buf:match("(.-)([^\\/]-%.?([^%.\\/]*))$") + + return path .. "." .. name .. ".kernel.json" end -- Start quarto session -local startsession = function(file, args) - file = file or default_buffer_session() +local startsession = function(opts) + local args = opts.fargs + local kernel_filen = args[1] or kernel_filename() + vim.b["sessionfile"] = kernel_filen local path = require("core.util").get_python_venv_bin() if not path then @@ -19,39 +26,53 @@ local startsession = function(file, args) end vim.g["python3_host_prog"] = path - if vim.fn.executable("jupyter-console") ~= 1 then + -- simply attach to existing if exists + if vim.fn.filereadable(kernel_filen) == 1 then + vim.cmd("MoltenInit " .. kernel_filen) return end - if args then - file = args[0] + -- look for session maker + local exec_name = "jupyter-kernel" + local exec_path = (require("core.util").get_python_venv_basefolder() or "") .. "/bin/" .. exec_name + if vim.fn.filereadable(exec_path) ~= 1 then + exec_path = exec_name + if vim.fn.executable(exec_path) ~= 1 then + return + end end + + -- make our own session local once = false - vim.fn.jobstart({ "jupyter", "console", "-f", file }, { - on_stdout = function(_) + vim.fn.jobstart({ exec_path, "--KernelManager.connection_file", kernel_filen }, { + on_stderr = function(_, data) if not once then - vim.cmd("MoltenInit " .. file) + for _, v in pairs(data) do + if v:find("connect a client") then + vim.cmd("MoltenInit " .. kernel_filen) + once = true + end + end end - once = true end, on_exit = function(_) - vim.notify(string.format("jupyter kernel stopped: %s", file), vim.log.levels.INFO) + vim.notify(string.format("jupyter kernel stopped: %s", kernel_filen), vim.log.levels.INFO) end, stdin = nil, }) end -vim.api.nvim_create_user_command("JupyterStart", function() - startsession(vim.b["sessionfile"] or default_buffer_session()) -end, {}) + +vim.api.nvim_create_user_command("JupyterStart", function(opts) + startsession(opts) +end, { nargs = "?" }) +vim.keymap.set("n", "cS", ":JupyterStart", { desc = "start code session", silent = true }) if vim.g.quarto_auto_init_molten_session then - vim.api.nvim_create_autocmd({ "InsertEnter", "BufEnter" }, { + vim.api.nvim_create_autocmd({ "BufEnter" }, { callback = function() if vim.b["sessionfile"] == nil then - local path = default_buffer_session() - vim.b["sessionfile"] = path - vim.schedule_wrap(function() - startsession(path) + vim.schedule(function() + startsession() end) end end, diff --git a/nvim/.config/nvim/after/ftplugin/typst.lua b/nvim/.config/nvim/after/ftplugin/typst.lua new file mode 100644 index 0000000..e3d8d14 --- /dev/null +++ b/nvim/.config/nvim/after/ftplugin/typst.lua @@ -0,0 +1,3 @@ +if vim.fn.exists(":TypstPreviewToggle") > 0 then + vim.keymap.set("n", "po", "TypstPreviewToggle", { desc = "show typst preview" }) +end diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 01b8a10..52fa1bc 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -1,47 +1,36 @@ { "Arduino.nvim": { "branch": "main", "commit": "5988e7b08d8d6dc0a2d37e805cbed57dc13d869a" }, "FixCursorHold.nvim": { "branch": "master", "commit": "1900f89dc17c603eec29960f57c00bd9ae696495" }, - "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, "Navigator.nvim": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" }, - "aerial.nvim": { "branch": "master", "commit": "9c29a1a66eb31384888e413e510ba72496e06770" }, "bats.vim": { "branch": "master", "commit": "6a5d2ef22b0ede503d867770afd02ebb1f97b709" }, - "cmp-beancount": { "branch": "main", "commit": "29e23297c06b9d69771e4b14e0fb3b9d583a150e" }, - "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "blink.cmp": { "branch": "main", "commit": "b6f11a0aa33e601c469a126e3ed6e35208fe3ea3" }, + "blink.compat": { "branch": "main", "commit": "1176525a78319a208300a1910b6fd9e0cfabff25" }, "cmp-calc": { "branch": "main", "commit": "5947b412da67306c5b68698a02a846760059be2e" }, - "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, - "cmp-latex-symbols": { "branch": "main", "commit": "165fb66afdbd016eaa1570e41672c4c557b57124" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, - "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7" }, - "cmp-pandoc-references": { "branch": "master", "commit": "2c808dff631a783ddd2c554c4c6033907589baf6" }, - "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, - "cmp-rg": { "branch": "master", "commit": "70a43543f61b6083ba9c3b7deb9ccee671410ac6" }, + "cmp-pandoc.nvim": { "branch": "main", "commit": "30faa4456a7643c4cb02d8fa18438fd484ed7602" }, "cmp-spell": { "branch": "master", "commit": "694a4e50809d6d645c1ea29015dad0c293f019d6" }, - "cmp-treesitter": { "branch": "master", "commit": "958fcfa0d8ce46d215e19cc3992c542f576c4123" }, - "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, - "completion-vcard": { "branch": "master", "commit": "2220fd517a985ececed1adcf0e5be8f2815564c7" }, - "conform.nvim": { "branch": "master", "commit": "6239d9986f51ca93ded99ecdb1af0e287eabb651" }, - "dial.nvim": { "branch": "master", "commit": "46b4375e84e8eb771129bff6b2b1e47746601ef9" }, - "dressing.nvim": { "branch": "master", "commit": "43b8f74e0b1e3f41e51f640f8efa3bcd401cea0d" }, - "fidget.nvim": { "branch": "main", "commit": "ef99df04a1c53a453602421bc0f756997edc8289" }, + "codecompanion.nvim": { "branch": "main", "commit": "7cc8c94b373a60f86ef40bfc4ecc7c83a9771231" }, + "conform.nvim": { "branch": "master", "commit": "80b57f662b5e13ae8c2c7c38639966084625fa5e" }, + "copilot.vim": { "branch": "release", "commit": "87038123804796ca7af20d1b71c3428d858a9124" }, + "dial.nvim": { "branch": "master", "commit": "34bbd9c387c358190e61ce71017faad3dffa7a74" }, + "dressing.nvim": { "branch": "master", "commit": "3a45525bb182730fe462325c99395529308f431e" }, + "fidget.nvim": { "branch": "main", "commit": "9238947645ce17d96f30842e61ba81147185b657" }, "flash.nvim": { "branch": "main", "commit": "ec0bf2842189f65f60fd40bf3557cac1029cc932" }, - "friendly-snippets": { "branch": "main", "commit": "de8fce94985873666bd9712ea3e49ee17aadb1ed" }, + "friendly-snippets": { "branch": "main", "commit": "efff286dd74c22f731cdec26a70b46e5b203c619" }, "fwatch.nvim": { "branch": "main", "commit": "a691f7349dc66285cd75a1a698dd28bca45f2bf8" }, "git-conflict.nvim": { "branch": "main", "commit": "4bbfdd92d547d2862a75b4e80afaf30e73f7bbb4" }, "gitsigns.nvim": { "branch": "main", "commit": "0b04035bb7b3c83e999b9676e2fb46fd0aa9f910" }, - "glance.nvim": { "branch": "master", "commit": "17ee84e29ac33e7e5d91609f675cee8477586bda" }, - "grug-far.nvim": { "branch": "main", "commit": "9a2f78219390b47d67795ab09390d7f092e23976" }, + "glance.nvim": { "branch": "master", "commit": "1a08824835d7582457b67acbe23ca33487912a5e" }, + "grug-far.nvim": { "branch": "main", "commit": "635e69adf3a714621bd0a289314bc23c5848babb" }, "helpview.nvim": { "branch": "main", "commit": "34be34afd0811dee17e6b0c46176d9140659fe8e" }, - "hunk.nvim": { "branch": "master", "commit": "eb89245a66bdfce10436d15923bf4deb43d23c96" }, - "image.nvim": { "branch": "master", "commit": "da64ce69598875c9af028afe129f916b02ccc42e" }, + "image.nvim": { "branch": "master", "commit": "6ffafab2e98b5bda46bf227055aa84b90add8cdc" }, "img-clip.nvim": { "branch": "main", "commit": "28a32d811d69042f4fa5c3d5fa35571df2bc1623" }, "jupytext.nvim": { "branch": "main", "commit": "c8baf3ad344c59b3abd461ecc17fc16ec44d0f7b" }, - "lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" }, + "lazy.nvim": { "branch": "main", "commit": "7e6c863bc7563efbdd757a310d17ebc95166cef3" }, "lazydev.nvim": { "branch": "main", "commit": "f59bd14a852ca43db38e3662395354cb2a9b13e0" }, - "lsp-setup.nvim": { "branch": "main", "commit": "6e4e977512ce426d8b52c27f3b6e6aefc73e1452" }, - "ltex_extra.nvim": { "branch": "dev", "commit": "57192d7ae5ba8cef3c10e90f2cd62d4a7cdaab69" }, + "ltex_extra.nvim": { "branch": "dev", "commit": "09dc879b1873001f855bca5ad1f024ca15b9bbaf" }, "lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" }, "luarocks.nvim": { "branch": "main", "commit": "1db9093915eb16ba2473cfb8d343ace5ee04130a" }, - "luvit-meta": { "branch": "main", "commit": "57d464c4acb5c2e66bd4145060f5dc9e96a7bbb7" }, + "luvit-meta": { "branch": "main", "commit": "1df30b60b1b4aecfebc785aa98943db6c6989716" }, "markmap.nvim": { "branch": "main", "commit": "5fb6755cf5434511cc23a4936c9eb76b9142fba5" }, "mason-conform.nvim": { "branch": "main", "commit": "abce2be529f3b4b336c56d0ba6336a9144e0fee6" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" }, @@ -49,54 +38,51 @@ "mason.nvim": { "branch": "main", "commit": "c43eeb5614a09dc17c03a7fb49de2e05de203924" }, "mdeval.nvim": { "branch": "master", "commit": "0e1b248db174a9659a9ab16eb8c90ff3aec55264" }, "mini.nvim": { "branch": "main", "commit": "64e95aa77587d04f97a5579b2106a82a08a7d968" }, - "molten-nvim": { "branch": "main", "commit": "66ee5c0a0fbe3e014b867d04db44592f2d3eb30f" }, - "neo-tree.nvim": { "branch": "main", "commit": "a77af2e764c5ed4038d27d1c463fa49cd4794e07" }, - "neogen": { "branch": "main", "commit": "dc50715c009f89b8111197fd2f282f6042daa7ea" }, - "neotest": { "branch": "master", "commit": "6d3d22cdad49999ef774ebe1bc250a4994038964" }, + "molten-nvim": { "branch": "main", "commit": "c621baf53459a6c45dfd98dcc11cbba7a7ae9470" }, + "neo-tree.nvim": { "branch": "main", "commit": "5d172e8315444dbc32867d1c7b04d8e7e68ec4e1" }, + "neogen": { "branch": "main", "commit": "b2e78708876f4da507839726816010a68e33fec8" }, + "neotest": { "branch": "master", "commit": "d66cf4e05a116957f0d3a7755a24291c7d1e1f72" }, "neotest-python": { "branch": "master", "commit": "a2861ab3c9a0bf75a56b11835c2bfc8270f5be7e" }, "nui.nvim": { "branch": "main", "commit": "a0fd35fcbb4cb479366f1dc5f20145fd718a3733" }, "nvim-FeMaco.lua": { "branch": "main", "commit": "96bbf843595dbe865838b3f2484b73557f34700c" }, - "nvim-cmp": { "branch": "main", "commit": "ca4d3330d386e76967e53b85953c170658255ecb" }, - "nvim-colorizer.lua": { "branch": "master", "commit": "4acf88d31b3a7a1a7f31e9c30bf2b23c6313abdb" }, - "nvim-coverage": { "branch": "main", "commit": "aa4b4400588e2259e87e372b1e4e90ae13cf5a39" }, - "nvim-lint": { "branch": "master", "commit": "6b46370d02cd001509a765591a3ffc481b538794" }, - "nvim-lspconfig": { "branch": "master", "commit": "7b0a2f6b14485bb5a237fc1328a487ff3e4a08c5" }, - "nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" }, - "nvim-surround": { "branch": "main", "commit": "9f0cb495f25bff32c936062d85046fbda0c43517" }, - "nvim-toggleterm.lua": { "branch": "main", "commit": "022ff5594acccc8d90d2e46dc43994f7722ebdf7" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "39142aa1390d6ccdca57cb6dc5b2c7bfed460ffe" }, + "nvim-coverage": { "branch": "main", "commit": "a939e425e363319d952a6c35fb3f38b34041ded2" }, + "nvim-lint": { "branch": "master", "commit": "789b7ada1b4f00e08d026dffde410dcfa6a0ba87" }, + "nvim-lspconfig": { "branch": "master", "commit": "bf81bef7d75a0f4a0cf61462b318ea00b3c97cc8" }, + "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, + "nvim-surround": { "branch": "main", "commit": "ae298105122c87bbe0a36b1ad20b06d417c0433e" }, + "nvim-toggleterm.lua": { "branch": "main", "commit": "50ea089fc548917cc3cc16b46a8211833b9e3c7c" }, "nvim-treesitter": { "branch": "master", "commit": "cfc6f2c117aaaa82f19bcce44deec2c194d900ab" }, - "nvim-treesitter-context": { "branch": "master", "commit": "920999bf53daa63ddf12efdeb5137a7cea1cc201" }, + "nvim-treesitter-context": { "branch": "master", "commit": "bece284c5322ddf6946fa4bdc383a2bc033269d7" }, "nvim-treesitter-endwise": { "branch": "master", "commit": "8b34305ffc28bd75a22f5a0a9928ee726a85c9a6" }, "nvim-treesitter-textsubjects": { "branch": "master", "commit": "a8d2844bba925d9450ef7ab215f3b054028288ca" }, - "nvim-ts-autotag": { "branch": "main", "commit": "f2d24aca1bcbbd2c0306fd93d52e3697027b77ff" }, - "nvim-ts-context-commentstring": { "branch": "main", "commit": "9c74db656c3d0b1c4392fc89a016b1910539e7c0" }, + "nvim-ts-autotag": { "branch": "main", "commit": "1cca23c9da708047922d3895a71032bc0449c52d" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "1b212c2eee76d787bbea6aa5e92a2b534e7b4f8f" }, "nvim-web-devicons": { "branch": "master", "commit": "5b9067899ee6a2538891573500e8fd6ff008440f" }, - "otter.nvim": { "branch": "main", "commit": "ca9ce67d0399380b659923381b58d174344c9ee7" }, - "parrot.nvim": { "branch": "main", "commit": "413679a79cf220c261a4700cee5a01cadd99db53" }, + "otter.nvim": { "branch": "main", "commit": "7b42ce1f9deabc596214fc3b80e5ab4fd5b32726" }, "peek.nvim": { "branch": "master", "commit": "5820d937d5414baea5f586dc2a3d912a74636e5b" }, - "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, + "plenary.nvim": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" }, "popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" }, - "quarto-nvim": { "branch": "main", "commit": "23083a0152799ca7263ac9ae53d768d4dd93d24e" }, - "rainbow-delimiters.nvim": { "branch": "master", "commit": "e0f9b3efe150724af2d2ed59997d5ece373840e3" }, - "render-markdown": { "branch": "main", "commit": "6096cf3608b576a38fd1396227dbc0473091714d" }, + "quarto-nvim": { "branch": "main", "commit": "1cb2d24d7793241bd43f38e3a6f99a6d11f84458" }, + "rainbow-delimiters.nvim": { "branch": "master", "commit": "dc788723f717bdd3041838b8db34cce53c9aa920" }, + "render-markdown": { "branch": "main", "commit": "16369540a005ad0cf267498162aedca6dfca1b9c" }, "smartcolumn.nvim": { "branch": "main", "commit": "d01b99355c7fab13233f48d0f28dc097e68a03f7" }, "stickybuf.nvim": { "branch": "master", "commit": "2160fcd536d81f5fa43f7167dba6634e814e3154" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, - "telescope-jj.nvim": { "branch": "main", "commit": "9527e39f30eded7950ca127698422ec412d633c4" }, - "telescope-luasnip.nvim": { "branch": "master", "commit": "11668478677de360dea45cf2b090d34f21b8ae07" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "dae2eac9d91464448b584c7949a31df8faefec56" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "texpresso.vim": { "branch": "main", "commit": "1cc949fde8ed3220968039b6b1b6ccdd9f475087" }, + "texpresso.vim": { "branch": "main", "commit": "907838c08bbf99ad6bed3c908f1d0551a92ab4e0" }, "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, "trouble.nvim": { "branch": "main", "commit": "40c5317a6e90fe3393f07b0fee580d9e93a216b4" }, "twilight.nvim": { "branch": "main", "commit": "8bb7fa7b918baab1ca81b977102ddb54afa63512" }, + "typst-preview.nvim": { "branch": "master", "commit": "c1100e8788baabe8ca8f8cd7fd63d3d479e49e36" }, "undotree": { "branch": "main", "commit": "eab459ab87dd249617b5f7187bb69e614a083047" }, "vifm.vim": { "branch": "master", "commit": "a8130c37d144b51d84bee19f0532abcd3583383f" }, "vim-criticmarkup": { "branch": "master", "commit": "d15dc134eb177a170c79f6377f81eb02a9d20b02" }, "vim-numbertoggle": { "branch": "main", "commit": "df9b1fe616507340718716204ba7f434125bdf7a" }, "vim-spellsync": { "branch": "master", "commit": "3d6dd50de9c4d953cc16638112a6ae196df41463" }, "wezterm.nvim": { "branch": "main", "commit": "f73bba23ab4becd146fa2d0a3a16a84b987eeaca" }, - "which-key.nvim": { "branch": "main", "commit": "9b365a6428a9633e3eeb34dbef1b791511c54f70" }, + "which-key.nvim": { "branch": "main", "commit": "8ab96b38a2530eacba5be717f52e04601eb59326" }, "wrapping.nvim": { "branch": "master", "commit": "3a823200c297885b70515fa8d974e1763c578e26" }, "zen-mode.nvim": { "branch": "main", "commit": "04b52674b8c800f8b7d4609e8bd8d0212e3ffa79" }, - "zk-nvim": { "branch": "main", "commit": "469e7562b8dbf1bcbfe1be245ca5d1724917f5c6" } + "zk-nvim": { "branch": "main", "commit": "50d92038d22ad9a537dcfd463c38527591430df6" } } diff --git a/nvim/.config/nvim/lua/core/mappings.lua b/nvim/.config/nvim/lua/core/mappings.lua index c0c5880..dab1ef0 100644 --- a/nvim/.config/nvim/lua/core/mappings.lua +++ b/nvim/.config/nvim/lua/core/mappings.lua @@ -120,7 +120,7 @@ map("n", "\\", ":vsp", { desc = "open vert split" }) map("n", "T", ":tabedit | Vifm", { desc = "open tab" }) -- select the whole buffer with -a -map("n", "a", "ggVG", { desc = "select all" }) +map("n", "A", "ggVG", { desc = "select all" }) -- Format current Paragraph (esp useful in prose writing) map("n", "q", "gqap", { silent = true, desc = "Format current paragraph" }) diff --git a/nvim/.config/nvim/lua/core/util.lua b/nvim/.config/nvim/lua/core/util.lua index 043136a..5fb9e4a 100644 --- a/nvim/.config/nvim/lua/core/util.lua +++ b/nvim/.config/nvim/lua/core/util.lua @@ -64,6 +64,11 @@ function T.get_python_venv_basefolder(workspace) return venv_path_cached end local match + match = vim.fn.finddir(".venv", "**1") + if match ~= "" then + venv_path_cached = match + return venv_path_cached + end -- Look downwards for file, can be nested. Limit to 1 depth for speed rn -- TODO: Maybe not hardcode 1-depth but allow choice. match = vim.fn.findfile("pyvenv.cfg", "**1") @@ -79,8 +84,8 @@ function T.get_python_venv_basefolder(workspace) if obj.code ~= 0 then return end - local venv_base_folder = obj.stdout:match("^%s*(.-)%s*$") - venv_path_cached = venv_base_folder + match = obj.stdout:match("^%s*(.-)%s*$") + venv_path_cached = match return venv_path_cached end end diff --git a/nvim/.config/nvim/lua/plugins/base.lua b/nvim/.config/nvim/lua/plugins/base.lua index 35bac31..be88221 100644 --- a/nvim/.config/nvim/lua/plugins/base.lua +++ b/nvim/.config/nvim/lua/plugins/base.lua @@ -203,6 +203,32 @@ return { draw = { animation = require("mini.indentscope").gen_animation.none() }, options = { indent_at_cursor = false }, }) + -- disable indentlines for terminals + vim.api.nvim_create_autocmd("TermOpen", { + pattern = "*", + callback = function() + vim.b.miniindentscope_disable = true + end, + }) + vim.api.nvim_create_autocmd("FileType", { + pattern = { + "lazy", + "mason", + "help", + "lspinfo", + "packer", + "checkhealth", + "man", + "gitcommit", + "TelescopePrompt", + "TelescopeResults", + "trouble", + }, + callback = function() + vim.b.miniindentscope_disable = true + end, + }) + require("mini.map").setup() require("mini.move").setup() require("mini.operators").setup() @@ -251,4 +277,6 @@ return { { "stevearc/stickybuf.nvim", config = true }, -- make it a little less painful to open really big (>2mb) files by disabling features -- { "LunarVim/bigfile.nvim", lazy = false }, + -- set plenary to follow master branch here, but let individual plugins actually load it + { "nvim-lua/plenary.nvim", version = false, optional = true }, } diff --git a/nvim/.config/nvim/lua/plugins/completion.lua b/nvim/.config/nvim/lua/plugins/completion.lua index 6d38c40..7b39561 100644 --- a/nvim/.config/nvim/lua/plugins/completion.lua +++ b/nvim/.config/nvim/lua/plugins/completion.lua @@ -1,270 +1,69 @@ -local completion_engine = { - { - "hrsh7th/nvim-cmp", - branch = "main", - version = false, -- new releases (>2022) are sadly not versioned - dependencies = { - -- TODO: Move to lsp - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-nvim-lsp-signature-help", - "hrsh7th/cmp-path", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-calc", - "hrsh7th/cmp-cmdline", - -- TODO: Move me into a separate load? - "cbarrete/completion-vcard", - "f3fora/cmp-spell", - "jc-doyle/cmp-pandoc-references", - -- TODO: Decide: get rid or just enable in very specific circumstances - "lukas-reineke/cmp-rg", - -- TODO: Move to treesitter - { "ray-x/cmp-treesitter", dependencies = { "nvim-treesitter/nvim-treesitter" } }, - }, - opts = function() - local cmp = require("cmp") - -- style 'ghosttext' which appears behind cursor, showing current completion - vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) - - local has_words_before = function() - ---@diagnostic disable-next-line:deprecated - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 - and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - - local kind_icons = { - Text = "", - Method = "", - Function = "󰊕", - Constructor = "", - Field = "", - Variable = "", - Class = "", - Interface = "", - Module = "", - Property = "", - Unit = "", - Value = "V", - Enum = "", - Keyword = "", - Snippet = "", - Color = "", - File = "", - Reference = "", - Folder = "", - EnumMember = "", - Constant = "", - Struct = "", - Event = "", - Operator = "", - TypeParameter = "", - } - - -- `/` cmdline setup. - cmp.setup.cmdline("/", { - completion = { completeopt = "menu,menuone,noinsert,noselect" }, - preselect = cmp.PreselectMode.None, - mapping = cmp.mapping.preset.cmdline(), - sources = { { name = "buffer" } }, - }) - -- `:` cmdline setup. - cmp.setup.cmdline(":", { - completion = { completeopt = "menu,menuone,noinsert,noselect" }, - preselect = cmp.PreselectMode.None, - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ { name = "path" } }, { - { name = "cmdline", option = { ignore_cmds = { "Man", "!" } } }, - }), - }) - return { - window = { documentation = cmp.config.window.bordered() }, - -- add noselect to not automatically select first item - completion = { completeopt = "menu,menuone,noinsert" }, - preselect = cmp.PreselectMode.Item, -- not sure what this changes diff than above? - experimental = { - ghost_text = { - hl_group = "CmpGhostText", - }, - }, - sources = { - { name = "nvim_lsp" }, - { name = "nvim_lsp_signature_help" }, - { name = "pandoc_references" }, - { name = "calc" }, - { name = "path" }, - { name = "buffer", keyword_length = 3 }, - { name = "spell", keyword_length = 3 }, - -- { name = 'rg', keyword_length = 5 }, - { name = "vCard" }, - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping({ - i = function(fallback) - if cmp.visible() and cmp.get_active_entry() then - cmp.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = false, - }) - else - fallback() - end - end, - s = cmp.mapping.confirm({ select = true }), - c = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = false, - }), -- disable selection in cmd mode - }), - [""] = cmp.mapping(function(fallback) - -- expand_or_jumpable() will always jump - -- expand_or_locally_jumpable() only jumps when still inside snippet region - if cmp.visible() then - cmp.select_next_item() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end, { "i", "s" }), - }), - formatting = { - expandable_indicator = true, - fields = { "kind", "abbr", "menu" }, - format = function(entry, vim_item) - -- Kind icons, removing kind text leaving only icon - -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) - vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) - - -- Source - vim_item.menu = ({ - buffer = "", - calc = "󰃬", - digraphs = "∬", - latex_symbols = "𝓧", - luasnip = "", - nvim_lsp = "ℒ", - nvim_lua = "󰢱", - pandoc_references = "", - spell = "󰓆", - vCard = "󰛋", - })[entry.source.name] - return vim_item - end, - }, - } - end, - event = { "InsertEnter", "CmdlineEnter" }, - }, -} --- --- TODO: Enable more lazy loaded startup? And integrate into --- cmp as insert source instead of in its setup config below. -local snippet_engine = { - "nvim-cmp", +return { + -- full documentation here: https://cmp.saghen.dev/ + "saghen/blink.cmp", dependencies = { - "L3MON4D3/LuaSnip", + "saghen/blink.compat", "rafamadriz/friendly-snippets", - "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-calc", + "f3fora/cmp-spell", { - "benfowler/telescope-luasnip.nvim", - dependencies = { { "nvim-telescope/telescope.nvim", optional = true } }, - config = function() - if require("core.util").is_available("telescope") then - require("telescope").load_extension("luasnip") - end - end, + "aspeddro/cmp-pandoc.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + }, + opts = { + filetypes = { "pandoc", "markdown", "quarto", "rmd" }, + }, }, }, event = { "InsertEnter" }, - build = "make install_jsregexp", - opts = function(_, opts) - local cmp = require("cmp") - local luasnip = require("luasnip") + opts = { + keymap = { preset = "default" }, - require("luasnip.loaders.from_vscode").lazy_load({ exclude = { "markdown", "quarto" } }) - require("luasnip.loaders.from_snipmate").lazy_load() + appearance = { + -- Sets the fallback highlight groups to nvim-cmp's highlight groups + -- Useful for when your theme doesn't support blink.cmp + -- Will be removed in a future release + use_nvim_cmp_as_default = true, + -- Set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font' + -- Adjusts spacing to ensure icons are aligned + nerd_font_variant = "mono", + }, + completion = { + documentation = { auto_show = true, auto_show_delay_ms = 500 }, + -- ghost_text = { enabled = true }, + }, + signature = { + enabled = true, + }, - opts.snippet = { - expand = function(item) - require("luasnip").lsp_expand(item.body) - end, - } - local has_words_before = function() - ---@diagnostic disable-next-line:deprecated - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - end - - table.insert(opts.sources, { name = "luasnip", keyword_length = 1 }) - - opts.mapping[""] = cmp.mapping(function(fallback) -- expand_or_jumpable() will always jump - -- expand_or_locally_jumpable() only jumps when still inside snippet region - if luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - elseif cmp.visible() then - cmp.select_next_item() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }) - opts.mapping[""] = cmp.mapping(function(fallback) - if luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - elseif cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end, { "i", "s" }) - end, -} - -local beancount_cmp = { - "nvim-cmp", - dependencies = { - "crispgm/cmp-beancount", + -- Default list of enabled providers defined so that you can extend it + -- elsewhere in your config, without redefining it, due to `opts_extend` + sources = { + default = { + "pandoc", + "calc", + "lsp", + "path", + "snippets", + "buffer", + "spell", + }, + providers = { + calc = { + name = "calc", + module = "blink.compat.source", + }, + spell = { + name = "spell", + module = "blink.compat.source", + }, + pandoc = { + name = "cmp_pandoc", + module = "blink.compat.source", + }, + }, + }, }, - ft = "beancount", - opts = function(_, opts) - vim.g.python3_host_prog = "/home/marty/.local/pipx/venvs/beancount/bin/python" - table.insert(opts.sources, { - name = "beancount", - -- option = { - -- -- TODO: implement dynamically - -- -- I believe if we don't supply this it automatically takes - -- -- from the open file which would be good enough - -- account = "/home/marty/documents/records/budget/main.beancount", - -- }, - }) - end, -} - -local latex_cmp = { - "nvim-cmp", - dependencies = { - -- TODO: Needs better lazy loading - "kdheepak/cmp-latex-symbols", - }, - event = "CursorHold", - opts = function(_, opts) - table.insert(opts.sources, { name = "latex_symbols" }) - end, -} - -return { - completion_engine, - snippet_engine, - beancount_cmp, - latex_cmp, + opts_extend = { "sources.default" }, } diff --git a/nvim/.config/nvim/lua/plugins/data_analysis.lua b/nvim/.config/nvim/lua/plugins/data_analysis.lua index 6719b50..e05887b 100644 --- a/nvim/.config/nvim/lua/plugins/data_analysis.lua +++ b/nvim/.config/nvim/lua/plugins/data_analysis.lua @@ -15,7 +15,6 @@ return { dependencies = { "jmbuhr/otter.nvim", "neovim/nvim-lspconfig", - "hrsh7th/nvim-cmp", "nvim-treesitter/nvim-treesitter", { "benlubas/molten-nvim", optional = true }, }, @@ -41,10 +40,11 @@ return { map("n", "ca", require("quarto.runner").run_above, { desc = "run cells above" }) map("n", "cb", require("quarto.runner").run_below, { desc = "run cells below" }) map("n", "cA", require("quarto.runner").run_all, { desc = "run all similar cells" }) + -- TODO: overwritten by other moves, i.e. comment? map("n", "]c", "/^```{}:nohl", { desc = "Codecell forward" }) map("n", "[c", "?^```n}:nohl", { desc = "Codecell last" }) - map("n", "co", "o```{python}```k", { desc = "Insert quarto cell below" }) - map("n", "cO", "O```{python}```k", { desc = "Insert quarto cell above" }) + map("n", "co", "o```{python}```k", { desc = "Insert code cell below" }) + map("n", "cO", "O```{python}```k", { desc = "Insert code cell above" }) if require("core.util").is_available("which-key") then require("which-key").add({ "c", group = "codecells" }) @@ -53,48 +53,44 @@ return { ft = { "quarto" }, }, - { - "vhyrro/luarocks.nvim", - priority = 1001, -- this plugin needs to run before anything else - opts = { - rocks = { "magick" }, - }, - }, -- image display { "3rd/image.nvim", - dependencies = { "luarocks.nvim", { "nvim-treesitter/nvim-treesitter", optional = true } }, - cond = vim.fn.executable("magick") == 1, -- only runs if imagemagick installed - config = function() - local integrations = {} - if vim.treesitter.language.get_lang("markdown") then - integrations["markdown"] = { - enabled = true, - clear_in_insert_mode = true, - download_remote_images = true, + version = false, + dependencies = { + { + "vhyrro/luarocks.nvim", + priority = 1001, -- this plugin needs to run before anything else + opts = { + rocks = { "magick" }, + }, + }, + { "nvim-treesitter/nvim-treesitter", optional = true }, + }, + opts = { + backend = "kitty", + editor_only_render_when_focused = true, + -- TODO: Check that this works without TS md parser, norg or typst installed + -- If errors go back to commit before 87691932 when this check was still here + integrations = { + markdown = { only_render_image_at_cursor = true, filetypes = { "markdown", "vimwiki", "quarto" }, - } - end - if vim.treesitter.language.get_lang("norg") then - integrations["neorg"] = { - enabled = true, - clear_in_insert_mode = true, - download_remote_images = true, + }, + neorg = { only_render_image_at_cursor = true, - filetypes = { "norg" }, - } - end - if next(integrations) ~= nil then -- only set up if we have at least 1 TS parser - require("image").setup({ - backend = "kitty", - integrations = integrations, - }) - vim.g.molten_image_provider = "image.nvim" - pcall(vim.fn.MoltenUpdateOption, "molten_image_provider", "image.nvim") - end + }, + typst = { + only_render_image_at_cursor = true, + }, + }, + }, + config = function(_, opts) + require("image").setup(opts) + vim.g.molten_image_provider = "image.nvim" + pcall(vim.fn.MoltenUpdateOption, "molten_image_provider", "image.nvim") end, - ft = { "markdown", "vimwiki", "quarto", "norg", "python" }, + ft = { "markdown", "vimwiki", "quarto", "norg", "typst", "python" }, priority = 60, }, -- REPL work @@ -145,7 +141,7 @@ return { ":noautocmd :MoltenEnterOutput", { silent = true, desc = "show output" } ) - map("n", "cP", function() + map("n", "cx", function() vim.cmd("MoltenHideOutput") vim.cmd("MoltenDelete") end, { silent = true, desc = "hide output" }) @@ -192,9 +188,9 @@ return { ft = { "norg", "quarto", "python" }, keys = { { "vn", ":MoltenInfo" }, - { "cJ", ":JupyterStart", desc = "start jupyter", silent = true }, }, cmd = { + "JupyterStart", "MoltenInfo", "MoltenInit", "MoltenDeinit", @@ -225,25 +221,29 @@ return { -- Edit code blocks in md/quarto using whatever language is { "AckslD/nvim-FeMaco.lua", - cmd = { - "FeMaco", + cmd = { "FeMaco" }, + ft = { "markdown", "rmd", "quarto" }, + opts = { + ensure_newline = function(base_ft) + if base_ft == "quarto" or base_ft == "markdown" then + return true + end + return false + end, }, - ft = { "markdown", "quarto" }, - opts = {}, + config = function(_, opts) + vim.keymap.set("n", "ce", ":FeMaco", { desc = "edit codecell" }) + require("femaco").setup(opts) + end, dependencies = { "nvim-treesitter/nvim-treesitter", }, - keys = { - { "ce", ":FeMaco", desc = "edit codecell" }, - }, }, -- MARKDOWN ONLY -- Evaluate markdown code blocks - { + { -- TODO: Have results appear as virtual text instead of real text? "jubnzv/mdeval.nvim", - cmd = { - "MdEval", - }, + cmd = { "MdEval" }, ft = { "markdown" }, opts = { require_confirmation = false, @@ -271,7 +271,7 @@ return { }, }, }, - cond = vim.fn.executable("jupytext") == 1, -- only runs if imagemagick installed + cond = vim.fn.executable("jupytext") == 1, -- only runs if jupytext installed lazy = false, -- does not work in lazy mode }, } diff --git a/nvim/.config/nvim/lua/plugins/formatting.lua b/nvim/.config/nvim/lua/plugins/formatting.lua index 2ff40a2..c382f80 100644 --- a/nvim/.config/nvim/lua/plugins/formatting.lua +++ b/nvim/.config/nvim/lua/plugins/formatting.lua @@ -14,7 +14,7 @@ local formatters = { lua = { "stylua" }, markdown = { "prettier", "injected" }, nim = { "nimpretty" }, - python = { "ruff_fix", "ruff_format", "ruff_organize_imports" }, + python = { "ruff_format", "ruff_organize_imports" }, quarto = { "prettier", "injected" }, sh = { "shfmt" }, sql = { "sleek" }, diff --git a/nvim/.config/nvim/lua/plugins/languages.lua b/nvim/.config/nvim/lua/plugins/languages.lua index c24cc38..26d42f8 100644 --- a/nvim/.config/nvim/lua/plugins/languages.lua +++ b/nvim/.config/nvim/lua/plugins/languages.lua @@ -12,17 +12,18 @@ return { }, dependencies = { { "Bilal2453/luvit-meta" }, -- optional `vim.uv` typings - { -- optional completion source for require statements and module annotations - "hrsh7th/nvim-cmp", - opts = function(_, opts) - opts.sources = opts.sources or {} - table.insert(opts.sources, { - name = "lazydev", - group_index = 0, -- set group index to 0 to skip loading LuaLS completions - }) - end, - optional = true, - }, + -- FIXME: Set up to work with blink.cmp + -- { -- optional completion source for require statements and module annotations + -- "hrsh7th/nvim-cmp", + -- opts = function(_, opts) + -- opts.sources = opts.sources or {} + -- table.insert(opts.sources, { + -- name = "lazydev", + -- group_index = 0, -- set group index to 0 to skip loading LuaLS completions + -- }) + -- end, + -- optional = true, + -- }, }, }, } diff --git a/nvim/.config/nvim/lua/plugins/llm.lua b/nvim/.config/nvim/lua/plugins/llm.lua new file mode 100644 index 0000000..0307ceb --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/llm.lua @@ -0,0 +1,54 @@ +return { + -- TODO: Add completion w blink, see https://codecompanion.olimorris.dev/installation.html + { + "olimorris/codecompanion.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + "github/copilot.vim", + }, + init = function(_) + if require("core.util").is_available("which-key") then + require("which-key").add({ "a", group = "codecompanion" }) + end + end, + opts = { + strategies = { + chat = { adapter = "groq" }, + inline = { adapter = "groq" }, + }, + adapters = { + groq = function() + return require("codecompanion.adapters").extend("openai", { + env = { + api_key = "GROQ_API_KEY", + }, + name = "Groq", + url = "https://api.groq.com/openai/v1/chat/completions", + schema = { + model = { + default = "llama-3.1-8b-instant", + choices = { + "llama-3.3-70b-versatile", + "mixtral-8x7b-32768", + }, + }, + }, + max_tokens = { + default = 4096, + }, + temperature = { + default = 1, + }, + }) + end, + }, + }, + keys = { + { "aa", "CodeCompanionActions", desc = "Actions", silent = true, mode = { "n", "v" } }, + { "ac", "CodeCompanionChat Toggle", desc = "Toggle chat", silent = true }, + { "ac", "CodeCompanionChat Add", desc = "Add to chat", silent = true, mode = "v" }, + }, + cmd = { "CodeCompanionActions", "CodeCompanionChat", "CodeCompanion", "CodeCompanionCmd" }, + }, +} diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua index 5b6e2ac..0618215 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -35,183 +35,55 @@ local servers = { serve_d = {}, taplo = {}, texlab = {}, - tinymist = {}, + tinymist = { + settings = { + formatterMode = "typstyle", + }, + }, ts_ls = {}, yamlls = {}, } -return { - -- lsp setup +local lsp = { + { -- pretty lsp 'peek' menus + "DNLHC/glance.nvim", + opts = { border = { enable = true }, theme = { enable = true, mode = "auto" } }, + cmd = { "Glance" }, + }, { - "junnplus/lsp-setup.nvim", + "neovim/nvim-lspconfig", dependencies = { - { - "neovim/nvim-lspconfig", - -- will sometimes not keep up with lsp changes if set to stable - version = false, - }, - { - "williamboman/mason.nvim", - cmd = { - "Mason", - "MasonInstall", - "MasonUninstall", - "MasonUninstallAll", - "MasonLog", - "MasonUpdate", - }, - build = ":MasonUpdate", - keys = { - { "vm", ":Mason", desc = "Mason" }, - }, - }, { "williamboman/mason-lspconfig.nvim", + opts = { automatic_installation = true }, + dependencies = { + "williamboman/mason.nvim", + cmd = { + "Mason", + "MasonInstall", + "MasonUninstall", + "MasonUninstallAll", + "MasonLog", + "MasonUpdate", + }, + opts = {}, + build = ":MasonUpdate", + keys = { + { "vm", ":Mason", desc = "Mason" }, + }, + }, cmd = { "LspInstall", "LspUninstall" }, }, + { "saghen/blink.cmp", optional = true }, }, event = { "BufReadPost", "BufNewFile", "BufWritePre" }, - config = function() - vim.diagnostic.config({ virtual_text = true }) - vim.fn.sign_define("DiagnosticSignError", { text = "✘", texthl = "DiagnosticSignError" }) - vim.fn.sign_define("DiagnosticSignWarn", { text = "", texthl = "DiagnosticSignWarn" }) - vim.fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo" }) - vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) - - local lsp = require("lsp-setup") - - local function on_attach(_, bufnr) - local map = vim.keymap.set - map( - "n", - "[d", - "lua vim.diagnostic.goto_prev()", - { buffer = bufnr, desc = "Previous diagnostic" } - ) - map("n", "]d", "lua vim.diagnostic.goto_next()", { buffer = bufnr, desc = "Next diagnostic" }) - map( - "n", - "[D", - "lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})", - { buffer = bufnr, desc = "Previous error" } - ) - map( - "n", - "]D", - "lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})", - { buffer = bufnr, desc = "Next error" } - ) - - if require("core.util").is_available("which-key") then - require("which-key").add({ "l", group = "language" }) - end - map( - "n", - "ld", - "lua vim.diagnostic.open_float()", - { buffer = bufnr, desc = "Line diagnostics" } - ) - map("n", "li", function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) - end, { buffer = bufnr, desc = "Inlay hints" }) - map( - "n", - "la", - "lua vim.lsp.buf.code_action()", - { buffer = bufnr, desc = "Codeactions" } - ) - map( - "n", - "ln", - "lua vim.lsp.buf.rename()", - { buffer = bufnr, desc = "Rename element" } - ) - if vim.fn.exists(":Glance") then - map("n", "lr", "Glance references", { buffer = bufnr, desc = "References" }) - map("n", "lf", "Glance definitions", { buffer = bufnr, desc = "Definition" }) - map( - "n", - "lt", - "Glance type_definitions", - { buffer = bufnr, desc = "Type definition" } - ) - map( - "n", - "lm", - "Glance implementations", - { buffer = bufnr, desc = "Implementation" } - ) - elseif vim.fn.exists(":Telescope") then - map( - "n", - "lr", - "Telescope lsp_references", - { buffer = bufnr, desc = "References" } - ) - map( - "n", - "lf", - "Telescope lsp_definitions", - { buffer = bufnr, desc = "Definition" } - ) - map( - "n", - "lt", - "Telescope lsp_type_definitions", - { buffer = bufnr, desc = "Type definition" } - ) - map( - "n", - "lm", - "Telescope lsp_implementations", - { buffer = bufnr, desc = "Implementation" } - ) - else - map( - "n", - "lr", - "lua vim.lsp.buf.references()", - { buffer = bufnr, desc = "References" } - ) - map( - "n", - "lf", - "lua vim.lsp.buf.definition()", - { buffer = bufnr, desc = "Definition" } - ) - map( - "n", - "lt", - "lua vim.lsp.buf.type_definition()", - { buffer = bufnr, desc = "Type definition" } - ) - map( - "n", - "lm", - "lua vim.lsp.buf.implementation()", - { buffer = bufnr, desc = "Implementation" } - ) - end - map("n", "K", "lua vim.lsp.buf.hover()", { buffer = bufnr, desc = "Hover definition" }) - map( - "n", - "lc", - "lua vim.lsp.buf.declaration()", - { buffer = bufnr, desc = "Declaration" } - ) - map( - "n", - "ls", - "lua vim.lsp.buf.signature_help()", - { buffer = bufnr, desc = "Signature help" } - ) - map("n", "lo", function() - vim.diagnostic.enable(not vim.diagnostic.is_enabled()) - end, { buffer = bufnr, desc = "Toggle Diagnostics" }) - end + opts = { servers = servers }, + config = function(_, lspconfig_opts) + local lspconfig = require("lspconfig") -- Display diagnostics as virtual text only if not in insert mode -- /r/neovim/comments/12inp4c/disable_diagnostics_virtual_text_when_in_insert/jqqifwk/ + vim.diagnostic.config({ virtual_text = true }) vim.api.nvim_create_autocmd("InsertEnter", { callback = function() vim.diagnostic.config({ virtual_text = false }) @@ -223,16 +95,19 @@ return { end, }) - lsp.setup({ - default_mappings = false, - servers = servers, - on_attach = on_attach, - inlay_hints = { - enabled = vim.fn.has("nvim-0.10") == true and true or false, - }, - }) + vim.fn.sign_define("DiagnosticSignError", { text = "✘", texthl = "DiagnosticSignError" }) + vim.fn.sign_define("DiagnosticSignWarn", { text = "", texthl = "DiagnosticSignWarn" }) + vim.fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo" }) + vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) + + for server, config in pairs(lspconfig_opts.servers) do + -- TODO: Check if it actually can be ignored in Nvim 0.11+, see https://cmp.saghen.dev/installation.html#lazy-nvim + if vim.fn.has("nvim-0.11") == false then + config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities) + end + lspconfig[server].setup(config) + end - local lspconfig = require("lspconfig") lspconfig.nushell.setup({}) lspconfig.marksman.setup({ @@ -275,7 +150,6 @@ return { end, } end - on_attach(client, bufnr) end, on_new_config = function(conf, new_root) if require("lspconfig.util").root_pattern(".zk")(new_root) then @@ -291,12 +165,10 @@ return { -- we primarily use pyright for cmp lsp completion & hover info lspconfig.basedpyright.setup({ on_attach = function(client, bufnr) - on_attach(client, bufnr) require("core.util").set_python_env() if python_path == nil then python_path, _ = vim.fn.expand(require("core.util").get_python_venv_bin(client.config.root_dir)) end - -- print(string.format("[PYTHON VENV]: %s", vim.inspect(python_path))) client.config.settings.python = {} or client.config.settings.python client.config.settings.python.pythonPath = python_path end, @@ -315,7 +187,6 @@ return { }) lspconfig.ruff.setup({ on_attach = function(client, bufnr) - on_attach(client, bufnr) require("core.util").set_python_env() client.server_capabilities.hoverProvider = false -- we use pyright for hover info if python_path == nil then @@ -339,7 +210,6 @@ return { callback = function() lspconfig.ltex.setup({ on_attach = function(client, bufnr) - on_attach(client, bufnr) if require("core.util").is_available("ltex_extra") then require("ltex_extra").setup() end @@ -356,10 +226,98 @@ return { end, keys = { { "vs", ":LspInfo", desc = "LspInfo" } }, }, - -- pretty lsp 'peek' menus - { - "DNLHC/glance.nvim", - opts = { border = { enable = true }, theme = { enable = true, mode = "auto" } }, - cmd = { "Glance" }, - }, } + +vim.api.nvim_create_autocmd("LspAttach", { + desc = "LSP actions", + callback = function(event) + local o = function(add_opts) + return vim.tbl_extend("force", { buffer = event.buf }, add_opts) + end + + local map = vim.keymap.set + map("n", "K", "lua vim.lsp.buf.hover()", o({ desc = "Hover definition" })) + map("n", "[d", "lua vim.diagnostic.goto_prev()", o({ desc = "Previous diagnostic" })) + map("n", "]d", "lua vim.diagnostic.goto_next()", o({ desc = "Next diagnostic" })) + map( + "n", + "[D", + "lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})", + o({ desc = "Previous error" }) + ) + map( + "n", + "]D", + "lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})", + o({ desc = "Next error" }) + ) + + if require("core.util").is_available("which-key") then + require("which-key").add({ "l", group = "language" }) + end + map("n", "ld", "lua vim.diagnostic.open_float()", o({ desc = "Show line diagnostics" })) + map("n", "lI", function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled()) + end, o({ desc = "Toggle inlay hints" })) + map("n", "la", "lua vim.lsp.buf.code_action()", o({ desc = "Codeactions" })) + map("n", "ln", "lua vim.lsp.buf.rename()", o({ desc = "Rename element" })) + map("n", "lc", "lua vim.lsp.buf.declaration()", o({ desc = "Declaration" })) + map("n", "ls", "lua vim.lsp.buf.signature_help()", o({ desc = "Signature help" })) + map("n", "lo", function() + vim.diagnostic.enable(not vim.diagnostic.is_enabled()) + end, o({ desc = "Toggle Diagnostics" })) + + local pref = function(glances, telescope, fallback) + if glances and vim.fn.exists(":Glance") > 0 then + return glances + elseif telescope and vim.fn.exists(":Telescope") > 0 then + return telescope + else + return fallback + end + end + + map( + "n", + "lr", + pref( + "Glance references", + "Telescope lsp_references", + "lua vim.lsp.buf.references()" + ), + o({ desc = "References" }) + ) + map( + "n", + "lf", + pref( + "Glance definitions", + "Telescope lsp_definitions", + "lua vim.lsp.buf.definition()" + ), + o({ desc = "Definition" }) + ) + map( + "n", + "lt", + pref( + "Glance type_definitions", + "Telescope lsp_type_definitions", + "lua vim.lsp.buf.type_definition()" + ), + o({ desc = "Type definition" }) + ) + map( + "n", + "lm", + pref( + "Glance implementations", + "Telescope lsp_implementations", + "lua vim.lsp.buf.implementation()" + ), + o({ desc = "Implementation" }) + ) + end, +}) + +return lsp diff --git a/nvim/.config/nvim/lua/plugins/pickers.lua b/nvim/.config/nvim/lua/plugins/pickers.lua index c8d1053..0ab8c6b 100644 --- a/nvim/.config/nvim/lua/plugins/pickers.lua +++ b/nvim/.config/nvim/lua/plugins/pickers.lua @@ -28,7 +28,7 @@ return { keys = { { "se", "Neotree toggle left", desc = "filetree", silent = true }, }, - lazy = false + lazy = false, }, { "MagicDuck/grug-far.nvim", lazy = false, opts = {} }, -- fuzzy matching picker diff --git a/nvim/.config/nvim/lua/plugins/prose.lua b/nvim/.config/nvim/lua/plugins/prose.lua index 602954f..76b531b 100644 --- a/nvim/.config/nvim/lua/plugins/prose.lua +++ b/nvim/.config/nvim/lua/plugins/prose.lua @@ -72,7 +72,8 @@ local prose_plugs = { render_modes = { "n", "c", "i" }, code = { sign = false, - width = "block", + width = "full", + position = "right", right_pad = 1, }, checkbox = { @@ -81,6 +82,11 @@ local prose_plugs = { removed = { raw = "[_]", rendered = "󱋭 ", highlight = "RenderMarkdownTodo" }, }, }, + html = { + comment = { + conceal = false, + }, + }, }, name = "render-markdown", -- Only needed if you have another plugin named markdown.nvim dependencies = { @@ -91,7 +97,7 @@ local prose_plugs = { cmd = "RenderMarkdown", keys = { { - "pp", + "pm", function() require("render-markdown").toggle() end, @@ -100,29 +106,43 @@ local prose_plugs = { }, }, }, + --- PREVIEW SECTION -- generate an auto-updating html preview for md files -- uses the very nice peek if deno is available, otherwise falls back to markdown-preview { "toppair/peek.nvim", - event = { "VeryLazy" }, cond = vim.fn.executable("deno") == 1, build = "deno task --quiet build:fast", ft = md_like, - config = function() - require("peek").setup() - vim.api.nvim_create_user_command("PeekOpen", require("peek").open, {}) - vim.api.nvim_create_user_command("PeekClose", require("peek").close, {}) - end, + opts = {}, }, { "iamcco/markdown-preview.nvim", - event = { "VeryLazy" }, cond = vim.fn.executable("deno") == 0, build = function() vim.fn["mkdp#util#install"]() end, + version = false, ft = md_like, + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, }, + { + "chomosuke/typst-preview.nvim", + ft = { "typst" }, + opts = { -- to use mason-managed binary + dependencies_bin = { ["tinymist"] = "tinymist" }, + }, + cmd = { + "TypstPreview", + "TypstPreviewUpdate", + "TypstPreviewStop", + "TypstPreviewToggle", + "TypstPreviewFollowCursor", + "TypstPreviewNoFollowCursor", + "TypstPreviewFollowCursorToggle", + }, + }, + --- END PREVIEW SECTION -- easy copy paste of images into markup files { @@ -139,14 +159,14 @@ local prose_plugs = { }, cmd = { "PasteImage" }, keys = { - { "pi", "PasteImage", desc = "Paste image from system clipboard" }, + { "pi", "PasteImage", desc = "Paste image from system clipboard" }, }, ft = prose_ft, }, -- bring zettelkasten commands { - "mickael-menu/zk-nvim", + "zk-org/zk-nvim", config = function() if require("core.util").is_available("which-key") then require("which-key").add({ @@ -159,6 +179,24 @@ local prose_plugs = { opts = vim.tbl_extend("force", { orphan = true }, opts or {}) require("zk").edit(opts, { title = "Zk Orphans" }) end) + require("zk.commands").add("ZkGrep", function(opts) + local collection = {} + local list_opts = { select = { "title", "path", "absPath" } } + require("zk.api").list(vim.env.ZK_NOTEBOOK_DIR, list_opts, function(_, notes) + for _, note in ipairs(notes) do + collection[note.absPath] = note.title or note.path + end + end) + local options = vim.tbl_deep_extend("force", { + prompt_title = "Notes", + search_dirs = { vim.env.ZK_NOTEBOOK_DIR }, + disable_coordinates = true, + path_display = function(_, path) + return collection[path] + end, + }, opts or {}) + require("telescope.builtin").live_grep(options) + end) end require("zk").setup({ picker = "telescope", @@ -199,6 +237,7 @@ local prose_plugs = { desc = "note search", }, { "nf", "ZkMatch", desc = "find note from selection", mode = "v" }, + { "nw", "ZkGrep", desc = "grep notes" }, { "nt", "ZkTags", desc = "note tags" }, { "nc", "ZkCd", desc = "notedir cd" }, { "no", "ZkOrphans { sort = { 'modified' } }", desc = "orphans list" }, @@ -219,22 +258,25 @@ local prose_plugs = { -- cite as you write from papis databases -- ADDITIONAL DEPENDENCIES: papis and yq in shell env - -- { - -- "jghauser/papis.nvim", - -- dependencies = { - -- "kkharji/sqlite.lua", - -- "MunifTanjim/nui.nvim", - -- "pysan3/pathlib.nvim", - -- "nvim-neotest/nvim-nio", - -- "nvim-treesitter/nvim-treesitter", - -- }, - -- cond = vim.fn.executable("papis") == 1 and vim.fn.executable("yq") == 1, - -- ft = writing_ft, - -- lazy = false, - -- config = function() - -- require("papis").setup({}) - -- end, - -- }, + -- still same issues: slow, buggy, does not work for me + { + "jghauser/papis.nvim", + dependencies = { + "kkharji/sqlite.lua", + "MunifTanjim/nui.nvim", + "pysan3/pathlib.nvim", + "nvim-neotest/nvim-nio", + -- if not already installed, you may also want: + { "nvim-telescope/telescope.nvim", optional = true }, + -- "hrsh7th/nvim-cmp", + }, + config = function() + require("papis").setup({ + init_filetypes = prose_ft, + }) + end, + lazy = false, + }, { "barreiroleo/ltex_extra.nvim", branch = "dev", diff --git a/nvim/.config/nvim/lua/plugins/statusline.lua b/nvim/.config/nvim/lua/plugins/statusline.lua index 468067b..3543201 100644 --- a/nvim/.config/nvim/lua/plugins/statusline.lua +++ b/nvim/.config/nvim/lua/plugins/statusline.lua @@ -22,14 +22,11 @@ return { return "" -- we don't know if we have python yet, start a check else - vim.system({ "poetry", "env", "info", "-p" }, { text = true }, function(obj) - if obj.code == 0 then - has_pynvim = 1 - else - has_pynvim = 0 - end - end) - has_pynvim = 0 + if vim.fn.has("python3") == 1 then + has_pynvim = 1 + else + has_pynvim = 0 + end end end diff --git a/nvim/.config/nvim/lua/plugins/terminal.lua b/nvim/.config/nvim/lua/plugins/terminal.lua index ac97546..54f5726 100644 --- a/nvim/.config/nvim/lua/plugins/terminal.lua +++ b/nvim/.config/nvim/lua/plugins/terminal.lua @@ -1,68 +1,54 @@ -return { - -- simpler, programmable and multiple terminal toggling for nvim +return { -- simple programmable terminal toggling for nvim { "akinsho/nvim-toggleterm.lua", + init = function(_) + if require("core.util").is_available("which-key") then + require("which-key").add({ "t", group = "terminal" }) + end + end, config = function() require("toggleterm").setup({ - open_mapping = [[=]], + open_mapping = [[tt]], insert_mappings = false, -- don't map the key in insert mode terminal_mappings = false, }) local Terminal = require("toggleterm.terminal").Terminal - -- need to disable indentlines since they obscure first line of terminal - if require("core.util").is_available("mini.nvim") then - vim.api.nvim_create_autocmd({ "TermOpen" }, { - pattern = "*", - callback = function() - vim.b.miniindentscope_disable = true - end, - }) - end - local function custom_term_set_toggle_key(term) vim.keymap.set("t", "", function() term:toggle() - end, { silent = true, buffer = true }) + end, { silent = true, buffer = true, desc = "terminal" }) end - -- create python window - local function get_python_cmd() - if vim.fn.executable("py") then - return "py" - end - if vim.fn.executable("ptipython") then - return "ptipython" - end - if vim.fn.executable("ipython") then - return "ipython" - end - if vim.fn.executable("ptpython") then - return "ptpython" - end - if vim.fn.executable("python") then - return "python" - end + local custom_term_default_style = function(cmd) + return { + cmd = cmd, + hidden = true, + direction = "float", + float_opts = { border = "curved" }, + on_open = custom_term_set_toggle_key, + } end local terms = { - lazygit = Terminal:new({ - cmd = "lazygit", - hidden = true, - direction = "float", - float_opts = { border = "curved" }, - on_open = custom_term_set_toggle_key, - }), - python = Terminal:new({ - cmd = get_python_cmd(), - hidden = true, - direction = "float", - float_opts = { border = "curved" }, - on_open = custom_term_set_toggle_key, - }), + lazygit = Terminal:new(custom_term_default_style("lazygit")), + python = Terminal:new(custom_term_default_style(function() + for _, exec in pairs({ "py", "ptipython", "ipython", "ptpython", "python" }) do + if vim.fn.executable(exec) > 0 then + return exec + end + end + end)), + euporie = Terminal:new(custom_term_default_style(function() + local kernel = vim.b.sessionfile + if kernel then + return "euporie-console --connection-file '" .. kernel .. "'" + end + return "euporie-console" + end)), } - -- create a lazygit window with the lazygit command - local function toggle_custom_term(term, bang, vertsize) + -- have user decide between floating or split + local function toggle_split_or_float(term, bang, vertsize) vertsize = vertsize or vim.o.columns * 0.4 if not bang then term.direction = "float" @@ -74,30 +60,25 @@ return { end end - local function _Pythonterm_toggle(opts) - toggle_custom_term(terms.python, opts.bang) - end - local function _Lazygit_toggle(opts) - toggle_custom_term(terms.lazygit, opts.bang, vim.o.columns * 0.6) - end - - vim.api.nvim_create_user_command( - "Lazygit", - _Lazygit_toggle, - { desc = "Toggle floating Lazygit terminal", bang = true } - ) - vim.api.nvim_create_user_command( - "Pythonterm", - _Pythonterm_toggle, - { desc = "Toggle floating Python terminal", bang = true } - ) + vim.api.nvim_create_user_command("Lazygit", function(opts) + toggle_split_or_float(terms.lazygit, opts.bang, vim.o.columns * 0.6) + end, { desc = "Toggle floating Lazygit terminal", bang = true }) + vim.api.nvim_create_user_command("Pythonterm", function(opts) + toggle_split_or_float(terms.python, opts.bang) + end, { desc = "Toggle floating Python terminal", bang = true }) + vim.api.nvim_create_user_command("Euporieterm", function(opts) + toggle_split_or_float(terms.euporie, opts.bang) + end, { desc = "Toggle floating Euporie terminal", bang = true }) end, - cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" }, + cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm", "Euporieterm" }, keys = { - { "sg", ":Lazygit", desc = "git floating" }, - { "sG", ":Lazygit!", desc = "git buffer" }, - { "sp", ":Pythonterm", desc = "python floating" }, - { "sP", ":Pythonterm!", desc = "python buffer" }, + { "tt", ":ToggleTerm", desc = "terminal" }, + { "tg", ":Lazygit", desc = "git floating" }, + { "tG", ":Lazygit!", desc = "git buffer" }, + { "tp", ":Pythonterm", desc = "python floating" }, + { "tP", ":Pythonterm!", desc = "python buffer" }, + { "te", ":Euporieterm", desc = "euporie floating" }, + { "tE", ":Euporieterm!", desc = "euporie buffer" }, }, }, } diff --git a/office/.config/task/taskrc b/office/.config/task/taskrc index c9cf994..12270ae 100644 --- a/office/.config/task/taskrc +++ b/office/.config/task/taskrc @@ -44,10 +44,10 @@ report.today.sort=urgency- report.today.columns=id,project,priority,urgency,due,description,tags,scheduled,entry.age,recur report.today.labels=,Project,Pri,Urg,Due,Description,Tags,Sched,Age,Recur # report overview of tasks accomplished today -report.today.completed.description=Tasks completed today -report.today.completed.filter=status:completed end.after:tod -report.today.completed.columns=id,project,priority,urgency,due,description,tags,scheduled,entry.age,recur -report.today.completed.labels=,Project,Pri,Urg,Due,Description,Tags,Sched,Age,Recur +report.donetoday.description=Tasks completed today +report.donetoday.filter=status:completed end.after:tod +report.donetoday.columns=id,project,priority,urgency,due,description,tags,scheduled,entry.age,recur +report.donetoday.labels=,Project,Pri,Urg,Due,Description,Tags,Sched,Age,Recur # reorder priorities so that explicitly tagged 'Low' items are lower than normal uda.priority.values=H,M,,L diff --git a/writing/jrnl/config/jrnl/jrnl.yaml b/writing/jrnl/config/jrnl/jrnl.yaml index 5971cb8..14741d0 100644 --- a/writing/jrnl/config/jrnl/jrnl.yaml +++ b/writing/jrnl/config/jrnl/jrnl.yaml @@ -13,7 +13,7 @@ journals: default: journal: ~/documents/records/jrnl.md linewrap: 79 -tagsymbols: '+' +tagsymbols: + template: false timeformat: '%F %r' -version: v4.1 +version: v4.2