diff --git a/nvim/.config/nvim/after/ftplugin/markdown.lua b/nvim/.config/nvim/after/ftplugin/markdown.lua index 50d5511..d7f2888 100644 --- a/nvim/.config/nvim/after/ftplugin/markdown.lua +++ b/nvim/.config/nvim/after/ftplugin/markdown.lua @@ -11,37 +11,35 @@ 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 -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 +map("n", "cc", "MdEval", { silent = true, desc = "evaluate code block" }) +map("n", "cx", "MdEvalClean", { silent = true, desc = "clear code results" }) -- 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 code cell below" }) -map("n", "cO", "O```python```k", { desc = "Insert code cell above" }) +map("n", "co", "o```python```k", { desc = "Insert quarto cell below" }) +map("n", "cO", "O```python```k", { desc = "Insert quarto 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 - map("n", peek_key, function() - local peek = require("peek") + local peek = require("peek") + local function togglePeek() if peek.is_open() then peek.close() else peek.open() end - end, { desc = "show md preview" }) -elseif vim.fn.exists(":MarkdownPreviewToggle") > 0 then - map("n", peek_key, "MarkdownPreviewToggle", { desc = "show md preview" }) + end + map("n", "po", togglePeek, { desc = "show md preview" }) +else + map("n", "po", "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 a38d353..170805a 100644 --- a/nvim/.config/nvim/after/ftplugin/quarto.lua +++ b/nvim/.config/nvim/after/ftplugin/quarto.lua @@ -1,24 +1,17 @@ -if require("core.util").is_available("quarto") then - vim.keymap.set("n", "po", require("quarto").quartoPreview, { desc = "show quarto preview" }) -end +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" --- 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() + local dir = vim.fn.fnamemodify(temp_path, ":p:h") + if vim.fn.getftype(dir) ~= "dir" then + vim.fn.mkdir(dir, "p") end - local path, name = buf:match("(.-)([^\\/]-%.?([^%.\\/]*))$") - - return path .. "." .. name .. ".kernel.json" + return temp_path end -- Start quarto session -local startsession = function(opts) - local args = opts.fargs - local kernel_filen = args[1] or kernel_filename() - vim.b["sessionfile"] = kernel_filen +local startsession = function(file, args) + file = file or default_buffer_session() local path = require("core.util").get_python_venv_bin() if not path then @@ -26,53 +19,39 @@ local startsession = function(opts) end vim.g["python3_host_prog"] = path - -- simply attach to existing if exists - if vim.fn.filereadable(kernel_filen) == 1 then - vim.cmd("MoltenInit " .. kernel_filen) + if vim.fn.executable("jupyter-console") ~= 1 then return end - -- 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 + if args then + file = args[0] end - - -- make our own session local once = false - vim.fn.jobstart({ exec_path, "--KernelManager.connection_file", kernel_filen }, { - on_stderr = function(_, data) + vim.fn.jobstart({ "jupyter", "console", "-f", file }, { + on_stdout = function(_) if not once then - for _, v in pairs(data) do - if v:find("connect a client") then - vim.cmd("MoltenInit " .. kernel_filen) - once = true - end - end + vim.cmd("MoltenInit " .. file) end + once = true end, on_exit = function(_) - vim.notify(string.format("jupyter kernel stopped: %s", kernel_filen), vim.log.levels.INFO) + vim.notify(string.format("jupyter kernel stopped: %s", file), vim.log.levels.INFO) end, stdin = nil, }) 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 }) +vim.api.nvim_create_user_command("JupyterStart", function() + startsession(vim.b["sessionfile"] or default_buffer_session()) +end, {}) if vim.g.quarto_auto_init_molten_session then - vim.api.nvim_create_autocmd({ "BufEnter" }, { + vim.api.nvim_create_autocmd({ "InsertEnter", "BufEnter" }, { callback = function() if vim.b["sessionfile"] == nil then - vim.schedule(function() - startsession() + local path = default_buffer_session() + vim.b["sessionfile"] = path + vim.schedule_wrap(function() + startsession(path) end) end end, diff --git a/nvim/.config/nvim/after/ftplugin/typst.lua b/nvim/.config/nvim/after/ftplugin/typst.lua deleted file mode 100644 index e3d8d14..0000000 --- a/nvim/.config/nvim/after/ftplugin/typst.lua +++ /dev/null @@ -1,3 +0,0 @@ -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 52fa1bc..01b8a10 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -1,36 +1,47 @@ { "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" }, - "blink.cmp": { "branch": "main", "commit": "b6f11a0aa33e601c469a126e3ed6e35208fe3ea3" }, - "blink.compat": { "branch": "main", "commit": "1176525a78319a208300a1910b6fd9e0cfabff25" }, + "cmp-beancount": { "branch": "main", "commit": "29e23297c06b9d69771e4b14e0fb3b9d583a150e" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-calc": { "branch": "main", "commit": "5947b412da67306c5b68698a02a846760059be2e" }, - "cmp-pandoc.nvim": { "branch": "main", "commit": "30faa4456a7643c4cb02d8fa18438fd484ed7602" }, + "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-spell": { "branch": "master", "commit": "694a4e50809d6d645c1ea29015dad0c293f019d6" }, - "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" }, + "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" }, "flash.nvim": { "branch": "main", "commit": "ec0bf2842189f65f60fd40bf3557cac1029cc932" }, - "friendly-snippets": { "branch": "main", "commit": "efff286dd74c22f731cdec26a70b46e5b203c619" }, + "friendly-snippets": { "branch": "main", "commit": "de8fce94985873666bd9712ea3e49ee17aadb1ed" }, "fwatch.nvim": { "branch": "main", "commit": "a691f7349dc66285cd75a1a698dd28bca45f2bf8" }, "git-conflict.nvim": { "branch": "main", "commit": "4bbfdd92d547d2862a75b4e80afaf30e73f7bbb4" }, "gitsigns.nvim": { "branch": "main", "commit": "0b04035bb7b3c83e999b9676e2fb46fd0aa9f910" }, - "glance.nvim": { "branch": "master", "commit": "1a08824835d7582457b67acbe23ca33487912a5e" }, - "grug-far.nvim": { "branch": "main", "commit": "635e69adf3a714621bd0a289314bc23c5848babb" }, + "glance.nvim": { "branch": "master", "commit": "17ee84e29ac33e7e5d91609f675cee8477586bda" }, + "grug-far.nvim": { "branch": "main", "commit": "9a2f78219390b47d67795ab09390d7f092e23976" }, "helpview.nvim": { "branch": "main", "commit": "34be34afd0811dee17e6b0c46176d9140659fe8e" }, - "image.nvim": { "branch": "master", "commit": "6ffafab2e98b5bda46bf227055aa84b90add8cdc" }, + "hunk.nvim": { "branch": "master", "commit": "eb89245a66bdfce10436d15923bf4deb43d23c96" }, + "image.nvim": { "branch": "master", "commit": "da64ce69598875c9af028afe129f916b02ccc42e" }, "img-clip.nvim": { "branch": "main", "commit": "28a32d811d69042f4fa5c3d5fa35571df2bc1623" }, "jupytext.nvim": { "branch": "main", "commit": "c8baf3ad344c59b3abd461ecc17fc16ec44d0f7b" }, - "lazy.nvim": { "branch": "main", "commit": "7e6c863bc7563efbdd757a310d17ebc95166cef3" }, + "lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" }, "lazydev.nvim": { "branch": "main", "commit": "f59bd14a852ca43db38e3662395354cb2a9b13e0" }, - "ltex_extra.nvim": { "branch": "dev", "commit": "09dc879b1873001f855bca5ad1f024ca15b9bbaf" }, + "lsp-setup.nvim": { "branch": "main", "commit": "6e4e977512ce426d8b52c27f3b6e6aefc73e1452" }, + "ltex_extra.nvim": { "branch": "dev", "commit": "57192d7ae5ba8cef3c10e90f2cd62d4a7cdaab69" }, "lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" }, "luarocks.nvim": { "branch": "main", "commit": "1db9093915eb16ba2473cfb8d343ace5ee04130a" }, - "luvit-meta": { "branch": "main", "commit": "1df30b60b1b4aecfebc785aa98943db6c6989716" }, + "luvit-meta": { "branch": "main", "commit": "57d464c4acb5c2e66bd4145060f5dc9e96a7bbb7" }, "markmap.nvim": { "branch": "main", "commit": "5fb6755cf5434511cc23a4936c9eb76b9142fba5" }, "mason-conform.nvim": { "branch": "main", "commit": "abce2be529f3b4b336c56d0ba6336a9144e0fee6" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" }, @@ -38,51 +49,54 @@ "mason.nvim": { "branch": "main", "commit": "c43eeb5614a09dc17c03a7fb49de2e05de203924" }, "mdeval.nvim": { "branch": "master", "commit": "0e1b248db174a9659a9ab16eb8c90ff3aec55264" }, "mini.nvim": { "branch": "main", "commit": "64e95aa77587d04f97a5579b2106a82a08a7d968" }, - "molten-nvim": { "branch": "main", "commit": "c621baf53459a6c45dfd98dcc11cbba7a7ae9470" }, - "neo-tree.nvim": { "branch": "main", "commit": "5d172e8315444dbc32867d1c7b04d8e7e68ec4e1" }, - "neogen": { "branch": "main", "commit": "b2e78708876f4da507839726816010a68e33fec8" }, - "neotest": { "branch": "master", "commit": "d66cf4e05a116957f0d3a7755a24291c7d1e1f72" }, + "molten-nvim": { "branch": "main", "commit": "66ee5c0a0fbe3e014b867d04db44592f2d3eb30f" }, + "neo-tree.nvim": { "branch": "main", "commit": "a77af2e764c5ed4038d27d1c463fa49cd4794e07" }, + "neogen": { "branch": "main", "commit": "dc50715c009f89b8111197fd2f282f6042daa7ea" }, + "neotest": { "branch": "master", "commit": "6d3d22cdad49999ef774ebe1bc250a4994038964" }, "neotest-python": { "branch": "master", "commit": "a2861ab3c9a0bf75a56b11835c2bfc8270f5be7e" }, "nui.nvim": { "branch": "main", "commit": "a0fd35fcbb4cb479366f1dc5f20145fd718a3733" }, "nvim-FeMaco.lua": { "branch": "main", "commit": "96bbf843595dbe865838b3f2484b73557f34700c" }, - "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-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-treesitter": { "branch": "master", "commit": "cfc6f2c117aaaa82f19bcce44deec2c194d900ab" }, - "nvim-treesitter-context": { "branch": "master", "commit": "bece284c5322ddf6946fa4bdc383a2bc033269d7" }, + "nvim-treesitter-context": { "branch": "master", "commit": "920999bf53daa63ddf12efdeb5137a7cea1cc201" }, "nvim-treesitter-endwise": { "branch": "master", "commit": "8b34305ffc28bd75a22f5a0a9928ee726a85c9a6" }, "nvim-treesitter-textsubjects": { "branch": "master", "commit": "a8d2844bba925d9450ef7ab215f3b054028288ca" }, - "nvim-ts-autotag": { "branch": "main", "commit": "1cca23c9da708047922d3895a71032bc0449c52d" }, - "nvim-ts-context-commentstring": { "branch": "main", "commit": "1b212c2eee76d787bbea6aa5e92a2b534e7b4f8f" }, + "nvim-ts-autotag": { "branch": "main", "commit": "f2d24aca1bcbbd2c0306fd93d52e3697027b77ff" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "9c74db656c3d0b1c4392fc89a016b1910539e7c0" }, "nvim-web-devicons": { "branch": "master", "commit": "5b9067899ee6a2538891573500e8fd6ff008440f" }, - "otter.nvim": { "branch": "main", "commit": "7b42ce1f9deabc596214fc3b80e5ab4fd5b32726" }, + "otter.nvim": { "branch": "main", "commit": "ca9ce67d0399380b659923381b58d174344c9ee7" }, + "parrot.nvim": { "branch": "main", "commit": "413679a79cf220c261a4700cee5a01cadd99db53" }, "peek.nvim": { "branch": "master", "commit": "5820d937d5414baea5f586dc2a3d912a74636e5b" }, - "plenary.nvim": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" }, + "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, "popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" }, - "quarto-nvim": { "branch": "main", "commit": "1cb2d24d7793241bd43f38e3a6f99a6d11f84458" }, - "rainbow-delimiters.nvim": { "branch": "master", "commit": "dc788723f717bdd3041838b8db34cce53c9aa920" }, - "render-markdown": { "branch": "main", "commit": "16369540a005ad0cf267498162aedca6dfca1b9c" }, + "quarto-nvim": { "branch": "main", "commit": "23083a0152799ca7263ac9ae53d768d4dd93d24e" }, + "rainbow-delimiters.nvim": { "branch": "master", "commit": "e0f9b3efe150724af2d2ed59997d5ece373840e3" }, + "render-markdown": { "branch": "main", "commit": "6096cf3608b576a38fd1396227dbc0473091714d" }, "smartcolumn.nvim": { "branch": "main", "commit": "d01b99355c7fab13233f48d0f28dc097e68a03f7" }, "stickybuf.nvim": { "branch": "master", "commit": "2160fcd536d81f5fa43f7167dba6634e814e3154" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "dae2eac9d91464448b584c7949a31df8faefec56" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, + "telescope-jj.nvim": { "branch": "main", "commit": "9527e39f30eded7950ca127698422ec412d633c4" }, + "telescope-luasnip.nvim": { "branch": "master", "commit": "11668478677de360dea45cf2b090d34f21b8ae07" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "texpresso.vim": { "branch": "main", "commit": "907838c08bbf99ad6bed3c908f1d0551a92ab4e0" }, + "texpresso.vim": { "branch": "main", "commit": "1cc949fde8ed3220968039b6b1b6ccdd9f475087" }, "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": "8ab96b38a2530eacba5be717f52e04601eb59326" }, + "which-key.nvim": { "branch": "main", "commit": "9b365a6428a9633e3eeb34dbef1b791511c54f70" }, "wrapping.nvim": { "branch": "master", "commit": "3a823200c297885b70515fa8d974e1763c578e26" }, "zen-mode.nvim": { "branch": "main", "commit": "04b52674b8c800f8b7d4609e8bd8d0212e3ffa79" }, - "zk-nvim": { "branch": "main", "commit": "50d92038d22ad9a537dcfd463c38527591430df6" } + "zk-nvim": { "branch": "main", "commit": "469e7562b8dbf1bcbfe1be245ca5d1724917f5c6" } } diff --git a/nvim/.config/nvim/lua/core/mappings.lua b/nvim/.config/nvim/lua/core/mappings.lua index dab1ef0..c0c5880 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 5fb9e4a..043136a 100644 --- a/nvim/.config/nvim/lua/core/util.lua +++ b/nvim/.config/nvim/lua/core/util.lua @@ -64,11 +64,6 @@ 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") @@ -84,8 +79,8 @@ function T.get_python_venv_basefolder(workspace) if obj.code ~= 0 then return end - match = obj.stdout:match("^%s*(.-)%s*$") - venv_path_cached = match + local venv_base_folder = obj.stdout:match("^%s*(.-)%s*$") + venv_path_cached = venv_base_folder 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 be88221..35bac31 100644 --- a/nvim/.config/nvim/lua/plugins/base.lua +++ b/nvim/.config/nvim/lua/plugins/base.lua @@ -203,32 +203,6 @@ 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() @@ -277,6 +251,4 @@ 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 7b39561..6d38c40 100644 --- a/nvim/.config/nvim/lua/plugins/completion.lua +++ b/nvim/.config/nvim/lua/plugins/completion.lua @@ -1,69 +1,270 @@ -return { - -- full documentation here: https://cmp.saghen.dev/ - "saghen/blink.cmp", +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", dependencies = { - "saghen/blink.compat", + "L3MON4D3/LuaSnip", "rafamadriz/friendly-snippets", - "hrsh7th/cmp-calc", - "f3fora/cmp-spell", + "saadparwaiz1/cmp_luasnip", { - "aspeddro/cmp-pandoc.nvim", - dependencies = { - "nvim-lua/plenary.nvim", - }, - opts = { - filetypes = { "pandoc", "markdown", "quarto", "rmd" }, - }, + "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, }, }, event = { "InsertEnter" }, - opts = { - keymap = { preset = "default" }, + build = "make install_jsregexp", + opts = function(_, opts) + local cmp = require("cmp") + local luasnip = require("luasnip") - 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, - }, + require("luasnip.loaders.from_vscode").lazy_load({ exclude = { "markdown", "quarto" } }) + require("luasnip.loaders.from_snipmate").lazy_load() - -- 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", - }, - }, - }, - }, - opts_extend = { "sources.default" }, + 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", + }, + 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, } diff --git a/nvim/.config/nvim/lua/plugins/data_analysis.lua b/nvim/.config/nvim/lua/plugins/data_analysis.lua index e05887b..6719b50 100644 --- a/nvim/.config/nvim/lua/plugins/data_analysis.lua +++ b/nvim/.config/nvim/lua/plugins/data_analysis.lua @@ -15,6 +15,7 @@ return { dependencies = { "jmbuhr/otter.nvim", "neovim/nvim-lspconfig", + "hrsh7th/nvim-cmp", "nvim-treesitter/nvim-treesitter", { "benlubas/molten-nvim", optional = true }, }, @@ -40,11 +41,10 @@ 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 code cell below" }) - map("n", "cO", "O```{python}```k", { desc = "Insert code cell above" }) + map("n", "co", "o```{python}```k", { desc = "Insert quarto cell below" }) + map("n", "cO", "O```{python}```k", { desc = "Insert quarto cell above" }) if require("core.util").is_available("which-key") then require("which-key").add({ "c", group = "codecells" }) @@ -53,44 +53,48 @@ return { ft = { "quarto" }, }, + { + "vhyrro/luarocks.nvim", + priority = 1001, -- this plugin needs to run before anything else + opts = { + rocks = { "magick" }, + }, + }, -- image display { "3rd/image.nvim", - 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 = { + 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, only_render_image_at_cursor = true, filetypes = { "markdown", "vimwiki", "quarto" }, - }, - neorg = { + } + end + if vim.treesitter.language.get_lang("norg") then + integrations["neorg"] = { + enabled = true, + clear_in_insert_mode = true, + download_remote_images = true, only_render_image_at_cursor = true, - }, - 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") + 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 end, - ft = { "markdown", "vimwiki", "quarto", "norg", "typst", "python" }, + ft = { "markdown", "vimwiki", "quarto", "norg", "python" }, priority = 60, }, -- REPL work @@ -141,7 +145,7 @@ return { ":noautocmd :MoltenEnterOutput", { silent = true, desc = "show output" } ) - map("n", "cx", function() + map("n", "cP", function() vim.cmd("MoltenHideOutput") vim.cmd("MoltenDelete") end, { silent = true, desc = "hide output" }) @@ -188,9 +192,9 @@ return { ft = { "norg", "quarto", "python" }, keys = { { "vn", ":MoltenInfo" }, + { "cJ", ":JupyterStart", desc = "start jupyter", silent = true }, }, cmd = { - "JupyterStart", "MoltenInfo", "MoltenInit", "MoltenDeinit", @@ -221,29 +225,25 @@ return { -- Edit code blocks in md/quarto using whatever language is { "AckslD/nvim-FeMaco.lua", - 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, + cmd = { + "FeMaco", }, - config = function(_, opts) - vim.keymap.set("n", "ce", ":FeMaco", { desc = "edit codecell" }) - require("femaco").setup(opts) - end, + ft = { "markdown", "quarto" }, + opts = {}, 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 jupytext installed + cond = vim.fn.executable("jupytext") == 1, -- only runs if imagemagick 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 c382f80..2ff40a2 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_format", "ruff_organize_imports" }, + python = { "ruff_fix", "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 26d42f8..c24cc38 100644 --- a/nvim/.config/nvim/lua/plugins/languages.lua +++ b/nvim/.config/nvim/lua/plugins/languages.lua @@ -12,18 +12,17 @@ return { }, dependencies = { { "Bilal2453/luvit-meta" }, -- optional `vim.uv` typings - -- 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, - -- }, + { -- 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 deleted file mode 100644 index 0307ceb..0000000 --- a/nvim/.config/nvim/lua/plugins/llm.lua +++ /dev/null @@ -1,54 +0,0 @@ -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 0618215..5b6e2ac 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -35,55 +35,183 @@ local servers = { serve_d = {}, taplo = {}, texlab = {}, - tinymist = { - settings = { - formatterMode = "typstyle", - }, - }, + tinymist = {}, ts_ls = {}, yamlls = {}, } -local lsp = { - { -- pretty lsp 'peek' menus - "DNLHC/glance.nvim", - opts = { border = { enable = true }, theme = { enable = true, mode = "auto" } }, - cmd = { "Glance" }, - }, +return { + -- lsp setup { - "neovim/nvim-lspconfig", + "junnplus/lsp-setup.nvim", dependencies = { { - "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" }, - }, + "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", cmd = { "LspInstall", "LspUninstall" }, }, - { "saghen/blink.cmp", optional = true }, }, event = { "BufReadPost", "BufNewFile", "BufWritePre" }, - opts = { servers = servers }, - config = function(_, lspconfig_opts) - local lspconfig = require("lspconfig") + 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 -- 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 }) @@ -95,19 +223,16 @@ local lsp = { end, }) - 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 + 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, + }, + }) + local lspconfig = require("lspconfig") lspconfig.nushell.setup({}) lspconfig.marksman.setup({ @@ -150,6 +275,7 @@ local lsp = { end, } end + on_attach(client, bufnr) end, on_new_config = function(conf, new_root) if require("lspconfig.util").root_pattern(".zk")(new_root) then @@ -165,10 +291,12 @@ local lsp = { -- 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, @@ -187,6 +315,7 @@ local lsp = { }) 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 @@ -210,6 +339,7 @@ local lsp = { 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 @@ -226,98 +356,10 @@ local lsp = { 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 0ab8c6b..c8d1053 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 76b531b..602954f 100644 --- a/nvim/.config/nvim/lua/plugins/prose.lua +++ b/nvim/.config/nvim/lua/plugins/prose.lua @@ -72,8 +72,7 @@ local prose_plugs = { render_modes = { "n", "c", "i" }, code = { sign = false, - width = "full", - position = "right", + width = "block", right_pad = 1, }, checkbox = { @@ -82,11 +81,6 @@ 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 = { @@ -97,7 +91,7 @@ local prose_plugs = { cmd = "RenderMarkdown", keys = { { - "pm", + "pp", function() require("render-markdown").toggle() end, @@ -106,43 +100,29 @@ 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, - opts = {}, + 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, }, { "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 { @@ -159,14 +139,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 { - "zk-org/zk-nvim", + "mickael-menu/zk-nvim", config = function() if require("core.util").is_available("which-key") then require("which-key").add({ @@ -179,24 +159,6 @@ 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", @@ -237,7 +199,6 @@ 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" }, @@ -258,25 +219,22 @@ local prose_plugs = { -- cite as you write from papis databases -- ADDITIONAL DEPENDENCIES: papis and yq in shell env - -- 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, - }, + -- { + -- "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, + -- }, { "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 3543201..468067b 100644 --- a/nvim/.config/nvim/lua/plugins/statusline.lua +++ b/nvim/.config/nvim/lua/plugins/statusline.lua @@ -22,11 +22,14 @@ return { return "" -- we don't know if we have python yet, start a check else - if vim.fn.has("python3") == 1 then - has_pynvim = 1 - else - has_pynvim = 0 - end + 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 end end diff --git a/nvim/.config/nvim/lua/plugins/terminal.lua b/nvim/.config/nvim/lua/plugins/terminal.lua index 54f5726..ac97546 100644 --- a/nvim/.config/nvim/lua/plugins/terminal.lua +++ b/nvim/.config/nvim/lua/plugins/terminal.lua @@ -1,54 +1,68 @@ -return { -- simple programmable terminal toggling for nvim +return { + -- simpler, programmable and multiple 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 = [[tt]], + open_mapping = [[=]], 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, desc = "terminal" }) + end, { silent = true, buffer = true }) end - local custom_term_default_style = function(cmd) - return { - cmd = cmd, + -- 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 + end + local terms = { + lazygit = Terminal:new({ + cmd = "lazygit", hidden = true, direction = "float", float_opts = { border = "curved" }, on_open = custom_term_set_toggle_key, - } - end - local terms = { - 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)), + }), + python = Terminal:new({ + cmd = get_python_cmd(), + hidden = true, + direction = "float", + float_opts = { border = "curved" }, + on_open = custom_term_set_toggle_key, + }), } - -- have user decide between floating or split - local function toggle_split_or_float(term, bang, vertsize) + -- create a lazygit window with the lazygit command + local function toggle_custom_term(term, bang, vertsize) vertsize = vertsize or vim.o.columns * 0.4 if not bang then term.direction = "float" @@ -60,25 +74,30 @@ return { -- simple programmable terminal toggling for nvim end end - 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 }) + 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 } + ) end, - cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm", "Euporieterm" }, + cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" }, keys = { - { "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" }, + { "sg", ":Lazygit", desc = "git floating" }, + { "sG", ":Lazygit!", desc = "git buffer" }, + { "sp", ":Pythonterm", desc = "python floating" }, + { "sP", ":Pythonterm!", desc = "python buffer" }, }, }, } diff --git a/office/.config/task/taskrc b/office/.config/task/taskrc index 12270ae..c9cf994 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.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 +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 # 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 14741d0..5971cb8 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.2 +version: v4.1