From 7ff62840b73df947705700b0035ed5f233d57f97 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 16:57:17 +0200 Subject: [PATCH 1/8] nvim: Move core.autocmds to core.commands --- nvim/.config/nvim/lazy-lock.json | 1 - nvim/.config/nvim/lua/core/autocmds.lua | 26 ------------------------- nvim/.config/nvim/lua/core/commands.lua | 26 +++++++++++++++++++++++++ nvim/.config/nvim/lua/core/init.lua | 2 +- 4 files changed, 27 insertions(+), 28 deletions(-) delete mode 100644 nvim/.config/nvim/lua/core/autocmds.lua create mode 100644 nvim/.config/nvim/lua/core/commands.lua diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index bd81b5b..3ed8b73 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -39,7 +39,6 @@ "jupytext.nvim": { "branch": "main", "commit": "c8baf3ad344c59b3abd461ecc17fc16ec44d0f7b" }, "lazy.nvim": { "branch": "main", "commit": "c501b429cf995c645454539b924aaefae45bb9eb" }, "lsp-setup.nvim": { "branch": "main", "commit": "6e4e977512ce426d8b52c27f3b6e6aefc73e1452" }, - "ltex_extra.nvim": { "branch": "dev", "commit": "57192d7ae5ba8cef3c10e90f2cd62d4a7cdaab69" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "luarocks.nvim": { "branch": "main", "commit": "1db9093915eb16ba2473cfb8d343ace5ee04130a" }, "markmap.nvim": { "branch": "main", "commit": "5fb6755cf5434511cc23a4936c9eb76b9142fba5" }, diff --git a/nvim/.config/nvim/lua/core/autocmds.lua b/nvim/.config/nvim/lua/core/autocmds.lua deleted file mode 100644 index cfd2303..0000000 --- a/nvim/.config/nvim/lua/core/autocmds.lua +++ /dev/null @@ -1,26 +0,0 @@ --- Highlight whatever is being yanked -vim.api.nvim_create_autocmd({ "TextYankPost" }, { - command = 'silent! lua require"vim.highlight".on_yank{timeout=500}', - desc = "Highlight yanked text whenevery yanking something", - group = vim.api.nvim_create_augroup("highlightyanks", { clear = true }), -}) - --- Special setting for editing gopass files - make sure nothing leaks outside the directories it is supposed to -vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, { - pattern = { - "/dev/shm/gopass.*", - "/dev/shm/pass.?*/?*.txt", - "$TMPDIR/pass.?*/?*.txt", - "/tmp/pass.?*/?*.txt", - }, - command = "setlocal noswapfile nobackup noundofile nowritebackup viminfo=", - desc = "Don't leak any information when editing potential password files", - group = vim.api.nvim_create_augroup("passnoleak", { clear = true }), -}) - --- remove line numbers from terminal buffers -vim.api.nvim_create_autocmd({ "TermOpen" }, { - desc = "Hide buffer numbers for terminals", - pattern = "*", - command = "setlocal nonumber norelativenumber", -}) diff --git a/nvim/.config/nvim/lua/core/commands.lua b/nvim/.config/nvim/lua/core/commands.lua new file mode 100644 index 0000000..1a3906b --- /dev/null +++ b/nvim/.config/nvim/lua/core/commands.lua @@ -0,0 +1,26 @@ +-- Highlight whatever is being yanked +vim.api.nvim_create_autocmd({ "TextYankPost" }, { + command = 'silent! lua require"vim.highlight".on_yank{timeout=500}', + desc = "Highlight yanked text whenevery yanking something", + group = vim.api.nvim_create_augroup("highlightyanks", { clear = true }), +}) + +-- Special setting for editing gopass files - make sure nothing leaks outside the directories it is supposed to +vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, { + pattern = { + "/dev/shm/gopass.*", + "/dev/shm/pass.?*/?*.txt", + "$TMPDIR/pass.?*/?*.txt", + "/tmp/pass.?*/?*.txt", + }, + command = "setlocal noswapfile nobackup noundofile nowritebackup viminfo=", + desc = "Don't leak any information when editing potential password files", + group = vim.api.nvim_create_augroup("passnoleak", { clear = true }), +}) + +-- remove line numbers from terminal buffers +vim.api.nvim_create_autocmd({ "TermOpen" }, { + desc = "Hide buffer numbers for terminals", + pattern = "*", + command = "setlocal nonumber norelativenumber", +}) diff --git a/nvim/.config/nvim/lua/core/init.lua b/nvim/.config/nvim/lua/core/init.lua index addb99f..577c6e5 100644 --- a/nvim/.config/nvim/lua/core/init.lua +++ b/nvim/.config/nvim/lua/core/init.lua @@ -1,7 +1,7 @@ for _, source in ipairs({ "core.settings", "core.lazy", - "core.autocmds", + "core.commands", "core.mappings", }) do local status_ok, fault = pcall(require, source) From 9ded34f73cd2cf560208865b58c853d24dc69174 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:18:34 +0200 Subject: [PATCH 2/8] nvim: Add custom spellcheck toggle with user events Added a user command `SpellTogle` which toggles on or off spellchecking in the current buffer. Can be invoked like that, or with one or multiple language to spellcheck (e.g. `SpellToggle en_us en_gb`). Can also be invoked with a bang to always enable instead of toggling. Publishes a user event called `SpellEnable` or `SpellDisable` depending on the aciton which autocommands can listen for. --- nvim/.config/nvim/lua/core/commands.lua | 17 +++++++++++++++++ nvim/.config/nvim/lua/core/mappings.lua | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/nvim/.config/nvim/lua/core/commands.lua b/nvim/.config/nvim/lua/core/commands.lua index 1a3906b..289cd36 100644 --- a/nvim/.config/nvim/lua/core/commands.lua +++ b/nvim/.config/nvim/lua/core/commands.lua @@ -24,3 +24,20 @@ vim.api.nvim_create_autocmd({ "TermOpen" }, { pattern = "*", command = "setlocal nonumber norelativenumber", }) + +-- Custom spell enable which fires an event that other things can +-- hook into. +-- Toggles off and on by default, only turns on if called with bang. +vim.api.nvim_create_user_command("SpellToggle", function(opt) + vim.opt.spell = opt.bang or not vim.opt.spell:get() + if vim.opt.spell:get() then + if next(opt.fargs) ~= nil then + vim.opt.spelllang = opt.fargs + end + vim.api.nvim_exec_autocmds("User", { pattern = "SpellEnable" }) + vim.notify("Spellcheck enabled") + else + vim.api.nvim_exec_autocmds("User", { pattern = "SpellDisable" }) + vim.notify("Spellcheck disabled") + end +end, { nargs = "*", bang = true }) diff --git a/nvim/.config/nvim/lua/core/mappings.lua b/nvim/.config/nvim/lua/core/mappings.lua index a4d3028..5f61ba8 100644 --- a/nvim/.config/nvim/lua/core/mappings.lua +++ b/nvim/.config/nvim/lua/core/mappings.lua @@ -127,10 +127,11 @@ map("n", "Q", "vapJgqap", { silent = true, desc = "Unformat then fo -- SPELL CHECKING -- Move to the prev/next spelling error with [S ]S -- Move to the prev/next spelling error or suggestion with [s ]s -map("n", "ZZ", ":setlocal spell! spelllang=en_us,en_gb,de_de", { desc = "Toggle spellcheck" }) -map("n", "ZE", ":setlocal spell! spelllang=en_us", { desc = "Toggle EN_US spellcheck" }) -map("n", "ZB", ":setlocal spell! spelllang=en_gb", { desc = "Toggle EN_GB spellcheck" }) -map("n", "ZD", ":setlocal spell! spelllang=de_de", { desc = "Toggle DE_DE spellcheck" }) +map("n", "ZZ", "SpellToggle en_us en_gb de_de", { desc = "Toggle spellcheck" }) +map("n", "ZA", "SpellToggle! en_us en_gb de_de", { desc = "Enable spellcheck" }) +map("n", "ZE", "SpellToggle en_us", { desc = "Toggle EN_US spellcheck" }) +map("n", "ZB", "SpellToggle en_gb", { desc = "Toggle EN_GB spellcheck" }) +map("n", "ZD", "SpellToggle de_de", { desc = "Toggle DE_DE spellcheck" }) -- undo last spelling mistake from insert and normal mode map("i", "", "ue[s1z=`]au") map("n", "z", "mse[s1z=`s", { desc = "Fix last spell error" }) From e6497a2241eeebfdb24d1de164ff9d3daaa2dc8a Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:20:35 +0200 Subject: [PATCH 3/8] nvim: Only start ltex LSP if spellchecking enabled Since ltex-lsp eats quite a lot of resources and takes a while to start up we don't always want it enabled for every prose file. This commit ensures that it only starts up when spellchecking is enabled for a buffer (through the custom user command `SpellToggle`). --- nvim/.config/nvim/lazy-lock.json | 1 + nvim/.config/nvim/lua/plugins/config/lsp.lua | 22 +++++++++++++++++++- nvim/.config/nvim/lua/plugins/prose.lua | 2 -- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 3ed8b73..bd81b5b 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -39,6 +39,7 @@ "jupytext.nvim": { "branch": "main", "commit": "c8baf3ad344c59b3abd461ecc17fc16ec44d0f7b" }, "lazy.nvim": { "branch": "main", "commit": "c501b429cf995c645454539b924aaefae45bb9eb" }, "lsp-setup.nvim": { "branch": "main", "commit": "6e4e977512ce426d8b52c27f3b6e6aefc73e1452" }, + "ltex_extra.nvim": { "branch": "dev", "commit": "57192d7ae5ba8cef3c10e90f2cd62d4a7cdaab69" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, "luarocks.nvim": { "branch": "main", "commit": "1db9093915eb16ba2473cfb8d343ace5ee04130a" }, "markmap.nvim": { "branch": "main", "commit": "5fb6755cf5434511cc23a4936c9eb76b9142fba5" }, diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index 8650f74..d81fb37 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -20,7 +20,7 @@ local servers = { eslint = {}, gopls = {}, julials = {}, - ltex = {}, + ltex = { autostart = false }, lua_ls = { settings = { Lua = { @@ -201,3 +201,23 @@ if require("core.util").is_available("arduino") then on_new_config = require("arduino").on_new_config, }) end + +vim.api.nvim_create_autocmd("User", { + pattern = "SpellEnable", + 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 + end, + settings = { + ltex = { + language = vim.opt.spelllang:get(), + }, + }, + }) + vim.cmd("LspStart ltex") + end, +}) diff --git a/nvim/.config/nvim/lua/plugins/prose.lua b/nvim/.config/nvim/lua/plugins/prose.lua index b9ad789..2c2981f 100644 --- a/nvim/.config/nvim/lua/plugins/prose.lua +++ b/nvim/.config/nvim/lua/plugins/prose.lua @@ -182,8 +182,6 @@ local prose_plugs = { { "barreiroleo/ltex_extra.nvim", branch = "dev", - ft = writing_ft, - opts = {}, }, } From 894b7ff175ba874aa19b3dfb080e46000f0e768d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:22:03 +0200 Subject: [PATCH 4/8] nvim: Disable marksman lsp in zk notebook directories When a `.zk` directory is found in the current root directory of the marksman project, the lsp is disabled. This is because zk delivers its own lsp server with correct following of note ids instead of full file names which marksman expects and fails to find. --- nvim/.config/nvim/lua/plugins/config/lsp.lua | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index d81fb37..b4e3236 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -35,9 +35,7 @@ local servers = { }, }, }, - marksman = { - filetypes = { "markdown", "quarto" }, - }, + marksman = {}, basedpyright = {}, ruff = {}, serve_d = {}, @@ -157,6 +155,25 @@ lsp.setup({ local lspconfig = require("lspconfig") lspconfig.nushell.setup({}) +lspconfig.marksman.setup({ + filetypes = { "markdown", "quarto" }, + on_attach = function(client, bufnr) + -- TODO: for some reason this is always true even though it shouldn't be + if client.config.in_zk_notebook then + vim.defer_fn(function() + vim.lsp.buf_detach_client(bufnr, client.id) + end, 1000) + end + end, + on_new_config = function(conf, new_root) + if require("lspconfig.util").root_pattern(".zk")(new_root) then + conf.in_zk_notebook = true + else + conf.in_zk_notebook = false + end + end, +}) + local python_path -- ensure python virtualenv is determined automatically on lsp start lspconfig.basedpyright.setup({ From 851bf58b21515c5cce4011eabddc66e9a5d027c8 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:24:29 +0200 Subject: [PATCH 5/8] nvim: Improve snippet jumping Snippets can be jumped through more easily now since jumping between snippets (with and ) takes precedence over completions and jumping through completions. That means when a snippet has been expanded we can now cycle through its insertion points without worrying about activating completion items instead. Additionally, only jump through insertion points as long as we are within the snippet boundaries with the cursor, so it doesn't surprise jump later when pressing from somewhere else in the file. --- nvim/.config/nvim/lua/plugins/completion.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/completion.lua b/nvim/.config/nvim/lua/plugins/completion.lua index cb5a3fc..a97c9bb 100644 --- a/nvim/.config/nvim/lua/plugins/completion.lua +++ b/nvim/.config/nvim/lua/plugins/completion.lua @@ -135,12 +135,12 @@ return { }), -- disable selection in cmd mode }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() - -- they way you will only jump inside the snippet region - elseif luasnip.expand_or_jumpable() then + -- 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 @@ -148,10 +148,10 @@ return { end end, { "i", "s" }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then + if luasnip.jumpable(-1) then luasnip.jump(-1) + elseif cmp.visible() then + cmp.select_prev_item() else fallback() end From 444c378d89c28cda4eb23cdaddb753ff19c845a2 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:26:02 +0200 Subject: [PATCH 6/8] nvim: Update ZK mappings --- nvim/.config/nvim/lua/plugins/prose.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/prose.lua b/nvim/.config/nvim/lua/plugins/prose.lua index 2c2981f..502fc34 100644 --- a/nvim/.config/nvim/lua/plugins/prose.lua +++ b/nvim/.config/nvim/lua/plugins/prose.lua @@ -133,7 +133,10 @@ local prose_plugs = { keys = { -- additional key instpirations https://github.com/al1-ce/MonolithVim/blob/master/after/ftplugin/markdown.lua { "ni", "edit ~/documents/notes/index.md", desc = "open index", silent = true }, - { "nn", "ZkNotes { sort = { 'modified' } }", desc = "note list" }, + { "nn", "ZkNew { title = vim.fn.input('Title: ') }", desc = "new note" }, + { "nn", ":'<,'>ZkNewFromTitleSelection", desc = "new note from selection", mode = "v" }, + { "nN", ":'<,'>ZkNewFromContentSelection", desc = "content from selection", mode = "v" }, + { "nl", "ZkNotes { sort = { 'modified' } }", desc = "note list" }, { "nf", "ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }", @@ -142,12 +145,9 @@ local prose_plugs = { { "nf", "ZkMatch", desc = "find note from selection", mode = "v" }, { "nt", "ZkTags", desc = "note tags" }, { "nc", "ZkCd", desc = "notedir cd" }, - { "no", "ZkNotes { sort = { 'modified' } }", desc = "orphans list" }, - { "nl", "ZkLinks", desc = "note links" }, - { "nb", "ZkBacklinks", desc = "note backlinks" }, - { "nn", "ZkNew { title = vim.fn.input('Title: ') }", desc = "new note" }, - { "nn", ":'<,'>ZkNewFromTitleSelection", desc = "new note from selection", mode = "v" }, - { "nN", ":'<,'>ZkNewFromContentSelection", desc = "content from selection", mode = "v" }, + { "no", "ZkOrphans { sort = { 'modified' } }", desc = "orphans list" }, + { "nb", "ZkBacklinks", desc = "note backlinks" }, + { "nl", "ZkLinks", desc = "note links" }, }, }, From 52c0260d6d2f907859d4693f1a95540701254e7b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:34:42 +0200 Subject: [PATCH 7/8] script: Close pass repository when locking screen Before locking emit `pass close` if pass binary is found in path. --- scripts/.local/bin/lockscreen | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/.local/bin/lockscreen b/scripts/.local/bin/lockscreen index c7f7435..6bf7cf4 100755 --- a/scripts/.local/bin/lockscreen +++ b/scripts/.local/bin/lockscreen @@ -25,6 +25,10 @@ pre_lock() { type mpc >/dev/null 2>&1 && mpc -q pause type playerctl >/dev/null 2>&1 && playerctl -s pause type amixer >/dev/null 2>&1 && amixer -q set Master mute + + # lock any pass coffins if we have them + type pass >/dev/null 2>&1 && pass close >/dev/null 2>&1 + return } From d99c908ac31d911b2c4c0061ed08c5658cd81624 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 27 Jun 2024 17:35:35 +0200 Subject: [PATCH 8/8] qutebrowser: Use fastside for redirects by default Default to fastside.link instead of farside.link. --- qutebrowser/config/redirects.py | 34 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/qutebrowser/config/redirects.py b/qutebrowser/config/redirects.py index 0749fdd..d6db906 100644 --- a/qutebrowser/config/redirects.py +++ b/qutebrowser/config/redirects.py @@ -1,6 +1,6 @@ import random import re -from typing import Any, Callable +from typing import Callable from urllib import parse from qutebrowser.api import interceptor @@ -29,7 +29,11 @@ def fixScribePath(url: QUrl): return url -redirects = { +type Service = dict[str, list[str]] +type Redirects = dict[str, Service] + + +redirects: Redirects = { "youtube": { "source": ["youtube.com"], "farside": ["invidious"], @@ -163,11 +167,9 @@ def rewrite(request: interceptor.Request) -> None: url = request.request_url if service := _should_be_redirected(url.host()): - if "farside" in service: - url = _farside_redirect(url, _pick_random(service["farside"])) - else: - srv = _pick_random(service["target"]) - url = _target_redirect(url, srv) + url = _farside_redirect( + url, _pick_random(service["farside" if "farside" in service else "target"]) + ) try: request.redirect(url) except RedirectException as e: @@ -177,28 +179,24 @@ def rewrite(request: interceptor.Request) -> None: url = service["postprocess"](url) -def _farside_redirect(url: QUrl, service: str) -> QUrl: +def _farside_redirect(url: QUrl, service: str, use_fastside: bool = True) -> QUrl: try: - url.setHost("farside.link") + url.setHost("fastside.link" if use_fastside else "farside.link") url.setPath(f"/{service}{url.path()}") except RedirectException as e: message.error(str(e)) return url -def _target_redirect(url: QUrl, target: str) -> QUrl: - if target is not None and url.setHost(target) is not False: - return url - return url - - -def _pick_random(choices: list) -> Any: +def _pick_random[T](choices: list[T]) -> T: return choices[random.randint(0, len(choices) - 1)] def _should_be_redirected( - host: str, redirects: dict = redirects -) -> dict[str, list] | None: + # TODO: Update to use typedefs/classes instead of this jumble + host: str, + redirects: Redirects = redirects, +) -> Service | None: for service in redirects.values(): for source in service["source"]: if re.search(source, host):